@tanstack/react-query 5.0.0-alpha.7 → 5.0.0-alpha.71
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/codemods/__testfixtures__/default-import.input.tsx +94 -0
- package/build/codemods/__testfixtures__/default-import.output.tsx +96 -0
- package/build/codemods/__testfixtures__/named-import.input.tsx +96 -0
- package/build/codemods/__testfixtures__/named-import.output.tsx +98 -0
- package/build/codemods/__testfixtures__/namespaced-import.input.tsx +86 -0
- package/build/codemods/__testfixtures__/namespaced-import.output.tsx +88 -0
- package/build/codemods/__testfixtures__/parameter-is-identifier.input.tsx +49 -0
- package/build/codemods/__testfixtures__/parameter-is-identifier.output.tsx +49 -0
- package/build/codemods/__testfixtures__/parameter-is-object-expression.input.tsx +128 -0
- package/build/codemods/__testfixtures__/parameter-is-object-expression.output.tsx +175 -0
- package/build/codemods/__testfixtures__/replace-import-specifier.input.tsx +10 -0
- package/build/codemods/__testfixtures__/replace-import-specifier.output.tsx +10 -0
- package/build/codemods/__testfixtures__/type-arguments.input.tsx +25 -0
- package/build/codemods/__testfixtures__/type-arguments.output.tsx +31 -0
- package/build/codemods/__tests__/key-transformation.test.js +32 -0
- package/build/codemods/__tests__/replace-import-specifier.test.js +12 -0
- package/build/codemods/remove-overloads/__testfixtures__/default-import.input.tsx +199 -0
- package/build/codemods/remove-overloads/__testfixtures__/default-import.output.tsx +484 -0
- package/build/codemods/remove-overloads/__tests__/remove-overloads.test.js +6 -0
- package/build/codemods/remove-overloads/remove-overloads.js +59 -0
- package/build/codemods/remove-overloads/transformers/filter-aware-usage-transformer.js +153 -0
- package/build/codemods/remove-overloads/transformers/query-fn-aware-usage-transformer.js +188 -0
- package/build/codemods/remove-overloads/utils/index.js +124 -0
- package/build/codemods/remove-overloads/utils/unknown-usage-error.js +27 -0
- package/build/codemods/src/utils/index.js +205 -0
- package/build/codemods/src/v4/key-transformation.js +138 -0
- package/build/codemods/src/v4/replace-import-specifier.js +25 -0
- package/build/codemods/transformers/query-cache-transformer.js +116 -0
- package/build/codemods/transformers/query-client-transformer.js +48 -0
- package/build/codemods/transformers/use-query-like-transformer.js +32 -0
- package/build/codemods/utils/replacers/key-replacer.js +164 -0
- package/build/lib/HydrationBoundary.cjs +50 -0
- package/build/lib/{HydrationBoundary.mjs.map → HydrationBoundary.cjs.map} +1 -1
- package/build/lib/HydrationBoundary.d.ts +1 -0
- package/build/lib/HydrationBoundary.d.ts.map +1 -0
- package/build/lib/HydrationBoundary.js +9 -29
- package/build/lib/HydrationBoundary.js.map +1 -1
- package/build/lib/HydrationBoundary.legacy.cjs +50 -0
- package/build/lib/HydrationBoundary.legacy.cjs.map +1 -0
- package/build/lib/{HydrationBoundary.esm.js → HydrationBoundary.legacy.js} +3 -2
- package/build/lib/HydrationBoundary.legacy.js.map +1 -0
- package/build/lib/QueryClientProvider.cjs +54 -0
- package/build/lib/QueryClientProvider.cjs.map +1 -0
- package/build/lib/QueryClientProvider.d.ts +2 -1
- package/build/lib/QueryClientProvider.d.ts.map +1 -0
- package/build/lib/QueryClientProvider.js +7 -29
- package/build/lib/QueryClientProvider.js.map +1 -1
- package/build/lib/QueryClientProvider.legacy.cjs +54 -0
- package/build/lib/QueryClientProvider.legacy.cjs.map +1 -0
- package/build/lib/{QueryClientProvider.esm.js → QueryClientProvider.legacy.js} +2 -1
- package/build/lib/QueryClientProvider.legacy.js.map +1 -0
- package/build/lib/QueryErrorResetBoundary.cjs +60 -0
- package/build/lib/{QueryErrorResetBoundary.mjs.map → QueryErrorResetBoundary.cjs.map} +1 -1
- package/build/lib/QueryErrorResetBoundary.d.ts +1 -0
- package/build/lib/QueryErrorResetBoundary.d.ts.map +1 -0
- package/build/lib/QueryErrorResetBoundary.js +7 -28
- package/build/lib/QueryErrorResetBoundary.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.legacy.cjs +60 -0
- package/build/lib/QueryErrorResetBoundary.legacy.cjs.map +1 -0
- package/build/lib/{QueryErrorResetBoundary.esm.js → QueryErrorResetBoundary.legacy.js} +2 -1
- package/build/lib/QueryErrorResetBoundary.legacy.js.map +1 -0
- package/build/lib/__tests__/HydrationBoundary.test.d.ts +1 -0
- package/build/lib/__tests__/HydrationBoundary.test.d.ts.map +1 -0
- package/build/lib/__tests__/QueryClientProvider.test.d.ts +1 -0
- package/build/lib/__tests__/QueryClientProvider.test.d.ts.map +1 -0
- package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts +1 -0
- package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts.map +1 -0
- package/build/lib/__tests__/ssr-hydration.test.d.ts +1 -0
- package/build/lib/__tests__/ssr-hydration.test.d.ts.map +1 -0
- package/build/lib/__tests__/ssr.test.d.ts +1 -0
- package/build/lib/__tests__/ssr.test.d.ts.map +1 -0
- package/build/lib/__tests__/suspense.test.d.ts +1 -0
- package/build/lib/__tests__/suspense.test.d.ts.map +1 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts.map +1 -0
- package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts +1 -0
- package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts.map +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts.map +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts.map +1 -0
- package/build/lib/__tests__/useMutationState.test.d.ts +1 -0
- package/build/lib/__tests__/useMutationState.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQuery.types.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.types.test.d.ts.map +1 -0
- package/build/lib/__tests__/utils.d.ts +3 -2
- package/build/lib/__tests__/utils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.cjs +51 -0
- package/build/lib/errorBoundaryUtils.cjs.map +1 -0
- package/build/lib/errorBoundaryUtils.d.ts +4 -3
- package/build/lib/errorBoundaryUtils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.js +8 -30
- package/build/lib/errorBoundaryUtils.js.map +1 -1
- package/build/lib/errorBoundaryUtils.legacy.cjs +51 -0
- package/build/lib/errorBoundaryUtils.legacy.cjs.map +1 -0
- package/build/lib/{errorBoundaryUtils.esm.js → errorBoundaryUtils.legacy.js} +6 -5
- package/build/lib/errorBoundaryUtils.legacy.js.map +1 -0
- package/build/lib/index.cjs +40 -0
- package/build/lib/index.cjs.map +1 -0
- package/build/lib/index.d.ts +2 -0
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.js +12 -37
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.legacy.cjs +40 -0
- package/build/lib/index.legacy.cjs.map +1 -0
- package/build/lib/index.legacy.js +13 -0
- package/build/lib/index.legacy.js.map +1 -0
- package/build/lib/isRestoring.cjs +31 -0
- package/build/lib/isRestoring.cjs.map +1 -0
- package/build/lib/isRestoring.d.ts +1 -0
- package/build/lib/isRestoring.d.ts.map +1 -0
- package/build/lib/isRestoring.js +5 -26
- package/build/lib/isRestoring.js.map +1 -1
- package/build/lib/isRestoring.legacy.cjs +31 -0
- package/build/lib/isRestoring.legacy.cjs.map +1 -0
- package/build/lib/{isRestoring.esm.js → isRestoring.legacy.js} +2 -1
- package/build/lib/isRestoring.legacy.js.map +1 -0
- package/build/lib/queryOptions.cjs +8 -0
- package/build/lib/queryOptions.cjs.map +1 -0
- package/build/lib/queryOptions.d.ts +11 -0
- package/build/lib/queryOptions.d.ts.map +1 -0
- package/build/lib/queryOptions.js +6 -0
- package/build/lib/queryOptions.js.map +1 -0
- package/build/lib/queryOptions.legacy.cjs +8 -0
- package/build/lib/queryOptions.legacy.cjs.map +1 -0
- package/build/lib/queryOptions.legacy.js +6 -0
- package/build/lib/queryOptions.legacy.js.map +1 -0
- package/build/lib/suspense.cjs +22 -0
- package/build/lib/suspense.cjs.map +1 -0
- package/build/lib/suspense.d.ts +3 -5
- package/build/lib/suspense.d.ts.map +1 -0
- package/build/lib/suspense.js +3 -15
- package/build/lib/suspense.js.map +1 -1
- package/build/lib/{suspense.esm.js → suspense.legacy.cjs} +8 -10
- package/build/lib/suspense.legacy.cjs.map +1 -0
- package/build/lib/{suspense.mjs → suspense.legacy.js} +3 -10
- package/build/lib/suspense.legacy.js.map +1 -0
- package/build/lib/types.d.ts +11 -10
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/useBaseQuery.cjs +80 -0
- package/build/lib/useBaseQuery.cjs.map +1 -0
- package/build/lib/useBaseQuery.d.ts +1 -0
- package/build/lib/useBaseQuery.d.ts.map +1 -0
- package/build/lib/useBaseQuery.js +30 -54
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useBaseQuery.legacy.cjs +80 -0
- package/build/lib/useBaseQuery.legacy.cjs.map +1 -0
- package/build/lib/{useBaseQuery.mjs → useBaseQuery.legacy.js} +16 -19
- package/build/lib/useBaseQuery.legacy.js.map +1 -0
- package/build/lib/useInfiniteQuery.cjs +15 -0
- package/build/lib/useInfiniteQuery.cjs.map +1 -0
- package/build/lib/useInfiniteQuery.d.ts +1 -0
- package/build/lib/useInfiniteQuery.d.ts.map +1 -0
- package/build/lib/useInfiniteQuery.js +6 -7
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.legacy.cjs +15 -0
- package/build/lib/useInfiniteQuery.legacy.cjs.map +1 -0
- package/build/lib/{useInfiniteQuery.esm.js → useInfiniteQuery.legacy.js} +3 -2
- package/build/lib/useInfiniteQuery.legacy.js.map +1 -0
- package/build/lib/useIsFetching.cjs +34 -0
- package/build/lib/useIsFetching.cjs.map +1 -0
- package/build/lib/useIsFetching.d.ts +1 -0
- package/build/lib/useIsFetching.d.ts.map +1 -0
- package/build/lib/useIsFetching.js +7 -27
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useIsFetching.legacy.cjs +34 -0
- package/build/lib/useIsFetching.legacy.cjs.map +1 -0
- package/build/lib/{useIsFetching.esm.js → useIsFetching.legacy.js} +3 -2
- package/build/lib/useIsFetching.legacy.js.map +1 -0
- package/build/lib/useMutation.cjs +54 -0
- package/build/lib/useMutation.cjs.map +1 -0
- package/build/lib/useMutation.d.ts +1 -0
- package/build/lib/useMutation.d.ts.map +1 -0
- package/build/lib/useMutation.js +12 -32
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutation.legacy.cjs +54 -0
- package/build/lib/useMutation.legacy.cjs.map +1 -0
- package/build/lib/{useMutation.esm.js → useMutation.legacy.js} +5 -4
- package/build/lib/useMutation.legacy.js.map +1 -0
- package/build/lib/useMutationState.cjs +60 -0
- package/build/lib/useMutationState.cjs.map +1 -0
- package/build/lib/useMutationState.d.ts +4 -3
- package/build/lib/useMutationState.d.ts.map +1 -0
- package/build/lib/useMutationState.js +13 -34
- package/build/lib/useMutationState.js.map +1 -1
- package/build/lib/useMutationState.legacy.cjs +60 -0
- package/build/lib/useMutationState.legacy.cjs.map +1 -0
- package/build/lib/{useMutationState.esm.js → useMutationState.legacy.js} +3 -2
- package/build/lib/useMutationState.legacy.js.map +1 -0
- package/build/lib/useQueries.cjs +99 -0
- package/build/lib/useQueries.cjs.map +1 -0
- package/build/lib/useQueries.d.ts +10 -8
- package/build/lib/useQueries.d.ts.map +1 -0
- package/build/lib/useQueries.js +52 -67
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQueries.legacy.cjs +102 -0
- package/build/lib/useQueries.legacy.cjs.map +1 -0
- package/build/lib/{useQueries.esm.js → useQueries.legacy.js} +37 -28
- package/build/lib/useQueries.legacy.js.map +1 -0
- package/build/lib/useQuery.cjs +14 -0
- package/build/lib/useQuery.cjs.map +1 -0
- package/build/lib/useQuery.d.ts +3 -8
- package/build/lib/useQuery.d.ts.map +1 -0
- package/build/lib/useQuery.js +5 -6
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/useQuery.legacy.cjs +14 -0
- package/build/lib/useQuery.legacy.cjs.map +1 -0
- package/build/lib/{useQuery.esm.js → useQuery.legacy.js} +3 -2
- package/build/lib/useQuery.legacy.js.map +1 -0
- package/build/lib/{utils.mjs → utils.cjs} +4 -2
- package/build/lib/{utils.mjs.map → utils.cjs.map} +1 -1
- package/build/lib/utils.d.ts +1 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +1 -3
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.legacy.cjs +12 -0
- package/build/lib/utils.legacy.cjs.map +1 -0
- package/build/lib/{utils.esm.js → utils.legacy.js} +1 -1
- package/build/lib/utils.legacy.js.map +1 -0
- package/package.json +25 -15
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +752 -620
- package/src/__tests__/ssr-hydration.test.tsx +2 -2
- package/src/__tests__/suspense.test.tsx +6 -88
- package/src/__tests__/useInfiniteQuery.type.test.tsx +0 -27
- package/src/__tests__/useMutation.test.tsx +4 -4
- package/src/__tests__/useMutationState.test.tsx +23 -0
- package/src/__tests__/useQueries.test.tsx +206 -83
- package/src/__tests__/useQuery.test.tsx +246 -338
- package/src/__tests__/useQuery.types.test.tsx +21 -0
- package/src/errorBoundaryUtils.ts +6 -5
- package/src/index.ts +1 -0
- package/src/queryOptions.ts +42 -0
- package/src/suspense.ts +9 -15
- package/src/useBaseQuery.ts +12 -23
- package/src/useInfiniteQuery.ts +1 -0
- package/src/useIsFetching.ts +1 -0
- package/src/useMutation.ts +2 -1
- package/src/useMutationState.ts +4 -3
- package/src/useQueries.ts +44 -26
- package/src/useQuery.ts +5 -17
- package/build/lib/HydrationBoundary.esm.js.map +0 -1
- package/build/lib/HydrationBoundary.mjs +0 -28
- package/build/lib/QueryClientProvider.esm.js.map +0 -1
- package/build/lib/QueryClientProvider.mjs +0 -30
- package/build/lib/QueryClientProvider.mjs.map +0 -1
- package/build/lib/QueryErrorResetBoundary.esm.js.map +0 -1
- package/build/lib/QueryErrorResetBoundary.mjs +0 -37
- package/build/lib/errorBoundaryUtils.esm.js.map +0 -1
- package/build/lib/errorBoundaryUtils.mjs +0 -27
- package/build/lib/errorBoundaryUtils.mjs.map +0 -1
- package/build/lib/index.esm.js +0 -12
- package/build/lib/index.esm.js.map +0 -1
- package/build/lib/index.mjs +0 -12
- package/build/lib/index.mjs.map +0 -1
- package/build/lib/isRestoring.esm.js.map +0 -1
- package/build/lib/isRestoring.mjs +0 -8
- package/build/lib/isRestoring.mjs.map +0 -1
- package/build/lib/suspense.esm.js.map +0 -1
- package/build/lib/suspense.mjs.map +0 -1
- package/build/lib/useBaseQuery.esm.js +0 -62
- package/build/lib/useBaseQuery.esm.js.map +0 -1
- package/build/lib/useBaseQuery.mjs.map +0 -1
- package/build/lib/useInfiniteQuery.esm.js.map +0 -1
- package/build/lib/useInfiniteQuery.mjs +0 -12
- package/build/lib/useInfiniteQuery.mjs.map +0 -1
- package/build/lib/useIsFetching.esm.js.map +0 -1
- package/build/lib/useIsFetching.mjs +0 -12
- package/build/lib/useIsFetching.mjs.map +0 -1
- package/build/lib/useMutation.esm.js.map +0 -1
- package/build/lib/useMutation.mjs +0 -32
- package/build/lib/useMutation.mjs.map +0 -1
- package/build/lib/useMutationState.esm.js.map +0 -1
- package/build/lib/useMutationState.mjs +0 -37
- package/build/lib/useMutationState.mjs.map +0 -1
- package/build/lib/useQueries.esm.js.map +0 -1
- package/build/lib/useQueries.mjs +0 -69
- package/build/lib/useQueries.mjs.map +0 -1
- package/build/lib/useQuery.esm.js.map +0 -1
- package/build/lib/useQuery.mjs +0 -11
- package/build/lib/useQuery.mjs.map +0 -1
- package/build/lib/utils.esm.js.map +0 -1
- package/build/umd/index.development.js +0 -3040
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -2
- package/build/umd/index.production.js.map +0 -1
- /package/src/{isRestoring.tsx → isRestoring.ts} +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
'use client'
|
|
1
2
|
import type {
|
|
2
3
|
DefaultedQueryObserverOptions,
|
|
3
4
|
Query,
|
|
4
5
|
QueryKey,
|
|
5
6
|
QueryObserverResult,
|
|
6
|
-
|
|
7
|
+
ThrowOnError,
|
|
7
8
|
} from '@tanstack/query-core'
|
|
8
9
|
import type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'
|
|
9
10
|
import * as React from 'react'
|
|
@@ -25,7 +26,7 @@ export const ensurePreventErrorBoundaryRetry = <
|
|
|
25
26
|
>,
|
|
26
27
|
errorResetBoundary: QueryErrorResetBoundaryValue,
|
|
27
28
|
) => {
|
|
28
|
-
if (options.suspense || options.
|
|
29
|
+
if (options.suspense || options.throwOnError) {
|
|
29
30
|
// Prevent retrying failed query if the error boundary has not been reset yet
|
|
30
31
|
if (!errorResetBoundary.isReset()) {
|
|
31
32
|
options.retryOnMount = false
|
|
@@ -50,18 +51,18 @@ export const getHasError = <
|
|
|
50
51
|
>({
|
|
51
52
|
result,
|
|
52
53
|
errorResetBoundary,
|
|
53
|
-
|
|
54
|
+
throwOnError,
|
|
54
55
|
query,
|
|
55
56
|
}: {
|
|
56
57
|
result: QueryObserverResult<TData, TError>
|
|
57
58
|
errorResetBoundary: QueryErrorResetBoundaryValue
|
|
58
|
-
|
|
59
|
+
throwOnError: ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey>
|
|
59
60
|
query: Query<TQueryFnData, TError, TQueryData, TQueryKey>
|
|
60
61
|
}) => {
|
|
61
62
|
return (
|
|
62
63
|
result.isError &&
|
|
63
64
|
!errorResetBoundary.isReset() &&
|
|
64
65
|
!result.isFetching &&
|
|
65
|
-
shouldThrowError(
|
|
66
|
+
shouldThrowError(throwOnError, [result.error, query])
|
|
66
67
|
)
|
|
67
68
|
}
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './types'
|
|
|
8
8
|
export { useQueries } from './useQueries'
|
|
9
9
|
export type { QueriesResults, QueriesOptions } from './useQueries'
|
|
10
10
|
export { useQuery } from './useQuery'
|
|
11
|
+
export { queryOptions } from './queryOptions'
|
|
11
12
|
export {
|
|
12
13
|
QueryClientContext,
|
|
13
14
|
QueryClientProvider,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { DefaultError, QueryKey } from '@tanstack/query-core'
|
|
2
|
+
import type { UseQueryOptions } from './types'
|
|
3
|
+
|
|
4
|
+
export type UndefinedInitialDataOptions<
|
|
5
|
+
TQueryFnData = unknown,
|
|
6
|
+
TError = DefaultError,
|
|
7
|
+
TData = TQueryFnData,
|
|
8
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
9
|
+
> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
10
|
+
initialData?: undefined
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type DefinedInitialDataOptions<
|
|
14
|
+
TQueryFnData = unknown,
|
|
15
|
+
TError = DefaultError,
|
|
16
|
+
TData = TQueryFnData,
|
|
17
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
18
|
+
> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
19
|
+
initialData: TQueryFnData | (() => TQueryFnData)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function queryOptions<
|
|
23
|
+
TQueryFnData = unknown,
|
|
24
|
+
TError = DefaultError,
|
|
25
|
+
TData = TQueryFnData,
|
|
26
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
27
|
+
>(
|
|
28
|
+
options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
29
|
+
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
|
|
30
|
+
|
|
31
|
+
export function queryOptions<
|
|
32
|
+
TQueryFnData = unknown,
|
|
33
|
+
TError = DefaultError,
|
|
34
|
+
TData = TQueryFnData,
|
|
35
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
36
|
+
>(
|
|
37
|
+
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
38
|
+
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
|
|
39
|
+
|
|
40
|
+
export function queryOptions(options: unknown) {
|
|
41
|
+
return options
|
|
42
|
+
}
|
package/src/suspense.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
DefaultedQueryObserverOptions,
|
|
3
|
+
QueryObserverResult,
|
|
4
|
+
QueryKey,
|
|
5
|
+
QueryObserver,
|
|
6
|
+
} from '@tanstack/query-core'
|
|
3
7
|
import type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'
|
|
4
|
-
import type { QueryObserverResult } from '@tanstack/query-core'
|
|
5
|
-
import type { QueryKey } from '@tanstack/query-core'
|
|
6
8
|
|
|
7
9
|
export const ensureStaleTime = (
|
|
8
10
|
defaultedOptions: DefaultedQueryObserverOptions<any, any, any, any, any>,
|
|
@@ -46,14 +48,6 @@ export const fetchOptimistic = <
|
|
|
46
48
|
observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
|
|
47
49
|
errorResetBoundary: QueryErrorResetBoundaryValue,
|
|
48
50
|
) =>
|
|
49
|
-
observer
|
|
50
|
-
.
|
|
51
|
-
|
|
52
|
-
defaultedOptions.onSuccess?.(data as TData)
|
|
53
|
-
defaultedOptions.onSettled?.(data, null)
|
|
54
|
-
})
|
|
55
|
-
.catch((error) => {
|
|
56
|
-
errorResetBoundary.clearReset()
|
|
57
|
-
defaultedOptions.onError?.(error)
|
|
58
|
-
defaultedOptions.onSettled?.(undefined, error)
|
|
59
|
-
})
|
|
51
|
+
observer.fetchOptimistic(defaultedOptions).catch(() => {
|
|
52
|
+
errorResetBoundary.clearReset()
|
|
53
|
+
})
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client'
|
|
1
2
|
import * as React from 'react'
|
|
2
3
|
|
|
3
4
|
import type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core'
|
|
@@ -40,25 +41,6 @@ export function useBaseQuery<
|
|
|
40
41
|
? 'isRestoring'
|
|
41
42
|
: 'optimistic'
|
|
42
43
|
|
|
43
|
-
// Include callbacks in batch renders
|
|
44
|
-
if (defaultedOptions.onError) {
|
|
45
|
-
defaultedOptions.onError = notifyManager.batchCalls(
|
|
46
|
-
defaultedOptions.onError,
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (defaultedOptions.onSuccess) {
|
|
51
|
-
defaultedOptions.onSuccess = notifyManager.batchCalls(
|
|
52
|
-
defaultedOptions.onSuccess,
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (defaultedOptions.onSettled) {
|
|
57
|
-
defaultedOptions.onSettled = notifyManager.batchCalls(
|
|
58
|
-
defaultedOptions.onSettled,
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
44
|
ensureStaleTime(defaultedOptions)
|
|
63
45
|
ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary)
|
|
64
46
|
|
|
@@ -76,10 +58,17 @@ export function useBaseQuery<
|
|
|
76
58
|
|
|
77
59
|
React.useSyncExternalStore(
|
|
78
60
|
React.useCallback(
|
|
79
|
-
(onStoreChange) =>
|
|
80
|
-
isRestoring
|
|
61
|
+
(onStoreChange) => {
|
|
62
|
+
const unsubscribe = isRestoring
|
|
81
63
|
? () => undefined
|
|
82
|
-
: observer.subscribe(notifyManager.batchCalls(onStoreChange))
|
|
64
|
+
: observer.subscribe(notifyManager.batchCalls(onStoreChange))
|
|
65
|
+
|
|
66
|
+
// Update result to make sure we did not miss any query updates
|
|
67
|
+
// between creating the observer and subscribing to it.
|
|
68
|
+
observer.updateResult()
|
|
69
|
+
|
|
70
|
+
return unsubscribe
|
|
71
|
+
},
|
|
83
72
|
[observer, isRestoring],
|
|
84
73
|
),
|
|
85
74
|
() => observer.getCurrentResult(),
|
|
@@ -102,7 +91,7 @@ export function useBaseQuery<
|
|
|
102
91
|
getHasError({
|
|
103
92
|
result,
|
|
104
93
|
errorResetBoundary,
|
|
105
|
-
|
|
94
|
+
throwOnError: defaultedOptions.throwOnError,
|
|
106
95
|
query: observer.getCurrentQuery(),
|
|
107
96
|
})
|
|
108
97
|
) {
|
package/src/useInfiniteQuery.ts
CHANGED
package/src/useIsFetching.ts
CHANGED
package/src/useMutation.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client'
|
|
1
2
|
import * as React from 'react'
|
|
2
3
|
import type { QueryClient, DefaultError } from '@tanstack/query-core'
|
|
3
4
|
import { notifyManager, MutationObserver } from '@tanstack/query-core'
|
|
@@ -55,7 +56,7 @@ export function useMutation<
|
|
|
55
56
|
|
|
56
57
|
if (
|
|
57
58
|
result.error &&
|
|
58
|
-
shouldThrowError(observer.options.
|
|
59
|
+
shouldThrowError(observer.options.throwOnError, [result.error])
|
|
59
60
|
) {
|
|
60
61
|
throw result.error
|
|
61
62
|
}
|
package/src/useMutationState.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client'
|
|
1
2
|
import * as React from 'react'
|
|
2
3
|
|
|
3
4
|
import type {
|
|
@@ -6,10 +7,10 @@ import type {
|
|
|
6
7
|
Mutation,
|
|
7
8
|
MutationCache,
|
|
8
9
|
DefaultError,
|
|
10
|
+
MutationState,
|
|
9
11
|
} from '@tanstack/query-core'
|
|
10
12
|
import { notifyManager, replaceEqualDeep } from '@tanstack/query-core'
|
|
11
13
|
import { useQueryClient } from './QueryClientProvider'
|
|
12
|
-
import type { MutationState } from '@tanstack/query-core/build/lib/mutation'
|
|
13
14
|
|
|
14
15
|
export function useIsMutating(
|
|
15
16
|
filters?: MutationFilters,
|
|
@@ -22,7 +23,7 @@ export function useIsMutating(
|
|
|
22
23
|
).length
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
type MutationStateOptions<TResult> = {
|
|
26
|
+
type MutationStateOptions<TResult = MutationState> = {
|
|
26
27
|
filters?: MutationFilters
|
|
27
28
|
select?: (
|
|
28
29
|
mutation: Mutation<unknown, DefaultError, unknown, unknown>,
|
|
@@ -45,7 +46,7 @@ function getResult<TResult = MutationState>(
|
|
|
45
46
|
)
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
export function useMutationState<TResult =
|
|
49
|
+
export function useMutationState<TResult = MutationState>(
|
|
49
50
|
options: MutationStateOptions<TResult> = {},
|
|
50
51
|
queryClient?: QueryClient,
|
|
51
52
|
): Array<TResult> {
|
package/src/useQueries.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client'
|
|
1
2
|
import * as React from 'react'
|
|
2
3
|
|
|
3
4
|
import type {
|
|
@@ -6,6 +7,7 @@ import type {
|
|
|
6
7
|
QueriesPlaceholderDataFunction,
|
|
7
8
|
QueryClient,
|
|
8
9
|
DefaultError,
|
|
10
|
+
QueriesObserverOptions,
|
|
9
11
|
} from '@tanstack/query-core'
|
|
10
12
|
import { notifyManager, QueriesObserver } from '@tanstack/query-core'
|
|
11
13
|
import { useQueryClient } from './QueryClientProvider'
|
|
@@ -155,21 +157,27 @@ export type QueriesResults<
|
|
|
155
157
|
: // Fallback
|
|
156
158
|
UseQueryResult[]
|
|
157
159
|
|
|
158
|
-
export function useQueries<
|
|
160
|
+
export function useQueries<
|
|
161
|
+
T extends any[],
|
|
162
|
+
TCombinedResult = QueriesResults<T>,
|
|
163
|
+
>(
|
|
159
164
|
{
|
|
160
165
|
queries,
|
|
166
|
+
...options
|
|
161
167
|
}: {
|
|
162
168
|
queries: readonly [...QueriesOptions<T>]
|
|
169
|
+
combine?: (result: QueriesResults<T>) => TCombinedResult
|
|
163
170
|
},
|
|
164
171
|
queryClient?: QueryClient,
|
|
165
|
-
):
|
|
172
|
+
): TCombinedResult {
|
|
166
173
|
const client = useQueryClient(queryClient)
|
|
167
174
|
const isRestoring = useIsRestoring()
|
|
175
|
+
const errorResetBoundary = useQueryErrorResetBoundary()
|
|
168
176
|
|
|
169
177
|
const defaultedQueries = React.useMemo(
|
|
170
178
|
() =>
|
|
171
|
-
queries.map((
|
|
172
|
-
const defaultedOptions = client.defaultQueryOptions(
|
|
179
|
+
queries.map((opts) => {
|
|
180
|
+
const defaultedOptions = client.defaultQueryOptions(opts)
|
|
173
181
|
|
|
174
182
|
// Make sure the results are already in fetching state before subscribing or updating options
|
|
175
183
|
defaultedOptions._optimisticResults = isRestoring
|
|
@@ -181,11 +189,24 @@ export function useQueries<T extends any[]>(
|
|
|
181
189
|
[queries, client, isRestoring],
|
|
182
190
|
)
|
|
183
191
|
|
|
192
|
+
defaultedQueries.forEach((query) => {
|
|
193
|
+
ensureStaleTime(query)
|
|
194
|
+
ensurePreventErrorBoundaryRetry(query, errorResetBoundary)
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
useClearResetErrorBoundary(errorResetBoundary)
|
|
198
|
+
|
|
184
199
|
const [observer] = React.useState(
|
|
185
|
-
() =>
|
|
200
|
+
() =>
|
|
201
|
+
new QueriesObserver<TCombinedResult>(
|
|
202
|
+
client,
|
|
203
|
+
defaultedQueries,
|
|
204
|
+
options as QueriesObserverOptions<TCombinedResult>,
|
|
205
|
+
),
|
|
186
206
|
)
|
|
187
207
|
|
|
188
|
-
const optimisticResult =
|
|
208
|
+
const [optimisticResult, getCombinedResult, trackResult] =
|
|
209
|
+
observer.getOptimisticResult(defaultedQueries)
|
|
189
210
|
|
|
190
211
|
React.useSyncExternalStore(
|
|
191
212
|
React.useCallback(
|
|
@@ -202,17 +223,14 @@ export function useQueries<T extends any[]>(
|
|
|
202
223
|
React.useEffect(() => {
|
|
203
224
|
// Do not notify on updates because of changes in the options because
|
|
204
225
|
// these changes should already be reflected in the optimistic result.
|
|
205
|
-
observer.setQueries(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
useClearResetErrorBoundary(errorResetBoundary)
|
|
226
|
+
observer.setQueries(
|
|
227
|
+
defaultedQueries,
|
|
228
|
+
options as QueriesObserverOptions<TCombinedResult>,
|
|
229
|
+
{
|
|
230
|
+
listeners: false,
|
|
231
|
+
},
|
|
232
|
+
)
|
|
233
|
+
}, [defaultedQueries, options, observer])
|
|
216
234
|
|
|
217
235
|
const shouldAtLeastOneSuspend = optimisticResult.some((result, index) =>
|
|
218
236
|
shouldSuspend(defaultedQueries[index], result, isRestoring),
|
|
@@ -220,14 +238,14 @@ export function useQueries<T extends any[]>(
|
|
|
220
238
|
|
|
221
239
|
const suspensePromises = shouldAtLeastOneSuspend
|
|
222
240
|
? optimisticResult.flatMap((result, index) => {
|
|
223
|
-
const
|
|
241
|
+
const opts = defaultedQueries[index]
|
|
224
242
|
const queryObserver = observer.getObservers()[index]
|
|
225
243
|
|
|
226
|
-
if (
|
|
227
|
-
if (shouldSuspend(
|
|
228
|
-
return fetchOptimistic(
|
|
244
|
+
if (opts && queryObserver) {
|
|
245
|
+
if (shouldSuspend(opts, result, isRestoring)) {
|
|
246
|
+
return fetchOptimistic(opts, queryObserver, errorResetBoundary)
|
|
229
247
|
} else if (willFetch(result, isRestoring)) {
|
|
230
|
-
void fetchOptimistic(
|
|
248
|
+
void fetchOptimistic(opts, queryObserver, errorResetBoundary)
|
|
231
249
|
}
|
|
232
250
|
}
|
|
233
251
|
return []
|
|
@@ -237,14 +255,14 @@ export function useQueries<T extends any[]>(
|
|
|
237
255
|
if (suspensePromises.length > 0) {
|
|
238
256
|
throw Promise.all(suspensePromises)
|
|
239
257
|
}
|
|
240
|
-
|
|
258
|
+
const observerQueries = observer.getQueries()
|
|
241
259
|
const firstSingleResultWhichShouldThrow = optimisticResult.find(
|
|
242
260
|
(result, index) =>
|
|
243
261
|
getHasError({
|
|
244
262
|
result,
|
|
245
263
|
errorResetBoundary,
|
|
246
|
-
|
|
247
|
-
query:
|
|
264
|
+
throwOnError: defaultedQueries[index]?.throwOnError ?? false,
|
|
265
|
+
query: observerQueries[index]!,
|
|
248
266
|
}),
|
|
249
267
|
)
|
|
250
268
|
|
|
@@ -252,5 +270,5 @@ export function useQueries<T extends any[]>(
|
|
|
252
270
|
throw firstSingleResultWhichShouldThrow.error
|
|
253
271
|
}
|
|
254
272
|
|
|
255
|
-
return
|
|
273
|
+
return getCombinedResult(trackResult())
|
|
256
274
|
}
|
package/src/useQuery.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client'
|
|
1
2
|
import type { QueryClient, QueryKey, DefaultError } from '@tanstack/query-core'
|
|
2
3
|
import { QueryObserver } from '@tanstack/query-core'
|
|
3
4
|
import type {
|
|
@@ -6,25 +7,12 @@ import type {
|
|
|
6
7
|
UseQueryResult,
|
|
7
8
|
} from './types'
|
|
8
9
|
import { useBaseQuery } from './useBaseQuery'
|
|
10
|
+
import type {
|
|
11
|
+
DefinedInitialDataOptions,
|
|
12
|
+
UndefinedInitialDataOptions,
|
|
13
|
+
} from './queryOptions'
|
|
9
14
|
|
|
10
15
|
// HOOK
|
|
11
|
-
type UndefinedInitialDataOptions<
|
|
12
|
-
TQueryFnData = unknown,
|
|
13
|
-
TError = DefaultError,
|
|
14
|
-
TData = TQueryFnData,
|
|
15
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
16
|
-
> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
17
|
-
initialData?: undefined
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type DefinedInitialDataOptions<
|
|
21
|
-
TQueryFnData = unknown,
|
|
22
|
-
TError = DefaultError,
|
|
23
|
-
TData = TQueryFnData,
|
|
24
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
25
|
-
> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
26
|
-
initialData: TQueryFnData | (() => TQueryFnData)
|
|
27
|
-
}
|
|
28
16
|
|
|
29
17
|
export function useQuery<
|
|
30
18
|
TQueryFnData = unknown,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HydrationBoundary.esm.js","sources":["../../src/HydrationBoundary.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { HydrateOptions, QueryClient } from '@tanstack/query-core'\nimport { hydrate } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nexport interface HydrationBoundaryProps {\n state?: unknown\n options?: HydrateOptions\n children?: React.ReactNode\n queryClient?: QueryClient\n}\n\nexport const HydrationBoundary = ({\n children,\n options = {},\n state,\n queryClient,\n}: HydrationBoundaryProps) => {\n const client = useQueryClient(queryClient)\n\n const optionsRef = React.useRef(options)\n optionsRef.current = options\n\n // Running hydrate again with the same queries is safe,\n // it wont overwrite or initialize existing queries,\n // relying on useMemo here is only a performance optimization.\n // hydrate can and should be run *during* render here for SSR to work properly\n React.useMemo(() => {\n if (state) {\n hydrate(client, state, optionsRef.current)\n }\n }, [client, state])\n\n return children as React.ReactElement\n}\n"],"names":["HydrationBoundary","children","options","state","queryClient","client","useQueryClient","optionsRef","React","useRef","current","useMemo","hydrate"],"mappings":";;;;AAcO,MAAMA,iBAAiB,GAAG,CAAC;EAChCC,QAAQ;EACRC,OAAO,GAAG,EAAE;EACZC,KAAK;AACLC,EAAAA,WAAAA;AACsB,CAAC,KAAK;AAC5B,EAAA,MAAMC,MAAM,GAAGC,cAAc,CAACF,WAAW,CAAC,CAAA;AAE1C,EAAA,MAAMG,UAAU,GAAGC,KAAK,CAACC,MAAM,CAACP,OAAO,CAAC,CAAA;EACxCK,UAAU,CAACG,OAAO,GAAGR,OAAO,CAAA;;AAE5B;AACA;AACA;AACA;EACAM,KAAK,CAACG,OAAO,CAAC,MAAM;AAClB,IAAA,IAAIR,KAAK,EAAE;MACTS,OAAO,CAACP,MAAM,EAAEF,KAAK,EAAEI,UAAU,CAACG,OAAO,CAAC,CAAA;AAC5C,KAAA;AACF,GAAC,EAAE,CAACL,MAAM,EAAEF,KAAK,CAAC,CAAC,CAAA;AAEnB,EAAA,OAAOF,QAAQ,CAAA;AACjB;;;;"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { hydrate } from '@tanstack/query-core';
|
|
3
|
-
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
4
|
-
|
|
5
|
-
const HydrationBoundary = ({
|
|
6
|
-
children,
|
|
7
|
-
options = {},
|
|
8
|
-
state,
|
|
9
|
-
queryClient
|
|
10
|
-
}) => {
|
|
11
|
-
const client = useQueryClient(queryClient);
|
|
12
|
-
const optionsRef = React.useRef(options);
|
|
13
|
-
optionsRef.current = options;
|
|
14
|
-
|
|
15
|
-
// Running hydrate again with the same queries is safe,
|
|
16
|
-
// it wont overwrite or initialize existing queries,
|
|
17
|
-
// relying on useMemo here is only a performance optimization.
|
|
18
|
-
// hydrate can and should be run *during* render here for SSR to work properly
|
|
19
|
-
React.useMemo(() => {
|
|
20
|
-
if (state) {
|
|
21
|
-
hydrate(client, state, optionsRef.current);
|
|
22
|
-
}
|
|
23
|
-
}, [client, state]);
|
|
24
|
-
return children;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export { HydrationBoundary };
|
|
28
|
-
//# sourceMappingURL=HydrationBoundary.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QueryClientProvider.esm.js","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { QueryClient } from '@tanstack/query-core'\n\nexport const QueryClientContext = React.createContext<QueryClient | undefined>(\n undefined,\n)\n\nexport const useQueryClient = (queryClient?: QueryClient) => {\n const client = React.useContext(QueryClientContext)\n\n if (queryClient) {\n return queryClient\n }\n\n if (!client) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return client\n}\n\nexport type QueryClientProviderProps = {\n client: QueryClient\n children?: React.ReactNode\n}\n\nexport const QueryClientProvider = ({\n client,\n children,\n}: QueryClientProviderProps): JSX.Element => {\n React.useEffect(() => {\n client.mount()\n return () => {\n client.unmount()\n }\n }, [client])\n\n return (\n <QueryClientContext.Provider value={client}>\n {children}\n </QueryClientContext.Provider>\n )\n}\n"],"names":["QueryClientContext","React","createContext","undefined","useQueryClient","queryClient","client","useContext","Error","QueryClientProvider","children","useEffect","mount","unmount"],"mappings":";;AAKO,MAAMA,kBAAkB,gBAAGC,KAAK,CAACC,aAAa,CACnDC,SAAS,EACV;AAEYC,MAAAA,cAAc,GAAIC,WAAyB,IAAK;AAC3D,EAAA,MAAMC,MAAM,GAAGL,KAAK,CAACM,UAAU,CAACP,kBAAkB,CAAC,CAAA;AAEnD,EAAA,IAAIK,WAAW,EAAE;AACf,IAAA,OAAOA,WAAW,CAAA;AACpB,GAAA;EAEA,IAAI,CAACC,MAAM,EAAE;AACX,IAAA,MAAM,IAAIE,KAAK,CAAC,wDAAwD,CAAC,CAAA;AAC3E,GAAA;AAEA,EAAA,OAAOF,MAAM,CAAA;AACf,EAAC;AAOM,MAAMG,mBAAmB,GAAG,CAAC;EAClCH,MAAM;AACNI,EAAAA,QAAAA;AACwB,CAAC,KAAkB;EAC3CT,KAAK,CAACU,SAAS,CAAC,MAAM;IACpBL,MAAM,CAACM,KAAK,EAAE,CAAA;AACd,IAAA,OAAO,MAAM;MACXN,MAAM,CAACO,OAAO,EAAE,CAAA;KACjB,CAAA;AACH,GAAC,EAAE,CAACP,MAAM,CAAC,CAAC,CAAA;EAEZ,oBACE,KAAA,CAAA,aAAA,CAAC,kBAAkB,CAAC,QAAQ,EAAA;AAAC,IAAA,KAAK,EAAEA,MAAAA;AAAO,GAAA,EACxCI,QAAQ,CACmB,CAAA;AAElC;;;;"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
const QueryClientContext = /*#__PURE__*/React.createContext(undefined);
|
|
4
|
-
const useQueryClient = queryClient => {
|
|
5
|
-
const client = React.useContext(QueryClientContext);
|
|
6
|
-
if (queryClient) {
|
|
7
|
-
return queryClient;
|
|
8
|
-
}
|
|
9
|
-
if (!client) {
|
|
10
|
-
throw new Error('No QueryClient set, use QueryClientProvider to set one');
|
|
11
|
-
}
|
|
12
|
-
return client;
|
|
13
|
-
};
|
|
14
|
-
const QueryClientProvider = ({
|
|
15
|
-
client,
|
|
16
|
-
children
|
|
17
|
-
}) => {
|
|
18
|
-
React.useEffect(() => {
|
|
19
|
-
client.mount();
|
|
20
|
-
return () => {
|
|
21
|
-
client.unmount();
|
|
22
|
-
};
|
|
23
|
-
}, [client]);
|
|
24
|
-
return /*#__PURE__*/React.createElement(QueryClientContext.Provider, {
|
|
25
|
-
value: client
|
|
26
|
-
}, children);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export { QueryClientContext, QueryClientProvider, useQueryClient };
|
|
30
|
-
//# sourceMappingURL=QueryClientProvider.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QueryClientProvider.mjs","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { QueryClient } from '@tanstack/query-core'\n\nexport const QueryClientContext = React.createContext<QueryClient | undefined>(\n undefined,\n)\n\nexport const useQueryClient = (queryClient?: QueryClient) => {\n const client = React.useContext(QueryClientContext)\n\n if (queryClient) {\n return queryClient\n }\n\n if (!client) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return client\n}\n\nexport type QueryClientProviderProps = {\n client: QueryClient\n children?: React.ReactNode\n}\n\nexport const QueryClientProvider = ({\n client,\n children,\n}: QueryClientProviderProps): JSX.Element => {\n React.useEffect(() => {\n client.mount()\n return () => {\n client.unmount()\n }\n }, [client])\n\n return (\n <QueryClientContext.Provider value={client}>\n {children}\n </QueryClientContext.Provider>\n )\n}\n"],"names":["QueryClientContext","React","createContext","undefined","useQueryClient","queryClient","client","useContext","Error","QueryClientProvider","children","useEffect","mount","unmount"],"mappings":";;AAKO,MAAMA,kBAAkB,gBAAGC,KAAK,CAACC,aAAa,CACnDC,SAAS,EACV;AAEYC,MAAAA,cAAc,GAAIC,WAAyB,IAAK;AAC3D,EAAA,MAAMC,MAAM,GAAGL,KAAK,CAACM,UAAU,CAACP,kBAAkB,CAAC,CAAA;AAEnD,EAAA,IAAIK,WAAW,EAAE;AACf,IAAA,OAAOA,WAAW,CAAA;AACpB,GAAA;EAEA,IAAI,CAACC,MAAM,EAAE;AACX,IAAA,MAAM,IAAIE,KAAK,CAAC,wDAAwD,CAAC,CAAA;AAC3E,GAAA;AAEA,EAAA,OAAOF,MAAM,CAAA;AACf,EAAC;AAOM,MAAMG,mBAAmB,GAAG,CAAC;EAClCH,MAAM;AACNI,EAAAA,QAAAA;AACwB,CAAC,KAAkB;EAC3CT,KAAK,CAACU,SAAS,CAAC,MAAM;IACpBL,MAAM,CAACM,KAAK,EAAE,CAAA;AACd,IAAA,OAAO,MAAM;MACXN,MAAM,CAACO,OAAO,EAAE,CAAA;KACjB,CAAA;AACH,GAAC,EAAE,CAACP,MAAM,CAAC,CAAC,CAAA;EAEZ,oBACE,KAAA,CAAA,aAAA,CAAC,kBAAkB,CAAC,QAAQ,EAAA;AAAC,IAAA,KAAK,EAAEA,MAAAA;AAAO,GAAA,EACxCI,QAAQ,CACmB,CAAA;AAElC;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorResetBoundary.esm.js","sources":["../../src/QueryErrorResetBoundary.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\n// CONTEXT\n\nexport interface QueryErrorResetBoundaryValue {\n clearReset: () => void\n isReset: () => boolean\n reset: () => void\n}\n\nfunction createValue(): QueryErrorResetBoundaryValue {\n let isReset = false\n return {\n clearReset: () => {\n isReset = false\n },\n reset: () => {\n isReset = true\n },\n isReset: () => {\n return isReset\n },\n }\n}\n\nconst QueryErrorResetBoundaryContext = React.createContext(createValue())\n\n// HOOK\n\nexport const useQueryErrorResetBoundary = () =>\n React.useContext(QueryErrorResetBoundaryContext)\n\n// COMPONENT\n\nexport interface QueryErrorResetBoundaryProps {\n children:\n | ((value: QueryErrorResetBoundaryValue) => React.ReactNode)\n | React.ReactNode\n}\n\nexport const QueryErrorResetBoundary = ({\n children,\n}: QueryErrorResetBoundaryProps) => {\n const [value] = React.useState(() => createValue())\n return (\n <QueryErrorResetBoundaryContext.Provider value={value}>\n {typeof children === 'function'\n ? (children as Function)(value)\n : children}\n </QueryErrorResetBoundaryContext.Provider>\n )\n}\n"],"names":["createValue","isReset","clearReset","reset","QueryErrorResetBoundaryContext","React","createContext","useQueryErrorResetBoundary","useContext","QueryErrorResetBoundary","children","value","useState"],"mappings":";;AAGA;;AAQA,SAASA,WAAW,GAAiC;EACnD,IAAIC,OAAO,GAAG,KAAK,CAAA;EACnB,OAAO;AACLC,IAAAA,UAAU,EAAE,MAAM;AAChBD,MAAAA,OAAO,GAAG,KAAK,CAAA;KAChB;AACDE,IAAAA,KAAK,EAAE,MAAM;AACXF,MAAAA,OAAO,GAAG,IAAI,CAAA;KACf;AACDA,IAAAA,OAAO,EAAE,MAAM;AACb,MAAA,OAAOA,OAAO,CAAA;AAChB,KAAA;GACD,CAAA;AACH,CAAA;AAEA,MAAMG,8BAA8B,gBAAGC,KAAK,CAACC,aAAa,CAACN,WAAW,EAAE,CAAC,CAAA;;AAEzE;;AAEO,MAAMO,0BAA0B,GAAG,MACxCF,KAAK,CAACG,UAAU,CAACJ,8BAA8B,EAAC;;AAElD;;AAQO,MAAMK,uBAAuB,GAAG,CAAC;AACtCC,EAAAA,QAAAA;AAC4B,CAAC,KAAK;EAClC,MAAM,CAACC,KAAK,CAAC,GAAGN,KAAK,CAACO,QAAQ,CAAC,MAAMZ,WAAW,EAAE,CAAC,CAAA;EACnD,oBACE,KAAA,CAAA,aAAA,CAAC,8BAA8B,CAAC,QAAQ,EAAA;AAAC,IAAA,KAAK,EAAEW,KAAAA;GAC7C,EAAA,OAAOD,QAAQ,KAAK,UAAU,GAC1BA,QAAQ,CAAcC,KAAK,CAAC,GAC7BD,QAAQ,CAC4B,CAAA;AAE9C;;;;"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
// CONTEXT
|
|
4
|
-
|
|
5
|
-
function createValue() {
|
|
6
|
-
let isReset = false;
|
|
7
|
-
return {
|
|
8
|
-
clearReset: () => {
|
|
9
|
-
isReset = false;
|
|
10
|
-
},
|
|
11
|
-
reset: () => {
|
|
12
|
-
isReset = true;
|
|
13
|
-
},
|
|
14
|
-
isReset: () => {
|
|
15
|
-
return isReset;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
const QueryErrorResetBoundaryContext = /*#__PURE__*/React.createContext(createValue());
|
|
20
|
-
|
|
21
|
-
// HOOK
|
|
22
|
-
|
|
23
|
-
const useQueryErrorResetBoundary = () => React.useContext(QueryErrorResetBoundaryContext);
|
|
24
|
-
|
|
25
|
-
// COMPONENT
|
|
26
|
-
|
|
27
|
-
const QueryErrorResetBoundary = ({
|
|
28
|
-
children
|
|
29
|
-
}) => {
|
|
30
|
-
const [value] = React.useState(() => createValue());
|
|
31
|
-
return /*#__PURE__*/React.createElement(QueryErrorResetBoundaryContext.Provider, {
|
|
32
|
-
value: value
|
|
33
|
-
}, typeof children === 'function' ? children(value) : children);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export { QueryErrorResetBoundary, useQueryErrorResetBoundary };
|
|
37
|
-
//# sourceMappingURL=QueryErrorResetBoundary.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errorBoundaryUtils.esm.js","sources":["../../src/errorBoundaryUtils.ts"],"sourcesContent":["import type {\n DefaultedQueryObserverOptions,\n Query,\n QueryKey,\n QueryObserverResult,\n ThrowErrors,\n} from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\nimport * as React from 'react'\nimport { shouldThrowError } from './utils'\n\nexport const ensurePreventErrorBoundaryRetry = <\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n if (options.suspense || options.throwErrors) {\n // Prevent retrying failed query if the error boundary has not been reset yet\n if (!errorResetBoundary.isReset()) {\n options.retryOnMount = false\n }\n }\n}\n\nexport const useClearResetErrorBoundary = (\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n React.useEffect(() => {\n errorResetBoundary.clearReset()\n }, [errorResetBoundary])\n}\n\nexport const getHasError = <\n TData,\n TError,\n TQueryFnData,\n TQueryData,\n TQueryKey extends QueryKey,\n>({\n result,\n errorResetBoundary,\n throwErrors,\n query,\n}: {\n result: QueryObserverResult<TData, TError>\n errorResetBoundary: QueryErrorResetBoundaryValue\n throwErrors: ThrowErrors<TQueryFnData, TError, TQueryData, TQueryKey>\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey>\n}) => {\n return (\n result.isError &&\n !errorResetBoundary.isReset() &&\n !result.isFetching &&\n shouldThrowError(throwErrors, [result.error, query])\n )\n}\n"],"names":["ensurePreventErrorBoundaryRetry","options","errorResetBoundary","suspense","throwErrors","isReset","retryOnMount","useClearResetErrorBoundary","React","useEffect","clearReset","getHasError","result","query","isError","isFetching","shouldThrowError","error"],"mappings":";;;MAWaA,+BAA+B,GAAG,CAO7CC,OAMC,EACDC,kBAAgD,KAC7C;AACH,EAAA,IAAID,OAAO,CAACE,QAAQ,IAAIF,OAAO,CAACG,WAAW,EAAE;AAC3C;AACA,IAAA,IAAI,CAACF,kBAAkB,CAACG,OAAO,EAAE,EAAE;MACjCJ,OAAO,CAACK,YAAY,GAAG,KAAK,CAAA;AAC9B,KAAA;AACF,GAAA;AACF,EAAC;AAEYC,MAAAA,0BAA0B,GACrCL,kBAAgD,IAC7C;EACHM,KAAK,CAACC,SAAS,CAAC,MAAM;IACpBP,kBAAkB,CAACQ,UAAU,EAAE,CAAA;AACjC,GAAC,EAAE,CAACR,kBAAkB,CAAC,CAAC,CAAA;AAC1B,EAAC;AAEM,MAAMS,WAAW,GAAG,CAMzB;EACAC,MAAM;EACNV,kBAAkB;EAClBE,WAAW;AACXS,EAAAA,KAAAA;AAMF,CAAC,KAAK;EACJ,OACED,MAAM,CAACE,OAAO,IACd,CAACZ,kBAAkB,CAACG,OAAO,EAAE,IAC7B,CAACO,MAAM,CAACG,UAAU,IAClBC,gBAAgB,CAACZ,WAAW,EAAE,CAACQ,MAAM,CAACK,KAAK,EAAEJ,KAAK,CAAC,CAAC,CAAA;AAExD;;;;"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { shouldThrowError } from './utils.mjs';
|
|
3
|
-
|
|
4
|
-
const ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
|
|
5
|
-
if (options.suspense || options.throwErrors) {
|
|
6
|
-
// Prevent retrying failed query if the error boundary has not been reset yet
|
|
7
|
-
if (!errorResetBoundary.isReset()) {
|
|
8
|
-
options.retryOnMount = false;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
const useClearResetErrorBoundary = errorResetBoundary => {
|
|
13
|
-
React.useEffect(() => {
|
|
14
|
-
errorResetBoundary.clearReset();
|
|
15
|
-
}, [errorResetBoundary]);
|
|
16
|
-
};
|
|
17
|
-
const getHasError = ({
|
|
18
|
-
result,
|
|
19
|
-
errorResetBoundary,
|
|
20
|
-
throwErrors,
|
|
21
|
-
query
|
|
22
|
-
}) => {
|
|
23
|
-
return result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(throwErrors, [result.error, query]);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export { ensurePreventErrorBoundaryRetry, getHasError, useClearResetErrorBoundary };
|
|
27
|
-
//# sourceMappingURL=errorBoundaryUtils.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errorBoundaryUtils.mjs","sources":["../../src/errorBoundaryUtils.ts"],"sourcesContent":["import type {\n DefaultedQueryObserverOptions,\n Query,\n QueryKey,\n QueryObserverResult,\n ThrowErrors,\n} from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\nimport * as React from 'react'\nimport { shouldThrowError } from './utils'\n\nexport const ensurePreventErrorBoundaryRetry = <\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n if (options.suspense || options.throwErrors) {\n // Prevent retrying failed query if the error boundary has not been reset yet\n if (!errorResetBoundary.isReset()) {\n options.retryOnMount = false\n }\n }\n}\n\nexport const useClearResetErrorBoundary = (\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n React.useEffect(() => {\n errorResetBoundary.clearReset()\n }, [errorResetBoundary])\n}\n\nexport const getHasError = <\n TData,\n TError,\n TQueryFnData,\n TQueryData,\n TQueryKey extends QueryKey,\n>({\n result,\n errorResetBoundary,\n throwErrors,\n query,\n}: {\n result: QueryObserverResult<TData, TError>\n errorResetBoundary: QueryErrorResetBoundaryValue\n throwErrors: ThrowErrors<TQueryFnData, TError, TQueryData, TQueryKey>\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey>\n}) => {\n return (\n result.isError &&\n !errorResetBoundary.isReset() &&\n !result.isFetching &&\n shouldThrowError(throwErrors, [result.error, query])\n )\n}\n"],"names":["ensurePreventErrorBoundaryRetry","options","errorResetBoundary","suspense","throwErrors","isReset","retryOnMount","useClearResetErrorBoundary","React","useEffect","clearReset","getHasError","result","query","isError","isFetching","shouldThrowError","error"],"mappings":";;;MAWaA,+BAA+B,GAAG,CAO7CC,OAMC,EACDC,kBAAgD,KAC7C;AACH,EAAA,IAAID,OAAO,CAACE,QAAQ,IAAIF,OAAO,CAACG,WAAW,EAAE;AAC3C;AACA,IAAA,IAAI,CAACF,kBAAkB,CAACG,OAAO,EAAE,EAAE;MACjCJ,OAAO,CAACK,YAAY,GAAG,KAAK,CAAA;AAC9B,KAAA;AACF,GAAA;AACF,EAAC;AAEYC,MAAAA,0BAA0B,GACrCL,kBAAgD,IAC7C;EACHM,KAAK,CAACC,SAAS,CAAC,MAAM;IACpBP,kBAAkB,CAACQ,UAAU,EAAE,CAAA;AACjC,GAAC,EAAE,CAACR,kBAAkB,CAAC,CAAC,CAAA;AAC1B,EAAC;AAEM,MAAMS,WAAW,GAAG,CAMzB;EACAC,MAAM;EACNV,kBAAkB;EAClBE,WAAW;AACXS,EAAAA,KAAAA;AAMF,CAAC,KAAK;EACJ,OACED,MAAM,CAACE,OAAO,IACd,CAACZ,kBAAkB,CAACG,OAAO,EAAE,IAC7B,CAACO,MAAM,CAACG,UAAU,IAClBC,gBAAgB,CAACZ,WAAW,EAAE,CAACQ,MAAM,CAACK,KAAK,EAAEJ,KAAK,CAAC,CAAC,CAAA;AAExD;;;;"}
|
package/build/lib/index.esm.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from '@tanstack/query-core';
|
|
2
|
-
export { useQueries } from './useQueries.esm.js';
|
|
3
|
-
export { useQuery } from './useQuery.esm.js';
|
|
4
|
-
export { QueryClientContext, QueryClientProvider, useQueryClient } from './QueryClientProvider.esm.js';
|
|
5
|
-
export { HydrationBoundary } from './HydrationBoundary.esm.js';
|
|
6
|
-
export { QueryErrorResetBoundary, useQueryErrorResetBoundary } from './QueryErrorResetBoundary.esm.js';
|
|
7
|
-
export { useIsFetching } from './useIsFetching.esm.js';
|
|
8
|
-
export { useIsMutating, useMutationState } from './useMutationState.esm.js';
|
|
9
|
-
export { useMutation } from './useMutation.esm.js';
|
|
10
|
-
export { useInfiniteQuery } from './useInfiniteQuery.esm.js';
|
|
11
|
-
export { IsRestoringProvider, useIsRestoring } from './isRestoring.esm.js';
|
|
12
|
-
//# sourceMappingURL=index.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
package/build/lib/index.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from '@tanstack/query-core';
|
|
2
|
-
export { useQueries } from './useQueries.mjs';
|
|
3
|
-
export { useQuery } from './useQuery.mjs';
|
|
4
|
-
export { QueryClientContext, QueryClientProvider, useQueryClient } from './QueryClientProvider.mjs';
|
|
5
|
-
export { HydrationBoundary } from './HydrationBoundary.mjs';
|
|
6
|
-
export { QueryErrorResetBoundary, useQueryErrorResetBoundary } from './QueryErrorResetBoundary.mjs';
|
|
7
|
-
export { useIsFetching } from './useIsFetching.mjs';
|
|
8
|
-
export { useIsMutating, useMutationState } from './useMutationState.mjs';
|
|
9
|
-
export { useMutation } from './useMutation.mjs';
|
|
10
|
-
export { useInfiniteQuery } from './useInfiniteQuery.mjs';
|
|
11
|
-
export { IsRestoringProvider, useIsRestoring } from './isRestoring.mjs';
|
|
12
|
-
//# sourceMappingURL=index.mjs.map
|
package/build/lib/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isRestoring.esm.js","sources":["../../src/isRestoring.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nconst IsRestoringContext = React.createContext(false)\n\nexport const useIsRestoring = () => React.useContext(IsRestoringContext)\nexport const IsRestoringProvider = IsRestoringContext.Provider\n"],"names":["IsRestoringContext","React","createContext","useIsRestoring","useContext","IsRestoringProvider","Provider"],"mappings":";;AAGA,MAAMA,kBAAkB,gBAAGC,KAAK,CAACC,aAAa,CAAC,KAAK,CAAC,CAAA;AAE9C,MAAMC,cAAc,GAAG,MAAMF,KAAK,CAACG,UAAU,CAACJ,kBAAkB,EAAC;AAC3DK,MAAAA,mBAAmB,GAAGL,kBAAkB,CAACM;;;;"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
const IsRestoringContext = /*#__PURE__*/React.createContext(false);
|
|
4
|
-
const useIsRestoring = () => React.useContext(IsRestoringContext);
|
|
5
|
-
const IsRestoringProvider = IsRestoringContext.Provider;
|
|
6
|
-
|
|
7
|
-
export { IsRestoringProvider, useIsRestoring };
|
|
8
|
-
//# sourceMappingURL=isRestoring.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isRestoring.mjs","sources":["../../src/isRestoring.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nconst IsRestoringContext = React.createContext(false)\n\nexport const useIsRestoring = () => React.useContext(IsRestoringContext)\nexport const IsRestoringProvider = IsRestoringContext.Provider\n"],"names":["IsRestoringContext","React","createContext","useIsRestoring","useContext","IsRestoringProvider","Provider"],"mappings":";;AAGA,MAAMA,kBAAkB,gBAAGC,KAAK,CAACC,aAAa,CAAC,KAAK,CAAC,CAAA;AAE9C,MAAMC,cAAc,GAAG,MAAMF,KAAK,CAACG,UAAU,CAACJ,kBAAkB,EAAC;AAC3DK,MAAAA,mBAAmB,GAAGL,kBAAkB,CAACM;;;;"}
|