@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
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import {
|
|
2
|
+
isServer,
|
|
3
|
+
isValidTimeout,
|
|
4
|
+
noop,
|
|
5
|
+
replaceData,
|
|
6
|
+
shallowEqualObjects,
|
|
7
|
+
timeUntilStale
|
|
8
|
+
} from "./utils";
|
|
9
|
+
import { notifyManager } from "./notifyManager";
|
|
10
|
+
import { focusManager } from "./focusManager";
|
|
11
|
+
import { Subscribable } from "./subscribable";
|
|
12
|
+
import { canFetch } from "./retryer";
|
|
7
13
|
class QueryObserver extends Subscribable {
|
|
14
|
+
constructor(client, options) {
|
|
15
|
+
super();
|
|
16
|
+
this.#currentQuery = void 0;
|
|
17
|
+
this.#currentQueryInitialState = void 0;
|
|
18
|
+
this.#currentResult = void 0;
|
|
19
|
+
this.#trackedProps = /* @__PURE__ */ new Set();
|
|
20
|
+
this.#client = client;
|
|
21
|
+
this.options = options;
|
|
22
|
+
this.#selectError = null;
|
|
23
|
+
this.bindMethods();
|
|
24
|
+
this.setOptions(options);
|
|
25
|
+
}
|
|
8
26
|
#client;
|
|
9
|
-
#currentQuery
|
|
10
|
-
#currentQueryInitialState
|
|
11
|
-
#currentResult
|
|
27
|
+
#currentQuery;
|
|
28
|
+
#currentQueryInitialState;
|
|
29
|
+
#currentResult;
|
|
12
30
|
#currentResultState;
|
|
13
31
|
#currentResultOptions;
|
|
14
32
|
#selectError;
|
|
@@ -20,15 +38,7 @@ class QueryObserver extends Subscribable {
|
|
|
20
38
|
#staleTimeoutId;
|
|
21
39
|
#refetchIntervalId;
|
|
22
40
|
#currentRefetchInterval;
|
|
23
|
-
#trackedProps
|
|
24
|
-
constructor(client, options) {
|
|
25
|
-
super();
|
|
26
|
-
this.#client = client;
|
|
27
|
-
this.options = options;
|
|
28
|
-
this.#selectError = null;
|
|
29
|
-
this.bindMethods();
|
|
30
|
-
this.setOptions(options);
|
|
31
|
-
}
|
|
41
|
+
#trackedProps;
|
|
32
42
|
bindMethods() {
|
|
33
43
|
this.refetch = this.refetch.bind(this);
|
|
34
44
|
}
|
|
@@ -47,13 +57,21 @@ class QueryObserver extends Subscribable {
|
|
|
47
57
|
}
|
|
48
58
|
}
|
|
49
59
|
shouldFetchOnReconnect() {
|
|
50
|
-
return shouldFetchOn(
|
|
60
|
+
return shouldFetchOn(
|
|
61
|
+
this.#currentQuery,
|
|
62
|
+
this.options,
|
|
63
|
+
this.options.refetchOnReconnect
|
|
64
|
+
);
|
|
51
65
|
}
|
|
52
66
|
shouldFetchOnWindowFocus() {
|
|
53
|
-
return shouldFetchOn(
|
|
67
|
+
return shouldFetchOn(
|
|
68
|
+
this.#currentQuery,
|
|
69
|
+
this.options,
|
|
70
|
+
this.options.refetchOnWindowFocus
|
|
71
|
+
);
|
|
54
72
|
}
|
|
55
73
|
destroy() {
|
|
56
|
-
this.listeners = new Set();
|
|
74
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
57
75
|
this.#clearStaleTimeout();
|
|
58
76
|
this.#clearRefetchInterval();
|
|
59
77
|
this.#currentQuery.removeObserver(this);
|
|
@@ -64,37 +82,32 @@ class QueryObserver extends Subscribable {
|
|
|
64
82
|
this.options = this.#client.defaultQueryOptions(options);
|
|
65
83
|
if (!shallowEqualObjects(prevOptions, this.options)) {
|
|
66
84
|
this.#client.getQueryCache().notify({
|
|
67
|
-
type:
|
|
85
|
+
type: "observerOptionsUpdated",
|
|
68
86
|
query: this.#currentQuery,
|
|
69
87
|
observer: this
|
|
70
88
|
});
|
|
71
89
|
}
|
|
72
|
-
if (typeof this.options.enabled !==
|
|
73
|
-
throw new Error(
|
|
90
|
+
if (typeof this.options.enabled !== "undefined" && typeof this.options.enabled !== "boolean") {
|
|
91
|
+
throw new Error("Expected enabled to be a boolean");
|
|
74
92
|
}
|
|
75
|
-
|
|
76
|
-
// Keep previous query key if the user does not supply one
|
|
77
93
|
if (!this.options.queryKey) {
|
|
78
94
|
this.options.queryKey = prevOptions.queryKey;
|
|
79
95
|
}
|
|
80
96
|
this.#updateQuery();
|
|
81
97
|
const mounted = this.hasListeners();
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
98
|
+
if (mounted && shouldFetchOptionally(
|
|
99
|
+
this.#currentQuery,
|
|
100
|
+
prevQuery,
|
|
101
|
+
this.options,
|
|
102
|
+
prevOptions
|
|
103
|
+
)) {
|
|
85
104
|
this.#executeFetch();
|
|
86
105
|
}
|
|
87
|
-
|
|
88
|
-
// Update result
|
|
89
106
|
this.updateResult(notifyOptions);
|
|
90
|
-
|
|
91
|
-
// Update stale interval if needed
|
|
92
107
|
if (mounted && (this.#currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
|
|
93
108
|
this.#updateStaleTimeout();
|
|
94
109
|
}
|
|
95
110
|
const nextRefetchInterval = this.#computeRefetchInterval();
|
|
96
|
-
|
|
97
|
-
// Update refetch interval if needed
|
|
98
111
|
if (mounted && (this.#currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== this.#currentRefetchInterval)) {
|
|
99
112
|
this.#updateRefetchInterval(nextRefetchInterval);
|
|
100
113
|
}
|
|
@@ -103,22 +116,6 @@ class QueryObserver extends Subscribable {
|
|
|
103
116
|
const query = this.#client.getQueryCache().build(this.#client, options);
|
|
104
117
|
const result = this.createResult(query, options);
|
|
105
118
|
if (shouldAssignObserverCurrentProperties(this, result)) {
|
|
106
|
-
// this assigns the optimistic result to the current Observer
|
|
107
|
-
// because if the query function changes, useQuery will be performing
|
|
108
|
-
// an effect where it would fetch again.
|
|
109
|
-
// When the fetch finishes, we perform a deep data cloning in order
|
|
110
|
-
// to reuse objects references. This deep data clone is performed against
|
|
111
|
-
// the `observer.currentResult.data` property
|
|
112
|
-
// When QueryKey changes, we refresh the query and get new `optimistic`
|
|
113
|
-
// result, while we leave the `observer.currentResult`, so when new data
|
|
114
|
-
// arrives, it finds the old `observer.currentResult` which is related
|
|
115
|
-
// to the old QueryKey. Which means that currentResult and selectData are
|
|
116
|
-
// out of sync already.
|
|
117
|
-
// To solve this, we move the cursor of the currentResult everytime
|
|
118
|
-
// an observer reads an optimistic value.
|
|
119
|
-
|
|
120
|
-
// When keeping the previous data, the result doesn't change until new
|
|
121
|
-
// data arrives.
|
|
122
119
|
this.#currentResult = result;
|
|
123
120
|
this.#currentResultOptions = this.options;
|
|
124
121
|
this.#currentResultState = this.#currentQuery.state;
|
|
@@ -130,7 +127,7 @@ class QueryObserver extends Subscribable {
|
|
|
130
127
|
}
|
|
131
128
|
trackResult(result) {
|
|
132
129
|
const trackedResult = {};
|
|
133
|
-
Object.keys(result).forEach(key => {
|
|
130
|
+
Object.keys(result).forEach((key) => {
|
|
134
131
|
Object.defineProperty(trackedResult, key, {
|
|
135
132
|
configurable: false,
|
|
136
133
|
enumerable: true,
|
|
@@ -145,9 +142,7 @@ class QueryObserver extends Subscribable {
|
|
|
145
142
|
getCurrentQuery() {
|
|
146
143
|
return this.#currentQuery;
|
|
147
144
|
}
|
|
148
|
-
refetch({
|
|
149
|
-
...options
|
|
150
|
-
} = {}) {
|
|
145
|
+
refetch({ ...options } = {}) {
|
|
151
146
|
return this.fetch({
|
|
152
147
|
...options
|
|
153
148
|
});
|
|
@@ -168,11 +163,11 @@ class QueryObserver extends Subscribable {
|
|
|
168
163
|
});
|
|
169
164
|
}
|
|
170
165
|
#executeFetch(fetchOptions) {
|
|
171
|
-
// Make sure we reference the latest query as the current one might have been removed
|
|
172
166
|
this.#updateQuery();
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
167
|
+
let promise = this.#currentQuery.fetch(
|
|
168
|
+
this.options,
|
|
169
|
+
fetchOptions
|
|
170
|
+
);
|
|
176
171
|
if (!fetchOptions?.throwOnError) {
|
|
177
172
|
promise = promise.catch(noop);
|
|
178
173
|
}
|
|
@@ -183,10 +178,10 @@ class QueryObserver extends Subscribable {
|
|
|
183
178
|
if (isServer || this.#currentResult.isStale || !isValidTimeout(this.options.staleTime)) {
|
|
184
179
|
return;
|
|
185
180
|
}
|
|
186
|
-
const time = timeUntilStale(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
181
|
+
const time = timeUntilStale(
|
|
182
|
+
this.#currentResult.dataUpdatedAt,
|
|
183
|
+
this.options.staleTime
|
|
184
|
+
);
|
|
190
185
|
const timeout = time + 1;
|
|
191
186
|
this.#staleTimeoutId = setTimeout(() => {
|
|
192
187
|
if (!this.#currentResult.isStale) {
|
|
@@ -195,7 +190,10 @@ class QueryObserver extends Subscribable {
|
|
|
195
190
|
}, timeout);
|
|
196
191
|
}
|
|
197
192
|
#computeRefetchInterval() {
|
|
198
|
-
return (typeof this.options.refetchInterval ===
|
|
193
|
+
return (typeof this.options.refetchInterval === "function" ? this.options.refetchInterval(
|
|
194
|
+
this.#currentResult.data,
|
|
195
|
+
this.#currentQuery
|
|
196
|
+
) : this.options.refetchInterval) ?? false;
|
|
199
197
|
}
|
|
200
198
|
#updateRefetchInterval(nextInterval) {
|
|
201
199
|
this.#clearRefetchInterval();
|
|
@@ -216,13 +214,13 @@ class QueryObserver extends Subscribable {
|
|
|
216
214
|
#clearStaleTimeout() {
|
|
217
215
|
if (this.#staleTimeoutId) {
|
|
218
216
|
clearTimeout(this.#staleTimeoutId);
|
|
219
|
-
this.#staleTimeoutId =
|
|
217
|
+
this.#staleTimeoutId = void 0;
|
|
220
218
|
}
|
|
221
219
|
}
|
|
222
220
|
#clearRefetchInterval() {
|
|
223
221
|
if (this.#refetchIntervalId) {
|
|
224
222
|
clearInterval(this.#refetchIntervalId);
|
|
225
|
-
this.#refetchIntervalId =
|
|
223
|
+
this.#refetchIntervalId = void 0;
|
|
226
224
|
}
|
|
227
225
|
}
|
|
228
226
|
createResult(query, options) {
|
|
@@ -233,37 +231,25 @@ class QueryObserver extends Subscribable {
|
|
|
233
231
|
const prevResultOptions = this.#currentResultOptions;
|
|
234
232
|
const queryChange = query !== prevQuery;
|
|
235
233
|
const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
|
|
236
|
-
const {
|
|
237
|
-
|
|
238
|
-
} = query;
|
|
239
|
-
let {
|
|
240
|
-
error,
|
|
241
|
-
errorUpdatedAt,
|
|
242
|
-
fetchStatus,
|
|
243
|
-
status
|
|
244
|
-
} = state;
|
|
234
|
+
const { state } = query;
|
|
235
|
+
let { error, errorUpdatedAt, fetchStatus, status } = state;
|
|
245
236
|
let isPlaceholderData = false;
|
|
246
237
|
let data;
|
|
247
|
-
|
|
248
|
-
// Optimistically set result in fetching state if needed
|
|
249
238
|
if (options._optimisticResults) {
|
|
250
239
|
const mounted = this.hasListeners();
|
|
251
240
|
const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
|
|
252
241
|
const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
|
|
253
242
|
if (fetchOnMount || fetchOptionally) {
|
|
254
|
-
fetchStatus = canFetch(query.options.networkMode) ?
|
|
243
|
+
fetchStatus = canFetch(query.options.networkMode) ? "fetching" : "paused";
|
|
255
244
|
if (!state.dataUpdatedAt) {
|
|
256
|
-
status =
|
|
245
|
+
status = "pending";
|
|
257
246
|
}
|
|
258
247
|
}
|
|
259
|
-
if (options._optimisticResults ===
|
|
260
|
-
fetchStatus =
|
|
248
|
+
if (options._optimisticResults === "isRestoring") {
|
|
249
|
+
fetchStatus = "idle";
|
|
261
250
|
}
|
|
262
251
|
}
|
|
263
|
-
|
|
264
|
-
// Select data if needed
|
|
265
|
-
if (options.select && typeof state.data !== 'undefined') {
|
|
266
|
-
// Memoize select result
|
|
252
|
+
if (options.select && typeof state.data !== "undefined") {
|
|
267
253
|
if (prevResult && state.data === prevResultState?.data && options.select === this.#selectFn) {
|
|
268
254
|
data = this.#selectResult;
|
|
269
255
|
} else {
|
|
@@ -277,22 +263,19 @@ class QueryObserver extends Subscribable {
|
|
|
277
263
|
this.#selectError = selectError;
|
|
278
264
|
}
|
|
279
265
|
}
|
|
280
|
-
}
|
|
281
|
-
// Use query data
|
|
282
|
-
else {
|
|
266
|
+
} else {
|
|
283
267
|
data = state.data;
|
|
284
268
|
}
|
|
285
|
-
|
|
286
|
-
// Show placeholder data if needed
|
|
287
|
-
if (typeof options.placeholderData !== 'undefined' && typeof data === 'undefined' && status === 'pending') {
|
|
269
|
+
if (typeof options.placeholderData !== "undefined" && typeof data === "undefined" && status === "pending") {
|
|
288
270
|
let placeholderData;
|
|
289
|
-
|
|
290
|
-
// Memoize placeholder data
|
|
291
271
|
if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
|
|
292
272
|
placeholderData = prevResult.data;
|
|
293
273
|
} else {
|
|
294
|
-
placeholderData = typeof options.placeholderData ===
|
|
295
|
-
|
|
274
|
+
placeholderData = typeof options.placeholderData === "function" ? options.placeholderData(
|
|
275
|
+
this.#lastQueryWithDefinedData?.state.data,
|
|
276
|
+
this.#lastQueryWithDefinedData
|
|
277
|
+
) : options.placeholderData;
|
|
278
|
+
if (options.select && typeof placeholderData !== "undefined") {
|
|
296
279
|
try {
|
|
297
280
|
placeholderData = options.select(placeholderData);
|
|
298
281
|
this.#selectError = null;
|
|
@@ -301,9 +284,13 @@ class QueryObserver extends Subscribable {
|
|
|
301
284
|
}
|
|
302
285
|
}
|
|
303
286
|
}
|
|
304
|
-
if (typeof placeholderData !==
|
|
305
|
-
status =
|
|
306
|
-
data = replaceData(
|
|
287
|
+
if (typeof placeholderData !== "undefined") {
|
|
288
|
+
status = "success";
|
|
289
|
+
data = replaceData(
|
|
290
|
+
prevResult?.data,
|
|
291
|
+
placeholderData,
|
|
292
|
+
options
|
|
293
|
+
);
|
|
307
294
|
isPlaceholderData = true;
|
|
308
295
|
}
|
|
309
296
|
}
|
|
@@ -311,17 +298,17 @@ class QueryObserver extends Subscribable {
|
|
|
311
298
|
error = this.#selectError;
|
|
312
299
|
data = this.#selectResult;
|
|
313
300
|
errorUpdatedAt = Date.now();
|
|
314
|
-
status =
|
|
301
|
+
status = "error";
|
|
315
302
|
}
|
|
316
|
-
const isFetching = fetchStatus ===
|
|
317
|
-
const isPending = status ===
|
|
318
|
-
const isError = status ===
|
|
303
|
+
const isFetching = fetchStatus === "fetching";
|
|
304
|
+
const isPending = status === "pending";
|
|
305
|
+
const isError = status === "error";
|
|
319
306
|
const isLoading = isPending && isFetching;
|
|
320
307
|
const result = {
|
|
321
308
|
status,
|
|
322
309
|
fetchStatus,
|
|
323
310
|
isPending,
|
|
324
|
-
isSuccess: status ===
|
|
311
|
+
isSuccess: status === "success",
|
|
325
312
|
isError,
|
|
326
313
|
isInitialLoading: isLoading,
|
|
327
314
|
isLoading,
|
|
@@ -337,7 +324,7 @@ class QueryObserver extends Subscribable {
|
|
|
337
324
|
isFetching,
|
|
338
325
|
isRefetching: isFetching && !isPending,
|
|
339
326
|
isLoadingError: isError && state.dataUpdatedAt === 0,
|
|
340
|
-
isPaused: fetchStatus ===
|
|
327
|
+
isPaused: fetchStatus === "paused",
|
|
341
328
|
isPlaceholderData,
|
|
342
329
|
isRefetchError: isError && state.dataUpdatedAt !== 0,
|
|
343
330
|
isStale: isStale(query, options),
|
|
@@ -350,33 +337,27 @@ class QueryObserver extends Subscribable {
|
|
|
350
337
|
const nextResult = this.createResult(this.#currentQuery, this.options);
|
|
351
338
|
this.#currentResultState = this.#currentQuery.state;
|
|
352
339
|
this.#currentResultOptions = this.options;
|
|
353
|
-
|
|
354
|
-
// Only notify and update result if something has changed
|
|
355
340
|
if (shallowEqualObjects(nextResult, prevResult)) {
|
|
356
341
|
return;
|
|
357
342
|
}
|
|
358
|
-
if (this.#currentResultState.data !==
|
|
343
|
+
if (this.#currentResultState.data !== void 0) {
|
|
359
344
|
this.#lastQueryWithDefinedData = this.#currentQuery;
|
|
360
345
|
}
|
|
361
346
|
this.#currentResult = nextResult;
|
|
362
|
-
|
|
363
|
-
// Determine which callbacks to trigger
|
|
364
347
|
const defaultNotifyOptions = {};
|
|
365
348
|
const shouldNotifyListeners = () => {
|
|
366
349
|
if (!prevResult) {
|
|
367
350
|
return true;
|
|
368
351
|
}
|
|
369
|
-
const {
|
|
370
|
-
|
|
371
|
-
} = this.options;
|
|
372
|
-
if (notifyOnChangeProps === 'all' || !notifyOnChangeProps && !this.#trackedProps.size) {
|
|
352
|
+
const { notifyOnChangeProps } = this.options;
|
|
353
|
+
if (notifyOnChangeProps === "all" || !notifyOnChangeProps && !this.#trackedProps.size) {
|
|
373
354
|
return true;
|
|
374
355
|
}
|
|
375
356
|
const includedProps = new Set(notifyOnChangeProps ?? this.#trackedProps);
|
|
376
357
|
if (this.options.throwOnError) {
|
|
377
|
-
includedProps.add(
|
|
358
|
+
includedProps.add("error");
|
|
378
359
|
}
|
|
379
|
-
return Object.keys(this.#currentResult).some(key => {
|
|
360
|
+
return Object.keys(this.#currentResult).some((key) => {
|
|
380
361
|
const typedKey = key;
|
|
381
362
|
const changed = this.#currentResult[typedKey] !== prevResult[typedKey];
|
|
382
363
|
return changed && includedProps.has(typedKey);
|
|
@@ -385,10 +366,7 @@ class QueryObserver extends Subscribable {
|
|
|
385
366
|
if (notifyOptions?.listeners !== false && shouldNotifyListeners()) {
|
|
386
367
|
defaultNotifyOptions.listeners = true;
|
|
387
368
|
}
|
|
388
|
-
this.#notify({
|
|
389
|
-
...defaultNotifyOptions,
|
|
390
|
-
...notifyOptions
|
|
391
|
-
});
|
|
369
|
+
this.#notify({ ...defaultNotifyOptions, ...notifyOptions });
|
|
392
370
|
}
|
|
393
371
|
#updateQuery() {
|
|
394
372
|
const query = this.#client.getQueryCache().build(this.#client, this.options);
|
|
@@ -411,53 +389,44 @@ class QueryObserver extends Subscribable {
|
|
|
411
389
|
}
|
|
412
390
|
#notify(notifyOptions) {
|
|
413
391
|
notifyManager.batch(() => {
|
|
414
|
-
// First, trigger the listeners
|
|
415
392
|
if (notifyOptions.listeners) {
|
|
416
|
-
this.listeners.forEach(listener => {
|
|
393
|
+
this.listeners.forEach((listener) => {
|
|
417
394
|
listener(this.#currentResult);
|
|
418
395
|
});
|
|
419
396
|
}
|
|
420
|
-
|
|
421
|
-
// Then the cache listeners
|
|
422
397
|
this.#client.getQueryCache().notify({
|
|
423
398
|
query: this.#currentQuery,
|
|
424
|
-
type:
|
|
399
|
+
type: "observerResultsUpdated"
|
|
425
400
|
});
|
|
426
401
|
});
|
|
427
402
|
}
|
|
428
403
|
}
|
|
429
404
|
function shouldLoadOnMount(query, options) {
|
|
430
|
-
return options.enabled !== false && !query.state.dataUpdatedAt && !(query.state.status ===
|
|
405
|
+
return options.enabled !== false && !query.state.dataUpdatedAt && !(query.state.status === "error" && options.retryOnMount === false);
|
|
431
406
|
}
|
|
432
407
|
function shouldFetchOnMount(query, options) {
|
|
433
408
|
return shouldLoadOnMount(query, options) || query.state.dataUpdatedAt > 0 && shouldFetchOn(query, options, options.refetchOnMount);
|
|
434
409
|
}
|
|
435
410
|
function shouldFetchOn(query, options, field) {
|
|
436
411
|
if (options.enabled !== false) {
|
|
437
|
-
const value = typeof field ===
|
|
438
|
-
return value ===
|
|
412
|
+
const value = typeof field === "function" ? field(query) : field;
|
|
413
|
+
return value === "always" || value !== false && isStale(query, options);
|
|
439
414
|
}
|
|
440
415
|
return false;
|
|
441
416
|
}
|
|
442
417
|
function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
|
|
443
|
-
return options.enabled !== false && (query !== prevQuery || prevOptions.enabled === false) && (!options.suspense || query.state.status !==
|
|
418
|
+
return options.enabled !== false && (query !== prevQuery || prevOptions.enabled === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
|
|
444
419
|
}
|
|
445
420
|
function isStale(query, options) {
|
|
446
421
|
return query.isStaleByTime(options.staleTime);
|
|
447
422
|
}
|
|
448
|
-
|
|
449
|
-
// this function would decide if we will update the observer's 'current'
|
|
450
|
-
// properties after an optimistic reading via getOptimisticResult
|
|
451
423
|
function shouldAssignObserverCurrentProperties(observer, optimisticResult) {
|
|
452
|
-
// if the newly created result isn't what the observer is holding as current,
|
|
453
|
-
// then we'll need to update the properties as well
|
|
454
424
|
if (observer.getCurrentResult() !== optimisticResult) {
|
|
455
425
|
return true;
|
|
456
426
|
}
|
|
457
|
-
|
|
458
|
-
// basically, just keep previous properties if nothing changed
|
|
459
427
|
return false;
|
|
460
428
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
429
|
+
export {
|
|
430
|
+
QueryObserver
|
|
431
|
+
};
|
|
432
|
+
//# sourceMappingURL=queryObserver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/queryObserver.ts"],"sourcesContent":["import {\n isServer,\n isValidTimeout,\n noop,\n replaceData,\n shallowEqualObjects,\n timeUntilStale,\n} from './utils'\nimport { notifyManager } from './notifyManager'\nimport { focusManager } from './focusManager'\nimport { Subscribable } from './subscribable'\nimport { canFetch } from './retryer'\nimport type { QueryClient } from './queryClient'\nimport type { FetchOptions, Query, QueryState } from './query'\nimport type {\n DefaultError,\n DefaultedQueryObserverOptions,\n PlaceholderDataFunction,\n QueryKey,\n QueryObserverBaseResult,\n QueryObserverOptions,\n QueryObserverResult,\n QueryOptions,\n RefetchOptions,\n} from './types'\n\ntype QueryObserverListener<TData, TError> = (\n result: QueryObserverResult<TData, TError>,\n) => void\n\nexport interface NotifyOptions {\n listeners?: boolean\n}\n\nexport interface ObserverFetchOptions extends FetchOptions {\n throwOnError?: boolean\n}\n\nexport class QueryObserver<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends Subscribable<QueryObserverListener<TData, TError>> {\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n\n #client: QueryClient\n #currentQuery: Query<TQueryFnData, TError, TQueryData, TQueryKey> = undefined!\n #currentQueryInitialState: QueryState<TQueryData, TError> = undefined!\n #currentResult: QueryObserverResult<TData, TError> = undefined!\n #currentResultState?: QueryState<TQueryData, TError>\n #currentResultOptions?: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n #selectError: TError | null\n #selectFn?: (data: TQueryData) => TData\n #selectResult?: TData\n // This property keeps track of the last query with defined data.\n // It will be used to pass the previous data and query to the placeholder function between renders.\n #lastQueryWithDefinedData?: Query<TQueryFnData, TError, TQueryData, TQueryKey>\n #staleTimeoutId?: ReturnType<typeof setTimeout>\n #refetchIntervalId?: ReturnType<typeof setInterval>\n #currentRefetchInterval?: number | false\n #trackedProps: Set<keyof QueryObserverResult> = new Set()\n\n constructor(\n client: QueryClient,\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ) {\n super()\n\n this.#client = client\n this.options = options\n this.#selectError = null\n this.bindMethods()\n this.setOptions(options)\n }\n\n protected bindMethods(): void {\n this.refetch = this.refetch.bind(this)\n }\n\n protected onSubscribe(): void {\n if (this.listeners.size === 1) {\n this.#currentQuery.addObserver(this)\n\n if (shouldFetchOnMount(this.#currentQuery, this.options)) {\n this.#executeFetch()\n }\n\n this.#updateTimers()\n }\n }\n\n protected onUnsubscribe(): void {\n if (!this.hasListeners()) {\n this.destroy()\n }\n }\n\n shouldFetchOnReconnect(): boolean {\n return shouldFetchOn(\n this.#currentQuery,\n this.options,\n this.options.refetchOnReconnect,\n )\n }\n\n shouldFetchOnWindowFocus(): boolean {\n return shouldFetchOn(\n this.#currentQuery,\n this.options,\n this.options.refetchOnWindowFocus,\n )\n }\n\n destroy(): void {\n this.listeners = new Set()\n this.#clearStaleTimeout()\n this.#clearRefetchInterval()\n this.#currentQuery.removeObserver(this)\n }\n\n setOptions(\n options?: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n notifyOptions?: NotifyOptions,\n ): void {\n const prevOptions = this.options\n const prevQuery = this.#currentQuery\n\n this.options = this.#client.defaultQueryOptions(options)\n\n if (!shallowEqualObjects(prevOptions, this.options)) {\n this.#client.getQueryCache().notify({\n type: 'observerOptionsUpdated',\n query: this.#currentQuery,\n observer: this,\n })\n }\n\n if (\n typeof this.options.enabled !== 'undefined' &&\n typeof this.options.enabled !== 'boolean'\n ) {\n throw new Error('Expected enabled to be a boolean')\n }\n\n // Keep previous query key if the user does not supply one\n if (!this.options.queryKey) {\n this.options.queryKey = prevOptions.queryKey\n }\n\n this.#updateQuery()\n\n const mounted = this.hasListeners()\n\n // Fetch if there are subscribers\n if (\n mounted &&\n shouldFetchOptionally(\n this.#currentQuery,\n prevQuery,\n this.options,\n prevOptions,\n )\n ) {\n this.#executeFetch()\n }\n\n // Update result\n this.updateResult(notifyOptions)\n\n // Update stale interval if needed\n if (\n mounted &&\n (this.#currentQuery !== prevQuery ||\n this.options.enabled !== prevOptions.enabled ||\n this.options.staleTime !== prevOptions.staleTime)\n ) {\n this.#updateStaleTimeout()\n }\n\n const nextRefetchInterval = this.#computeRefetchInterval()\n\n // Update refetch interval if needed\n if (\n mounted &&\n (this.#currentQuery !== prevQuery ||\n this.options.enabled !== prevOptions.enabled ||\n nextRefetchInterval !== this.#currentRefetchInterval)\n ) {\n this.#updateRefetchInterval(nextRefetchInterval)\n }\n }\n\n getOptimisticResult(\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): QueryObserverResult<TData, TError> {\n const query = this.#client.getQueryCache().build(this.#client, options)\n\n const result = this.createResult(query, options)\n\n if (shouldAssignObserverCurrentProperties(this, result)) {\n // this assigns the optimistic result to the current Observer\n // because if the query function changes, useQuery will be performing\n // an effect where it would fetch again.\n // When the fetch finishes, we perform a deep data cloning in order\n // to reuse objects references. This deep data clone is performed against\n // the `observer.currentResult.data` property\n // When QueryKey changes, we refresh the query and get new `optimistic`\n // result, while we leave the `observer.currentResult`, so when new data\n // arrives, it finds the old `observer.currentResult` which is related\n // to the old QueryKey. Which means that currentResult and selectData are\n // out of sync already.\n // To solve this, we move the cursor of the currentResult everytime\n // an observer reads an optimistic value.\n\n // When keeping the previous data, the result doesn't change until new\n // data arrives.\n this.#currentResult = result\n this.#currentResultOptions = this.options\n this.#currentResultState = this.#currentQuery.state\n }\n return result\n }\n\n getCurrentResult(): QueryObserverResult<TData, TError> {\n return this.#currentResult\n }\n\n trackResult(\n result: QueryObserverResult<TData, TError>,\n ): QueryObserverResult<TData, TError> {\n const trackedResult = {} as QueryObserverResult<TData, TError>\n\n Object.keys(result).forEach((key) => {\n Object.defineProperty(trackedResult, key, {\n configurable: false,\n enumerable: true,\n get: () => {\n this.#trackedProps.add(key as keyof QueryObserverResult)\n return result[key as keyof QueryObserverResult]\n },\n })\n })\n\n return trackedResult\n }\n\n getCurrentQuery(): Query<TQueryFnData, TError, TQueryData, TQueryKey> {\n return this.#currentQuery\n }\n\n refetch({ ...options }: RefetchOptions = {}): Promise<\n QueryObserverResult<TData, TError>\n > {\n return this.fetch({\n ...options,\n })\n }\n\n fetchOptimistic(\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): Promise<QueryObserverResult<TData, TError>> {\n const defaultedOptions = this.#client.defaultQueryOptions(options)\n\n const query = this.#client\n .getQueryCache()\n .build(this.#client, defaultedOptions)\n query.isFetchingOptimistic = true\n\n return query.fetch().then(() => this.createResult(query, defaultedOptions))\n }\n\n protected fetch(\n fetchOptions: ObserverFetchOptions,\n ): Promise<QueryObserverResult<TData, TError>> {\n return this.#executeFetch({\n ...fetchOptions,\n cancelRefetch: fetchOptions.cancelRefetch ?? true,\n }).then(() => {\n this.updateResult()\n return this.#currentResult\n })\n }\n\n #executeFetch(\n fetchOptions?: ObserverFetchOptions,\n ): Promise<TQueryData | undefined> {\n // Make sure we reference the latest query as the current one might have been removed\n this.#updateQuery()\n\n // Fetch\n let promise: Promise<TQueryData | undefined> = this.#currentQuery.fetch(\n this.options as QueryOptions<TQueryFnData, TError, TQueryData, TQueryKey>,\n fetchOptions,\n )\n\n if (!fetchOptions?.throwOnError) {\n promise = promise.catch(noop)\n }\n\n return promise\n }\n\n #updateStaleTimeout(): void {\n this.#clearStaleTimeout()\n\n if (\n isServer ||\n this.#currentResult.isStale ||\n !isValidTimeout(this.options.staleTime)\n ) {\n return\n }\n\n const time = timeUntilStale(\n this.#currentResult.dataUpdatedAt,\n this.options.staleTime,\n )\n\n // The timeout is sometimes triggered 1 ms before the stale time expiration.\n // To mitigate this issue we always add 1 ms to the timeout.\n const timeout = time + 1\n\n this.#staleTimeoutId = setTimeout(() => {\n if (!this.#currentResult.isStale) {\n this.updateResult()\n }\n }, timeout)\n }\n\n #computeRefetchInterval() {\n return (\n (typeof this.options.refetchInterval === 'function'\n ? this.options.refetchInterval(\n this.#currentResult.data,\n this.#currentQuery,\n )\n : this.options.refetchInterval) ?? false\n )\n }\n\n #updateRefetchInterval(nextInterval: number | false): void {\n this.#clearRefetchInterval()\n\n this.#currentRefetchInterval = nextInterval\n\n if (\n isServer ||\n this.options.enabled === false ||\n !isValidTimeout(this.#currentRefetchInterval) ||\n this.#currentRefetchInterval === 0\n ) {\n return\n }\n\n this.#refetchIntervalId = setInterval(() => {\n if (\n this.options.refetchIntervalInBackground ||\n focusManager.isFocused()\n ) {\n this.#executeFetch()\n }\n }, this.#currentRefetchInterval)\n }\n\n #updateTimers(): void {\n this.#updateStaleTimeout()\n this.#updateRefetchInterval(this.#computeRefetchInterval())\n }\n\n #clearStaleTimeout(): void {\n if (this.#staleTimeoutId) {\n clearTimeout(this.#staleTimeoutId)\n this.#staleTimeoutId = undefined\n }\n }\n\n #clearRefetchInterval(): void {\n if (this.#refetchIntervalId) {\n clearInterval(this.#refetchIntervalId)\n this.#refetchIntervalId = undefined\n }\n }\n\n protected createResult(\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): QueryObserverResult<TData, TError> {\n const prevQuery = this.#currentQuery\n const prevOptions = this.options\n const prevResult = this.#currentResult as\n | QueryObserverResult<TData, TError>\n | undefined\n const prevResultState = this.#currentResultState\n const prevResultOptions = this.#currentResultOptions\n const queryChange = query !== prevQuery\n const queryInitialState = queryChange\n ? query.state\n : this.#currentQueryInitialState\n\n const { state } = query\n let { error, errorUpdatedAt, fetchStatus, status } = state\n let isPlaceholderData = false\n let data: TData | undefined\n\n // Optimistically set result in fetching state if needed\n if (options._optimisticResults) {\n const mounted = this.hasListeners()\n\n const fetchOnMount = !mounted && shouldFetchOnMount(query, options)\n\n const fetchOptionally =\n mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions)\n\n if (fetchOnMount || fetchOptionally) {\n fetchStatus = canFetch(query.options.networkMode)\n ? 'fetching'\n : 'paused'\n if (!state.dataUpdatedAt) {\n status = 'pending'\n }\n }\n if (options._optimisticResults === 'isRestoring') {\n fetchStatus = 'idle'\n }\n }\n\n // Select data if needed\n if (options.select && typeof state.data !== 'undefined') {\n // Memoize select result\n if (\n prevResult &&\n state.data === prevResultState?.data &&\n options.select === this.#selectFn\n ) {\n data = this.#selectResult\n } else {\n try {\n this.#selectFn = options.select\n data = options.select(state.data)\n data = replaceData(prevResult?.data, data, options)\n this.#selectResult = data\n this.#selectError = null\n } catch (selectError) {\n this.#selectError = selectError as TError\n }\n }\n }\n // Use query data\n else {\n data = state.data as unknown as TData\n }\n\n // Show placeholder data if needed\n if (\n typeof options.placeholderData !== 'undefined' &&\n typeof data === 'undefined' &&\n status === 'pending'\n ) {\n let placeholderData\n\n // Memoize placeholder data\n if (\n prevResult?.isPlaceholderData &&\n options.placeholderData === prevResultOptions?.placeholderData\n ) {\n placeholderData = prevResult.data\n } else {\n placeholderData =\n typeof options.placeholderData === 'function'\n ? (\n options.placeholderData as unknown as PlaceholderDataFunction<TQueryData>\n )(\n this.#lastQueryWithDefinedData?.state.data,\n this.#lastQueryWithDefinedData as any,\n )\n : options.placeholderData\n if (options.select && typeof placeholderData !== 'undefined') {\n try {\n placeholderData = options.select(placeholderData)\n this.#selectError = null\n } catch (selectError) {\n this.#selectError = selectError as TError\n }\n }\n }\n\n if (typeof placeholderData !== 'undefined') {\n status = 'success'\n data = replaceData(\n prevResult?.data,\n placeholderData as unknown,\n options,\n ) as TData\n isPlaceholderData = true\n }\n }\n\n if (this.#selectError) {\n error = this.#selectError as any\n data = this.#selectResult\n errorUpdatedAt = Date.now()\n status = 'error'\n }\n\n const isFetching = fetchStatus === 'fetching'\n const isPending = status === 'pending'\n const isError = status === 'error'\n\n const isLoading = isPending && isFetching\n\n const result: QueryObserverBaseResult<TData, TError> = {\n status,\n fetchStatus,\n isPending,\n isSuccess: status === 'success',\n isError,\n isInitialLoading: isLoading,\n isLoading,\n data,\n dataUpdatedAt: state.dataUpdatedAt,\n error,\n errorUpdatedAt,\n failureCount: state.fetchFailureCount,\n failureReason: state.fetchFailureReason,\n errorUpdateCount: state.errorUpdateCount,\n isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,\n isFetchedAfterMount:\n state.dataUpdateCount > queryInitialState.dataUpdateCount ||\n state.errorUpdateCount > queryInitialState.errorUpdateCount,\n isFetching,\n isRefetching: isFetching && !isPending,\n isLoadingError: isError && state.dataUpdatedAt === 0,\n isPaused: fetchStatus === 'paused',\n isPlaceholderData,\n isRefetchError: isError && state.dataUpdatedAt !== 0,\n isStale: isStale(query, options),\n refetch: this.refetch,\n }\n\n return result as QueryObserverResult<TData, TError>\n }\n\n updateResult(notifyOptions?: NotifyOptions): void {\n const prevResult = this.#currentResult as\n | QueryObserverResult<TData, TError>\n | undefined\n\n const nextResult = this.createResult(this.#currentQuery, this.options)\n this.#currentResultState = this.#currentQuery.state\n this.#currentResultOptions = this.options\n\n // Only notify and update result if something has changed\n if (shallowEqualObjects(nextResult, prevResult)) {\n return\n }\n\n if (this.#currentResultState.data !== undefined) {\n this.#lastQueryWithDefinedData = this.#currentQuery\n }\n this.#currentResult = nextResult\n\n // Determine which callbacks to trigger\n const defaultNotifyOptions: NotifyOptions = {}\n\n const shouldNotifyListeners = (): boolean => {\n if (!prevResult) {\n return true\n }\n\n const { notifyOnChangeProps } = this.options\n\n if (\n notifyOnChangeProps === 'all' ||\n (!notifyOnChangeProps && !this.#trackedProps.size)\n ) {\n return true\n }\n\n const includedProps = new Set(notifyOnChangeProps ?? this.#trackedProps)\n\n if (this.options.throwOnError) {\n includedProps.add('error')\n }\n\n return Object.keys(this.#currentResult).some((key) => {\n const typedKey = key as keyof QueryObserverResult\n const changed = this.#currentResult[typedKey] !== prevResult[typedKey]\n return changed && includedProps.has(typedKey)\n })\n }\n\n if (notifyOptions?.listeners !== false && shouldNotifyListeners()) {\n defaultNotifyOptions.listeners = true\n }\n\n this.#notify({ ...defaultNotifyOptions, ...notifyOptions })\n }\n\n #updateQuery(): void {\n const query = this.#client.getQueryCache().build(this.#client, this.options)\n\n if (query === this.#currentQuery) {\n return\n }\n\n const prevQuery = this.#currentQuery as\n | Query<TQueryFnData, TError, TQueryData, TQueryKey>\n | undefined\n this.#currentQuery = query\n this.#currentQueryInitialState = query.state\n\n if (this.hasListeners()) {\n prevQuery?.removeObserver(this)\n query.addObserver(this)\n }\n }\n\n onQueryUpdate(): void {\n this.updateResult()\n\n if (this.hasListeners()) {\n this.#updateTimers()\n }\n }\n\n #notify(notifyOptions: NotifyOptions): void {\n notifyManager.batch(() => {\n // First, trigger the listeners\n if (notifyOptions.listeners) {\n this.listeners.forEach((listener) => {\n listener(this.#currentResult)\n })\n }\n\n // Then the cache listeners\n this.#client.getQueryCache().notify({\n query: this.#currentQuery,\n type: 'observerResultsUpdated',\n })\n })\n }\n}\n\nfunction shouldLoadOnMount(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any>,\n): boolean {\n return (\n options.enabled !== false &&\n !query.state.dataUpdatedAt &&\n !(query.state.status === 'error' && options.retryOnMount === false)\n )\n}\n\nfunction shouldFetchOnMount(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n): boolean {\n return (\n shouldLoadOnMount(query, options) ||\n (query.state.dataUpdatedAt > 0 &&\n shouldFetchOn(query, options, options.refetchOnMount))\n )\n}\n\nfunction shouldFetchOn(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n field: (typeof options)['refetchOnMount'] &\n (typeof options)['refetchOnWindowFocus'] &\n (typeof options)['refetchOnReconnect'],\n) {\n if (options.enabled !== false) {\n const value = typeof field === 'function' ? field(query) : field\n\n return value === 'always' || (value !== false && isStale(query, options))\n }\n return false\n}\n\nfunction shouldFetchOptionally(\n query: Query<any, any, any, any>,\n prevQuery: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n prevOptions: QueryObserverOptions<any, any, any, any, any>,\n): boolean {\n return (\n options.enabled !== false &&\n (query !== prevQuery || prevOptions.enabled === false) &&\n (!options.suspense || query.state.status !== 'error') &&\n isStale(query, options)\n )\n}\n\nfunction isStale(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n): boolean {\n return query.isStaleByTime(options.staleTime)\n}\n\n// this function would decide if we will update the observer's 'current'\n// properties after an optimistic reading via getOptimisticResult\nfunction shouldAssignObserverCurrentProperties<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>,\n optimisticResult: QueryObserverResult<TData, TError>,\n) {\n // if the newly created result isn't what the observer is holding as current,\n // then we'll need to update the properties as well\n if (observer.getCurrentResult() !== optimisticResult) {\n return true\n }\n\n // basically, just keep previous properties if nothing changed\n return false\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AA2BlB,MAAM,sBAMH,aAAmD;AAAA,EAgC3D,YACE,QACA,SAOA;AACA,UAAM;AAhCR,yBAAoE;AACpE,qCAA4D;AAC5D,0BAAqD;AAkBrD,yBAAgD,oBAAI,IAAI;AActD,SAAK,UAAU;AACf,SAAK,UAAU;AACf,SAAK,eAAe;AACpB,SAAK,YAAY;AACjB,SAAK,WAAW,OAAO;AA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
|
+
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 removable_exports = {};
|
|
20
|
+
__export(removable_exports, {
|
|
21
|
+
Removable: () => Removable
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(removable_exports);
|
|
24
|
+
var import_utils = require("./utils");
|
|
25
|
+
class Removable {
|
|
26
|
+
#gcTimeout;
|
|
27
|
+
destroy() {
|
|
28
|
+
this.clearGcTimeout();
|
|
29
|
+
}
|
|
30
|
+
scheduleGc() {
|
|
31
|
+
this.clearGcTimeout();
|
|
32
|
+
if ((0, import_utils.isValidTimeout)(this.gcTime)) {
|
|
33
|
+
this.#gcTimeout = setTimeout(() => {
|
|
34
|
+
this.optionalRemove();
|
|
35
|
+
}, this.gcTime);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
updateGcTime(newGcTime) {
|
|
39
|
+
this.gcTime = Math.max(
|
|
40
|
+
this.gcTime || 0,
|
|
41
|
+
newGcTime ?? (import_utils.isServer ? Infinity : 5 * 60 * 1e3)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
clearGcTimeout() {
|
|
45
|
+
if (this.#gcTimeout) {
|
|
46
|
+
clearTimeout(this.#gcTimeout);
|
|
47
|
+
this.#gcTimeout = void 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
Removable
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=removable.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/removable.ts"],"sourcesContent":["import { isServer, isValidTimeout } from './utils'\n\nexport abstract class Removable {\n gcTime!: number\n #gcTimeout?: ReturnType<typeof setTimeout>\n\n destroy(): void {\n this.clearGcTimeout()\n }\n\n protected scheduleGc(): void {\n this.clearGcTimeout()\n\n if (isValidTimeout(this.gcTime)) {\n this.#gcTimeout = setTimeout(() => {\n this.optionalRemove()\n }, this.gcTime)\n }\n }\n\n protected updateGcTime(newGcTime: number | undefined): void {\n // Default to 5 minutes (Infinity for server-side) if no gcTime is set\n this.gcTime = Math.max(\n this.gcTime || 0,\n newGcTime ?? (isServer ? Infinity : 5 * 60 * 1000),\n )\n }\n\n protected clearGcTimeout() {\n if (this.#gcTimeout) {\n clearTimeout(this.#gcTimeout)\n this.#gcTimeout = undefined\n }\n }\n\n protected abstract optionalRemove(): void\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyC;AAElC,MAAe,UAAU;AAAA,EAE9B;AAAA,EAEA,UAAgB;AACd,SAAK,eAAe;AAAA,EACtB;AAAA,EAEU,aAAmB;AAC3B,SAAK,eAAe;AAEpB,YAAI,6BAAe,KAAK,MAAM,GAAG;AAC/B,WAAK,aAAa,WAAW,MAAM;AACjC,aAAK,eAAe;AAAA,MACtB,GAAG,KAAK,MAAM;AAAA,IAChB;AAAA,EACF;AAAA,EAEU,aAAa,WAAqC;AAE1D,SAAK,SAAS,KAAK;AAAA,MACjB,KAAK,UAAU;AAAA,MACf,cAAc,wBAAW,WAAW,IAAI,KAAK;AAAA,IAC/C;AAAA,EACF;AAAA,EAEU,iBAAiB;AACzB,QAAI,KAAK,YAAY;AACnB,mBAAa,KAAK,UAAU;AAC5B,WAAK,aAAa;AAAA,IACpB;AAAA,EACF;AAGF;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare abstract class Removable {
|
|
2
|
+
#private;
|
|
3
|
+
gcTime: number;
|
|
4
|
+
destroy(): void;
|
|
5
|
+
protected scheduleGc(): void;
|
|
6
|
+
protected updateGcTime(newGcTime: number | undefined): void;
|
|
7
|
+
protected clearGcTimeout(): void;
|
|
8
|
+
protected abstract optionalRemove(): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { Removable };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare abstract class Removable {
|
|
2
|
+
#private;
|
|
3
|
+
gcTime: number;
|
|
4
|
+
destroy(): void;
|
|
5
|
+
protected scheduleGc(): void;
|
|
6
|
+
protected updateGcTime(newGcTime: number | undefined): void;
|
|
7
|
+
protected clearGcTimeout(): void;
|
|
8
|
+
protected abstract optionalRemove(): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { Removable };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { isServer, isValidTimeout } from "./utils";
|
|
3
2
|
class Removable {
|
|
4
3
|
#gcTimeout;
|
|
5
4
|
destroy() {
|
|
@@ -14,16 +13,19 @@ class Removable {
|
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
15
|
updateGcTime(newGcTime) {
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
this.gcTime = Math.max(
|
|
17
|
+
this.gcTime || 0,
|
|
18
|
+
newGcTime ?? (isServer ? Infinity : 5 * 60 * 1e3)
|
|
19
|
+
);
|
|
19
20
|
}
|
|
20
21
|
clearGcTimeout() {
|
|
21
22
|
if (this.#gcTimeout) {
|
|
22
23
|
clearTimeout(this.#gcTimeout);
|
|
23
|
-
this.#gcTimeout =
|
|
24
|
+
this.#gcTimeout = void 0;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
export {
|
|
29
|
+
Removable
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=removable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/removable.ts"],"sourcesContent":["import { isServer, isValidTimeout } from './utils'\n\nexport abstract class Removable {\n gcTime!: number\n #gcTimeout?: ReturnType<typeof setTimeout>\n\n destroy(): void {\n this.clearGcTimeout()\n }\n\n protected scheduleGc(): void {\n this.clearGcTimeout()\n\n if (isValidTimeout(this.gcTime)) {\n this.#gcTimeout = setTimeout(() => {\n this.optionalRemove()\n }, this.gcTime)\n }\n }\n\n protected updateGcTime(newGcTime: number | undefined): void {\n // Default to 5 minutes (Infinity for server-side) if no gcTime is set\n this.gcTime = Math.max(\n this.gcTime || 0,\n newGcTime ?? (isServer ? Infinity : 5 * 60 * 1000),\n )\n }\n\n protected clearGcTimeout() {\n if (this.#gcTimeout) {\n clearTimeout(this.#gcTimeout)\n this.#gcTimeout = undefined\n }\n }\n\n protected abstract optionalRemove(): void\n}\n"],"mappings":"AAAA,SAAS,UAAU,sBAAsB;AAElC,MAAe,UAAU;AAAA,EAE9B;AAAA,EAEA,UAAgB;AACd,SAAK,eAAe;AAAA,EACtB;AAAA,EAEU,aAAmB;AAC3B,SAAK,eAAe;AAEpB,QAAI,eAAe,KAAK,MAAM,GAAG;AAC/B,WAAK,aAAa,WAAW,MAAM;AACjC,aAAK,eAAe;AAAA,MACtB,GAAG,KAAK,MAAM;AAAA,IAChB;AAAA,EACF;AAAA,EAEU,aAAa,WAAqC;AAE1D,SAAK,SAAS,KAAK;AAAA,MACjB,KAAK,UAAU;AAAA,MACf,cAAc,WAAW,WAAW,IAAI,KAAK;AAAA,IAC/C;AAAA,EACF;AAAA,EAEU,iBAAiB;AACzB,QAAI,KAAK,YAAY;AACnB,mBAAa,KAAK,UAAU;AAC5B,WAAK,aAAa;AAAA,IACpB;AAAA,EACF;AAGF;","names":[]}
|