@tanstack/react-query 5.0.0-alpha.3 → 5.0.0-alpha.31
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/utils/index.js +205 -0
- package/build/codemods/utils/transformers/query-cache-transformer.js +116 -0
- package/build/codemods/utils/transformers/query-client-transformer.js +48 -0
- package/build/codemods/utils/transformers/use-query-like-transformer.js +32 -0
- package/build/codemods/v4/__testfixtures__/default-import.input.tsx +94 -0
- package/build/codemods/v4/__testfixtures__/default-import.output.tsx +96 -0
- package/build/codemods/v4/__testfixtures__/named-import.input.tsx +96 -0
- package/build/codemods/v4/__testfixtures__/named-import.output.tsx +98 -0
- package/build/codemods/v4/__testfixtures__/namespaced-import.input.tsx +86 -0
- package/build/codemods/v4/__testfixtures__/namespaced-import.output.tsx +88 -0
- package/build/codemods/v4/__testfixtures__/parameter-is-identifier.input.tsx +49 -0
- package/build/codemods/v4/__testfixtures__/parameter-is-identifier.output.tsx +49 -0
- package/build/codemods/v4/__testfixtures__/parameter-is-object-expression.input.tsx +128 -0
- package/build/codemods/v4/__testfixtures__/parameter-is-object-expression.output.tsx +175 -0
- package/build/codemods/v4/__testfixtures__/replace-import-specifier.input.tsx +10 -0
- package/build/codemods/v4/__testfixtures__/replace-import-specifier.output.tsx +10 -0
- package/build/codemods/v4/__testfixtures__/type-arguments.input.tsx +25 -0
- package/build/codemods/v4/__testfixtures__/type-arguments.output.tsx +31 -0
- package/build/codemods/v4/__tests__/key-transformation.test.js +32 -0
- package/build/codemods/v4/__tests__/replace-import-specifier.test.js +12 -0
- package/build/codemods/v4/key-transformation.js +138 -0
- package/build/codemods/v4/replace-import-specifier.js +25 -0
- package/build/codemods/v4/utils/replacers/key-replacer.js +164 -0
- package/build/codemods/v5/remove-overloads/__testfixtures__/default-import.input.tsx +199 -0
- package/build/codemods/v5/remove-overloads/__testfixtures__/default-import.output.tsx +484 -0
- package/build/codemods/v5/remove-overloads/__tests__/remove-overloads.test.js +6 -0
- package/build/codemods/v5/remove-overloads/remove-overloads.js +59 -0
- package/build/codemods/v5/remove-overloads/transformers/filter-aware-usage-transformer.js +153 -0
- package/build/codemods/v5/remove-overloads/transformers/query-fn-aware-usage-transformer.js +188 -0
- package/build/codemods/v5/remove-overloads/utils/index.js +124 -0
- package/build/codemods/v5/remove-overloads/utils/unknown-usage-error.js +26 -0
- package/build/lib/HydrationBoundary.d.ts +1 -0
- package/build/lib/HydrationBoundary.d.ts.map +1 -0
- package/build/lib/HydrationBoundary.esm.js +1 -0
- package/build/lib/HydrationBoundary.esm.js.map +1 -1
- package/build/lib/HydrationBoundary.js +1 -0
- package/build/lib/HydrationBoundary.js.map +1 -1
- package/build/lib/HydrationBoundary.mjs +1 -0
- package/build/lib/HydrationBoundary.mjs.map +1 -1
- package/build/lib/QueryClientProvider.d.ts +1 -0
- package/build/lib/QueryClientProvider.d.ts.map +1 -0
- package/build/lib/QueryClientProvider.esm.js +1 -0
- package/build/lib/QueryClientProvider.esm.js.map +1 -1
- package/build/lib/QueryClientProvider.js +1 -0
- package/build/lib/QueryClientProvider.js.map +1 -1
- package/build/lib/QueryClientProvider.mjs +1 -0
- package/build/lib/QueryClientProvider.mjs.map +1 -1
- package/build/lib/QueryErrorResetBoundary.d.ts +1 -0
- package/build/lib/QueryErrorResetBoundary.d.ts.map +1 -0
- package/build/lib/QueryErrorResetBoundary.esm.js +1 -0
- package/build/lib/QueryErrorResetBoundary.esm.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.js +1 -0
- package/build/lib/QueryErrorResetBoundary.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.mjs +1 -0
- package/build/lib/QueryErrorResetBoundary.mjs.map +1 -1
- 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 -3
- 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 -3
- package/build/lib/__tests__/utils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.d.ts +4 -3
- package/build/lib/errorBoundaryUtils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.esm.js +4 -3
- package/build/lib/errorBoundaryUtils.esm.js.map +1 -1
- package/build/lib/errorBoundaryUtils.js +4 -3
- package/build/lib/errorBoundaryUtils.js.map +1 -1
- package/build/lib/errorBoundaryUtils.mjs +4 -3
- package/build/lib/errorBoundaryUtils.mjs.map +1 -1
- package/build/lib/index.d.ts +2 -1
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.esm.js +1 -1
- package/build/lib/index.js +1 -0
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1 -1
- package/build/lib/isRestoring.d.ts +1 -0
- package/build/lib/isRestoring.d.ts.map +1 -0
- package/build/lib/isRestoring.esm.js +1 -0
- package/build/lib/isRestoring.esm.js.map +1 -1
- package/build/lib/isRestoring.js +1 -0
- package/build/lib/isRestoring.js.map +1 -1
- package/build/lib/isRestoring.mjs +1 -0
- package/build/lib/isRestoring.mjs.map +1 -1
- package/build/lib/suspense.d.ts +2 -1
- package/build/lib/suspense.d.ts.map +1 -0
- package/build/lib/suspense.esm.js +2 -9
- package/build/lib/suspense.esm.js.map +1 -1
- package/build/lib/suspense.js +2 -9
- package/build/lib/suspense.js.map +1 -1
- package/build/lib/suspense.mjs +1 -8
- package/build/lib/suspense.mjs.map +1 -1
- package/build/lib/types.d.ts +1 -0
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/useBaseQuery.d.ts +1 -0
- package/build/lib/useBaseQuery.d.ts.map +1 -0
- package/build/lib/useBaseQuery.esm.js +2 -12
- package/build/lib/useBaseQuery.esm.js.map +1 -1
- package/build/lib/useBaseQuery.js +2 -12
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useBaseQuery.mjs +2 -12
- package/build/lib/useBaseQuery.mjs.map +1 -1
- package/build/lib/useInfiniteQuery.d.ts +1 -0
- package/build/lib/useInfiniteQuery.d.ts.map +1 -0
- package/build/lib/useInfiniteQuery.esm.js +1 -0
- package/build/lib/useInfiniteQuery.esm.js.map +1 -1
- package/build/lib/useInfiniteQuery.js +1 -0
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.mjs +1 -0
- package/build/lib/useInfiniteQuery.mjs.map +1 -1
- package/build/lib/useIsFetching.d.ts +1 -0
- package/build/lib/useIsFetching.d.ts.map +1 -0
- package/build/lib/useIsFetching.esm.js +1 -0
- package/build/lib/useIsFetching.esm.js.map +1 -1
- package/build/lib/useIsFetching.js +1 -0
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useIsFetching.mjs +1 -0
- package/build/lib/useIsFetching.mjs.map +1 -1
- package/build/lib/useMutation.d.ts +1 -0
- package/build/lib/useMutation.d.ts.map +1 -0
- package/build/lib/useMutation.esm.js +2 -1
- package/build/lib/useMutation.esm.js.map +1 -1
- package/build/lib/useMutation.js +2 -1
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutation.mjs +2 -1
- package/build/lib/useMutation.mjs.map +1 -1
- package/build/lib/useMutationState.d.ts +4 -3
- package/build/lib/useMutationState.d.ts.map +1 -0
- package/build/lib/useMutationState.esm.js +1 -0
- package/build/lib/useMutationState.esm.js.map +1 -1
- package/build/lib/useMutationState.js +1 -0
- package/build/lib/useMutationState.js.map +1 -1
- package/build/lib/useMutationState.mjs +1 -0
- package/build/lib/useMutationState.mjs.map +1 -1
- package/build/lib/useQueries.d.ts +3 -3
- package/build/lib/useQueries.d.ts.map +1 -0
- package/build/lib/useQueries.esm.js +20 -16
- package/build/lib/useQueries.esm.js.map +1 -1
- package/build/lib/useQueries.js +20 -16
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQueries.mjs +12 -11
- package/build/lib/useQueries.mjs.map +1 -1
- package/build/lib/useQuery.d.ts +3 -0
- package/build/lib/useQuery.d.ts.map +1 -0
- package/build/lib/useQuery.esm.js +6 -1
- package/build/lib/useQuery.esm.js.map +1 -1
- package/build/lib/useQuery.js +6 -0
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/useQuery.mjs +6 -1
- package/build/lib/useQuery.mjs.map +1 -1
- package/build/lib/utils.d.ts +1 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/umd/index.development.js +124 -155
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +9 -4
- package/src/__tests__/HydrationBoundary.test.tsx +4 -3
- package/src/__tests__/QueryClientProvider.test.tsx +2 -1
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +753 -620
- package/src/__tests__/ssr-hydration.test.tsx +11 -10
- package/src/__tests__/ssr.test.tsx +4 -7
- package/src/__tests__/suspense.test.tsx +17 -98
- package/src/__tests__/useInfiniteQuery.test.tsx +18 -16
- package/src/__tests__/useInfiniteQuery.type.test.tsx +94 -13
- package/src/__tests__/useMutation.test.tsx +25 -24
- package/src/__tests__/useMutationState.test.tsx +24 -58
- package/src/__tests__/useQueries.test.tsx +34 -163
- package/src/__tests__/useQuery.test.tsx +234 -365
- package/src/__tests__/useQuery.types.test.tsx +21 -1
- package/src/__tests__/utils.tsx +3 -2
- package/src/errorBoundaryUtils.ts +6 -5
- package/src/index.ts +1 -1
- package/src/suspense.ts +3 -11
- package/src/useBaseQuery.ts +2 -20
- 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 +20 -19
- package/src/useQuery.ts +23 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useQuery } from '../useQuery'
|
|
1
|
+
import { queryOptions, useQuery } from '../useQuery'
|
|
2
2
|
import type { Expect, Equal } from './utils'
|
|
3
3
|
import { doNotExecute } from './utils'
|
|
4
4
|
|
|
@@ -23,6 +23,26 @@ describe('initialData', () => {
|
|
|
23
23
|
})
|
|
24
24
|
})
|
|
25
25
|
|
|
26
|
+
it('TData should be defined when passed through queryOptions', () => {
|
|
27
|
+
doNotExecute(() => {
|
|
28
|
+
const options = queryOptions({
|
|
29
|
+
queryKey: ['key'],
|
|
30
|
+
queryFn: () => {
|
|
31
|
+
return {
|
|
32
|
+
wow: true,
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
initialData: {
|
|
36
|
+
wow: true,
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
const { data } = useQuery(options)
|
|
40
|
+
|
|
41
|
+
const result: Expect<Equal<{ wow: boolean }, typeof data>> = true
|
|
42
|
+
return result
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
26
46
|
it('TData should always be defined when initialData is provided as a function which ALWAYS returns the data', () => {
|
|
27
47
|
doNotExecute(() => {
|
|
28
48
|
const { data } = useQuery({
|
package/src/__tests__/utils.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { act, render } from '@testing-library/react'
|
|
|
3
3
|
import type { QueryClientConfig } from '..'
|
|
4
4
|
import { QueryClient, QueryClientProvider } from '..'
|
|
5
5
|
import * as utils from '@tanstack/query-core'
|
|
6
|
+
import { vi } from 'vitest'
|
|
6
7
|
|
|
7
8
|
export function renderWithClient(
|
|
8
9
|
client: QueryClient,
|
|
@@ -45,11 +46,11 @@ export function createQueryClient(config?: QueryClientConfig): QueryClient {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
export function mockVisibilityState(value: DocumentVisibilityState) {
|
|
48
|
-
return
|
|
49
|
+
return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
export function mockNavigatorOnLine(value: boolean) {
|
|
52
|
-
return
|
|
53
|
+
return vi.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
let queryKeyCount = 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
|
@@ -7,7 +7,7 @@ export * from '@tanstack/query-core'
|
|
|
7
7
|
export * from './types'
|
|
8
8
|
export { useQueries } from './useQueries'
|
|
9
9
|
export type { QueriesResults, QueriesOptions } from './useQueries'
|
|
10
|
-
export { useQuery } from './useQuery'
|
|
10
|
+
export { useQuery, queryOptions } from './useQuery'
|
|
11
11
|
export {
|
|
12
12
|
QueryClientContext,
|
|
13
13
|
QueryClientProvider,
|
package/src/suspense.ts
CHANGED
|
@@ -46,14 +46,6 @@ export const fetchOptimistic = <
|
|
|
46
46
|
observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
|
|
47
47
|
errorResetBoundary: QueryErrorResetBoundaryValue,
|
|
48
48
|
) =>
|
|
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
|
-
})
|
|
49
|
+
observer.fetchOptimistic(defaultedOptions).catch(() => {
|
|
50
|
+
errorResetBoundary.clearReset()
|
|
51
|
+
})
|
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
|
|
|
@@ -102,7 +84,7 @@ export function useBaseQuery<
|
|
|
102
84
|
getHasError({
|
|
103
85
|
result,
|
|
104
86
|
errorResetBoundary,
|
|
105
|
-
|
|
87
|
+
throwOnError: defaultedOptions.throwOnError,
|
|
106
88
|
query: observer.getCurrentQuery(),
|
|
107
89
|
})
|
|
108
90
|
) {
|
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 {
|
|
@@ -155,15 +156,17 @@ export type QueriesResults<
|
|
|
155
156
|
: // Fallback
|
|
156
157
|
UseQueryResult[]
|
|
157
158
|
|
|
158
|
-
export function useQueries<T extends any[]>(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}: {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
159
|
+
export function useQueries<T extends any[]>(
|
|
160
|
+
{
|
|
161
|
+
queries,
|
|
162
|
+
}: {
|
|
163
|
+
queries: readonly [...QueriesOptions<T>]
|
|
164
|
+
},
|
|
165
|
+
queryClient?: QueryClient,
|
|
166
|
+
): QueriesResults<T> {
|
|
165
167
|
const client = useQueryClient(queryClient)
|
|
166
168
|
const isRestoring = useIsRestoring()
|
|
169
|
+
const errorResetBoundary = useQueryErrorResetBoundary()
|
|
167
170
|
|
|
168
171
|
const defaultedQueries = React.useMemo(
|
|
169
172
|
() =>
|
|
@@ -180,6 +183,13 @@ export function useQueries<T extends any[]>({
|
|
|
180
183
|
[queries, client, isRestoring],
|
|
181
184
|
)
|
|
182
185
|
|
|
186
|
+
defaultedQueries.forEach((query) => {
|
|
187
|
+
ensureStaleTime(query)
|
|
188
|
+
ensurePreventErrorBoundaryRetry(query, errorResetBoundary)
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
useClearResetErrorBoundary(errorResetBoundary)
|
|
192
|
+
|
|
183
193
|
const [observer] = React.useState(
|
|
184
194
|
() => new QueriesObserver(client, defaultedQueries),
|
|
185
195
|
)
|
|
@@ -204,15 +214,6 @@ export function useQueries<T extends any[]>({
|
|
|
204
214
|
observer.setQueries(defaultedQueries, { listeners: false })
|
|
205
215
|
}, [defaultedQueries, observer])
|
|
206
216
|
|
|
207
|
-
const errorResetBoundary = useQueryErrorResetBoundary()
|
|
208
|
-
|
|
209
|
-
defaultedQueries.forEach((query) => {
|
|
210
|
-
ensurePreventErrorBoundaryRetry(query, errorResetBoundary)
|
|
211
|
-
ensureStaleTime(query)
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
useClearResetErrorBoundary(errorResetBoundary)
|
|
215
|
-
|
|
216
217
|
const shouldAtLeastOneSuspend = optimisticResult.some((result, index) =>
|
|
217
218
|
shouldSuspend(defaultedQueries[index], result, isRestoring),
|
|
218
219
|
)
|
|
@@ -236,14 +237,14 @@ export function useQueries<T extends any[]>({
|
|
|
236
237
|
if (suspensePromises.length > 0) {
|
|
237
238
|
throw Promise.all(suspensePromises)
|
|
238
239
|
}
|
|
239
|
-
|
|
240
|
+
const observerQueries = observer.getQueries()
|
|
240
241
|
const firstSingleResultWhichShouldThrow = optimisticResult.find(
|
|
241
242
|
(result, index) =>
|
|
242
243
|
getHasError({
|
|
243
244
|
result,
|
|
244
245
|
errorResetBoundary,
|
|
245
|
-
|
|
246
|
-
query:
|
|
246
|
+
throwOnError: defaultedQueries[index]?.throwOnError ?? false,
|
|
247
|
+
query: observerQueries[index]!,
|
|
247
248
|
}),
|
|
248
249
|
)
|
|
249
250
|
|
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 {
|
|
@@ -7,6 +8,28 @@ import type {
|
|
|
7
8
|
} from './types'
|
|
8
9
|
import { useBaseQuery } from './useBaseQuery'
|
|
9
10
|
|
|
11
|
+
export function queryOptions<
|
|
12
|
+
TQueryFnData = unknown,
|
|
13
|
+
TError = unknown,
|
|
14
|
+
TData = TQueryFnData,
|
|
15
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
16
|
+
>(
|
|
17
|
+
options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
18
|
+
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
|
|
19
|
+
|
|
20
|
+
export function queryOptions<
|
|
21
|
+
TQueryFnData = unknown,
|
|
22
|
+
TError = unknown,
|
|
23
|
+
TData = TQueryFnData,
|
|
24
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
25
|
+
>(
|
|
26
|
+
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
27
|
+
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
|
|
28
|
+
|
|
29
|
+
export function queryOptions(options: unknown) {
|
|
30
|
+
return options
|
|
31
|
+
}
|
|
32
|
+
|
|
10
33
|
// HOOK
|
|
11
34
|
type UndefinedInitialDataOptions<
|
|
12
35
|
TQueryFnData = unknown,
|