@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
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
module.exports = ({ root, jscodeshift }) => {
|
|
2
|
+
const findImportIdentifierOf = (importSpecifiers, identifier) => {
|
|
3
|
+
const specifier = importSpecifiers
|
|
4
|
+
.filter((node) => node.value.imported.name === identifier)
|
|
5
|
+
.paths()
|
|
6
|
+
|
|
7
|
+
if (specifier.length > 0) {
|
|
8
|
+
return specifier[0].value.local
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return jscodeshift.identifier(identifier)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const findImportSpecifiers = () =>
|
|
15
|
+
root
|
|
16
|
+
.find(jscodeshift.ImportDeclaration, {
|
|
17
|
+
source: {
|
|
18
|
+
value: 'react-query',
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
.find(jscodeshift.ImportSpecifier, {})
|
|
22
|
+
|
|
23
|
+
const locateImports = (identifiers) => {
|
|
24
|
+
const findNamespaceImportIdentifier = () => {
|
|
25
|
+
const specifier = root
|
|
26
|
+
.find(jscodeshift.ImportDeclaration, {
|
|
27
|
+
source: {
|
|
28
|
+
value: 'react-query',
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
.find(jscodeshift.ImportNamespaceSpecifier)
|
|
32
|
+
.paths()
|
|
33
|
+
|
|
34
|
+
return specifier.length > 0 ? specifier[0].value.local : null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* First, we search for the namespace import identifier because if we have any, we assume the consumer uses
|
|
39
|
+
* namespace imports. In this case, we won't search for named imports at all.
|
|
40
|
+
*/
|
|
41
|
+
const namespaceImportIdentifier = findNamespaceImportIdentifier()
|
|
42
|
+
|
|
43
|
+
if (namespaceImportIdentifier) {
|
|
44
|
+
const identifierMap = {}
|
|
45
|
+
|
|
46
|
+
for (const identifier of identifiers) {
|
|
47
|
+
identifierMap[identifier] = jscodeshift.identifier(identifier)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
namespace: namespaceImportIdentifier,
|
|
52
|
+
...identifierMap,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const importSpecifiers = findImportSpecifiers()
|
|
57
|
+
const identifierMap = {}
|
|
58
|
+
|
|
59
|
+
for (const identifier of identifiers) {
|
|
60
|
+
identifierMap[identifier] = findImportIdentifierOf(
|
|
61
|
+
importSpecifiers,
|
|
62
|
+
identifier,
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
namespace: null,
|
|
68
|
+
...identifierMap,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const findAllMethodCalls = () =>
|
|
73
|
+
root
|
|
74
|
+
// First, we need to find all method calls.
|
|
75
|
+
.find(jscodeshift.CallExpression, {
|
|
76
|
+
callee: {
|
|
77
|
+
type: jscodeshift.MemberExpression.name,
|
|
78
|
+
property: {
|
|
79
|
+
type: jscodeshift.Identifier.name,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const findQueryClientIdentifiers = (importIdentifiers) =>
|
|
85
|
+
root
|
|
86
|
+
.find(jscodeshift.VariableDeclarator, {})
|
|
87
|
+
.filter((node) => {
|
|
88
|
+
if (node.value.init) {
|
|
89
|
+
const initializer = node.value.init
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
isClassInstantiationOf(
|
|
93
|
+
initializer,
|
|
94
|
+
getSelectorByImports(importIdentifiers, 'QueryClient'),
|
|
95
|
+
) ||
|
|
96
|
+
isFunctionCallOf(
|
|
97
|
+
initializer,
|
|
98
|
+
getSelectorByImports(importIdentifiers, 'useQueryClient'),
|
|
99
|
+
)
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return false
|
|
104
|
+
})
|
|
105
|
+
.paths()
|
|
106
|
+
.map((node) => node.value.id.name)
|
|
107
|
+
|
|
108
|
+
const isCallExpression = (node) =>
|
|
109
|
+
jscodeshift.match(node, { type: jscodeshift.CallExpression.name })
|
|
110
|
+
|
|
111
|
+
const isIdentifier = (node) =>
|
|
112
|
+
jscodeshift.match(node, { type: jscodeshift.Identifier.name })
|
|
113
|
+
|
|
114
|
+
const isMemberExpression = (node) =>
|
|
115
|
+
jscodeshift.match(node, { type: jscodeshift.MemberExpression.name })
|
|
116
|
+
|
|
117
|
+
const isNewExpression = (node) =>
|
|
118
|
+
jscodeshift.match(node, { type: jscodeshift.NewExpression.name })
|
|
119
|
+
|
|
120
|
+
const isArrayExpression = (node) =>
|
|
121
|
+
jscodeshift.match(node, { type: jscodeshift.ArrayExpression.name })
|
|
122
|
+
|
|
123
|
+
const isObjectExpression = (node) =>
|
|
124
|
+
jscodeshift.match(node, { type: jscodeshift.ObjectExpression.name })
|
|
125
|
+
|
|
126
|
+
const isObjectProperty = (node) =>
|
|
127
|
+
jscodeshift.match(node, { type: jscodeshift.ObjectProperty.name })
|
|
128
|
+
|
|
129
|
+
const isSpreadElement = (node) =>
|
|
130
|
+
jscodeshift.match(node, { type: jscodeshift.SpreadElement.name })
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @param {import('jscodeshift').Node} node
|
|
134
|
+
* @returns {boolean}
|
|
135
|
+
*/
|
|
136
|
+
const isFunctionDefinition = (node) => {
|
|
137
|
+
const isArrowFunctionExpression = jscodeshift.match(node, {
|
|
138
|
+
type: jscodeshift.ArrowFunctionExpression.name,
|
|
139
|
+
})
|
|
140
|
+
const isFunctionExpression = jscodeshift.match(node, {
|
|
141
|
+
type: jscodeshift.FunctionExpression.name,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
return isArrowFunctionExpression || isFunctionExpression
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const warn = (message) => {
|
|
148
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
149
|
+
console.warn(message)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const isClassInstantiationOf = (node, selector) => {
|
|
154
|
+
if (!isNewExpression(node)) {
|
|
155
|
+
return false
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const parts = selector.split('.')
|
|
159
|
+
|
|
160
|
+
return parts.length === 1
|
|
161
|
+
? isIdentifier(node.callee) && node.callee.name === parts[0]
|
|
162
|
+
: isMemberExpression(node.callee) &&
|
|
163
|
+
node.callee.object.name === parts[0] &&
|
|
164
|
+
node.callee.property.name === parts[1]
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const isFunctionCallOf = (node, selector) => {
|
|
168
|
+
if (!isCallExpression(node)) {
|
|
169
|
+
return false
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const parts = selector.split('.')
|
|
173
|
+
|
|
174
|
+
return parts.length === 1
|
|
175
|
+
? isIdentifier(node.callee) && node.callee.name === parts[0]
|
|
176
|
+
: isMemberExpression(node.callee) &&
|
|
177
|
+
node.callee.object.name === parts[0] &&
|
|
178
|
+
node.callee.property.name === parts[1]
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const getSelectorByImports = (imports, path) =>
|
|
182
|
+
imports.namespace
|
|
183
|
+
? `${imports.namespace.name}.${imports[path].name}`
|
|
184
|
+
: imports[path].name
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
findAllMethodCalls,
|
|
188
|
+
getSelectorByImports,
|
|
189
|
+
isCallExpression,
|
|
190
|
+
isClassInstantiationOf,
|
|
191
|
+
isFunctionCallOf,
|
|
192
|
+
isIdentifier,
|
|
193
|
+
isMemberExpression,
|
|
194
|
+
isArrayExpression,
|
|
195
|
+
isObjectExpression,
|
|
196
|
+
isObjectProperty,
|
|
197
|
+
isSpreadElement,
|
|
198
|
+
isFunctionDefinition,
|
|
199
|
+
locateImports,
|
|
200
|
+
warn,
|
|
201
|
+
queryClient: {
|
|
202
|
+
findQueryClientIdentifiers,
|
|
203
|
+
},
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
+
const createUtilsObject = require('../utils')
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
4
|
+
const createKeyReplacer = require('./utils/replacers/key-replacer')
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
6
|
+
const createUseQueryLikeTransformer = require('../utils/transformers/use-query-like-transformer')
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
8
|
+
const createQueryClientTransformer = require('../utils/transformers/query-client-transformer')
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10
|
+
const createQueryCacheTransformer = require('../utils/transformers/query-cache-transformer')
|
|
11
|
+
|
|
12
|
+
const transformQueryClientUsages = ({ jscodeshift, utils, root, filePath }) => {
|
|
13
|
+
const transformer = createQueryClientTransformer({ jscodeshift, utils, root })
|
|
14
|
+
const replacer = createKeyReplacer({ jscodeshift, root, filePath })
|
|
15
|
+
|
|
16
|
+
transformer.execute(
|
|
17
|
+
[
|
|
18
|
+
// Not object syntax-aware methods.
|
|
19
|
+
'getMutationDefaults',
|
|
20
|
+
'getQueriesData',
|
|
21
|
+
'getQueryData',
|
|
22
|
+
'getQueryDefaults',
|
|
23
|
+
'getQueryState',
|
|
24
|
+
'isFetching',
|
|
25
|
+
'setMutationDefaults',
|
|
26
|
+
'setQueriesData',
|
|
27
|
+
'setQueryData',
|
|
28
|
+
'setQueryDefaults',
|
|
29
|
+
// Object syntax-aware methods.
|
|
30
|
+
'cancelQueries',
|
|
31
|
+
'fetchInfiniteQuery',
|
|
32
|
+
'fetchQuery',
|
|
33
|
+
'invalidateQueries',
|
|
34
|
+
'prefetchInfiniteQuery',
|
|
35
|
+
'prefetchQuery',
|
|
36
|
+
'refetchQueries',
|
|
37
|
+
'removeQueries',
|
|
38
|
+
'resetQueries',
|
|
39
|
+
],
|
|
40
|
+
replacer,
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const transformUseQueriesUsages = ({ jscodeshift, utils, root }) => {
|
|
45
|
+
const transformer = createUseQueryLikeTransformer({
|
|
46
|
+
jscodeshift,
|
|
47
|
+
utils,
|
|
48
|
+
root,
|
|
49
|
+
})
|
|
50
|
+
const replacer = ({ node }) => {
|
|
51
|
+
/**
|
|
52
|
+
* When the node doesn't have the 'original' property, that means the codemod has been already applied,
|
|
53
|
+
* so we don't need to do any changes.
|
|
54
|
+
*/
|
|
55
|
+
if (!node.original) {
|
|
56
|
+
return node
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const newCallExpression = jscodeshift.callExpression(node.original.callee, [
|
|
60
|
+
jscodeshift.objectExpression([
|
|
61
|
+
jscodeshift.property(
|
|
62
|
+
'init',
|
|
63
|
+
jscodeshift.identifier('queries'),
|
|
64
|
+
node.original.arguments[0],
|
|
65
|
+
),
|
|
66
|
+
]),
|
|
67
|
+
])
|
|
68
|
+
|
|
69
|
+
// TODO: This should be part of one function!
|
|
70
|
+
if (node.typeParameters) {
|
|
71
|
+
newCallExpression.typeArguments = node.typeParameters
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return newCallExpression
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
transformer.execute(['useQueries'], replacer)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const transformUseQueryLikeUsages = ({
|
|
81
|
+
jscodeshift,
|
|
82
|
+
utils,
|
|
83
|
+
root,
|
|
84
|
+
filePath,
|
|
85
|
+
}) => {
|
|
86
|
+
const transformer = createUseQueryLikeTransformer({
|
|
87
|
+
jscodeshift,
|
|
88
|
+
utils,
|
|
89
|
+
root,
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
transformer.execute(
|
|
93
|
+
['useQuery', 'useInfiniteQuery', 'useIsFetching', 'useIsMutating'],
|
|
94
|
+
createKeyReplacer({
|
|
95
|
+
jscodeshift,
|
|
96
|
+
root,
|
|
97
|
+
filePath,
|
|
98
|
+
keyName: 'queryKey',
|
|
99
|
+
}),
|
|
100
|
+
)
|
|
101
|
+
transformer.execute(
|
|
102
|
+
['useMutation'],
|
|
103
|
+
createKeyReplacer({
|
|
104
|
+
jscodeshift,
|
|
105
|
+
root,
|
|
106
|
+
filePath,
|
|
107
|
+
keyName: 'mutationKey',
|
|
108
|
+
}),
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const transformQueryCacheUsages = ({ jscodeshift, utils, root, filePath }) => {
|
|
113
|
+
const transformer = createQueryCacheTransformer({ jscodeshift, utils, root })
|
|
114
|
+
const replacer = createKeyReplacer({ jscodeshift, root, filePath })
|
|
115
|
+
|
|
116
|
+
transformer.execute(replacer)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = (file, api) => {
|
|
120
|
+
const jscodeshift = api.jscodeshift
|
|
121
|
+
const root = jscodeshift(file.source)
|
|
122
|
+
|
|
123
|
+
// TODO: Execute the transformers only when it contains a `react-query` import!
|
|
124
|
+
|
|
125
|
+
const utils = createUtilsObject({ root, jscodeshift })
|
|
126
|
+
const filePath = file.path
|
|
127
|
+
|
|
128
|
+
// This function transforms usages like `useQuery` and `useMutation`.
|
|
129
|
+
transformUseQueryLikeUsages({ jscodeshift, utils, root, filePath })
|
|
130
|
+
// This function transforms usages of `useQueries`.
|
|
131
|
+
transformUseQueriesUsages({ jscodeshift, utils, root })
|
|
132
|
+
// This function transforms usages of `QueryClient`.
|
|
133
|
+
transformQueryClientUsages({ jscodeshift, utils, root, filePath })
|
|
134
|
+
// This function transforms usages of `QueryCache`.
|
|
135
|
+
transformQueryCacheUsages({ jscodeshift, utils, root, filePath })
|
|
136
|
+
|
|
137
|
+
return root.toSource({ quote: 'single', lineTerminator: '\n' })
|
|
138
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module.exports = (file, api) => {
|
|
2
|
+
const jscodeshift = api.jscodeshift
|
|
3
|
+
const root = jscodeshift(file.source)
|
|
4
|
+
|
|
5
|
+
const replacements = [
|
|
6
|
+
{ from: 'react-query', to: '@tanstack/react-query' },
|
|
7
|
+
{ from: 'react-query/devtools', to: '@tanstack/react-query-devtools' },
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
replacements.forEach(({ from, to }) => {
|
|
11
|
+
root
|
|
12
|
+
.find(jscodeshift.ImportDeclaration, {
|
|
13
|
+
source: {
|
|
14
|
+
value: from,
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
.replaceWith(({ node }) => {
|
|
18
|
+
node.source.value = to
|
|
19
|
+
|
|
20
|
+
return node
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
return root.toSource({ quote: 'single', lineTerminator: '\n' })
|
|
25
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
module.exports = ({ jscodeshift, utils, root }) => {
|
|
2
|
+
const isGetQueryCacheMethodCall = (
|
|
3
|
+
initializer,
|
|
4
|
+
importIdentifiers,
|
|
5
|
+
knownQueryClientIds,
|
|
6
|
+
) => {
|
|
7
|
+
const isKnownQueryClient = (node) =>
|
|
8
|
+
utils.isIdentifier(node) && knownQueryClientIds.includes(node.name)
|
|
9
|
+
|
|
10
|
+
const isGetQueryCacheIdentifier = (node) =>
|
|
11
|
+
utils.isIdentifier(node) && node.name === 'getQueryCache'
|
|
12
|
+
|
|
13
|
+
const isValidInitializer = (node) =>
|
|
14
|
+
utils.isCallExpression(node) && utils.isMemberExpression(node.callee)
|
|
15
|
+
|
|
16
|
+
if (isValidInitializer(initializer)) {
|
|
17
|
+
const instance = initializer.callee.object
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
isGetQueryCacheIdentifier(initializer.callee.property) &&
|
|
21
|
+
(isKnownQueryClient(instance) ||
|
|
22
|
+
utils.isFunctionCallOf(
|
|
23
|
+
instance,
|
|
24
|
+
utils.getSelectorByImports(importIdentifiers, 'useQueryClient'),
|
|
25
|
+
))
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const findQueryCacheInstantiations = (
|
|
33
|
+
importIdentifiers,
|
|
34
|
+
knownQueryClientIds,
|
|
35
|
+
) =>
|
|
36
|
+
root.find(jscodeshift.VariableDeclarator, {}).filter((node) => {
|
|
37
|
+
if (node.value.init) {
|
|
38
|
+
const initializer = node.value.init
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
utils.isClassInstantiationOf(
|
|
42
|
+
initializer,
|
|
43
|
+
utils.getSelectorByImports(importIdentifiers, 'QueryCache'),
|
|
44
|
+
) ||
|
|
45
|
+
isGetQueryCacheMethodCall(
|
|
46
|
+
initializer,
|
|
47
|
+
importIdentifiers,
|
|
48
|
+
knownQueryClientIds,
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return false
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const filterQueryCacheMethodCalls = (node) =>
|
|
57
|
+
utils.isIdentifier(node) && ['find', 'findAll'].includes(node.name)
|
|
58
|
+
|
|
59
|
+
const findQueryCacheMethodCalls = (importIdentifiers) => {
|
|
60
|
+
/**
|
|
61
|
+
* Here we collect all query client instantiations. We have to make aware of them because the query cache can be
|
|
62
|
+
* accessed by the query client as well.
|
|
63
|
+
*/
|
|
64
|
+
const queryClientIdentifiers =
|
|
65
|
+
utils.queryClient.findQueryClientIdentifiers(importIdentifiers)
|
|
66
|
+
/**
|
|
67
|
+
* Here we collect all query cache instantiations. The reason is simple: the methods can be called on query cache
|
|
68
|
+
* instances, to locate the possible usages we need to be aware of the identifier names.
|
|
69
|
+
*/
|
|
70
|
+
const queryCacheIdentifiers = findQueryCacheInstantiations(
|
|
71
|
+
importIdentifiers,
|
|
72
|
+
queryClientIdentifiers,
|
|
73
|
+
)
|
|
74
|
+
.paths()
|
|
75
|
+
.map((node) => node.value.id.name)
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
utils
|
|
79
|
+
// First, we need to find all method calls.
|
|
80
|
+
.findAllMethodCalls()
|
|
81
|
+
// Then we narrow the collection to all `fetch` and `fetchAll` methods.
|
|
82
|
+
.filter((node) =>
|
|
83
|
+
filterQueryCacheMethodCalls(node.value.callee.property),
|
|
84
|
+
)
|
|
85
|
+
.filter((node) => {
|
|
86
|
+
const object = node.value.callee.object
|
|
87
|
+
|
|
88
|
+
// If the method is called on a `QueryCache` instance, we keep it in the collection.
|
|
89
|
+
if (utils.isIdentifier(object)) {
|
|
90
|
+
return queryCacheIdentifiers.includes(object.name)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// If the method is called on a `QueryClient` instance, we keep it in the collection.
|
|
94
|
+
if (utils.isCallExpression(object)) {
|
|
95
|
+
return isGetQueryCacheMethodCall(
|
|
96
|
+
object,
|
|
97
|
+
importIdentifiers,
|
|
98
|
+
queryClientIdentifiers,
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return false
|
|
103
|
+
})
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const execute = (replacer) => {
|
|
108
|
+
findQueryCacheMethodCalls(
|
|
109
|
+
utils.locateImports(['QueryCache', 'QueryClient', 'useQueryClient']),
|
|
110
|
+
).replaceWith(replacer)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
execute,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module.exports = ({ jscodeshift, utils, root }) => {
|
|
2
|
+
const filterQueryClientMethodCalls = (node, methods) =>
|
|
3
|
+
utils.isIdentifier(node) && methods.includes(node.name)
|
|
4
|
+
|
|
5
|
+
const findQueryClientMethodCalls = (importIdentifiers, methods) => {
|
|
6
|
+
/**
|
|
7
|
+
* Here we collect all query client instantiations. We have to make aware of them because some method calls might
|
|
8
|
+
* be invoked on these instances.
|
|
9
|
+
*/
|
|
10
|
+
const queryClientIdentifiers =
|
|
11
|
+
utils.queryClient.findQueryClientIdentifiers(importIdentifiers)
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
utils
|
|
15
|
+
// First, we need to find all method calls.
|
|
16
|
+
.findAllMethodCalls()
|
|
17
|
+
// Then we narrow the collection to `QueryClient` methods.
|
|
18
|
+
.filter((node) =>
|
|
19
|
+
filterQueryClientMethodCalls(node.value.callee.property, methods),
|
|
20
|
+
)
|
|
21
|
+
.filter((node) => {
|
|
22
|
+
const object = node.value.callee.object
|
|
23
|
+
|
|
24
|
+
// If the method is called on a `QueryClient` instance, we keep it in the collection.
|
|
25
|
+
if (utils.isIdentifier(object)) {
|
|
26
|
+
return queryClientIdentifiers.includes(object.name)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// If the method is called on the return value of `useQueryClient` hook, we keep it in the collection.
|
|
30
|
+
return utils.isFunctionCallOf(
|
|
31
|
+
object,
|
|
32
|
+
utils.getSelectorByImports(importIdentifiers, 'useQueryClient'),
|
|
33
|
+
)
|
|
34
|
+
})
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const execute = (methods, replacer) => {
|
|
39
|
+
findQueryClientMethodCalls(
|
|
40
|
+
utils.locateImports(['QueryClient', 'useQueryClient']),
|
|
41
|
+
methods,
|
|
42
|
+
).replaceWith(replacer)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
execute,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module.exports = ({ jscodeshift, utils, root }) => {
|
|
2
|
+
const filterUseQueryLikeHookCalls = (node, importIdentifiers, hooks) => {
|
|
3
|
+
for (const hook of hooks) {
|
|
4
|
+
const selector = utils.getSelectorByImports(importIdentifiers, hook)
|
|
5
|
+
|
|
6
|
+
if (utils.isFunctionCallOf(node, selector)) {
|
|
7
|
+
return true
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const findUseQueryLikeHookCalls = (importIdentifiers, hooks) =>
|
|
15
|
+
root
|
|
16
|
+
// First, we need to find all call expressions.
|
|
17
|
+
.find(jscodeshift.CallExpression, {})
|
|
18
|
+
// Then we narrow the collection to the `useQuery` like hook calls.
|
|
19
|
+
.filter((node) =>
|
|
20
|
+
filterUseQueryLikeHookCalls(node.value, importIdentifiers, hooks),
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const execute = (hooks, replacer) => {
|
|
24
|
+
findUseQueryLikeHookCalls(utils.locateImports(hooks), hooks).replaceWith(
|
|
25
|
+
replacer,
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
execute,
|
|
31
|
+
}
|
|
32
|
+
}
|