@tanstack/query-core 5.74.9 → 5.75.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-CwYEwyQI.d.cts → hydration-B6nZCPcW.d.cts} +2 -2
- package/build/legacy/{hydration-BlEK5ylC.d.ts → hydration-ZCurbX1S.d.ts} +2 -2
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/index.d.cts +1 -1
- package/build/legacy/index.d.ts +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/queriesObserver.d.cts +1 -1
- package/build/legacy/queriesObserver.d.ts +1 -1
- package/build/legacy/query.d.cts +1 -1
- package/build/legacy/query.d.ts +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.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/streamedQuery.cjs +23 -17
- package/build/legacy/streamedQuery.cjs.map +1 -1
- package/build/legacy/streamedQuery.d.cts +6 -3
- package/build/legacy/streamedQuery.d.ts +6 -3
- package/build/legacy/streamedQuery.js +23 -17
- package/build/legacy/streamedQuery.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.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/modern/{hydration-CwYEwyQI.d.cts → hydration-B6nZCPcW.d.cts} +2 -2
- package/build/modern/{hydration-BlEK5ylC.d.ts → hydration-ZCurbX1S.d.ts} +2 -2
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/index.d.cts +1 -1
- package/build/modern/index.d.ts +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/queriesObserver.d.cts +1 -1
- package/build/modern/queriesObserver.d.ts +1 -1
- package/build/modern/query.d.cts +1 -1
- package/build/modern/query.d.ts +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.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/streamedQuery.cjs +23 -17
- package/build/modern/streamedQuery.cjs.map +1 -1
- package/build/modern/streamedQuery.d.cts +6 -3
- package/build/modern/streamedQuery.d.ts +6 -3
- package/build/modern/streamedQuery.js +23 -17
- package/build/modern/streamedQuery.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.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/streamedQuery.ts +38 -21
- package/src/types.ts +5 -5
package/build/modern/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { J as AnyDataTag, b1 as CancelOptions, C as CancelledError, K as DataTag, A as DefaultError, b0 as DefaultOptions, af as DefaultedInfiniteQueryObserverOptions, ad as DefaultedQueryObserverOptions, aK as DefinedInfiniteQueryObserverResult, aB as DefinedQueryObserverResult, D as DehydrateOptions, x as DehydratedState, y as DistributiveOmit, W as Enabled, ai as EnsureInfiniteQueryDataOptions, ah as EnsureQueryDataOptions, aj as FetchInfiniteQueryOptions, aq as FetchNextPageOptions, ar as FetchPreviousPageOptions, ag as FetchQueryOptions, at as FetchStatus, a2 as GetNextPageParamFunction, a1 as GetPreviousPageParamFunction, H as HydrateOptions, L as InferDataFromTag, P as InferErrorFromTag, a3 as InfiniteData, aD as InfiniteQueryObserverBaseResult, aG as InfiniteQueryObserverLoadingErrorResult, aF as InfiniteQueryObserverLoadingResult, ae as InfiniteQueryObserverOptions, aE as InfiniteQueryObserverPendingResult, aJ as InfiniteQueryObserverPlaceholderResult, aH as InfiniteQueryObserverRefetchErrorResult, aL as InfiniteQueryObserverResult, aI as InfiniteQueryObserverSuccessResult, a9 as InfiniteQueryPageParamsOptions, Z as InitialDataFunction, a8 as InitialPageParam, ao as InvalidateOptions, am as InvalidateQueryFilters, aU as MutateFunction, aT as MutateOptions, w as Mutation, M as MutationCache, d as MutationCacheNotifyEvent, g as MutationFilters, aQ as MutationFunction, aM as MutationKey, aP as MutationMeta, e as MutationObserver, aV as MutationObserverBaseResult, aY as MutationObserverErrorResult, aW as MutationObserverIdleResult, aX as MutationObserverLoadingResult, aS as MutationObserverOptions, a_ as MutationObserverResult, aZ as MutationObserverSuccessResult, aR as MutationOptions, aO as MutationScope, v as MutationState, aN as MutationStatus, a5 as NetworkMode, N as NoInfer, b4 as NotifyEvent, b3 as NotifyEventType, a6 as NotifyOnChangeProps, O as OmitKeyof, z as Override, _ as PlaceholderDataFunction, $ as QueriesPlaceholderDataFunction, u as Query, Q as QueryCache, a as QueryCacheNotifyEvent, b as QueryClient, a$ as QueryClientConfig, j as QueryFilters, T as QueryFunction, Y as QueryFunctionContext, B as QueryKey, a0 as QueryKeyHashFunction, a4 as QueryMeta, c as QueryObserver, au as QueryObserverBaseResult, ax as QueryObserverLoadingErrorResult, aw as QueryObserverLoadingResult, ab as QueryObserverOptions, av as QueryObserverPendingResult, aA as QueryObserverPlaceholderResult, ay as QueryObserverRefetchErrorResult, aC as QueryObserverResult, az as QueryObserverSuccessResult, a7 as QueryOptions, X as QueryPersister, t as QueryState, as as QueryStatus, al as RefetchOptions, an as RefetchQueryFilters, R as Register, ap as ResetOptions, ak as ResultOptions, b2 as SetDataOptions, S as SkipToken, V as StaleTime, aa as ThrowOnError, I as UnsetMarker, U as Updater, ac as WithRequired, F as dataTagErrorSymbol, E as dataTagSymbol, q as defaultShouldDehydrateMutation, p as defaultShouldDehydrateQuery, n as dehydrate, h as hashKey, o as hydrate, l as isCancelledError, i as isServer, k as keepPreviousData, f as matchMutation, m as matchQuery, r as replaceEqualDeep, s as skipToken, G as unsetMarker } from './hydration-B6nZCPcW.cjs';
|
|
2
2
|
export { QueriesObserver, QueriesObserverOptions } from './queriesObserver.cjs';
|
|
3
3
|
export { InfiniteQueryObserver } from './infiniteQueryObserver.cjs';
|
|
4
4
|
export { defaultScheduler, notifyManager } from './notifyManager.cjs';
|
package/build/modern/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { J as AnyDataTag, b1 as CancelOptions, C as CancelledError, K as DataTag, A as DefaultError, b0 as DefaultOptions, af as DefaultedInfiniteQueryObserverOptions, ad as DefaultedQueryObserverOptions, aK as DefinedInfiniteQueryObserverResult, aB as DefinedQueryObserverResult, D as DehydrateOptions, x as DehydratedState, y as DistributiveOmit, W as Enabled, ai as EnsureInfiniteQueryDataOptions, ah as EnsureQueryDataOptions, aj as FetchInfiniteQueryOptions, aq as FetchNextPageOptions, ar as FetchPreviousPageOptions, ag as FetchQueryOptions, at as FetchStatus, a2 as GetNextPageParamFunction, a1 as GetPreviousPageParamFunction, H as HydrateOptions, L as InferDataFromTag, P as InferErrorFromTag, a3 as InfiniteData, aD as InfiniteQueryObserverBaseResult, aG as InfiniteQueryObserverLoadingErrorResult, aF as InfiniteQueryObserverLoadingResult, ae as InfiniteQueryObserverOptions, aE as InfiniteQueryObserverPendingResult, aJ as InfiniteQueryObserverPlaceholderResult, aH as InfiniteQueryObserverRefetchErrorResult, aL as InfiniteQueryObserverResult, aI as InfiniteQueryObserverSuccessResult, a9 as InfiniteQueryPageParamsOptions, Z as InitialDataFunction, a8 as InitialPageParam, ao as InvalidateOptions, am as InvalidateQueryFilters, aU as MutateFunction, aT as MutateOptions, w as Mutation, M as MutationCache, d as MutationCacheNotifyEvent, g as MutationFilters, aQ as MutationFunction, aM as MutationKey, aP as MutationMeta, e as MutationObserver, aV as MutationObserverBaseResult, aY as MutationObserverErrorResult, aW as MutationObserverIdleResult, aX as MutationObserverLoadingResult, aS as MutationObserverOptions, a_ as MutationObserverResult, aZ as MutationObserverSuccessResult, aR as MutationOptions, aO as MutationScope, v as MutationState, aN as MutationStatus, a5 as NetworkMode, N as NoInfer, b4 as NotifyEvent, b3 as NotifyEventType, a6 as NotifyOnChangeProps, O as OmitKeyof, z as Override, _ as PlaceholderDataFunction, $ as QueriesPlaceholderDataFunction, u as Query, Q as QueryCache, a as QueryCacheNotifyEvent, b as QueryClient, a$ as QueryClientConfig, j as QueryFilters, T as QueryFunction, Y as QueryFunctionContext, B as QueryKey, a0 as QueryKeyHashFunction, a4 as QueryMeta, c as QueryObserver, au as QueryObserverBaseResult, ax as QueryObserverLoadingErrorResult, aw as QueryObserverLoadingResult, ab as QueryObserverOptions, av as QueryObserverPendingResult, aA as QueryObserverPlaceholderResult, ay as QueryObserverRefetchErrorResult, aC as QueryObserverResult, az as QueryObserverSuccessResult, a7 as QueryOptions, X as QueryPersister, t as QueryState, as as QueryStatus, al as RefetchOptions, an as RefetchQueryFilters, R as Register, ap as ResetOptions, ak as ResultOptions, b2 as SetDataOptions, S as SkipToken, V as StaleTime, aa as ThrowOnError, I as UnsetMarker, U as Updater, ac as WithRequired, F as dataTagErrorSymbol, E as dataTagSymbol, q as defaultShouldDehydrateMutation, p as defaultShouldDehydrateQuery, n as dehydrate, h as hashKey, o as hydrate, l as isCancelledError, i as isServer, k as keepPreviousData, f as matchMutation, m as matchQuery, r as replaceEqualDeep, s as skipToken, G as unsetMarker } from './hydration-ZCurbX1S.js';
|
|
2
2
|
export { QueriesObserver, QueriesObserverOptions } from './queriesObserver.js';
|
|
3
3
|
export { InfiniteQueryObserver } from './infiniteQueryObserver.js';
|
|
4
4
|
export { defaultScheduler, notifyManager } from './notifyManager.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b5 as QueryBehavior,
|
|
1
|
+
import { b5 as QueryBehavior, a3 as InfiniteData, a9 as InfiniteQueryPageParamsOptions } from './hydration-B6nZCPcW.cjs';
|
|
2
2
|
import './removable.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b5 as QueryBehavior,
|
|
1
|
+
import { b5 as QueryBehavior, a3 as InfiniteData, a9 as InfiniteQueryPageParamsOptions } from './hydration-ZCurbX1S.js';
|
|
2
2
|
import './removable.js';
|
|
3
3
|
import './subscribable.js';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as DefaultError, a3 as InfiniteData, B as QueryKey, c as QueryObserver, aL as InfiniteQueryObserverResult, b as QueryClient, ae as InfiniteQueryObserverOptions, af as DefaultedInfiniteQueryObserverOptions, aq as FetchNextPageOptions, ar as FetchPreviousPageOptions, u as Query } from './hydration-B6nZCPcW.cjs';
|
|
2
2
|
import { Subscribable } from './subscribable.cjs';
|
|
3
3
|
import './removable.cjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as DefaultError, a3 as InfiniteData, B as QueryKey, c as QueryObserver, aL as InfiniteQueryObserverResult, b as QueryClient, ae as InfiniteQueryObserverOptions, af as DefaultedInfiniteQueryObserverOptions, aq as FetchNextPageOptions, ar as FetchPreviousPageOptions, u as Query } from './hydration-ZCurbX1S.js';
|
|
2
2
|
import { Subscribable } from './subscribable.js';
|
|
3
3
|
import './removable.js';
|
|
4
4
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import './removable.cjs';
|
|
2
|
-
export { bd as Action, w as Mutation, v as MutationState, be as getDefaultState } from './hydration-
|
|
2
|
+
export { bd as Action, w as Mutation, v as MutationState, be as getDefaultState } from './hydration-B6nZCPcW.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import './removable.js';
|
|
2
|
-
export { bd as Action, w as Mutation, v as MutationState, be as getDefaultState } from './hydration-
|
|
2
|
+
export { bd as Action, w as Mutation, v as MutationState, be as getDefaultState } from './hydration-ZCurbX1S.js';
|
|
3
3
|
import './subscribable.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { aC as QueryObserverResult, b as QueryClient,
|
|
1
|
+
import { aC as QueryObserverResult, b as QueryClient, ab as QueryObserverOptions, u as Query, c as QueryObserver } from './hydration-B6nZCPcW.cjs';
|
|
2
2
|
import { Subscribable } from './subscribable.cjs';
|
|
3
3
|
import './removable.cjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { aC as QueryObserverResult, b as QueryClient,
|
|
1
|
+
import { aC as QueryObserverResult, b as QueryClient, ab as QueryObserverOptions, u as Query, c as QueryObserver } from './hydration-ZCurbX1S.js';
|
|
2
2
|
import { Subscribable } from './subscribable.js';
|
|
3
3
|
import './removable.js';
|
|
4
4
|
|
package/build/modern/query.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import './removable.cjs';
|
|
2
|
-
export { ba as Action, b6 as FetchContext, b7 as FetchDirection, b8 as FetchMeta, b9 as FetchOptions, u as Query, b5 as QueryBehavior, t as QueryState, bb as SetStateOptions, bc as fetchState } from './hydration-
|
|
2
|
+
export { ba as Action, b6 as FetchContext, b7 as FetchDirection, b8 as FetchMeta, b9 as FetchOptions, u as Query, b5 as QueryBehavior, t as QueryState, bb as SetStateOptions, bc as fetchState } from './hydration-B6nZCPcW.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
package/build/modern/query.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import './removable.js';
|
|
2
|
-
export { ba as Action, b6 as FetchContext, b7 as FetchDirection, b8 as FetchMeta, b9 as FetchOptions, u as Query, b5 as QueryBehavior, t as QueryState, bb as SetStateOptions, bc as fetchState } from './hydration-
|
|
2
|
+
export { ba as Action, b6 as FetchContext, b7 as FetchDirection, b8 as FetchMeta, b9 as FetchOptions, u as Query, b5 as QueryBehavior, t as QueryState, bb as SetStateOptions, bc as fetchState } from './hydration-ZCurbX1S.js';
|
|
3
3
|
import './subscribable.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { C as CancelledError, bz as RetryDelayValue, by as RetryValue, bx as Retryer, bA as canFetch, bB as createRetryer, l as isCancelledError } from './hydration-
|
|
1
|
+
export { C as CancelledError, bz as RetryDelayValue, by as RetryValue, bx as Retryer, bA as canFetch, bB as createRetryer, l as isCancelledError } from './hydration-B6nZCPcW.cjs';
|
|
2
2
|
import './removable.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { C as CancelledError, bz as RetryDelayValue, by as RetryValue, bx as Retryer, bA as canFetch, bB as createRetryer, l as isCancelledError } from './hydration-
|
|
1
|
+
export { C as CancelledError, bz as RetryDelayValue, by as RetryValue, bx as Retryer, bA as canFetch, bB as createRetryer, l as isCancelledError } from './hydration-ZCurbX1S.js';
|
|
2
2
|
import './removable.js';
|
|
3
3
|
import './subscribable.js';
|
|
@@ -25,31 +25,37 @@ __export(streamedQuery_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(streamedQuery_exports);
|
|
26
26
|
function streamedQuery({
|
|
27
27
|
queryFn,
|
|
28
|
-
refetchMode
|
|
28
|
+
refetchMode = "reset"
|
|
29
29
|
}) {
|
|
30
30
|
return async (context) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
31
|
+
const query = context.client.getQueryCache().find({ queryKey: context.queryKey, exact: true });
|
|
32
|
+
const isRefetch = !!query && query.state.data !== void 0;
|
|
33
|
+
if (isRefetch && refetchMode === "reset") {
|
|
34
|
+
query.setState({
|
|
35
|
+
status: "pending",
|
|
36
|
+
data: void 0,
|
|
37
|
+
error: null,
|
|
38
|
+
fetchStatus: "fetching"
|
|
39
|
+
});
|
|
41
40
|
}
|
|
41
|
+
const result = [];
|
|
42
42
|
const stream = await queryFn(context);
|
|
43
43
|
for await (const chunk of stream) {
|
|
44
44
|
if (context.signal.aborted) {
|
|
45
45
|
break;
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
context.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
if (!isRefetch || refetchMode !== "replace") {
|
|
48
|
+
context.client.setQueryData(
|
|
49
|
+
context.queryKey,
|
|
50
|
+
(prev = []) => {
|
|
51
|
+
return prev.concat([chunk]);
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
result.push(chunk);
|
|
56
|
+
}
|
|
57
|
+
if (isRefetch && refetchMode === "replace" && !context.signal.aborted) {
|
|
58
|
+
context.client.setQueryData(context.queryKey, result);
|
|
53
59
|
}
|
|
54
60
|
return context.client.getQueryData(context.queryKey);
|
|
55
61
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import 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 - Defaults to 'reset'
|
|
1
|
+
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import 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 the data to the cache at the end of the stream.\n */\nexport function streamedQuery<\n TQueryFnData = unknown,\n TQueryKey extends QueryKey = QueryKey,\n>({\n queryFn,\n refetchMode = 'reset',\n}: {\n queryFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n refetchMode?: 'append' | 'reset' | 'replace'\n}): QueryFunction<Array<TQueryFnData>, TQueryKey> {\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\n if (isRefetch && refetchMode === 'reset') {\n query.setState({\n status: 'pending',\n data: undefined,\n error: null,\n fetchStatus: 'fetching',\n })\n }\n\n const result: Array<TQueryFnData> = []\n const stream = await queryFn(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<Array<TQueryFnData>>(\n context.queryKey,\n (prev = []) => {\n return prev.concat([chunk])\n },\n )\n }\n result.push(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<Array<TQueryFnData>>(context.queryKey, result)\n }\n\n return context.client.getQueryData(context.queryKey)!\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,SAAS,cAGd;AAAA,EACA;AAAA,EACA,cAAc;AAChB,GAKkD;AAChD,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;AAElD,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,UAAM,SAA8B,CAAC;AACrC,UAAM,SAAS,MAAM,QAAQ,OAAO;AAEpC,qBAAiB,SAAS,QAAQ;AAChC,UAAI,QAAQ,OAAO,SAAS;AAC1B;AAAA,MACF;AAGA,UAAI,CAAC,aAAa,gBAAgB,WAAW;AAC3C,gBAAQ,OAAO;AAAA,UACb,QAAQ;AAAA,UACR,CAAC,OAAO,CAAC,MAAM;AACb,mBAAO,KAAK,OAAO,CAAC,KAAK,CAAC;AAAA,UAC5B;AAAA,QACF;AAAA,MACF;AACA,aAAO,KAAK,KAAK;AAAA,IACnB;AAGA,QAAI,aAAa,gBAAgB,aAAa,CAAC,QAAQ,OAAO,SAAS;AACrE,cAAQ,OAAO,aAAkC,QAAQ,UAAU,MAAM;AAAA,IAC3E;AAEA,WAAO,QAAQ,OAAO,aAAa,QAAQ,QAAQ;AAAA,EACrD;AACF;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as QueryKey, Y as QueryFunctionContext, T as QueryFunction } from './hydration-B6nZCPcW.cjs';
|
|
2
2
|
import './removable.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
|
4
4
|
|
|
@@ -8,11 +8,14 @@ import './subscribable.cjs';
|
|
|
8
8
|
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
9
9
|
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
10
10
|
* @param queryFn - The function that returns an AsyncIterable to stream data from.
|
|
11
|
-
* @param refetchMode -
|
|
11
|
+
* @param refetchMode - Defines how re-fetches are handled.
|
|
12
|
+
* Defaults to `'reset'`, erases all data and puts the query back into `pending` state.
|
|
13
|
+
* Set to `'append'` to append new data to the existing data.
|
|
14
|
+
* Set to `'replace'` to write the data to the cache at the end of the stream.
|
|
12
15
|
*/
|
|
13
16
|
declare function streamedQuery<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>({ queryFn, refetchMode, }: {
|
|
14
17
|
queryFn: (context: QueryFunctionContext<TQueryKey>) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>;
|
|
15
|
-
refetchMode?: 'append' | 'reset';
|
|
18
|
+
refetchMode?: 'append' | 'reset' | 'replace';
|
|
16
19
|
}): QueryFunction<Array<TQueryFnData>, TQueryKey>;
|
|
17
20
|
|
|
18
21
|
export { streamedQuery };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as QueryKey, Y as QueryFunctionContext, T as QueryFunction } from './hydration-ZCurbX1S.js';
|
|
2
2
|
import './removable.js';
|
|
3
3
|
import './subscribable.js';
|
|
4
4
|
|
|
@@ -8,11 +8,14 @@ import './subscribable.js';
|
|
|
8
8
|
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
9
9
|
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
10
10
|
* @param queryFn - The function that returns an AsyncIterable to stream data from.
|
|
11
|
-
* @param refetchMode -
|
|
11
|
+
* @param refetchMode - Defines how re-fetches are handled.
|
|
12
|
+
* Defaults to `'reset'`, erases all data and puts the query back into `pending` state.
|
|
13
|
+
* Set to `'append'` to append new data to the existing data.
|
|
14
|
+
* Set to `'replace'` to write the data to the cache at the end of the stream.
|
|
12
15
|
*/
|
|
13
16
|
declare function streamedQuery<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>({ queryFn, refetchMode, }: {
|
|
14
17
|
queryFn: (context: QueryFunctionContext<TQueryKey>) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>;
|
|
15
|
-
refetchMode?: 'append' | 'reset';
|
|
18
|
+
refetchMode?: 'append' | 'reset' | 'replace';
|
|
16
19
|
}): QueryFunction<Array<TQueryFnData>, TQueryKey>;
|
|
17
20
|
|
|
18
21
|
export { streamedQuery };
|
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
// src/streamedQuery.ts
|
|
2
2
|
function streamedQuery({
|
|
3
3
|
queryFn,
|
|
4
|
-
refetchMode
|
|
4
|
+
refetchMode = "reset"
|
|
5
5
|
}) {
|
|
6
6
|
return async (context) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
7
|
+
const query = context.client.getQueryCache().find({ queryKey: context.queryKey, exact: true });
|
|
8
|
+
const isRefetch = !!query && query.state.data !== void 0;
|
|
9
|
+
if (isRefetch && refetchMode === "reset") {
|
|
10
|
+
query.setState({
|
|
11
|
+
status: "pending",
|
|
12
|
+
data: void 0,
|
|
13
|
+
error: null,
|
|
14
|
+
fetchStatus: "fetching"
|
|
15
|
+
});
|
|
17
16
|
}
|
|
17
|
+
const result = [];
|
|
18
18
|
const stream = await queryFn(context);
|
|
19
19
|
for await (const chunk of stream) {
|
|
20
20
|
if (context.signal.aborted) {
|
|
21
21
|
break;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
context.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
if (!isRefetch || refetchMode !== "replace") {
|
|
24
|
+
context.client.setQueryData(
|
|
25
|
+
context.queryKey,
|
|
26
|
+
(prev = []) => {
|
|
27
|
+
return prev.concat([chunk]);
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
result.push(chunk);
|
|
32
|
+
}
|
|
33
|
+
if (isRefetch && refetchMode === "replace" && !context.signal.aborted) {
|
|
34
|
+
context.client.setQueryData(context.queryKey, result);
|
|
29
35
|
}
|
|
30
36
|
return context.client.getQueryData(context.queryKey);
|
|
31
37
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import 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 - Defaults to 'reset'
|
|
1
|
+
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import 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 the data to the cache at the end of the stream.\n */\nexport function streamedQuery<\n TQueryFnData = unknown,\n TQueryKey extends QueryKey = QueryKey,\n>({\n queryFn,\n refetchMode = 'reset',\n}: {\n queryFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n refetchMode?: 'append' | 'reset' | 'replace'\n}): QueryFunction<Array<TQueryFnData>, TQueryKey> {\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\n if (isRefetch && refetchMode === 'reset') {\n query.setState({\n status: 'pending',\n data: undefined,\n error: null,\n fetchStatus: 'fetching',\n })\n }\n\n const result: Array<TQueryFnData> = []\n const stream = await queryFn(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<Array<TQueryFnData>>(\n context.queryKey,\n (prev = []) => {\n return prev.concat([chunk])\n },\n )\n }\n result.push(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<Array<TQueryFnData>>(context.queryKey, result)\n }\n\n return context.client.getQueryData(context.queryKey)!\n }\n}\n"],"mappings":";AAaO,SAAS,cAGd;AAAA,EACA;AAAA,EACA,cAAc;AAChB,GAKkD;AAChD,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;AAElD,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,UAAM,SAA8B,CAAC;AACrC,UAAM,SAAS,MAAM,QAAQ,OAAO;AAEpC,qBAAiB,SAAS,QAAQ;AAChC,UAAI,QAAQ,OAAO,SAAS;AAC1B;AAAA,MACF;AAGA,UAAI,CAAC,aAAa,gBAAgB,WAAW;AAC3C,gBAAQ,OAAO;AAAA,UACb,QAAQ;AAAA,UACR,CAAC,OAAO,CAAC,MAAM;AACb,mBAAO,KAAK,OAAO,CAAC,KAAK,CAAC;AAAA,UAC5B;AAAA,QACF;AAAA,MACF;AACA,aAAO,KAAK,KAAK;AAAA,IACnB;AAGA,QAAI,aAAa,gBAAgB,aAAa,CAAC,QAAQ,OAAO,SAAS;AACrE,cAAQ,OAAO,aAAkC,QAAQ,UAAU,MAAM;AAAA,IAC3E;AAEA,WAAO,QAAQ,OAAO,aAAa,QAAQ,QAAQ;AAAA,EACrD;AACF;","names":[]}
|