@tanstack/query-core 5.104.0 → 5.104.2

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 (359) hide show
  1. package/build/legacy/environmentManager.cjs +3 -1
  2. package/build/legacy/environmentManager.cjs.map +1 -1
  3. package/build/legacy/environmentManager.d.cts +6 -1
  4. package/build/legacy/environmentManager.d.cts.map +1 -1
  5. package/build/legacy/environmentManager.d.ts +6 -1
  6. package/build/legacy/environmentManager.d.ts.map +1 -1
  7. package/build/legacy/environmentManager.js +3 -1
  8. package/build/legacy/environmentManager.js.map +1 -1
  9. package/build/legacy/focusManager.cjs +4 -2
  10. package/build/legacy/focusManager.cjs.map +1 -1
  11. package/build/legacy/focusManager.d.cts +5 -3
  12. package/build/legacy/focusManager.d.cts.map +1 -1
  13. package/build/legacy/focusManager.d.ts +5 -3
  14. package/build/legacy/focusManager.d.ts.map +1 -1
  15. package/build/legacy/focusManager.js +4 -2
  16. package/build/legacy/focusManager.js.map +1 -1
  17. package/build/legacy/{hydration-B9t5w6NC.d.ts → hydration-Dfuxd5FW.d.cts} +1410 -128
  18. package/build/legacy/hydration-Dfuxd5FW.d.cts.map +1 -0
  19. package/build/legacy/{hydration-Br9VIGXa.d.cts → hydration-UAqdtMIf.d.ts} +1410 -128
  20. package/build/legacy/hydration-UAqdtMIf.d.ts.map +1 -0
  21. package/build/legacy/hydration.cjs +35 -0
  22. package/build/legacy/hydration.cjs.map +1 -1
  23. package/build/legacy/hydration.d.cts +1 -1
  24. package/build/legacy/hydration.d.ts +1 -1
  25. package/build/legacy/hydration.js +35 -0
  26. package/build/legacy/hydration.js.map +1 -1
  27. package/build/legacy/index.d.cts +1 -1
  28. package/build/legacy/index.d.ts +1 -1
  29. package/build/legacy/infiniteQueryBehavior.cjs +29 -0
  30. package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
  31. package/build/legacy/infiniteQueryBehavior.d.cts +16 -1
  32. package/build/legacy/infiniteQueryBehavior.d.cts.map +1 -1
  33. package/build/legacy/infiniteQueryBehavior.d.ts +16 -1
  34. package/build/legacy/infiniteQueryBehavior.d.ts.map +1 -1
  35. package/build/legacy/infiniteQueryBehavior.js +29 -0
  36. package/build/legacy/infiniteQueryBehavior.js.map +1 -1
  37. package/build/legacy/infiniteQueryObserver.cjs +13 -7
  38. package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
  39. package/build/legacy/infiniteQueryObserver.d.cts +15 -9
  40. package/build/legacy/infiniteQueryObserver.d.cts.map +1 -1
  41. package/build/legacy/infiniteQueryObserver.d.ts +15 -9
  42. package/build/legacy/infiniteQueryObserver.d.ts.map +1 -1
  43. package/build/legacy/infiniteQueryObserver.js +13 -7
  44. package/build/legacy/infiniteQueryObserver.js.map +1 -1
  45. package/build/legacy/mutation.cjs +27 -10
  46. package/build/legacy/mutation.cjs.map +1 -1
  47. package/build/legacy/mutation.d.cts +1 -1
  48. package/build/legacy/mutation.d.ts +1 -1
  49. package/build/legacy/mutation.js +27 -10
  50. package/build/legacy/mutation.js.map +1 -1
  51. package/build/legacy/mutationCache.cjs +53 -12
  52. package/build/legacy/mutationCache.cjs.map +1 -1
  53. package/build/legacy/mutationCache.d.cts +1 -1
  54. package/build/legacy/mutationCache.d.ts +1 -1
  55. package/build/legacy/mutationCache.js +53 -12
  56. package/build/legacy/mutationCache.js.map +1 -1
  57. package/build/legacy/mutationObserver.cjs +27 -16
  58. package/build/legacy/mutationObserver.cjs.map +1 -1
  59. package/build/legacy/mutationObserver.d.cts +1 -1
  60. package/build/legacy/mutationObserver.d.ts +1 -1
  61. package/build/legacy/mutationObserver.js +27 -16
  62. package/build/legacy/mutationObserver.js.map +1 -1
  63. package/build/legacy/notifyManager.cjs +12 -2
  64. package/build/legacy/notifyManager.cjs.map +1 -1
  65. package/build/legacy/notifyManager.d.cts +19 -4
  66. package/build/legacy/notifyManager.d.cts.map +1 -1
  67. package/build/legacy/notifyManager.d.ts +19 -4
  68. package/build/legacy/notifyManager.d.ts.map +1 -1
  69. package/build/legacy/notifyManager.js +12 -2
  70. package/build/legacy/notifyManager.js.map +1 -1
  71. package/build/legacy/onlineManager.cjs +4 -2
  72. package/build/legacy/onlineManager.cjs.map +1 -1
  73. package/build/legacy/onlineManager.d.cts +5 -3
  74. package/build/legacy/onlineManager.d.cts.map +1 -1
  75. package/build/legacy/onlineManager.d.ts +5 -3
  76. package/build/legacy/onlineManager.d.ts.map +1 -1
  77. package/build/legacy/onlineManager.js +4 -2
  78. package/build/legacy/onlineManager.js.map +1 -1
  79. package/build/legacy/queriesObserver.cjs +15 -3
  80. package/build/legacy/queriesObserver.cjs.map +1 -1
  81. package/build/legacy/queriesObserver.d.cts +14 -5
  82. package/build/legacy/queriesObserver.d.cts.map +1 -1
  83. package/build/legacy/queriesObserver.d.ts +14 -5
  84. package/build/legacy/queriesObserver.d.ts.map +1 -1
  85. package/build/legacy/queriesObserver.js +15 -3
  86. package/build/legacy/queriesObserver.js.map +1 -1
  87. package/build/legacy/query.cjs +89 -15
  88. package/build/legacy/query.cjs.map +1 -1
  89. package/build/legacy/query.d.cts +1 -1
  90. package/build/legacy/query.d.ts +1 -1
  91. package/build/legacy/query.js +89 -15
  92. package/build/legacy/query.js.map +1 -1
  93. package/build/legacy/queryCache.cjs +34 -12
  94. package/build/legacy/queryCache.cjs.map +1 -1
  95. package/build/legacy/queryCache.d.cts +1 -1
  96. package/build/legacy/queryCache.d.ts +1 -1
  97. package/build/legacy/queryCache.js +34 -12
  98. package/build/legacy/queryCache.js.map +1 -1
  99. package/build/legacy/queryClient.cjs +104 -32
  100. package/build/legacy/queryClient.cjs.map +1 -1
  101. package/build/legacy/queryClient.d.cts +1 -1
  102. package/build/legacy/queryClient.d.ts +1 -1
  103. package/build/legacy/queryClient.js +104 -32
  104. package/build/legacy/queryClient.js.map +1 -1
  105. package/build/legacy/queryObserver.cjs +78 -6
  106. package/build/legacy/queryObserver.cjs.map +1 -1
  107. package/build/legacy/queryObserver.d.cts +1 -1
  108. package/build/legacy/queryObserver.d.ts +1 -1
  109. package/build/legacy/queryObserver.js +78 -6
  110. package/build/legacy/queryObserver.js.map +1 -1
  111. package/build/{modern/removable-0GzhW1PK.d.cts → legacy/removable-Cw9GNGyK.d.cts} +17 -1
  112. package/build/legacy/removable-Cw9GNGyK.d.cts.map +1 -0
  113. package/build/legacy/{removable-0GzhW1PK.d.cts → removable-Cw9GNGyK.d.ts} +17 -1
  114. package/build/legacy/removable-Cw9GNGyK.d.ts.map +1 -0
  115. package/build/legacy/removable.cjs +12 -0
  116. package/build/legacy/removable.cjs.map +1 -1
  117. package/build/legacy/removable.d.cts +1 -1
  118. package/build/legacy/removable.d.ts +1 -1
  119. package/build/legacy/removable.js +12 -0
  120. package/build/legacy/removable.js.map +1 -1
  121. package/build/legacy/retryer.cjs +26 -4
  122. package/build/legacy/retryer.cjs.map +1 -1
  123. package/build/legacy/retryer.d.cts +1 -1
  124. package/build/legacy/retryer.d.ts +1 -1
  125. package/build/legacy/retryer.js +26 -4
  126. package/build/legacy/retryer.js.map +1 -1
  127. package/build/legacy/streamedQuery.cjs +3 -1
  128. package/build/legacy/streamedQuery.cjs.map +1 -1
  129. package/build/legacy/streamedQuery.d.cts +4 -2
  130. package/build/legacy/streamedQuery.d.cts.map +1 -1
  131. package/build/legacy/streamedQuery.d.ts +4 -2
  132. package/build/legacy/streamedQuery.d.ts.map +1 -1
  133. package/build/legacy/streamedQuery.js +3 -1
  134. package/build/legacy/streamedQuery.js.map +1 -1
  135. package/build/{modern/subscribable-CysQ0tne.d.cts → legacy/subscribable-czlHOxMP.d.cts} +11 -1
  136. package/build/legacy/subscribable-czlHOxMP.d.cts.map +1 -0
  137. package/build/legacy/{subscribable-CysQ0tne.d.cts → subscribable-czlHOxMP.d.ts} +11 -1
  138. package/build/legacy/subscribable-czlHOxMP.d.ts.map +1 -0
  139. package/build/legacy/subscribable.cjs +10 -0
  140. package/build/legacy/subscribable.cjs.map +1 -1
  141. package/build/legacy/subscribable.d.cts +1 -1
  142. package/build/legacy/subscribable.d.ts +1 -1
  143. package/build/legacy/subscribable.js +10 -0
  144. package/build/legacy/subscribable.js.map +1 -1
  145. package/build/legacy/timeoutManager.cjs +11 -6
  146. package/build/legacy/timeoutManager.cjs.map +1 -1
  147. package/build/legacy/timeoutManager.d.cts +23 -6
  148. package/build/legacy/timeoutManager.d.cts.map +1 -1
  149. package/build/legacy/timeoutManager.d.ts +23 -6
  150. package/build/legacy/timeoutManager.d.ts.map +1 -1
  151. package/build/legacy/timeoutManager.js +11 -6
  152. package/build/legacy/timeoutManager.js.map +1 -1
  153. package/build/legacy/types.cjs.map +1 -1
  154. package/build/legacy/types.d.cts +1 -1
  155. package/build/legacy/types.d.ts +1 -1
  156. package/build/legacy/types.js.map +1 -1
  157. package/build/legacy/utils.cjs +117 -8
  158. package/build/legacy/utils.cjs.map +1 -1
  159. package/build/legacy/utils.d.cts +1 -1
  160. package/build/legacy/utils.d.ts +1 -1
  161. package/build/legacy/utils.js +117 -8
  162. package/build/legacy/utils.js.map +1 -1
  163. package/build/modern/environmentManager.cjs +3 -1
  164. package/build/modern/environmentManager.cjs.map +1 -1
  165. package/build/modern/environmentManager.d.cts +6 -1
  166. package/build/modern/environmentManager.d.cts.map +1 -1
  167. package/build/modern/environmentManager.d.ts +6 -1
  168. package/build/modern/environmentManager.d.ts.map +1 -1
  169. package/build/modern/environmentManager.js +3 -1
  170. package/build/modern/environmentManager.js.map +1 -1
  171. package/build/modern/focusManager.cjs +4 -2
  172. package/build/modern/focusManager.cjs.map +1 -1
  173. package/build/modern/focusManager.d.cts +5 -3
  174. package/build/modern/focusManager.d.cts.map +1 -1
  175. package/build/modern/focusManager.d.ts +5 -3
  176. package/build/modern/focusManager.d.ts.map +1 -1
  177. package/build/modern/focusManager.js +4 -2
  178. package/build/modern/focusManager.js.map +1 -1
  179. package/build/modern/{hydration-B9t5w6NC.d.ts → hydration-Dfuxd5FW.d.cts} +1410 -128
  180. package/build/modern/hydration-Dfuxd5FW.d.cts.map +1 -0
  181. package/build/modern/{hydration-Br9VIGXa.d.cts → hydration-UAqdtMIf.d.ts} +1410 -128
  182. package/build/modern/hydration-UAqdtMIf.d.ts.map +1 -0
  183. package/build/modern/hydration.cjs +35 -0
  184. package/build/modern/hydration.cjs.map +1 -1
  185. package/build/modern/hydration.d.cts +1 -1
  186. package/build/modern/hydration.d.ts +1 -1
  187. package/build/modern/hydration.js +35 -0
  188. package/build/modern/hydration.js.map +1 -1
  189. package/build/modern/index.d.cts +1 -1
  190. package/build/modern/index.d.ts +1 -1
  191. package/build/modern/infiniteQueryBehavior.cjs +29 -0
  192. package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
  193. package/build/modern/infiniteQueryBehavior.d.cts +16 -1
  194. package/build/modern/infiniteQueryBehavior.d.cts.map +1 -1
  195. package/build/modern/infiniteQueryBehavior.d.ts +16 -1
  196. package/build/modern/infiniteQueryBehavior.d.ts.map +1 -1
  197. package/build/modern/infiniteQueryBehavior.js +29 -0
  198. package/build/modern/infiniteQueryBehavior.js.map +1 -1
  199. package/build/modern/infiniteQueryObserver.cjs +13 -7
  200. package/build/modern/infiniteQueryObserver.cjs.map +1 -1
  201. package/build/modern/infiniteQueryObserver.d.cts +15 -9
  202. package/build/modern/infiniteQueryObserver.d.cts.map +1 -1
  203. package/build/modern/infiniteQueryObserver.d.ts +15 -9
  204. package/build/modern/infiniteQueryObserver.d.ts.map +1 -1
  205. package/build/modern/infiniteQueryObserver.js +13 -7
  206. package/build/modern/infiniteQueryObserver.js.map +1 -1
  207. package/build/modern/mutation.cjs +27 -10
  208. package/build/modern/mutation.cjs.map +1 -1
  209. package/build/modern/mutation.d.cts +1 -1
  210. package/build/modern/mutation.d.ts +1 -1
  211. package/build/modern/mutation.js +27 -10
  212. package/build/modern/mutation.js.map +1 -1
  213. package/build/modern/mutationCache.cjs +53 -12
  214. package/build/modern/mutationCache.cjs.map +1 -1
  215. package/build/modern/mutationCache.d.cts +1 -1
  216. package/build/modern/mutationCache.d.ts +1 -1
  217. package/build/modern/mutationCache.js +53 -12
  218. package/build/modern/mutationCache.js.map +1 -1
  219. package/build/modern/mutationObserver.cjs +23 -12
  220. package/build/modern/mutationObserver.cjs.map +1 -1
  221. package/build/modern/mutationObserver.d.cts +1 -1
  222. package/build/modern/mutationObserver.d.ts +1 -1
  223. package/build/modern/mutationObserver.js +23 -12
  224. package/build/modern/mutationObserver.js.map +1 -1
  225. package/build/modern/notifyManager.cjs +12 -2
  226. package/build/modern/notifyManager.cjs.map +1 -1
  227. package/build/modern/notifyManager.d.cts +19 -4
  228. package/build/modern/notifyManager.d.cts.map +1 -1
  229. package/build/modern/notifyManager.d.ts +19 -4
  230. package/build/modern/notifyManager.d.ts.map +1 -1
  231. package/build/modern/notifyManager.js +12 -2
  232. package/build/modern/notifyManager.js.map +1 -1
  233. package/build/modern/onlineManager.cjs +4 -2
  234. package/build/modern/onlineManager.cjs.map +1 -1
  235. package/build/modern/onlineManager.d.cts +5 -3
  236. package/build/modern/onlineManager.d.cts.map +1 -1
  237. package/build/modern/onlineManager.d.ts +5 -3
  238. package/build/modern/onlineManager.d.ts.map +1 -1
  239. package/build/modern/onlineManager.js +4 -2
  240. package/build/modern/onlineManager.js.map +1 -1
  241. package/build/modern/queriesObserver.cjs +15 -3
  242. package/build/modern/queriesObserver.cjs.map +1 -1
  243. package/build/modern/queriesObserver.d.cts +14 -5
  244. package/build/modern/queriesObserver.d.cts.map +1 -1
  245. package/build/modern/queriesObserver.d.ts +14 -5
  246. package/build/modern/queriesObserver.d.ts.map +1 -1
  247. package/build/modern/queriesObserver.js +15 -3
  248. package/build/modern/queriesObserver.js.map +1 -1
  249. package/build/modern/query.cjs +89 -15
  250. package/build/modern/query.cjs.map +1 -1
  251. package/build/modern/query.d.cts +1 -1
  252. package/build/modern/query.d.ts +1 -1
  253. package/build/modern/query.js +89 -15
  254. package/build/modern/query.js.map +1 -1
  255. package/build/modern/queryCache.cjs +34 -12
  256. package/build/modern/queryCache.cjs.map +1 -1
  257. package/build/modern/queryCache.d.cts +1 -1
  258. package/build/modern/queryCache.d.ts +1 -1
  259. package/build/modern/queryCache.js +34 -12
  260. package/build/modern/queryCache.js.map +1 -1
  261. package/build/modern/queryClient.cjs +104 -32
  262. package/build/modern/queryClient.cjs.map +1 -1
  263. package/build/modern/queryClient.d.cts +1 -1
  264. package/build/modern/queryClient.d.ts +1 -1
  265. package/build/modern/queryClient.js +104 -32
  266. package/build/modern/queryClient.js.map +1 -1
  267. package/build/modern/queryObserver.cjs +78 -6
  268. package/build/modern/queryObserver.cjs.map +1 -1
  269. package/build/modern/queryObserver.d.cts +1 -1
  270. package/build/modern/queryObserver.d.ts +1 -1
  271. package/build/modern/queryObserver.js +78 -6
  272. package/build/modern/queryObserver.js.map +1 -1
  273. package/build/modern/{removable-0GzhW1PK.d.ts → removable-Cw9GNGyK.d.cts} +17 -1
  274. package/build/modern/removable-Cw9GNGyK.d.cts.map +1 -0
  275. package/build/{legacy/removable-0GzhW1PK.d.ts → modern/removable-Cw9GNGyK.d.ts} +17 -1
  276. package/build/modern/removable-Cw9GNGyK.d.ts.map +1 -0
  277. package/build/modern/removable.cjs +12 -0
  278. package/build/modern/removable.cjs.map +1 -1
  279. package/build/modern/removable.d.cts +1 -1
  280. package/build/modern/removable.d.ts +1 -1
  281. package/build/modern/removable.js +12 -0
  282. package/build/modern/removable.js.map +1 -1
  283. package/build/modern/retryer.cjs +26 -4
  284. package/build/modern/retryer.cjs.map +1 -1
  285. package/build/modern/retryer.d.cts +1 -1
  286. package/build/modern/retryer.d.ts +1 -1
  287. package/build/modern/retryer.js +26 -4
  288. package/build/modern/retryer.js.map +1 -1
  289. package/build/modern/streamedQuery.cjs +3 -1
  290. package/build/modern/streamedQuery.cjs.map +1 -1
  291. package/build/modern/streamedQuery.d.cts +4 -2
  292. package/build/modern/streamedQuery.d.cts.map +1 -1
  293. package/build/modern/streamedQuery.d.ts +4 -2
  294. package/build/modern/streamedQuery.d.ts.map +1 -1
  295. package/build/modern/streamedQuery.js +3 -1
  296. package/build/modern/streamedQuery.js.map +1 -1
  297. package/build/modern/{subscribable-CysQ0tne.d.ts → subscribable-czlHOxMP.d.cts} +11 -1
  298. package/build/modern/subscribable-czlHOxMP.d.cts.map +1 -0
  299. package/build/{legacy/subscribable-CysQ0tne.d.ts → modern/subscribable-czlHOxMP.d.ts} +11 -1
  300. package/build/modern/subscribable-czlHOxMP.d.ts.map +1 -0
  301. package/build/modern/subscribable.cjs +10 -0
  302. package/build/modern/subscribable.cjs.map +1 -1
  303. package/build/modern/subscribable.d.cts +1 -1
  304. package/build/modern/subscribable.d.ts +1 -1
  305. package/build/modern/subscribable.js +10 -0
  306. package/build/modern/subscribable.js.map +1 -1
  307. package/build/modern/timeoutManager.cjs +11 -6
  308. package/build/modern/timeoutManager.cjs.map +1 -1
  309. package/build/modern/timeoutManager.d.cts +23 -6
  310. package/build/modern/timeoutManager.d.cts.map +1 -1
  311. package/build/modern/timeoutManager.d.ts +23 -6
  312. package/build/modern/timeoutManager.d.ts.map +1 -1
  313. package/build/modern/timeoutManager.js +11 -6
  314. package/build/modern/timeoutManager.js.map +1 -1
  315. package/build/modern/types.cjs.map +1 -1
  316. package/build/modern/types.d.cts +1 -1
  317. package/build/modern/types.d.ts +1 -1
  318. package/build/modern/types.js.map +1 -1
  319. package/build/modern/utils.cjs +117 -8
  320. package/build/modern/utils.cjs.map +1 -1
  321. package/build/modern/utils.d.cts +1 -1
  322. package/build/modern/utils.d.ts +1 -1
  323. package/build/modern/utils.js +117 -8
  324. package/build/modern/utils.js.map +1 -1
  325. package/package.json +4 -4
  326. package/src/environmentManager.ts +6 -1
  327. package/src/focusManager.ts +8 -6
  328. package/src/hydration.ts +42 -1
  329. package/src/infiniteQueryBehavior.ts +29 -0
  330. package/src/infiniteQueryObserver.ts +20 -14
  331. package/src/mutation.ts +32 -11
  332. package/src/mutationCache.ts +53 -12
  333. package/src/mutationObserver.ts +29 -14
  334. package/src/notifyManager.ts +12 -2
  335. package/src/onlineManager.ts +7 -5
  336. package/src/queriesObserver.ts +20 -5
  337. package/src/query.ts +153 -20
  338. package/src/queryCache.ts +54 -13
  339. package/src/queryClient.ts +110 -38
  340. package/src/queryObserver.ts +88 -12
  341. package/src/removable.ts +16 -0
  342. package/src/retryer.ts +57 -4
  343. package/src/streamedQuery.ts +4 -3
  344. package/src/subscribable.ts +10 -0
  345. package/src/timeoutManager.ts +23 -6
  346. package/src/types.ts +801 -27
  347. package/src/utils.ts +130 -10
  348. package/build/legacy/hydration-B9t5w6NC.d.ts.map +0 -1
  349. package/build/legacy/hydration-Br9VIGXa.d.cts.map +0 -1
  350. package/build/legacy/removable-0GzhW1PK.d.cts.map +0 -1
  351. package/build/legacy/removable-0GzhW1PK.d.ts.map +0 -1
  352. package/build/legacy/subscribable-CysQ0tne.d.cts.map +0 -1
  353. package/build/legacy/subscribable-CysQ0tne.d.ts.map +0 -1
  354. package/build/modern/hydration-B9t5w6NC.d.ts.map +0 -1
  355. package/build/modern/hydration-Br9VIGXa.d.cts.map +0 -1
  356. package/build/modern/removable-0GzhW1PK.d.cts.map +0 -1
  357. package/build/modern/removable-0GzhW1PK.d.ts.map +0 -1
  358. package/build/modern/subscribable-CysQ0tne.d.cts.map +0 -1
  359. package/build/modern/subscribable-CysQ0tne.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"mutationCache.cjs","names":["Subscribable","Mutation","matchMutation","notifyManager","noop"],"sources":["../../src/mutationCache.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Mutation } from './mutation'\nimport { matchMutation, noop } from './utils'\nimport { Subscribable } from './subscribable'\nimport type { MutationObserver } from './mutationObserver'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationOptions,\n NotifyEvent,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Action, MutationState } from './mutation'\nimport type { MutationFilters } from './utils'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every mutation handled by a `MutationCache`, regardless of which\n * component or observer triggered it. They differ from the `defaultOptions` provided to a\n * `QueryClient` in two ways: `defaultOptions` can be overridden by each mutation, while these\n * callbacks are always called, and `onMutate` here does not allow returning a result.\n *\n * If a callback returns a promise, it will be awaited before the mutation continues.\n */\nexport interface MutationCacheConfig {\n /** Called when any mutation in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n /** Called when any mutation in the cache is successful. */\n onSuccess?: (\n data: unknown,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n /** Called before any mutation in the cache executes. */\n onMutate?: (\n variables: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n /** Called when any mutation in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n}\n\ninterface NotifyEventMutationAdded extends NotifyEvent {\n type: 'added'\n mutation: Mutation<any, any, any, any>\n}\ninterface NotifyEventMutationRemoved extends NotifyEvent {\n type: 'removed'\n mutation: Mutation<any, any, any, any>\n}\n\ninterface NotifyEventMutationObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n mutation?: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any, any>\n}\n\ninterface NotifyEventMutationUpdated extends NotifyEvent {\n type: 'updated'\n mutation: Mutation<any, any, any, any>\n action: Action<any, any, any, any>\n}\n\n/**\n * The event passed to a `MutationCache` subscriber. Fired whenever a mutation is added or removed\n * from the cache, its state is updated, or one of its observers is added, removed, or has its\n * options updated.\n */\nexport type MutationCacheNotifyEvent =\n | NotifyEventMutationAdded\n | NotifyEventMutationRemoved\n | NotifyEventMutationObserverAdded\n | NotifyEventMutationObserverRemoved\n | NotifyEventMutationObserverOptionsUpdated\n | NotifyEventMutationUpdated\n\ntype MutationCacheListener = (event: MutationCacheNotifyEvent) => void\n\n// CLASS\n\n/**\n * The `MutationCache` is the storage for mutations.\n *\n * Normally, you will not interact with the `MutationCache` directly and instead use a\n * `QueryClient`. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as mutations being added, removed, or updated.\n *\n * @example\n * ```ts\n * const unsubscribe = mutationCache.subscribe((event) => {\n * console.log(event.type, event.mutation)\n * })\n * ```\n */\nexport class MutationCache extends Subscribable<MutationCacheListener> {\n #mutations: Set<Mutation<any, any, any, any>>\n #scopes: Map<string, Array<Mutation<any, any, any, any>>>\n #mutationId: number\n\n constructor(public config: MutationCacheConfig = {}) {\n super()\n this.#mutations = new Set()\n this.#scopes = new Map()\n this.#mutationId = 0\n }\n\n /** @internal */\n build<TData, TError, TVariables, TOnMutateResult>(\n client: QueryClient,\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> {\n const mutation = new Mutation({\n client,\n mutationCache: this,\n mutationId: ++this.#mutationId,\n options: client.defaultMutationOptions(options),\n state,\n })\n\n this.add(mutation)\n\n return mutation\n }\n\n /** @internal */\n add(mutation: Mutation<any, any, any, any>): void {\n this.#mutations.add(mutation)\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n scopedMutations.push(mutation)\n } else {\n this.#scopes.set(scope, [mutation])\n }\n }\n this.notify({ type: 'added', mutation })\n }\n\n /** @internal */\n remove(mutation: Mutation<any, any, any, any>): void {\n if (this.#mutations.delete(mutation)) {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n if (scopedMutations.length > 1) {\n const index = scopedMutations.indexOf(mutation)\n if (index !== -1) {\n scopedMutations.splice(index, 1)\n }\n } else if (scopedMutations[0] === mutation) {\n this.#scopes.delete(scope)\n }\n }\n }\n }\n\n // Currently we notify the removal even if the mutation was already removed.\n // Consider making this an error or not notifying of the removal depending on the desired semantics.\n this.notify({ type: 'removed', mutation })\n }\n\n /** @internal */\n canRun(mutation: Mutation<any, any, any, any>): boolean {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const mutationsWithSameScope = this.#scopes.get(scope)\n const firstPendingMutation = mutationsWithSameScope?.find(\n (m) => m.state.status === 'pending',\n )\n // we can run if there is no current pending mutation (start use-case)\n // or if WE are the first pending mutation (continue use-case)\n return !firstPendingMutation || firstPendingMutation === mutation\n } else {\n // For unscoped mutations there are never any pending mutations in front of the\n // current mutation\n return true\n }\n }\n\n /** @internal */\n runNext(mutation: Mutation<any, any, any, any>): Promise<unknown> {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const foundMutation = this.#scopes\n .get(scope)\n ?.find((m) => m !== mutation && m.state.isPaused)\n\n return foundMutation?.continue() ?? Promise.resolve()\n } else {\n return Promise.resolve()\n }\n }\n\n /**\n * Removes all mutations from the cache.\n *\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * mutationCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.#mutations.forEach((mutation) => {\n this.notify({ type: 'removed', mutation })\n })\n this.#mutations.clear()\n this.#scopes.clear()\n })\n }\n\n /**\n * Returns all mutations within the cache.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a mutation in rare scenarios.\n *\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutations = mutationCache.getAll()\n * ```\n */\n getAll(): Array<Mutation> {\n return Array.from(this.#mutations)\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing mutation instance from\n * the cache. If the mutation does not exist, `undefined` is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a mutation in rare scenarios.\n *\n * @see {@link MutationCache#findAll}\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutation = mutationCache.find({ mutationKey: ['addPost'] })\n * ```\n */\n find<\n TData = unknown,\n TError = DefaultError,\n TVariables = any,\n TOnMutateResult = unknown,\n >(\n filters: MutationFilters,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((mutation) =>\n matchMutation(defaultedFilters, mutation),\n ) as Mutation<TData, TError, TVariables, TOnMutateResult> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing mutation instances from the\n * cache that match the given filters. If no mutations match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about mutations in rare scenarios.\n *\n * @see {@link MutationCache#find}\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutations = mutationCache.findAll({ mutationKey: ['addPost'] })\n * ```\n */\n findAll(filters: MutationFilters = {}): Array<Mutation> {\n return this.getAll().filter((mutation) => matchMutation(filters, mutation))\n }\n\n /** @internal */\n notify(event: MutationCacheNotifyEvent) {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /** @internal */\n resumePausedMutations(): Promise<unknown> {\n const pausedMutations = this.getAll().filter((x) => x.state.isPaused)\n\n return notifyManager.batch(() =>\n Promise.all(\n pausedMutations.map((mutation) => mutation.continue().catch(noop)),\n ),\n )\n }\n}\n\nfunction scopeFor(mutation: Mutation<any, any, any, any>) {\n return mutation.options.scope?.id\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2HA,I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;;;;;;CAeA,SAA0B;EACxB,OAAO,MAAM,KAAA,8BAAA,uBAAA,YAAK,IAAA,CAAe;CACnC;;;;;;;;;;;;;;;;CAiBA,KAME,SACkE;EAClE,MAAM,mBAAmB;GAAE,OAAO;GAAM,GAAG;EAAQ;EAEnD,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,aACzBC,cAAAA,cAAc,kBAAkB,QAAQ,CAC1C;CACF;;;;;;;;;;;;;;;;CAiBA,QAAQ,UAA2B,CAAC,GAAoB;EACtD,OAAO,KAAK,OAAO,CAAC,CAAC,QAAQ,aAAaA,cAAAA,cAAc,SAAS,QAAQ,CAAC;CAC5E;;CAGA,OAAO,OAAiC;EACtC,sBAAA,cAAc,YAAY;GACxB,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,KAAK;GAChB,CAAC;EACH,CAAC;CACH;;CAGA,wBAA0C;EACxC,MAAM,kBAAkB,KAAK,OAAO,CAAC,CAAC,QAAQ,MAAM,EAAE,MAAM,QAAQ;EAEpE,OAAOC,sBAAAA,cAAc,YACnB,QAAQ,IACN,gBAAgB,KAAK,aAAa,SAAS,SAAS,CAAC,CAAC,MAAMC,cAAAA,IAAI,CAAC,CACnE,CACF;CACF;AACF;AAEA,SAAS,SAAS,UAAwC;;CACxD,QAAA,wBAAO,SAAS,QAAQ,WAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAO;AACjC"}
1
+ {"version":3,"file":"mutationCache.cjs","names":["Subscribable","Mutation","matchMutation","notifyManager","noop"],"sources":["../../src/mutationCache.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Mutation } from './mutation'\nimport { matchMutation, noop } from './utils'\nimport { Subscribable } from './subscribable'\nimport type { MutationObserver } from './mutationObserver'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationOptions,\n NotifyEvent,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Action, MutationState } from './mutation'\nimport type { MutationFilters } from './utils'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every mutation handled by a `MutationCache`, regardless of which\n * component or observer triggered it. They differ from the `defaultOptions` provided to a\n * `QueryClient` in two ways: `defaultOptions` can be overridden by each mutation, while these\n * callbacks are always called, and `onMutate` here does not allow returning a result.\n *\n * If a callback returns a promise, it will be awaited before the mutation continues.\n */\nexport interface MutationCacheConfig {\n /** Called when any mutation in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n /** Called when any mutation in the cache is successful. */\n onSuccess?: (\n data: unknown,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n /** Called before any mutation in the cache executes. */\n onMutate?: (\n variables: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n /** Called when any mutation in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n}\n\ninterface NotifyEventMutationAdded extends NotifyEvent {\n type: 'added'\n mutation: Mutation<any, any, any, any>\n}\ninterface NotifyEventMutationRemoved extends NotifyEvent {\n type: 'removed'\n mutation: Mutation<any, any, any, any>\n}\n\ninterface NotifyEventMutationObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n mutation?: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any, any>\n}\n\ninterface NotifyEventMutationUpdated extends NotifyEvent {\n type: 'updated'\n mutation: Mutation<any, any, any, any>\n action: Action<any, any, any, any>\n}\n\n/**\n * The event passed to a `MutationCache` subscriber. Fired whenever a mutation is added or removed\n * from the cache, its state is updated, or one of its observers is added, removed, or has its\n * options updated.\n */\nexport type MutationCacheNotifyEvent =\n | NotifyEventMutationAdded\n | NotifyEventMutationRemoved\n | NotifyEventMutationObserverAdded\n | NotifyEventMutationObserverRemoved\n | NotifyEventMutationObserverOptionsUpdated\n | NotifyEventMutationUpdated\n\ntype MutationCacheListener = (event: MutationCacheNotifyEvent) => void\n\n// CLASS\n\n/**\n * The `MutationCache` is the storage for mutations.\n *\n * Normally, you will not interact with the `MutationCache` directly and instead use a\n * `QueryClient`. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as mutations being added, removed, or updated.\n * @example\n * ```ts\n * const unsubscribe = mutationCache.subscribe((event) => {\n * console.log(event.type, event.mutation)\n * })\n * ```\n */\nexport class MutationCache extends Subscribable<MutationCacheListener> {\n #mutations: Set<Mutation<any, any, any, any>>\n #scopes: Map<string, Array<Mutation<any, any, any, any>>>\n #mutationId: number\n\n constructor(public config: MutationCacheConfig = {}) {\n super()\n this.#mutations = new Set()\n this.#scopes = new Map()\n this.#mutationId = 0\n }\n\n /**\n * Creates a mutation and adds it to the cache.\n * @internal\n * @param client - The client the mutation belongs to, used to default its options.\n * @param options - The mutation options. They are defaulted with {@link\n * QueryClient#defaultMutationOptions}.\n * @param state - The initial state of the mutation, e.g. when restoring a dehydrated mutation.\n * @returns The new mutation, already added to the cache.\n */\n build<TData, TError, TVariables, TOnMutateResult>(\n client: QueryClient,\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> {\n const mutation = new Mutation({\n client,\n mutationCache: this,\n mutationId: ++this.#mutationId,\n options: client.defaultMutationOptions(options),\n state,\n })\n\n this.add(mutation)\n\n return mutation\n }\n\n /**\n * Adds a mutation to the cache.\n * @internal\n * @param mutation - The mutation to add. If it has a `scope`, it is queued in that scope.\n */\n add(mutation: Mutation<any, any, any, any>): void {\n this.#mutations.add(mutation)\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n scopedMutations.push(mutation)\n } else {\n this.#scopes.set(scope, [mutation])\n }\n }\n this.notify({ type: 'added', mutation })\n }\n\n /**\n * Removes a mutation from the cache.\n * @internal\n * @param mutation - The mutation to remove, also from its scope's queue.\n */\n remove(mutation: Mutation<any, any, any, any>): void {\n if (this.#mutations.delete(mutation)) {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n if (scopedMutations.length > 1) {\n const index = scopedMutations.indexOf(mutation)\n if (index !== -1) {\n scopedMutations.splice(index, 1)\n }\n } else if (scopedMutations[0] === mutation) {\n this.#scopes.delete(scope)\n }\n }\n }\n }\n\n // Currently we notify the removal even if the mutation was already removed.\n // Consider making this an error or not notifying of the removal depending on the desired semantics.\n this.notify({ type: 'removed', mutation })\n }\n\n /**\n * Checks whether a mutation can run now, given the other mutations in its `scope`.\n * @internal\n * @param mutation - The mutation to check.\n * @returns `true` if the mutation has no `scope`, or no other mutation in its scope is pending\n * ahead of it.\n */\n canRun(mutation: Mutation<any, any, any, any>): boolean {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const mutationsWithSameScope = this.#scopes.get(scope)\n const firstPendingMutation = mutationsWithSameScope?.find(\n (m) => m.state.status === 'pending',\n )\n // we can run if there is no current pending mutation (start use-case)\n // or if WE are the first pending mutation (continue use-case)\n return !firstPendingMutation || firstPendingMutation === mutation\n } else {\n // For unscoped mutations there are never any pending mutations in front of the\n // current mutation\n return true\n }\n }\n\n /**\n * Continues the next paused mutation in the same `scope` after a mutation finishes.\n * @internal\n * @param mutation - The mutation that finished.\n * @returns A promise that resolves once the next paused mutation in the same scope has continued,\n * or immediately if there is none.\n */\n runNext(mutation: Mutation<any, any, any, any>): Promise<unknown> {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const foundMutation = this.#scopes\n .get(scope)\n ?.find((m) => m !== mutation && m.state.isPaused)\n\n return foundMutation?.continue() ?? Promise.resolve()\n } else {\n return Promise.resolve()\n }\n }\n\n /**\n * Removes all mutations from the cache.\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * mutationCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.#mutations.forEach((mutation) => {\n this.notify({ type: 'removed', mutation })\n })\n this.#mutations.clear()\n this.#scopes.clear()\n })\n }\n\n /**\n * Returns all mutations within the cache.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a mutation in rare scenarios.\n * @returns Every mutation in the cache.\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutations = mutationCache.getAll()\n * ```\n */\n getAll(): Array<Mutation> {\n return Array.from(this.#mutations)\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing mutation instance from\n * the cache. If the mutation does not exist, `undefined` is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a mutation in rare scenarios.\n * @param filters - The filters to match. `exact` defaults to `true`.\n * @returns The first matching mutation, or `undefined`.\n * @see {@link MutationCache#findAll}\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutation = mutationCache.find({ mutationKey: ['addPost'] })\n * ```\n */\n find<\n TData = unknown,\n TError = DefaultError,\n TVariables = any,\n TOnMutateResult = unknown,\n >(\n filters: MutationFilters,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((mutation) =>\n matchMutation(defaultedFilters, mutation),\n ) as Mutation<TData, TError, TVariables, TOnMutateResult> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing mutation instances from the\n * cache that match the given filters. If no mutations match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about mutations in rare scenarios.\n * @param filters - The filters to match. Without filters, every mutation is returned.\n * @returns The matching mutations.\n * @see {@link MutationCache#find}\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutations = mutationCache.findAll({ mutationKey: ['addPost'] })\n * ```\n */\n findAll(filters: MutationFilters = {}): Array<Mutation> {\n return this.getAll().filter((mutation) => matchMutation(filters, mutation))\n }\n\n /**\n * Notifies every cache listener of an event, in one batch.\n * @internal\n * @param event - The event passed to every listener.\n */\n notify(event: MutationCacheNotifyEvent) {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /**\n * Continues every paused mutation, e.g. when the app comes back online.\n * @internal\n * @returns A promise that resolves once every paused mutation has continued and settled.\n */\n resumePausedMutations(): Promise<unknown> {\n const pausedMutations = this.getAll().filter((x) => x.state.isPaused)\n\n return notifyManager.batch(() =>\n Promise.all(\n pausedMutations.map((mutation) => mutation.continue().catch(noop)),\n ),\n )\n }\n}\n\n/**\n * Returns the scope id of a mutation, used to run mutations with the same scope one after another.\n * @param mutation - The mutation to read the scope of.\n * @returns The mutation's `scope.id`, or `undefined` if it has no scope.\n */\nfunction scopeFor(mutation: Mutation<any, any, any, any>) {\n return mutation.options.scope?.id\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA0HA,IAAa,gBAAb,cAAmCA,qBAAAA,aAAoC;CAKrE,YAAY,SAAqC,CAAC,GAAG;EACnD,MAAM;EADW,KAAA,SAAA;;;;EAEjB,8BAAA,uBAAA,YAAA,sBAAkB,IAAI,IAAI,CAAA;EAC1B,8BAAA,uBAAA,SAAA,sBAAe,IAAI,IAAI,CAAA;EACvB,8BAAA,uBAAA,aAAA,MAAmB,CAAA;CACrB;;;;;;;;;;CAWA,MACE,QACA,SACA,OACsD;;EACtD,MAAM,WAAW,IAAI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kBA,QAAQ,UAA2B,CAAC,GAAoB;EACtD,OAAO,KAAK,OAAO,CAAC,CAAC,QAAQ,aAAaA,cAAAA,cAAc,SAAS,QAAQ,CAAC;CAC5E;;;;;;CAOA,OAAO,OAAiC;EACtC,sBAAA,cAAc,YAAY;GACxB,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,KAAK;GAChB,CAAC;EACH,CAAC;CACH;;;;;;CAOA,wBAA0C;EACxC,MAAM,kBAAkB,KAAK,OAAO,CAAC,CAAC,QAAQ,MAAM,EAAE,MAAM,QAAQ;EAEpE,OAAOC,sBAAAA,cAAc,YACnB,QAAQ,IACN,gBAAgB,KAAK,aAAa,SAAS,SAAS,CAAC,CAAC,MAAMC,cAAAA,IAAI,CAAC,CACnE,CACF;CACF;AACF;;;;;;AAOA,SAAS,SAAS,UAAwC;;CACxD,QAAA,wBAAO,SAAS,QAAQ,WAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAO;AACjC"}
@@ -1,2 +1,2 @@
1
- import { Gn as MutationCacheConfig, Kn as MutationCacheNotifyEvent, Wn as MutationCache } from "./hydration-Br9VIGXa.cjs";
1
+ import { Gn as MutationCacheConfig, Kn as MutationCacheNotifyEvent, Wn as MutationCache } from "./hydration-Dfuxd5FW.cjs";
2
2
  export { MutationCache, MutationCacheConfig, MutationCacheNotifyEvent };
@@ -1,2 +1,2 @@
1
- import { Gn as MutationCacheConfig, Kn as MutationCacheNotifyEvent, Wn as MutationCache } from "./hydration-B9t5w6NC.js";
1
+ import { Gn as MutationCacheConfig, Kn as MutationCacheNotifyEvent, Wn as MutationCache } from "./hydration-UAqdtMIf.js";
2
2
  export { MutationCache, MutationCacheConfig, MutationCacheNotifyEvent };
@@ -13,7 +13,6 @@ var _mutationId = /* @__PURE__ */ new WeakMap();
13
13
  * Normally, you will not interact with the `MutationCache` directly and instead use a
14
14
  * `QueryClient`. You can subscribe to it (inherited from `Subscribable`) to be informed of
15
15
  * safe/known updates to the cache, such as mutations being added, removed, or updated.
16
- *
17
16
  * @example
18
17
  * ```ts
19
18
  * const unsubscribe = mutationCache.subscribe((event) => {
@@ -32,7 +31,15 @@ var MutationCache = class extends Subscribable {
32
31
  _classPrivateFieldSet2(_scopes, this, /* @__PURE__ */ new Map());
33
32
  _classPrivateFieldSet2(_mutationId, this, 0);
34
33
  }
35
- /** @internal */
34
+ /**
35
+ * Creates a mutation and adds it to the cache.
36
+ * @internal
37
+ * @param client - The client the mutation belongs to, used to default its options.
38
+ * @param options - The mutation options. They are defaulted with {@link
39
+ * QueryClient#defaultMutationOptions}.
40
+ * @param state - The initial state of the mutation, e.g. when restoring a dehydrated mutation.
41
+ * @returns The new mutation, already added to the cache.
42
+ */
36
43
  build(client, options, state) {
37
44
  var _this$mutationId;
38
45
  const mutation = new Mutation({
@@ -45,7 +52,11 @@ var MutationCache = class extends Subscribable {
45
52
  this.add(mutation);
46
53
  return mutation;
47
54
  }
48
- /** @internal */
55
+ /**
56
+ * Adds a mutation to the cache.
57
+ * @internal
58
+ * @param mutation - The mutation to add. If it has a `scope`, it is queued in that scope.
59
+ */
49
60
  add(mutation) {
50
61
  _classPrivateFieldGet2(_mutations, this).add(mutation);
51
62
  const scope = scopeFor(mutation);
@@ -59,7 +70,11 @@ var MutationCache = class extends Subscribable {
59
70
  mutation
60
71
  });
61
72
  }
62
- /** @internal */
73
+ /**
74
+ * Removes a mutation from the cache.
75
+ * @internal
76
+ * @param mutation - The mutation to remove, also from its scope's queue.
77
+ */
63
78
  remove(mutation) {
64
79
  if (_classPrivateFieldGet2(_mutations, this).delete(mutation)) {
65
80
  const scope = scopeFor(mutation);
@@ -78,7 +93,13 @@ var MutationCache = class extends Subscribable {
78
93
  mutation
79
94
  });
80
95
  }
81
- /** @internal */
96
+ /**
97
+ * Checks whether a mutation can run now, given the other mutations in its `scope`.
98
+ * @internal
99
+ * @param mutation - The mutation to check.
100
+ * @returns `true` if the mutation has no `scope`, or no other mutation in its scope is pending
101
+ * ahead of it.
102
+ */
82
103
  canRun(mutation) {
83
104
  const scope = scopeFor(mutation);
84
105
  if (typeof scope === "string") {
@@ -87,7 +108,13 @@ var MutationCache = class extends Subscribable {
87
108
  return !firstPendingMutation || firstPendingMutation === mutation;
88
109
  } else return true;
89
110
  }
90
- /** @internal */
111
+ /**
112
+ * Continues the next paused mutation in the same `scope` after a mutation finishes.
113
+ * @internal
114
+ * @param mutation - The mutation that finished.
115
+ * @returns A promise that resolves once the next paused mutation in the same scope has continued,
116
+ * or immediately if there is none.
117
+ */
91
118
  runNext(mutation) {
92
119
  const scope = scopeFor(mutation);
93
120
  if (typeof scope === "string") {
@@ -98,7 +125,6 @@ var MutationCache = class extends Subscribable {
98
125
  }
99
126
  /**
100
127
  * Removes all mutations from the cache.
101
- *
102
128
  * @example
103
129
  * ```ts
104
130
  * const mutationCache = queryClient.getMutationCache()
@@ -123,7 +149,7 @@ var MutationCache = class extends Subscribable {
123
149
  *
124
150
  * This is not typically needed for most applications, but can come in handy when needing more
125
151
  * information about a mutation in rare scenarios.
126
- *
152
+ * @returns Every mutation in the cache.
127
153
  * @example
128
154
  * ```ts
129
155
  * const mutationCache = queryClient.getMutationCache()
@@ -140,7 +166,8 @@ var MutationCache = class extends Subscribable {
140
166
  *
141
167
  * This is not typically needed for most applications, but can come in handy when needing more
142
168
  * information about a mutation in rare scenarios.
143
- *
169
+ * @param filters - The filters to match. `exact` defaults to `true`.
170
+ * @returns The first matching mutation, or `undefined`.
144
171
  * @see {@link MutationCache#findAll}
145
172
  * @example
146
173
  * ```ts
@@ -162,7 +189,8 @@ var MutationCache = class extends Subscribable {
162
189
  *
163
190
  * This is not typically needed for most applications, but can come in handy when needing more
164
191
  * information about mutations in rare scenarios.
165
- *
192
+ * @param filters - The filters to match. Without filters, every mutation is returned.
193
+ * @returns The matching mutations.
166
194
  * @see {@link MutationCache#find}
167
195
  * @example
168
196
  * ```ts
@@ -174,7 +202,11 @@ var MutationCache = class extends Subscribable {
174
202
  findAll(filters = {}) {
175
203
  return this.getAll().filter((mutation) => matchMutation(filters, mutation));
176
204
  }
177
- /** @internal */
205
+ /**
206
+ * Notifies every cache listener of an event, in one batch.
207
+ * @internal
208
+ * @param event - The event passed to every listener.
209
+ */
178
210
  notify(event) {
179
211
  notifyManager.batch(() => {
180
212
  this.listeners.forEach((listener) => {
@@ -182,12 +214,21 @@ var MutationCache = class extends Subscribable {
182
214
  });
183
215
  });
184
216
  }
185
- /** @internal */
217
+ /**
218
+ * Continues every paused mutation, e.g. when the app comes back online.
219
+ * @internal
220
+ * @returns A promise that resolves once every paused mutation has continued and settled.
221
+ */
186
222
  resumePausedMutations() {
187
223
  const pausedMutations = this.getAll().filter((x) => x.state.isPaused);
188
224
  return notifyManager.batch(() => Promise.all(pausedMutations.map((mutation) => mutation.continue().catch(noop))));
189
225
  }
190
226
  };
227
+ /**
228
+ * Returns the scope id of a mutation, used to run mutations with the same scope one after another.
229
+ * @param mutation - The mutation to read the scope of.
230
+ * @returns The mutation's `scope.id`, or `undefined` if it has no scope.
231
+ */
191
232
  function scopeFor(mutation) {
192
233
  var _mutation$options$sco;
193
234
  return (_mutation$options$sco = mutation.options.scope) === null || _mutation$options$sco === void 0 ? void 0 : _mutation$options$sco.id;
@@ -1 +1 @@
1
- {"version":3,"file":"mutationCache.js","names":[],"sources":["../../src/mutationCache.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Mutation } from './mutation'\nimport { matchMutation, noop } from './utils'\nimport { Subscribable } from './subscribable'\nimport type { MutationObserver } from './mutationObserver'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationOptions,\n NotifyEvent,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Action, MutationState } from './mutation'\nimport type { MutationFilters } from './utils'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every mutation handled by a `MutationCache`, regardless of which\n * component or observer triggered it. They differ from the `defaultOptions` provided to a\n * `QueryClient` in two ways: `defaultOptions` can be overridden by each mutation, while these\n * callbacks are always called, and `onMutate` here does not allow returning a result.\n *\n * If a callback returns a promise, it will be awaited before the mutation continues.\n */\nexport interface MutationCacheConfig {\n /** Called when any mutation in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n /** Called when any mutation in the cache is successful. */\n onSuccess?: (\n data: unknown,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n /** Called before any mutation in the cache executes. */\n onMutate?: (\n variables: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n /** Called when any mutation in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n}\n\ninterface NotifyEventMutationAdded extends NotifyEvent {\n type: 'added'\n mutation: Mutation<any, any, any, any>\n}\ninterface NotifyEventMutationRemoved extends NotifyEvent {\n type: 'removed'\n mutation: Mutation<any, any, any, any>\n}\n\ninterface NotifyEventMutationObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n mutation?: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any, any>\n}\n\ninterface NotifyEventMutationUpdated extends NotifyEvent {\n type: 'updated'\n mutation: Mutation<any, any, any, any>\n action: Action<any, any, any, any>\n}\n\n/**\n * The event passed to a `MutationCache` subscriber. Fired whenever a mutation is added or removed\n * from the cache, its state is updated, or one of its observers is added, removed, or has its\n * options updated.\n */\nexport type MutationCacheNotifyEvent =\n | NotifyEventMutationAdded\n | NotifyEventMutationRemoved\n | NotifyEventMutationObserverAdded\n | NotifyEventMutationObserverRemoved\n | NotifyEventMutationObserverOptionsUpdated\n | NotifyEventMutationUpdated\n\ntype MutationCacheListener = (event: MutationCacheNotifyEvent) => void\n\n// CLASS\n\n/**\n * The `MutationCache` is the storage for mutations.\n *\n * Normally, you will not interact with the `MutationCache` directly and instead use a\n * `QueryClient`. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as mutations being added, removed, or updated.\n *\n * @example\n * ```ts\n * const unsubscribe = mutationCache.subscribe((event) => {\n * console.log(event.type, event.mutation)\n * })\n * ```\n */\nexport class MutationCache extends Subscribable<MutationCacheListener> {\n #mutations: Set<Mutation<any, any, any, any>>\n #scopes: Map<string, Array<Mutation<any, any, any, any>>>\n #mutationId: number\n\n constructor(public config: MutationCacheConfig = {}) {\n super()\n this.#mutations = new Set()\n this.#scopes = new Map()\n this.#mutationId = 0\n }\n\n /** @internal */\n build<TData, TError, TVariables, TOnMutateResult>(\n client: QueryClient,\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> {\n const mutation = new Mutation({\n client,\n mutationCache: this,\n mutationId: ++this.#mutationId,\n options: client.defaultMutationOptions(options),\n state,\n })\n\n this.add(mutation)\n\n return mutation\n }\n\n /** @internal */\n add(mutation: Mutation<any, any, any, any>): void {\n this.#mutations.add(mutation)\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n scopedMutations.push(mutation)\n } else {\n this.#scopes.set(scope, [mutation])\n }\n }\n this.notify({ type: 'added', mutation })\n }\n\n /** @internal */\n remove(mutation: Mutation<any, any, any, any>): void {\n if (this.#mutations.delete(mutation)) {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n if (scopedMutations.length > 1) {\n const index = scopedMutations.indexOf(mutation)\n if (index !== -1) {\n scopedMutations.splice(index, 1)\n }\n } else if (scopedMutations[0] === mutation) {\n this.#scopes.delete(scope)\n }\n }\n }\n }\n\n // Currently we notify the removal even if the mutation was already removed.\n // Consider making this an error or not notifying of the removal depending on the desired semantics.\n this.notify({ type: 'removed', mutation })\n }\n\n /** @internal */\n canRun(mutation: Mutation<any, any, any, any>): boolean {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const mutationsWithSameScope = this.#scopes.get(scope)\n const firstPendingMutation = mutationsWithSameScope?.find(\n (m) => m.state.status === 'pending',\n )\n // we can run if there is no current pending mutation (start use-case)\n // or if WE are the first pending mutation (continue use-case)\n return !firstPendingMutation || firstPendingMutation === mutation\n } else {\n // For unscoped mutations there are never any pending mutations in front of the\n // current mutation\n return true\n }\n }\n\n /** @internal */\n runNext(mutation: Mutation<any, any, any, any>): Promise<unknown> {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const foundMutation = this.#scopes\n .get(scope)\n ?.find((m) => m !== mutation && m.state.isPaused)\n\n return foundMutation?.continue() ?? Promise.resolve()\n } else {\n return Promise.resolve()\n }\n }\n\n /**\n * Removes all mutations from the cache.\n *\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * mutationCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.#mutations.forEach((mutation) => {\n this.notify({ type: 'removed', mutation })\n })\n this.#mutations.clear()\n this.#scopes.clear()\n })\n }\n\n /**\n * Returns all mutations within the cache.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a mutation in rare scenarios.\n *\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutations = mutationCache.getAll()\n * ```\n */\n getAll(): Array<Mutation> {\n return Array.from(this.#mutations)\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing mutation instance from\n * the cache. If the mutation does not exist, `undefined` is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a mutation in rare scenarios.\n *\n * @see {@link MutationCache#findAll}\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutation = mutationCache.find({ mutationKey: ['addPost'] })\n * ```\n */\n find<\n TData = unknown,\n TError = DefaultError,\n TVariables = any,\n TOnMutateResult = unknown,\n >(\n filters: MutationFilters,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((mutation) =>\n matchMutation(defaultedFilters, mutation),\n ) as Mutation<TData, TError, TVariables, TOnMutateResult> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing mutation instances from the\n * cache that match the given filters. If no mutations match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about mutations in rare scenarios.\n *\n * @see {@link MutationCache#find}\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutations = mutationCache.findAll({ mutationKey: ['addPost'] })\n * ```\n */\n findAll(filters: MutationFilters = {}): Array<Mutation> {\n return this.getAll().filter((mutation) => matchMutation(filters, mutation))\n }\n\n /** @internal */\n notify(event: MutationCacheNotifyEvent) {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /** @internal */\n resumePausedMutations(): Promise<unknown> {\n const pausedMutations = this.getAll().filter((x) => x.state.isPaused)\n\n return notifyManager.batch(() =>\n Promise.all(\n pausedMutations.map((mutation) => mutation.continue().catch(noop)),\n ),\n )\n }\n}\n\nfunction scopeFor(mutation: Mutation<any, any, any, any>) {\n return mutation.options.scope?.id\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA2HA,IAAa,gBAAb,cAAmC,aAAoC;CAKrE,YAAY,SAAqC,CAAC,GAAG;EACnD,MAAM;EADW,KAAA,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kB,QAAQ,CAC1C;CACF;;;;;;;;;;;;;;;;CAiBA,QAAQ,UAA2B,CAAC,GAAoB;EACtD,OAAO,KAAK,OAAO,CAAC,CAAC,QAAQ,aAAa,cAAc,SAAS,QAAQ,CAAC;CAC5E;;CAGA,OAAO,OAAiC;EACtC,cAAc,YAAY;GACxB,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,KAAK;GAChB,CAAC;EACH,CAAC;CACH;;CAGA,wBAA0C;EACxC,MAAM,kBAAkB,KAAK,OAAO,CAAC,CAAC,QAAQ,MAAM,EAAE,MAAM,QAAQ;EAEpE,OAAO,cAAc,YACnB,QAAQ,IACN,gBAAgB,KAAK,aAAa,SAAS,SAAS,CAAC,CAAC,MAAM,IAAI,CAAC,CACnE,CACF;CACF;AACF;AAEA,SAAS,SAAS,UAAwC;;CACxD,QAAA,wBAAO,SAAS,QAAQ,WAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAO;AACjC"}
1
+ {"version":3,"file":"mutationCache.js","names":[],"sources":["../../src/mutationCache.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Mutation } from './mutation'\nimport { matchMutation, noop } from './utils'\nimport { Subscribable } from './subscribable'\nimport type { MutationObserver } from './mutationObserver'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationOptions,\n NotifyEvent,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Action, MutationState } from './mutation'\nimport type { MutationFilters } from './utils'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every mutation handled by a `MutationCache`, regardless of which\n * component or observer triggered it. They differ from the `defaultOptions` provided to a\n * `QueryClient` in two ways: `defaultOptions` can be overridden by each mutation, while these\n * callbacks are always called, and `onMutate` here does not allow returning a result.\n *\n * If a callback returns a promise, it will be awaited before the mutation continues.\n */\nexport interface MutationCacheConfig {\n /** Called when any mutation in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n /** Called when any mutation in the cache is successful. */\n onSuccess?: (\n data: unknown,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n /** Called before any mutation in the cache executes. */\n onMutate?: (\n variables: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n /** Called when any mutation in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n}\n\ninterface NotifyEventMutationAdded extends NotifyEvent {\n type: 'added'\n mutation: Mutation<any, any, any, any>\n}\ninterface NotifyEventMutationRemoved extends NotifyEvent {\n type: 'removed'\n mutation: Mutation<any, any, any, any>\n}\n\ninterface NotifyEventMutationObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n mutation?: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any, any>\n}\n\ninterface NotifyEventMutationUpdated extends NotifyEvent {\n type: 'updated'\n mutation: Mutation<any, any, any, any>\n action: Action<any, any, any, any>\n}\n\n/**\n * The event passed to a `MutationCache` subscriber. Fired whenever a mutation is added or removed\n * from the cache, its state is updated, or one of its observers is added, removed, or has its\n * options updated.\n */\nexport type MutationCacheNotifyEvent =\n | NotifyEventMutationAdded\n | NotifyEventMutationRemoved\n | NotifyEventMutationObserverAdded\n | NotifyEventMutationObserverRemoved\n | NotifyEventMutationObserverOptionsUpdated\n | NotifyEventMutationUpdated\n\ntype MutationCacheListener = (event: MutationCacheNotifyEvent) => void\n\n// CLASS\n\n/**\n * The `MutationCache` is the storage for mutations.\n *\n * Normally, you will not interact with the `MutationCache` directly and instead use a\n * `QueryClient`. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as mutations being added, removed, or updated.\n * @example\n * ```ts\n * const unsubscribe = mutationCache.subscribe((event) => {\n * console.log(event.type, event.mutation)\n * })\n * ```\n */\nexport class MutationCache extends Subscribable<MutationCacheListener> {\n #mutations: Set<Mutation<any, any, any, any>>\n #scopes: Map<string, Array<Mutation<any, any, any, any>>>\n #mutationId: number\n\n constructor(public config: MutationCacheConfig = {}) {\n super()\n this.#mutations = new Set()\n this.#scopes = new Map()\n this.#mutationId = 0\n }\n\n /**\n * Creates a mutation and adds it to the cache.\n * @internal\n * @param client - The client the mutation belongs to, used to default its options.\n * @param options - The mutation options. They are defaulted with {@link\n * QueryClient#defaultMutationOptions}.\n * @param state - The initial state of the mutation, e.g. when restoring a dehydrated mutation.\n * @returns The new mutation, already added to the cache.\n */\n build<TData, TError, TVariables, TOnMutateResult>(\n client: QueryClient,\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> {\n const mutation = new Mutation({\n client,\n mutationCache: this,\n mutationId: ++this.#mutationId,\n options: client.defaultMutationOptions(options),\n state,\n })\n\n this.add(mutation)\n\n return mutation\n }\n\n /**\n * Adds a mutation to the cache.\n * @internal\n * @param mutation - The mutation to add. If it has a `scope`, it is queued in that scope.\n */\n add(mutation: Mutation<any, any, any, any>): void {\n this.#mutations.add(mutation)\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n scopedMutations.push(mutation)\n } else {\n this.#scopes.set(scope, [mutation])\n }\n }\n this.notify({ type: 'added', mutation })\n }\n\n /**\n * Removes a mutation from the cache.\n * @internal\n * @param mutation - The mutation to remove, also from its scope's queue.\n */\n remove(mutation: Mutation<any, any, any, any>): void {\n if (this.#mutations.delete(mutation)) {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n if (scopedMutations.length > 1) {\n const index = scopedMutations.indexOf(mutation)\n if (index !== -1) {\n scopedMutations.splice(index, 1)\n }\n } else if (scopedMutations[0] === mutation) {\n this.#scopes.delete(scope)\n }\n }\n }\n }\n\n // Currently we notify the removal even if the mutation was already removed.\n // Consider making this an error or not notifying of the removal depending on the desired semantics.\n this.notify({ type: 'removed', mutation })\n }\n\n /**\n * Checks whether a mutation can run now, given the other mutations in its `scope`.\n * @internal\n * @param mutation - The mutation to check.\n * @returns `true` if the mutation has no `scope`, or no other mutation in its scope is pending\n * ahead of it.\n */\n canRun(mutation: Mutation<any, any, any, any>): boolean {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const mutationsWithSameScope = this.#scopes.get(scope)\n const firstPendingMutation = mutationsWithSameScope?.find(\n (m) => m.state.status === 'pending',\n )\n // we can run if there is no current pending mutation (start use-case)\n // or if WE are the first pending mutation (continue use-case)\n return !firstPendingMutation || firstPendingMutation === mutation\n } else {\n // For unscoped mutations there are never any pending mutations in front of the\n // current mutation\n return true\n }\n }\n\n /**\n * Continues the next paused mutation in the same `scope` after a mutation finishes.\n * @internal\n * @param mutation - The mutation that finished.\n * @returns A promise that resolves once the next paused mutation in the same scope has continued,\n * or immediately if there is none.\n */\n runNext(mutation: Mutation<any, any, any, any>): Promise<unknown> {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const foundMutation = this.#scopes\n .get(scope)\n ?.find((m) => m !== mutation && m.state.isPaused)\n\n return foundMutation?.continue() ?? Promise.resolve()\n } else {\n return Promise.resolve()\n }\n }\n\n /**\n * Removes all mutations from the cache.\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * mutationCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.#mutations.forEach((mutation) => {\n this.notify({ type: 'removed', mutation })\n })\n this.#mutations.clear()\n this.#scopes.clear()\n })\n }\n\n /**\n * Returns all mutations within the cache.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a mutation in rare scenarios.\n * @returns Every mutation in the cache.\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutations = mutationCache.getAll()\n * ```\n */\n getAll(): Array<Mutation> {\n return Array.from(this.#mutations)\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing mutation instance from\n * the cache. If the mutation does not exist, `undefined` is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a mutation in rare scenarios.\n * @param filters - The filters to match. `exact` defaults to `true`.\n * @returns The first matching mutation, or `undefined`.\n * @see {@link MutationCache#findAll}\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutation = mutationCache.find({ mutationKey: ['addPost'] })\n * ```\n */\n find<\n TData = unknown,\n TError = DefaultError,\n TVariables = any,\n TOnMutateResult = unknown,\n >(\n filters: MutationFilters,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((mutation) =>\n matchMutation(defaultedFilters, mutation),\n ) as Mutation<TData, TError, TVariables, TOnMutateResult> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing mutation instances from the\n * cache that match the given filters. If no mutations match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about mutations in rare scenarios.\n * @param filters - The filters to match. Without filters, every mutation is returned.\n * @returns The matching mutations.\n * @see {@link MutationCache#find}\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutations = mutationCache.findAll({ mutationKey: ['addPost'] })\n * ```\n */\n findAll(filters: MutationFilters = {}): Array<Mutation> {\n return this.getAll().filter((mutation) => matchMutation(filters, mutation))\n }\n\n /**\n * Notifies every cache listener of an event, in one batch.\n * @internal\n * @param event - The event passed to every listener.\n */\n notify(event: MutationCacheNotifyEvent) {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /**\n * Continues every paused mutation, e.g. when the app comes back online.\n * @internal\n * @returns A promise that resolves once every paused mutation has continued and settled.\n */\n resumePausedMutations(): Promise<unknown> {\n const pausedMutations = this.getAll().filter((x) => x.state.isPaused)\n\n return notifyManager.batch(() =>\n Promise.all(\n pausedMutations.map((mutation) => mutation.continue().catch(noop)),\n ),\n )\n }\n}\n\n/**\n * Returns the scope id of a mutation, used to run mutations with the same scope one after another.\n * @param mutation - The mutation to read the scope of.\n * @returns The mutation's `scope.id`, or `undefined` if it has no scope.\n */\nfunction scopeFor(mutation: Mutation<any, any, any, any>) {\n return mutation.options.scope?.id\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0HA,IAAa,gBAAb,cAAmC,aAAoC;CAKrE,YAAY,SAAqC,CAAC,GAAG;EACnD,MAAM;EADW,KAAA,SAAA;;;;EAEjB,uBAAA,YAAA,sBAAkB,IAAI,IAAI,CAAA;EAC1B,uBAAA,SAAA,sBAAe,IAAI,IAAI,CAAA;EACvB,uBAAA,aAAA,MAAmB,CAAA;CACrB;;;;;;;;;;CAWA,MACE,QACA,SACA,OACsD;;EACtD,MAAM,WAAW,IAAI,SAAS;GAC5B;GACA,eAAe;GACf,YAAA,uBAAA,aAAc,OAAA,mBAAA,uBAAA,aAAA,IAAA,GAAA,EAAA,iBAAA;GACd,SAAS,OAAO,uBAAuB,OAAO;GAC9C;EACF,CAAC;EAED,KAAK,IAAI,QAAQ;EAEjB,OAAO;CACT;;;;;;CAOA,IAAI,UAA8C;EAChD,uBAAA,YAAA,IAAA,CAAA,CAAgB,IAAI,QAAQ;EAC5B,MAAM,QAAQ,SAAS,QAAQ;EAC/B,IAAI,OAAO,UAAU,UAAU;GAC7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AS,SAAS,UAAwC;;CACxD,QAAA,wBAAO,SAAS,QAAQ,WAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAO;AACjC"}
@@ -18,7 +18,6 @@ var _MutationObserver_brand = /* @__PURE__ */ new WeakSet();
18
18
  * passed to the hook change, subscribes to it to re-render on updates, and
19
19
  * reads `getCurrentResult()` for the value to return. Calling `mutate()`
20
20
  * builds a new underlying `Mutation` in the `MutationCache` and executes it.
21
- *
22
21
  * @example
23
22
  * ```ts
24
23
  * const observer = new MutationObserver(queryClient, {
@@ -39,6 +38,10 @@ var MutationObserver = class extends require_subscribable.Subscribable {
39
38
  this.bindMethods();
40
39
  require_classPrivateFieldSet2._assertClassBrand(_MutationObserver_brand, this, _updateResult).call(this);
41
40
  }
41
+ /**
42
+ * Binds the methods of the result (`mutate` and `reset`) to the observer, so they keep working when
43
+ * destructured from it.
44
+ */
42
45
  bindMethods() {
43
46
  this.mutate = this.mutate.bind(this);
44
47
  this.reset = this.reset.bind(this);
@@ -50,7 +53,8 @@ var MutationObserver = class extends require_subscribable.Subscribable {
50
53
  * defined), the observer is reset, detaching it from the mutation it was
51
54
  * observing. Otherwise, if the currently observed mutation is still
52
55
  * `pending`, its options are updated in place as well.
53
- *
56
+ * @param options - The new mutation observer options. They are defaulted with {@link
57
+ * QueryClient#defaultMutationOptions} before being applied.
54
58
  * @example
55
59
  * ```ts
56
60
  * observer.setOptions({
@@ -83,7 +87,12 @@ var MutationObserver = class extends require_subscribable.Subscribable {
83
87
  (_classPrivateFieldGet3 = require_classPrivateFieldSet2._classPrivateFieldGet2(_currentMutation, this)) === null || _classPrivateFieldGet3 === void 0 || _classPrivateFieldGet3.removeObserver(this);
84
88
  }
85
89
  }
86
- /** @internal */
90
+ /**
91
+ * Updates the observer's result when the observed mutation changes, and notifies its listeners.
92
+ * @internal
93
+ * @param action - The action that updated the observed mutation, passed on to the observer's
94
+ * callbacks.
95
+ */
87
96
  onMutationUpdate(action) {
88
97
  require_classPrivateFieldSet2._assertClassBrand(_MutationObserver_brand, this, _updateResult).call(this);
89
98
  require_classPrivateFieldSet2._assertClassBrand(_MutationObserver_brand, this, _notify).call(this, action);
@@ -92,6 +101,7 @@ var MutationObserver = class extends require_subscribable.Subscribable {
92
101
  * Returns the observer's current result, derived from the observed
93
102
  * mutation's state (or the default, `idle` state if no mutation has been
94
103
  * built yet, e.g. before the first `mutate()` call or after `reset()`).
104
+ * @returns The observer's latest result.
95
105
  */
96
106
  getCurrentResult() {
97
107
  return require_classPrivateFieldSet2._classPrivateFieldGet2(_currentResult, this);
@@ -104,13 +114,11 @@ var MutationObserver = class extends require_subscribable.Subscribable {
104
114
  * running to completion and its own callbacks still fire, but this
105
115
  * observer stops reflecting its state and a subsequent `mutate()` call
106
116
  * will build a brand new mutation.
107
- *
117
+ * @see {@link MutationObserver#mutate}
108
118
  * @example
109
119
  * ```ts
110
120
  * observer.reset()
111
121
  * ```
112
- *
113
- * @see {@link MutationObserver#mutate}
114
122
  */
115
123
  reset() {
116
124
  var _classPrivateFieldGet4;
@@ -128,7 +136,9 @@ var MutationObserver = class extends require_subscribable.Subscribable {
128
136
  * The optional per-call `options` (`onSuccess`/`onError`/`onSettled`) are
129
137
  * invoked once the mutation settles, in addition to any callbacks defined
130
138
  * on the observer's own options.
131
- *
139
+ * @param variables - The variables passed to the `mutationFn`.
140
+ * @param options - Per-call `onSuccess`, `onError`, and `onSettled` callbacks.
141
+ * @returns A promise that resolves with the mutation's data, or rejects with its error.
132
142
  * @example
133
143
  * ```ts
134
144
  * await observer.mutate(
@@ -161,7 +171,8 @@ function _updateResult() {
161
171
  }
162
172
  function _notify(action) {
163
173
  require_notifyManager.notifyManager.batch(() => {
164
- if (require_classPrivateFieldSet2._classPrivateFieldGet2(_mutateOptions, this) && this.hasListeners()) {
174
+ const mutateOptions = require_classPrivateFieldSet2._classPrivateFieldGet2(_mutateOptions, this);
175
+ if (mutateOptions && this.hasListeners()) {
165
176
  const variables = require_classPrivateFieldSet2._classPrivateFieldGet2(_currentResult, this).variables;
166
177
  const onMutateResult = require_classPrivateFieldSet2._classPrivateFieldGet2(_currentResult, this).context;
167
178
  const context = {
@@ -171,27 +182,27 @@ function _notify(action) {
171
182
  };
172
183
  if ((action === null || action === void 0 ? void 0 : action.type) === "success") {
173
184
  try {
174
- var _classPrivateFieldGet7, _classPrivateFieldGet8;
175
- (_classPrivateFieldGet7 = (_classPrivateFieldGet8 = require_classPrivateFieldSet2._classPrivateFieldGet2(_mutateOptions, this)).onSuccess) === null || _classPrivateFieldGet7 === void 0 || _classPrivateFieldGet7.call(_classPrivateFieldGet8, action.data, variables, onMutateResult, context);
185
+ var _mutateOptions$onSucc;
186
+ (_mutateOptions$onSucc = mutateOptions.onSuccess) === null || _mutateOptions$onSucc === void 0 || _mutateOptions$onSucc.call(mutateOptions, action.data, variables, onMutateResult, context);
176
187
  } catch (e) {
177
188
  Promise.reject(e);
178
189
  }
179
190
  try {
180
- var _classPrivateFieldGet9, _classPrivateFieldGet10;
181
- (_classPrivateFieldGet9 = (_classPrivateFieldGet10 = require_classPrivateFieldSet2._classPrivateFieldGet2(_mutateOptions, this)).onSettled) === null || _classPrivateFieldGet9 === void 0 || _classPrivateFieldGet9.call(_classPrivateFieldGet10, action.data, null, variables, onMutateResult, context);
191
+ var _mutateOptions$onSett;
192
+ (_mutateOptions$onSett = mutateOptions.onSettled) === null || _mutateOptions$onSett === void 0 || _mutateOptions$onSett.call(mutateOptions, action.data, null, variables, onMutateResult, context);
182
193
  } catch (e) {
183
194
  Promise.reject(e);
184
195
  }
185
196
  } else if ((action === null || action === void 0 ? void 0 : action.type) === "error") {
186
197
  try {
187
- var _classPrivateFieldGet11, _classPrivateFieldGet12;
188
- (_classPrivateFieldGet11 = (_classPrivateFieldGet12 = require_classPrivateFieldSet2._classPrivateFieldGet2(_mutateOptions, this)).onError) === null || _classPrivateFieldGet11 === void 0 || _classPrivateFieldGet11.call(_classPrivateFieldGet12, action.error, variables, onMutateResult, context);
198
+ var _mutateOptions$onErro;
199
+ (_mutateOptions$onErro = mutateOptions.onError) === null || _mutateOptions$onErro === void 0 || _mutateOptions$onErro.call(mutateOptions, action.error, variables, onMutateResult, context);
189
200
  } catch (e) {
190
201
  Promise.reject(e);
191
202
  }
192
203
  try {
193
- var _classPrivateFieldGet13, _classPrivateFieldGet14;
194
- (_classPrivateFieldGet13 = (_classPrivateFieldGet14 = require_classPrivateFieldSet2._classPrivateFieldGet2(_mutateOptions, this)).onSettled) === null || _classPrivateFieldGet13 === void 0 || _classPrivateFieldGet13.call(_classPrivateFieldGet14, void 0, action.error, variables, onMutateResult, context);
204
+ var _mutateOptions$onSett2;
205
+ (_mutateOptions$onSett2 = mutateOptions.onSettled) === null || _mutateOptions$onSett2 === void 0 || _mutateOptions$onSett2.call(mutateOptions, void 0, action.error, variables, onMutateResult, context);
195
206
  } catch (e) {
196
207
  Promise.reject(e);
197
208
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mutationObserver.cjs","names":["Subscribable","shallowEqualObjects","hashKey","getDefaultState"],"sources":["../../src/mutationObserver.ts"],"sourcesContent":["import { getDefaultState } from './mutation'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport { hashKey, shallowEqualObjects } from './utils'\nimport type { QueryClient } from './queryClient'\nimport type {\n DefaultError,\n MutateOptions,\n MutationFunctionContext,\n MutationObserverOptions,\n MutationObserverResult,\n} from './types'\nimport type { Action, Mutation } from './mutation'\n\n// TYPES\n\ntype MutationObserverListener<TData, TError, TVariables, TOnMutateResult> = (\n result: MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n) => void\n\n// CLASS\n\n/**\n * Observes a single mutation and derives a `MutationObserverResult` from it.\n * A framework hook like `useMutation` creates one `MutationObserver` per hook\n * call, keeps it stable across re-renders, calls `setOptions` when the options\n * passed to the hook change, subscribes to it to re-render on updates, and\n * reads `getCurrentResult()` for the value to return. Calling `mutate()`\n * builds a new underlying `Mutation` in the `MutationCache` and executes it.\n *\n * @example\n * ```ts\n * const observer = new MutationObserver(queryClient, {\n * mutationFn: (variables: { title: string }) => addPost(variables),\n * })\n * ```\n */\nexport class MutationObserver<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> extends Subscribable<\n MutationObserverListener<TData, TError, TVariables, TOnMutateResult>\n> {\n options!: MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n\n #client: QueryClient\n #currentResult: MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > = undefined!\n #currentMutation?: Mutation<TData, TError, TVariables, TOnMutateResult>\n #mutateOptions?: MutateOptions<TData, TError, TVariables, TOnMutateResult>\n\n constructor(\n client: QueryClient,\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n super()\n\n this.#client = client\n this.setOptions(options)\n this.bindMethods()\n this.#updateResult()\n }\n\n protected bindMethods(): void {\n this.mutate = this.mutate.bind(this)\n this.reset = this.reset.bind(this)\n }\n\n /**\n * Updates the observer's options.\n *\n * If the new `mutationKey` differs from the previous one (and both were\n * defined), the observer is reset, detaching it from the mutation it was\n * observing. Otherwise, if the currently observed mutation is still\n * `pending`, its options are updated in place as well.\n *\n * @example\n * ```ts\n * observer.setOptions({\n * mutationFn: (variables: { title: string }) => addPost(variables),\n * onSuccess: (data) => console.log(data),\n * })\n * ```\n */\n setOptions(\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n const prevOptions = this.options as\n | MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n | undefined\n this.options = this.#client.defaultMutationOptions(options)\n if (!shallowEqualObjects(this.options, prevOptions)) {\n this.#client.getMutationCache().notify({\n type: 'observerOptionsUpdated',\n mutation: this.#currentMutation,\n observer: this,\n })\n }\n\n if (\n prevOptions?.mutationKey &&\n this.options.mutationKey &&\n hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey)\n ) {\n this.reset()\n } else if (this.#currentMutation?.state.status === 'pending') {\n this.#currentMutation.setOptions(this.options)\n }\n }\n\n protected onSubscribe(): void {\n if (this.listeners.size === 1 && this.#currentMutation) {\n this.#currentMutation.addObserver(this)\n\n this.#updateResult()\n }\n }\n\n protected onUnsubscribe(): void {\n if (!this.hasListeners()) {\n this.#currentMutation?.removeObserver(this)\n }\n }\n\n /** @internal */\n onMutationUpdate(\n action: Action<TData, TError, TVariables, TOnMutateResult>,\n ): void {\n this.#updateResult()\n\n this.#notify(action)\n }\n\n /**\n * Returns the observer's current result, derived from the observed\n * mutation's state (or the default, `idle` state if no mutation has been\n * built yet, e.g. before the first `mutate()` call or after `reset()`).\n */\n getCurrentResult(): MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > {\n return this.#currentResult\n }\n\n /**\n * Detaches the observer from the mutation it is currently observing (if\n * any) and resets the observed result back to its default, `idle` state.\n *\n * This does not cancel an in-flight mutation; the mutation itself keeps\n * running to completion and its own callbacks still fire, but this\n * observer stops reflecting its state and a subsequent `mutate()` call\n * will build a brand new mutation.\n *\n * @example\n * ```ts\n * observer.reset()\n * ```\n *\n * @see {@link MutationObserver#mutate}\n */\n reset(): void {\n // reset needs to remove the observer from the mutation because there is no way to \"get it back\"\n // another mutate call will yield a new mutation!\n this.#currentMutation?.removeObserver(this)\n this.#currentMutation = undefined\n this.#updateResult()\n this.#notify()\n }\n\n /**\n * Builds a new `Mutation` in the `MutationCache` using the observer's\n * current options, detaches this observer from any previously observed\n * mutation, attaches it to the new one, and executes it with the given\n * variables.\n *\n * The optional per-call `options` (`onSuccess`/`onError`/`onSettled`) are\n * invoked once the mutation settles, in addition to any callbacks defined\n * on the observer's own options.\n *\n * @example\n * ```ts\n * await observer.mutate(\n * { title: 'New post' },\n * { onSuccess: (data) => console.log(data) },\n * )\n * ```\n */\n mutate(\n variables: TVariables,\n options?: MutateOptions<TData, TError, TVariables, TOnMutateResult>,\n ): Promise<TData> {\n this.#mutateOptions = options\n\n this.#currentMutation?.removeObserver(this)\n\n this.#currentMutation = this.#client\n .getMutationCache()\n .build(this.#client, this.options)\n\n this.#currentMutation.addObserver(this)\n\n return this.#currentMutation.execute(variables)\n }\n\n #updateResult(): void {\n const state =\n this.#currentMutation?.state ??\n getDefaultState<TData, TError, TVariables, TOnMutateResult>()\n\n this.#currentResult = {\n ...state,\n isPending: state.status === 'pending',\n isSuccess: state.status === 'success',\n isError: state.status === 'error',\n isIdle: state.status === 'idle',\n mutate: this.mutate,\n reset: this.reset,\n } as MutationObserverResult<TData, TError, TVariables, TOnMutateResult>\n }\n\n #notify(action?: Action<TData, TError, TVariables, TOnMutateResult>): void {\n notifyManager.batch(() => {\n // First trigger the mutate callbacks\n if (this.#mutateOptions && this.hasListeners()) {\n const variables = this.#currentResult.variables!\n const onMutateResult = this.#currentResult.context\n\n const context = {\n client: this.#client,\n meta: this.options.meta,\n mutationKey: this.options.mutationKey,\n } satisfies MutationFunctionContext\n\n if (action?.type === 'success') {\n try {\n this.#mutateOptions.onSuccess?.(\n action.data,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n this.#mutateOptions.onSettled?.(\n action.data,\n null,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n } else if (action?.type === 'error') {\n try {\n this.#mutateOptions.onError?.(\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n this.#mutateOptions.onSettled?.(\n undefined,\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n }\n }\n\n // Then trigger the listeners\n this.listeners.forEach((listener) => {\n listener(this.#currentResult)\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAa,mBAAb,cAKUA,qBAAAA,aAER;CAaA,YACE,QACA,SAMA;EACA,MAAM;;;EAbJ,8BAAA,2BAAA,MAAA,gBAAA,KAAA,CAAA;;;EAeF,8BAAA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AAA,KAAA,wBAAA,KAAA,yBAClB,OAAO,OACP,WACA,gBACA,OACF;IACF,SAAS,GAAG;KACV,QAAa,OAAO,CAAC;IACvB;IACA,IAAI;;KACF,CAAA,2BAAA,0BAAA,8BAAA,uBAAA,gBAAA,IAAA,EAAA,CAAoB,eAAA,QAAA,4BAAA,KAAA,KAAA,wBAAA,KAAA,yBAClB,KAAA,GACA,OAAO,OACP,WACA,gBACA,OACF;IACF,SAAS,GAAG;KACV,QAAa,OAAO,CAAC;IACvB;GACF;EACF;EAGA,KAAK,UAAU,SAAS,aAAa;GACnC,SAAA,8BAAA,uBAAA,gBAAS,IAAA,CAAmB;EAC9B,CAAC;CACH,CAAC;AACH"}
1
+ {"version":3,"file":"mutationObserver.cjs","names":["Subscribable","shallowEqualObjects","hashKey","getDefaultState"],"sources":["../../src/mutationObserver.ts"],"sourcesContent":["import { getDefaultState } from './mutation'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport { hashKey, shallowEqualObjects } from './utils'\nimport type { QueryClient } from './queryClient'\nimport type {\n DefaultError,\n MutateOptions,\n MutationFunctionContext,\n MutationObserverOptions,\n MutationObserverResult,\n} from './types'\nimport type { Action, Mutation } from './mutation'\n\n// TYPES\n\ntype MutationObserverListener<TData, TError, TVariables, TOnMutateResult> = (\n result: MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n) => void\n\n// CLASS\n\n/**\n * Observes a single mutation and derives a `MutationObserverResult` from it.\n * A framework hook like `useMutation` creates one `MutationObserver` per hook\n * call, keeps it stable across re-renders, calls `setOptions` when the options\n * passed to the hook change, subscribes to it to re-render on updates, and\n * reads `getCurrentResult()` for the value to return. Calling `mutate()`\n * builds a new underlying `Mutation` in the `MutationCache` and executes it.\n * @example\n * ```ts\n * const observer = new MutationObserver(queryClient, {\n * mutationFn: (variables: { title: string }) => addPost(variables),\n * })\n * ```\n */\nexport class MutationObserver<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> extends Subscribable<\n MutationObserverListener<TData, TError, TVariables, TOnMutateResult>\n> {\n options!: MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n\n #client: QueryClient\n #currentResult: MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > = undefined!\n #currentMutation?: Mutation<TData, TError, TVariables, TOnMutateResult>\n #mutateOptions?: MutateOptions<TData, TError, TVariables, TOnMutateResult>\n\n constructor(\n client: QueryClient,\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n super()\n\n this.#client = client\n this.setOptions(options)\n this.bindMethods()\n this.#updateResult()\n }\n\n /**\n * Binds the methods of the result (`mutate` and `reset`) to the observer, so they keep working when\n * destructured from it.\n */\n protected bindMethods(): void {\n this.mutate = this.mutate.bind(this)\n this.reset = this.reset.bind(this)\n }\n\n /**\n * Updates the observer's options.\n *\n * If the new `mutationKey` differs from the previous one (and both were\n * defined), the observer is reset, detaching it from the mutation it was\n * observing. Otherwise, if the currently observed mutation is still\n * `pending`, its options are updated in place as well.\n * @param options - The new mutation observer options. They are defaulted with {@link\n * QueryClient#defaultMutationOptions} before being applied.\n * @example\n * ```ts\n * observer.setOptions({\n * mutationFn: (variables: { title: string }) => addPost(variables),\n * onSuccess: (data) => console.log(data),\n * })\n * ```\n */\n setOptions(\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n const prevOptions = this.options as\n | MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n | undefined\n this.options = this.#client.defaultMutationOptions(options)\n if (!shallowEqualObjects(this.options, prevOptions)) {\n this.#client.getMutationCache().notify({\n type: 'observerOptionsUpdated',\n mutation: this.#currentMutation,\n observer: this,\n })\n }\n\n if (\n prevOptions?.mutationKey &&\n this.options.mutationKey &&\n hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey)\n ) {\n this.reset()\n } else if (this.#currentMutation?.state.status === 'pending') {\n this.#currentMutation.setOptions(this.options)\n }\n }\n\n protected override onSubscribe(): void {\n if (this.listeners.size === 1 && this.#currentMutation) {\n this.#currentMutation.addObserver(this)\n\n this.#updateResult()\n }\n }\n\n protected override onUnsubscribe(): void {\n if (!this.hasListeners()) {\n this.#currentMutation?.removeObserver(this)\n }\n }\n\n /**\n * Updates the observer's result when the observed mutation changes, and notifies its listeners.\n * @internal\n * @param action - The action that updated the observed mutation, passed on to the observer's\n * callbacks.\n */\n onMutationUpdate(\n action: Action<TData, TError, TVariables, TOnMutateResult>,\n ): void {\n this.#updateResult()\n\n this.#notify(action)\n }\n\n /**\n * Returns the observer's current result, derived from the observed\n * mutation's state (or the default, `idle` state if no mutation has been\n * built yet, e.g. before the first `mutate()` call or after `reset()`).\n * @returns The observer's latest result.\n */\n getCurrentResult(): MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > {\n return this.#currentResult\n }\n\n /**\n * Detaches the observer from the mutation it is currently observing (if\n * any) and resets the observed result back to its default, `idle` state.\n *\n * This does not cancel an in-flight mutation; the mutation itself keeps\n * running to completion and its own callbacks still fire, but this\n * observer stops reflecting its state and a subsequent `mutate()` call\n * will build a brand new mutation.\n * @see {@link MutationObserver#mutate}\n * @example\n * ```ts\n * observer.reset()\n * ```\n */\n reset(): void {\n // reset needs to remove the observer from the mutation because there is no way to \"get it back\"\n // another mutate call will yield a new mutation!\n this.#currentMutation?.removeObserver(this)\n this.#currentMutation = undefined\n this.#updateResult()\n this.#notify()\n }\n\n /**\n * Builds a new `Mutation` in the `MutationCache` using the observer's\n * current options, detaches this observer from any previously observed\n * mutation, attaches it to the new one, and executes it with the given\n * variables.\n *\n * The optional per-call `options` (`onSuccess`/`onError`/`onSettled`) are\n * invoked once the mutation settles, in addition to any callbacks defined\n * on the observer's own options.\n * @param variables - The variables passed to the `mutationFn`.\n * @param options - Per-call `onSuccess`, `onError`, and `onSettled` callbacks.\n * @returns A promise that resolves with the mutation's data, or rejects with its error.\n * @example\n * ```ts\n * await observer.mutate(\n * { title: 'New post' },\n * { onSuccess: (data) => console.log(data) },\n * )\n * ```\n */\n mutate(\n variables: TVariables,\n options?: MutateOptions<TData, TError, TVariables, TOnMutateResult>,\n ): Promise<TData> {\n this.#mutateOptions = options\n\n this.#currentMutation?.removeObserver(this)\n\n this.#currentMutation = this.#client\n .getMutationCache()\n .build(this.#client, this.options)\n\n this.#currentMutation.addObserver(this)\n\n return this.#currentMutation.execute(variables)\n }\n\n #updateResult(): void {\n const state =\n this.#currentMutation?.state ??\n getDefaultState<TData, TError, TVariables, TOnMutateResult>()\n\n this.#currentResult = {\n ...state,\n isPending: state.status === 'pending',\n isSuccess: state.status === 'success',\n isError: state.status === 'error',\n isIdle: state.status === 'idle',\n mutate: this.mutate,\n reset: this.reset,\n } as MutationObserverResult<TData, TError, TVariables, TOnMutateResult>\n }\n\n #notify(action?: Action<TData, TError, TVariables, TOnMutateResult>): void {\n notifyManager.batch(() => {\n // First trigger the mutate callbacks\n // Snapshot mutateOptions before dispatching — a callback (e.g. onSuccess)\n // may call mutate() again, which overwrites this.#mutateOptions in place.\n // Without the snapshot, onSettled would fire with the *next* mutation's\n // options but the *current* mutation's data/variables.\n const mutateOptions = this.#mutateOptions\n if (mutateOptions && this.hasListeners()) {\n const variables = this.#currentResult.variables!\n const onMutateResult = this.#currentResult.context\n\n const context = {\n client: this.#client,\n meta: this.options.meta,\n mutationKey: this.options.mutationKey,\n } satisfies MutationFunctionContext\n\n if (action?.type === 'success') {\n try {\n mutateOptions.onSuccess?.(\n action.data,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n mutateOptions.onSettled?.(\n action.data,\n null,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n } else if (action?.type === 'error') {\n try {\n mutateOptions.onError?.(\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n mutateOptions.onSettled?.(\n undefined,\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n }\n }\n\n // Then trigger the listeners\n this.listeners.forEach((listener) => {\n listener(this.#currentResult)\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,mBAAb,cAKUA,qBAAAA,aAER;CAaA,YACE,QACA,SAMA;EACA,MAAM;;;EAbJ,8BAAA,2BAAA,MAAA,gBAAA,KAAA,CAAA;;;EAeF,8BAAA,uBAAA,SAAA,MAAe,MAAA;EACf,KAAK,WAAW,OAAO;EACvB,KAAK,YAAY;EACjB,8BAAA,kBAAA,yBAAA,MAAA,aAAA,CAAA,CAAA,KAAA,IAAmB;CACrB;;;;;CAMA,cAA8B;EAC5B,KAAK,SAAS,KAAK,OAAO,KAAK,IAAI;EACnC,KAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;CACnC;;;;;;;;;;;;;;;;;;CAmBA,WACE,SAMA;;EACA,MAAM,cAAc,KAAK;EAGzB,KAAK,UAAA,8BAAA,uBAAA,SAAU,IAAA,CAAA,CAAa,uBAAuB,OAAO;EAC1D,IAAI,CAACC,cAAAA,oBAAoB,KAAK,SAAS,WAAW,GAChD,8BAAA,uBAAA,SAAA,IAAA,CAAA,CAAa,iBAAiB,CAAC,CAAC,OAAO;GACrC,MAAM;GACN,UAAA,8BAAA,uBAAA,kBAAU,IAAA;GACV,UAAU;EACZ,CAAC;EAGH,KAAA,gBAAA,QAAA,gBAAA,KAAA,IAAA,KAAA,IACE,YAAa,gBACb,KAAK,QAAQ,eACbC,cAAAA,QAAQ,YAAY,WAAW,MAAMA,cAAAA,QAAQ,KAAK,QAAQ,WAAW,GAErE,KAAK,MAAM;OACN,MAAA,2BAAA,8BAAA,uBAAA,kBAAI,IAAA,OAAA,QAAA,6BAAA,KAAA,IAAA,KAAA,IAAA,yBAAuB,MAAM,YAAW,WACjD,8BAAA,uBAAA,kBAAA,IAAA,CAAA,CAAsB,WAAW,KAAK,OAA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AO,MACP,MACA,WACA,gBACA,OACF;IACF,SAAS,GAAG;KACV,QAAa,OAAO,CAAC;IACvB;GACF,OAAO,KAAA,WAAA,QAAA,WAAA,KAAA,IAAA,KAAA,IAAI,OAAQ,UAAS,SAAS;IACnC,IAAI;;KACF,CAAA,wBAAA,cAAc,aAAA,QAAA,0BAAA,KAAA,KAAA,sBAAA,KAAA,eACZ,OAAO,OACP,WACA,gBACA,OACF;IACF,SAAS,GAAG;KACV,QAAa,OAAO,CAAC;IACvB;IACA,IAAI;;KACF,CAAA,yBAAA,cAAc,eAAA,QAAA,2BAAA,KAAA,KAAA,uBAAA,KAAA,eACZ,KAAA,GACA,OAAO,OACP,WACA,gBACA,OACF;IACF,SAAS,GAAG;KACV,QAAa,OAAO,CAAC;IACvB;GACF;EACF;EAGA,KAAK,UAAU,SAAS,aAAa;GACnC,SAAA,8BAAA,uBAAA,gBAAS,IAAA,CAAmB;EAC9B,CAAC;CACH,CAAC;AACH"}
@@ -1,2 +1,2 @@
1
- import { qn as MutationObserver } from "./hydration-Br9VIGXa.cjs";
1
+ import { qn as MutationObserver } from "./hydration-Dfuxd5FW.cjs";
2
2
  export { MutationObserver };
@@ -1,2 +1,2 @@
1
- import { qn as MutationObserver } from "./hydration-B9t5w6NC.js";
1
+ import { qn as MutationObserver } from "./hydration-UAqdtMIf.js";
2
2
  export { MutationObserver };
@@ -17,7 +17,6 @@ var _MutationObserver_brand = /* @__PURE__ */ new WeakSet();
17
17
  * passed to the hook change, subscribes to it to re-render on updates, and
18
18
  * reads `getCurrentResult()` for the value to return. Calling `mutate()`
19
19
  * builds a new underlying `Mutation` in the `MutationCache` and executes it.
20
- *
21
20
  * @example
22
21
  * ```ts
23
22
  * const observer = new MutationObserver(queryClient, {
@@ -38,6 +37,10 @@ var MutationObserver = class extends Subscribable {
38
37
  this.bindMethods();
39
38
  _assertClassBrand(_MutationObserver_brand, this, _updateResult).call(this);
40
39
  }
40
+ /**
41
+ * Binds the methods of the result (`mutate` and `reset`) to the observer, so they keep working when
42
+ * destructured from it.
43
+ */
41
44
  bindMethods() {
42
45
  this.mutate = this.mutate.bind(this);
43
46
  this.reset = this.reset.bind(this);
@@ -49,7 +52,8 @@ var MutationObserver = class extends Subscribable {
49
52
  * defined), the observer is reset, detaching it from the mutation it was
50
53
  * observing. Otherwise, if the currently observed mutation is still
51
54
  * `pending`, its options are updated in place as well.
52
- *
55
+ * @param options - The new mutation observer options. They are defaulted with {@link
56
+ * QueryClient#defaultMutationOptions} before being applied.
53
57
  * @example
54
58
  * ```ts
55
59
  * observer.setOptions({
@@ -82,7 +86,12 @@ var MutationObserver = class extends Subscribable {
82
86
  (_classPrivateFieldGet3 = _classPrivateFieldGet2(_currentMutation, this)) === null || _classPrivateFieldGet3 === void 0 || _classPrivateFieldGet3.removeObserver(this);
83
87
  }
84
88
  }
85
- /** @internal */
89
+ /**
90
+ * Updates the observer's result when the observed mutation changes, and notifies its listeners.
91
+ * @internal
92
+ * @param action - The action that updated the observed mutation, passed on to the observer's
93
+ * callbacks.
94
+ */
86
95
  onMutationUpdate(action) {
87
96
  _assertClassBrand(_MutationObserver_brand, this, _updateResult).call(this);
88
97
  _assertClassBrand(_MutationObserver_brand, this, _notify).call(this, action);
@@ -91,6 +100,7 @@ var MutationObserver = class extends Subscribable {
91
100
  * Returns the observer's current result, derived from the observed
92
101
  * mutation's state (or the default, `idle` state if no mutation has been
93
102
  * built yet, e.g. before the first `mutate()` call or after `reset()`).
103
+ * @returns The observer's latest result.
94
104
  */
95
105
  getCurrentResult() {
96
106
  return _classPrivateFieldGet2(_currentResult, this);
@@ -103,13 +113,11 @@ var MutationObserver = class extends Subscribable {
103
113
  * running to completion and its own callbacks still fire, but this
104
114
  * observer stops reflecting its state and a subsequent `mutate()` call
105
115
  * will build a brand new mutation.
106
- *
116
+ * @see {@link MutationObserver#mutate}
107
117
  * @example
108
118
  * ```ts
109
119
  * observer.reset()
110
120
  * ```
111
- *
112
- * @see {@link MutationObserver#mutate}
113
121
  */
114
122
  reset() {
115
123
  var _classPrivateFieldGet4;
@@ -127,7 +135,9 @@ var MutationObserver = class extends Subscribable {
127
135
  * The optional per-call `options` (`onSuccess`/`onError`/`onSettled`) are
128
136
  * invoked once the mutation settles, in addition to any callbacks defined
129
137
  * on the observer's own options.
130
- *
138
+ * @param variables - The variables passed to the `mutationFn`.
139
+ * @param options - Per-call `onSuccess`, `onError`, and `onSettled` callbacks.
140
+ * @returns A promise that resolves with the mutation's data, or rejects with its error.
131
141
  * @example
132
142
  * ```ts
133
143
  * await observer.mutate(
@@ -160,7 +170,8 @@ function _updateResult() {
160
170
  }
161
171
  function _notify(action) {
162
172
  notifyManager.batch(() => {
163
- if (_classPrivateFieldGet2(_mutateOptions, this) && this.hasListeners()) {
173
+ const mutateOptions = _classPrivateFieldGet2(_mutateOptions, this);
174
+ if (mutateOptions && this.hasListeners()) {
164
175
  const variables = _classPrivateFieldGet2(_currentResult, this).variables;
165
176
  const onMutateResult = _classPrivateFieldGet2(_currentResult, this).context;
166
177
  const context = {
@@ -170,27 +181,27 @@ function _notify(action) {
170
181
  };
171
182
  if ((action === null || action === void 0 ? void 0 : action.type) === "success") {
172
183
  try {
173
- var _classPrivateFieldGet7, _classPrivateFieldGet8;
174
- (_classPrivateFieldGet7 = (_classPrivateFieldGet8 = _classPrivateFieldGet2(_mutateOptions, this)).onSuccess) === null || _classPrivateFieldGet7 === void 0 || _classPrivateFieldGet7.call(_classPrivateFieldGet8, action.data, variables, onMutateResult, context);
184
+ var _mutateOptions$onSucc;
185
+ (_mutateOptions$onSucc = mutateOptions.onSuccess) === null || _mutateOptions$onSucc === void 0 || _mutateOptions$onSucc.call(mutateOptions, action.data, variables, onMutateResult, context);
175
186
  } catch (e) {
176
187
  Promise.reject(e);
177
188
  }
178
189
  try {
179
- var _classPrivateFieldGet9, _classPrivateFieldGet10;
180
- (_classPrivateFieldGet9 = (_classPrivateFieldGet10 = _classPrivateFieldGet2(_mutateOptions, this)).onSettled) === null || _classPrivateFieldGet9 === void 0 || _classPrivateFieldGet9.call(_classPrivateFieldGet10, action.data, null, variables, onMutateResult, context);
190
+ var _mutateOptions$onSett;
191
+ (_mutateOptions$onSett = mutateOptions.onSettled) === null || _mutateOptions$onSett === void 0 || _mutateOptions$onSett.call(mutateOptions, action.data, null, variables, onMutateResult, context);
181
192
  } catch (e) {
182
193
  Promise.reject(e);
183
194
  }
184
195
  } else if ((action === null || action === void 0 ? void 0 : action.type) === "error") {
185
196
  try {
186
- var _classPrivateFieldGet11, _classPrivateFieldGet12;
187
- (_classPrivateFieldGet11 = (_classPrivateFieldGet12 = _classPrivateFieldGet2(_mutateOptions, this)).onError) === null || _classPrivateFieldGet11 === void 0 || _classPrivateFieldGet11.call(_classPrivateFieldGet12, action.error, variables, onMutateResult, context);
197
+ var _mutateOptions$onErro;
198
+ (_mutateOptions$onErro = mutateOptions.onError) === null || _mutateOptions$onErro === void 0 || _mutateOptions$onErro.call(mutateOptions, action.error, variables, onMutateResult, context);
188
199
  } catch (e) {
189
200
  Promise.reject(e);
190
201
  }
191
202
  try {
192
- var _classPrivateFieldGet13, _classPrivateFieldGet14;
193
- (_classPrivateFieldGet13 = (_classPrivateFieldGet14 = _classPrivateFieldGet2(_mutateOptions, this)).onSettled) === null || _classPrivateFieldGet13 === void 0 || _classPrivateFieldGet13.call(_classPrivateFieldGet14, void 0, action.error, variables, onMutateResult, context);
203
+ var _mutateOptions$onSett2;
204
+ (_mutateOptions$onSett2 = mutateOptions.onSettled) === null || _mutateOptions$onSett2 === void 0 || _mutateOptions$onSett2.call(mutateOptions, void 0, action.error, variables, onMutateResult, context);
194
205
  } catch (e) {
195
206
  Promise.reject(e);
196
207
  }