@tanstack/query-core 5.83.1 → 5.87.4
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/{hydration-Cvr-9VdO.d.ts → hydration-BYonJkjc.d.ts} +8 -6
- package/build/legacy/{hydration-CADtEOkK.d.cts → hydration-_hO-y142.d.cts} +8 -6
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/index.cjs +14 -12
- package/build/legacy/index.cjs.map +1 -1
- package/build/legacy/index.d.cts +5 -4
- package/build/legacy/index.d.ts +5 -4
- package/build/legacy/index.js +26 -23
- package/build/legacy/index.js.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +1 -1
- package/build/legacy/infiniteQueryObserver.d.ts +1 -1
- package/build/legacy/mutation.d.cts +1 -1
- package/build/legacy/mutation.d.ts +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationObserver.d.cts +1 -1
- package/build/legacy/mutationObserver.d.ts +1 -1
- package/build/legacy/notifyManager.cjs +2 -1
- package/build/legacy/notifyManager.cjs.map +1 -1
- package/build/legacy/notifyManager.js +2 -1
- package/build/legacy/notifyManager.js.map +1 -1
- package/build/legacy/queriesObserver.cjs +19 -13
- package/build/legacy/queriesObserver.cjs.map +1 -1
- package/build/legacy/queriesObserver.d.cts +1 -1
- package/build/legacy/queriesObserver.d.ts +1 -1
- package/build/legacy/queriesObserver.js +20 -14
- package/build/legacy/queriesObserver.js.map +1 -1
- package/build/legacy/query.cjs +78 -61
- 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 +79 -62
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryObserver.cjs +12 -9
- 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 +12 -9
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/legacy/removable.cjs +3 -2
- package/build/legacy/removable.cjs.map +1 -1
- package/build/legacy/removable.js +3 -2
- package/build/legacy/removable.js.map +1 -1
- package/build/legacy/retryer.cjs +12 -16
- 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 +12 -16
- package/build/legacy/retryer.js.map +1 -1
- package/build/legacy/streamedQuery.cjs +7 -8
- package/build/legacy/streamedQuery.cjs.map +1 -1
- package/build/legacy/streamedQuery.d.cts +18 -10
- package/build/legacy/streamedQuery.d.ts +18 -10
- package/build/legacy/streamedQuery.js +7 -8
- package/build/legacy/streamedQuery.js.map +1 -1
- package/build/legacy/timeoutManager.cjs +110 -0
- package/build/legacy/timeoutManager.cjs.map +1 -0
- package/build/legacy/timeoutManager.d.cts +58 -0
- package/build/legacy/timeoutManager.d.ts +58 -0
- package/build/legacy/timeoutManager.js +81 -0
- package/build/legacy/timeoutManager.js.map +1 -0
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/utils.cjs +26 -22
- 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 +26 -22
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/{hydration-Cvr-9VdO.d.ts → hydration-BYonJkjc.d.ts} +8 -6
- package/build/modern/{hydration-CADtEOkK.d.cts → hydration-_hO-y142.d.cts} +8 -6
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/index.cjs +14 -12
- package/build/modern/index.cjs.map +1 -1
- package/build/modern/index.d.cts +5 -4
- package/build/modern/index.d.ts +5 -4
- package/build/modern/index.js +26 -23
- package/build/modern/index.js.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +1 -1
- package/build/modern/infiniteQueryObserver.d.ts +1 -1
- package/build/modern/mutation.d.cts +1 -1
- package/build/modern/mutation.d.ts +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationObserver.d.cts +1 -1
- package/build/modern/mutationObserver.d.ts +1 -1
- package/build/modern/notifyManager.cjs +2 -1
- package/build/modern/notifyManager.cjs.map +1 -1
- package/build/modern/notifyManager.js +2 -1
- package/build/modern/notifyManager.js.map +1 -1
- package/build/modern/queriesObserver.cjs +19 -13
- package/build/modern/queriesObserver.cjs.map +1 -1
- package/build/modern/queriesObserver.d.cts +1 -1
- package/build/modern/queriesObserver.d.ts +1 -1
- package/build/modern/queriesObserver.js +20 -14
- package/build/modern/queriesObserver.js.map +1 -1
- package/build/modern/query.cjs +71 -52
- 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 +72 -53
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryObserver.cjs +12 -9
- 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 +12 -9
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/removable.cjs +3 -2
- package/build/modern/removable.cjs.map +1 -1
- package/build/modern/removable.js +3 -2
- package/build/modern/removable.js.map +1 -1
- package/build/modern/retryer.cjs +12 -14
- 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 +12 -14
- package/build/modern/retryer.js.map +1 -1
- package/build/modern/streamedQuery.cjs +7 -8
- package/build/modern/streamedQuery.cjs.map +1 -1
- package/build/modern/streamedQuery.d.cts +18 -10
- package/build/modern/streamedQuery.d.ts +18 -10
- package/build/modern/streamedQuery.js +7 -8
- package/build/modern/streamedQuery.js.map +1 -1
- package/build/modern/timeoutManager.cjs +98 -0
- package/build/modern/timeoutManager.cjs.map +1 -0
- package/build/modern/timeoutManager.d.cts +58 -0
- package/build/modern/timeoutManager.d.ts +58 -0
- package/build/modern/timeoutManager.js +70 -0
- package/build/modern/timeoutManager.js.map +1 -0
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/utils.cjs +26 -22
- 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 +26 -22
- package/build/modern/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +32 -27
- package/src/notifyManager.ts +3 -1
- package/src/queriesObserver.ts +24 -15
- package/src/query.ts +96 -69
- package/src/queryObserver.ts +19 -11
- package/src/removable.ts +5 -3
- package/src/retryer.ts +20 -17
- package/src/streamedQuery.ts +47 -23
- package/src/timeoutManager.ts +135 -0
- package/src/utils.ts +39 -31
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addToEnd } from './utils'\nimport type { QueryFunction, QueryFunctionContext, QueryKey } from './types'\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 queryFn - The function that returns an AsyncIterable to stream data from.\n * @param refetchMode - Defines how re-fetches are handled.\n * Defaults to `'reset'`, erases all data and puts the query back into `pending` state.\n * Set to `'append'` to append new data to the existing data.\n * Set to `'replace'` to write all data to the cache once the stream ends.\n * @param
|
|
1
|
+
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addToEnd } from './utils'\nimport type { QueryFunction, QueryFunctionContext, QueryKey } from './types'\n\ntype BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {\n streamFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\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 reducer: (acc: TData, chunk: TQueryFnData) => TData\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 queryFn - The function that returns an AsyncIterable to stream data from.\n * @param refetchMode - Defines how re-fetches are handled.\n * Defaults to `'reset'`, erases all data and puts the query back into `pending` state.\n * Set to `'append'` to append new data to the existing data.\n * Set to `'replace'` to write all data to the cache once the stream ends.\n * @param reducer - A function to reduce the streamed chunks into the final data.\n * Defaults to a function that appends chunks to the end of the array.\n * @param initialValue - Initial value to be used while the first chunk is being fetched.\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.state.data !== undefined\n if (isRefetch && refetchMode === 'reset') {\n query.setState({\n status: 'pending',\n data: undefined,\n error: null,\n fetchStatus: 'fetching',\n })\n }\n\n let result = initialValue\n\n const stream = await streamFn(context)\n\n for await (const chunk of stream) {\n if (context.signal.aborted) {\n break\n }\n\n // don't append to the cache directly when replace-refetching\n if (!isRefetch || refetchMode !== 'replace') {\n context.client.setQueryData<TData>(context.queryKey, (prev) =>\n reducer(prev === undefined ? initialValue : prev, chunk),\n )\n }\n result = reducer(result, chunk)\n }\n\n // finalize result: replace-refetching needs to write to the cache\n if (isRefetch && refetchMode === 'replace' && !context.signal.aborted) {\n context.client.setQueryData<TData>(context.queryKey, result)\n }\n\n return context.client.getQueryData(context.queryKey)!\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyB;AA6ClB,SAAS,cAId;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,UAAU,CAAC,OAAO,cAChB,uBAAS,OAA8B,KAAK;AAAA,EAC9C,eAAe,CAAC;AAClB,GAGE;AACA,SAAO,OAAO,YAAY;AACxB,UAAM,QAAQ,QAAQ,OACnB,cAAc,EACd,KAAK,EAAE,UAAU,QAAQ,UAAU,OAAO,KAAK,CAAC;AACnD,UAAM,YAAY,CAAC,CAAC,SAAS,MAAM,MAAM,SAAS;AAClD,QAAI,aAAa,gBAAgB,SAAS;AACxC,YAAM,SAAS;AAAA,QACb,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,OAAO;AAAA,QACP,aAAa;AAAA,MACf,CAAC;AAAA,IACH;AAEA,QAAI,SAAS;AAEb,UAAM,SAAS,MAAM,SAAS,OAAO;AAErC,qBAAiB,SAAS,QAAQ;AAChC,UAAI,QAAQ,OAAO,SAAS;AAC1B;AAAA,MACF;AAGA,UAAI,CAAC,aAAa,gBAAgB,WAAW;AAC3C,gBAAQ,OAAO;AAAA,UAAoB,QAAQ;AAAA,UAAU,CAAC,SACpD,QAAQ,SAAS,SAAY,eAAe,MAAM,KAAK;AAAA,QACzD;AAAA,MACF;AACA,eAAS,QAAQ,QAAQ,KAAK;AAAA,IAChC;AAGA,QAAI,aAAa,gBAAgB,aAAa,CAAC,QAAQ,OAAO,SAAS;AACrE,cAAQ,OAAO,aAAoB,QAAQ,UAAU,MAAM;AAAA,IAC7D;AAEA,WAAO,QAAQ,OAAO,aAAa,QAAQ,QAAQ;AAAA,EACrD;AACF;","names":[]}
|
|
@@ -1,7 +1,20 @@
|
|
|
1
|
-
import { I as QueryKey, a1 as QueryFunctionContext, Y as QueryFunction } from './hydration-
|
|
1
|
+
import { I as QueryKey, a1 as QueryFunctionContext, Y as QueryFunction } from './hydration-_hO-y142.cjs';
|
|
2
2
|
import './removable.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
|
4
4
|
|
|
5
|
+
type BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {
|
|
6
|
+
streamFn: (context: QueryFunctionContext<TQueryKey>) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>;
|
|
7
|
+
refetchMode?: 'append' | 'reset' | 'replace';
|
|
8
|
+
};
|
|
9
|
+
type SimpleStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {
|
|
10
|
+
reducer?: never;
|
|
11
|
+
initialValue?: never;
|
|
12
|
+
};
|
|
13
|
+
type ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {
|
|
14
|
+
reducer: (acc: TData, chunk: TQueryFnData) => TData;
|
|
15
|
+
initialValue: TData;
|
|
16
|
+
};
|
|
17
|
+
type StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> = SimpleStreamedQueryParams<TQueryFnData, TQueryKey> | ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey>;
|
|
5
18
|
/**
|
|
6
19
|
* This is a helper function to create a query function that streams data from an AsyncIterable.
|
|
7
20
|
* Data will be an Array of all the chunks received.
|
|
@@ -12,15 +25,10 @@ import './subscribable.cjs';
|
|
|
12
25
|
* Defaults to `'reset'`, erases all data and puts the query back into `pending` state.
|
|
13
26
|
* Set to `'append'` to append new data to the existing data.
|
|
14
27
|
* Set to `'replace'` to write all data to the cache once the stream ends.
|
|
15
|
-
* @param
|
|
16
|
-
* Defaults to
|
|
17
|
-
*
|
|
18
|
-
* If the number of chunks exceeds this number, the oldest chunk will be removed.
|
|
28
|
+
* @param reducer - A function to reduce the streamed chunks into the final data.
|
|
29
|
+
* Defaults to a function that appends chunks to the end of the array.
|
|
30
|
+
* @param initialValue - Initial value to be used while the first chunk is being fetched.
|
|
19
31
|
*/
|
|
20
|
-
declare function streamedQuery<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>({
|
|
21
|
-
queryFn: (context: QueryFunctionContext<TQueryKey>) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>;
|
|
22
|
-
refetchMode?: 'append' | 'reset' | 'replace';
|
|
23
|
-
maxChunks?: number;
|
|
24
|
-
}): QueryFunction<Array<TQueryFnData>, TQueryKey>;
|
|
32
|
+
declare function streamedQuery<TQueryFnData = unknown, TData = Array<TQueryFnData>, TQueryKey extends QueryKey = QueryKey>({ streamFn, refetchMode, reducer, initialValue, }: StreamedQueryParams<TQueryFnData, TData, TQueryKey>): QueryFunction<TData, TQueryKey>;
|
|
25
33
|
|
|
26
34
|
export { streamedQuery };
|
|
@@ -1,7 +1,20 @@
|
|
|
1
|
-
import { I as QueryKey, a1 as QueryFunctionContext, Y as QueryFunction } from './hydration-
|
|
1
|
+
import { I as QueryKey, a1 as QueryFunctionContext, Y as QueryFunction } from './hydration-BYonJkjc.js';
|
|
2
2
|
import './removable.js';
|
|
3
3
|
import './subscribable.js';
|
|
4
4
|
|
|
5
|
+
type BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {
|
|
6
|
+
streamFn: (context: QueryFunctionContext<TQueryKey>) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>;
|
|
7
|
+
refetchMode?: 'append' | 'reset' | 'replace';
|
|
8
|
+
};
|
|
9
|
+
type SimpleStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {
|
|
10
|
+
reducer?: never;
|
|
11
|
+
initialValue?: never;
|
|
12
|
+
};
|
|
13
|
+
type ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {
|
|
14
|
+
reducer: (acc: TData, chunk: TQueryFnData) => TData;
|
|
15
|
+
initialValue: TData;
|
|
16
|
+
};
|
|
17
|
+
type StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> = SimpleStreamedQueryParams<TQueryFnData, TQueryKey> | ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey>;
|
|
5
18
|
/**
|
|
6
19
|
* This is a helper function to create a query function that streams data from an AsyncIterable.
|
|
7
20
|
* Data will be an Array of all the chunks received.
|
|
@@ -12,15 +25,10 @@ import './subscribable.js';
|
|
|
12
25
|
* Defaults to `'reset'`, erases all data and puts the query back into `pending` state.
|
|
13
26
|
* Set to `'append'` to append new data to the existing data.
|
|
14
27
|
* Set to `'replace'` to write all data to the cache once the stream ends.
|
|
15
|
-
* @param
|
|
16
|
-
* Defaults to
|
|
17
|
-
*
|
|
18
|
-
* If the number of chunks exceeds this number, the oldest chunk will be removed.
|
|
28
|
+
* @param reducer - A function to reduce the streamed chunks into the final data.
|
|
29
|
+
* Defaults to a function that appends chunks to the end of the array.
|
|
30
|
+
* @param initialValue - Initial value to be used while the first chunk is being fetched.
|
|
19
31
|
*/
|
|
20
|
-
declare function streamedQuery<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>({
|
|
21
|
-
queryFn: (context: QueryFunctionContext<TQueryKey>) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>;
|
|
22
|
-
refetchMode?: 'append' | 'reset' | 'replace';
|
|
23
|
-
maxChunks?: number;
|
|
24
|
-
}): QueryFunction<Array<TQueryFnData>, TQueryKey>;
|
|
32
|
+
declare function streamedQuery<TQueryFnData = unknown, TData = Array<TQueryFnData>, TQueryKey extends QueryKey = QueryKey>({ streamFn, refetchMode, reducer, initialValue, }: StreamedQueryParams<TQueryFnData, TData, TQueryKey>): QueryFunction<TData, TQueryKey>;
|
|
25
33
|
|
|
26
34
|
export { streamedQuery };
|
|
@@ -3,9 +3,10 @@ import "./chunk-PXG64RU4.js";
|
|
|
3
3
|
// src/streamedQuery.ts
|
|
4
4
|
import { addToEnd } from "./utils.js";
|
|
5
5
|
function streamedQuery({
|
|
6
|
-
|
|
6
|
+
streamFn,
|
|
7
7
|
refetchMode = "reset",
|
|
8
|
-
|
|
8
|
+
reducer = (items, chunk) => addToEnd(items, chunk),
|
|
9
|
+
initialValue = []
|
|
9
10
|
}) {
|
|
10
11
|
return async (context) => {
|
|
11
12
|
const query = context.client.getQueryCache().find({ queryKey: context.queryKey, exact: true });
|
|
@@ -18,8 +19,8 @@ function streamedQuery({
|
|
|
18
19
|
fetchStatus: "fetching"
|
|
19
20
|
});
|
|
20
21
|
}
|
|
21
|
-
let result =
|
|
22
|
-
const stream = await
|
|
22
|
+
let result = initialValue;
|
|
23
|
+
const stream = await streamFn(context);
|
|
23
24
|
for await (const chunk of stream) {
|
|
24
25
|
if (context.signal.aborted) {
|
|
25
26
|
break;
|
|
@@ -27,12 +28,10 @@ function streamedQuery({
|
|
|
27
28
|
if (!isRefetch || refetchMode !== "replace") {
|
|
28
29
|
context.client.setQueryData(
|
|
29
30
|
context.queryKey,
|
|
30
|
-
(prev
|
|
31
|
-
return addToEnd(prev, chunk, maxChunks);
|
|
32
|
-
}
|
|
31
|
+
(prev) => reducer(prev === void 0 ? initialValue : prev, chunk)
|
|
33
32
|
);
|
|
34
33
|
}
|
|
35
|
-
result =
|
|
34
|
+
result = reducer(result, chunk);
|
|
36
35
|
}
|
|
37
36
|
if (isRefetch && refetchMode === "replace" && !context.signal.aborted) {
|
|
38
37
|
context.client.setQueryData(context.queryKey, result);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addToEnd } from './utils'\nimport type { QueryFunction, QueryFunctionContext, QueryKey } from './types'\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 queryFn - The function that returns an AsyncIterable to stream data from.\n * @param refetchMode - Defines how re-fetches are handled.\n * Defaults to `'reset'`, erases all data and puts the query back into `pending` state.\n * Set to `'append'` to append new data to the existing data.\n * Set to `'replace'` to write all data to the cache once the stream ends.\n * @param
|
|
1
|
+
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addToEnd } from './utils'\nimport type { QueryFunction, QueryFunctionContext, QueryKey } from './types'\n\ntype BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {\n streamFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\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 reducer: (acc: TData, chunk: TQueryFnData) => TData\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 queryFn - The function that returns an AsyncIterable to stream data from.\n * @param refetchMode - Defines how re-fetches are handled.\n * Defaults to `'reset'`, erases all data and puts the query back into `pending` state.\n * Set to `'append'` to append new data to the existing data.\n * Set to `'replace'` to write all data to the cache once the stream ends.\n * @param reducer - A function to reduce the streamed chunks into the final data.\n * Defaults to a function that appends chunks to the end of the array.\n * @param initialValue - Initial value to be used while the first chunk is being fetched.\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.state.data !== undefined\n if (isRefetch && refetchMode === 'reset') {\n query.setState({\n status: 'pending',\n data: undefined,\n error: null,\n fetchStatus: 'fetching',\n })\n }\n\n let result = initialValue\n\n const stream = await streamFn(context)\n\n for await (const chunk of stream) {\n if (context.signal.aborted) {\n break\n }\n\n // don't append to the cache directly when replace-refetching\n if (!isRefetch || refetchMode !== 'replace') {\n context.client.setQueryData<TData>(context.queryKey, (prev) =>\n reducer(prev === undefined ? initialValue : prev, chunk),\n )\n }\n result = reducer(result, chunk)\n }\n\n // finalize result: replace-refetching needs to write to the cache\n if (isRefetch && refetchMode === 'replace' && !context.signal.aborted) {\n context.client.setQueryData<TData>(context.queryKey, result)\n }\n\n return context.client.getQueryData(context.queryKey)!\n }\n}\n"],"mappings":";;;AAAA,SAAS,gBAAgB;AA6ClB,SAAS,cAId;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,UAAU,CAAC,OAAO,UAChB,SAAS,OAA8B,KAAK;AAAA,EAC9C,eAAe,CAAC;AAClB,GAGE;AACA,SAAO,OAAO,YAAY;AACxB,UAAM,QAAQ,QAAQ,OACnB,cAAc,EACd,KAAK,EAAE,UAAU,QAAQ,UAAU,OAAO,KAAK,CAAC;AACnD,UAAM,YAAY,CAAC,CAAC,SAAS,MAAM,MAAM,SAAS;AAClD,QAAI,aAAa,gBAAgB,SAAS;AACxC,YAAM,SAAS;AAAA,QACb,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,OAAO;AAAA,QACP,aAAa;AAAA,MACf,CAAC;AAAA,IACH;AAEA,QAAI,SAAS;AAEb,UAAM,SAAS,MAAM,SAAS,OAAO;AAErC,qBAAiB,SAAS,QAAQ;AAChC,UAAI,QAAQ,OAAO,SAAS;AAC1B;AAAA,MACF;AAGA,UAAI,CAAC,aAAa,gBAAgB,WAAW;AAC3C,gBAAQ,OAAO;AAAA,UAAoB,QAAQ;AAAA,UAAU,CAAC,SACpD,QAAQ,SAAS,SAAY,eAAe,MAAM,KAAK;AAAA,QACzD;AAAA,MACF;AACA,eAAS,QAAQ,QAAQ,KAAK;AAAA,IAChC;AAGA,QAAI,aAAa,gBAAgB,aAAa,CAAC,QAAQ,OAAO,SAAS;AACrE,cAAQ,OAAO,aAAoB,QAAQ,UAAU,MAAM;AAAA,IAC7D;AAEA,WAAO,QAAQ,OAAO,aAAa,QAAQ,QAAQ;AAAA,EACrD;AACF;","names":[]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
|
+
|
|
27
|
+
// src/timeoutManager.ts
|
|
28
|
+
var timeoutManager_exports = {};
|
|
29
|
+
__export(timeoutManager_exports, {
|
|
30
|
+
TimeoutManager: () => TimeoutManager,
|
|
31
|
+
defaultTimeoutProvider: () => defaultTimeoutProvider,
|
|
32
|
+
systemSetTimeoutZero: () => systemSetTimeoutZero,
|
|
33
|
+
timeoutManager: () => timeoutManager
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(timeoutManager_exports);
|
|
36
|
+
var defaultTimeoutProvider = {
|
|
37
|
+
// We need the wrapper function syntax below instead of direct references to
|
|
38
|
+
// global setTimeout etc.
|
|
39
|
+
//
|
|
40
|
+
// BAD: `setTimeout: setTimeout`
|
|
41
|
+
// GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`
|
|
42
|
+
//
|
|
43
|
+
// If we use direct references here, then anything that wants to spy on or
|
|
44
|
+
// replace the global setTimeout (like tests) won't work since we'll already
|
|
45
|
+
// have a hard reference to the original implementation at the time when this
|
|
46
|
+
// file was imported.
|
|
47
|
+
setTimeout: (callback, delay) => setTimeout(callback, delay),
|
|
48
|
+
clearTimeout: (timeoutId) => clearTimeout(timeoutId),
|
|
49
|
+
setInterval: (callback, delay) => setInterval(callback, delay),
|
|
50
|
+
clearInterval: (intervalId) => clearInterval(intervalId)
|
|
51
|
+
};
|
|
52
|
+
var _provider, _providerCalled;
|
|
53
|
+
var TimeoutManager = class {
|
|
54
|
+
constructor() {
|
|
55
|
+
// We cannot have TimeoutManager<T> as we must instantiate it with a concrete
|
|
56
|
+
// type at app boot; and if we leave that type, then any new timer provider
|
|
57
|
+
// would need to support ReturnType<typeof setTimeout>, which is infeasible.
|
|
58
|
+
//
|
|
59
|
+
// We settle for type safety for the TimeoutProvider type, and accept that
|
|
60
|
+
// this class is unsafe internally to allow for extension.
|
|
61
|
+
__privateAdd(this, _provider, defaultTimeoutProvider);
|
|
62
|
+
__privateAdd(this, _providerCalled, false);
|
|
63
|
+
}
|
|
64
|
+
setTimeoutProvider(provider) {
|
|
65
|
+
if (process.env.NODE_ENV !== "production") {
|
|
66
|
+
if (__privateGet(this, _providerCalled) && provider !== __privateGet(this, _provider)) {
|
|
67
|
+
console.error(
|
|
68
|
+
`[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,
|
|
69
|
+
{ previous: __privateGet(this, _provider), provider }
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
__privateSet(this, _provider, provider);
|
|
74
|
+
if (process.env.NODE_ENV !== "production") {
|
|
75
|
+
__privateSet(this, _providerCalled, false);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
setTimeout(callback, delay) {
|
|
79
|
+
if (process.env.NODE_ENV !== "production") {
|
|
80
|
+
__privateSet(this, _providerCalled, true);
|
|
81
|
+
}
|
|
82
|
+
return __privateGet(this, _provider).setTimeout(callback, delay);
|
|
83
|
+
}
|
|
84
|
+
clearTimeout(timeoutId) {
|
|
85
|
+
__privateGet(this, _provider).clearTimeout(timeoutId);
|
|
86
|
+
}
|
|
87
|
+
setInterval(callback, delay) {
|
|
88
|
+
if (process.env.NODE_ENV !== "production") {
|
|
89
|
+
__privateSet(this, _providerCalled, true);
|
|
90
|
+
}
|
|
91
|
+
return __privateGet(this, _provider).setInterval(callback, delay);
|
|
92
|
+
}
|
|
93
|
+
clearInterval(intervalId) {
|
|
94
|
+
__privateGet(this, _provider).clearInterval(intervalId);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
_provider = new WeakMap();
|
|
98
|
+
_providerCalled = new WeakMap();
|
|
99
|
+
var timeoutManager = new TimeoutManager();
|
|
100
|
+
function systemSetTimeoutZero(callback) {
|
|
101
|
+
setTimeout(callback, 0);
|
|
102
|
+
}
|
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
0 && (module.exports = {
|
|
105
|
+
TimeoutManager,
|
|
106
|
+
defaultTimeoutProvider,
|
|
107
|
+
systemSetTimeoutZero,
|
|
108
|
+
timeoutManager
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=timeoutManager.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/timeoutManager.ts"],"sourcesContent":["/**\n * {@link TimeoutManager} does not support passing arguments to the callback.\n *\n * `(_: void)` is the argument type inferred by TypeScript's default typings for\n * `setTimeout(cb, number)`.\n * If we don't accept a single void argument, then\n * `new Promise(resolve => timeoutManager.setTimeout(resolve, N))` is a type error.\n */\nexport type TimeoutCallback = (_: void) => void\n\n/**\n * Wrapping `setTimeout` is awkward from a typing perspective because platform\n * typings may extend the return type of `setTimeout`. For example, NodeJS\n * typings add `NodeJS.Timeout`; but a non-default `timeoutManager` may not be\n * able to return such a type.\n */\nexport type ManagedTimerId = number | { [Symbol.toPrimitive]: () => number }\n\n/**\n * Backend for timer functions.\n */\nexport type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> =\n {\n readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearTimeout: (timeoutId: TTimerId | undefined) => void\n\n readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearInterval: (intervalId: TTimerId | undefined) => void\n }\n\nexport const defaultTimeoutProvider: TimeoutProvider<\n ReturnType<typeof setTimeout>\n> = {\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) => clearTimeout(timeoutId),\n\n setInterval: (callback, delay) => setInterval(callback, delay),\n clearInterval: (intervalId) => clearInterval(intervalId),\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 ReturnType<typeof setTimeout>, which is infeasible.\n //\n // We settle for type safety for the TimeoutProvider type, and accept that\n // this class is unsafe internally to allow for extension.\n #provider: TimeoutProvider<any> = defaultTimeoutProvider\n #providerCalled = false\n\n setTimeoutProvider<TTimerId extends ManagedTimerId>(\n provider: TimeoutProvider<TTimerId>,\n ): void {\n if (process.env.NODE_ENV !== 'production') {\n if (this.#providerCalled && provider !== this.#provider) {\n // After changing providers, `clearTimeout` will not work as expected for\n // timeouts from the previous provider.\n //\n // Since they may allocate the same timeout ID, clearTimeout may cancel an\n // arbitrary different timeout, or unexpected no-op.\n //\n // We could protect against this by mixing the timeout ID bits\n // deterministically with some per-provider bits.\n //\n // We could internally queue `setTimeout` calls to `TimeoutManager` until\n // some API call to set the initial provider.\n console.error(\n `[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,\n { previous: this.#provider, provider },\n )\n }\n }\n\n this.#provider = provider\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = false\n }\n }\n\n setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setTimeout(callback, delay)\n }\n\n clearTimeout(timeoutId: ManagedTimerId | undefined): void {\n this.#provider.clearTimeout(timeoutId)\n }\n\n setInterval(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setInterval(callback, delay)\n }\n\n clearInterval(intervalId: ManagedTimerId | undefined): void {\n this.#provider.clearInterval(intervalId)\n }\n}\n\nexport const timeoutManager = new TimeoutManager()\n\n/**\n * In many cases code wants to delay to the next event loop tick; this is not\n * mediated by {@link timeoutManager}.\n *\n * This function is provided to make auditing the `tanstack/query-core` for\n * incorrect use of system `setTimeout` easier.\n */\nexport function systemSetTimeoutZero(callback: TimeoutCallback): void {\n setTimeout(callback, 0)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BO,IAAM,yBAET;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWF,YAAY,CAAC,UAAU,UAAU,WAAW,UAAU,KAAK;AAAA,EAC3D,cAAc,CAAC,cAAc,aAAa,SAAS;AAAA,EAEnD,aAAa,CAAC,UAAU,UAAU,YAAY,UAAU,KAAK;AAAA,EAC7D,eAAe,CAAC,eAAe,cAAc,UAAU;AACzD;AAhDA;AA6DO,IAAM,iBAAN,MAA8D;AAAA,EAA9D;AAOL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAAkC;AAClC,wCAAkB;AAAA;AAAA,EAElB,mBACE,UACM;AACN,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,UAAI,mBAAK,oBAAmB,aAAa,mBAAK,YAAW;AAYvD,gBAAQ;AAAA,UACN;AAAA,UACA,EAAE,UAAU,mBAAK,YAAW,SAAS;AAAA,QACvC;AAAA,MACF;AAAA,IACF;AAEA,uBAAK,WAAY;AACjB,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,yBAAK,iBAAkB;AAAA,IACzB;AAAA,EACF;AAAA,EAEA,WAAW,UAA2B,OAA+B;AACnE,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,yBAAK,iBAAkB;AAAA,IACzB;AACA,WAAO,mBAAK,WAAU,WAAW,UAAU,KAAK;AAAA,EAClD;AAAA,EAEA,aAAa,WAA6C;AACxD,uBAAK,WAAU,aAAa,SAAS;AAAA,EACvC;AAAA,EAEA,YAAY,UAA2B,OAA+B;AACpE,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,yBAAK,iBAAkB;AAAA,IACzB;AACA,WAAO,mBAAK,WAAU,YAAY,UAAU,KAAK;AAAA,EACnD;AAAA,EAEA,cAAc,YAA8C;AAC1D,uBAAK,WAAU,cAAc,UAAU;AAAA,EACzC;AACF;AArDE;AACA;AAsDK,IAAM,iBAAiB,IAAI,eAAe;AAS1C,SAAS,qBAAqB,UAAiC;AACpE,aAAW,UAAU,CAAC;AACxB;","names":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* {@link TimeoutManager} does not support passing arguments to the callback.
|
|
3
|
+
*
|
|
4
|
+
* `(_: void)` is the argument type inferred by TypeScript's default typings for
|
|
5
|
+
* `setTimeout(cb, number)`.
|
|
6
|
+
* If we don't accept a single void argument, then
|
|
7
|
+
* `new Promise(resolve => timeoutManager.setTimeout(resolve, N))` is a type error.
|
|
8
|
+
*/
|
|
9
|
+
type TimeoutCallback = (_: void) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Wrapping `setTimeout` is awkward from a typing perspective because platform
|
|
12
|
+
* typings may extend the return type of `setTimeout`. For example, NodeJS
|
|
13
|
+
* typings add `NodeJS.Timeout`; but a non-default `timeoutManager` may not be
|
|
14
|
+
* able to return such a type.
|
|
15
|
+
*/
|
|
16
|
+
type ManagedTimerId = number | {
|
|
17
|
+
[Symbol.toPrimitive]: () => number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Backend for timer functions.
|
|
21
|
+
*/
|
|
22
|
+
type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> = {
|
|
23
|
+
readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId;
|
|
24
|
+
readonly clearTimeout: (timeoutId: TTimerId | undefined) => void;
|
|
25
|
+
readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId;
|
|
26
|
+
readonly clearInterval: (intervalId: TTimerId | undefined) => void;
|
|
27
|
+
};
|
|
28
|
+
declare const defaultTimeoutProvider: TimeoutProvider<ReturnType<typeof setTimeout>>;
|
|
29
|
+
/**
|
|
30
|
+
* Allows customization of how timeouts are created.
|
|
31
|
+
*
|
|
32
|
+
* @tanstack/query-core makes liberal use of timeouts to implement `staleTime`
|
|
33
|
+
* and `gcTime`. The default TimeoutManager provider uses the platform's global
|
|
34
|
+
* `setTimeout` implementation, which is known to have scalability issues with
|
|
35
|
+
* thousands of timeouts on the event loop.
|
|
36
|
+
*
|
|
37
|
+
* If you hit this limitation, consider providing a custom TimeoutProvider that
|
|
38
|
+
* coalesces timeouts.
|
|
39
|
+
*/
|
|
40
|
+
declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
|
|
41
|
+
#private;
|
|
42
|
+
setTimeoutProvider<TTimerId extends ManagedTimerId>(provider: TimeoutProvider<TTimerId>): void;
|
|
43
|
+
setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId;
|
|
44
|
+
clearTimeout(timeoutId: ManagedTimerId | undefined): void;
|
|
45
|
+
setInterval(callback: TimeoutCallback, delay: number): ManagedTimerId;
|
|
46
|
+
clearInterval(intervalId: ManagedTimerId | undefined): void;
|
|
47
|
+
}
|
|
48
|
+
declare const timeoutManager: TimeoutManager;
|
|
49
|
+
/**
|
|
50
|
+
* In many cases code wants to delay to the next event loop tick; this is not
|
|
51
|
+
* mediated by {@link timeoutManager}.
|
|
52
|
+
*
|
|
53
|
+
* This function is provided to make auditing the `tanstack/query-core` for
|
|
54
|
+
* incorrect use of system `setTimeout` easier.
|
|
55
|
+
*/
|
|
56
|
+
declare function systemSetTimeoutZero(callback: TimeoutCallback): void;
|
|
57
|
+
|
|
58
|
+
export { type ManagedTimerId, type TimeoutCallback, TimeoutManager, type TimeoutProvider, defaultTimeoutProvider, systemSetTimeoutZero, timeoutManager };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* {@link TimeoutManager} does not support passing arguments to the callback.
|
|
3
|
+
*
|
|
4
|
+
* `(_: void)` is the argument type inferred by TypeScript's default typings for
|
|
5
|
+
* `setTimeout(cb, number)`.
|
|
6
|
+
* If we don't accept a single void argument, then
|
|
7
|
+
* `new Promise(resolve => timeoutManager.setTimeout(resolve, N))` is a type error.
|
|
8
|
+
*/
|
|
9
|
+
type TimeoutCallback = (_: void) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Wrapping `setTimeout` is awkward from a typing perspective because platform
|
|
12
|
+
* typings may extend the return type of `setTimeout`. For example, NodeJS
|
|
13
|
+
* typings add `NodeJS.Timeout`; but a non-default `timeoutManager` may not be
|
|
14
|
+
* able to return such a type.
|
|
15
|
+
*/
|
|
16
|
+
type ManagedTimerId = number | {
|
|
17
|
+
[Symbol.toPrimitive]: () => number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Backend for timer functions.
|
|
21
|
+
*/
|
|
22
|
+
type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> = {
|
|
23
|
+
readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId;
|
|
24
|
+
readonly clearTimeout: (timeoutId: TTimerId | undefined) => void;
|
|
25
|
+
readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId;
|
|
26
|
+
readonly clearInterval: (intervalId: TTimerId | undefined) => void;
|
|
27
|
+
};
|
|
28
|
+
declare const defaultTimeoutProvider: TimeoutProvider<ReturnType<typeof setTimeout>>;
|
|
29
|
+
/**
|
|
30
|
+
* Allows customization of how timeouts are created.
|
|
31
|
+
*
|
|
32
|
+
* @tanstack/query-core makes liberal use of timeouts to implement `staleTime`
|
|
33
|
+
* and `gcTime`. The default TimeoutManager provider uses the platform's global
|
|
34
|
+
* `setTimeout` implementation, which is known to have scalability issues with
|
|
35
|
+
* thousands of timeouts on the event loop.
|
|
36
|
+
*
|
|
37
|
+
* If you hit this limitation, consider providing a custom TimeoutProvider that
|
|
38
|
+
* coalesces timeouts.
|
|
39
|
+
*/
|
|
40
|
+
declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
|
|
41
|
+
#private;
|
|
42
|
+
setTimeoutProvider<TTimerId extends ManagedTimerId>(provider: TimeoutProvider<TTimerId>): void;
|
|
43
|
+
setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId;
|
|
44
|
+
clearTimeout(timeoutId: ManagedTimerId | undefined): void;
|
|
45
|
+
setInterval(callback: TimeoutCallback, delay: number): ManagedTimerId;
|
|
46
|
+
clearInterval(intervalId: ManagedTimerId | undefined): void;
|
|
47
|
+
}
|
|
48
|
+
declare const timeoutManager: TimeoutManager;
|
|
49
|
+
/**
|
|
50
|
+
* In many cases code wants to delay to the next event loop tick; this is not
|
|
51
|
+
* mediated by {@link timeoutManager}.
|
|
52
|
+
*
|
|
53
|
+
* This function is provided to make auditing the `tanstack/query-core` for
|
|
54
|
+
* incorrect use of system `setTimeout` easier.
|
|
55
|
+
*/
|
|
56
|
+
declare function systemSetTimeoutZero(callback: TimeoutCallback): void;
|
|
57
|
+
|
|
58
|
+
export { type ManagedTimerId, type TimeoutCallback, TimeoutManager, type TimeoutProvider, defaultTimeoutProvider, systemSetTimeoutZero, timeoutManager };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__privateAdd,
|
|
3
|
+
__privateGet,
|
|
4
|
+
__privateSet
|
|
5
|
+
} from "./chunk-PXG64RU4.js";
|
|
6
|
+
|
|
7
|
+
// src/timeoutManager.ts
|
|
8
|
+
var defaultTimeoutProvider = {
|
|
9
|
+
// We need the wrapper function syntax below instead of direct references to
|
|
10
|
+
// global setTimeout etc.
|
|
11
|
+
//
|
|
12
|
+
// BAD: `setTimeout: setTimeout`
|
|
13
|
+
// GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`
|
|
14
|
+
//
|
|
15
|
+
// If we use direct references here, then anything that wants to spy on or
|
|
16
|
+
// replace the global setTimeout (like tests) won't work since we'll already
|
|
17
|
+
// have a hard reference to the original implementation at the time when this
|
|
18
|
+
// file was imported.
|
|
19
|
+
setTimeout: (callback, delay) => setTimeout(callback, delay),
|
|
20
|
+
clearTimeout: (timeoutId) => clearTimeout(timeoutId),
|
|
21
|
+
setInterval: (callback, delay) => setInterval(callback, delay),
|
|
22
|
+
clearInterval: (intervalId) => clearInterval(intervalId)
|
|
23
|
+
};
|
|
24
|
+
var _provider, _providerCalled;
|
|
25
|
+
var TimeoutManager = class {
|
|
26
|
+
constructor() {
|
|
27
|
+
// We cannot have TimeoutManager<T> as we must instantiate it with a concrete
|
|
28
|
+
// type at app boot; and if we leave that type, then any new timer provider
|
|
29
|
+
// would need to support ReturnType<typeof setTimeout>, which is infeasible.
|
|
30
|
+
//
|
|
31
|
+
// We settle for type safety for the TimeoutProvider type, and accept that
|
|
32
|
+
// this class is unsafe internally to allow for extension.
|
|
33
|
+
__privateAdd(this, _provider, defaultTimeoutProvider);
|
|
34
|
+
__privateAdd(this, _providerCalled, false);
|
|
35
|
+
}
|
|
36
|
+
setTimeoutProvider(provider) {
|
|
37
|
+
if (process.env.NODE_ENV !== "production") {
|
|
38
|
+
if (__privateGet(this, _providerCalled) && provider !== __privateGet(this, _provider)) {
|
|
39
|
+
console.error(
|
|
40
|
+
`[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,
|
|
41
|
+
{ previous: __privateGet(this, _provider), provider }
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
__privateSet(this, _provider, provider);
|
|
46
|
+
if (process.env.NODE_ENV !== "production") {
|
|
47
|
+
__privateSet(this, _providerCalled, false);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
setTimeout(callback, delay) {
|
|
51
|
+
if (process.env.NODE_ENV !== "production") {
|
|
52
|
+
__privateSet(this, _providerCalled, true);
|
|
53
|
+
}
|
|
54
|
+
return __privateGet(this, _provider).setTimeout(callback, delay);
|
|
55
|
+
}
|
|
56
|
+
clearTimeout(timeoutId) {
|
|
57
|
+
__privateGet(this, _provider).clearTimeout(timeoutId);
|
|
58
|
+
}
|
|
59
|
+
setInterval(callback, delay) {
|
|
60
|
+
if (process.env.NODE_ENV !== "production") {
|
|
61
|
+
__privateSet(this, _providerCalled, true);
|
|
62
|
+
}
|
|
63
|
+
return __privateGet(this, _provider).setInterval(callback, delay);
|
|
64
|
+
}
|
|
65
|
+
clearInterval(intervalId) {
|
|
66
|
+
__privateGet(this, _provider).clearInterval(intervalId);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
_provider = new WeakMap();
|
|
70
|
+
_providerCalled = new WeakMap();
|
|
71
|
+
var timeoutManager = new TimeoutManager();
|
|
72
|
+
function systemSetTimeoutZero(callback) {
|
|
73
|
+
setTimeout(callback, 0);
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
TimeoutManager,
|
|
77
|
+
defaultTimeoutProvider,
|
|
78
|
+
systemSetTimeoutZero,
|
|
79
|
+
timeoutManager
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=timeoutManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/timeoutManager.ts"],"sourcesContent":["/**\n * {@link TimeoutManager} does not support passing arguments to the callback.\n *\n * `(_: void)` is the argument type inferred by TypeScript's default typings for\n * `setTimeout(cb, number)`.\n * If we don't accept a single void argument, then\n * `new Promise(resolve => timeoutManager.setTimeout(resolve, N))` is a type error.\n */\nexport type TimeoutCallback = (_: void) => void\n\n/**\n * Wrapping `setTimeout` is awkward from a typing perspective because platform\n * typings may extend the return type of `setTimeout`. For example, NodeJS\n * typings add `NodeJS.Timeout`; but a non-default `timeoutManager` may not be\n * able to return such a type.\n */\nexport type ManagedTimerId = number | { [Symbol.toPrimitive]: () => number }\n\n/**\n * Backend for timer functions.\n */\nexport type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> =\n {\n readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearTimeout: (timeoutId: TTimerId | undefined) => void\n\n readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearInterval: (intervalId: TTimerId | undefined) => void\n }\n\nexport const defaultTimeoutProvider: TimeoutProvider<\n ReturnType<typeof setTimeout>\n> = {\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) => clearTimeout(timeoutId),\n\n setInterval: (callback, delay) => setInterval(callback, delay),\n clearInterval: (intervalId) => clearInterval(intervalId),\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 ReturnType<typeof setTimeout>, which is infeasible.\n //\n // We settle for type safety for the TimeoutProvider type, and accept that\n // this class is unsafe internally to allow for extension.\n #provider: TimeoutProvider<any> = defaultTimeoutProvider\n #providerCalled = false\n\n setTimeoutProvider<TTimerId extends ManagedTimerId>(\n provider: TimeoutProvider<TTimerId>,\n ): void {\n if (process.env.NODE_ENV !== 'production') {\n if (this.#providerCalled && provider !== this.#provider) {\n // After changing providers, `clearTimeout` will not work as expected for\n // timeouts from the previous provider.\n //\n // Since they may allocate the same timeout ID, clearTimeout may cancel an\n // arbitrary different timeout, or unexpected no-op.\n //\n // We could protect against this by mixing the timeout ID bits\n // deterministically with some per-provider bits.\n //\n // We could internally queue `setTimeout` calls to `TimeoutManager` until\n // some API call to set the initial provider.\n console.error(\n `[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,\n { previous: this.#provider, provider },\n )\n }\n }\n\n this.#provider = provider\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = false\n }\n }\n\n setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setTimeout(callback, delay)\n }\n\n clearTimeout(timeoutId: ManagedTimerId | undefined): void {\n this.#provider.clearTimeout(timeoutId)\n }\n\n setInterval(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setInterval(callback, delay)\n }\n\n clearInterval(intervalId: ManagedTimerId | undefined): void {\n this.#provider.clearInterval(intervalId)\n }\n}\n\nexport const timeoutManager = new TimeoutManager()\n\n/**\n * In many cases code wants to delay to the next event loop tick; this is not\n * mediated by {@link timeoutManager}.\n *\n * This function is provided to make auditing the `tanstack/query-core` for\n * incorrect use of system `setTimeout` easier.\n */\nexport function systemSetTimeoutZero(callback: TimeoutCallback): void {\n setTimeout(callback, 0)\n}\n"],"mappings":";;;;;;;AA8BO,IAAM,yBAET;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWF,YAAY,CAAC,UAAU,UAAU,WAAW,UAAU,KAAK;AAAA,EAC3D,cAAc,CAAC,cAAc,aAAa,SAAS;AAAA,EAEnD,aAAa,CAAC,UAAU,UAAU,YAAY,UAAU,KAAK;AAAA,EAC7D,eAAe,CAAC,eAAe,cAAc,UAAU;AACzD;AAhDA;AA6DO,IAAM,iBAAN,MAA8D;AAAA,EAA9D;AAOL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAAkC;AAClC,wCAAkB;AAAA;AAAA,EAElB,mBACE,UACM;AACN,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,UAAI,mBAAK,oBAAmB,aAAa,mBAAK,YAAW;AAYvD,gBAAQ;AAAA,UACN;AAAA,UACA,EAAE,UAAU,mBAAK,YAAW,SAAS;AAAA,QACvC;AAAA,MACF;AAAA,IACF;AAEA,uBAAK,WAAY;AACjB,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,yBAAK,iBAAkB;AAAA,IACzB;AAAA,EACF;AAAA,EAEA,WAAW,UAA2B,OAA+B;AACnE,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,yBAAK,iBAAkB;AAAA,IACzB;AACA,WAAO,mBAAK,WAAU,WAAW,UAAU,KAAK;AAAA,EAClD;AAAA,EAEA,aAAa,WAA6C;AACxD,uBAAK,WAAU,aAAa,SAAS;AAAA,EACvC;AAAA,EAEA,YAAY,UAA2B,OAA+B;AACpE,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,yBAAK,iBAAkB;AAAA,IACzB;AACA,WAAO,mBAAK,WAAU,YAAY,UAAU,KAAK;AAAA,EACnD;AAAA,EAEA,cAAc,YAA8C;AAC1D,uBAAK,WAAU,cAAc,UAAU;AAAA,EACzC;AACF;AArDE;AACA;AAsDK,IAAM,iBAAiB,IAAI,eAAe;AAS1C,SAAS,qBAAqB,UAAiC;AACpE,aAAW,UAAU,CAAC;AACxB;","names":[]}
|
package/build/legacy/types.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { T as AnyDataTag, b6 as CancelOptions, V as DataTag, G as DefaultError, b5 as DefaultOptions, ak as DefaultedInfiniteQueryObserverOptions, ai as DefaultedQueryObserverOptions, aP as DefinedInfiniteQueryObserverResult, aG as DefinedQueryObserverResult, B as DistributiveOmit, $ as Enabled, an as EnsureInfiniteQueryDataOptions, am as EnsureQueryDataOptions, ao as FetchInfiniteQueryOptions, av as FetchNextPageOptions, aw as FetchPreviousPageOptions, al as FetchQueryOptions, ay as FetchStatus, a7 as GetNextPageParamFunction, a6 as GetPreviousPageParamFunction, W as InferDataFromTag, X as InferErrorFromTag, a8 as InfiniteData, aI as InfiniteQueryObserverBaseResult, aL as InfiniteQueryObserverLoadingErrorResult, aK as InfiniteQueryObserverLoadingResult, aj as InfiniteQueryObserverOptions, aJ as InfiniteQueryObserverPendingResult, aO as InfiniteQueryObserverPlaceholderResult, aM as InfiniteQueryObserverRefetchErrorResult, aQ as InfiniteQueryObserverResult, aN as InfiniteQueryObserverSuccessResult, ae as InfiniteQueryPageParamsOptions, a2 as InitialDataFunction, ad as InitialPageParam, at as InvalidateOptions, ar as InvalidateQueryFilters, aZ as MutateFunction, aY as MutateOptions, aV as MutationFunction, aR as MutationKey, aU as MutationMeta, a_ as MutationObserverBaseResult, b1 as MutationObserverErrorResult, a$ as MutationObserverIdleResult, b0 as MutationObserverLoadingResult, aX as MutationObserverOptions, b3 as MutationObserverResult, b2 as MutationObserverSuccessResult, aW as MutationOptions, aT as MutationScope, aS as MutationStatus, aa as NetworkMode, F as NoInfer, N as NonUndefinedGuard, b9 as NotifyEvent, b8 as NotifyEventType, ab as NotifyOnChangeProps, O as OmitKeyof, E as Override, a3 as PlaceholderDataFunction, a4 as QueriesPlaceholderDataFunction, b4 as QueryClientConfig, Y as QueryFunction, a1 as QueryFunctionContext, I as QueryKey, a5 as QueryKeyHashFunction, a9 as QueryMeta, az as QueryObserverBaseResult, aC as QueryObserverLoadingErrorResult, aB as QueryObserverLoadingResult, ag as QueryObserverOptions, aA as QueryObserverPendingResult, aF as QueryObserverPlaceholderResult, aD as QueryObserverRefetchErrorResult, aH as QueryObserverResult, aE as QueryObserverSuccessResult, ac as QueryOptions, a0 as QueryPersister, ax as QueryStatus, aq as RefetchOptions, as as RefetchQueryFilters, R as Register, au as ResetOptions, ap as ResultOptions, b7 as SetDataOptions, Z as StaleTime, _ as StaleTimeFunction, af as ThrowOnError, P as UnsetMarker, ah as WithRequired, K as dataTagErrorSymbol, J as dataTagSymbol, L as unsetMarker } from './hydration-
|
|
1
|
+
export { T as AnyDataTag, b6 as CancelOptions, V as DataTag, G as DefaultError, b5 as DefaultOptions, ak as DefaultedInfiniteQueryObserverOptions, ai as DefaultedQueryObserverOptions, aP as DefinedInfiniteQueryObserverResult, aG as DefinedQueryObserverResult, B as DistributiveOmit, $ as Enabled, an as EnsureInfiniteQueryDataOptions, am as EnsureQueryDataOptions, ao as FetchInfiniteQueryOptions, av as FetchNextPageOptions, aw as FetchPreviousPageOptions, al as FetchQueryOptions, ay as FetchStatus, a7 as GetNextPageParamFunction, a6 as GetPreviousPageParamFunction, W as InferDataFromTag, X as InferErrorFromTag, a8 as InfiniteData, aI as InfiniteQueryObserverBaseResult, aL as InfiniteQueryObserverLoadingErrorResult, aK as InfiniteQueryObserverLoadingResult, aj as InfiniteQueryObserverOptions, aJ as InfiniteQueryObserverPendingResult, aO as InfiniteQueryObserverPlaceholderResult, aM as InfiniteQueryObserverRefetchErrorResult, aQ as InfiniteQueryObserverResult, aN as InfiniteQueryObserverSuccessResult, ae as InfiniteQueryPageParamsOptions, a2 as InitialDataFunction, ad as InitialPageParam, at as InvalidateOptions, ar as InvalidateQueryFilters, aZ as MutateFunction, aY as MutateOptions, aV as MutationFunction, aR as MutationKey, aU as MutationMeta, a_ as MutationObserverBaseResult, b1 as MutationObserverErrorResult, a$ as MutationObserverIdleResult, b0 as MutationObserverLoadingResult, aX as MutationObserverOptions, b3 as MutationObserverResult, b2 as MutationObserverSuccessResult, aW as MutationOptions, aT as MutationScope, aS as MutationStatus, aa as NetworkMode, F as NoInfer, N as NonUndefinedGuard, b9 as NotifyEvent, b8 as NotifyEventType, ab as NotifyOnChangeProps, O as OmitKeyof, E as Override, a3 as PlaceholderDataFunction, a4 as QueriesPlaceholderDataFunction, b4 as QueryClientConfig, Y as QueryFunction, a1 as QueryFunctionContext, I as QueryKey, a5 as QueryKeyHashFunction, a9 as QueryMeta, az as QueryObserverBaseResult, aC as QueryObserverLoadingErrorResult, aB as QueryObserverLoadingResult, ag as QueryObserverOptions, aA as QueryObserverPendingResult, aF as QueryObserverPlaceholderResult, aD as QueryObserverRefetchErrorResult, aH as QueryObserverResult, aE as QueryObserverSuccessResult, ac as QueryOptions, a0 as QueryPersister, ax as QueryStatus, aq as RefetchOptions, as as RefetchQueryFilters, R as Register, au as ResetOptions, ap as ResultOptions, b7 as SetDataOptions, Z as StaleTime, _ as StaleTimeFunction, af as ThrowOnError, P as UnsetMarker, ah as WithRequired, K as dataTagErrorSymbol, J as dataTagSymbol, L as unsetMarker } from './hydration-_hO-y142.cjs';
|
|
2
2
|
import './removable.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
package/build/legacy/types.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { T as AnyDataTag, b6 as CancelOptions, V as DataTag, G as DefaultError, b5 as DefaultOptions, ak as DefaultedInfiniteQueryObserverOptions, ai as DefaultedQueryObserverOptions, aP as DefinedInfiniteQueryObserverResult, aG as DefinedQueryObserverResult, B as DistributiveOmit, $ as Enabled, an as EnsureInfiniteQueryDataOptions, am as EnsureQueryDataOptions, ao as FetchInfiniteQueryOptions, av as FetchNextPageOptions, aw as FetchPreviousPageOptions, al as FetchQueryOptions, ay as FetchStatus, a7 as GetNextPageParamFunction, a6 as GetPreviousPageParamFunction, W as InferDataFromTag, X as InferErrorFromTag, a8 as InfiniteData, aI as InfiniteQueryObserverBaseResult, aL as InfiniteQueryObserverLoadingErrorResult, aK as InfiniteQueryObserverLoadingResult, aj as InfiniteQueryObserverOptions, aJ as InfiniteQueryObserverPendingResult, aO as InfiniteQueryObserverPlaceholderResult, aM as InfiniteQueryObserverRefetchErrorResult, aQ as InfiniteQueryObserverResult, aN as InfiniteQueryObserverSuccessResult, ae as InfiniteQueryPageParamsOptions, a2 as InitialDataFunction, ad as InitialPageParam, at as InvalidateOptions, ar as InvalidateQueryFilters, aZ as MutateFunction, aY as MutateOptions, aV as MutationFunction, aR as MutationKey, aU as MutationMeta, a_ as MutationObserverBaseResult, b1 as MutationObserverErrorResult, a$ as MutationObserverIdleResult, b0 as MutationObserverLoadingResult, aX as MutationObserverOptions, b3 as MutationObserverResult, b2 as MutationObserverSuccessResult, aW as MutationOptions, aT as MutationScope, aS as MutationStatus, aa as NetworkMode, F as NoInfer, N as NonUndefinedGuard, b9 as NotifyEvent, b8 as NotifyEventType, ab as NotifyOnChangeProps, O as OmitKeyof, E as Override, a3 as PlaceholderDataFunction, a4 as QueriesPlaceholderDataFunction, b4 as QueryClientConfig, Y as QueryFunction, a1 as QueryFunctionContext, I as QueryKey, a5 as QueryKeyHashFunction, a9 as QueryMeta, az as QueryObserverBaseResult, aC as QueryObserverLoadingErrorResult, aB as QueryObserverLoadingResult, ag as QueryObserverOptions, aA as QueryObserverPendingResult, aF as QueryObserverPlaceholderResult, aD as QueryObserverRefetchErrorResult, aH as QueryObserverResult, aE as QueryObserverSuccessResult, ac as QueryOptions, a0 as QueryPersister, ax as QueryStatus, aq as RefetchOptions, as as RefetchQueryFilters, R as Register, au as ResetOptions, ap as ResultOptions, b7 as SetDataOptions, Z as StaleTime, _ as StaleTimeFunction, af as ThrowOnError, P as UnsetMarker, ah as WithRequired, K as dataTagErrorSymbol, J as dataTagSymbol, L as unsetMarker } from './hydration-
|
|
1
|
+
export { T as AnyDataTag, b6 as CancelOptions, V as DataTag, G as DefaultError, b5 as DefaultOptions, ak as DefaultedInfiniteQueryObserverOptions, ai as DefaultedQueryObserverOptions, aP as DefinedInfiniteQueryObserverResult, aG as DefinedQueryObserverResult, B as DistributiveOmit, $ as Enabled, an as EnsureInfiniteQueryDataOptions, am as EnsureQueryDataOptions, ao as FetchInfiniteQueryOptions, av as FetchNextPageOptions, aw as FetchPreviousPageOptions, al as FetchQueryOptions, ay as FetchStatus, a7 as GetNextPageParamFunction, a6 as GetPreviousPageParamFunction, W as InferDataFromTag, X as InferErrorFromTag, a8 as InfiniteData, aI as InfiniteQueryObserverBaseResult, aL as InfiniteQueryObserverLoadingErrorResult, aK as InfiniteQueryObserverLoadingResult, aj as InfiniteQueryObserverOptions, aJ as InfiniteQueryObserverPendingResult, aO as InfiniteQueryObserverPlaceholderResult, aM as InfiniteQueryObserverRefetchErrorResult, aQ as InfiniteQueryObserverResult, aN as InfiniteQueryObserverSuccessResult, ae as InfiniteQueryPageParamsOptions, a2 as InitialDataFunction, ad as InitialPageParam, at as InvalidateOptions, ar as InvalidateQueryFilters, aZ as MutateFunction, aY as MutateOptions, aV as MutationFunction, aR as MutationKey, aU as MutationMeta, a_ as MutationObserverBaseResult, b1 as MutationObserverErrorResult, a$ as MutationObserverIdleResult, b0 as MutationObserverLoadingResult, aX as MutationObserverOptions, b3 as MutationObserverResult, b2 as MutationObserverSuccessResult, aW as MutationOptions, aT as MutationScope, aS as MutationStatus, aa as NetworkMode, F as NoInfer, N as NonUndefinedGuard, b9 as NotifyEvent, b8 as NotifyEventType, ab as NotifyOnChangeProps, O as OmitKeyof, E as Override, a3 as PlaceholderDataFunction, a4 as QueriesPlaceholderDataFunction, b4 as QueryClientConfig, Y as QueryFunction, a1 as QueryFunctionContext, I as QueryKey, a5 as QueryKeyHashFunction, a9 as QueryMeta, az as QueryObserverBaseResult, aC as QueryObserverLoadingErrorResult, aB as QueryObserverLoadingResult, ag as QueryObserverOptions, aA as QueryObserverPendingResult, aF as QueryObserverPlaceholderResult, aD as QueryObserverRefetchErrorResult, aH as QueryObserverResult, aE as QueryObserverSuccessResult, ac as QueryOptions, a0 as QueryPersister, ax as QueryStatus, aq as RefetchOptions, as as RefetchQueryFilters, R as Register, au as ResetOptions, ap as ResultOptions, b7 as SetDataOptions, Z as StaleTime, _ as StaleTimeFunction, af as ThrowOnError, P as UnsetMarker, ah as WithRequired, K as dataTagErrorSymbol, J as dataTagSymbol, L as unsetMarker } from './hydration-BYonJkjc.js';
|
|
2
2
|
import './removable.js';
|
|
3
3
|
import './subscribable.js';
|
package/build/legacy/utils.cjs
CHANGED
|
@@ -46,6 +46,7 @@ __export(utils_exports, {
|
|
|
46
46
|
timeUntilStale: () => timeUntilStale
|
|
47
47
|
});
|
|
48
48
|
module.exports = __toCommonJS(utils_exports);
|
|
49
|
+
var import_timeoutManager = require("./timeoutManager.cjs");
|
|
49
50
|
var isServer = typeof window === "undefined" || "Deno" in globalThis;
|
|
50
51
|
function noop() {
|
|
51
52
|
}
|
|
@@ -149,34 +150,37 @@ function partialMatchKey(a, b) {
|
|
|
149
150
|
}
|
|
150
151
|
return false;
|
|
151
152
|
}
|
|
153
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
152
154
|
function replaceEqualDeep(a, b) {
|
|
153
155
|
if (a === b) {
|
|
154
156
|
return a;
|
|
155
157
|
}
|
|
156
158
|
const array = isPlainArray(a) && isPlainArray(b);
|
|
157
|
-
if (array
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
159
|
+
if (!array && !(isPlainObject(a) && isPlainObject(b))) return b;
|
|
160
|
+
const aItems = array ? a : Object.keys(a);
|
|
161
|
+
const aSize = aItems.length;
|
|
162
|
+
const bItems = array ? b : Object.keys(b);
|
|
163
|
+
const bSize = bItems.length;
|
|
164
|
+
const copy = array ? new Array(bSize) : {};
|
|
165
|
+
let equalItems = 0;
|
|
166
|
+
for (let i = 0; i < bSize; i++) {
|
|
167
|
+
const key = array ? i : bItems[i];
|
|
168
|
+
const aItem = a[key];
|
|
169
|
+
const bItem = b[key];
|
|
170
|
+
if (aItem === bItem) {
|
|
171
|
+
copy[key] = aItem;
|
|
172
|
+
if (array ? i < aSize : hasOwn.call(a, key)) equalItems++;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (aItem === null || bItem === null || typeof aItem !== "object" || typeof bItem !== "object") {
|
|
176
|
+
copy[key] = bItem;
|
|
177
|
+
continue;
|
|
176
178
|
}
|
|
177
|
-
|
|
179
|
+
const v = replaceEqualDeep(aItem, bItem);
|
|
180
|
+
copy[key] = v;
|
|
181
|
+
if (v === aItem) equalItems++;
|
|
178
182
|
}
|
|
179
|
-
return
|
|
183
|
+
return aSize === bSize && equalItems === aSize ? a : copy;
|
|
180
184
|
}
|
|
181
185
|
function shallowEqualObjects(a, b) {
|
|
182
186
|
if (!b || Object.keys(a).length !== Object.keys(b).length) {
|
|
@@ -217,7 +221,7 @@ function hasObjectPrototype(o) {
|
|
|
217
221
|
}
|
|
218
222
|
function sleep(timeout) {
|
|
219
223
|
return new Promise((resolve) => {
|
|
220
|
-
setTimeout(resolve, timeout);
|
|
224
|
+
import_timeoutManager.timeoutManager.setTimeout(resolve, timeout);
|
|
221
225
|
});
|
|
222
226
|
}
|
|
223
227
|
function replaceData(prevData, data, options) {
|