@tanstack/query-core 5.56.1 → 5.59.0
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-D6canbuP.d.cts → hydration-CVKA21uy.d.cts} +53 -0
- package/build/legacy/{hydration-DgUcX5FN.d.ts → hydration-DHZNyHqg.d.ts} +53 -0
- 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.cjs +1 -1
- package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
- package/build/legacy/infiniteQueryBehavior.js +1 -1
- package/build/legacy/infiniteQueryBehavior.js.map +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.cjs +44 -5
- 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 +45 -6
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/legacy/retryer.cjs +7 -11
- 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 +7 -11
- package/build/legacy/retryer.js.map +1 -1
- package/build/legacy/thenable.cjs +61 -0
- package/build/legacy/thenable.cjs.map +1 -0
- package/build/legacy/thenable.d.cts +36 -0
- package/build/legacy/thenable.d.ts +36 -0
- package/build/legacy/thenable.js +38 -0
- package/build/legacy/thenable.js.map +1 -0
- 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/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/modern/{hydration-D6canbuP.d.cts → hydration-CVKA21uy.d.cts} +53 -0
- package/build/modern/{hydration-DgUcX5FN.d.ts → hydration-DHZNyHqg.d.ts} +53 -0
- 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.cjs +1 -1
- package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +1 -1
- package/build/modern/infiniteQueryBehavior.js +1 -1
- package/build/modern/infiniteQueryBehavior.js.map +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.cjs +42 -4
- 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 +43 -5
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/retryer.cjs +7 -11
- 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 +7 -11
- package/build/modern/retryer.js.map +1 -1
- package/build/modern/thenable.cjs +61 -0
- package/build/modern/thenable.cjs.map +1 -0
- package/build/modern/thenable.d.cts +36 -0
- package/build/modern/thenable.d.ts +36 -0
- package/build/modern/thenable.js +36 -0
- package/build/modern/thenable.js.map +1 -0
- 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/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/__tests__/infiniteQueryBehavior.test.tsx +28 -0
- package/src/__tests__/queryObserver.test.tsx +101 -1
- package/src/infiniteQueryBehavior.ts +1 -1
- package/src/queryObserver.ts +63 -4
- package/src/retryer.ts +7 -11
- package/src/thenable.ts +82 -0
- package/src/types.ts +54 -0
|
@@ -703,6 +703,10 @@ interface QueryObserverOptions<TQueryFnData = unknown, TError = DefaultError, TD
|
|
|
703
703
|
*/
|
|
704
704
|
placeholderData?: NonFunctionGuard<TQueryData> | PlaceholderDataFunction<NonFunctionGuard<TQueryData>, TError, NonFunctionGuard<TQueryData>, TQueryKey>;
|
|
705
705
|
_optimisticResults?: 'optimistic' | 'isRestoring';
|
|
706
|
+
/**
|
|
707
|
+
* Enable prefetching during rendering
|
|
708
|
+
*/
|
|
709
|
+
experimental_prefetchInRender?: boolean;
|
|
706
710
|
}
|
|
707
711
|
type WithRequired<TTarget, TKey extends keyof TTarget> = TTarget & {
|
|
708
712
|
[_ in TKey]: {};
|
|
@@ -896,6 +900,55 @@ interface QueryObserverBaseResult<TData = unknown, TError = DefaultError> {
|
|
|
896
900
|
* - See [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information.
|
|
897
901
|
*/
|
|
898
902
|
fetchStatus: FetchStatus;
|
|
903
|
+
/**
|
|
904
|
+
* A stable promise that will be resolved with the data of the query.
|
|
905
|
+
* Requires the `experimental_prefetchInRender` feature flag to be enabled.
|
|
906
|
+
* @example
|
|
907
|
+
*
|
|
908
|
+
* ### Enabling the feature flag
|
|
909
|
+
* ```ts
|
|
910
|
+
* const client = new QueryClient({
|
|
911
|
+
* defaultOptions: {
|
|
912
|
+
* queries: {
|
|
913
|
+
* experimental_prefetchInRender: true,
|
|
914
|
+
* },
|
|
915
|
+
* },
|
|
916
|
+
* })
|
|
917
|
+
* ```
|
|
918
|
+
*
|
|
919
|
+
* ### Usage
|
|
920
|
+
* ```tsx
|
|
921
|
+
* import { useQuery } from '@tanstack/react-query'
|
|
922
|
+
* import React from 'react'
|
|
923
|
+
* import { fetchTodos, type Todo } from './api'
|
|
924
|
+
*
|
|
925
|
+
* function TodoList({ query }: { query: UseQueryResult<Todo[], Error> }) {
|
|
926
|
+
* const data = React.use(query.promise)
|
|
927
|
+
*
|
|
928
|
+
* return (
|
|
929
|
+
* <ul>
|
|
930
|
+
* {data.map(todo => (
|
|
931
|
+
* <li key={todo.id}>{todo.title}</li>
|
|
932
|
+
* ))}
|
|
933
|
+
* </ul>
|
|
934
|
+
* )
|
|
935
|
+
* }
|
|
936
|
+
*
|
|
937
|
+
* export function App() {
|
|
938
|
+
* const query = useQuery({ queryKey: ['todos'], queryFn: fetchTodos })
|
|
939
|
+
*
|
|
940
|
+
* return (
|
|
941
|
+
* <>
|
|
942
|
+
* <h1>Todos</h1>
|
|
943
|
+
* <React.Suspense fallback={<div>Loading...</div>}>
|
|
944
|
+
* <TodoList query={query} />
|
|
945
|
+
* </React.Suspense>
|
|
946
|
+
* </>
|
|
947
|
+
* )
|
|
948
|
+
* }
|
|
949
|
+
* ```
|
|
950
|
+
*/
|
|
951
|
+
promise: Promise<TData>;
|
|
899
952
|
}
|
|
900
953
|
interface QueryObserverPendingResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
|
|
901
954
|
data: undefined;
|
|
@@ -703,6 +703,10 @@ interface QueryObserverOptions<TQueryFnData = unknown, TError = DefaultError, TD
|
|
|
703
703
|
*/
|
|
704
704
|
placeholderData?: NonFunctionGuard<TQueryData> | PlaceholderDataFunction<NonFunctionGuard<TQueryData>, TError, NonFunctionGuard<TQueryData>, TQueryKey>;
|
|
705
705
|
_optimisticResults?: 'optimistic' | 'isRestoring';
|
|
706
|
+
/**
|
|
707
|
+
* Enable prefetching during rendering
|
|
708
|
+
*/
|
|
709
|
+
experimental_prefetchInRender?: boolean;
|
|
706
710
|
}
|
|
707
711
|
type WithRequired<TTarget, TKey extends keyof TTarget> = TTarget & {
|
|
708
712
|
[_ in TKey]: {};
|
|
@@ -896,6 +900,55 @@ interface QueryObserverBaseResult<TData = unknown, TError = DefaultError> {
|
|
|
896
900
|
* - See [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information.
|
|
897
901
|
*/
|
|
898
902
|
fetchStatus: FetchStatus;
|
|
903
|
+
/**
|
|
904
|
+
* A stable promise that will be resolved with the data of the query.
|
|
905
|
+
* Requires the `experimental_prefetchInRender` feature flag to be enabled.
|
|
906
|
+
* @example
|
|
907
|
+
*
|
|
908
|
+
* ### Enabling the feature flag
|
|
909
|
+
* ```ts
|
|
910
|
+
* const client = new QueryClient({
|
|
911
|
+
* defaultOptions: {
|
|
912
|
+
* queries: {
|
|
913
|
+
* experimental_prefetchInRender: true,
|
|
914
|
+
* },
|
|
915
|
+
* },
|
|
916
|
+
* })
|
|
917
|
+
* ```
|
|
918
|
+
*
|
|
919
|
+
* ### Usage
|
|
920
|
+
* ```tsx
|
|
921
|
+
* import { useQuery } from '@tanstack/react-query'
|
|
922
|
+
* import React from 'react'
|
|
923
|
+
* import { fetchTodos, type Todo } from './api'
|
|
924
|
+
*
|
|
925
|
+
* function TodoList({ query }: { query: UseQueryResult<Todo[], Error> }) {
|
|
926
|
+
* const data = React.use(query.promise)
|
|
927
|
+
*
|
|
928
|
+
* return (
|
|
929
|
+
* <ul>
|
|
930
|
+
* {data.map(todo => (
|
|
931
|
+
* <li key={todo.id}>{todo.title}</li>
|
|
932
|
+
* ))}
|
|
933
|
+
* </ul>
|
|
934
|
+
* )
|
|
935
|
+
* }
|
|
936
|
+
*
|
|
937
|
+
* export function App() {
|
|
938
|
+
* const query = useQuery({ queryKey: ['todos'], queryFn: fetchTodos })
|
|
939
|
+
*
|
|
940
|
+
* return (
|
|
941
|
+
* <>
|
|
942
|
+
* <h1>Todos</h1>
|
|
943
|
+
* <React.Suspense fallback={<div>Loading...</div>}>
|
|
944
|
+
* <TodoList query={query} />
|
|
945
|
+
* </React.Suspense>
|
|
946
|
+
* </>
|
|
947
|
+
* )
|
|
948
|
+
* }
|
|
949
|
+
* ```
|
|
950
|
+
*/
|
|
951
|
+
promise: Promise<TData>;
|
|
899
952
|
}
|
|
900
953
|
interface QueryObserverPendingResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
|
|
901
954
|
data: undefined;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { D as DehydrateOptions, x as DehydratedState, H as HydrateOptions, q as defaultShouldDehydrateMutation, p as defaultShouldDehydrateQuery, n as dehydrate, o as hydrate } from './hydration-
|
|
1
|
+
export { D as DehydrateOptions, x as DehydratedState, H as HydrateOptions, q as defaultShouldDehydrateMutation, p as defaultShouldDehydrateQuery, n as dehydrate, o as hydrate } from './hydration-CVKA21uy.cjs';
|
|
2
2
|
import './removable.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { D as DehydrateOptions, x as DehydratedState, H as HydrateOptions, q as defaultShouldDehydrateMutation, p as defaultShouldDehydrateQuery, n as dehydrate, o as hydrate } from './hydration-
|
|
1
|
+
export { D as DehydrateOptions, x as DehydratedState, H as HydrateOptions, q as defaultShouldDehydrateMutation, p as defaultShouldDehydrateQuery, n as dehydrate, o as hydrate } from './hydration-DHZNyHqg.js';
|
|
2
2
|
import './removable.js';
|
|
3
3
|
import './subscribable.js';
|
package/build/legacy/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { aV as CancelOptions, C as CancelledError, E as DataTag, z as DefaultError, aU as DefaultOptions, a9 as DefaultedInfiniteQueryObserverOptions, a7 as DefaultedQueryObserverOptions, aC as DefinedInfiniteQueryObserverResult, au as DefinedQueryObserverResult, D as DehydrateOptions, x as DehydratedState, I as Enabled, ac as EnsureInfiniteQueryDataOptions, ab as EnsureQueryDataOptions, ad as FetchInfiniteQueryOptions, ak as FetchNextPageOptions, al as FetchPreviousPageOptions, aa as FetchQueryOptions, an as FetchStatus, X as GetNextPageParamFunction, W as GetPreviousPageParamFunction, H as HydrateOptions, Y as InfiniteData, aw as InfiniteQueryObserverBaseResult, az as InfiniteQueryObserverLoadingErrorResult, ay as InfiniteQueryObserverLoadingResult, a8 as InfiniteQueryObserverOptions, ax as InfiniteQueryObserverPendingResult, aA as InfiniteQueryObserverRefetchErrorResult, aD as InfiniteQueryObserverResult, aB as InfiniteQueryObserverSuccessResult, a2 as InfiniteQueryPageParamsOptions, L as InitialDataFunction, a1 as InitialPageParam, ai as InvalidateOptions, ag as InvalidateQueryFilters, aM as MutateFunction, aL as MutateOptions, w as Mutation, M as MutationCache, d as MutationCacheNotifyEvent, g as MutationFilters, aI as MutationFunction, aE as MutationKey, aH as MutationMeta, e as MutationObserver, aN as MutationObserverBaseResult, aQ as MutationObserverErrorResult, aO as MutationObserverIdleResult, aP as MutationObserverLoadingResult, aK as MutationObserverOptions, aS as MutationObserverResult, aR as MutationObserverSuccessResult, aJ as MutationOptions, aG as MutationScope, v as MutationState, aF as MutationStatus, _ as NetworkMode, N as NoInfer, aY as NotifyEvent, aX as NotifyEventType, $ as NotifyOnChangeProps, O as OmitKeyof, a6 as Optional, y as Override, P as PlaceholderDataFunction, T as QueriesPlaceholderDataFunction, u as Query, Q as QueryCache, a as QueryCacheNotifyEvent, b as QueryClient, aT as QueryClientConfig, j as QueryFilters, F as QueryFunction, K as QueryFunctionContext, A as QueryKey, V as QueryKeyHashFunction, Z as QueryMeta, c as QueryObserver, ao as QueryObserverBaseResult, ar as QueryObserverLoadingErrorResult, aq as QueryObserverLoadingResult, a4 as QueryObserverOptions, ap as QueryObserverPendingResult, as as QueryObserverRefetchErrorResult, av as QueryObserverResult, at as QueryObserverSuccessResult, a0 as QueryOptions, J as QueryPersister, t as QueryState, am as QueryStatus, af as RefetchOptions, ah as RefetchQueryFilters, R as Register, aj as ResetOptions, ae as ResultOptions, aW as SetDataOptions, S as SkipToken, G as StaleTime, a3 as ThrowOnError, U as Updater, a5 as WithRequired, B 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 } from './hydration-
|
|
1
|
+
export { aV as CancelOptions, C as CancelledError, E as DataTag, z as DefaultError, aU as DefaultOptions, a9 as DefaultedInfiniteQueryObserverOptions, a7 as DefaultedQueryObserverOptions, aC as DefinedInfiniteQueryObserverResult, au as DefinedQueryObserverResult, D as DehydrateOptions, x as DehydratedState, I as Enabled, ac as EnsureInfiniteQueryDataOptions, ab as EnsureQueryDataOptions, ad as FetchInfiniteQueryOptions, ak as FetchNextPageOptions, al as FetchPreviousPageOptions, aa as FetchQueryOptions, an as FetchStatus, X as GetNextPageParamFunction, W as GetPreviousPageParamFunction, H as HydrateOptions, Y as InfiniteData, aw as InfiniteQueryObserverBaseResult, az as InfiniteQueryObserverLoadingErrorResult, ay as InfiniteQueryObserverLoadingResult, a8 as InfiniteQueryObserverOptions, ax as InfiniteQueryObserverPendingResult, aA as InfiniteQueryObserverRefetchErrorResult, aD as InfiniteQueryObserverResult, aB as InfiniteQueryObserverSuccessResult, a2 as InfiniteQueryPageParamsOptions, L as InitialDataFunction, a1 as InitialPageParam, ai as InvalidateOptions, ag as InvalidateQueryFilters, aM as MutateFunction, aL as MutateOptions, w as Mutation, M as MutationCache, d as MutationCacheNotifyEvent, g as MutationFilters, aI as MutationFunction, aE as MutationKey, aH as MutationMeta, e as MutationObserver, aN as MutationObserverBaseResult, aQ as MutationObserverErrorResult, aO as MutationObserverIdleResult, aP as MutationObserverLoadingResult, aK as MutationObserverOptions, aS as MutationObserverResult, aR as MutationObserverSuccessResult, aJ as MutationOptions, aG as MutationScope, v as MutationState, aF as MutationStatus, _ as NetworkMode, N as NoInfer, aY as NotifyEvent, aX as NotifyEventType, $ as NotifyOnChangeProps, O as OmitKeyof, a6 as Optional, y as Override, P as PlaceholderDataFunction, T as QueriesPlaceholderDataFunction, u as Query, Q as QueryCache, a as QueryCacheNotifyEvent, b as QueryClient, aT as QueryClientConfig, j as QueryFilters, F as QueryFunction, K as QueryFunctionContext, A as QueryKey, V as QueryKeyHashFunction, Z as QueryMeta, c as QueryObserver, ao as QueryObserverBaseResult, ar as QueryObserverLoadingErrorResult, aq as QueryObserverLoadingResult, a4 as QueryObserverOptions, ap as QueryObserverPendingResult, as as QueryObserverRefetchErrorResult, av as QueryObserverResult, at as QueryObserverSuccessResult, a0 as QueryOptions, J as QueryPersister, t as QueryState, am as QueryStatus, af as RefetchOptions, ah as RefetchQueryFilters, R as Register, aj as ResetOptions, ae as ResultOptions, aW as SetDataOptions, S as SkipToken, G as StaleTime, a3 as ThrowOnError, U as Updater, a5 as WithRequired, B 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 } from './hydration-CVKA21uy.cjs';
|
|
2
2
|
export { QueriesObserver, QueriesObserverOptions } from './queriesObserver.cjs';
|
|
3
3
|
export { InfiniteQueryObserver } from './infiniteQueryObserver.cjs';
|
|
4
4
|
export { notifyManager } from './notifyManager.cjs';
|
package/build/legacy/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { aV as CancelOptions, C as CancelledError, E as DataTag, z as DefaultError, aU as DefaultOptions, a9 as DefaultedInfiniteQueryObserverOptions, a7 as DefaultedQueryObserverOptions, aC as DefinedInfiniteQueryObserverResult, au as DefinedQueryObserverResult, D as DehydrateOptions, x as DehydratedState, I as Enabled, ac as EnsureInfiniteQueryDataOptions, ab as EnsureQueryDataOptions, ad as FetchInfiniteQueryOptions, ak as FetchNextPageOptions, al as FetchPreviousPageOptions, aa as FetchQueryOptions, an as FetchStatus, X as GetNextPageParamFunction, W as GetPreviousPageParamFunction, H as HydrateOptions, Y as InfiniteData, aw as InfiniteQueryObserverBaseResult, az as InfiniteQueryObserverLoadingErrorResult, ay as InfiniteQueryObserverLoadingResult, a8 as InfiniteQueryObserverOptions, ax as InfiniteQueryObserverPendingResult, aA as InfiniteQueryObserverRefetchErrorResult, aD as InfiniteQueryObserverResult, aB as InfiniteQueryObserverSuccessResult, a2 as InfiniteQueryPageParamsOptions, L as InitialDataFunction, a1 as InitialPageParam, ai as InvalidateOptions, ag as InvalidateQueryFilters, aM as MutateFunction, aL as MutateOptions, w as Mutation, M as MutationCache, d as MutationCacheNotifyEvent, g as MutationFilters, aI as MutationFunction, aE as MutationKey, aH as MutationMeta, e as MutationObserver, aN as MutationObserverBaseResult, aQ as MutationObserverErrorResult, aO as MutationObserverIdleResult, aP as MutationObserverLoadingResult, aK as MutationObserverOptions, aS as MutationObserverResult, aR as MutationObserverSuccessResult, aJ as MutationOptions, aG as MutationScope, v as MutationState, aF as MutationStatus, _ as NetworkMode, N as NoInfer, aY as NotifyEvent, aX as NotifyEventType, $ as NotifyOnChangeProps, O as OmitKeyof, a6 as Optional, y as Override, P as PlaceholderDataFunction, T as QueriesPlaceholderDataFunction, u as Query, Q as QueryCache, a as QueryCacheNotifyEvent, b as QueryClient, aT as QueryClientConfig, j as QueryFilters, F as QueryFunction, K as QueryFunctionContext, A as QueryKey, V as QueryKeyHashFunction, Z as QueryMeta, c as QueryObserver, ao as QueryObserverBaseResult, ar as QueryObserverLoadingErrorResult, aq as QueryObserverLoadingResult, a4 as QueryObserverOptions, ap as QueryObserverPendingResult, as as QueryObserverRefetchErrorResult, av as QueryObserverResult, at as QueryObserverSuccessResult, a0 as QueryOptions, J as QueryPersister, t as QueryState, am as QueryStatus, af as RefetchOptions, ah as RefetchQueryFilters, R as Register, aj as ResetOptions, ae as ResultOptions, aW as SetDataOptions, S as SkipToken, G as StaleTime, a3 as ThrowOnError, U as Updater, a5 as WithRequired, B 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 } from './hydration-
|
|
1
|
+
export { aV as CancelOptions, C as CancelledError, E as DataTag, z as DefaultError, aU as DefaultOptions, a9 as DefaultedInfiniteQueryObserverOptions, a7 as DefaultedQueryObserverOptions, aC as DefinedInfiniteQueryObserverResult, au as DefinedQueryObserverResult, D as DehydrateOptions, x as DehydratedState, I as Enabled, ac as EnsureInfiniteQueryDataOptions, ab as EnsureQueryDataOptions, ad as FetchInfiniteQueryOptions, ak as FetchNextPageOptions, al as FetchPreviousPageOptions, aa as FetchQueryOptions, an as FetchStatus, X as GetNextPageParamFunction, W as GetPreviousPageParamFunction, H as HydrateOptions, Y as InfiniteData, aw as InfiniteQueryObserverBaseResult, az as InfiniteQueryObserverLoadingErrorResult, ay as InfiniteQueryObserverLoadingResult, a8 as InfiniteQueryObserverOptions, ax as InfiniteQueryObserverPendingResult, aA as InfiniteQueryObserverRefetchErrorResult, aD as InfiniteQueryObserverResult, aB as InfiniteQueryObserverSuccessResult, a2 as InfiniteQueryPageParamsOptions, L as InitialDataFunction, a1 as InitialPageParam, ai as InvalidateOptions, ag as InvalidateQueryFilters, aM as MutateFunction, aL as MutateOptions, w as Mutation, M as MutationCache, d as MutationCacheNotifyEvent, g as MutationFilters, aI as MutationFunction, aE as MutationKey, aH as MutationMeta, e as MutationObserver, aN as MutationObserverBaseResult, aQ as MutationObserverErrorResult, aO as MutationObserverIdleResult, aP as MutationObserverLoadingResult, aK as MutationObserverOptions, aS as MutationObserverResult, aR as MutationObserverSuccessResult, aJ as MutationOptions, aG as MutationScope, v as MutationState, aF as MutationStatus, _ as NetworkMode, N as NoInfer, aY as NotifyEvent, aX as NotifyEventType, $ as NotifyOnChangeProps, O as OmitKeyof, a6 as Optional, y as Override, P as PlaceholderDataFunction, T as QueriesPlaceholderDataFunction, u as Query, Q as QueryCache, a as QueryCacheNotifyEvent, b as QueryClient, aT as QueryClientConfig, j as QueryFilters, F as QueryFunction, K as QueryFunctionContext, A as QueryKey, V as QueryKeyHashFunction, Z as QueryMeta, c as QueryObserver, ao as QueryObserverBaseResult, ar as QueryObserverLoadingErrorResult, aq as QueryObserverLoadingResult, a4 as QueryObserverOptions, ap as QueryObserverPendingResult, as as QueryObserverRefetchErrorResult, av as QueryObserverResult, at as QueryObserverSuccessResult, a0 as QueryOptions, J as QueryPersister, t as QueryState, am as QueryStatus, af as RefetchOptions, ah as RefetchQueryFilters, R as Register, aj as ResetOptions, ae as ResultOptions, aW as SetDataOptions, S as SkipToken, G as StaleTime, a3 as ThrowOnError, U as Updater, a5 as WithRequired, B 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 } from './hydration-DHZNyHqg.js';
|
|
2
2
|
export { QueriesObserver, QueriesObserverOptions } from './queriesObserver.js';
|
|
3
3
|
export { InfiniteQueryObserver } from './infiniteQueryObserver.js';
|
|
4
4
|
export { notifyManager } from './notifyManager.js';
|
|
@@ -91,7 +91,7 @@ function infiniteQueryBehavior(pages) {
|
|
|
91
91
|
const remainingPages = pages ?? oldPages.length;
|
|
92
92
|
do {
|
|
93
93
|
const param = currentPage === 0 ? oldPageParams[0] ?? options.initialPageParam : getNextPageParam(options, result);
|
|
94
|
-
if (param == null) {
|
|
94
|
+
if (currentPage > 0 && param == null) {
|
|
95
95
|
break;
|
|
96
96
|
}
|
|
97
97
|
result = await fetchPage(result, param);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/infiniteQueryBehavior.ts"],"sourcesContent":["import { addToEnd, addToStart, ensureQueryFn } from './utils'\nimport type { QueryBehavior } from './query'\nimport type {\n InfiniteData,\n InfiniteQueryPageParamsOptions,\n OmitKeyof,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\nexport function infiniteQueryBehavior<TQueryFnData, TError, TData, TPageParam>(\n pages?: number,\n): QueryBehavior<TQueryFnData, TError, InfiniteData<TData, TPageParam>> {\n return {\n onFetch: (context, query) => {\n const options = context.options as InfiniteQueryPageParamsOptions<TData>\n const direction = context.fetchOptions?.meta?.fetchMore?.direction\n const oldPages = context.state.data?.pages || []\n const oldPageParams = context.state.data?.pageParams || []\n let result: InfiniteData<unknown> = { pages: [], pageParams: [] }\n let currentPage = 0\n\n const fetchFn = async () => {\n let cancelled = false\n const addSignalProperty = (object: unknown) => {\n Object.defineProperty(object, 'signal', {\n enumerable: true,\n get: () => {\n if (context.signal.aborted) {\n cancelled = true\n } else {\n context.signal.addEventListener('abort', () => {\n cancelled = true\n })\n }\n return context.signal\n },\n })\n }\n\n const queryFn = ensureQueryFn(context.options, context.fetchOptions)\n\n // Create function to fetch a page\n const fetchPage = async (\n data: InfiniteData<unknown>,\n param: unknown,\n previous?: boolean,\n ): Promise<InfiniteData<unknown>> => {\n if (cancelled) {\n return Promise.reject()\n }\n\n if (param == null && data.pages.length) {\n return Promise.resolve(data)\n }\n\n const queryFnContext: OmitKeyof<\n QueryFunctionContext<QueryKey, unknown>,\n 'signal'\n > = {\n queryKey: context.queryKey,\n pageParam: param,\n direction: previous ? 'backward' : 'forward',\n meta: context.options.meta,\n }\n\n addSignalProperty(queryFnContext)\n\n const page = await queryFn(\n queryFnContext as QueryFunctionContext<QueryKey, unknown>,\n )\n\n const { maxPages } = context.options\n const addTo = previous ? addToStart : addToEnd\n\n return {\n pages: addTo(data.pages, page, maxPages),\n pageParams: addTo(data.pageParams, param, maxPages),\n }\n }\n\n // fetch next / previous page?\n if (direction && oldPages.length) {\n const previous = direction === 'backward'\n const pageParamFn = previous ? getPreviousPageParam : getNextPageParam\n const oldData = {\n pages: oldPages,\n pageParams: oldPageParams,\n }\n const param = pageParamFn(options, oldData)\n\n result = await fetchPage(oldData, param, previous)\n } else {\n const remainingPages = pages ?? oldPages.length\n\n // Fetch all pages\n do {\n const param =\n currentPage === 0\n ? (oldPageParams[0] ?? options.initialPageParam)\n : getNextPageParam(options, result)\n if (param == null) {\n break\n }\n result = await fetchPage(result, param)\n currentPage++\n } while (currentPage < remainingPages)\n }\n\n return result\n }\n if (context.options.persister) {\n context.fetchFn = () => {\n return context.options.persister?.(\n fetchFn as any,\n {\n queryKey: context.queryKey,\n meta: context.options.meta,\n signal: context.signal,\n },\n query,\n )\n }\n } else {\n context.fetchFn = fetchFn\n }\n },\n }\n}\n\nfunction getNextPageParam(\n options: InfiniteQueryPageParamsOptions<any>,\n { pages, pageParams }: InfiniteData<unknown>,\n): unknown | undefined {\n const lastIndex = pages.length - 1\n return pages.length > 0\n ? options.getNextPageParam(\n pages[lastIndex],\n pages,\n pageParams[lastIndex],\n pageParams,\n )\n : undefined\n}\n\nfunction getPreviousPageParam(\n options: InfiniteQueryPageParamsOptions<any>,\n { pages, pageParams }: InfiniteData<unknown>,\n): unknown | undefined {\n return pages.length > 0\n ? options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams)\n : undefined\n}\n\n/**\n * Checks if there is a next page.\n */\nexport function hasNextPage(\n options: InfiniteQueryPageParamsOptions<any, any>,\n data?: InfiniteData<unknown>,\n): boolean {\n if (!data) return false\n return getNextPageParam(options, data) != null\n}\n\n/**\n * Checks if there is a previous page.\n */\nexport function hasPreviousPage(\n options: InfiniteQueryPageParamsOptions<any, any>,\n data?: InfiniteData<unknown>,\n): boolean {\n if (!data || !options.getPreviousPageParam) return false\n return getPreviousPageParam(options, data) != null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAoD;AAU7C,SAAS,sBACd,OACsE;AACtE,SAAO;AAAA,IACL,SAAS,CAAC,SAAS,UAAU;AAdjC;AAeM,YAAM,UAAU,QAAQ;AACxB,YAAM,aAAY,yBAAQ,iBAAR,mBAAsB,SAAtB,mBAA4B,cAA5B,mBAAuC;AACzD,YAAM,aAAW,aAAQ,MAAM,SAAd,mBAAoB,UAAS,CAAC;AAC/C,YAAM,kBAAgB,aAAQ,MAAM,SAAd,mBAAoB,eAAc,CAAC;AACzD,UAAI,SAAgC,EAAE,OAAO,CAAC,GAAG,YAAY,CAAC,EAAE;AAChE,UAAI,cAAc;AAElB,YAAM,UAAU,YAAY;AAC1B,YAAI,YAAY;AAChB,cAAM,oBAAoB,CAAC,WAAoB;AAC7C,iBAAO,eAAe,QAAQ,UAAU;AAAA,YACtC,YAAY;AAAA,YACZ,KAAK,MAAM;AACT,kBAAI,QAAQ,OAAO,SAAS;AAC1B,4BAAY;AAAA,cACd,OAAO;AACL,wBAAQ,OAAO,iBAAiB,SAAS,MAAM;AAC7C,8BAAY;AAAA,gBACd,CAAC;AAAA,cACH;AACA,qBAAO,QAAQ;AAAA,YACjB;AAAA,UACF,CAAC;AAAA,QACH;AAEA,cAAM,cAAU,4BAAc,QAAQ,SAAS,QAAQ,YAAY;AAGnE,cAAM,YAAY,OAChB,MACA,OACA,aACmC;AACnC,cAAI,WAAW;AACb,mBAAO,QAAQ,OAAO;AAAA,UACxB;AAEA,cAAI,SAAS,QAAQ,KAAK,MAAM,QAAQ;AACtC,mBAAO,QAAQ,QAAQ,IAAI;AAAA,UAC7B;AAEA,gBAAM,iBAGF;AAAA,YACF,UAAU,QAAQ;AAAA,YAClB,WAAW;AAAA,YACX,WAAW,WAAW,aAAa;AAAA,YACnC,MAAM,QAAQ,QAAQ;AAAA,UACxB;AAEA,4BAAkB,cAAc;AAEhC,gBAAM,OAAO,MAAM;AAAA,YACjB;AAAA,UACF;AAEA,gBAAM,EAAE,SAAS,IAAI,QAAQ;AAC7B,gBAAM,QAAQ,WAAW,0BAAa;AAEtC,iBAAO;AAAA,YACL,OAAO,MAAM,KAAK,OAAO,MAAM,QAAQ;AAAA,YACvC,YAAY,MAAM,KAAK,YAAY,OAAO,QAAQ;AAAA,UACpD;AAAA,QACF;AAGA,YAAI,aAAa,SAAS,QAAQ;AAChC,gBAAM,WAAW,cAAc;AAC/B,gBAAM,cAAc,WAAW,uBAAuB;AACtD,gBAAM,UAAU;AAAA,YACd,OAAO;AAAA,YACP,YAAY;AAAA,UACd;AACA,gBAAM,QAAQ,YAAY,SAAS,OAAO;AAE1C,mBAAS,MAAM,UAAU,SAAS,OAAO,QAAQ;AAAA,QACnD,OAAO;AACL,gBAAM,iBAAiB,SAAS,SAAS;AAGzC,aAAG;AACD,kBAAM,QACJ,gBAAgB,IACX,cAAc,CAAC,KAAK,QAAQ,mBAC7B,iBAAiB,SAAS,MAAM;AACtC,gBAAI,SAAS,MAAM;
|
|
1
|
+
{"version":3,"sources":["../../src/infiniteQueryBehavior.ts"],"sourcesContent":["import { addToEnd, addToStart, ensureQueryFn } from './utils'\nimport type { QueryBehavior } from './query'\nimport type {\n InfiniteData,\n InfiniteQueryPageParamsOptions,\n OmitKeyof,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\nexport function infiniteQueryBehavior<TQueryFnData, TError, TData, TPageParam>(\n pages?: number,\n): QueryBehavior<TQueryFnData, TError, InfiniteData<TData, TPageParam>> {\n return {\n onFetch: (context, query) => {\n const options = context.options as InfiniteQueryPageParamsOptions<TData>\n const direction = context.fetchOptions?.meta?.fetchMore?.direction\n const oldPages = context.state.data?.pages || []\n const oldPageParams = context.state.data?.pageParams || []\n let result: InfiniteData<unknown> = { pages: [], pageParams: [] }\n let currentPage = 0\n\n const fetchFn = async () => {\n let cancelled = false\n const addSignalProperty = (object: unknown) => {\n Object.defineProperty(object, 'signal', {\n enumerable: true,\n get: () => {\n if (context.signal.aborted) {\n cancelled = true\n } else {\n context.signal.addEventListener('abort', () => {\n cancelled = true\n })\n }\n return context.signal\n },\n })\n }\n\n const queryFn = ensureQueryFn(context.options, context.fetchOptions)\n\n // Create function to fetch a page\n const fetchPage = async (\n data: InfiniteData<unknown>,\n param: unknown,\n previous?: boolean,\n ): Promise<InfiniteData<unknown>> => {\n if (cancelled) {\n return Promise.reject()\n }\n\n if (param == null && data.pages.length) {\n return Promise.resolve(data)\n }\n\n const queryFnContext: OmitKeyof<\n QueryFunctionContext<QueryKey, unknown>,\n 'signal'\n > = {\n queryKey: context.queryKey,\n pageParam: param,\n direction: previous ? 'backward' : 'forward',\n meta: context.options.meta,\n }\n\n addSignalProperty(queryFnContext)\n\n const page = await queryFn(\n queryFnContext as QueryFunctionContext<QueryKey, unknown>,\n )\n\n const { maxPages } = context.options\n const addTo = previous ? addToStart : addToEnd\n\n return {\n pages: addTo(data.pages, page, maxPages),\n pageParams: addTo(data.pageParams, param, maxPages),\n }\n }\n\n // fetch next / previous page?\n if (direction && oldPages.length) {\n const previous = direction === 'backward'\n const pageParamFn = previous ? getPreviousPageParam : getNextPageParam\n const oldData = {\n pages: oldPages,\n pageParams: oldPageParams,\n }\n const param = pageParamFn(options, oldData)\n\n result = await fetchPage(oldData, param, previous)\n } else {\n const remainingPages = pages ?? oldPages.length\n\n // Fetch all pages\n do {\n const param =\n currentPage === 0\n ? (oldPageParams[0] ?? options.initialPageParam)\n : getNextPageParam(options, result)\n if (currentPage > 0 && param == null) {\n break\n }\n result = await fetchPage(result, param)\n currentPage++\n } while (currentPage < remainingPages)\n }\n\n return result\n }\n if (context.options.persister) {\n context.fetchFn = () => {\n return context.options.persister?.(\n fetchFn as any,\n {\n queryKey: context.queryKey,\n meta: context.options.meta,\n signal: context.signal,\n },\n query,\n )\n }\n } else {\n context.fetchFn = fetchFn\n }\n },\n }\n}\n\nfunction getNextPageParam(\n options: InfiniteQueryPageParamsOptions<any>,\n { pages, pageParams }: InfiniteData<unknown>,\n): unknown | undefined {\n const lastIndex = pages.length - 1\n return pages.length > 0\n ? options.getNextPageParam(\n pages[lastIndex],\n pages,\n pageParams[lastIndex],\n pageParams,\n )\n : undefined\n}\n\nfunction getPreviousPageParam(\n options: InfiniteQueryPageParamsOptions<any>,\n { pages, pageParams }: InfiniteData<unknown>,\n): unknown | undefined {\n return pages.length > 0\n ? options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams)\n : undefined\n}\n\n/**\n * Checks if there is a next page.\n */\nexport function hasNextPage(\n options: InfiniteQueryPageParamsOptions<any, any>,\n data?: InfiniteData<unknown>,\n): boolean {\n if (!data) return false\n return getNextPageParam(options, data) != null\n}\n\n/**\n * Checks if there is a previous page.\n */\nexport function hasPreviousPage(\n options: InfiniteQueryPageParamsOptions<any, any>,\n data?: InfiniteData<unknown>,\n): boolean {\n if (!data || !options.getPreviousPageParam) return false\n return getPreviousPageParam(options, data) != null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAoD;AAU7C,SAAS,sBACd,OACsE;AACtE,SAAO;AAAA,IACL,SAAS,CAAC,SAAS,UAAU;AAdjC;AAeM,YAAM,UAAU,QAAQ;AACxB,YAAM,aAAY,yBAAQ,iBAAR,mBAAsB,SAAtB,m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,MAAM,CAAC,GAAG,OAAO,WAAW,CAAC,GAAG,cAC/D;AACN;AAKO,SAAS,YACd,SACA,MACS;AACT,MAAI,CAAC;AAAM,WAAO;AAClB,SAAO,iBAAiB,SAAS,IAAI,KAAK;AAC5C;AAKO,SAAS,gBACd,SACA,MACS;AACT,MAAI,CAAC,QAAQ,CAAC,QAAQ;AAAsB,WAAO;AACnD,SAAO,qBAAqB,SAAS,IAAI,KAAK;AAChD;","names":["_a","_b"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { aZ as QueryBehavior, Y as InfiniteData, a2 as InfiniteQueryPageParamsOptions } from './hydration-
|
|
1
|
+
import { aZ as QueryBehavior, Y as InfiniteData, a2 as InfiniteQueryPageParamsOptions } from './hydration-CVKA21uy.cjs';
|
|
2
2
|
import './removable.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { aZ as QueryBehavior, Y as InfiniteData, a2 as InfiniteQueryPageParamsOptions } from './hydration-
|
|
1
|
+
import { aZ as QueryBehavior, Y as InfiniteData, a2 as InfiniteQueryPageParamsOptions } from './hydration-DHZNyHqg.js';
|
|
2
2
|
import './removable.js';
|
|
3
3
|
import './subscribable.js';
|
|
4
4
|
|
|
@@ -67,7 +67,7 @@ function infiniteQueryBehavior(pages) {
|
|
|
67
67
|
const remainingPages = pages ?? oldPages.length;
|
|
68
68
|
do {
|
|
69
69
|
const param = currentPage === 0 ? oldPageParams[0] ?? options.initialPageParam : getNextPageParam(options, result);
|
|
70
|
-
if (param == null) {
|
|
70
|
+
if (currentPage > 0 && param == null) {
|
|
71
71
|
break;
|
|
72
72
|
}
|
|
73
73
|
result = await fetchPage(result, param);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/infiniteQueryBehavior.ts"],"sourcesContent":["import { addToEnd, addToStart, ensureQueryFn } from './utils'\nimport type { QueryBehavior } from './query'\nimport type {\n InfiniteData,\n InfiniteQueryPageParamsOptions,\n OmitKeyof,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\nexport function infiniteQueryBehavior<TQueryFnData, TError, TData, TPageParam>(\n pages?: number,\n): QueryBehavior<TQueryFnData, TError, InfiniteData<TData, TPageParam>> {\n return {\n onFetch: (context, query) => {\n const options = context.options as InfiniteQueryPageParamsOptions<TData>\n const direction = context.fetchOptions?.meta?.fetchMore?.direction\n const oldPages = context.state.data?.pages || []\n const oldPageParams = context.state.data?.pageParams || []\n let result: InfiniteData<unknown> = { pages: [], pageParams: [] }\n let currentPage = 0\n\n const fetchFn = async () => {\n let cancelled = false\n const addSignalProperty = (object: unknown) => {\n Object.defineProperty(object, 'signal', {\n enumerable: true,\n get: () => {\n if (context.signal.aborted) {\n cancelled = true\n } else {\n context.signal.addEventListener('abort', () => {\n cancelled = true\n })\n }\n return context.signal\n },\n })\n }\n\n const queryFn = ensureQueryFn(context.options, context.fetchOptions)\n\n // Create function to fetch a page\n const fetchPage = async (\n data: InfiniteData<unknown>,\n param: unknown,\n previous?: boolean,\n ): Promise<InfiniteData<unknown>> => {\n if (cancelled) {\n return Promise.reject()\n }\n\n if (param == null && data.pages.length) {\n return Promise.resolve(data)\n }\n\n const queryFnContext: OmitKeyof<\n QueryFunctionContext<QueryKey, unknown>,\n 'signal'\n > = {\n queryKey: context.queryKey,\n pageParam: param,\n direction: previous ? 'backward' : 'forward',\n meta: context.options.meta,\n }\n\n addSignalProperty(queryFnContext)\n\n const page = await queryFn(\n queryFnContext as QueryFunctionContext<QueryKey, unknown>,\n )\n\n const { maxPages } = context.options\n const addTo = previous ? addToStart : addToEnd\n\n return {\n pages: addTo(data.pages, page, maxPages),\n pageParams: addTo(data.pageParams, param, maxPages),\n }\n }\n\n // fetch next / previous page?\n if (direction && oldPages.length) {\n const previous = direction === 'backward'\n const pageParamFn = previous ? getPreviousPageParam : getNextPageParam\n const oldData = {\n pages: oldPages,\n pageParams: oldPageParams,\n }\n const param = pageParamFn(options, oldData)\n\n result = await fetchPage(oldData, param, previous)\n } else {\n const remainingPages = pages ?? oldPages.length\n\n // Fetch all pages\n do {\n const param =\n currentPage === 0\n ? (oldPageParams[0] ?? options.initialPageParam)\n : getNextPageParam(options, result)\n if (param == null) {\n break\n }\n result = await fetchPage(result, param)\n currentPage++\n } while (currentPage < remainingPages)\n }\n\n return result\n }\n if (context.options.persister) {\n context.fetchFn = () => {\n return context.options.persister?.(\n fetchFn as any,\n {\n queryKey: context.queryKey,\n meta: context.options.meta,\n signal: context.signal,\n },\n query,\n )\n }\n } else {\n context.fetchFn = fetchFn\n }\n },\n }\n}\n\nfunction getNextPageParam(\n options: InfiniteQueryPageParamsOptions<any>,\n { pages, pageParams }: InfiniteData<unknown>,\n): unknown | undefined {\n const lastIndex = pages.length - 1\n return pages.length > 0\n ? options.getNextPageParam(\n pages[lastIndex],\n pages,\n pageParams[lastIndex],\n pageParams,\n )\n : undefined\n}\n\nfunction getPreviousPageParam(\n options: InfiniteQueryPageParamsOptions<any>,\n { pages, pageParams }: InfiniteData<unknown>,\n): unknown | undefined {\n return pages.length > 0\n ? options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams)\n : undefined\n}\n\n/**\n * Checks if there is a next page.\n */\nexport function hasNextPage(\n options: InfiniteQueryPageParamsOptions<any, any>,\n data?: InfiniteData<unknown>,\n): boolean {\n if (!data) return false\n return getNextPageParam(options, data) != null\n}\n\n/**\n * Checks if there is a previous page.\n */\nexport function hasPreviousPage(\n options: InfiniteQueryPageParamsOptions<any, any>,\n data?: InfiniteData<unknown>,\n): boolean {\n if (!data || !options.getPreviousPageParam) return false\n return getPreviousPageParam(options, data) != null\n}\n"],"mappings":";;;AAAA,SAAS,UAAU,YAAY,qBAAqB;AAU7C,SAAS,sBACd,OACsE;AACtE,SAAO;AAAA,IACL,SAAS,CAAC,SAAS,UAAU;AAdjC;AAeM,YAAM,UAAU,QAAQ;AACxB,YAAM,aAAY,yBAAQ,iBAAR,mBAAsB,SAAtB,mBA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,YAAI,aAAa,SAAS,QAAQ;AAChC,gBAAM,WAAW,cAAc;AAC/B,gBAAM,cAAc,WAAW,uBAAuB;AACtD,gBAAM,UAAU;AAAA,YACd,OAAO;AAAA,YACP,YAAY;AAAA,UACd;AACA,gBAAM,QAAQ,YAAY,SAAS,OAAO;AAE1C,mBAAS,MAAM,UAAU,SAAS,OAAO,QAAQ;AAAA,QACnD,OAAO;AACL,gBAAM,iBAAiB,SAAS,SAAS;AAGzC,aAAG;AACD,kBAAM,QACJ,gBAAgB,IACX,cAAc,CAAC,KAAK,QAAQ,mBAC7B,iBAAiB,SAAS,MAAM;AACtC,gBAAI,SAAS,MAAM;
|
|
1
|
+
{"version":3,"sources":["../../src/infiniteQueryBehavior.ts"],"sourcesContent":["import { addToEnd, addToStart, ensureQueryFn } from './utils'\nimport type { QueryBehavior } from './query'\nimport type {\n InfiniteData,\n InfiniteQueryPageParamsOptions,\n OmitKeyof,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\nexport function infiniteQueryBehavior<TQueryFnData, TError, TData, TPageParam>(\n pages?: number,\n): QueryBehavior<TQueryFnData, TError, InfiniteData<TData, TPageParam>> {\n return {\n onFetch: (context, query) => {\n const options = context.options as InfiniteQueryPageParamsOptions<TData>\n const direction = context.fetchOptions?.meta?.fetchMore?.direction\n const oldPages = context.state.data?.pages || []\n const oldPageParams = context.state.data?.pageParams || []\n let result: InfiniteData<unknown> = { pages: [], pageParams: [] }\n let currentPage = 0\n\n const fetchFn = async () => {\n let cancelled = false\n const addSignalProperty = (object: unknown) => {\n Object.defineProperty(object, 'signal', {\n enumerable: true,\n get: () => {\n if (context.signal.aborted) {\n cancelled = true\n } else {\n context.signal.addEventListener('abort', () => {\n cancelled = true\n })\n }\n return context.signal\n },\n })\n }\n\n const queryFn = ensureQueryFn(context.options, context.fetchOptions)\n\n // Create function to fetch a page\n const fetchPage = async (\n data: InfiniteData<unknown>,\n param: unknown,\n previous?: boolean,\n ): Promise<InfiniteData<unknown>> => {\n if (cancelled) {\n return Promise.reject()\n }\n\n if (param == null && data.pages.length) {\n return Promise.resolve(data)\n }\n\n const queryFnContext: OmitKeyof<\n QueryFunctionContext<QueryKey, unknown>,\n 'signal'\n > = {\n queryKey: context.queryKey,\n pageParam: param,\n direction: previous ? 'backward' : 'forward',\n meta: context.options.meta,\n }\n\n addSignalProperty(queryFnContext)\n\n const page = await queryFn(\n queryFnContext as QueryFunctionContext<QueryKey, unknown>,\n )\n\n const { maxPages } = context.options\n const addTo = previous ? addToStart : addToEnd\n\n return {\n pages: addTo(data.pages, page, maxPages),\n pageParams: addTo(data.pageParams, param, maxPages),\n }\n }\n\n // fetch next / previous page?\n if (direction && oldPages.length) {\n const previous = direction === 'backward'\n const pageParamFn = previous ? getPreviousPageParam : getNextPageParam\n const oldData = {\n pages: oldPages,\n pageParams: oldPageParams,\n }\n const param = pageParamFn(options, oldData)\n\n result = await fetchPage(oldData, param, previous)\n } else {\n const remainingPages = pages ?? oldPages.length\n\n // Fetch all pages\n do {\n const param =\n currentPage === 0\n ? (oldPageParams[0] ?? options.initialPageParam)\n : getNextPageParam(options, result)\n if (currentPage > 0 && param == null) {\n break\n }\n result = await fetchPage(result, param)\n currentPage++\n } while (currentPage < remainingPages)\n }\n\n return result\n }\n if (context.options.persister) {\n context.fetchFn = () => {\n return context.options.persister?.(\n fetchFn as any,\n {\n queryKey: context.queryKey,\n meta: context.options.meta,\n signal: context.signal,\n },\n query,\n )\n }\n } else {\n context.fetchFn = fetchFn\n }\n },\n }\n}\n\nfunction getNextPageParam(\n options: InfiniteQueryPageParamsOptions<any>,\n { pages, pageParams }: InfiniteData<unknown>,\n): unknown | undefined {\n const lastIndex = pages.length - 1\n return pages.length > 0\n ? options.getNextPageParam(\n pages[lastIndex],\n pages,\n pageParams[lastIndex],\n pageParams,\n )\n : undefined\n}\n\nfunction getPreviousPageParam(\n options: InfiniteQueryPageParamsOptions<any>,\n { pages, pageParams }: InfiniteData<unknown>,\n): unknown | undefined {\n return pages.length > 0\n ? options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams)\n : undefined\n}\n\n/**\n * Checks if there is a next page.\n */\nexport function hasNextPage(\n options: InfiniteQueryPageParamsOptions<any, any>,\n data?: InfiniteData<unknown>,\n): boolean {\n if (!data) return false\n return getNextPageParam(options, data) != null\n}\n\n/**\n * Checks if there is a previous page.\n */\nexport function hasPreviousPage(\n options: InfiniteQueryPageParamsOptions<any, any>,\n data?: InfiniteData<unknown>,\n): boolean {\n if (!data || !options.getPreviousPageParam) return false\n return getPreviousPageParam(options, data) != null\n}\n"],"mappings":";;;AAAA,SAAS,UAAU,YAAY,qBAAqB;AAU7C,SAAS,sBACd,OACsE;AACtE,SAAO;AAAA,IACL,SAAS,CAAC,SAAS,UAAU;AAdjC;AAeM,YAAM,UAAU,QAAQ;AACxB,YAAM,aAAY,yBAAQ,iBAAR,mBAAsB,SAAtB,mBAA4B,cAA5B,mBAAuC;AACzD,YAAM,aAAW,aAAQ,MAAM,SAAd,mBAAoB,UAAS,CAAC;AAC/C,YAAM,kBAAgB,aAAQ,MAAM,SAAd,mBAAoB,eAAc,CAAC;AACzD,UAAI,SAAgC,EAAE,OAAO,CAAC,GAAG,YAAY,CAAC,EAAE;AAChE,UAAI,cAAc;AAElB,YAAM,UAAU,YAAY;AAC1B,YAAI,YAAY;AAChB,cAAM,oBAAoB,CAAC,WAAoB;AAC7C,iBAAO,eAAe,QAAQ,UAAU;AAAA,YACtC,YAAY;AAAA,YACZ,KAAK,MAAM;AACT,kBAAI,QAAQ,OAAO,SAAS;AAC1B,4BAAY;AAAA,cACd,OAAO;AACL,wBAAQ,OAAO,iBAAiB,SAAS,MAAM;AAC7C,8BAAY;AAAA,gBACd,CAAC;AAAA,cACH;AACA,qBAAO,QAAQ;AAAA,YACjB;AAAA,UACF,CAAC;AAAA,QACH;AAEA,cAAM,UAAU,cAAc,QAAQ,SAAS,QAAQ,YAAY;AAGnE,cAAM,YAAY,OAChB,MACA,OACA,aACmC;AACnC,cAA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,IAAA;AAAA,YAAAD;AAAA,YACL;AAAA,YACA;AAAA,cACE,UAAU,QAAQ;AAAA,cAClB,MAAM,QAAQ,QAAQ;AAAA,cACtB,QAAQ,QAAQ;AAAA,YAClB;AAAA,YACA;AAAA;AAAA,QAEJ;AAAA,MACF,OAAO;AACL,gBAAQ,UAAU;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,iBACP,SACA,EAAE,OAAO,WAAW,GACC;AACrB,QAAM,YAAY,MAAM,SAAS;AACjC,SAAO,MAAM,SAAS,IAClB,QAAQ;AAAA,IACN,MAAM,SAAS;AAAA,IACf;AAAA,IACA,WAAW,SAAS;AAAA,IACpB;AAAA,EACF,IACA;AACN;AAEA,SAAS,qBACP,SACA,EAAE,OAAO,WAAW,GACC;AApJvB;AAqJE,SAAO,MAAM,SAAS,KAClB,aAAQ,yBAAR,iCAA+B,MAAM,CAAC,GAAG,OAAO,WAAW,CAAC,GAAG,cAC/D;AACN;AAKO,SAAS,YACd,SACA,MACS;AACT,MAAI,CAAC;AAAM,WAAO;AAClB,SAAO,iBAAiB,SAAS,IAAI,KAAK;AAC5C;AAKO,SAAS,gBACd,SACA,MACS;AACT,MAAI,CAAC,QAAQ,CAAC,QAAQ;AAAsB,WAAO;AACnD,SAAO,qBAAqB,SAAS,IAAI,KAAK;AAChD;","names":["_a","_b"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z as DefaultError, Y as InfiniteData, A as QueryKey, c as QueryObserver, aD as InfiniteQueryObserverResult, b as QueryClient, a8 as InfiniteQueryObserverOptions, a_ as NotifyOptions, a9 as DefaultedInfiniteQueryObserverOptions, ak as FetchNextPageOptions, al as FetchPreviousPageOptions, u as Query } from './hydration-
|
|
1
|
+
import { z as DefaultError, Y as InfiniteData, A as QueryKey, c as QueryObserver, aD as InfiniteQueryObserverResult, b as QueryClient, a8 as InfiniteQueryObserverOptions, a_ as NotifyOptions, a9 as DefaultedInfiniteQueryObserverOptions, ak as FetchNextPageOptions, al as FetchPreviousPageOptions, u as Query } from './hydration-CVKA21uy.cjs';
|
|
2
2
|
import { Subscribable } from './subscribable.cjs';
|
|
3
3
|
import './removable.cjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z as DefaultError, Y as InfiniteData, A as QueryKey, c as QueryObserver, aD as InfiniteQueryObserverResult, b as QueryClient, a8 as InfiniteQueryObserverOptions, a_ as NotifyOptions, a9 as DefaultedInfiniteQueryObserverOptions, ak as FetchNextPageOptions, al as FetchPreviousPageOptions, u as Query } from './hydration-
|
|
1
|
+
import { z as DefaultError, Y as InfiniteData, A as QueryKey, c as QueryObserver, aD as InfiniteQueryObserverResult, b as QueryClient, a8 as InfiniteQueryObserverOptions, a_ as NotifyOptions, a9 as DefaultedInfiniteQueryObserverOptions, ak as FetchNextPageOptions, al as FetchPreviousPageOptions, u as Query } from './hydration-DHZNyHqg.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 { bo as Action, w as Mutation, v as MutationState, bp as getDefaultState } from './hydration-
|
|
2
|
+
export { bo as Action, w as Mutation, v as MutationState, bp as getDefaultState } from './hydration-CVKA21uy.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import './removable.js';
|
|
2
|
-
export { bo as Action, w as Mutation, v as MutationState, bp as getDefaultState } from './hydration-
|
|
2
|
+
export { bo as Action, w as Mutation, v as MutationState, bp as getDefaultState } from './hydration-DHZNyHqg.js';
|
|
3
3
|
import './subscribable.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { av as QueryObserverResult, b as QueryClient, a4 as QueryObserverOptions, a_ as NotifyOptions, u as Query, A as QueryKey, c as QueryObserver } from './hydration-
|
|
1
|
+
import { av as QueryObserverResult, b as QueryClient, a4 as QueryObserverOptions, a_ as NotifyOptions, u as Query, A as QueryKey, c as QueryObserver } from './hydration-CVKA21uy.cjs';
|
|
2
2
|
import { Subscribable } from './subscribable.cjs';
|
|
3
3
|
import './removable.cjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { av as QueryObserverResult, b as QueryClient, a4 as QueryObserverOptions, a_ as NotifyOptions, u as Query, A as QueryKey, c as QueryObserver } from './hydration-
|
|
1
|
+
import { av as QueryObserverResult, b as QueryClient, a4 as QueryObserverOptions, a_ as NotifyOptions, u as Query, A as QueryKey, c as QueryObserver } from './hydration-DHZNyHqg.js';
|
|
2
2
|
import { Subscribable } from './subscribable.js';
|
|
3
3
|
import './removable.js';
|
|
4
4
|
|
package/build/legacy/query.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import './removable.cjs';
|
|
2
|
-
export { b3 as Action, a$ as FetchContext, b0 as FetchDirection, b1 as FetchMeta, b2 as FetchOptions, u as Query, aZ as QueryBehavior, t as QueryState, b4 as SetStateOptions, b5 as fetchState } from './hydration-
|
|
2
|
+
export { b3 as Action, a$ as FetchContext, b0 as FetchDirection, b1 as FetchMeta, b2 as FetchOptions, u as Query, aZ as QueryBehavior, t as QueryState, b4 as SetStateOptions, b5 as fetchState } from './hydration-CVKA21uy.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
package/build/legacy/query.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import './removable.js';
|
|
2
|
-
export { b3 as Action, a$ as FetchContext, b0 as FetchDirection, b1 as FetchMeta, b2 as FetchOptions, u as Query, aZ as QueryBehavior, t as QueryState, b4 as SetStateOptions, b5 as fetchState } from './hydration-
|
|
2
|
+
export { b3 as Action, a$ as FetchContext, b0 as FetchDirection, b1 as FetchMeta, b2 as FetchOptions, u as Query, aZ as QueryBehavior, t as QueryState, b4 as SetStateOptions, b5 as fetchState } from './hydration-DHZNyHqg.js';
|
|
3
3
|
import './subscribable.js';
|
|
@@ -45,12 +45,13 @@ __export(queryObserver_exports, {
|
|
|
45
45
|
QueryObserver: () => QueryObserver
|
|
46
46
|
});
|
|
47
47
|
module.exports = __toCommonJS(queryObserver_exports);
|
|
48
|
-
var import_utils = require("./utils.cjs");
|
|
49
|
-
var import_notifyManager = require("./notifyManager.cjs");
|
|
50
48
|
var import_focusManager = require("./focusManager.cjs");
|
|
51
|
-
var
|
|
49
|
+
var import_notifyManager = require("./notifyManager.cjs");
|
|
52
50
|
var import_query = require("./query.cjs");
|
|
53
|
-
var
|
|
51
|
+
var import_subscribable = require("./subscribable.cjs");
|
|
52
|
+
var import_thenable = require("./thenable.cjs");
|
|
53
|
+
var import_utils = require("./utils.cjs");
|
|
54
|
+
var _client, _currentQuery, _currentQueryInitialState, _currentResult, _currentResultState, _currentResultOptions, _currentThenable, _selectError, _selectFn, _selectResult, _lastQueryWithDefinedData, _staleTimeoutId, _refetchIntervalId, _currentRefetchInterval, _trackedProps, _executeFetch, executeFetch_fn, _updateStaleTimeout, updateStaleTimeout_fn, _computeRefetchInterval, computeRefetchInterval_fn, _updateRefetchInterval, updateRefetchInterval_fn, _updateTimers, updateTimers_fn, _clearStaleTimeout, clearStaleTimeout_fn, _clearRefetchInterval, clearRefetchInterval_fn, _updateQuery, updateQuery_fn, _notify, notify_fn;
|
|
54
55
|
var QueryObserver = class extends import_subscribable.Subscribable {
|
|
55
56
|
constructor(client, options) {
|
|
56
57
|
super();
|
|
@@ -70,6 +71,7 @@ var QueryObserver = class extends import_subscribable.Subscribable {
|
|
|
70
71
|
__privateAdd(this, _currentResult, void 0);
|
|
71
72
|
__privateAdd(this, _currentResultState, void 0);
|
|
72
73
|
__privateAdd(this, _currentResultOptions, void 0);
|
|
74
|
+
__privateAdd(this, _currentThenable, void 0);
|
|
73
75
|
__privateAdd(this, _selectError, void 0);
|
|
74
76
|
__privateAdd(this, _selectFn, void 0);
|
|
75
77
|
__privateAdd(this, _selectResult, void 0);
|
|
@@ -82,6 +84,12 @@ var QueryObserver = class extends import_subscribable.Subscribable {
|
|
|
82
84
|
__privateAdd(this, _trackedProps, /* @__PURE__ */ new Set());
|
|
83
85
|
__privateSet(this, _client, client);
|
|
84
86
|
__privateSet(this, _selectError, null);
|
|
87
|
+
__privateSet(this, _currentThenable, (0, import_thenable.pendingThenable)());
|
|
88
|
+
if (!this.options.experimental_prefetchInRender) {
|
|
89
|
+
__privateGet(this, _currentThenable).reject(
|
|
90
|
+
new Error("experimental_prefetchInRender feature flag is not enabled")
|
|
91
|
+
);
|
|
92
|
+
}
|
|
85
93
|
this.bindMethods();
|
|
86
94
|
this.setOptions(options);
|
|
87
95
|
}
|
|
@@ -322,7 +330,8 @@ var QueryObserver = class extends import_subscribable.Subscribable {
|
|
|
322
330
|
isPlaceholderData,
|
|
323
331
|
isRefetchError: isError && hasData,
|
|
324
332
|
isStale: isStale(query, options),
|
|
325
|
-
refetch: this.refetch
|
|
333
|
+
refetch: this.refetch,
|
|
334
|
+
promise: __privateGet(this, _currentThenable)
|
|
326
335
|
};
|
|
327
336
|
return result;
|
|
328
337
|
}
|
|
@@ -337,6 +346,35 @@ var QueryObserver = class extends import_subscribable.Subscribable {
|
|
|
337
346
|
if ((0, import_utils.shallowEqualObjects)(nextResult, prevResult)) {
|
|
338
347
|
return;
|
|
339
348
|
}
|
|
349
|
+
if (this.options.experimental_prefetchInRender) {
|
|
350
|
+
const finalizeThenableIfPossible = (thenable) => {
|
|
351
|
+
if (nextResult.status === "error") {
|
|
352
|
+
thenable.reject(nextResult.error);
|
|
353
|
+
} else if (nextResult.data !== void 0) {
|
|
354
|
+
thenable.resolve(nextResult.data);
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
const recreateThenable = () => {
|
|
358
|
+
const pending = __privateSet(this, _currentThenable, nextResult.promise = (0, import_thenable.pendingThenable)());
|
|
359
|
+
finalizeThenableIfPossible(pending);
|
|
360
|
+
};
|
|
361
|
+
const prevThenable = __privateGet(this, _currentThenable);
|
|
362
|
+
switch (prevThenable.status) {
|
|
363
|
+
case "pending":
|
|
364
|
+
finalizeThenableIfPossible(prevThenable);
|
|
365
|
+
break;
|
|
366
|
+
case "fulfilled":
|
|
367
|
+
if (nextResult.status === "error" || nextResult.data !== prevThenable.value) {
|
|
368
|
+
recreateThenable();
|
|
369
|
+
}
|
|
370
|
+
break;
|
|
371
|
+
case "rejected":
|
|
372
|
+
if (nextResult.status !== "error" || nextResult.error !== prevThenable.reason) {
|
|
373
|
+
recreateThenable();
|
|
374
|
+
}
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
340
378
|
__privateSet(this, _currentResult, nextResult);
|
|
341
379
|
const defaultNotifyOptions = {};
|
|
342
380
|
const shouldNotifyListeners = () => {
|
|
@@ -378,6 +416,7 @@ _currentQueryInitialState = new WeakMap();
|
|
|
378
416
|
_currentResult = new WeakMap();
|
|
379
417
|
_currentResultState = new WeakMap();
|
|
380
418
|
_currentResultOptions = new WeakMap();
|
|
419
|
+
_currentThenable = new WeakMap();
|
|
381
420
|
_selectError = new WeakMap();
|
|
382
421
|
_selectFn = new WeakMap();
|
|
383
422
|
_selectResult = new WeakMap();
|