@tanstack/query-core 5.104.1 → 5.104.3
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/environmentManager.cjs +3 -1
- package/build/legacy/environmentManager.cjs.map +1 -1
- package/build/legacy/environmentManager.d.cts +6 -1
- package/build/legacy/environmentManager.d.cts.map +1 -1
- package/build/legacy/environmentManager.d.ts +6 -1
- package/build/legacy/environmentManager.d.ts.map +1 -1
- package/build/legacy/environmentManager.js +3 -1
- package/build/legacy/environmentManager.js.map +1 -1
- package/build/legacy/focusManager.cjs +4 -2
- package/build/legacy/focusManager.cjs.map +1 -1
- package/build/legacy/focusManager.d.cts +5 -3
- package/build/legacy/focusManager.d.cts.map +1 -1
- package/build/legacy/focusManager.d.ts +5 -3
- package/build/legacy/focusManager.d.ts.map +1 -1
- package/build/legacy/focusManager.js +4 -2
- package/build/legacy/focusManager.js.map +1 -1
- package/build/legacy/{hydration-B9t5w6NC.d.ts → hydration-Bf0oMcwO.d.ts} +1411 -129
- package/build/legacy/hydration-Bf0oMcwO.d.ts.map +1 -0
- package/build/legacy/{hydration-Br9VIGXa.d.cts → hydration-C6zghADG.d.cts} +1411 -129
- package/build/legacy/hydration-C6zghADG.d.cts.map +1 -0
- package/build/legacy/hydration.cjs +35 -0
- package/build/legacy/hydration.cjs.map +1 -1
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/hydration.js +35 -0
- package/build/legacy/hydration.js.map +1 -1
- package/build/legacy/index.d.cts +1 -1
- package/build/legacy/index.d.ts +1 -1
- package/build/legacy/infiniteQueryBehavior.cjs +29 -0
- package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +16 -1
- package/build/legacy/infiniteQueryBehavior.d.cts.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +16 -1
- package/build/legacy/infiniteQueryBehavior.d.ts.map +1 -1
- package/build/legacy/infiniteQueryBehavior.js +29 -0
- package/build/legacy/infiniteQueryBehavior.js.map +1 -1
- package/build/legacy/infiniteQueryObserver.cjs +13 -7
- package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +15 -9
- package/build/legacy/infiniteQueryObserver.d.cts.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.ts +15 -9
- package/build/legacy/infiniteQueryObserver.d.ts.map +1 -1
- package/build/legacy/infiniteQueryObserver.js +13 -7
- package/build/legacy/infiniteQueryObserver.js.map +1 -1
- package/build/legacy/mutation.cjs +27 -10
- package/build/legacy/mutation.cjs.map +1 -1
- package/build/legacy/mutation.d.cts +1 -1
- package/build/legacy/mutation.d.ts +1 -1
- package/build/legacy/mutation.js +27 -10
- package/build/legacy/mutation.js.map +1 -1
- package/build/legacy/mutationCache.cjs +53 -12
- package/build/legacy/mutationCache.cjs.map +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationCache.js +53 -12
- package/build/legacy/mutationCache.js.map +1 -1
- package/build/legacy/mutationObserver.cjs +27 -16
- package/build/legacy/mutationObserver.cjs.map +1 -1
- package/build/legacy/mutationObserver.d.cts +1 -1
- package/build/legacy/mutationObserver.d.ts +1 -1
- package/build/legacy/mutationObserver.js +27 -16
- package/build/legacy/mutationObserver.js.map +1 -1
- package/build/legacy/notifyManager.cjs +12 -2
- package/build/legacy/notifyManager.cjs.map +1 -1
- package/build/legacy/notifyManager.d.cts +19 -4
- package/build/legacy/notifyManager.d.cts.map +1 -1
- package/build/legacy/notifyManager.d.ts +19 -4
- package/build/legacy/notifyManager.d.ts.map +1 -1
- package/build/legacy/notifyManager.js +12 -2
- package/build/legacy/notifyManager.js.map +1 -1
- package/build/legacy/onlineManager.cjs +4 -2
- package/build/legacy/onlineManager.cjs.map +1 -1
- package/build/legacy/onlineManager.d.cts +5 -3
- package/build/legacy/onlineManager.d.cts.map +1 -1
- package/build/legacy/onlineManager.d.ts +5 -3
- package/build/legacy/onlineManager.d.ts.map +1 -1
- package/build/legacy/onlineManager.js +4 -2
- package/build/legacy/onlineManager.js.map +1 -1
- package/build/legacy/queriesObserver.cjs +15 -3
- package/build/legacy/queriesObserver.cjs.map +1 -1
- package/build/legacy/queriesObserver.d.cts +14 -5
- package/build/legacy/queriesObserver.d.cts.map +1 -1
- package/build/legacy/queriesObserver.d.ts +14 -5
- package/build/legacy/queriesObserver.d.ts.map +1 -1
- package/build/legacy/queriesObserver.js +15 -3
- package/build/legacy/queriesObserver.js.map +1 -1
- package/build/legacy/query.cjs +89 -15
- package/build/legacy/query.cjs.map +1 -1
- package/build/legacy/query.d.cts +1 -1
- package/build/legacy/query.d.ts +1 -1
- package/build/legacy/query.js +89 -15
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryCache.cjs +34 -12
- package/build/legacy/queryCache.cjs.map +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryCache.js +34 -12
- package/build/legacy/queryCache.js.map +1 -1
- package/build/legacy/queryClient.cjs +104 -32
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryClient.js +104 -32
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryObserver.cjs +78 -6
- package/build/legacy/queryObserver.cjs.map +1 -1
- package/build/legacy/queryObserver.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/queryObserver.js +78 -6
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/{modern/removable-0GzhW1PK.d.cts → legacy/removable-Cw9GNGyK.d.cts} +17 -1
- package/build/legacy/removable-Cw9GNGyK.d.cts.map +1 -0
- package/build/legacy/{removable-0GzhW1PK.d.cts → removable-Cw9GNGyK.d.ts} +17 -1
- package/build/legacy/removable-Cw9GNGyK.d.ts.map +1 -0
- package/build/legacy/removable.cjs +12 -0
- package/build/legacy/removable.cjs.map +1 -1
- package/build/legacy/removable.d.cts +1 -1
- package/build/legacy/removable.d.ts +1 -1
- package/build/legacy/removable.js +12 -0
- package/build/legacy/removable.js.map +1 -1
- package/build/legacy/retryer.cjs +26 -4
- package/build/legacy/retryer.cjs.map +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/retryer.js +26 -4
- package/build/legacy/retryer.js.map +1 -1
- package/build/legacy/streamedQuery.cjs +3 -1
- package/build/legacy/streamedQuery.cjs.map +1 -1
- package/build/legacy/streamedQuery.d.cts +4 -2
- package/build/legacy/streamedQuery.d.cts.map +1 -1
- package/build/legacy/streamedQuery.d.ts +4 -2
- package/build/legacy/streamedQuery.d.ts.map +1 -1
- package/build/legacy/streamedQuery.js +3 -1
- package/build/legacy/streamedQuery.js.map +1 -1
- package/build/{modern/subscribable-CysQ0tne.d.cts → legacy/subscribable-czlHOxMP.d.cts} +11 -1
- package/build/legacy/subscribable-czlHOxMP.d.cts.map +1 -0
- package/build/legacy/{subscribable-CysQ0tne.d.cts → subscribable-czlHOxMP.d.ts} +11 -1
- package/build/legacy/subscribable-czlHOxMP.d.ts.map +1 -0
- package/build/legacy/subscribable.cjs +10 -0
- package/build/legacy/subscribable.cjs.map +1 -1
- package/build/legacy/subscribable.d.cts +1 -1
- package/build/legacy/subscribable.d.ts +1 -1
- package/build/legacy/subscribable.js +10 -0
- package/build/legacy/subscribable.js.map +1 -1
- package/build/legacy/timeoutManager.cjs +11 -6
- package/build/legacy/timeoutManager.cjs.map +1 -1
- package/build/legacy/timeoutManager.d.cts +23 -6
- package/build/legacy/timeoutManager.d.cts.map +1 -1
- package/build/legacy/timeoutManager.d.ts +23 -6
- package/build/legacy/timeoutManager.d.ts.map +1 -1
- package/build/legacy/timeoutManager.js +11 -6
- package/build/legacy/timeoutManager.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/utils.cjs +117 -8
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/legacy/utils.js +117 -8
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/environmentManager.cjs +3 -1
- package/build/modern/environmentManager.cjs.map +1 -1
- package/build/modern/environmentManager.d.cts +6 -1
- package/build/modern/environmentManager.d.cts.map +1 -1
- package/build/modern/environmentManager.d.ts +6 -1
- package/build/modern/environmentManager.d.ts.map +1 -1
- package/build/modern/environmentManager.js +3 -1
- package/build/modern/environmentManager.js.map +1 -1
- package/build/modern/focusManager.cjs +4 -2
- package/build/modern/focusManager.cjs.map +1 -1
- package/build/modern/focusManager.d.cts +5 -3
- package/build/modern/focusManager.d.cts.map +1 -1
- package/build/modern/focusManager.d.ts +5 -3
- package/build/modern/focusManager.d.ts.map +1 -1
- package/build/modern/focusManager.js +4 -2
- package/build/modern/focusManager.js.map +1 -1
- package/build/modern/{hydration-B9t5w6NC.d.ts → hydration-Bf0oMcwO.d.ts} +1411 -129
- package/build/modern/hydration-Bf0oMcwO.d.ts.map +1 -0
- package/build/modern/{hydration-Br9VIGXa.d.cts → hydration-C6zghADG.d.cts} +1411 -129
- package/build/modern/hydration-C6zghADG.d.cts.map +1 -0
- package/build/modern/hydration.cjs +35 -0
- package/build/modern/hydration.cjs.map +1 -1
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/hydration.js +35 -0
- package/build/modern/hydration.js.map +1 -1
- package/build/modern/index.d.cts +1 -1
- package/build/modern/index.d.ts +1 -1
- package/build/modern/infiniteQueryBehavior.cjs +29 -0
- package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +16 -1
- package/build/modern/infiniteQueryBehavior.d.cts.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +16 -1
- package/build/modern/infiniteQueryBehavior.d.ts.map +1 -1
- package/build/modern/infiniteQueryBehavior.js +29 -0
- package/build/modern/infiniteQueryBehavior.js.map +1 -1
- package/build/modern/infiniteQueryObserver.cjs +13 -7
- package/build/modern/infiniteQueryObserver.cjs.map +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +15 -9
- package/build/modern/infiniteQueryObserver.d.cts.map +1 -1
- package/build/modern/infiniteQueryObserver.d.ts +15 -9
- package/build/modern/infiniteQueryObserver.d.ts.map +1 -1
- package/build/modern/infiniteQueryObserver.js +13 -7
- package/build/modern/infiniteQueryObserver.js.map +1 -1
- package/build/modern/mutation.cjs +27 -10
- package/build/modern/mutation.cjs.map +1 -1
- package/build/modern/mutation.d.cts +1 -1
- package/build/modern/mutation.d.ts +1 -1
- package/build/modern/mutation.js +27 -10
- package/build/modern/mutation.js.map +1 -1
- package/build/modern/mutationCache.cjs +53 -12
- package/build/modern/mutationCache.cjs.map +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationCache.js +53 -12
- package/build/modern/mutationCache.js.map +1 -1
- package/build/modern/mutationObserver.cjs +23 -12
- package/build/modern/mutationObserver.cjs.map +1 -1
- package/build/modern/mutationObserver.d.cts +1 -1
- package/build/modern/mutationObserver.d.ts +1 -1
- package/build/modern/mutationObserver.js +23 -12
- package/build/modern/mutationObserver.js.map +1 -1
- package/build/modern/notifyManager.cjs +12 -2
- package/build/modern/notifyManager.cjs.map +1 -1
- package/build/modern/notifyManager.d.cts +19 -4
- package/build/modern/notifyManager.d.cts.map +1 -1
- package/build/modern/notifyManager.d.ts +19 -4
- package/build/modern/notifyManager.d.ts.map +1 -1
- package/build/modern/notifyManager.js +12 -2
- package/build/modern/notifyManager.js.map +1 -1
- package/build/modern/onlineManager.cjs +4 -2
- package/build/modern/onlineManager.cjs.map +1 -1
- package/build/modern/onlineManager.d.cts +5 -3
- package/build/modern/onlineManager.d.cts.map +1 -1
- package/build/modern/onlineManager.d.ts +5 -3
- package/build/modern/onlineManager.d.ts.map +1 -1
- package/build/modern/onlineManager.js +4 -2
- package/build/modern/onlineManager.js.map +1 -1
- package/build/modern/queriesObserver.cjs +15 -3
- package/build/modern/queriesObserver.cjs.map +1 -1
- package/build/modern/queriesObserver.d.cts +14 -5
- package/build/modern/queriesObserver.d.cts.map +1 -1
- package/build/modern/queriesObserver.d.ts +14 -5
- package/build/modern/queriesObserver.d.ts.map +1 -1
- package/build/modern/queriesObserver.js +15 -3
- package/build/modern/queriesObserver.js.map +1 -1
- package/build/modern/query.cjs +89 -15
- package/build/modern/query.cjs.map +1 -1
- package/build/modern/query.d.cts +1 -1
- package/build/modern/query.d.ts +1 -1
- package/build/modern/query.js +89 -15
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryCache.cjs +34 -12
- package/build/modern/queryCache.cjs.map +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryCache.js +34 -12
- package/build/modern/queryCache.js.map +1 -1
- package/build/modern/queryClient.cjs +104 -32
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryClient.js +104 -32
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryObserver.cjs +78 -6
- package/build/modern/queryObserver.cjs.map +1 -1
- package/build/modern/queryObserver.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/queryObserver.js +78 -6
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/{removable-0GzhW1PK.d.ts → removable-Cw9GNGyK.d.cts} +17 -1
- package/build/modern/removable-Cw9GNGyK.d.cts.map +1 -0
- package/build/{legacy/removable-0GzhW1PK.d.ts → modern/removable-Cw9GNGyK.d.ts} +17 -1
- package/build/modern/removable-Cw9GNGyK.d.ts.map +1 -0
- package/build/modern/removable.cjs +12 -0
- package/build/modern/removable.cjs.map +1 -1
- package/build/modern/removable.d.cts +1 -1
- package/build/modern/removable.d.ts +1 -1
- package/build/modern/removable.js +12 -0
- package/build/modern/removable.js.map +1 -1
- package/build/modern/retryer.cjs +26 -4
- package/build/modern/retryer.cjs.map +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/retryer.js +26 -4
- package/build/modern/retryer.js.map +1 -1
- package/build/modern/streamedQuery.cjs +3 -1
- package/build/modern/streamedQuery.cjs.map +1 -1
- package/build/modern/streamedQuery.d.cts +4 -2
- package/build/modern/streamedQuery.d.cts.map +1 -1
- package/build/modern/streamedQuery.d.ts +4 -2
- package/build/modern/streamedQuery.d.ts.map +1 -1
- package/build/modern/streamedQuery.js +3 -1
- package/build/modern/streamedQuery.js.map +1 -1
- package/build/modern/{subscribable-CysQ0tne.d.ts → subscribable-czlHOxMP.d.cts} +11 -1
- package/build/modern/subscribable-czlHOxMP.d.cts.map +1 -0
- package/build/{legacy/subscribable-CysQ0tne.d.ts → modern/subscribable-czlHOxMP.d.ts} +11 -1
- package/build/modern/subscribable-czlHOxMP.d.ts.map +1 -0
- package/build/modern/subscribable.cjs +10 -0
- package/build/modern/subscribable.cjs.map +1 -1
- package/build/modern/subscribable.d.cts +1 -1
- package/build/modern/subscribable.d.ts +1 -1
- package/build/modern/subscribable.js +10 -0
- package/build/modern/subscribable.js.map +1 -1
- package/build/modern/timeoutManager.cjs +11 -6
- package/build/modern/timeoutManager.cjs.map +1 -1
- package/build/modern/timeoutManager.d.cts +23 -6
- package/build/modern/timeoutManager.d.cts.map +1 -1
- package/build/modern/timeoutManager.d.ts +23 -6
- package/build/modern/timeoutManager.d.ts.map +1 -1
- package/build/modern/timeoutManager.js +11 -6
- package/build/modern/timeoutManager.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/types.js.map +1 -1
- package/build/modern/utils.cjs +117 -8
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/build/modern/utils.js +117 -8
- package/build/modern/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/environmentManager.ts +6 -1
- package/src/focusManager.ts +8 -6
- package/src/hydration.ts +42 -1
- package/src/infiniteQueryBehavior.ts +29 -0
- package/src/infiniteQueryObserver.ts +20 -14
- package/src/mutation.ts +32 -11
- package/src/mutationCache.ts +53 -12
- package/src/mutationObserver.ts +29 -14
- package/src/notifyManager.ts +12 -2
- package/src/onlineManager.ts +7 -5
- package/src/queriesObserver.ts +20 -5
- package/src/query.ts +153 -20
- package/src/queryCache.ts +54 -13
- package/src/queryClient.ts +114 -42
- package/src/queryObserver.ts +88 -12
- package/src/removable.ts +16 -0
- package/src/retryer.ts +57 -4
- package/src/streamedQuery.ts +4 -3
- package/src/subscribable.ts +10 -0
- package/src/timeoutManager.ts +23 -6
- package/src/types.ts +801 -27
- package/src/utils.ts +130 -10
- package/build/legacy/hydration-B9t5w6NC.d.ts.map +0 -1
- package/build/legacy/hydration-Br9VIGXa.d.cts.map +0 -1
- package/build/legacy/removable-0GzhW1PK.d.cts.map +0 -1
- package/build/legacy/removable-0GzhW1PK.d.ts.map +0 -1
- package/build/legacy/subscribable-CysQ0tne.d.cts.map +0 -1
- package/build/legacy/subscribable-CysQ0tne.d.ts.map +0 -1
- package/build/modern/hydration-B9t5w6NC.d.ts.map +0 -1
- package/build/modern/hydration-Br9VIGXa.d.cts.map +0 -1
- package/build/modern/removable-0GzhW1PK.d.cts.map +0 -1
- package/build/modern/removable-0GzhW1PK.d.ts.map +0 -1
- package/build/modern/subscribable-CysQ0tne.d.cts.map +0 -1
- package/build/modern/subscribable-CysQ0tne.d.ts.map +0 -1
|
@@ -6,7 +6,9 @@ const require_utils = require("./utils.cjs");
|
|
|
6
6
|
* Data will be an Array of all the chunks received.
|
|
7
7
|
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
8
8
|
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
9
|
-
* @param
|
|
9
|
+
* @param options - The `streamFn` that returns an AsyncIterable to stream data from, and the optional
|
|
10
|
+
* `refetchMode`, `reducer`, and `initialValue` options.
|
|
11
|
+
* @returns A query function to pass as `queryFn`.
|
|
10
12
|
* @example
|
|
11
13
|
* ```ts
|
|
12
14
|
* await queryClient.query({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamedQuery.cjs","names":["addToEnd","addConsumeAwareSignal"],"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addConsumeAwareSignal, addToEnd } from './utils'\nimport type {\n OmitKeyof,\n QueryFunction,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\ntype BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {\n /** The function that returns an `AsyncIterable` to stream data from. */\n streamFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n /**\n * Defines how refetches are handled.\n * - `'reset'` (default): erases all data and puts the query back into `pending` state.\n * - `'append'`: appends new data to the existing data.\n * - `'replace'`: writes all data to the cache once the stream ends.\n */\n refetchMode?: 'append' | 'reset' | 'replace'\n}\n\ntype SimpleStreamedQueryParams<\n TQueryFnData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n reducer?: never\n initialValue?: never\n}\n\ntype ReducibleStreamedQueryParams<\n TQueryFnData,\n TData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n /**\n * Reduces streamed chunks into the final data shape. Required whenever `TData` is not an\n * array, since there is no default way to accumulate non-array chunks.\n */\n reducer: (acc: TData, chunk: TQueryFnData) => TData\n /**\n * The value used while the first chunk is being fetched, and returned if the stream yields no\n * values. Required together with a custom `reducer`.\n */\n initialValue: TData\n}\n\ntype StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> =\n | SimpleStreamedQueryParams<TQueryFnData, TQueryKey>\n | ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey>\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param
|
|
1
|
+
{"version":3,"file":"streamedQuery.cjs","names":["addToEnd","addConsumeAwareSignal"],"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addConsumeAwareSignal, addToEnd } from './utils'\nimport type {\n OmitKeyof,\n QueryFunction,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\ntype BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {\n /** The function that returns an `AsyncIterable` to stream data from. */\n streamFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n /**\n * Defines how refetches are handled.\n * - `'reset'` (default): erases all data and puts the query back into `pending` state.\n * - `'append'`: appends new data to the existing data.\n * - `'replace'`: writes all data to the cache once the stream ends.\n */\n refetchMode?: 'append' | 'reset' | 'replace'\n}\n\ntype SimpleStreamedQueryParams<\n TQueryFnData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n reducer?: never\n initialValue?: never\n}\n\ntype ReducibleStreamedQueryParams<\n TQueryFnData,\n TData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n /**\n * Reduces streamed chunks into the final data shape. Required whenever `TData` is not an\n * array, since there is no default way to accumulate non-array chunks.\n */\n reducer: (acc: TData, chunk: TQueryFnData) => TData\n /**\n * The value used while the first chunk is being fetched, and returned if the stream yields no\n * values. Required together with a custom `reducer`.\n */\n initialValue: TData\n}\n\ntype StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> =\n | SimpleStreamedQueryParams<TQueryFnData, TQueryKey>\n | ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey>\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param options - The `streamFn` that returns an AsyncIterable to stream data from, and the optional\n * `refetchMode`, `reducer`, and `initialValue` options.\n * @returns A query function to pass as `queryFn`.\n * @example\n * ```ts\n * await queryClient.query({\n * queryKey: ['data'],\n * queryFn: streamedQuery({\n * streamFn: fetchDataInChunks,\n * }),\n * })\n * ```\n */\nexport function streamedQuery<\n TQueryFnData = unknown,\n TData = Array<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n>({\n streamFn,\n refetchMode = 'reset',\n reducer = (items, chunk) =>\n addToEnd(items as Array<TQueryFnData>, chunk) as TData,\n initialValue = [] as TData,\n}: StreamedQueryParams<TQueryFnData, TData, TQueryKey>): QueryFunction<\n TData,\n TQueryKey\n> {\n return async (context) => {\n const query = context.client\n .getQueryCache()\n .find({ queryKey: context.queryKey, exact: true })\n const isRefetch = !!query && query.isFetched()\n if (isRefetch && refetchMode === 'reset') {\n query.setState({\n ...query.resetState,\n fetchStatus: 'fetching',\n })\n }\n\n let result = initialValue\n\n let cancelled = false as boolean\n const streamFnContext = addConsumeAwareSignal<\n OmitKeyof<typeof context, 'signal'>\n >(\n {\n client: context.client,\n meta: context.meta,\n queryKey: context.queryKey,\n pageParam: context.pageParam,\n direction: context.direction,\n },\n () => context.signal,\n () => (cancelled = true),\n )\n\n const stream = await streamFn(streamFnContext)\n\n const isReplaceRefetch = isRefetch && refetchMode === 'replace'\n\n for await (const chunk of stream) {\n if (cancelled) {\n break\n }\n\n if (isReplaceRefetch) {\n // don't append to the cache directly when replace-refetching\n result = reducer(result, chunk)\n } else {\n context.client.setQueryData<TData>(context.queryKey, (prev) =>\n reducer(prev === undefined ? initialValue : prev, chunk),\n )\n }\n }\n\n // finalize result: replace-refetching needs to write to the cache\n if (isReplaceRefetch && !cancelled) {\n context.client.setQueryData<TData>(context.queryKey, result)\n }\n\n const data = context.client.getQueryData<TData>(context.queryKey)\n return data === undefined ? initialValue : data\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqEA,SAAgB,cAId,EACA,UACA,cAAc,SACd,WAAW,OAAO,UAChBA,cAAAA,SAAS,OAA8B,KAAK,GAC9C,eAAe,CAAC,KAIhB;CACA,OAAO,OAAO,YAAY;EACxB,MAAM,QAAQ,QAAQ,OACnB,cAAc,CAAC,CACf,KAAK;GAAE,UAAU,QAAQ;GAAU,OAAO;EAAK,CAAC;EACnD,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,UAAU;EAC7C,IAAI,aAAa,gBAAgB,SAC/B,MAAM,SAAS;GACb,GAAG,MAAM;GACT,aAAa;EACf,CAAC;EAGH,IAAI,SAAS;EAEb,IAAI,YAAY;EAehB,MAAM,SAAS,MAAM,SAdGC,cAAAA,sBAGtB;GACE,QAAQ,QAAQ;GAChB,MAAM,QAAQ;GACd,UAAU,QAAQ;GAClB,WAAW,QAAQ;GACnB,WAAW,QAAQ;EACrB,SACM,QAAQ,cACP,YAAY,IAGuB,CAAC;EAE7C,MAAM,mBAAmB,aAAa,gBAAgB;EAEtD,WAAW,MAAM,SAAS,QAAQ;GAChC,IAAI,WACF;GAGF,IAAI,kBAEF,SAAS,QAAQ,QAAQ,KAAK;QAE9B,QAAQ,OAAO,aAAoB,QAAQ,WAAW,SACpD,QAAQ,SAAS,KAAA,IAAY,eAAe,MAAM,KAAK,CACzD;EAEJ;EAGA,IAAI,oBAAoB,CAAC,WACvB,QAAQ,OAAO,aAAoB,QAAQ,UAAU,MAAM;EAG7D,MAAM,OAAO,QAAQ,OAAO,aAAoB,QAAQ,QAAQ;EAChE,OAAO,SAAS,KAAA,IAAY,eAAe;CAC7C;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ct as QueryKey, St as QueryFunctionContext, xt as QueryFunction } from "./hydration-
|
|
1
|
+
import { Ct as QueryKey, St as QueryFunctionContext, xt as QueryFunction } from "./hydration-C6zghADG.cjs";
|
|
2
2
|
//#region src/streamedQuery.d.ts
|
|
3
3
|
type BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {
|
|
4
4
|
/** The function that returns an `AsyncIterable` to stream data from. */
|
|
@@ -33,7 +33,9 @@ type StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> = Simp
|
|
|
33
33
|
* Data will be an Array of all the chunks received.
|
|
34
34
|
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
35
35
|
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
36
|
-
* @param
|
|
36
|
+
* @param options - The `streamFn` that returns an AsyncIterable to stream data from, and the optional
|
|
37
|
+
* `refetchMode`, `reducer`, and `initialValue` options.
|
|
38
|
+
* @returns A query function to pass as `queryFn`.
|
|
37
39
|
* @example
|
|
38
40
|
* ```ts
|
|
39
41
|
* await queryClient.query({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamedQuery.d.cts","names":[],"sources":["../../src/streamedQuery.ts"],"mappings":";;KAQK,wBAAwB,cAAc,kBAAkB;;EAE3D,WACE,SAAS,qBAAqB,eAC3B,cAAc,gBAAgB,QAAQ,cAAc;;;;;;;EAOzD;;KAGG,0BACH,cACA,kBAAkB,YAChB,wBAAwB,cAAc;EACxC;EACA;;KAGG,6BACH,cACA,OACA,kBAAkB,YAChB,wBAAwB,cAAc;;;;;EAKxC,UAAU,KAAK,OAAO,OAAO,iBAAiB;;;;;EAK9C,cAAc;;KAGX,oBAAoB,cAAc,OAAO,kBAAkB,YAC5D,0BAA0B,cAAc,aACxC,6BAA6B,cAAc,OAAO
|
|
1
|
+
{"version":3,"file":"streamedQuery.d.cts","names":[],"sources":["../../src/streamedQuery.ts"],"mappings":";;KAQK,wBAAwB,cAAc,kBAAkB;;EAE3D,WACE,SAAS,qBAAqB,eAC3B,cAAc,gBAAgB,QAAQ,cAAc;;;;;;;EAOzD;;KAGG,0BACH,cACA,kBAAkB,YAChB,wBAAwB,cAAc;EACxC;EACA;;KAGG,6BACH,cACA,OACA,kBAAkB,YAChB,wBAAwB,cAAc;;;;;EAKxC,UAAU,KAAK,OAAO,OAAO,iBAAiB;;;;;EAK9C,cAAc;;KAGX,oBAAoB,cAAc,OAAO,kBAAkB,YAC5D,0BAA0B,cAAc,aACxC,6BAA6B,cAAc,OAAO;;;;;;;;;;;;;;;;;;;wBAoBtC,cACd,wBACA,QAAQ,MAAM,eACd,kBAAkB,WAAW,YAE7B,UACA,aACA,SAEA,gBACC,oBAAoB,cAAc,OAAO,aAAa,cACvD,OACA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ct as QueryKey, St as QueryFunctionContext, xt as QueryFunction } from "./hydration-
|
|
1
|
+
import { Ct as QueryKey, St as QueryFunctionContext, xt as QueryFunction } from "./hydration-Bf0oMcwO.js";
|
|
2
2
|
//#region src/streamedQuery.d.ts
|
|
3
3
|
type BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {
|
|
4
4
|
/** The function that returns an `AsyncIterable` to stream data from. */
|
|
@@ -33,7 +33,9 @@ type StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> = Simp
|
|
|
33
33
|
* Data will be an Array of all the chunks received.
|
|
34
34
|
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
35
35
|
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
36
|
-
* @param
|
|
36
|
+
* @param options - The `streamFn` that returns an AsyncIterable to stream data from, and the optional
|
|
37
|
+
* `refetchMode`, `reducer`, and `initialValue` options.
|
|
38
|
+
* @returns A query function to pass as `queryFn`.
|
|
37
39
|
* @example
|
|
38
40
|
* ```ts
|
|
39
41
|
* await queryClient.query({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamedQuery.d.ts","names":[],"sources":["../../src/streamedQuery.ts"],"mappings":";;KAQK,wBAAwB,cAAc,kBAAkB;;EAE3D,WACE,SAAS,qBAAqB,eAC3B,cAAc,gBAAgB,QAAQ,cAAc;;;;;;;EAOzD;;KAGG,0BACH,cACA,kBAAkB,YAChB,wBAAwB,cAAc;EACxC;EACA;;KAGG,6BACH,cACA,OACA,kBAAkB,YAChB,wBAAwB,cAAc;;;;;EAKxC,UAAU,KAAK,OAAO,OAAO,iBAAiB;;;;;EAK9C,cAAc;;KAGX,oBAAoB,cAAc,OAAO,kBAAkB,YAC5D,0BAA0B,cAAc,aACxC,6BAA6B,cAAc,OAAO
|
|
1
|
+
{"version":3,"file":"streamedQuery.d.ts","names":[],"sources":["../../src/streamedQuery.ts"],"mappings":";;KAQK,wBAAwB,cAAc,kBAAkB;;EAE3D,WACE,SAAS,qBAAqB,eAC3B,cAAc,gBAAgB,QAAQ,cAAc;;;;;;;EAOzD;;KAGG,0BACH,cACA,kBAAkB,YAChB,wBAAwB,cAAc;EACxC;EACA;;KAGG,6BACH,cACA,OACA,kBAAkB,YAChB,wBAAwB,cAAc;;;;;EAKxC,UAAU,KAAK,OAAO,OAAO,iBAAiB;;;;;EAK9C,cAAc;;KAGX,oBAAoB,cAAc,OAAO,kBAAkB,YAC5D,0BAA0B,cAAc,aACxC,6BAA6B,cAAc,OAAO;;;;;;;;;;;;;;;;;;;wBAoBtC,cACd,wBACA,QAAQ,MAAM,eACd,kBAAkB,WAAW,YAE7B,UACA,aACA,SAEA,gBACC,oBAAoB,cAAc,OAAO,aAAa,cACvD,OACA"}
|
|
@@ -5,7 +5,9 @@ import { addConsumeAwareSignal, addToEnd } from "./utils.js";
|
|
|
5
5
|
* Data will be an Array of all the chunks received.
|
|
6
6
|
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
7
7
|
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
8
|
-
* @param
|
|
8
|
+
* @param options - The `streamFn` that returns an AsyncIterable to stream data from, and the optional
|
|
9
|
+
* `refetchMode`, `reducer`, and `initialValue` options.
|
|
10
|
+
* @returns A query function to pass as `queryFn`.
|
|
9
11
|
* @example
|
|
10
12
|
* ```ts
|
|
11
13
|
* await queryClient.query({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamedQuery.js","names":[],"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addConsumeAwareSignal, addToEnd } from './utils'\nimport type {\n OmitKeyof,\n QueryFunction,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\ntype BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {\n /** The function that returns an `AsyncIterable` to stream data from. */\n streamFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n /**\n * Defines how refetches are handled.\n * - `'reset'` (default): erases all data and puts the query back into `pending` state.\n * - `'append'`: appends new data to the existing data.\n * - `'replace'`: writes all data to the cache once the stream ends.\n */\n refetchMode?: 'append' | 'reset' | 'replace'\n}\n\ntype SimpleStreamedQueryParams<\n TQueryFnData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n reducer?: never\n initialValue?: never\n}\n\ntype ReducibleStreamedQueryParams<\n TQueryFnData,\n TData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n /**\n * Reduces streamed chunks into the final data shape. Required whenever `TData` is not an\n * array, since there is no default way to accumulate non-array chunks.\n */\n reducer: (acc: TData, chunk: TQueryFnData) => TData\n /**\n * The value used while the first chunk is being fetched, and returned if the stream yields no\n * values. Required together with a custom `reducer`.\n */\n initialValue: TData\n}\n\ntype StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> =\n | SimpleStreamedQueryParams<TQueryFnData, TQueryKey>\n | ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey>\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param
|
|
1
|
+
{"version":3,"file":"streamedQuery.js","names":[],"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addConsumeAwareSignal, addToEnd } from './utils'\nimport type {\n OmitKeyof,\n QueryFunction,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\ntype BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {\n /** The function that returns an `AsyncIterable` to stream data from. */\n streamFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n /**\n * Defines how refetches are handled.\n * - `'reset'` (default): erases all data and puts the query back into `pending` state.\n * - `'append'`: appends new data to the existing data.\n * - `'replace'`: writes all data to the cache once the stream ends.\n */\n refetchMode?: 'append' | 'reset' | 'replace'\n}\n\ntype SimpleStreamedQueryParams<\n TQueryFnData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n reducer?: never\n initialValue?: never\n}\n\ntype ReducibleStreamedQueryParams<\n TQueryFnData,\n TData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n /**\n * Reduces streamed chunks into the final data shape. Required whenever `TData` is not an\n * array, since there is no default way to accumulate non-array chunks.\n */\n reducer: (acc: TData, chunk: TQueryFnData) => TData\n /**\n * The value used while the first chunk is being fetched, and returned if the stream yields no\n * values. Required together with a custom `reducer`.\n */\n initialValue: TData\n}\n\ntype StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> =\n | SimpleStreamedQueryParams<TQueryFnData, TQueryKey>\n | ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey>\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param options - The `streamFn` that returns an AsyncIterable to stream data from, and the optional\n * `refetchMode`, `reducer`, and `initialValue` options.\n * @returns A query function to pass as `queryFn`.\n * @example\n * ```ts\n * await queryClient.query({\n * queryKey: ['data'],\n * queryFn: streamedQuery({\n * streamFn: fetchDataInChunks,\n * }),\n * })\n * ```\n */\nexport function streamedQuery<\n TQueryFnData = unknown,\n TData = Array<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n>({\n streamFn,\n refetchMode = 'reset',\n reducer = (items, chunk) =>\n addToEnd(items as Array<TQueryFnData>, chunk) as TData,\n initialValue = [] as TData,\n}: StreamedQueryParams<TQueryFnData, TData, TQueryKey>): QueryFunction<\n TData,\n TQueryKey\n> {\n return async (context) => {\n const query = context.client\n .getQueryCache()\n .find({ queryKey: context.queryKey, exact: true })\n const isRefetch = !!query && query.isFetched()\n if (isRefetch && refetchMode === 'reset') {\n query.setState({\n ...query.resetState,\n fetchStatus: 'fetching',\n })\n }\n\n let result = initialValue\n\n let cancelled = false as boolean\n const streamFnContext = addConsumeAwareSignal<\n OmitKeyof<typeof context, 'signal'>\n >(\n {\n client: context.client,\n meta: context.meta,\n queryKey: context.queryKey,\n pageParam: context.pageParam,\n direction: context.direction,\n },\n () => context.signal,\n () => (cancelled = true),\n )\n\n const stream = await streamFn(streamFnContext)\n\n const isReplaceRefetch = isRefetch && refetchMode === 'replace'\n\n for await (const chunk of stream) {\n if (cancelled) {\n break\n }\n\n if (isReplaceRefetch) {\n // don't append to the cache directly when replace-refetching\n result = reducer(result, chunk)\n } else {\n context.client.setQueryData<TData>(context.queryKey, (prev) =>\n reducer(prev === undefined ? initialValue : prev, chunk),\n )\n }\n }\n\n // finalize result: replace-refetching needs to write to the cache\n if (isReplaceRefetch && !cancelled) {\n context.client.setQueryData<TData>(context.queryKey, result)\n }\n\n const data = context.client.getQueryData<TData>(context.queryKey)\n return data === undefined ? initialValue : data\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqEA,SAAgB,cAId,EACA,UACA,cAAc,SACd,WAAW,OAAO,UAChB,SAAS,OAA8B,KAAK,GAC9C,eAAe,CAAC,KAIhB;CACA,OAAO,OAAO,YAAY;EACxB,MAAM,QAAQ,QAAQ,OACnB,cAAc,CAAC,CACf,KAAK;GAAE,UAAU,QAAQ;GAAU,OAAO;EAAK,CAAC;EACnD,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,UAAU;EAC7C,IAAI,aAAa,gBAAgB,SAC/B,MAAM,SAAS;GACb,GAAG,MAAM;GACT,aAAa;EACf,CAAC;EAGH,IAAI,SAAS;EAEb,IAAI,YAAY;EAehB,MAAM,SAAS,MAAM,SAdG,sBAGtB;GACE,QAAQ,QAAQ;GAChB,MAAM,QAAQ;GACd,UAAU,QAAQ;GAClB,WAAW,QAAQ;GACnB,WAAW,QAAQ;EACrB,SACM,QAAQ,cACP,YAAY,IAGuB,CAAC;EAE7C,MAAM,mBAAmB,aAAa,gBAAgB;EAEtD,WAAW,MAAM,SAAS,QAAQ;GAChC,IAAI,WACF;GAGF,IAAI,kBAEF,SAAS,QAAQ,QAAQ,KAAK;QAE9B,QAAQ,OAAO,aAAoB,QAAQ,WAAW,SACpD,QAAQ,SAAS,KAAA,IAAY,eAAe,MAAM,KAAK,CACzD;EAEJ;EAGA,IAAI,oBAAoB,CAAC,WACvB,QAAQ,OAAO,aAAoB,QAAQ,UAAU,MAAM;EAG7D,MAAM,OAAO,QAAQ,OAAO,aAAoB,QAAQ,QAAQ;EAChE,OAAO,SAAS,KAAA,IAAY,eAAe;CAC7C;AACF"}
|
|
@@ -12,6 +12,7 @@ declare class Subscribable<TListener extends Function> {
|
|
|
12
12
|
* that removes the listener again — call it to stop listening. The base class never drops a listener
|
|
13
13
|
* on its own, though some subclasses clear all of theirs in `destroy()`.
|
|
14
14
|
* @param listener - Called on each update, with whatever the subclass passes to its subscribers.
|
|
15
|
+
* @returns A function that removes the listener.
|
|
15
16
|
* @example
|
|
16
17
|
* ```ts
|
|
17
18
|
* const unsubscribe = subscribable.subscribe(() => {
|
|
@@ -24,11 +25,20 @@ declare class Subscribable<TListener extends Function> {
|
|
|
24
25
|
subscribe(listener: TListener): () => void;
|
|
25
26
|
/**
|
|
26
27
|
* Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.
|
|
28
|
+
* @returns `true` if at least one listener is registered.
|
|
27
29
|
*/
|
|
28
30
|
hasListeners(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Called after a listener is added. Does nothing here; subclasses override it, e.g. to start
|
|
33
|
+
* tracking what they observe once the first listener subscribes.
|
|
34
|
+
*/
|
|
29
35
|
protected onSubscribe(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Called after a listener is removed. Does nothing here; subclasses override it, e.g. to clean up
|
|
38
|
+
* once the last listener unsubscribes.
|
|
39
|
+
*/
|
|
30
40
|
protected onUnsubscribe(): void;
|
|
31
41
|
}
|
|
32
42
|
//#endregion
|
|
33
43
|
export { Subscribable as t };
|
|
34
|
-
//# sourceMappingURL=subscribable-
|
|
44
|
+
//# sourceMappingURL=subscribable-czlHOxMP.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribable-czlHOxMP.d.cts","names":[],"sources":["../../src/subscribable.ts"],"mappings":";;;;;;cAKa,aAAa,kBAAkB;YAChC,WAAS,IAAA;;;;;;;;;;;;;;;;;EAqBnB,UAAU,UAAU;;;;;EAepB;;;;;YAQU;;;;;YAQA"}
|
|
@@ -12,6 +12,7 @@ declare class Subscribable<TListener extends Function> {
|
|
|
12
12
|
* that removes the listener again — call it to stop listening. The base class never drops a listener
|
|
13
13
|
* on its own, though some subclasses clear all of theirs in `destroy()`.
|
|
14
14
|
* @param listener - Called on each update, with whatever the subclass passes to its subscribers.
|
|
15
|
+
* @returns A function that removes the listener.
|
|
15
16
|
* @example
|
|
16
17
|
* ```ts
|
|
17
18
|
* const unsubscribe = subscribable.subscribe(() => {
|
|
@@ -24,11 +25,20 @@ declare class Subscribable<TListener extends Function> {
|
|
|
24
25
|
subscribe(listener: TListener): () => void;
|
|
25
26
|
/**
|
|
26
27
|
* Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.
|
|
28
|
+
* @returns `true` if at least one listener is registered.
|
|
27
29
|
*/
|
|
28
30
|
hasListeners(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Called after a listener is added. Does nothing here; subclasses override it, e.g. to start
|
|
33
|
+
* tracking what they observe once the first listener subscribes.
|
|
34
|
+
*/
|
|
29
35
|
protected onSubscribe(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Called after a listener is removed. Does nothing here; subclasses override it, e.g. to clean up
|
|
38
|
+
* once the last listener unsubscribes.
|
|
39
|
+
*/
|
|
30
40
|
protected onUnsubscribe(): void;
|
|
31
41
|
}
|
|
32
42
|
//#endregion
|
|
33
43
|
export { Subscribable as t };
|
|
34
|
-
//# sourceMappingURL=subscribable-
|
|
44
|
+
//# sourceMappingURL=subscribable-czlHOxMP.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribable-czlHOxMP.d.ts","names":[],"sources":["../../src/subscribable.ts"],"mappings":";;;;;;cAKa,aAAa,kBAAkB;YAChC,WAAS,IAAA;;;;;;;;;;;;;;;;;EAqBnB,UAAU,UAAU;;;;;EAepB;;;;;YAQU;;;;;YAQA"}
|
|
@@ -15,6 +15,7 @@ var Subscribable = class {
|
|
|
15
15
|
* that removes the listener again — call it to stop listening. The base class never drops a listener
|
|
16
16
|
* on its own, though some subclasses clear all of theirs in `destroy()`.
|
|
17
17
|
* @param listener - Called on each update, with whatever the subclass passes to its subscribers.
|
|
18
|
+
* @returns A function that removes the listener.
|
|
18
19
|
* @example
|
|
19
20
|
* ```ts
|
|
20
21
|
* const unsubscribe = subscribable.subscribe(() => {
|
|
@@ -34,11 +35,20 @@ var Subscribable = class {
|
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
37
|
* Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.
|
|
38
|
+
* @returns `true` if at least one listener is registered.
|
|
37
39
|
*/
|
|
38
40
|
hasListeners() {
|
|
39
41
|
return this.listeners.size > 0;
|
|
40
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Called after a listener is added. Does nothing here; subclasses override it, e.g. to start
|
|
45
|
+
* tracking what they observe once the first listener subscribes.
|
|
46
|
+
*/
|
|
41
47
|
onSubscribe() {}
|
|
48
|
+
/**
|
|
49
|
+
* Called after a listener is removed. Does nothing here; subclasses override it, e.g. to clean up
|
|
50
|
+
* once the last listener unsubscribes.
|
|
51
|
+
*/
|
|
42
52
|
onUnsubscribe() {}
|
|
43
53
|
};
|
|
44
54
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribable.cjs","names":[],"sources":["../../src/subscribable.ts"],"sourcesContent":["/**\n * The base class behind everything in Query that you can subscribe to: `QueryCache`, `MutationCache`,\n * the observers, and the `FocusManager`/`OnlineManager` behind `focusManager` and `onlineManager`.\n * Subclasses decide what a listener receives and when it is called.\n */\nexport class Subscribable<TListener extends Function> {\n protected listeners = new Set<TListener>()\n\n constructor() {\n this.subscribe = this.subscribe.bind(this)\n }\n\n /**\n * Registers a listener to be called on every update this object notifies about. Returns a function\n * that removes the listener again — call it to stop listening. The base class never drops a listener\n * on its own, though some subclasses clear all of theirs in `destroy()`.\n * @param listener - Called on each update, with whatever the subclass passes to its subscribers.\n * @example\n * ```ts\n * const unsubscribe = subscribable.subscribe(() => {\n * // react to the update\n * })\n *\n * unsubscribe()\n * ```\n */\n subscribe(listener: TListener): () => void {\n this.listeners.add(listener)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(listener)\n this.onUnsubscribe()\n }\n }\n\n /**\n * Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.\n */\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n protected onSubscribe(): void {\n // Do nothing\n }\n\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n"],"mappings":";;;;;;;AAKA,IAAa,eAAb,MAAsD;CAGpD,cAAc;EAFQ,KAAA,4BAAA,IAAI,IAAe;EAGvC,KAAK,YAAY,KAAK,UAAU,KAAK,IAAI;CAC3C
|
|
1
|
+
{"version":3,"file":"subscribable.cjs","names":[],"sources":["../../src/subscribable.ts"],"sourcesContent":["/**\n * The base class behind everything in Query that you can subscribe to: `QueryCache`, `MutationCache`,\n * the observers, and the `FocusManager`/`OnlineManager` behind `focusManager` and `onlineManager`.\n * Subclasses decide what a listener receives and when it is called.\n */\nexport class Subscribable<TListener extends Function> {\n protected listeners = new Set<TListener>()\n\n constructor() {\n this.subscribe = this.subscribe.bind(this)\n }\n\n /**\n * Registers a listener to be called on every update this object notifies about. Returns a function\n * that removes the listener again — call it to stop listening. The base class never drops a listener\n * on its own, though some subclasses clear all of theirs in `destroy()`.\n * @param listener - Called on each update, with whatever the subclass passes to its subscribers.\n * @returns A function that removes the listener.\n * @example\n * ```ts\n * const unsubscribe = subscribable.subscribe(() => {\n * // react to the update\n * })\n *\n * unsubscribe()\n * ```\n */\n subscribe(listener: TListener): () => void {\n this.listeners.add(listener)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(listener)\n this.onUnsubscribe()\n }\n }\n\n /**\n * Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.\n * @returns `true` if at least one listener is registered.\n */\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n /**\n * Called after a listener is added. Does nothing here; subclasses override it, e.g. to start\n * tracking what they observe once the first listener subscribes.\n */\n protected onSubscribe(): void {\n // Do nothing\n }\n\n /**\n * Called after a listener is removed. Does nothing here; subclasses override it, e.g. to clean up\n * once the last listener unsubscribes.\n */\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n"],"mappings":";;;;;;;AAKA,IAAa,eAAb,MAAsD;CAGpD,cAAc;EAFQ,KAAA,4BAAA,IAAI,IAAe;EAGvC,KAAK,YAAY,KAAK,UAAU,KAAK,IAAI;CAC3C;;;;;;;;;;;;;;;;CAiBA,UAAU,UAAiC;EACzC,KAAK,UAAU,IAAI,QAAQ;EAE3B,KAAK,YAAY;EAEjB,aAAa;GACX,KAAK,UAAU,OAAO,QAAQ;GAC9B,KAAK,cAAc;EACrB;CACF;;;;;CAMA,eAAwB;EACtB,OAAO,KAAK,UAAU,OAAO;CAC/B;;;;;CAMA,cAA8B,CAE9B;;;;;CAMA,gBAAgC,CAEhC;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as Subscribable } from "./subscribable-
|
|
1
|
+
import { t as Subscribable } from "./subscribable-czlHOxMP.cjs";
|
|
2
2
|
export { Subscribable };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as Subscribable } from "./subscribable-
|
|
1
|
+
import { t as Subscribable } from "./subscribable-czlHOxMP.js";
|
|
2
2
|
export { Subscribable };
|
|
@@ -14,6 +14,7 @@ var Subscribable = class {
|
|
|
14
14
|
* that removes the listener again — call it to stop listening. The base class never drops a listener
|
|
15
15
|
* on its own, though some subclasses clear all of theirs in `destroy()`.
|
|
16
16
|
* @param listener - Called on each update, with whatever the subclass passes to its subscribers.
|
|
17
|
+
* @returns A function that removes the listener.
|
|
17
18
|
* @example
|
|
18
19
|
* ```ts
|
|
19
20
|
* const unsubscribe = subscribable.subscribe(() => {
|
|
@@ -33,11 +34,20 @@ var Subscribable = class {
|
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
35
36
|
* Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.
|
|
37
|
+
* @returns `true` if at least one listener is registered.
|
|
36
38
|
*/
|
|
37
39
|
hasListeners() {
|
|
38
40
|
return this.listeners.size > 0;
|
|
39
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Called after a listener is added. Does nothing here; subclasses override it, e.g. to start
|
|
44
|
+
* tracking what they observe once the first listener subscribes.
|
|
45
|
+
*/
|
|
40
46
|
onSubscribe() {}
|
|
47
|
+
/**
|
|
48
|
+
* Called after a listener is removed. Does nothing here; subclasses override it, e.g. to clean up
|
|
49
|
+
* once the last listener unsubscribes.
|
|
50
|
+
*/
|
|
41
51
|
onUnsubscribe() {}
|
|
42
52
|
};
|
|
43
53
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribable.js","names":[],"sources":["../../src/subscribable.ts"],"sourcesContent":["/**\n * The base class behind everything in Query that you can subscribe to: `QueryCache`, `MutationCache`,\n * the observers, and the `FocusManager`/`OnlineManager` behind `focusManager` and `onlineManager`.\n * Subclasses decide what a listener receives and when it is called.\n */\nexport class Subscribable<TListener extends Function> {\n protected listeners = new Set<TListener>()\n\n constructor() {\n this.subscribe = this.subscribe.bind(this)\n }\n\n /**\n * Registers a listener to be called on every update this object notifies about. Returns a function\n * that removes the listener again — call it to stop listening. The base class never drops a listener\n * on its own, though some subclasses clear all of theirs in `destroy()`.\n * @param listener - Called on each update, with whatever the subclass passes to its subscribers.\n * @example\n * ```ts\n * const unsubscribe = subscribable.subscribe(() => {\n * // react to the update\n * })\n *\n * unsubscribe()\n * ```\n */\n subscribe(listener: TListener): () => void {\n this.listeners.add(listener)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(listener)\n this.onUnsubscribe()\n }\n }\n\n /**\n * Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.\n */\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n protected onSubscribe(): void {\n // Do nothing\n }\n\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n"],"mappings":";;;;;;AAKA,IAAa,eAAb,MAAsD;CAGpD,cAAc;EAFQ,KAAA,4BAAA,IAAI,IAAe;EAGvC,KAAK,YAAY,KAAK,UAAU,KAAK,IAAI;CAC3C
|
|
1
|
+
{"version":3,"file":"subscribable.js","names":[],"sources":["../../src/subscribable.ts"],"sourcesContent":["/**\n * The base class behind everything in Query that you can subscribe to: `QueryCache`, `MutationCache`,\n * the observers, and the `FocusManager`/`OnlineManager` behind `focusManager` and `onlineManager`.\n * Subclasses decide what a listener receives and when it is called.\n */\nexport class Subscribable<TListener extends Function> {\n protected listeners = new Set<TListener>()\n\n constructor() {\n this.subscribe = this.subscribe.bind(this)\n }\n\n /**\n * Registers a listener to be called on every update this object notifies about. Returns a function\n * that removes the listener again — call it to stop listening. The base class never drops a listener\n * on its own, though some subclasses clear all of theirs in `destroy()`.\n * @param listener - Called on each update, with whatever the subclass passes to its subscribers.\n * @returns A function that removes the listener.\n * @example\n * ```ts\n * const unsubscribe = subscribable.subscribe(() => {\n * // react to the update\n * })\n *\n * unsubscribe()\n * ```\n */\n subscribe(listener: TListener): () => void {\n this.listeners.add(listener)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(listener)\n this.onUnsubscribe()\n }\n }\n\n /**\n * Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.\n * @returns `true` if at least one listener is registered.\n */\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n /**\n * Called after a listener is added. Does nothing here; subclasses override it, e.g. to start\n * tracking what they observe once the first listener subscribes.\n */\n protected onSubscribe(): void {\n // Do nothing\n }\n\n /**\n * Called after a listener is removed. Does nothing here; subclasses override it, e.g. to clean up\n * once the last listener unsubscribes.\n */\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n"],"mappings":";;;;;;AAKA,IAAa,eAAb,MAAsD;CAGpD,cAAc;EAFQ,KAAA,4BAAA,IAAI,IAAe;EAGvC,KAAK,YAAY,KAAK,UAAU,KAAK,IAAI;CAC3C;;;;;;;;;;;;;;;;CAiBA,UAAU,UAAiC;EACzC,KAAK,UAAU,IAAI,QAAQ;EAE3B,KAAK,YAAY;EAEjB,aAAa;GACX,KAAK,UAAU,OAAO,QAAQ;GAC9B,KAAK,cAAc;EACrB;CACF;;;;;CAMA,eAAwB;EACtB,OAAO,KAAK,UAAU,OAAO;CAC/B;;;;;CAMA,cAA8B,CAE9B;;;;;CAMA,gBAAgC,CAEhC;AACF"}
|
|
@@ -9,7 +9,7 @@ const defaultTimeoutProvider = {
|
|
|
9
9
|
/**
|
|
10
10
|
* Allows customization of how timeouts are created.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* `@tanstack/query-core` makes liberal use of timeouts to implement `staleTime`
|
|
13
13
|
* and `gcTime`. The default TimeoutManager provider uses the platform's global
|
|
14
14
|
* `setTimeout` implementation, which is known to have scalability issues with
|
|
15
15
|
* thousands of timeouts on the event loop.
|
|
@@ -34,7 +34,7 @@ var TimeoutManager = class {
|
|
|
34
34
|
* QueryClient or queries, so that the same provider is used consistently
|
|
35
35
|
* for all timers in the application, since different TimeoutProviders
|
|
36
36
|
* cannot cancel each others' timers.
|
|
37
|
-
*
|
|
37
|
+
* @param provider - The `TimeoutProvider` to use for all timers from now on.
|
|
38
38
|
* @example
|
|
39
39
|
* ```ts
|
|
40
40
|
* import { timeoutManager, QueryClient } from '@tanstack/query-core'
|
|
@@ -62,7 +62,9 @@ var TimeoutManager = class {
|
|
|
62
62
|
*
|
|
63
63
|
* It returns a timer ID, which may be a number or an object that can be
|
|
64
64
|
* coerced to a number via `Symbol.toPrimitive`.
|
|
65
|
-
*
|
|
65
|
+
* @param callback - The function to call when the timeout elapses.
|
|
66
|
+
* @param delay - The time to wait before calling `callback`, in milliseconds.
|
|
67
|
+
* @returns The timer ID, to pass to {@link TimeoutManager#clearTimeout}.
|
|
66
68
|
* @example
|
|
67
69
|
* ```ts
|
|
68
70
|
* import { timeoutManager } from '@tanstack/query-core'
|
|
@@ -83,7 +85,7 @@ var TimeoutManager = class {
|
|
|
83
85
|
* `clearTimeout` cancels a timeout callback scheduled with `setTimeout`,
|
|
84
86
|
* like the global `clearTimeout` function. It should be called with a
|
|
85
87
|
* timer ID returned by `setTimeout`.
|
|
86
|
-
*
|
|
88
|
+
* @param timeoutId - The timer ID returned by `setTimeout`, or `undefined`.
|
|
87
89
|
* @example
|
|
88
90
|
* ```ts
|
|
89
91
|
* import { timeoutManager } from '@tanstack/query-core'
|
|
@@ -105,7 +107,9 @@ var TimeoutManager = class {
|
|
|
105
107
|
*
|
|
106
108
|
* Like `setTimeout`, it returns a timer ID, which may be a number or an
|
|
107
109
|
* object that can be coerced to a number via `Symbol.toPrimitive`.
|
|
108
|
-
*
|
|
110
|
+
* @param callback - The function to call on every interval.
|
|
111
|
+
* @param delay - The time between calls, in milliseconds.
|
|
112
|
+
* @returns The timer ID, to pass to {@link TimeoutManager#clearInterval}.
|
|
109
113
|
* @example
|
|
110
114
|
* ```ts
|
|
111
115
|
* import { timeoutManager } from '@tanstack/query-core'
|
|
@@ -124,7 +128,7 @@ var TimeoutManager = class {
|
|
|
124
128
|
* `clearInterval` can be used to cancel an interval, like the global
|
|
125
129
|
* `clearInterval` function. It should be called with an interval ID
|
|
126
130
|
* returned by `setInterval`.
|
|
127
|
-
*
|
|
131
|
+
* @param intervalId - The timer ID returned by `setInterval`, or `undefined`.
|
|
128
132
|
* @example
|
|
129
133
|
* ```ts
|
|
130
134
|
* import { timeoutManager } from '@tanstack/query-core'
|
|
@@ -151,6 +155,7 @@ const timeoutManager = new TimeoutManager();
|
|
|
151
155
|
*
|
|
152
156
|
* This function is provided to make auditing the `tanstack/query-core` for
|
|
153
157
|
* incorrect use of system `setTimeout` easier.
|
|
158
|
+
* @param callback - The function to call on the next event loop tick.
|
|
154
159
|
*/
|
|
155
160
|
function systemSetTimeoutZero(callback) {
|
|
156
161
|
setTimeout(callback, 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeoutManager.cjs","names":[],"sources":["../../src/timeoutManager.ts"],"sourcesContent":["/**\n * {@link TimeoutManager} does not support passing arguments to the callback.\n *\n * `(_: void)` is the argument type inferred by TypeScript's default typings for\n * `setTimeout(cb, number)`.\n * If we don't accept a single void argument, then\n * `new Promise(resolve => timeoutManager.setTimeout(resolve, N))` is a type error.\n */\nexport type TimeoutCallback = (_: void) => void\n\n/**\n * Wrapping `setTimeout` is awkward from a typing perspective because platform\n * typings may extend the return type of `setTimeout`. For example, NodeJS\n * typings add `NodeJS.Timeout`; but a non-default `timeoutManager` may not be\n * able to return such a type.\n */\nexport type ManagedTimerId = number | { [Symbol.toPrimitive]: () => number }\n\n/**\n * Backend for timer functions.\n *\n * Timers are performance-sensitive: short-lived timers (delays under a few seconds) tend to be\n * latency-sensitive, while long-lived ones may benefit more from coalescing — batching timers\n * with similar deadlines together — which the default provider (backed by the platform's global\n * `setTimeout`/`setInterval`) does not do. A custom provider can implement coalescing, and can\n * also support delays longer than the ~24-day maximum of the global `setTimeout`.\n */\nexport type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> =\n {\n readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearTimeout: (timeoutId: TTimerId | undefined) => void\n\n readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearInterval: (intervalId: TTimerId | undefined) => void\n }\n\ntype SystemTimerId = ReturnType<typeof setTimeout>\n\nexport const defaultTimeoutProvider: TimeoutProvider = {\n // We need the wrapper function syntax below instead of direct references to\n // global setTimeout etc.\n //\n // BAD: `setTimeout: setTimeout`\n // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`\n //\n // If we use direct references here, then anything that wants to spy on or\n // replace the global setTimeout (like tests) won't work since we'll already\n // have a hard reference to the original implementation at the time when this\n // file was imported.\n setTimeout: (callback, delay) => setTimeout(callback, delay),\n clearTimeout: (timeoutId) =>\n clearTimeout(timeoutId as SystemTimerId | undefined),\n\n setInterval: (callback, delay) => setInterval(callback, delay),\n clearInterval: (intervalId) =>\n clearInterval(intervalId as SystemTimerId | undefined),\n}\n\n/**\n * Allows customization of how timeouts are created.\n *\n * @tanstack/query-core makes liberal use of timeouts to implement `staleTime`\n * and `gcTime`. The default TimeoutManager provider uses the platform's global\n * `setTimeout` implementation, which is known to have scalability issues with\n * thousands of timeouts on the event loop.\n *\n * If you hit this limitation, consider providing a custom TimeoutProvider that\n * coalesces timeouts.\n */\nexport class TimeoutManager implements Omit<TimeoutProvider, 'name'> {\n // We cannot have TimeoutManager<T> as we must instantiate it with a concrete\n // type at app boot; and if we leave that type, then any new timer provider\n // would need to support the default provider's concrete timer ID, which is\n // infeasible across environments.\n //\n // We settle for type safety for the TimeoutProvider type, and accept that\n // this class is unsafe internally to allow for extension.\n #provider: TimeoutProvider<any> = defaultTimeoutProvider\n #providerCalled = false\n\n /**\n * `setTimeoutProvider` can be used to set a custom implementation of the\n * `setTimeout`, `clearTimeout`, `setInterval`, `clearInterval` functions,\n * called a `TimeoutProvider`.\n *\n * This may be useful if you notice event loop performance issues with\n * thousands of queries. A custom TimeoutProvider could also support timer\n * delays longer than the global `setTimeout` maximum delay value of about\n * 24 days.\n *\n * It is important to call `setTimeoutProvider` before creating a\n * QueryClient or queries, so that the same provider is used consistently\n * for all timers in the application, since different TimeoutProviders\n * cannot cancel each others' timers.\n *\n * @example\n * ```ts\n * import { timeoutManager, QueryClient } from '@tanstack/query-core'\n * import { CustomTimeoutProvider } from './CustomTimeoutProvider'\n *\n * timeoutManager.setTimeoutProvider(new CustomTimeoutProvider())\n *\n * export const queryClient = new QueryClient()\n * ```\n */\n setTimeoutProvider<TTimerId extends ManagedTimerId>(\n provider: TimeoutProvider<TTimerId>,\n ): void {\n if (process.env.NODE_ENV !== 'production') {\n if (this.#providerCalled && provider !== this.#provider) {\n // After changing providers, `clearTimeout` will not work as expected for\n // timeouts from the previous provider.\n //\n // Since they may allocate the same timeout ID, clearTimeout may cancel an\n // arbitrary different timeout, or unexpected no-op.\n //\n // We could protect against this by mixing the timeout ID bits\n // deterministically with some per-provider bits.\n //\n // We could internally queue `setTimeout` calls to `TimeoutManager` until\n // some API call to set the initial provider.\n console.error(\n `[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,\n { previous: this.#provider, provider },\n )\n }\n }\n\n this.#provider = provider\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = false\n }\n }\n\n /**\n * `setTimeout` schedules a callback to run after approximately `delay`\n * milliseconds, like the global `setTimeout` function. The callback can be\n * canceled with `clearTimeout`.\n *\n * It returns a timer ID, which may be a number or an object that can be\n * coerced to a number via `Symbol.toPrimitive`.\n *\n * @example\n * ```ts\n * import { timeoutManager } from '@tanstack/query-core'\n *\n * const timeoutId = timeoutManager.setTimeout(\n * () => console.log('ran at:', new Date()),\n * 1000,\n * )\n *\n * const timeoutIdNumber: number = Number(timeoutId)\n * ```\n */\n setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setTimeout(callback, delay)\n }\n\n /**\n * `clearTimeout` cancels a timeout callback scheduled with `setTimeout`,\n * like the global `clearTimeout` function. It should be called with a\n * timer ID returned by `setTimeout`.\n *\n * @example\n * ```ts\n * import { timeoutManager } from '@tanstack/query-core'\n *\n * const timeoutId = timeoutManager.setTimeout(\n * () => console.log('ran at:', new Date()),\n * 1000,\n * )\n *\n * timeoutManager.clearTimeout(timeoutId)\n * ```\n */\n clearTimeout(timeoutId: ManagedTimerId | undefined): void {\n this.#provider.clearTimeout(timeoutId)\n }\n\n /**\n * `setInterval` schedules a callback to be called approximately every\n * `delay` milliseconds, like the global `setInterval` function.\n *\n * Like `setTimeout`, it returns a timer ID, which may be a number or an\n * object that can be coerced to a number via `Symbol.toPrimitive`.\n *\n * @example\n * ```ts\n * import { timeoutManager } from '@tanstack/query-core'\n *\n * const intervalId = timeoutManager.setInterval(\n * () => console.log('ran at:', new Date()),\n * 1000,\n * )\n * ```\n */\n setInterval(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setInterval(callback, delay)\n }\n\n /**\n * `clearInterval` can be used to cancel an interval, like the global\n * `clearInterval` function. It should be called with an interval ID\n * returned by `setInterval`.\n *\n * @example\n * ```ts\n * import { timeoutManager } from '@tanstack/query-core'\n *\n * const intervalId = timeoutManager.setInterval(\n * () => console.log('ran at:', new Date()),\n * 1000,\n * )\n *\n * timeoutManager.clearInterval(intervalId)\n * ```\n */\n clearInterval(intervalId: ManagedTimerId | undefined): void {\n this.#provider.clearInterval(intervalId)\n }\n}\n\n/**\n * Singleton instance of {@link TimeoutManager}, used throughout TanStack Query to schedule and cancel timers.\n */\nexport const timeoutManager = new TimeoutManager()\n\n/**\n * In many cases code wants to delay to the next event loop tick; this is not\n * mediated by {@link timeoutManager}.\n *\n * This function is provided to make auditing the `tanstack/query-core` for\n * incorrect use of system `setTimeout` easier.\n */\nexport function systemSetTimeoutZero(callback: TimeoutCallback): void {\n setTimeout(callback, 0)\n}\n"],"mappings":";;AAsCA,MAAa,yBAA0C;CAWrD,aAAa,UAAU,UAAU,WAAW,UAAU,KAAK;CAC3D,eAAe,cACb,aAAa,SAAsC;CAErD,cAAc,UAAU,UAAU,YAAY,UAAU,KAAK;CAC7D,gBAAgB,eACd,cAAc,UAAuC;AACzD;;;;;;;;;;;;AAaA,IAAa,iBAAb,MAAqE;CAQnE,YAAkC;CAClC,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BlB,mBACE,UACM;EACN,IAAI,QAAQ,IAAI,aAAa,cACvB;OAAA,KAAK,mBAAmB,aAAa,KAAK,WAY5C,QAAQ,MACN,8GACA;IAAE,UAAU,KAAK;IAAW;GAAS,CACvC;EAAA;EAIJ,KAAK,YAAY;EACjB,IAAI,QAAQ,IAAI,aAAa,cAC3B,KAAK,kBAAkB;CAE3B;;;;;;;;;;;;;;;;;;;;;CAsBA,WAAW,UAA2B,OAA+B;EACnE,IAAI,QAAQ,IAAI,aAAa,cAC3B,KAAK,kBAAkB;EAEzB,OAAO,KAAK,UAAU,WAAW,UAAU,KAAK;CAClD;;;;;;;;;;;;;;;;;;CAmBA,aAAa,WAA6C;EACxD,KAAK,UAAU,aAAa,SAAS;CACvC;;;;;;;;;;;;;;;;;;CAmBA,YAAY,UAA2B,OAA+B;EACpE,IAAI,QAAQ,IAAI,aAAa,cAC3B,KAAK,kBAAkB;EAEzB,OAAO,KAAK,UAAU,YAAY,UAAU,KAAK;CACnD;;;;;;;;;;;;;;;;;;CAmBA,cAAc,YAA8C;EAC1D,KAAK,UAAU,cAAc,UAAU;CACzC;AACF;;;;AAKA,MAAa,iBAAiB,IAAI,eAAe;;;;;;;;AASjD,SAAgB,qBAAqB,UAAiC;CACpE,WAAW,UAAU,CAAC;AACxB"}
|
|
1
|
+
{"version":3,"file":"timeoutManager.cjs","names":[],"sources":["../../src/timeoutManager.ts"],"sourcesContent":["/**\n * {@link TimeoutManager} does not support passing arguments to the callback.\n *\n * `(_: void)` is the argument type inferred by TypeScript's default typings for\n * `setTimeout(cb, number)`.\n * If we don't accept a single void argument, then\n * `new Promise(resolve => timeoutManager.setTimeout(resolve, N))` is a type error.\n */\nexport type TimeoutCallback = (_: void) => void\n\n/**\n * Wrapping `setTimeout` is awkward from a typing perspective because platform\n * typings may extend the return type of `setTimeout`. For example, NodeJS\n * typings add `NodeJS.Timeout`; but a non-default `timeoutManager` may not be\n * able to return such a type.\n */\nexport type ManagedTimerId = number | { [Symbol.toPrimitive]: () => number }\n\n/**\n * Backend for timer functions.\n *\n * Timers are performance-sensitive: short-lived timers (delays under a few seconds) tend to be\n * latency-sensitive, while long-lived ones may benefit more from coalescing — batching timers\n * with similar deadlines together — which the default provider (backed by the platform's global\n * `setTimeout`/`setInterval`) does not do. A custom provider can implement coalescing, and can\n * also support delays longer than the ~24-day maximum of the global `setTimeout`.\n */\nexport type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> =\n {\n /**\n * Schedules `callback` to run once after `delay` milliseconds, like the global `setTimeout`.\n */\n readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId\n /**\n * Cancels a timeout scheduled with `setTimeout`.\n */\n readonly clearTimeout: (timeoutId: TTimerId | undefined) => void\n\n /**\n * Schedules `callback` to run every `delay` milliseconds, like the global `setInterval`.\n */\n readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId\n /**\n * Cancels an interval scheduled with `setInterval`.\n */\n readonly clearInterval: (intervalId: TTimerId | undefined) => void\n }\n\ntype SystemTimerId = ReturnType<typeof setTimeout>\n\nexport const defaultTimeoutProvider: TimeoutProvider = {\n // We need the wrapper function syntax below instead of direct references to\n // global setTimeout etc.\n //\n // BAD: `setTimeout: setTimeout`\n // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`\n //\n // If we use direct references here, then anything that wants to spy on or\n // replace the global setTimeout (like tests) won't work since we'll already\n // have a hard reference to the original implementation at the time when this\n // file was imported.\n setTimeout: (callback, delay) => setTimeout(callback, delay),\n clearTimeout: (timeoutId) =>\n clearTimeout(timeoutId as SystemTimerId | undefined),\n\n setInterval: (callback, delay) => setInterval(callback, delay),\n clearInterval: (intervalId) =>\n clearInterval(intervalId as SystemTimerId | undefined),\n}\n\n/**\n * Allows customization of how timeouts are created.\n *\n * `@tanstack/query-core` makes liberal use of timeouts to implement `staleTime`\n * and `gcTime`. The default TimeoutManager provider uses the platform's global\n * `setTimeout` implementation, which is known to have scalability issues with\n * thousands of timeouts on the event loop.\n *\n * If you hit this limitation, consider providing a custom TimeoutProvider that\n * coalesces timeouts.\n */\nexport class TimeoutManager implements Omit<TimeoutProvider, 'name'> {\n // We cannot have TimeoutManager<T> as we must instantiate it with a concrete\n // type at app boot; and if we leave that type, then any new timer provider\n // would need to support the default provider's concrete timer ID, which is\n // infeasible across environments.\n //\n // We settle for type safety for the TimeoutProvider type, and accept that\n // this class is unsafe internally to allow for extension.\n #provider: TimeoutProvider<any> = defaultTimeoutProvider\n #providerCalled = false\n\n /**\n * `setTimeoutProvider` can be used to set a custom implementation of the\n * `setTimeout`, `clearTimeout`, `setInterval`, `clearInterval` functions,\n * called a `TimeoutProvider`.\n *\n * This may be useful if you notice event loop performance issues with\n * thousands of queries. A custom TimeoutProvider could also support timer\n * delays longer than the global `setTimeout` maximum delay value of about\n * 24 days.\n *\n * It is important to call `setTimeoutProvider` before creating a\n * QueryClient or queries, so that the same provider is used consistently\n * for all timers in the application, since different TimeoutProviders\n * cannot cancel each others' timers.\n * @param provider - The `TimeoutProvider` to use for all timers from now on.\n * @example\n * ```ts\n * import { timeoutManager, QueryClient } from '@tanstack/query-core'\n * import { CustomTimeoutProvider } from './CustomTimeoutProvider'\n *\n * timeoutManager.setTimeoutProvider(new CustomTimeoutProvider())\n *\n * export const queryClient = new QueryClient()\n * ```\n */\n setTimeoutProvider<TTimerId extends ManagedTimerId>(\n provider: TimeoutProvider<TTimerId>,\n ): void {\n if (process.env.NODE_ENV !== 'production') {\n if (this.#providerCalled && provider !== this.#provider) {\n // After changing providers, `clearTimeout` will not work as expected for\n // timeouts from the previous provider.\n //\n // Since they may allocate the same timeout ID, clearTimeout may cancel an\n // arbitrary different timeout, or unexpected no-op.\n //\n // We could protect against this by mixing the timeout ID bits\n // deterministically with some per-provider bits.\n //\n // We could internally queue `setTimeout` calls to `TimeoutManager` until\n // some API call to set the initial provider.\n console.error(\n `[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,\n { previous: this.#provider, provider },\n )\n }\n }\n\n this.#provider = provider\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = false\n }\n }\n\n /**\n * `setTimeout` schedules a callback to run after approximately `delay`\n * milliseconds, like the global `setTimeout` function. The callback can be\n * canceled with `clearTimeout`.\n *\n * It returns a timer ID, which may be a number or an object that can be\n * coerced to a number via `Symbol.toPrimitive`.\n * @param callback - The function to call when the timeout elapses.\n * @param delay - The time to wait before calling `callback`, in milliseconds.\n * @returns The timer ID, to pass to {@link TimeoutManager#clearTimeout}.\n * @example\n * ```ts\n * import { timeoutManager } from '@tanstack/query-core'\n *\n * const timeoutId = timeoutManager.setTimeout(\n * () => console.log('ran at:', new Date()),\n * 1000,\n * )\n *\n * const timeoutIdNumber: number = Number(timeoutId)\n * ```\n */\n setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setTimeout(callback, delay)\n }\n\n /**\n * `clearTimeout` cancels a timeout callback scheduled with `setTimeout`,\n * like the global `clearTimeout` function. It should be called with a\n * timer ID returned by `setTimeout`.\n * @param timeoutId - The timer ID returned by `setTimeout`, or `undefined`.\n * @example\n * ```ts\n * import { timeoutManager } from '@tanstack/query-core'\n *\n * const timeoutId = timeoutManager.setTimeout(\n * () => console.log('ran at:', new Date()),\n * 1000,\n * )\n *\n * timeoutManager.clearTimeout(timeoutId)\n * ```\n */\n clearTimeout(timeoutId: ManagedTimerId | undefined): void {\n this.#provider.clearTimeout(timeoutId)\n }\n\n /**\n * `setInterval` schedules a callback to be called approximately every\n * `delay` milliseconds, like the global `setInterval` function.\n *\n * Like `setTimeout`, it returns a timer ID, which may be a number or an\n * object that can be coerced to a number via `Symbol.toPrimitive`.\n * @param callback - The function to call on every interval.\n * @param delay - The time between calls, in milliseconds.\n * @returns The timer ID, to pass to {@link TimeoutManager#clearInterval}.\n * @example\n * ```ts\n * import { timeoutManager } from '@tanstack/query-core'\n *\n * const intervalId = timeoutManager.setInterval(\n * () => console.log('ran at:', new Date()),\n * 1000,\n * )\n * ```\n */\n setInterval(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setInterval(callback, delay)\n }\n\n /**\n * `clearInterval` can be used to cancel an interval, like the global\n * `clearInterval` function. It should be called with an interval ID\n * returned by `setInterval`.\n * @param intervalId - The timer ID returned by `setInterval`, or `undefined`.\n * @example\n * ```ts\n * import { timeoutManager } from '@tanstack/query-core'\n *\n * const intervalId = timeoutManager.setInterval(\n * () => console.log('ran at:', new Date()),\n * 1000,\n * )\n *\n * timeoutManager.clearInterval(intervalId)\n * ```\n */\n clearInterval(intervalId: ManagedTimerId | undefined): void {\n this.#provider.clearInterval(intervalId)\n }\n}\n\n/**\n * Singleton instance of {@link TimeoutManager}, used throughout TanStack Query to schedule and cancel timers.\n */\nexport const timeoutManager = new TimeoutManager()\n\n/**\n * In many cases code wants to delay to the next event loop tick; this is not\n * mediated by {@link timeoutManager}.\n *\n * This function is provided to make auditing the `tanstack/query-core` for\n * incorrect use of system `setTimeout` easier.\n * @param callback - The function to call on the next event loop tick.\n */\nexport function systemSetTimeoutZero(callback: TimeoutCallback): void {\n setTimeout(callback, 0)\n}\n"],"mappings":";;AAkDA,MAAa,yBAA0C;CAWrD,aAAa,UAAU,UAAU,WAAW,UAAU,KAAK;CAC3D,eAAe,cACb,aAAa,SAAsC;CAErD,cAAc,UAAU,UAAU,YAAY,UAAU,KAAK;CAC7D,gBAAgB,eACd,cAAc,UAAuC;AACzD;;;;;;;;;;;;AAaA,IAAa,iBAAb,MAAqE;CAQnE,YAAkC;CAClC,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BlB,mBACE,UACM;EACN,IAAI,QAAQ,IAAI,aAAa,cACvB;OAAA,KAAK,mBAAmB,aAAa,KAAK,WAY5C,QAAQ,MACN,8GACA;IAAE,UAAU,KAAK;IAAW;GAAS,CACvC;EAAA;EAIJ,KAAK,YAAY;EACjB,IAAI,QAAQ,IAAI,aAAa,cAC3B,KAAK,kBAAkB;CAE3B;;;;;;;;;;;;;;;;;;;;;;;CAwBA,WAAW,UAA2B,OAA+B;EACnE,IAAI,QAAQ,IAAI,aAAa,cAC3B,KAAK,kBAAkB;EAEzB,OAAO,KAAK,UAAU,WAAW,UAAU,KAAK;CAClD;;;;;;;;;;;;;;;;;;CAmBA,aAAa,WAA6C;EACxD,KAAK,UAAU,aAAa,SAAS;CACvC;;;;;;;;;;;;;;;;;;;;CAqBA,YAAY,UAA2B,OAA+B;EACpE,IAAI,QAAQ,IAAI,aAAa,cAC3B,KAAK,kBAAkB;EAEzB,OAAO,KAAK,UAAU,YAAY,UAAU,KAAK;CACnD;;;;;;;;;;;;;;;;;;CAmBA,cAAc,YAA8C;EAC1D,KAAK,UAAU,cAAc,UAAU;CACzC;AACF;;;;AAKA,MAAa,iBAAiB,IAAI,eAAe;;;;;;;;;AAUjD,SAAgB,qBAAqB,UAAiC;CACpE,WAAW,UAAU,CAAC;AACxB"}
|
|
@@ -27,16 +27,28 @@ export type ManagedTimerId = number | {
|
|
|
27
27
|
* also support delays longer than the ~24-day maximum of the global `setTimeout`.
|
|
28
28
|
*/
|
|
29
29
|
export type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> = {
|
|
30
|
+
/**
|
|
31
|
+
* Schedules `callback` to run once after `delay` milliseconds, like the global `setTimeout`.
|
|
32
|
+
*/
|
|
30
33
|
readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId;
|
|
34
|
+
/**
|
|
35
|
+
* Cancels a timeout scheduled with `setTimeout`.
|
|
36
|
+
*/
|
|
31
37
|
readonly clearTimeout: (timeoutId: TTimerId | undefined) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Schedules `callback` to run every `delay` milliseconds, like the global `setInterval`.
|
|
40
|
+
*/
|
|
32
41
|
readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId;
|
|
42
|
+
/**
|
|
43
|
+
* Cancels an interval scheduled with `setInterval`.
|
|
44
|
+
*/
|
|
33
45
|
readonly clearInterval: (intervalId: TTimerId | undefined) => void;
|
|
34
46
|
};
|
|
35
47
|
export declare const defaultTimeoutProvider: TimeoutProvider;
|
|
36
48
|
/**
|
|
37
49
|
* Allows customization of how timeouts are created.
|
|
38
50
|
*
|
|
39
|
-
*
|
|
51
|
+
* `@tanstack/query-core` makes liberal use of timeouts to implement `staleTime`
|
|
40
52
|
* and `gcTime`. The default TimeoutManager provider uses the platform's global
|
|
41
53
|
* `setTimeout` implementation, which is known to have scalability issues with
|
|
42
54
|
* thousands of timeouts on the event loop.
|
|
@@ -60,7 +72,7 @@ export declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
|
|
|
60
72
|
* QueryClient or queries, so that the same provider is used consistently
|
|
61
73
|
* for all timers in the application, since different TimeoutProviders
|
|
62
74
|
* cannot cancel each others' timers.
|
|
63
|
-
*
|
|
75
|
+
* @param provider - The `TimeoutProvider` to use for all timers from now on.
|
|
64
76
|
* @example
|
|
65
77
|
* ```ts
|
|
66
78
|
* import { timeoutManager, QueryClient } from '@tanstack/query-core'
|
|
@@ -79,7 +91,9 @@ export declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
|
|
|
79
91
|
*
|
|
80
92
|
* It returns a timer ID, which may be a number or an object that can be
|
|
81
93
|
* coerced to a number via `Symbol.toPrimitive`.
|
|
82
|
-
*
|
|
94
|
+
* @param callback - The function to call when the timeout elapses.
|
|
95
|
+
* @param delay - The time to wait before calling `callback`, in milliseconds.
|
|
96
|
+
* @returns The timer ID, to pass to {@link TimeoutManager#clearTimeout}.
|
|
83
97
|
* @example
|
|
84
98
|
* ```ts
|
|
85
99
|
* import { timeoutManager } from '@tanstack/query-core'
|
|
@@ -97,7 +111,7 @@ export declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
|
|
|
97
111
|
* `clearTimeout` cancels a timeout callback scheduled with `setTimeout`,
|
|
98
112
|
* like the global `clearTimeout` function. It should be called with a
|
|
99
113
|
* timer ID returned by `setTimeout`.
|
|
100
|
-
*
|
|
114
|
+
* @param timeoutId - The timer ID returned by `setTimeout`, or `undefined`.
|
|
101
115
|
* @example
|
|
102
116
|
* ```ts
|
|
103
117
|
* import { timeoutManager } from '@tanstack/query-core'
|
|
@@ -117,7 +131,9 @@ export declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
|
|
|
117
131
|
*
|
|
118
132
|
* Like `setTimeout`, it returns a timer ID, which may be a number or an
|
|
119
133
|
* object that can be coerced to a number via `Symbol.toPrimitive`.
|
|
120
|
-
*
|
|
134
|
+
* @param callback - The function to call on every interval.
|
|
135
|
+
* @param delay - The time between calls, in milliseconds.
|
|
136
|
+
* @returns The timer ID, to pass to {@link TimeoutManager#clearInterval}.
|
|
121
137
|
* @example
|
|
122
138
|
* ```ts
|
|
123
139
|
* import { timeoutManager } from '@tanstack/query-core'
|
|
@@ -133,7 +149,7 @@ export declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
|
|
|
133
149
|
* `clearInterval` can be used to cancel an interval, like the global
|
|
134
150
|
* `clearInterval` function. It should be called with an interval ID
|
|
135
151
|
* returned by `setInterval`.
|
|
136
|
-
*
|
|
152
|
+
* @param intervalId - The timer ID returned by `setInterval`, or `undefined`.
|
|
137
153
|
* @example
|
|
138
154
|
* ```ts
|
|
139
155
|
* import { timeoutManager } from '@tanstack/query-core'
|
|
@@ -158,6 +174,7 @@ export declare const timeoutManager: TimeoutManager;
|
|
|
158
174
|
*
|
|
159
175
|
* This function is provided to make auditing the `tanstack/query-core` for
|
|
160
176
|
* incorrect use of system `setTimeout` easier.
|
|
177
|
+
* @param callback - The function to call on the next event loop tick.
|
|
161
178
|
*/
|
|
162
179
|
export declare function systemSetTimeoutZero(callback: TimeoutCallback): void;
|
|
163
180
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeoutManager.d.cts","names":[],"sources":["../../src/timeoutManager.ts"],"mappings":";;;;;;;;;YAQY,mBAAmB;;;;;;;YAQnB;GAA6B,OAAO;;;;;;;;;;;YAWpC,gBAAgB,iBAAiB,iBAAiB
|
|
1
|
+
{"version":3,"file":"timeoutManager.d.cts","names":[],"sources":["../../src/timeoutManager.ts"],"mappings":";;;;;;;;;YAQY,mBAAmB;;;;;;;YAQnB;GAA6B,OAAO;;;;;;;;;;;YAWpC,gBAAgB,iBAAiB,iBAAiB;;;;WAKjD,aAAa,UAAU,iBAAiB,kBAAkB;;;;WAI1D,eAAe,WAAW;;;;WAK1B,cAAc,UAAU,iBAAiB,kBAAkB;;;;WAI3D,gBAAgB,YAAY;;qBAK5B,wBAAwB;;;;;;;;;;;;qBA+BxB,0BAA0B,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoC1C,mBAAmB,iBAAiB,gBAClC,UAAU,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;EAkD5B,WAAW,UAAU,iBAAiB,gBAAgB;;;;;;;;;;;;;;;;;;EAwBtD,aAAa,WAAW;;;;;;;;;;;;;;;;;;;;EAuBxB,YAAY,UAAU,iBAAiB,gBAAgB;;;;;;;;;;;;;;;;;;EAwBvD,cAAc,YAAY;;;;;qBAQf,gBAAc;;;;;;;;;wBAUX,qBAAqB,UAAU"}
|
|
@@ -27,16 +27,28 @@ export type ManagedTimerId = number | {
|
|
|
27
27
|
* also support delays longer than the ~24-day maximum of the global `setTimeout`.
|
|
28
28
|
*/
|
|
29
29
|
export type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> = {
|
|
30
|
+
/**
|
|
31
|
+
* Schedules `callback` to run once after `delay` milliseconds, like the global `setTimeout`.
|
|
32
|
+
*/
|
|
30
33
|
readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId;
|
|
34
|
+
/**
|
|
35
|
+
* Cancels a timeout scheduled with `setTimeout`.
|
|
36
|
+
*/
|
|
31
37
|
readonly clearTimeout: (timeoutId: TTimerId | undefined) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Schedules `callback` to run every `delay` milliseconds, like the global `setInterval`.
|
|
40
|
+
*/
|
|
32
41
|
readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId;
|
|
42
|
+
/**
|
|
43
|
+
* Cancels an interval scheduled with `setInterval`.
|
|
44
|
+
*/
|
|
33
45
|
readonly clearInterval: (intervalId: TTimerId | undefined) => void;
|
|
34
46
|
};
|
|
35
47
|
export declare const defaultTimeoutProvider: TimeoutProvider;
|
|
36
48
|
/**
|
|
37
49
|
* Allows customization of how timeouts are created.
|
|
38
50
|
*
|
|
39
|
-
*
|
|
51
|
+
* `@tanstack/query-core` makes liberal use of timeouts to implement `staleTime`
|
|
40
52
|
* and `gcTime`. The default TimeoutManager provider uses the platform's global
|
|
41
53
|
* `setTimeout` implementation, which is known to have scalability issues with
|
|
42
54
|
* thousands of timeouts on the event loop.
|
|
@@ -60,7 +72,7 @@ export declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
|
|
|
60
72
|
* QueryClient or queries, so that the same provider is used consistently
|
|
61
73
|
* for all timers in the application, since different TimeoutProviders
|
|
62
74
|
* cannot cancel each others' timers.
|
|
63
|
-
*
|
|
75
|
+
* @param provider - The `TimeoutProvider` to use for all timers from now on.
|
|
64
76
|
* @example
|
|
65
77
|
* ```ts
|
|
66
78
|
* import { timeoutManager, QueryClient } from '@tanstack/query-core'
|
|
@@ -79,7 +91,9 @@ export declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
|
|
|
79
91
|
*
|
|
80
92
|
* It returns a timer ID, which may be a number or an object that can be
|
|
81
93
|
* coerced to a number via `Symbol.toPrimitive`.
|
|
82
|
-
*
|
|
94
|
+
* @param callback - The function to call when the timeout elapses.
|
|
95
|
+
* @param delay - The time to wait before calling `callback`, in milliseconds.
|
|
96
|
+
* @returns The timer ID, to pass to {@link TimeoutManager#clearTimeout}.
|
|
83
97
|
* @example
|
|
84
98
|
* ```ts
|
|
85
99
|
* import { timeoutManager } from '@tanstack/query-core'
|
|
@@ -97,7 +111,7 @@ export declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
|
|
|
97
111
|
* `clearTimeout` cancels a timeout callback scheduled with `setTimeout`,
|
|
98
112
|
* like the global `clearTimeout` function. It should be called with a
|
|
99
113
|
* timer ID returned by `setTimeout`.
|
|
100
|
-
*
|
|
114
|
+
* @param timeoutId - The timer ID returned by `setTimeout`, or `undefined`.
|
|
101
115
|
* @example
|
|
102
116
|
* ```ts
|
|
103
117
|
* import { timeoutManager } from '@tanstack/query-core'
|
|
@@ -117,7 +131,9 @@ export declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
|
|
|
117
131
|
*
|
|
118
132
|
* Like `setTimeout`, it returns a timer ID, which may be a number or an
|
|
119
133
|
* object that can be coerced to a number via `Symbol.toPrimitive`.
|
|
120
|
-
*
|
|
134
|
+
* @param callback - The function to call on every interval.
|
|
135
|
+
* @param delay - The time between calls, in milliseconds.
|
|
136
|
+
* @returns The timer ID, to pass to {@link TimeoutManager#clearInterval}.
|
|
121
137
|
* @example
|
|
122
138
|
* ```ts
|
|
123
139
|
* import { timeoutManager } from '@tanstack/query-core'
|
|
@@ -133,7 +149,7 @@ export declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
|
|
|
133
149
|
* `clearInterval` can be used to cancel an interval, like the global
|
|
134
150
|
* `clearInterval` function. It should be called with an interval ID
|
|
135
151
|
* returned by `setInterval`.
|
|
136
|
-
*
|
|
152
|
+
* @param intervalId - The timer ID returned by `setInterval`, or `undefined`.
|
|
137
153
|
* @example
|
|
138
154
|
* ```ts
|
|
139
155
|
* import { timeoutManager } from '@tanstack/query-core'
|
|
@@ -158,6 +174,7 @@ export declare const timeoutManager: TimeoutManager;
|
|
|
158
174
|
*
|
|
159
175
|
* This function is provided to make auditing the `tanstack/query-core` for
|
|
160
176
|
* incorrect use of system `setTimeout` easier.
|
|
177
|
+
* @param callback - The function to call on the next event loop tick.
|
|
161
178
|
*/
|
|
162
179
|
export declare function systemSetTimeoutZero(callback: TimeoutCallback): void;
|
|
163
180
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeoutManager.d.ts","names":[],"sources":["../../src/timeoutManager.ts"],"mappings":";;;;;;;;;YAQY,mBAAmB;;;;;;;YAQnB;GAA6B,OAAO;;;;;;;;;;;YAWpC,gBAAgB,iBAAiB,iBAAiB
|
|
1
|
+
{"version":3,"file":"timeoutManager.d.ts","names":[],"sources":["../../src/timeoutManager.ts"],"mappings":";;;;;;;;;YAQY,mBAAmB;;;;;;;YAQnB;GAA6B,OAAO;;;;;;;;;;;YAWpC,gBAAgB,iBAAiB,iBAAiB;;;;WAKjD,aAAa,UAAU,iBAAiB,kBAAkB;;;;WAI1D,eAAe,WAAW;;;;WAK1B,cAAc,UAAU,iBAAiB,kBAAkB;;;;WAI3D,gBAAgB,YAAY;;qBAK5B,wBAAwB;;;;;;;;;;;;qBA+BxB,0BAA0B,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoC1C,mBAAmB,iBAAiB,gBAClC,UAAU,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;EAkD5B,WAAW,UAAU,iBAAiB,gBAAgB;;;;;;;;;;;;;;;;;;EAwBtD,aAAa,WAAW;;;;;;;;;;;;;;;;;;;;EAuBxB,YAAY,UAAU,iBAAiB,gBAAgB;;;;;;;;;;;;;;;;;;EAwBvD,cAAc,YAAY;;;;;qBAQf,gBAAc;;;;;;;;;wBAUX,qBAAqB,UAAU"}
|