@tanstack/query-core 5.0.0-alpha.86 → 5.0.0-alpha.87
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.
- package/build/legacy/focusManager.cjs +116 -0
- package/build/legacy/focusManager.cjs.map +1 -0
- package/build/legacy/focusManager.d.cts +16 -0
- package/build/{lib → legacy}/focusManager.d.ts +6 -5
- package/build/legacy/focusManager.js +91 -0
- package/build/legacy/focusManager.js.map +1 -0
- package/build/legacy/hydration.cjs +109 -0
- package/build/legacy/hydration.cjs.map +1 -0
- package/build/legacy/hydration.d.cts +35 -0
- package/build/legacy/hydration.d.ts +35 -0
- package/build/legacy/hydration.js +82 -0
- package/build/legacy/hydration.js.map +1 -0
- package/build/legacy/index.cjs +85 -0
- package/build/legacy/index.cjs.map +1 -0
- package/build/legacy/index.d.cts +9 -0
- package/build/legacy/index.d.ts +9 -0
- package/build/legacy/index.js +50 -0
- package/build/legacy/index.js.map +1 -0
- package/build/legacy/infiniteQueryBehavior.cjs +141 -0
- package/build/legacy/infiniteQueryBehavior.cjs.map +1 -0
- package/build/legacy/infiniteQueryBehavior.d.cts +15 -0
- package/build/legacy/infiniteQueryBehavior.d.ts +15 -0
- package/build/legacy/infiniteQueryBehavior.js +115 -0
- package/build/legacy/infiniteQueryBehavior.js.map +1 -0
- package/build/legacy/infiniteQueryObserver.cjs +88 -0
- package/build/legacy/infiniteQueryObserver.cjs.map +1 -0
- package/build/legacy/infiniteQueryObserver.d.cts +19 -0
- package/build/{lib → legacy}/infiniteQueryObserver.d.ts +7 -8
- package/build/{lib/infiniteQueryObserver.legacy.js → legacy/infiniteQueryObserver.js} +24 -32
- package/build/legacy/infiniteQueryObserver.js.map +1 -0
- package/build/legacy/mutation.cjs +297 -0
- package/build/legacy/mutation.cjs.map +1 -0
- package/build/legacy/mutation.d.cts +3 -0
- package/build/legacy/mutation.d.ts +3 -0
- package/build/legacy/mutation.js +272 -0
- package/build/legacy/mutation.js.map +1 -0
- package/build/legacy/mutationCache.cjs +133 -0
- package/build/legacy/mutationCache.cjs.map +1 -0
- package/build/legacy/mutationCache.d.cts +3 -0
- package/build/legacy/mutationCache.d.ts +3 -0
- package/build/legacy/mutationCache.js +109 -0
- package/build/legacy/mutationCache.js.map +1 -0
- package/build/legacy/mutationObserver.cjs +171 -0
- package/build/legacy/mutationObserver.cjs.map +1 -0
- package/build/legacy/mutationObserver.d.cts +3 -0
- package/build/legacy/mutationObserver.d.ts +3 -0
- package/build/legacy/mutationObserver.js +147 -0
- package/build/legacy/mutationObserver.js.map +1 -0
- package/build/legacy/notifyManager.cjs +97 -0
- package/build/legacy/notifyManager.cjs.map +1 -0
- package/build/legacy/notifyManager.d.cts +20 -0
- package/build/{lib → legacy}/notifyManager.d.ts +4 -4
- package/build/{lib → legacy}/notifyManager.js +14 -31
- package/build/legacy/notifyManager.js.map +1 -0
- package/build/legacy/onlineManager.cjs +106 -0
- package/build/legacy/onlineManager.cjs.map +1 -0
- package/build/legacy/onlineManager.d.cts +16 -0
- package/build/{lib → legacy}/onlineManager.d.ts +6 -5
- package/build/legacy/onlineManager.js +81 -0
- package/build/legacy/onlineManager.js.map +1 -0
- package/build/legacy/queriesObserver.cjs +242 -0
- package/build/legacy/queriesObserver.cjs.map +1 -0
- package/build/legacy/queriesObserver.d.cts +26 -0
- package/build/{lib → legacy}/queriesObserver.d.ts +10 -11
- package/build/legacy/queriesObserver.js +218 -0
- package/build/legacy/queriesObserver.js.map +1 -0
- package/build/legacy/query.cjs +423 -0
- package/build/legacy/query.cjs.map +1 -0
- package/build/legacy/query.d.cts +3 -0
- package/build/legacy/query.d.ts +3 -0
- package/build/legacy/query.js +399 -0
- package/build/legacy/query.js.map +1 -0
- package/build/legacy/queryCache.cjs +140 -0
- package/build/legacy/queryCache.cjs.map +1 -0
- package/build/legacy/queryCache.d.cts +3 -0
- package/build/legacy/queryCache.d.ts +3 -0
- package/build/legacy/queryCache.js +116 -0
- package/build/legacy/queryCache.js.map +1 -0
- package/build/legacy/queryClient-4ba6364e.d.ts +916 -0
- package/build/legacy/queryClient-d615ed9f.d.ts +916 -0
- package/build/legacy/queryClient.cjs +322 -0
- package/build/legacy/queryClient.cjs.map +1 -0
- package/build/legacy/queryClient.d.cts +3 -0
- package/build/legacy/queryClient.d.ts +3 -0
- package/build/legacy/queryClient.js +304 -0
- package/build/legacy/queryClient.js.map +1 -0
- package/build/legacy/queryObserver.cjs +501 -0
- package/build/legacy/queryObserver.cjs.map +1 -0
- package/build/legacy/queryObserver.d.cts +3 -0
- package/build/legacy/queryObserver.d.ts +3 -0
- package/build/legacy/queryObserver.js +484 -0
- package/build/legacy/queryObserver.js.map +1 -0
- package/build/legacy/removable.cjs +77 -0
- package/build/legacy/removable.cjs.map +1 -0
- package/build/legacy/removable.d.cts +11 -0
- package/build/{lib → legacy}/removable.d.ts +3 -2
- package/build/legacy/removable.js +53 -0
- package/build/legacy/removable.js.map +1 -0
- package/build/legacy/retryer.cjs +169 -0
- package/build/legacy/retryer.cjs.map +1 -0
- package/build/legacy/retryer.d.cts +3 -0
- package/build/legacy/retryer.d.ts +3 -0
- package/build/{lib/retryer.legacy.js → legacy/retryer.js} +37 -48
- package/build/legacy/retryer.js.map +1 -0
- package/build/legacy/subscribable.cjs +49 -0
- package/build/legacy/subscribable.cjs.map +1 -0
- package/build/legacy/subscribable.d.cts +11 -0
- package/build/{lib → legacy}/subscribable.d.ts +3 -3
- package/build/{lib → legacy}/subscribable.js +5 -6
- package/build/legacy/subscribable.js.map +1 -0
- package/build/legacy/types.cjs +17 -0
- package/build/legacy/types.cjs.map +1 -0
- package/build/legacy/types.d.cts +3 -0
- package/build/legacy/types.d.ts +3 -0
- package/build/legacy/types.js +1 -0
- package/build/legacy/types.js.map +1 -0
- package/build/{lib/utils.legacy.cjs → legacy/utils.cjs} +92 -93
- package/build/legacy/utils.cjs.map +1 -0
- package/build/legacy/utils.d.cts +3 -0
- package/build/legacy/utils.d.ts +3 -0
- package/build/{lib/utils.legacy.js → legacy/utils.js} +49 -72
- package/build/legacy/utils.js.map +1 -0
- package/build/modern/focusManager.cjs +91 -0
- package/build/modern/focusManager.cjs.map +1 -0
- package/build/modern/focusManager.d.cts +16 -0
- package/build/modern/focusManager.d.ts +16 -0
- package/build/modern/focusManager.js +66 -0
- package/build/modern/focusManager.js.map +1 -0
- package/build/modern/hydration.cjs +107 -0
- package/build/modern/hydration.cjs.map +1 -0
- package/build/modern/hydration.d.cts +35 -0
- package/build/modern/hydration.d.ts +35 -0
- package/build/modern/hydration.js +80 -0
- package/build/modern/hydration.js.map +1 -0
- package/build/modern/index.cjs +85 -0
- package/build/modern/index.cjs.map +1 -0
- package/build/modern/index.d.cts +9 -0
- package/build/modern/index.d.ts +9 -0
- package/build/modern/index.js +50 -0
- package/build/modern/index.js.map +1 -0
- package/build/modern/infiniteQueryBehavior.cjs +138 -0
- package/build/modern/infiniteQueryBehavior.cjs.map +1 -0
- package/build/modern/infiniteQueryBehavior.d.cts +15 -0
- package/build/modern/infiniteQueryBehavior.d.ts +15 -0
- package/build/{lib → modern}/infiniteQueryBehavior.js +46 -53
- package/build/modern/infiniteQueryBehavior.js.map +1 -0
- package/build/modern/infiniteQueryObserver.cjs +87 -0
- package/build/modern/infiniteQueryObserver.cjs.map +1 -0
- package/build/modern/infiniteQueryObserver.d.cts +19 -0
- package/build/modern/infiniteQueryObserver.d.ts +19 -0
- package/build/{lib → modern}/infiniteQueryObserver.js +23 -31
- package/build/modern/infiniteQueryObserver.js.map +1 -0
- package/build/modern/mutation.cjs +259 -0
- package/build/modern/mutation.cjs.map +1 -0
- package/build/modern/mutation.d.cts +3 -0
- package/build/modern/mutation.d.ts +3 -0
- package/build/{lib → modern}/mutation.js +86 -86
- package/build/modern/mutation.js.map +1 -0
- package/build/modern/mutationCache.cjs +103 -0
- package/build/modern/mutationCache.cjs.map +1 -0
- package/build/modern/mutationCache.d.cts +3 -0
- package/build/modern/mutationCache.d.ts +3 -0
- package/build/modern/mutationCache.js +79 -0
- package/build/modern/mutationCache.js.map +1 -0
- package/build/modern/mutationObserver.cjs +132 -0
- package/build/modern/mutationObserver.cjs.map +1 -0
- package/build/modern/mutationObserver.d.cts +3 -0
- package/build/modern/mutationObserver.d.ts +3 -0
- package/build/{lib → modern}/mutationObserver.js +44 -32
- package/build/modern/mutationObserver.js.map +1 -0
- package/build/modern/notifyManager.cjs +97 -0
- package/build/modern/notifyManager.cjs.map +1 -0
- package/build/modern/notifyManager.d.cts +20 -0
- package/build/modern/notifyManager.d.ts +20 -0
- package/build/{lib/notifyManager.legacy.js → modern/notifyManager.js} +14 -31
- package/build/modern/notifyManager.js.map +1 -0
- package/build/modern/onlineManager.cjs +82 -0
- package/build/modern/onlineManager.cjs.map +1 -0
- package/build/modern/onlineManager.d.cts +16 -0
- package/build/modern/onlineManager.d.ts +16 -0
- package/build/{lib → modern}/onlineManager.js +14 -17
- package/build/modern/onlineManager.js.map +1 -0
- package/build/modern/queriesObserver.cjs +202 -0
- package/build/modern/queriesObserver.cjs.map +1 -0
- package/build/modern/queriesObserver.d.cts +26 -0
- package/build/modern/queriesObserver.d.ts +26 -0
- package/build/{lib → modern}/queriesObserver.js +69 -50
- package/build/modern/queriesObserver.js.map +1 -0
- package/build/{lib → modern}/query.cjs +143 -186
- package/build/modern/query.cjs.map +1 -0
- package/build/modern/query.d.cts +3 -0
- package/build/modern/query.d.ts +3 -0
- package/build/{lib → modern}/query.js +110 -175
- package/build/modern/query.js.map +1 -0
- package/build/modern/queryCache.cjs +120 -0
- package/build/modern/queryCache.cjs.map +1 -0
- package/build/modern/queryCache.d.cts +3 -0
- package/build/modern/queryCache.d.ts +3 -0
- package/build/{lib → modern}/queryCache.js +21 -29
- package/build/modern/queryCache.js.map +1 -0
- package/build/modern/queryClient-4ba6364e.d.ts +916 -0
- package/build/modern/queryClient-d615ed9f.d.ts +916 -0
- package/build/modern/queryClient.cjs +284 -0
- package/build/modern/queryClient.cjs.map +1 -0
- package/build/modern/queryClient.d.cts +3 -0
- package/build/modern/queryClient.d.ts +3 -0
- package/build/{lib → modern}/queryClient.js +77 -94
- package/build/modern/queryClient.js.map +1 -0
- package/build/{lib → modern}/queryObserver.cjs +133 -149
- package/build/modern/queryObserver.cjs.map +1 -0
- package/build/modern/queryObserver.d.cts +3 -0
- package/build/modern/queryObserver.d.ts +3 -0
- package/build/{lib → modern}/queryObserver.js +107 -138
- package/build/modern/queryObserver.js.map +1 -0
- package/build/modern/removable.cjs +55 -0
- package/build/modern/removable.cjs.map +1 -0
- package/build/modern/removable.d.cts +11 -0
- package/build/modern/removable.d.ts +11 -0
- package/build/{lib → modern}/removable.js +10 -8
- package/build/modern/removable.js.map +1 -0
- package/build/{lib → modern}/retryer.cjs +50 -44
- package/build/modern/retryer.cjs.map +1 -0
- package/build/modern/retryer.d.cts +3 -0
- package/build/modern/retryer.d.ts +3 -0
- package/build/{lib → modern}/retryer.js +23 -39
- package/build/modern/retryer.js.map +1 -0
- package/build/modern/subscribable.cjs +49 -0
- package/build/modern/subscribable.cjs.map +1 -0
- package/build/modern/subscribable.d.cts +11 -0
- package/build/modern/subscribable.d.ts +11 -0
- package/build/{lib/subscribable.legacy.js → modern/subscribable.js} +5 -6
- package/build/modern/subscribable.js.map +1 -0
- package/build/modern/types.cjs +17 -0
- package/build/modern/types.cjs.map +1 -0
- package/build/modern/types.d.cts +3 -0
- package/build/modern/types.d.ts +3 -0
- package/build/modern/types.js +1 -0
- package/build/modern/types.js.map +1 -0
- package/build/{lib → modern}/utils.cjs +92 -93
- package/build/modern/utils.cjs.map +1 -0
- package/build/modern/utils.d.cts +3 -0
- package/build/modern/utils.d.ts +3 -0
- package/build/{lib → modern}/utils.js +49 -72
- package/build/modern/utils.js.map +1 -0
- package/package.json +15 -13
- package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.cjs +0 -16
- package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.cjs.map +0 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.js +0 -13
- package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.js.map +0 -1
- package/build/lib/focusManager.cjs +0 -75
- package/build/lib/focusManager.cjs.map +0 -1
- package/build/lib/focusManager.d.ts.map +0 -1
- package/build/lib/focusManager.js +0 -72
- package/build/lib/focusManager.js.map +0 -1
- package/build/lib/focusManager.legacy.cjs +0 -91
- package/build/lib/focusManager.legacy.cjs.map +0 -1
- package/build/lib/focusManager.legacy.js +0 -88
- package/build/lib/focusManager.legacy.js.map +0 -1
- package/build/lib/hydration.cjs +0 -97
- package/build/lib/hydration.cjs.map +0 -1
- package/build/lib/hydration.d.ts +0 -35
- package/build/lib/hydration.d.ts.map +0 -1
- package/build/lib/hydration.js +0 -92
- package/build/lib/hydration.js.map +0 -1
- package/build/lib/hydration.legacy.cjs +0 -100
- package/build/lib/hydration.legacy.cjs.map +0 -1
- package/build/lib/hydration.legacy.js +0 -95
- package/build/lib/hydration.legacy.js.map +0 -1
- package/build/lib/index.cjs +0 -40
- package/build/lib/index.cjs.map +0 -1
- package/build/lib/index.d.ts +0 -22
- package/build/lib/index.d.ts.map +0 -1
- package/build/lib/index.js +0 -14
- package/build/lib/index.js.map +0 -1
- package/build/lib/index.legacy.cjs +0 -40
- package/build/lib/index.legacy.cjs.map +0 -1
- package/build/lib/index.legacy.js +0 -14
- package/build/lib/index.legacy.js.map +0 -1
- package/build/lib/infiniteQueryBehavior.cjs +0 -123
- package/build/lib/infiniteQueryBehavior.cjs.map +0 -1
- package/build/lib/infiniteQueryBehavior.d.ts +0 -12
- package/build/lib/infiniteQueryBehavior.d.ts.map +0 -1
- package/build/lib/infiniteQueryBehavior.js.map +0 -1
- package/build/lib/infiniteQueryBehavior.legacy.cjs +0 -125
- package/build/lib/infiniteQueryBehavior.legacy.cjs.map +0 -1
- package/build/lib/infiniteQueryBehavior.legacy.js +0 -121
- package/build/lib/infiniteQueryBehavior.legacy.js.map +0 -1
- package/build/lib/infiniteQueryObserver.cjs +0 -77
- package/build/lib/infiniteQueryObserver.cjs.map +0 -1
- package/build/lib/infiniteQueryObserver.d.ts.map +0 -1
- package/build/lib/infiniteQueryObserver.js.map +0 -1
- package/build/lib/infiniteQueryObserver.legacy.cjs +0 -78
- package/build/lib/infiniteQueryObserver.legacy.cjs.map +0 -1
- package/build/lib/infiniteQueryObserver.legacy.js.map +0 -1
- package/build/lib/mutation.cjs +0 -237
- package/build/lib/mutation.cjs.map +0 -1
- package/build/lib/mutation.d.ts +0 -64
- package/build/lib/mutation.d.ts.map +0 -1
- package/build/lib/mutation.js.map +0 -1
- package/build/lib/mutation.legacy.cjs +0 -262
- package/build/lib/mutation.legacy.cjs.map +0 -1
- package/build/lib/mutation.legacy.js +0 -259
- package/build/lib/mutation.legacy.js.map +0 -1
- package/build/lib/mutationCache.cjs +0 -85
- package/build/lib/mutationCache.cjs.map +0 -1
- package/build/lib/mutationCache.d.ts +0 -59
- package/build/lib/mutationCache.d.ts.map +0 -1
- package/build/lib/mutationCache.js +0 -83
- package/build/lib/mutationCache.js.map +0 -1
- package/build/lib/mutationCache.legacy.cjs +0 -98
- package/build/lib/mutationCache.legacy.cjs.map +0 -1
- package/build/lib/mutationCache.legacy.js +0 -96
- package/build/lib/mutationCache.legacy.js.map +0 -1
- package/build/lib/mutationObserver.cjs +0 -98
- package/build/lib/mutationObserver.cjs.map +0 -1
- package/build/lib/mutationObserver.d.ts +0 -19
- package/build/lib/mutationObserver.d.ts.map +0 -1
- package/build/lib/mutationObserver.js.map +0 -1
- package/build/lib/mutationObserver.legacy.cjs +0 -128
- package/build/lib/mutationObserver.legacy.cjs.map +0 -1
- package/build/lib/mutationObserver.legacy.js +0 -126
- package/build/lib/mutationObserver.legacy.js.map +0 -1
- package/build/lib/notifyManager.cjs +0 -92
- package/build/lib/notifyManager.cjs.map +0 -1
- package/build/lib/notifyManager.d.ts.map +0 -1
- package/build/lib/notifyManager.js.map +0 -1
- package/build/lib/notifyManager.legacy.cjs +0 -92
- package/build/lib/notifyManager.legacy.cjs.map +0 -1
- package/build/lib/notifyManager.legacy.js.map +0 -1
- package/build/lib/onlineManager.cjs +0 -63
- package/build/lib/onlineManager.cjs.map +0 -1
- package/build/lib/onlineManager.d.ts.map +0 -1
- package/build/lib/onlineManager.js.map +0 -1
- package/build/lib/onlineManager.legacy.cjs +0 -78
- package/build/lib/onlineManager.legacy.cjs.map +0 -1
- package/build/lib/onlineManager.legacy.js +0 -75
- package/build/lib/onlineManager.legacy.js.map +0 -1
- package/build/lib/queriesObserver.cjs +0 -161
- package/build/lib/queriesObserver.cjs.map +0 -1
- package/build/lib/queriesObserver.d.ts.map +0 -1
- package/build/lib/queriesObserver.js.map +0 -1
- package/build/lib/queriesObserver.legacy.cjs +0 -207
- package/build/lib/queriesObserver.legacy.cjs.map +0 -1
- package/build/lib/queriesObserver.legacy.js +0 -205
- package/build/lib/queriesObserver.legacy.js.map +0 -1
- package/build/lib/query.cjs.map +0 -1
- package/build/lib/query.d.ts +0 -115
- package/build/lib/query.d.ts.map +0 -1
- package/build/lib/query.js.map +0 -1
- package/build/lib/query.legacy.cjs +0 -471
- package/build/lib/query.legacy.cjs.map +0 -1
- package/build/lib/query.legacy.js +0 -469
- package/build/lib/query.legacy.js.map +0 -1
- package/build/lib/queryCache.cjs +0 -106
- package/build/lib/queryCache.cjs.map +0 -1
- package/build/lib/queryCache.d.ts +0 -71
- package/build/lib/queryCache.d.ts.map +0 -1
- package/build/lib/queryCache.js.map +0 -1
- package/build/lib/queryCache.legacy.cjs +0 -111
- package/build/lib/queryCache.legacy.cjs.map +0 -1
- package/build/lib/queryCache.legacy.js +0 -109
- package/build/lib/queryCache.legacy.js.map +0 -1
- package/build/lib/queryClient.cjs +0 -285
- package/build/lib/queryClient.cjs.map +0 -1
- package/build/lib/queryClient.d.ts +0 -41
- package/build/lib/queryClient.d.ts.map +0 -1
- package/build/lib/queryClient.js.map +0 -1
- package/build/lib/queryClient.legacy.cjs +0 -322
- package/build/lib/queryClient.legacy.cjs.map +0 -1
- package/build/lib/queryClient.legacy.js +0 -320
- package/build/lib/queryClient.legacy.js.map +0 -1
- package/build/lib/queryObserver.cjs.map +0 -1
- package/build/lib/queryObserver.d.ts +0 -35
- package/build/lib/queryObserver.d.ts.map +0 -1
- package/build/lib/queryObserver.js.map +0 -1
- package/build/lib/queryObserver.legacy.cjs +0 -561
- package/build/lib/queryObserver.legacy.cjs.map +0 -1
- package/build/lib/queryObserver.legacy.js +0 -559
- package/build/lib/queryObserver.legacy.js.map +0 -1
- package/build/lib/removable.cjs +0 -31
- package/build/lib/removable.cjs.map +0 -1
- package/build/lib/removable.d.ts.map +0 -1
- package/build/lib/removable.js.map +0 -1
- package/build/lib/removable.legacy.cjs +0 -38
- package/build/lib/removable.legacy.cjs.map +0 -1
- package/build/lib/removable.legacy.js +0 -36
- package/build/lib/removable.legacy.js.map +0 -1
- package/build/lib/retryer.cjs.map +0 -1
- package/build/lib/retryer.d.ts +0 -34
- package/build/lib/retryer.d.ts.map +0 -1
- package/build/lib/retryer.js.map +0 -1
- package/build/lib/retryer.legacy.cjs +0 -158
- package/build/lib/retryer.legacy.cjs.map +0 -1
- package/build/lib/retryer.legacy.js.map +0 -1
- package/build/lib/subscribable.cjs +0 -28
- package/build/lib/subscribable.cjs.map +0 -1
- package/build/lib/subscribable.d.ts.map +0 -1
- package/build/lib/subscribable.js.map +0 -1
- package/build/lib/subscribable.legacy.cjs +0 -28
- package/build/lib/subscribable.legacy.cjs.map +0 -1
- package/build/lib/subscribable.legacy.js.map +0 -1
- package/build/lib/tests/focusManager.test.d.ts +0 -2
- package/build/lib/tests/focusManager.test.d.ts.map +0 -1
- package/build/lib/tests/hydration.test.d.ts +0 -2
- package/build/lib/tests/hydration.test.d.ts.map +0 -1
- package/build/lib/tests/infiniteQueryBehavior.test.d.ts +0 -2
- package/build/lib/tests/infiniteQueryBehavior.test.d.ts.map +0 -1
- package/build/lib/tests/infiniteQueryObserver.test.d.ts +0 -2
- package/build/lib/tests/infiniteQueryObserver.test.d.ts.map +0 -1
- package/build/lib/tests/mutationCache.test.d.ts +0 -2
- package/build/lib/tests/mutationCache.test.d.ts.map +0 -1
- package/build/lib/tests/mutationObserver.test.d.ts +0 -2
- package/build/lib/tests/mutationObserver.test.d.ts.map +0 -1
- package/build/lib/tests/mutations.test.d.ts +0 -2
- package/build/lib/tests/mutations.test.d.ts.map +0 -1
- package/build/lib/tests/notifyManager.test.d.ts +0 -2
- package/build/lib/tests/notifyManager.test.d.ts.map +0 -1
- package/build/lib/tests/onlineManager.test.d.ts +0 -2
- package/build/lib/tests/onlineManager.test.d.ts.map +0 -1
- package/build/lib/tests/queriesObserver.test.d.ts +0 -2
- package/build/lib/tests/queriesObserver.test.d.ts.map +0 -1
- package/build/lib/tests/query.test.d.ts +0 -2
- package/build/lib/tests/query.test.d.ts.map +0 -1
- package/build/lib/tests/queryCache.test.d.ts +0 -2
- package/build/lib/tests/queryCache.test.d.ts.map +0 -1
- package/build/lib/tests/queryClient.test.d.ts +0 -2
- package/build/lib/tests/queryClient.test.d.ts.map +0 -1
- package/build/lib/tests/queryObserver.test.d.ts +0 -2
- package/build/lib/tests/queryObserver.test.d.ts.map +0 -1
- package/build/lib/tests/utils.d.ts +0 -17
- package/build/lib/tests/utils.d.ts.map +0 -1
- package/build/lib/tests/utils.test.d.ts +0 -2
- package/build/lib/tests/utils.test.d.ts.map +0 -1
- package/build/lib/types.d.ts +0 -437
- package/build/lib/types.d.ts.map +0 -1
- package/build/lib/utils.cjs.map +0 -1
- package/build/lib/utils.d.ts +0 -90
- package/build/lib/utils.d.ts.map +0 -1
- package/build/lib/utils.js.map +0 -1
- package/build/lib/utils.legacy.cjs.map +0 -1
- package/build/lib/utils.legacy.js.map +0 -1
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var mutation_exports = {};
|
|
20
|
+
__export(mutation_exports, {
|
|
21
|
+
Mutation: () => Mutation,
|
|
22
|
+
getDefaultState: () => getDefaultState
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(mutation_exports);
|
|
25
|
+
var import_notifyManager = require("./notifyManager");
|
|
26
|
+
var import_removable = require("./removable");
|
|
27
|
+
var import_retryer = require("./retryer");
|
|
28
|
+
class Mutation extends import_removable.Removable {
|
|
29
|
+
constructor(config) {
|
|
30
|
+
super();
|
|
31
|
+
this.mutationId = config.mutationId;
|
|
32
|
+
this.#defaultOptions = config.defaultOptions;
|
|
33
|
+
this.#mutationCache = config.mutationCache;
|
|
34
|
+
this.#observers = [];
|
|
35
|
+
this.state = config.state || getDefaultState();
|
|
36
|
+
this.setOptions(config.options);
|
|
37
|
+
this.scheduleGc();
|
|
38
|
+
}
|
|
39
|
+
#observers;
|
|
40
|
+
#defaultOptions;
|
|
41
|
+
#mutationCache;
|
|
42
|
+
#retryer;
|
|
43
|
+
setOptions(options) {
|
|
44
|
+
this.options = { ...this.#defaultOptions, ...options };
|
|
45
|
+
this.updateGcTime(this.options.gcTime);
|
|
46
|
+
}
|
|
47
|
+
get meta() {
|
|
48
|
+
return this.options.meta;
|
|
49
|
+
}
|
|
50
|
+
addObserver(observer) {
|
|
51
|
+
if (!this.#observers.includes(observer)) {
|
|
52
|
+
this.#observers.push(observer);
|
|
53
|
+
this.clearGcTimeout();
|
|
54
|
+
this.#mutationCache.notify({
|
|
55
|
+
type: "observerAdded",
|
|
56
|
+
mutation: this,
|
|
57
|
+
observer
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
removeObserver(observer) {
|
|
62
|
+
this.#observers = this.#observers.filter((x) => x !== observer);
|
|
63
|
+
this.scheduleGc();
|
|
64
|
+
this.#mutationCache.notify({
|
|
65
|
+
type: "observerRemoved",
|
|
66
|
+
mutation: this,
|
|
67
|
+
observer
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
optionalRemove() {
|
|
71
|
+
if (!this.#observers.length) {
|
|
72
|
+
if (this.state.status === "pending") {
|
|
73
|
+
this.scheduleGc();
|
|
74
|
+
} else {
|
|
75
|
+
this.#mutationCache.remove(this);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
continue() {
|
|
80
|
+
return this.#retryer?.continue() ?? // continuing a mutation assumes that variables are set, mutation must have been dehydrated before
|
|
81
|
+
this.execute(this.state.variables);
|
|
82
|
+
}
|
|
83
|
+
async execute(variables) {
|
|
84
|
+
const executeMutation = () => {
|
|
85
|
+
this.#retryer = (0, import_retryer.createRetryer)({
|
|
86
|
+
fn: () => {
|
|
87
|
+
if (!this.options.mutationFn) {
|
|
88
|
+
return Promise.reject(new Error("No mutationFn found"));
|
|
89
|
+
}
|
|
90
|
+
return this.options.mutationFn(variables);
|
|
91
|
+
},
|
|
92
|
+
onFail: (failureCount, error) => {
|
|
93
|
+
this.#dispatch({ type: "failed", failureCount, error });
|
|
94
|
+
},
|
|
95
|
+
onPause: () => {
|
|
96
|
+
this.#dispatch({ type: "pause" });
|
|
97
|
+
},
|
|
98
|
+
onContinue: () => {
|
|
99
|
+
this.#dispatch({ type: "continue" });
|
|
100
|
+
},
|
|
101
|
+
retry: this.options.retry ?? 0,
|
|
102
|
+
retryDelay: this.options.retryDelay,
|
|
103
|
+
networkMode: this.options.networkMode
|
|
104
|
+
});
|
|
105
|
+
return this.#retryer.promise;
|
|
106
|
+
};
|
|
107
|
+
const restored = this.state.status === "pending";
|
|
108
|
+
try {
|
|
109
|
+
if (!restored) {
|
|
110
|
+
this.#dispatch({ type: "pending", variables });
|
|
111
|
+
await this.#mutationCache.config.onMutate?.(
|
|
112
|
+
variables,
|
|
113
|
+
this
|
|
114
|
+
);
|
|
115
|
+
const context = await this.options.onMutate?.(variables);
|
|
116
|
+
if (context !== this.state.context) {
|
|
117
|
+
this.#dispatch({
|
|
118
|
+
type: "pending",
|
|
119
|
+
context,
|
|
120
|
+
variables
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const data = await executeMutation();
|
|
125
|
+
await this.#mutationCache.config.onSuccess?.(
|
|
126
|
+
data,
|
|
127
|
+
variables,
|
|
128
|
+
this.state.context,
|
|
129
|
+
this
|
|
130
|
+
);
|
|
131
|
+
await this.options.onSuccess?.(data, variables, this.state.context);
|
|
132
|
+
await this.#mutationCache.config.onSettled?.(
|
|
133
|
+
data,
|
|
134
|
+
null,
|
|
135
|
+
this.state.variables,
|
|
136
|
+
this.state.context,
|
|
137
|
+
this
|
|
138
|
+
);
|
|
139
|
+
await this.options.onSettled?.(data, null, variables, this.state.context);
|
|
140
|
+
this.#dispatch({ type: "success", data });
|
|
141
|
+
return data;
|
|
142
|
+
} catch (error) {
|
|
143
|
+
try {
|
|
144
|
+
await this.#mutationCache.config.onError?.(
|
|
145
|
+
error,
|
|
146
|
+
variables,
|
|
147
|
+
this.state.context,
|
|
148
|
+
this
|
|
149
|
+
);
|
|
150
|
+
await this.options.onError?.(
|
|
151
|
+
error,
|
|
152
|
+
variables,
|
|
153
|
+
this.state.context
|
|
154
|
+
);
|
|
155
|
+
await this.#mutationCache.config.onSettled?.(
|
|
156
|
+
void 0,
|
|
157
|
+
error,
|
|
158
|
+
this.state.variables,
|
|
159
|
+
this.state.context,
|
|
160
|
+
this
|
|
161
|
+
);
|
|
162
|
+
await this.options.onSettled?.(
|
|
163
|
+
void 0,
|
|
164
|
+
error,
|
|
165
|
+
variables,
|
|
166
|
+
this.state.context
|
|
167
|
+
);
|
|
168
|
+
throw error;
|
|
169
|
+
} finally {
|
|
170
|
+
this.#dispatch({ type: "error", error });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
#dispatch(action) {
|
|
175
|
+
const reducer = (state) => {
|
|
176
|
+
switch (action.type) {
|
|
177
|
+
case "failed":
|
|
178
|
+
return {
|
|
179
|
+
...state,
|
|
180
|
+
failureCount: action.failureCount,
|
|
181
|
+
failureReason: action.error
|
|
182
|
+
};
|
|
183
|
+
case "pause":
|
|
184
|
+
return {
|
|
185
|
+
...state,
|
|
186
|
+
isPaused: true
|
|
187
|
+
};
|
|
188
|
+
case "continue":
|
|
189
|
+
return {
|
|
190
|
+
...state,
|
|
191
|
+
isPaused: false
|
|
192
|
+
};
|
|
193
|
+
case "pending":
|
|
194
|
+
return {
|
|
195
|
+
...state,
|
|
196
|
+
context: action.context,
|
|
197
|
+
data: void 0,
|
|
198
|
+
failureCount: 0,
|
|
199
|
+
failureReason: null,
|
|
200
|
+
error: null,
|
|
201
|
+
isPaused: !(0, import_retryer.canFetch)(this.options.networkMode),
|
|
202
|
+
status: "pending",
|
|
203
|
+
variables: action.variables,
|
|
204
|
+
submittedAt: Date.now()
|
|
205
|
+
};
|
|
206
|
+
case "success":
|
|
207
|
+
return {
|
|
208
|
+
...state,
|
|
209
|
+
data: action.data,
|
|
210
|
+
failureCount: 0,
|
|
211
|
+
failureReason: null,
|
|
212
|
+
error: null,
|
|
213
|
+
status: "success",
|
|
214
|
+
isPaused: false
|
|
215
|
+
};
|
|
216
|
+
case "error":
|
|
217
|
+
return {
|
|
218
|
+
...state,
|
|
219
|
+
data: void 0,
|
|
220
|
+
error: action.error,
|
|
221
|
+
failureCount: state.failureCount + 1,
|
|
222
|
+
failureReason: action.error,
|
|
223
|
+
isPaused: false,
|
|
224
|
+
status: "error"
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
this.state = reducer(this.state);
|
|
229
|
+
import_notifyManager.notifyManager.batch(() => {
|
|
230
|
+
this.#observers.forEach((observer) => {
|
|
231
|
+
observer.onMutationUpdate(action);
|
|
232
|
+
});
|
|
233
|
+
this.#mutationCache.notify({
|
|
234
|
+
mutation: this,
|
|
235
|
+
type: "updated",
|
|
236
|
+
action
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function getDefaultState() {
|
|
242
|
+
return {
|
|
243
|
+
context: void 0,
|
|
244
|
+
data: void 0,
|
|
245
|
+
error: null,
|
|
246
|
+
failureCount: 0,
|
|
247
|
+
failureReason: null,
|
|
248
|
+
isPaused: false,
|
|
249
|
+
status: "idle",
|
|
250
|
+
variables: void 0,
|
|
251
|
+
submittedAt: 0
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
255
|
+
0 && (module.exports = {
|
|
256
|
+
Mutation,
|
|
257
|
+
getDefaultState
|
|
258
|
+
});
|
|
259
|
+
//# sourceMappingURL=mutation.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mutation.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Removable } from './removable'\nimport { canFetch, createRetryer } from './retryer'\nimport type {\n DefaultError,\n MutationMeta,\n MutationOptions,\n MutationStatus,\n} from './types'\nimport type { MutationCache } from './mutationCache'\nimport type { MutationObserver } from './mutationObserver'\nimport type { Retryer } from './retryer'\n\n// TYPES\n\ninterface MutationConfig<TData, TError, TVariables, TContext> {\n mutationId: number\n mutationCache: MutationCache\n options: MutationOptions<TData, TError, TVariables, TContext>\n defaultOptions?: MutationOptions<TData, TError, TVariables, TContext>\n state?: MutationState<TData, TError, TVariables, TContext>\n}\n\nexport interface MutationState<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> {\n context: TContext | undefined\n data: TData | undefined\n error: TError | null\n failureCount: number\n failureReason: TError | null\n isPaused: boolean\n status: MutationStatus\n variables: TVariables | undefined\n submittedAt: number\n}\n\ninterface FailedAction<TError> {\n type: 'failed'\n failureCount: number\n error: TError | null\n}\n\ninterface PendingAction<TVariables, TContext> {\n type: 'pending'\n variables?: TVariables\n context?: TContext\n}\n\ninterface SuccessAction<TData> {\n type: 'success'\n data: TData\n}\n\ninterface ErrorAction<TError> {\n type: 'error'\n error: TError\n}\n\ninterface PauseAction {\n type: 'pause'\n}\n\ninterface ContinueAction {\n type: 'continue'\n}\n\nexport type Action<TData, TError, TVariables, TContext> =\n | ContinueAction\n | ErrorAction<TError>\n | FailedAction<TError>\n | PendingAction<TVariables, TContext>\n | PauseAction\n | SuccessAction<TData>\n\n// CLASS\n\nexport class Mutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> extends Removable {\n state: MutationState<TData, TError, TVariables, TContext>\n options!: MutationOptions<TData, TError, TVariables, TContext>\n readonly mutationId: number\n\n #observers: MutationObserver<TData, TError, TVariables, TContext>[]\n #defaultOptions?: MutationOptions<TData, TError, TVariables, TContext>\n #mutationCache: MutationCache\n #retryer?: Retryer<TData>\n\n constructor(config: MutationConfig<TData, TError, TVariables, TContext>) {\n super()\n\n this.mutationId = config.mutationId\n this.#defaultOptions = config.defaultOptions\n this.#mutationCache = config.mutationCache\n this.#observers = []\n this.state = config.state || getDefaultState()\n\n this.setOptions(config.options)\n this.scheduleGc()\n }\n\n setOptions(\n options?: MutationOptions<TData, TError, TVariables, TContext>,\n ): void {\n this.options = { ...this.#defaultOptions, ...options }\n\n this.updateGcTime(this.options.gcTime)\n }\n\n get meta(): MutationMeta | undefined {\n return this.options.meta\n }\n\n addObserver(observer: MutationObserver<any, any, any, any>): void {\n if (!this.#observers.includes(observer)) {\n this.#observers.push(observer)\n\n // Stop the mutation from being garbage collected\n this.clearGcTimeout()\n\n this.#mutationCache.notify({\n type: 'observerAdded',\n mutation: this,\n observer,\n })\n }\n }\n\n removeObserver(observer: MutationObserver<any, any, any, any>): void {\n this.#observers = this.#observers.filter((x) => x !== observer)\n\n this.scheduleGc()\n\n this.#mutationCache.notify({\n type: 'observerRemoved',\n mutation: this,\n observer,\n })\n }\n\n protected optionalRemove() {\n if (!this.#observers.length) {\n if (this.state.status === 'pending') {\n this.scheduleGc()\n } else {\n this.#mutationCache.remove(this)\n }\n }\n }\n\n continue(): Promise<unknown> {\n return (\n this.#retryer?.continue() ??\n // continuing a mutation assumes that variables are set, mutation must have been dehydrated before\n this.execute(this.state.variables!)\n )\n }\n\n async execute(variables: TVariables): Promise<TData> {\n const executeMutation = () => {\n this.#retryer = createRetryer({\n fn: () => {\n if (!this.options.mutationFn) {\n return Promise.reject(new Error('No mutationFn found'))\n }\n return this.options.mutationFn(variables)\n },\n onFail: (failureCount, error) => {\n this.#dispatch({ type: 'failed', failureCount, error })\n },\n onPause: () => {\n this.#dispatch({ type: 'pause' })\n },\n onContinue: () => {\n this.#dispatch({ type: 'continue' })\n },\n retry: this.options.retry ?? 0,\n retryDelay: this.options.retryDelay,\n networkMode: this.options.networkMode,\n })\n\n return this.#retryer.promise\n }\n\n const restored = this.state.status === 'pending'\n\n try {\n if (!restored) {\n this.#dispatch({ type: 'pending', variables })\n // Notify cache callback\n await this.#mutationCache.config.onMutate?.(\n variables,\n this as Mutation<unknown, unknown, unknown, unknown>,\n )\n const context = await this.options.onMutate?.(variables)\n if (context !== this.state.context) {\n this.#dispatch({\n type: 'pending',\n context,\n variables,\n })\n }\n }\n const data = await executeMutation()\n\n // Notify cache callback\n await this.#mutationCache.config.onSuccess?.(\n data,\n variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n )\n\n await this.options.onSuccess?.(data, variables, this.state.context)\n\n // Notify cache callback\n await this.#mutationCache.config.onSettled?.(\n data,\n null,\n this.state.variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n )\n\n await this.options.onSettled?.(data, null, variables, this.state.context)\n\n this.#dispatch({ type: 'success', data })\n return data\n } catch (error) {\n try {\n // Notify cache callback\n await this.#mutationCache.config.onError?.(\n error as any,\n variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n )\n\n await this.options.onError?.(\n error as TError,\n variables,\n this.state.context,\n )\n\n // Notify cache callback\n await this.#mutationCache.config.onSettled?.(\n undefined,\n error as any,\n this.state.variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n )\n\n await this.options.onSettled?.(\n undefined,\n error as TError,\n variables,\n this.state.context,\n )\n throw error\n } finally {\n this.#dispatch({ type: 'error', error: error as TError })\n }\n }\n }\n\n #dispatch(action: Action<TData, TError, TVariables, TContext>): void {\n const reducer = (\n state: MutationState<TData, TError, TVariables, TContext>,\n ): MutationState<TData, TError, TVariables, TContext> => {\n switch (action.type) {\n case 'failed':\n return {\n ...state,\n failureCount: action.failureCount,\n failureReason: action.error,\n }\n case 'pause':\n return {\n ...state,\n isPaused: true,\n }\n case 'continue':\n return {\n ...state,\n isPaused: false,\n }\n case 'pending':\n return {\n ...state,\n context: action.context,\n data: undefined,\n failureCount: 0,\n failureReason: null,\n error: null,\n isPaused: !canFetch(this.options.networkMode),\n status: 'pending',\n variables: action.variables,\n submittedAt: Date.now(),\n }\n case 'success':\n return {\n ...state,\n data: action.data,\n failureCount: 0,\n failureReason: null,\n error: null,\n status: 'success',\n isPaused: false,\n }\n case 'error':\n return {\n ...state,\n data: undefined,\n error: action.error,\n failureCount: state.failureCount + 1,\n failureReason: action.error,\n isPaused: false,\n status: 'error',\n }\n }\n }\n this.state = reducer(this.state)\n\n notifyManager.batch(() => {\n this.#observers.forEach((observer) => {\n observer.onMutationUpdate(action)\n })\n this.#mutationCache.notify({\n mutation: this,\n type: 'updated',\n action,\n })\n })\n }\n}\n\nexport function getDefaultState<\n TData,\n TError,\n TVariables,\n TContext,\n>(): MutationState<TData, TError, TVariables, TContext> {\n return {\n context: undefined,\n data: undefined,\n error: null,\n failureCount: 0,\n failureReason: null,\n isPaused: false,\n status: 'idle',\n variables: undefined,\n submittedAt: 0,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA8B;AAC9B,uBAA0B;AAC1B,qBAAwC;AA8EjC,MAAM,iBAKH,2BAAU;AAAA,EAUlB,YAAY,QAA6D;AACvE,UAAM;AAEN,SAAK,aAAa,OAAO;AACzB,SAAK,kBAAkB,OAAO;AAC9B,SAAK,iBAAiB,OAAO;AAC7B,SAAK,aAAa,CAAC;AACnB,SAAK,QAAQ,OAAO,SAAS,gBAAgB;AAE7C,SAAK,WAAW,OAAO,OAAO;AAC9B,SAAK,WAAW;AAAA,EAClB;AAAA,EAhBA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAeA,WACE,SACM;AACN,SAAK,UAAU,EAAE,GAAG,KAAK,iBAAiB,GAAG,QAAQ;AAErD,SAAK,aAAa,KAAK,QAAQ,MAAM;AAAA,EACvC;AAAA,EAEA,IAAI,OAAiC;AACnC,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA,EAEA,YAAY,UAAsD;AAChE,QAAI,CAAC,KAAK,WAAW,SAAS,QAAQ,GAAG;AACvC,WAAK,WAAW,KAAK,QAAQ;AAG7B,WAAK,eAAe;AAEpB,WAAK,eAAe,OAAO;AAAA,QACzB,MAAM;AAAA,QACN,UAAU;AAAA,QACV;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,eAAe,UAAsD;AACnE,SAAK,aAAa,KAAK,WAAW,OAAO,CAAC,MAAM,MAAM,QAAQ;AAE9D,SAAK,WAAW;AAEhB,SAAK,eAAe,OAAO;AAAA,MACzB,MAAM;AAAA,MACN,UA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,IACP,cAAc;AAAA,IACd,eAAe;AAAA,IACf,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,aAAa;AAAA,EACf;AACF;","names":[]}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import { notifyManager } from
|
|
2
|
-
import { Removable } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
// TYPES
|
|
6
|
-
|
|
7
|
-
// CLASS
|
|
8
|
-
|
|
1
|
+
import { notifyManager } from "./notifyManager";
|
|
2
|
+
import { Removable } from "./removable";
|
|
3
|
+
import { canFetch, createRetryer } from "./retryer";
|
|
9
4
|
class Mutation extends Removable {
|
|
10
|
-
#observers;
|
|
11
|
-
#defaultOptions;
|
|
12
|
-
#mutationCache;
|
|
13
|
-
#retryer;
|
|
14
5
|
constructor(config) {
|
|
15
6
|
super();
|
|
16
7
|
this.mutationId = config.mutationId;
|
|
@@ -21,11 +12,12 @@ class Mutation extends Removable {
|
|
|
21
12
|
this.setOptions(config.options);
|
|
22
13
|
this.scheduleGc();
|
|
23
14
|
}
|
|
15
|
+
#observers;
|
|
16
|
+
#defaultOptions;
|
|
17
|
+
#mutationCache;
|
|
18
|
+
#retryer;
|
|
24
19
|
setOptions(options) {
|
|
25
|
-
this.options = {
|
|
26
|
-
...this.#defaultOptions,
|
|
27
|
-
...options
|
|
28
|
-
};
|
|
20
|
+
this.options = { ...this.#defaultOptions, ...options };
|
|
29
21
|
this.updateGcTime(this.options.gcTime);
|
|
30
22
|
}
|
|
31
23
|
get meta() {
|
|
@@ -34,28 +26,26 @@ class Mutation extends Removable {
|
|
|
34
26
|
addObserver(observer) {
|
|
35
27
|
if (!this.#observers.includes(observer)) {
|
|
36
28
|
this.#observers.push(observer);
|
|
37
|
-
|
|
38
|
-
// Stop the mutation from being garbage collected
|
|
39
29
|
this.clearGcTimeout();
|
|
40
30
|
this.#mutationCache.notify({
|
|
41
|
-
type:
|
|
31
|
+
type: "observerAdded",
|
|
42
32
|
mutation: this,
|
|
43
33
|
observer
|
|
44
34
|
});
|
|
45
35
|
}
|
|
46
36
|
}
|
|
47
37
|
removeObserver(observer) {
|
|
48
|
-
this.#observers = this.#observers.filter(x => x !== observer);
|
|
38
|
+
this.#observers = this.#observers.filter((x) => x !== observer);
|
|
49
39
|
this.scheduleGc();
|
|
50
40
|
this.#mutationCache.notify({
|
|
51
|
-
type:
|
|
41
|
+
type: "observerRemoved",
|
|
52
42
|
mutation: this,
|
|
53
43
|
observer
|
|
54
44
|
});
|
|
55
45
|
}
|
|
56
46
|
optionalRemove() {
|
|
57
47
|
if (!this.#observers.length) {
|
|
58
|
-
if (this.state.status ===
|
|
48
|
+
if (this.state.status === "pending") {
|
|
59
49
|
this.scheduleGc();
|
|
60
50
|
} else {
|
|
61
51
|
this.#mutationCache.remove(this);
|
|
@@ -63,8 +53,7 @@ class Mutation extends Removable {
|
|
|
63
53
|
}
|
|
64
54
|
}
|
|
65
55
|
continue() {
|
|
66
|
-
return this.#retryer?.continue() ??
|
|
67
|
-
// continuing a mutation assumes that variables are set, mutation must have been dehydrated before
|
|
56
|
+
return this.#retryer?.continue() ?? // continuing a mutation assumes that variables are set, mutation must have been dehydrated before
|
|
68
57
|
this.execute(this.state.variables);
|
|
69
58
|
}
|
|
70
59
|
async execute(variables) {
|
|
@@ -72,26 +61,18 @@ class Mutation extends Removable {
|
|
|
72
61
|
this.#retryer = createRetryer({
|
|
73
62
|
fn: () => {
|
|
74
63
|
if (!this.options.mutationFn) {
|
|
75
|
-
return Promise.reject(new Error(
|
|
64
|
+
return Promise.reject(new Error("No mutationFn found"));
|
|
76
65
|
}
|
|
77
66
|
return this.options.mutationFn(variables);
|
|
78
67
|
},
|
|
79
68
|
onFail: (failureCount, error) => {
|
|
80
|
-
this.#dispatch({
|
|
81
|
-
type: 'failed',
|
|
82
|
-
failureCount,
|
|
83
|
-
error
|
|
84
|
-
});
|
|
69
|
+
this.#dispatch({ type: "failed", failureCount, error });
|
|
85
70
|
},
|
|
86
71
|
onPause: () => {
|
|
87
|
-
this.#dispatch({
|
|
88
|
-
type: 'pause'
|
|
89
|
-
});
|
|
72
|
+
this.#dispatch({ type: "pause" });
|
|
90
73
|
},
|
|
91
74
|
onContinue: () => {
|
|
92
|
-
this.#dispatch({
|
|
93
|
-
type: 'continue'
|
|
94
|
-
});
|
|
75
|
+
this.#dispatch({ type: "continue" });
|
|
95
76
|
},
|
|
96
77
|
retry: this.options.retry ?? 0,
|
|
97
78
|
retryDelay: this.options.retryDelay,
|
|
@@ -99,118 +80,135 @@ class Mutation extends Removable {
|
|
|
99
80
|
});
|
|
100
81
|
return this.#retryer.promise;
|
|
101
82
|
};
|
|
102
|
-
const restored = this.state.status ===
|
|
83
|
+
const restored = this.state.status === "pending";
|
|
103
84
|
try {
|
|
104
85
|
if (!restored) {
|
|
105
|
-
this.#dispatch({
|
|
106
|
-
|
|
107
|
-
variables
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
await this.#mutationCache.config.onMutate?.(variables, this);
|
|
86
|
+
this.#dispatch({ type: "pending", variables });
|
|
87
|
+
await this.#mutationCache.config.onMutate?.(
|
|
88
|
+
variables,
|
|
89
|
+
this
|
|
90
|
+
);
|
|
111
91
|
const context = await this.options.onMutate?.(variables);
|
|
112
92
|
if (context !== this.state.context) {
|
|
113
93
|
this.#dispatch({
|
|
114
|
-
type:
|
|
94
|
+
type: "pending",
|
|
115
95
|
context,
|
|
116
96
|
variables
|
|
117
97
|
});
|
|
118
98
|
}
|
|
119
99
|
}
|
|
120
100
|
const data = await executeMutation();
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
101
|
+
await this.#mutationCache.config.onSuccess?.(
|
|
102
|
+
data,
|
|
103
|
+
variables,
|
|
104
|
+
this.state.context,
|
|
105
|
+
this
|
|
106
|
+
);
|
|
124
107
|
await this.options.onSuccess?.(data, variables, this.state.context);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
108
|
+
await this.#mutationCache.config.onSettled?.(
|
|
109
|
+
data,
|
|
110
|
+
null,
|
|
111
|
+
this.state.variables,
|
|
112
|
+
this.state.context,
|
|
113
|
+
this
|
|
114
|
+
);
|
|
128
115
|
await this.options.onSettled?.(data, null, variables, this.state.context);
|
|
129
|
-
this.#dispatch({
|
|
130
|
-
type: 'success',
|
|
131
|
-
data
|
|
132
|
-
});
|
|
116
|
+
this.#dispatch({ type: "success", data });
|
|
133
117
|
return data;
|
|
134
118
|
} catch (error) {
|
|
135
119
|
try {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
await this.options.
|
|
120
|
+
await this.#mutationCache.config.onError?.(
|
|
121
|
+
error,
|
|
122
|
+
variables,
|
|
123
|
+
this.state.context,
|
|
124
|
+
this
|
|
125
|
+
);
|
|
126
|
+
await this.options.onError?.(
|
|
127
|
+
error,
|
|
128
|
+
variables,
|
|
129
|
+
this.state.context
|
|
130
|
+
);
|
|
131
|
+
await this.#mutationCache.config.onSettled?.(
|
|
132
|
+
void 0,
|
|
133
|
+
error,
|
|
134
|
+
this.state.variables,
|
|
135
|
+
this.state.context,
|
|
136
|
+
this
|
|
137
|
+
);
|
|
138
|
+
await this.options.onSettled?.(
|
|
139
|
+
void 0,
|
|
140
|
+
error,
|
|
141
|
+
variables,
|
|
142
|
+
this.state.context
|
|
143
|
+
);
|
|
143
144
|
throw error;
|
|
144
145
|
} finally {
|
|
145
|
-
this.#dispatch({
|
|
146
|
-
type: 'error',
|
|
147
|
-
error: error
|
|
148
|
-
});
|
|
146
|
+
this.#dispatch({ type: "error", error });
|
|
149
147
|
}
|
|
150
148
|
}
|
|
151
149
|
}
|
|
152
150
|
#dispatch(action) {
|
|
153
|
-
const reducer = state => {
|
|
151
|
+
const reducer = (state) => {
|
|
154
152
|
switch (action.type) {
|
|
155
|
-
case
|
|
153
|
+
case "failed":
|
|
156
154
|
return {
|
|
157
155
|
...state,
|
|
158
156
|
failureCount: action.failureCount,
|
|
159
157
|
failureReason: action.error
|
|
160
158
|
};
|
|
161
|
-
case
|
|
159
|
+
case "pause":
|
|
162
160
|
return {
|
|
163
161
|
...state,
|
|
164
162
|
isPaused: true
|
|
165
163
|
};
|
|
166
|
-
case
|
|
164
|
+
case "continue":
|
|
167
165
|
return {
|
|
168
166
|
...state,
|
|
169
167
|
isPaused: false
|
|
170
168
|
};
|
|
171
|
-
case
|
|
169
|
+
case "pending":
|
|
172
170
|
return {
|
|
173
171
|
...state,
|
|
174
172
|
context: action.context,
|
|
175
|
-
data:
|
|
173
|
+
data: void 0,
|
|
176
174
|
failureCount: 0,
|
|
177
175
|
failureReason: null,
|
|
178
176
|
error: null,
|
|
179
177
|
isPaused: !canFetch(this.options.networkMode),
|
|
180
|
-
status:
|
|
178
|
+
status: "pending",
|
|
181
179
|
variables: action.variables,
|
|
182
180
|
submittedAt: Date.now()
|
|
183
181
|
};
|
|
184
|
-
case
|
|
182
|
+
case "success":
|
|
185
183
|
return {
|
|
186
184
|
...state,
|
|
187
185
|
data: action.data,
|
|
188
186
|
failureCount: 0,
|
|
189
187
|
failureReason: null,
|
|
190
188
|
error: null,
|
|
191
|
-
status:
|
|
189
|
+
status: "success",
|
|
192
190
|
isPaused: false
|
|
193
191
|
};
|
|
194
|
-
case
|
|
192
|
+
case "error":
|
|
195
193
|
return {
|
|
196
194
|
...state,
|
|
197
|
-
data:
|
|
195
|
+
data: void 0,
|
|
198
196
|
error: action.error,
|
|
199
197
|
failureCount: state.failureCount + 1,
|
|
200
198
|
failureReason: action.error,
|
|
201
199
|
isPaused: false,
|
|
202
|
-
status:
|
|
200
|
+
status: "error"
|
|
203
201
|
};
|
|
204
202
|
}
|
|
205
203
|
};
|
|
206
204
|
this.state = reducer(this.state);
|
|
207
205
|
notifyManager.batch(() => {
|
|
208
|
-
this.#observers.forEach(observer => {
|
|
206
|
+
this.#observers.forEach((observer) => {
|
|
209
207
|
observer.onMutationUpdate(action);
|
|
210
208
|
});
|
|
211
209
|
this.#mutationCache.notify({
|
|
212
210
|
mutation: this,
|
|
213
|
-
type:
|
|
211
|
+
type: "updated",
|
|
214
212
|
action
|
|
215
213
|
});
|
|
216
214
|
});
|
|
@@ -218,17 +216,19 @@ class Mutation extends Removable {
|
|
|
218
216
|
}
|
|
219
217
|
function getDefaultState() {
|
|
220
218
|
return {
|
|
221
|
-
context:
|
|
222
|
-
data:
|
|
219
|
+
context: void 0,
|
|
220
|
+
data: void 0,
|
|
223
221
|
error: null,
|
|
224
222
|
failureCount: 0,
|
|
225
223
|
failureReason: null,
|
|
226
224
|
isPaused: false,
|
|
227
|
-
status:
|
|
228
|
-
variables:
|
|
225
|
+
status: "idle",
|
|
226
|
+
variables: void 0,
|
|
229
227
|
submittedAt: 0
|
|
230
228
|
};
|
|
231
229
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
230
|
+
export {
|
|
231
|
+
Mutation,
|
|
232
|
+
getDefaultState
|
|
233
|
+
};
|
|
234
|
+
//# sourceMappingURL=mutation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mutation.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Removable } from './removable'\nimport { canFetch, createRetryer } from './retryer'\nimport type {\n DefaultError,\n MutationMeta,\n MutationOptions,\n MutationStatus,\n} from './types'\nimport type { MutationCache } from './mutationCache'\nimport type { MutationObserver } from './mutationObserver'\nimport type { Retryer } from './retryer'\n\n// TYPES\n\ninterface MutationConfig<TData, TError, TVariables, TContext> {\n mutationId: number\n mutationCache: MutationCache\n options: MutationOptions<TData, TError, TVariables, TContext>\n defaultOptions?: MutationOptions<TData, TError, TVariables, TContext>\n state?: MutationState<TData, TError, TVariables, TContext>\n}\n\nexport interface MutationState<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> {\n context: TContext | undefined\n data: TData | undefined\n error: TError | null\n failureCount: number\n failureReason: TError | null\n isPaused: boolean\n status: MutationStatus\n variables: TVariables | undefined\n submittedAt: number\n}\n\ninterface FailedAction<TError> {\n type: 'failed'\n failureCount: number\n error: TError | null\n}\n\ninterface PendingAction<TVariables, TContext> {\n type: 'pending'\n variables?: TVariables\n context?: TContext\n}\n\ninterface SuccessAction<TData> {\n type: 'success'\n data: TData\n}\n\ninterface ErrorAction<TError> {\n type: 'error'\n error: TError\n}\n\ninterface PauseAction {\n type: 'pause'\n}\n\ninterface ContinueAction {\n type: 'continue'\n}\n\nexport type Action<TData, TError, TVariables, TContext> =\n | ContinueAction\n | ErrorAction<TError>\n | FailedAction<TError>\n | PendingAction<TVariables, TContext>\n | PauseAction\n | SuccessAction<TData>\n\n// CLASS\n\nexport class Mutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> extends Removable {\n state: MutationState<TData, TError, TVariables, TContext>\n options!: MutationOptions<TData, TError, TVariables, TContext>\n readonly mutationId: number\n\n #observers: MutationObserver<TData, TError, TVariables, TContext>[]\n #defaultOptions?: MutationOptions<TData, TError, TVariables, TContext>\n #mutationCache: MutationCache\n #retryer?: Retryer<TData>\n\n constructor(config: MutationConfig<TData, TError, TVariables, TContext>) {\n super()\n\n this.mutationId = config.mutationId\n this.#defaultOptions = config.defaultOptions\n this.#mutationCache = config.mutationCache\n this.#observers = []\n this.state = config.state || getDefaultState()\n\n this.setOptions(config.options)\n this.scheduleGc()\n }\n\n setOptions(\n options?: MutationOptions<TData, TError, TVariables, TContext>,\n ): void {\n this.options = { ...this.#defaultOptions, ...options }\n\n this.updateGcTime(this.options.gcTime)\n }\n\n get meta(): MutationMeta | undefined {\n return this.options.meta\n }\n\n addObserver(observer: MutationObserver<any, any, any, any>): void {\n if (!this.#observers.includes(observer)) {\n this.#observers.push(observer)\n\n // Stop the mutation from being garbage collected\n this.clearGcTimeout()\n\n this.#mutationCache.notify({\n type: 'observerAdded',\n mutation: this,\n observer,\n })\n }\n }\n\n removeObserver(observer: MutationObserver<any, any, any, any>): void {\n this.#observers = this.#observers.filter((x) => x !== observer)\n\n this.scheduleGc()\n\n this.#mutationCache.notify({\n type: 'observerRemoved',\n mutation: this,\n observer,\n })\n }\n\n protected optionalRemove() {\n if (!this.#observers.length) {\n if (this.state.status === 'pending') {\n this.scheduleGc()\n } else {\n this.#mutationCache.remove(this)\n }\n }\n }\n\n continue(): Promise<unknown> {\n return (\n this.#retryer?.continue() ??\n // continuing a mutation assumes that variables are set, mutation must have been dehydrated before\n this.execute(this.state.variables!)\n )\n }\n\n async execute(variables: TVariables): Promise<TData> {\n const executeMutation = () => {\n this.#retryer = createRetryer({\n fn: () => {\n if (!this.options.mutationFn) {\n return Promise.reject(new Error('No mutationFn found'))\n }\n return this.options.mutationFn(variables)\n },\n onFail: (failureCount, error) => {\n this.#dispatch({ type: 'failed', failureCount, error })\n },\n onPause: () => {\n this.#dispatch({ type: 'pause' })\n },\n onContinue: () => {\n this.#dispatch({ type: 'continue' })\n },\n retry: this.options.retry ?? 0,\n retryDelay: this.options.retryDelay,\n networkMode: this.options.networkMode,\n })\n\n return this.#retryer.promise\n }\n\n const restored = this.state.status === 'pending'\n\n try {\n if (!restored) {\n this.#dispatch({ type: 'pending', variables })\n // Notify cache callback\n await this.#mutationCache.config.onMutate?.(\n variables,\n this as Mutation<unknown, unknown, unknown, unknown>,\n )\n const context = await this.options.onMutate?.(variables)\n if (context !== this.state.context) {\n this.#dispatch({\n type: 'pending',\n context,\n variables,\n })\n }\n }\n const data = await executeMutation()\n\n // Notify cache callback\n await this.#mutationCache.config.onSuccess?.(\n data,\n variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n )\n\n await this.options.onSuccess?.(data, variables, this.state.context)\n\n // Notify cache callback\n await this.#mutationCache.config.onSettled?.(\n data,\n null,\n this.state.variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n )\n\n await this.options.onSettled?.(data, null, variables, this.state.context)\n\n this.#dispatch({ type: 'success', data })\n return data\n } catch (error) {\n try {\n // Notify cache callback\n await this.#mutationCache.config.onError?.(\n error as any,\n variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n )\n\n await this.options.onError?.(\n error as TError,\n variables,\n this.state.context,\n )\n\n // Notify cache callback\n await this.#mutationCache.config.onSettled?.(\n undefined,\n error as any,\n this.state.variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n )\n\n await this.options.onSettled?.(\n undefined,\n error as TError,\n variables,\n this.state.context,\n )\n throw error\n } finally {\n this.#dispatch({ type: 'error', error: error as TError })\n }\n }\n }\n\n #dispatch(action: Action<TData, TError, TVariables, TContext>): void {\n const reducer = (\n state: MutationState<TData, TError, TVariables, TContext>,\n ): MutationState<TData, TError, TVariables, TContext> => {\n switch (action.type) {\n case 'failed':\n return {\n ...state,\n failureCount: action.failureCount,\n failureReason: action.error,\n }\n case 'pause':\n return {\n ...state,\n isPaused: true,\n }\n case 'continue':\n return {\n ...state,\n isPaused: false,\n }\n case 'pending':\n return {\n ...state,\n context: action.context,\n data: undefined,\n failureCount: 0,\n failureReason: null,\n error: null,\n isPaused: !canFetch(this.options.networkMode),\n status: 'pending',\n variables: action.variables,\n submittedAt: Date.now(),\n }\n case 'success':\n return {\n ...state,\n data: action.data,\n failureCount: 0,\n failureReason: null,\n error: null,\n status: 'success',\n isPaused: false,\n }\n case 'error':\n return {\n ...state,\n data: undefined,\n error: action.error,\n failureCount: state.failureCount + 1,\n failureReason: action.error,\n isPaused: false,\n status: 'error',\n }\n }\n }\n this.state = reducer(this.state)\n\n notifyManager.batch(() => {\n this.#observers.forEach((observer) => {\n observer.onMutationUpdate(action)\n })\n this.#mutationCache.notify({\n mutation: this,\n type: 'updated',\n action,\n })\n })\n }\n}\n\nexport function getDefaultState<\n TData,\n TError,\n TVariables,\n TContext,\n>(): MutationState<TData, TError, TVariables, TContext> {\n return {\n context: undefined,\n data: undefined,\n error: null,\n failureCount: 0,\n failureReason: null,\n isPaused: false,\n status: 'idle',\n variables: undefined,\n submittedAt: 0,\n }\n}\n"],"mappings":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