@tanstack/react-query 5.0.0-alpha.9 → 5.0.0-alpha.91
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/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/rename-hydrate/rename-hydrate.js +55 -0
- package/build/codemods/rename-properties/rename-properties.js +41 -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/legacy/HydrationBoundary.cjs +60 -0
- package/build/legacy/HydrationBoundary.cjs.map +1 -0
- package/build/legacy/HydrationBoundary.d.cts +12 -0
- package/build/legacy/HydrationBoundary.d.ts +12 -0
- package/build/legacy/HydrationBoundary.js +26 -0
- package/build/legacy/HydrationBoundary.js.map +1 -0
- package/build/legacy/QueryClientProvider.cjs +71 -0
- package/build/legacy/QueryClientProvider.cjs.map +1 -0
- package/build/legacy/QueryClientProvider.d.cts +12 -0
- package/build/legacy/QueryClientProvider.d.ts +12 -0
- package/build/legacy/QueryClientProvider.js +35 -0
- package/build/legacy/QueryClientProvider.js.map +1 -0
- package/build/legacy/QueryErrorResetBoundary.cjs +66 -0
- package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -0
- package/build/legacy/QueryErrorResetBoundary.d.cts +14 -0
- package/build/legacy/QueryErrorResetBoundary.d.ts +14 -0
- package/build/legacy/QueryErrorResetBoundary.js +31 -0
- package/build/legacy/QueryErrorResetBoundary.js.map +1 -0
- package/build/legacy/errorBoundaryUtils.cjs +67 -0
- package/build/legacy/errorBoundaryUtils.cjs.map +1 -0
- package/build/legacy/errorBoundaryUtils.d.cts +14 -0
- package/build/legacy/errorBoundaryUtils.d.ts +14 -0
- package/build/legacy/errorBoundaryUtils.js +31 -0
- package/build/legacy/errorBoundaryUtils.js.map +1 -0
- package/build/legacy/index.cjs +85 -0
- package/build/legacy/index.cjs.map +1 -0
- package/build/legacy/index.d.cts +17 -0
- package/build/legacy/index.d.ts +17 -0
- package/build/legacy/index.js +46 -0
- package/build/legacy/index.js.map +1 -0
- package/build/legacy/infiniteQueryOptions.cjs +33 -0
- package/build/legacy/infiniteQueryOptions.cjs.map +1 -0
- package/build/legacy/infiniteQueryOptions.d.cts +13 -0
- package/build/legacy/infiniteQueryOptions.d.ts +13 -0
- package/build/legacy/infiniteQueryOptions.js +8 -0
- package/build/legacy/infiniteQueryOptions.js.map +1 -0
- package/build/legacy/isRestoring.cjs +47 -0
- package/build/legacy/isRestoring.cjs.map +1 -0
- package/build/legacy/isRestoring.d.cts +6 -0
- package/build/legacy/isRestoring.d.ts +6 -0
- package/build/legacy/isRestoring.js +12 -0
- package/build/legacy/isRestoring.js.map +1 -0
- package/build/legacy/queryOptions.cjs +33 -0
- package/build/legacy/queryOptions.cjs.map +1 -0
- package/build/legacy/queryOptions.d.cts +13 -0
- package/build/legacy/queryOptions.d.ts +13 -0
- package/build/legacy/queryOptions.js +8 -0
- package/build/legacy/queryOptions.js.map +1 -0
- package/build/legacy/suspense.cjs +48 -0
- package/build/legacy/suspense.cjs.map +1 -0
- package/build/legacy/suspense.d.cts +10 -0
- package/build/legacy/suspense.d.ts +10 -0
- package/build/legacy/suspense.js +20 -0
- package/build/legacy/suspense.js.map +1 -0
- package/build/legacy/types.cjs +19 -0
- package/build/legacy/types.cjs.map +1 -0
- package/build/legacy/types.d.cts +34 -0
- package/build/legacy/types.d.ts +34 -0
- package/build/legacy/types.js +1 -0
- package/build/legacy/types.js.map +1 -0
- package/build/legacy/useBaseQuery.cjs +92 -0
- package/build/legacy/useBaseQuery.cjs.map +1 -0
- package/build/legacy/useBaseQuery.d.cts +92 -0
- package/build/legacy/useBaseQuery.d.ts +92 -0
- package/build/legacy/useBaseQuery.js +62 -0
- package/build/legacy/useBaseQuery.js.map +1 -0
- package/build/legacy/useInfiniteQuery.cjs +41 -0
- package/build/legacy/useInfiniteQuery.cjs.map +1 -0
- package/build/legacy/useInfiniteQuery.d.cts +8 -0
- package/build/legacy/useInfiniteQuery.d.ts +8 -0
- package/build/legacy/useInfiniteQuery.js +17 -0
- package/build/legacy/useInfiniteQuery.js.map +1 -0
- package/build/legacy/useIsFetching.cjs +56 -0
- package/build/legacy/useIsFetching.cjs.map +1 -0
- package/build/legacy/useIsFetching.d.cts +5 -0
- package/build/legacy/useIsFetching.d.ts +5 -0
- package/build/legacy/useIsFetching.js +22 -0
- package/build/legacy/useIsFetching.js.map +1 -0
- package/build/legacy/useMutation.cjs +77 -0
- package/build/legacy/useMutation.cjs.map +1 -0
- package/build/legacy/useMutation.d.cts +6 -0
- package/build/legacy/useMutation.d.ts +6 -0
- package/build/legacy/useMutation.js +43 -0
- package/build/legacy/useMutation.js.map +1 -0
- package/build/legacy/useMutationState.cjs +88 -0
- package/build/legacy/useMutationState.cjs.map +1 -0
- package/build/legacy/useMutationState.d.cts +10 -0
- package/build/legacy/useMutationState.d.ts +10 -0
- package/build/legacy/useMutationState.js +53 -0
- package/build/legacy/useMutationState.js.map +1 -0
- package/build/legacy/useQueries.cjs +128 -0
- package/build/legacy/useQueries.cjs.map +1 -0
- package/build/legacy/useQueries.d.cts +53 -0
- package/build/{lib → legacy}/useQueries.d.ts +14 -11
- package/build/legacy/useQueries.js +103 -0
- package/build/legacy/useQueries.js.map +1 -0
- package/build/legacy/useQuery.cjs +36 -0
- package/build/legacy/useQuery.cjs.map +1 -0
- package/build/legacy/useQuery.d.cts +8 -0
- package/build/legacy/useQuery.d.ts +8 -0
- package/build/legacy/useQuery.js +12 -0
- package/build/legacy/useQuery.js.map +1 -0
- package/build/legacy/useSuspenseInfiniteQuery.cjs +46 -0
- package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.cts +6 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.ts +6 -0
- package/build/legacy/useSuspenseInfiniteQuery.js +22 -0
- package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -0
- package/build/legacy/useSuspenseQuery.cjs +45 -0
- package/build/legacy/useSuspenseQuery.cjs.map +1 -0
- package/build/legacy/useSuspenseQuery.d.cts +6 -0
- package/build/legacy/useSuspenseQuery.d.ts +6 -0
- package/build/legacy/useSuspenseQuery.js +21 -0
- package/build/legacy/useSuspenseQuery.js.map +1 -0
- package/build/legacy/utils.cjs +36 -0
- package/build/legacy/utils.cjs.map +1 -0
- package/build/legacy/utils.d.cts +3 -0
- package/build/legacy/utils.d.ts +3 -0
- package/build/legacy/utils.js +11 -0
- package/build/legacy/utils.js.map +1 -0
- package/build/modern/HydrationBoundary.cjs +60 -0
- package/build/modern/HydrationBoundary.cjs.map +1 -0
- package/build/modern/HydrationBoundary.d.cts +12 -0
- package/build/modern/HydrationBoundary.d.ts +12 -0
- package/build/modern/HydrationBoundary.js +26 -0
- package/build/modern/HydrationBoundary.js.map +1 -0
- package/build/modern/QueryClientProvider.cjs +71 -0
- package/build/modern/QueryClientProvider.cjs.map +1 -0
- package/build/modern/QueryClientProvider.d.cts +12 -0
- package/build/modern/QueryClientProvider.d.ts +12 -0
- package/build/modern/QueryClientProvider.js +35 -0
- package/build/modern/QueryClientProvider.js.map +1 -0
- package/build/modern/QueryErrorResetBoundary.cjs +66 -0
- package/build/modern/QueryErrorResetBoundary.cjs.map +1 -0
- package/build/modern/QueryErrorResetBoundary.d.cts +14 -0
- package/build/modern/QueryErrorResetBoundary.d.ts +14 -0
- package/build/modern/QueryErrorResetBoundary.js +31 -0
- package/build/modern/QueryErrorResetBoundary.js.map +1 -0
- package/build/modern/errorBoundaryUtils.cjs +67 -0
- package/build/modern/errorBoundaryUtils.cjs.map +1 -0
- package/build/modern/errorBoundaryUtils.d.cts +14 -0
- package/build/modern/errorBoundaryUtils.d.ts +14 -0
- package/build/modern/errorBoundaryUtils.js +31 -0
- package/build/modern/errorBoundaryUtils.js.map +1 -0
- package/build/modern/index.cjs +85 -0
- package/build/modern/index.cjs.map +1 -0
- package/build/modern/index.d.cts +17 -0
- package/build/modern/index.d.ts +17 -0
- package/build/modern/index.js +46 -0
- package/build/modern/index.js.map +1 -0
- package/build/modern/infiniteQueryOptions.cjs +33 -0
- package/build/modern/infiniteQueryOptions.cjs.map +1 -0
- package/build/modern/infiniteQueryOptions.d.cts +13 -0
- package/build/modern/infiniteQueryOptions.d.ts +13 -0
- package/build/modern/infiniteQueryOptions.js +8 -0
- package/build/modern/infiniteQueryOptions.js.map +1 -0
- package/build/modern/isRestoring.cjs +47 -0
- package/build/modern/isRestoring.cjs.map +1 -0
- package/build/modern/isRestoring.d.cts +6 -0
- package/build/modern/isRestoring.d.ts +6 -0
- package/build/modern/isRestoring.js +12 -0
- package/build/modern/isRestoring.js.map +1 -0
- package/build/modern/queryOptions.cjs +33 -0
- package/build/modern/queryOptions.cjs.map +1 -0
- package/build/modern/queryOptions.d.cts +13 -0
- package/build/modern/queryOptions.d.ts +13 -0
- package/build/modern/queryOptions.js +8 -0
- package/build/modern/queryOptions.js.map +1 -0
- package/build/modern/suspense.cjs +48 -0
- package/build/modern/suspense.cjs.map +1 -0
- package/build/modern/suspense.d.cts +10 -0
- package/build/modern/suspense.d.ts +10 -0
- package/build/modern/suspense.js +20 -0
- package/build/modern/suspense.js.map +1 -0
- package/build/modern/types.cjs +19 -0
- package/build/modern/types.cjs.map +1 -0
- package/build/modern/types.d.cts +34 -0
- package/build/modern/types.d.ts +34 -0
- package/build/modern/types.js +1 -0
- package/build/modern/types.js.map +1 -0
- package/build/modern/useBaseQuery.cjs +92 -0
- package/build/modern/useBaseQuery.cjs.map +1 -0
- package/build/modern/useBaseQuery.d.cts +92 -0
- package/build/modern/useBaseQuery.d.ts +92 -0
- package/build/modern/useBaseQuery.js +62 -0
- package/build/modern/useBaseQuery.js.map +1 -0
- package/build/modern/useInfiniteQuery.cjs +41 -0
- package/build/modern/useInfiniteQuery.cjs.map +1 -0
- package/build/modern/useInfiniteQuery.d.cts +8 -0
- package/build/modern/useInfiniteQuery.d.ts +8 -0
- package/build/modern/useInfiniteQuery.js +17 -0
- package/build/modern/useInfiniteQuery.js.map +1 -0
- package/build/modern/useIsFetching.cjs +56 -0
- package/build/modern/useIsFetching.cjs.map +1 -0
- package/build/modern/useIsFetching.d.cts +5 -0
- package/build/modern/useIsFetching.d.ts +5 -0
- package/build/modern/useIsFetching.js +22 -0
- package/build/modern/useIsFetching.js.map +1 -0
- package/build/modern/useMutation.cjs +77 -0
- package/build/modern/useMutation.cjs.map +1 -0
- package/build/modern/useMutation.d.cts +6 -0
- package/build/modern/useMutation.d.ts +6 -0
- package/build/modern/useMutation.js +43 -0
- package/build/modern/useMutation.js.map +1 -0
- package/build/modern/useMutationState.cjs +88 -0
- package/build/modern/useMutationState.cjs.map +1 -0
- package/build/modern/useMutationState.d.cts +10 -0
- package/build/modern/useMutationState.d.ts +10 -0
- package/build/modern/useMutationState.js +53 -0
- package/build/modern/useMutationState.js.map +1 -0
- package/build/modern/useQueries.cjs +125 -0
- package/build/modern/useQueries.cjs.map +1 -0
- package/build/modern/useQueries.d.cts +53 -0
- package/build/modern/useQueries.d.ts +53 -0
- package/build/modern/useQueries.js +100 -0
- package/build/modern/useQueries.js.map +1 -0
- package/build/modern/useQuery.cjs +36 -0
- package/build/modern/useQuery.cjs.map +1 -0
- package/build/modern/useQuery.d.cts +8 -0
- package/build/modern/useQuery.d.ts +8 -0
- package/build/modern/useQuery.js +12 -0
- package/build/modern/useQuery.js.map +1 -0
- package/build/modern/useSuspenseInfiniteQuery.cjs +46 -0
- package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -0
- package/build/modern/useSuspenseInfiniteQuery.d.cts +6 -0
- package/build/modern/useSuspenseInfiniteQuery.d.ts +6 -0
- package/build/modern/useSuspenseInfiniteQuery.js +22 -0
- package/build/modern/useSuspenseInfiniteQuery.js.map +1 -0
- package/build/modern/useSuspenseQuery.cjs +45 -0
- package/build/modern/useSuspenseQuery.cjs.map +1 -0
- package/build/modern/useSuspenseQuery.d.cts +6 -0
- package/build/modern/useSuspenseQuery.d.ts +6 -0
- package/build/modern/useSuspenseQuery.js +21 -0
- package/build/modern/useSuspenseQuery.js.map +1 -0
- package/build/modern/utils.cjs +36 -0
- package/build/modern/utils.cjs.map +1 -0
- package/build/modern/utils.d.cts +3 -0
- package/build/modern/utils.d.ts +3 -0
- package/build/modern/utils.js +11 -0
- package/build/modern/utils.js.map +1 -0
- package/package.json +29 -17
- package/src/HydrationBoundary.tsx +1 -1
- package/src/__tests__/HydrationBoundary.test.tsx +5 -5
- package/src/__tests__/QueryClientProvider.test.tsx +2 -2
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +753 -621
- package/src/__tests__/ssr-hydration.test.tsx +4 -4
- package/src/__tests__/ssr.test.tsx +2 -2
- package/src/__tests__/suspense.test.tsx +8 -90
- package/src/__tests__/useInfiniteQuery.test.tsx +36 -74
- package/src/__tests__/useInfiniteQuery.type.test.tsx +2 -29
- package/src/__tests__/useIsFetching.test.tsx +1 -1
- package/src/__tests__/useMutation.test.tsx +22 -23
- package/src/__tests__/useMutationState.test.tsx +23 -0
- package/src/__tests__/useQueries.test.tsx +214 -91
- package/src/__tests__/useQuery.test.tsx +691 -551
- package/src/__tests__/useQuery.types.test.tsx +22 -1
- package/src/__tests__/utils.tsx +11 -5
- package/src/errorBoundaryUtils.ts +7 -7
- package/src/index.ts +4 -0
- package/src/infiniteQueryOptions.ts +93 -0
- package/src/queryOptions.ts +42 -0
- package/src/suspense.ts +9 -15
- package/src/types.ts +50 -8
- package/src/useBaseQuery.ts +14 -26
- package/src/useInfiniteQuery.ts +50 -7
- package/src/useIsFetching.ts +1 -1
- package/src/useMutation.ts +4 -4
- package/src/useMutationState.ts +8 -8
- package/src/useQueries.ts +53 -36
- package/src/useQuery.ts +6 -21
- package/src/useSuspenseInfiniteQuery.ts +47 -0
- package/src/useSuspenseQuery.ts +26 -0
- package/build/lib/HydrationBoundary.d.ts +0 -9
- package/build/lib/HydrationBoundary.esm.js +0 -29
- package/build/lib/HydrationBoundary.esm.js.map +0 -1
- package/build/lib/HydrationBoundary.js +0 -50
- package/build/lib/HydrationBoundary.js.map +0 -1
- package/build/lib/HydrationBoundary.mjs +0 -29
- package/build/lib/HydrationBoundary.mjs.map +0 -1
- package/build/lib/QueryClientProvider.d.ts +0 -9
- package/build/lib/QueryClientProvider.esm.js +0 -31
- package/build/lib/QueryClientProvider.esm.js.map +0 -1
- package/build/lib/QueryClientProvider.js +0 -54
- package/build/lib/QueryClientProvider.js.map +0 -1
- package/build/lib/QueryClientProvider.mjs +0 -31
- package/build/lib/QueryClientProvider.mjs.map +0 -1
- package/build/lib/QueryErrorResetBoundary.d.ts +0 -11
- package/build/lib/QueryErrorResetBoundary.esm.js +0 -38
- package/build/lib/QueryErrorResetBoundary.esm.js.map +0 -1
- package/build/lib/QueryErrorResetBoundary.js +0 -60
- package/build/lib/QueryErrorResetBoundary.js.map +0 -1
- package/build/lib/QueryErrorResetBoundary.mjs +0 -38
- package/build/lib/QueryErrorResetBoundary.mjs.map +0 -1
- package/build/lib/__tests__/HydrationBoundary.test.d.ts +0 -1
- package/build/lib/__tests__/QueryClientProvider.test.d.ts +0 -1
- package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts +0 -6
- package/build/lib/__tests__/ssr-hydration.test.d.ts +0 -1
- package/build/lib/__tests__/ssr.test.d.ts +0 -1
- package/build/lib/__tests__/suspense.test.d.ts +0 -1
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts +0 -1
- package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts +0 -1
- package/build/lib/__tests__/useIsFetching.test.d.ts +0 -1
- package/build/lib/__tests__/useMutation.test.d.ts +0 -1
- package/build/lib/__tests__/useMutationState.test.d.ts +0 -1
- package/build/lib/__tests__/useQueries.test.d.ts +0 -1
- package/build/lib/__tests__/useQuery.test.d.ts +0 -1
- package/build/lib/__tests__/useQuery.types.test.d.ts +0 -1
- package/build/lib/__tests__/utils.d.ts +0 -28
- package/build/lib/errorBoundaryUtils.d.ts +0 -10
- package/build/lib/errorBoundaryUtils.esm.js +0 -28
- package/build/lib/errorBoundaryUtils.esm.js.map +0 -1
- package/build/lib/errorBoundaryUtils.js +0 -51
- package/build/lib/errorBoundaryUtils.js.map +0 -1
- package/build/lib/errorBoundaryUtils.mjs +0 -28
- package/build/lib/errorBoundaryUtils.mjs.map +0 -1
- package/build/lib/index.d.ts +0 -16
- package/build/lib/index.esm.js +0 -12
- package/build/lib/index.esm.js.map +0 -1
- package/build/lib/index.js +0 -38
- package/build/lib/index.js.map +0 -1
- package/build/lib/index.mjs +0 -12
- package/build/lib/index.mjs.map +0 -1
- package/build/lib/isRestoring.d.ts +0 -3
- package/build/lib/isRestoring.esm.js +0 -9
- package/build/lib/isRestoring.esm.js.map +0 -1
- package/build/lib/isRestoring.js +0 -31
- package/build/lib/isRestoring.js.map +0 -1
- package/build/lib/isRestoring.mjs +0 -9
- package/build/lib/isRestoring.mjs.map +0 -1
- package/build/lib/suspense.d.ts +0 -9
- package/build/lib/suspense.esm.js +0 -24
- package/build/lib/suspense.esm.js.map +0 -1
- package/build/lib/suspense.js +0 -29
- package/build/lib/suspense.js.map +0 -1
- package/build/lib/suspense.mjs +0 -24
- package/build/lib/suspense.mjs.map +0 -1
- package/build/lib/types.d.ts +0 -26
- package/build/lib/useBaseQuery.d.ts +0 -3
- package/build/lib/useBaseQuery.esm.js +0 -63
- package/build/lib/useBaseQuery.esm.js.map +0 -1
- package/build/lib/useBaseQuery.js +0 -84
- package/build/lib/useBaseQuery.js.map +0 -1
- package/build/lib/useBaseQuery.mjs +0 -63
- package/build/lib/useBaseQuery.mjs.map +0 -1
- package/build/lib/useInfiniteQuery.d.ts +0 -3
- package/build/lib/useInfiniteQuery.esm.js +0 -13
- package/build/lib/useInfiniteQuery.esm.js.map +0 -1
- package/build/lib/useInfiniteQuery.js +0 -15
- package/build/lib/useInfiniteQuery.js.map +0 -1
- package/build/lib/useInfiniteQuery.mjs +0 -13
- package/build/lib/useInfiniteQuery.mjs.map +0 -1
- package/build/lib/useIsFetching.d.ts +0 -2
- package/build/lib/useIsFetching.esm.js +0 -13
- package/build/lib/useIsFetching.esm.js.map +0 -1
- package/build/lib/useIsFetching.js +0 -34
- package/build/lib/useIsFetching.js.map +0 -1
- package/build/lib/useIsFetching.mjs +0 -13
- package/build/lib/useIsFetching.mjs.map +0 -1
- package/build/lib/useMutation.d.ts +0 -3
- package/build/lib/useMutation.esm.js +0 -33
- package/build/lib/useMutation.esm.js.map +0 -1
- package/build/lib/useMutation.js +0 -54
- package/build/lib/useMutation.js.map +0 -1
- package/build/lib/useMutation.mjs +0 -33
- package/build/lib/useMutation.mjs.map +0 -1
- package/build/lib/useMutationState.d.ts +0 -8
- package/build/lib/useMutationState.esm.js +0 -38
- package/build/lib/useMutationState.esm.js.map +0 -1
- package/build/lib/useMutationState.js +0 -60
- package/build/lib/useMutationState.js.map +0 -1
- package/build/lib/useMutationState.mjs +0 -38
- package/build/lib/useMutationState.mjs.map +0 -1
- package/build/lib/useQueries.esm.js +0 -73
- package/build/lib/useQueries.esm.js.map +0 -1
- package/build/lib/useQueries.js +0 -94
- package/build/lib/useQueries.js.map +0 -1
- package/build/lib/useQueries.mjs +0 -70
- package/build/lib/useQueries.mjs.map +0 -1
- package/build/lib/useQuery.d.ts +0 -11
- package/build/lib/useQuery.esm.js +0 -12
- package/build/lib/useQuery.esm.js.map +0 -1
- package/build/lib/useQuery.js +0 -14
- package/build/lib/useQuery.js.map +0 -1
- package/build/lib/useQuery.mjs +0 -12
- package/build/lib/useQuery.mjs.map +0 -1
- package/build/lib/utils.d.ts +0 -1
- package/build/lib/utils.esm.js +0 -10
- package/build/lib/utils.esm.js.map +0 -1
- package/build/lib/utils.js +0 -12
- package/build/lib/utils.js.map +0 -1
- package/build/lib/utils.mjs +0 -10
- package/build/lib/utils.mjs.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,6 +1,7 @@
|
|
|
1
1
|
import { useQuery } from '../useQuery'
|
|
2
|
-
import
|
|
2
|
+
import { queryOptions } from '../queryOptions'
|
|
3
3
|
import { doNotExecute } from './utils'
|
|
4
|
+
import type { Equal, Expect } from './utils'
|
|
4
5
|
|
|
5
6
|
describe('initialData', () => {
|
|
6
7
|
describe('Config object overload', () => {
|
|
@@ -23,6 +24,26 @@ describe('initialData', () => {
|
|
|
23
24
|
})
|
|
24
25
|
})
|
|
25
26
|
|
|
27
|
+
it('TData should be defined when passed through queryOptions', () => {
|
|
28
|
+
doNotExecute(() => {
|
|
29
|
+
const options = queryOptions({
|
|
30
|
+
queryKey: ['key'],
|
|
31
|
+
queryFn: () => {
|
|
32
|
+
return {
|
|
33
|
+
wow: true,
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
initialData: {
|
|
37
|
+
wow: true,
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
const { data } = useQuery(options)
|
|
41
|
+
|
|
42
|
+
const result: Expect<Equal<{ wow: boolean }, typeof data>> = true
|
|
43
|
+
return result
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
26
47
|
it('TData should always be defined when initialData is provided as a function which ALWAYS returns the data', () => {
|
|
27
48
|
doNotExecute(() => {
|
|
28
49
|
const { data } = useQuery({
|
package/src/__tests__/utils.tsx
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { act, render } from '@testing-library/react'
|
|
3
|
-
|
|
4
|
-
import { QueryClient, QueryClientProvider } from '..'
|
|
3
|
+
|
|
5
4
|
import * as utils from '@tanstack/query-core'
|
|
6
5
|
import { vi } from 'vitest'
|
|
6
|
+
import { QueryClient, QueryClientProvider, onlineManager } from '..'
|
|
7
|
+
import type { QueryClientConfig } from '..'
|
|
8
|
+
import type { SpyInstance } from 'vitest'
|
|
7
9
|
|
|
8
10
|
export function renderWithClient(
|
|
9
11
|
client: QueryClient,
|
|
@@ -45,12 +47,16 @@ export function createQueryClient(config?: QueryClientConfig): QueryClient {
|
|
|
45
47
|
return new QueryClient(config)
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
export function mockVisibilityState(
|
|
50
|
+
export function mockVisibilityState(
|
|
51
|
+
value: DocumentVisibilityState,
|
|
52
|
+
): SpyInstance<[], DocumentVisibilityState> {
|
|
49
53
|
return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
export function
|
|
53
|
-
|
|
56
|
+
export function mockOnlineManagerIsOnline(
|
|
57
|
+
value: boolean,
|
|
58
|
+
): SpyInstance<[], boolean> {
|
|
59
|
+
return vi.spyOn(onlineManager, 'isOnline').mockReturnValue(value)
|
|
54
60
|
}
|
|
55
61
|
|
|
56
62
|
let queryKeyCount = 0
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { shouldThrowError } from './utils'
|
|
2
4
|
import type {
|
|
3
5
|
DefaultedQueryObserverOptions,
|
|
4
6
|
Query,
|
|
5
7
|
QueryKey,
|
|
6
8
|
QueryObserverResult,
|
|
7
|
-
|
|
9
|
+
ThrowOnError,
|
|
8
10
|
} from '@tanstack/query-core'
|
|
9
11
|
import type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'
|
|
10
|
-
import * as React from 'react'
|
|
11
|
-
import { shouldThrowError } from './utils'
|
|
12
12
|
|
|
13
13
|
export const ensurePreventErrorBoundaryRetry = <
|
|
14
14
|
TQueryFnData,
|
|
@@ -26,7 +26,7 @@ export const ensurePreventErrorBoundaryRetry = <
|
|
|
26
26
|
>,
|
|
27
27
|
errorResetBoundary: QueryErrorResetBoundaryValue,
|
|
28
28
|
) => {
|
|
29
|
-
if (options.suspense || options.
|
|
29
|
+
if (options.suspense || options.throwOnError) {
|
|
30
30
|
// Prevent retrying failed query if the error boundary has not been reset yet
|
|
31
31
|
if (!errorResetBoundary.isReset()) {
|
|
32
32
|
options.retryOnMount = false
|
|
@@ -51,18 +51,18 @@ export const getHasError = <
|
|
|
51
51
|
>({
|
|
52
52
|
result,
|
|
53
53
|
errorResetBoundary,
|
|
54
|
-
|
|
54
|
+
throwOnError,
|
|
55
55
|
query,
|
|
56
56
|
}: {
|
|
57
57
|
result: QueryObserverResult<TData, TError>
|
|
58
58
|
errorResetBoundary: QueryErrorResetBoundaryValue
|
|
59
|
-
|
|
59
|
+
throwOnError: ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey>
|
|
60
60
|
query: Query<TQueryFnData, TError, TQueryData, TQueryKey>
|
|
61
61
|
}) => {
|
|
62
62
|
return (
|
|
63
63
|
result.isError &&
|
|
64
64
|
!errorResetBoundary.isReset() &&
|
|
65
65
|
!result.isFetching &&
|
|
66
|
-
shouldThrowError(
|
|
66
|
+
shouldThrowError(throwOnError, [result.error, query])
|
|
67
67
|
)
|
|
68
68
|
}
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,10 @@ 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 { useSuspenseQuery } from './useSuspenseQuery'
|
|
12
|
+
export { useSuspenseInfiniteQuery } from './useSuspenseInfiniteQuery'
|
|
13
|
+
export { queryOptions } from './queryOptions'
|
|
14
|
+
export { infiniteQueryOptions } from './infiniteQueryOptions'
|
|
11
15
|
export {
|
|
12
16
|
QueryClientContext,
|
|
13
17
|
QueryClientProvider,
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { InfiniteData } from '@tanstack/query-core'
|
|
2
|
+
import type { UseInfiniteQueryOptions } from './types'
|
|
3
|
+
import type { DefaultError, QueryKey } from '@tanstack/query-core'
|
|
4
|
+
|
|
5
|
+
export type UndefinedInitialDataInfiniteOptions<
|
|
6
|
+
TQueryFnData = unknown,
|
|
7
|
+
TError = DefaultError,
|
|
8
|
+
TData = TQueryFnData,
|
|
9
|
+
TQueryData = TQueryFnData,
|
|
10
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
11
|
+
TPageParam = unknown,
|
|
12
|
+
> = UseInfiniteQueryOptions<
|
|
13
|
+
TQueryFnData,
|
|
14
|
+
TError,
|
|
15
|
+
TData,
|
|
16
|
+
TQueryData,
|
|
17
|
+
TQueryKey,
|
|
18
|
+
TPageParam
|
|
19
|
+
> & {
|
|
20
|
+
initialData?: undefined
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type DefinedInitialDataInfiniteOptions<
|
|
24
|
+
TQueryFnData = unknown,
|
|
25
|
+
TError = DefaultError,
|
|
26
|
+
TData = TQueryFnData,
|
|
27
|
+
TQueryData = TQueryFnData,
|
|
28
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
29
|
+
TPageParam = unknown,
|
|
30
|
+
> = UseInfiniteQueryOptions<
|
|
31
|
+
TQueryFnData,
|
|
32
|
+
TError,
|
|
33
|
+
TData,
|
|
34
|
+
TQueryData,
|
|
35
|
+
TQueryKey,
|
|
36
|
+
TPageParam
|
|
37
|
+
> & {
|
|
38
|
+
initialData: InfiniteData<TQueryData> | (() => InfiniteData<TQueryData>)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function infiniteQueryOptions<
|
|
42
|
+
TQueryFnData = unknown,
|
|
43
|
+
TError = DefaultError,
|
|
44
|
+
TData = TQueryFnData,
|
|
45
|
+
TQueryData = TQueryFnData,
|
|
46
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
47
|
+
TPageParam = unknown,
|
|
48
|
+
>(
|
|
49
|
+
options: UndefinedInitialDataInfiniteOptions<
|
|
50
|
+
TQueryFnData,
|
|
51
|
+
TError,
|
|
52
|
+
TData,
|
|
53
|
+
TQueryFnData,
|
|
54
|
+
TQueryKey,
|
|
55
|
+
TPageParam
|
|
56
|
+
>,
|
|
57
|
+
): UndefinedInitialDataInfiniteOptions<
|
|
58
|
+
TQueryFnData,
|
|
59
|
+
TError,
|
|
60
|
+
TData,
|
|
61
|
+
TQueryFnData,
|
|
62
|
+
TQueryKey,
|
|
63
|
+
TPageParam
|
|
64
|
+
>
|
|
65
|
+
|
|
66
|
+
export function infiniteQueryOptions<
|
|
67
|
+
TQueryFnData = unknown,
|
|
68
|
+
TError = DefaultError,
|
|
69
|
+
TData = TQueryFnData,
|
|
70
|
+
TQueryData = TQueryFnData,
|
|
71
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
72
|
+
TPageParam = unknown,
|
|
73
|
+
>(
|
|
74
|
+
options: DefinedInitialDataInfiniteOptions<
|
|
75
|
+
TQueryFnData,
|
|
76
|
+
TError,
|
|
77
|
+
TData,
|
|
78
|
+
TQueryFnData,
|
|
79
|
+
TQueryKey,
|
|
80
|
+
TPageParam
|
|
81
|
+
>,
|
|
82
|
+
): DefinedInitialDataInfiniteOptions<
|
|
83
|
+
TQueryFnData,
|
|
84
|
+
TError,
|
|
85
|
+
TData,
|
|
86
|
+
TQueryFnData,
|
|
87
|
+
TQueryKey,
|
|
88
|
+
TPageParam
|
|
89
|
+
>
|
|
90
|
+
|
|
91
|
+
export function infiniteQueryOptions(options: unknown) {
|
|
92
|
+
return options
|
|
93
|
+
}
|
|
@@ -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
|
+
QueryKey,
|
|
4
|
+
QueryObserver,
|
|
5
|
+
QueryObserverResult,
|
|
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/types.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
/* istanbul ignore file */
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
|
+
DefaultError,
|
|
5
|
+
DefinedInfiniteQueryObserverResult,
|
|
6
|
+
DefinedQueryObserverResult,
|
|
4
7
|
InfiniteQueryObserverOptions,
|
|
5
8
|
InfiniteQueryObserverResult,
|
|
9
|
+
InfiniteQueryObserverSuccessResult,
|
|
10
|
+
MutateFunction,
|
|
11
|
+
MutationObserverOptions,
|
|
6
12
|
MutationObserverResult,
|
|
13
|
+
QueryKey,
|
|
7
14
|
QueryObserverOptions,
|
|
8
15
|
QueryObserverResult,
|
|
9
|
-
|
|
10
|
-
MutationObserverOptions,
|
|
11
|
-
MutateFunction,
|
|
12
|
-
DefinedQueryObserverResult,
|
|
16
|
+
QueryObserverSuccessResult,
|
|
13
17
|
WithRequired,
|
|
14
|
-
DefaultError,
|
|
15
18
|
} from '@tanstack/query-core'
|
|
16
19
|
|
|
17
20
|
export interface UseBaseQueryOptions<
|
|
@@ -35,6 +38,16 @@ export interface UseQueryOptions<
|
|
|
35
38
|
'queryKey'
|
|
36
39
|
> {}
|
|
37
40
|
|
|
41
|
+
export interface UseSuspenseQueryOptions<
|
|
42
|
+
TQueryFnData = unknown,
|
|
43
|
+
TError = DefaultError,
|
|
44
|
+
TData = TQueryFnData,
|
|
45
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
46
|
+
> extends Omit<
|
|
47
|
+
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
48
|
+
'enabled' | 'suspense' | 'throwOnError' | 'placeholderData'
|
|
49
|
+
> {}
|
|
50
|
+
|
|
38
51
|
export interface UseInfiniteQueryOptions<
|
|
39
52
|
TQueryFnData = unknown,
|
|
40
53
|
TError = DefaultError,
|
|
@@ -54,6 +67,25 @@ export interface UseInfiniteQueryOptions<
|
|
|
54
67
|
'queryKey'
|
|
55
68
|
> {}
|
|
56
69
|
|
|
70
|
+
export interface UseSuspenseInfiniteQueryOptions<
|
|
71
|
+
TQueryFnData = unknown,
|
|
72
|
+
TError = DefaultError,
|
|
73
|
+
TData = TQueryFnData,
|
|
74
|
+
TQueryData = TQueryFnData,
|
|
75
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
76
|
+
TPageParam = unknown,
|
|
77
|
+
> extends Omit<
|
|
78
|
+
UseInfiniteQueryOptions<
|
|
79
|
+
TQueryFnData,
|
|
80
|
+
TError,
|
|
81
|
+
TData,
|
|
82
|
+
TQueryData,
|
|
83
|
+
TQueryKey,
|
|
84
|
+
TPageParam
|
|
85
|
+
>,
|
|
86
|
+
'enabled' | 'suspense' | 'throwOnError' | 'placeholderData'
|
|
87
|
+
> {}
|
|
88
|
+
|
|
57
89
|
export type UseBaseQueryResult<
|
|
58
90
|
TData = unknown,
|
|
59
91
|
TError = DefaultError,
|
|
@@ -64,21 +96,31 @@ export type UseQueryResult<
|
|
|
64
96
|
TError = DefaultError,
|
|
65
97
|
> = UseBaseQueryResult<TData, TError>
|
|
66
98
|
|
|
67
|
-
export type
|
|
99
|
+
export type UseSuspenseQueryResult<
|
|
68
100
|
TData = unknown,
|
|
69
101
|
TError = DefaultError,
|
|
70
|
-
> =
|
|
102
|
+
> = Omit<QueryObserverSuccessResult<TData, TError>, 'isPlaceholderData'>
|
|
71
103
|
|
|
72
104
|
export type DefinedUseQueryResult<
|
|
73
105
|
TData = unknown,
|
|
74
106
|
TError = DefaultError,
|
|
75
|
-
> =
|
|
107
|
+
> = DefinedQueryObserverResult<TData, TError>
|
|
76
108
|
|
|
77
109
|
export type UseInfiniteQueryResult<
|
|
78
110
|
TData = unknown,
|
|
79
111
|
TError = DefaultError,
|
|
80
112
|
> = InfiniteQueryObserverResult<TData, TError>
|
|
81
113
|
|
|
114
|
+
export type DefinedUseInfiniteQueryResult<
|
|
115
|
+
TData = unknown,
|
|
116
|
+
TError = DefaultError,
|
|
117
|
+
> = DefinedInfiniteQueryObserverResult<TData, TError>
|
|
118
|
+
|
|
119
|
+
export type UseSuspenseInfiniteQueryResult<
|
|
120
|
+
TData = unknown,
|
|
121
|
+
TError = DefaultError,
|
|
122
|
+
> = Omit<InfiniteQueryObserverSuccessResult<TData, TError>, 'isPlaceholderData'>
|
|
123
|
+
|
|
82
124
|
export interface UseMutationOptions<
|
|
83
125
|
TData = unknown,
|
|
84
126
|
TError = DefaultError,
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
|
-
import type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core'
|
|
5
4
|
import { notifyManager } from '@tanstack/query-core'
|
|
6
5
|
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'
|
|
7
6
|
import { useQueryClient } from './QueryClientProvider'
|
|
8
|
-
import type { UseBaseQueryOptions } from './types'
|
|
9
7
|
import { useIsRestoring } from './isRestoring'
|
|
10
8
|
import {
|
|
11
9
|
ensurePreventErrorBoundaryRetry,
|
|
12
10
|
getHasError,
|
|
13
11
|
useClearResetErrorBoundary,
|
|
14
12
|
} from './errorBoundaryUtils'
|
|
15
|
-
import { ensureStaleTime,
|
|
13
|
+
import { ensureStaleTime, fetchOptimistic, shouldSuspend } from './suspense'
|
|
14
|
+
import type { UseBaseQueryOptions } from './types'
|
|
15
|
+
import type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core'
|
|
16
16
|
|
|
17
17
|
export function useBaseQuery<
|
|
18
18
|
TQueryFnData,
|
|
@@ -41,25 +41,6 @@ export function useBaseQuery<
|
|
|
41
41
|
? 'isRestoring'
|
|
42
42
|
: 'optimistic'
|
|
43
43
|
|
|
44
|
-
// Include callbacks in batch renders
|
|
45
|
-
if (defaultedOptions.onError) {
|
|
46
|
-
defaultedOptions.onError = notifyManager.batchCalls(
|
|
47
|
-
defaultedOptions.onError,
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (defaultedOptions.onSuccess) {
|
|
52
|
-
defaultedOptions.onSuccess = notifyManager.batchCalls(
|
|
53
|
-
defaultedOptions.onSuccess,
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (defaultedOptions.onSettled) {
|
|
58
|
-
defaultedOptions.onSettled = notifyManager.batchCalls(
|
|
59
|
-
defaultedOptions.onSettled,
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
44
|
ensureStaleTime(defaultedOptions)
|
|
64
45
|
ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary)
|
|
65
46
|
|
|
@@ -77,10 +58,17 @@ export function useBaseQuery<
|
|
|
77
58
|
|
|
78
59
|
React.useSyncExternalStore(
|
|
79
60
|
React.useCallback(
|
|
80
|
-
(onStoreChange) =>
|
|
81
|
-
isRestoring
|
|
61
|
+
(onStoreChange) => {
|
|
62
|
+
const unsubscribe = isRestoring
|
|
82
63
|
? () => undefined
|
|
83
|
-
: 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
|
+
},
|
|
84
72
|
[observer, isRestoring],
|
|
85
73
|
),
|
|
86
74
|
() => observer.getCurrentResult(),
|
|
@@ -103,7 +91,7 @@ export function useBaseQuery<
|
|
|
103
91
|
getHasError({
|
|
104
92
|
result,
|
|
105
93
|
errorResetBoundary,
|
|
106
|
-
|
|
94
|
+
throwOnError: defaultedOptions.throwOnError,
|
|
107
95
|
query: observer.getCurrentQuery(),
|
|
108
96
|
})
|
|
109
97
|
) {
|
package/src/useInfiniteQuery.ts
CHANGED
|
@@ -1,16 +1,59 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
import { InfiniteQueryObserver } from '@tanstack/query-core'
|
|
3
|
+
import { useBaseQuery } from './useBaseQuery'
|
|
2
4
|
import type {
|
|
3
|
-
QueryObserver,
|
|
4
|
-
QueryKey,
|
|
5
|
-
QueryClient,
|
|
6
5
|
DefaultError,
|
|
7
6
|
InfiniteData,
|
|
7
|
+
QueryClient,
|
|
8
|
+
QueryKey,
|
|
9
|
+
QueryObserver,
|
|
8
10
|
} from '@tanstack/query-core'
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
import type {
|
|
12
|
+
DefinedUseInfiniteQueryResult,
|
|
13
|
+
UseInfiniteQueryOptions,
|
|
14
|
+
UseInfiniteQueryResult,
|
|
15
|
+
} from './types'
|
|
16
|
+
import type {
|
|
17
|
+
DefinedInitialDataInfiniteOptions,
|
|
18
|
+
UndefinedInitialDataInfiniteOptions,
|
|
19
|
+
} from './infiniteQueryOptions'
|
|
20
|
+
|
|
21
|
+
export function useInfiniteQuery<
|
|
22
|
+
TQueryFnData,
|
|
23
|
+
TError = DefaultError,
|
|
24
|
+
TData = InfiniteData<TQueryFnData>,
|
|
25
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
26
|
+
TPageParam = unknown,
|
|
27
|
+
>(
|
|
28
|
+
options: UndefinedInitialDataInfiniteOptions<
|
|
29
|
+
TQueryFnData,
|
|
30
|
+
TError,
|
|
31
|
+
TData,
|
|
32
|
+
TQueryFnData,
|
|
33
|
+
TQueryKey,
|
|
34
|
+
TPageParam
|
|
35
|
+
>,
|
|
36
|
+
queryClient?: QueryClient,
|
|
37
|
+
): UseInfiniteQueryResult<TData, TError>
|
|
38
|
+
|
|
39
|
+
export function useInfiniteQuery<
|
|
40
|
+
TQueryFnData,
|
|
41
|
+
TError = DefaultError,
|
|
42
|
+
TData = InfiniteData<TQueryFnData>,
|
|
43
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
44
|
+
TPageParam = unknown,
|
|
45
|
+
>(
|
|
46
|
+
options: DefinedInitialDataInfiniteOptions<
|
|
47
|
+
TQueryFnData,
|
|
48
|
+
TError,
|
|
49
|
+
TData,
|
|
50
|
+
TQueryFnData,
|
|
51
|
+
TQueryKey,
|
|
52
|
+
TPageParam
|
|
53
|
+
>,
|
|
54
|
+
queryClient?: QueryClient,
|
|
55
|
+
): DefinedUseInfiniteQueryResult<TData, TError>
|
|
12
56
|
|
|
13
|
-
// HOOK
|
|
14
57
|
export function useInfiniteQuery<
|
|
15
58
|
TQueryFnData,
|
|
16
59
|
TError = DefaultError,
|
package/src/useIsFetching.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
|
-
import type { QueryClient, QueryFilters } from '@tanstack/query-core'
|
|
4
3
|
import { notifyManager } from '@tanstack/query-core'
|
|
5
4
|
|
|
6
5
|
import { useQueryClient } from './QueryClientProvider'
|
|
6
|
+
import type { QueryClient, QueryFilters } from '@tanstack/query-core'
|
|
7
7
|
|
|
8
8
|
export function useIsFetching(
|
|
9
9
|
filters?: QueryFilters,
|
package/src/useMutation.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
|
-
import
|
|
4
|
-
import { notifyManager, MutationObserver } from '@tanstack/query-core'
|
|
3
|
+
import { MutationObserver, notifyManager } from '@tanstack/query-core'
|
|
5
4
|
import { useQueryClient } from './QueryClientProvider'
|
|
5
|
+
import { shouldThrowError } from './utils'
|
|
6
6
|
import type {
|
|
7
7
|
UseMutateFunction,
|
|
8
8
|
UseMutationOptions,
|
|
9
9
|
UseMutationResult,
|
|
10
10
|
} from './types'
|
|
11
|
-
import {
|
|
11
|
+
import type { DefaultError, QueryClient } from '@tanstack/query-core'
|
|
12
12
|
|
|
13
13
|
// HOOK
|
|
14
14
|
|
|
@@ -56,7 +56,7 @@ export function useMutation<
|
|
|
56
56
|
|
|
57
57
|
if (
|
|
58
58
|
result.error &&
|
|
59
|
-
shouldThrowError(observer.options.
|
|
59
|
+
shouldThrowError(observer.options.throwOnError, [result.error])
|
|
60
60
|
) {
|
|
61
61
|
throw result.error
|
|
62
62
|
}
|
package/src/useMutationState.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
|
+
import { notifyManager, replaceEqualDeep } from '@tanstack/query-core'
|
|
5
|
+
import { useQueryClient } from './QueryClientProvider'
|
|
4
6
|
import type {
|
|
5
|
-
|
|
6
|
-
QueryClient,
|
|
7
|
+
DefaultError,
|
|
7
8
|
Mutation,
|
|
8
9
|
MutationCache,
|
|
9
|
-
|
|
10
|
+
MutationFilters,
|
|
11
|
+
MutationState,
|
|
12
|
+
QueryClient,
|
|
10
13
|
} from '@tanstack/query-core'
|
|
11
|
-
import { notifyManager, replaceEqualDeep } from '@tanstack/query-core'
|
|
12
|
-
import { useQueryClient } from './QueryClientProvider'
|
|
13
|
-
import type { MutationState } from '@tanstack/query-core/build/lib/mutation'
|
|
14
14
|
|
|
15
15
|
export function useIsMutating(
|
|
16
16
|
filters?: MutationFilters,
|
|
@@ -23,7 +23,7 @@ export function useIsMutating(
|
|
|
23
23
|
).length
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
type MutationStateOptions<TResult> = {
|
|
26
|
+
type MutationStateOptions<TResult = MutationState> = {
|
|
27
27
|
filters?: MutationFilters
|
|
28
28
|
select?: (
|
|
29
29
|
mutation: Mutation<unknown, DefaultError, unknown, unknown>,
|
|
@@ -46,7 +46,7 @@ function getResult<TResult = MutationState>(
|
|
|
46
46
|
)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export function useMutationState<TResult =
|
|
49
|
+
export function useMutationState<TResult = MutationState>(
|
|
50
50
|
options: MutationStateOptions<TResult> = {},
|
|
51
51
|
queryClient?: QueryClient,
|
|
52
52
|
): Array<TResult> {
|