@tanstack/react-query 5.0.0-alpha.9 → 5.0.0-alpha.90
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 +431 -453
- 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,59 @@
|
|
|
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 transformFilterAwareUsages = require('./transformers/filter-aware-usage-transformer')
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
6
|
+
const transformQueryFnAwareUsages = require('./transformers/query-fn-aware-usage-transformer')
|
|
7
|
+
|
|
8
|
+
module.exports = (file, api) => {
|
|
9
|
+
const jscodeshift = api.jscodeshift
|
|
10
|
+
const root = jscodeshift(file.source)
|
|
11
|
+
const utils = createUtilsObject({ root, jscodeshift })
|
|
12
|
+
const filePath = file.path
|
|
13
|
+
|
|
14
|
+
const dependencies = { jscodeshift, utils, root, filePath }
|
|
15
|
+
|
|
16
|
+
transformFilterAwareUsages({
|
|
17
|
+
...dependencies,
|
|
18
|
+
config: {
|
|
19
|
+
keyName: 'queryKey',
|
|
20
|
+
queryClientMethods: [
|
|
21
|
+
'cancelQueries',
|
|
22
|
+
'getQueriesData',
|
|
23
|
+
'invalidateQueries',
|
|
24
|
+
'isFetching',
|
|
25
|
+
'refetchQueries',
|
|
26
|
+
'removeQueries',
|
|
27
|
+
'resetQueries',
|
|
28
|
+
// 'setQueriesData',
|
|
29
|
+
],
|
|
30
|
+
hooks: ['useIsFetching'],
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
transformFilterAwareUsages({
|
|
35
|
+
...dependencies,
|
|
36
|
+
config: {
|
|
37
|
+
keyName: 'mutationKey',
|
|
38
|
+
queryClientMethods: [],
|
|
39
|
+
hooks: ['useIsMutating'],
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
transformQueryFnAwareUsages({
|
|
44
|
+
...dependencies,
|
|
45
|
+
config: {
|
|
46
|
+
keyName: 'queryKey',
|
|
47
|
+
queryClientMethods: [
|
|
48
|
+
'ensureQueryData',
|
|
49
|
+
'fetchQuery',
|
|
50
|
+
'prefetchQuery',
|
|
51
|
+
'fetchInfiniteQuery',
|
|
52
|
+
'prefetchInfiniteQuery',
|
|
53
|
+
],
|
|
54
|
+
hooks: [],
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return root.toSource({ quote: 'single', lineTerminator: '\n' })
|
|
59
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
+
const createV5UtilsObject = require('../utils')
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
4
|
+
const UnknownUsageError = require('../utils/unknown-usage-error')
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
6
|
+
const createQueryClientTransformer = require('../../../utils/transformers/query-client-transformer')
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
8
|
+
const createQueryCacheTransformer = require('../../../utils/transformers/query-cache-transformer')
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10
|
+
const createUseQueryLikeTransformer = require('../../../utils/transformers/use-query-like-transformer')
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {import('jscodeshift').api} jscodeshift
|
|
14
|
+
* @param {Object} utils
|
|
15
|
+
* @param {import('jscodeshift').Collection} root
|
|
16
|
+
* @param {string} filePath
|
|
17
|
+
* @param {{keyName: "mutationKey"|"queryKey", queryClientMethods: ReadonlyArray<string>, hooks: ReadonlyArray<string>}} config
|
|
18
|
+
*/
|
|
19
|
+
const transformFilterAwareUsages = ({
|
|
20
|
+
jscodeshift,
|
|
21
|
+
utils,
|
|
22
|
+
root,
|
|
23
|
+
filePath,
|
|
24
|
+
config,
|
|
25
|
+
}) => {
|
|
26
|
+
const v5Utils = createV5UtilsObject({ jscodeshift, utils })
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {import('jscodeshift').CallExpression} node
|
|
30
|
+
* @param {"mutationKey"|"queryKey"} keyName
|
|
31
|
+
* @returns {boolean}
|
|
32
|
+
*/
|
|
33
|
+
const canSkipReplacement = (node, keyName) => {
|
|
34
|
+
const callArguments = node.arguments
|
|
35
|
+
|
|
36
|
+
const hasKeyProperty = () =>
|
|
37
|
+
callArguments[0].properties.some(
|
|
38
|
+
(property) =>
|
|
39
|
+
utils.isObjectProperty(property) && property.key.name !== keyName,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* This call has at least one argument. If it's an object expression and contains the "queryKey" or "mutationKey"
|
|
44
|
+
* field, the transformation can be skipped, because it's already matching the expected signature.
|
|
45
|
+
*/
|
|
46
|
+
return (
|
|
47
|
+
callArguments.length > 0 &&
|
|
48
|
+
utils.isObjectExpression(callArguments[0]) &&
|
|
49
|
+
hasKeyProperty()
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* This function checks whether the given object property is a spread element or a property that's not named
|
|
55
|
+
* "queryKey" or "mutationKey".
|
|
56
|
+
*
|
|
57
|
+
* @param {import('jscodeshift').ObjectProperty} property
|
|
58
|
+
* @returns {boolean}
|
|
59
|
+
*/
|
|
60
|
+
const predicate = (property) => {
|
|
61
|
+
const isSpreadElement = utils.isSpreadElement(property)
|
|
62
|
+
const isObjectProperty = utils.isObjectProperty(property)
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
isSpreadElement ||
|
|
66
|
+
(isObjectProperty && property.key.name !== config.keyName)
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const replacer = (path) => {
|
|
71
|
+
const node = path.node
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
// If the given method/function call matches certain criteria, the node doesn't need to be replaced, this step can be skipped.
|
|
75
|
+
if (canSkipReplacement(node, config.keyName)) {
|
|
76
|
+
return node
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Here we attempt to determine the first parameter of the function call. If it's an array expression or an
|
|
81
|
+
* identifier that references an array expression then we create an object property from it.
|
|
82
|
+
*
|
|
83
|
+
* @type {import('jscodeshift').Property|undefined}
|
|
84
|
+
*/
|
|
85
|
+
const keyProperty = v5Utils.transformArgumentToKey(
|
|
86
|
+
path,
|
|
87
|
+
node.arguments[0],
|
|
88
|
+
config.keyName,
|
|
89
|
+
filePath,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The first parameter couldn't be transformed into an object property, so it's time to throw an exception,
|
|
94
|
+
* it will notify the consumers that they need to rewrite this usage manually.
|
|
95
|
+
*/
|
|
96
|
+
if (!keyProperty) {
|
|
97
|
+
throw new UnknownUsageError(node, filePath)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const parameters = [jscodeshift.objectExpression([keyProperty])]
|
|
101
|
+
const secondParameter = node.arguments[1]
|
|
102
|
+
|
|
103
|
+
if (secondParameter) {
|
|
104
|
+
const createdObjectExpression = parameters[0]
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* If it has a second argument, and it's an object expression, then we get the properties from it
|
|
108
|
+
* (except the "queryKey" or "mutationKey" properties), because these arguments will also be moved to the
|
|
109
|
+
* newly created object expression.
|
|
110
|
+
*/
|
|
111
|
+
if (utils.isObjectExpression(secondParameter)) {
|
|
112
|
+
v5Utils.copyPropertiesFromSource(
|
|
113
|
+
secondParameter,
|
|
114
|
+
createdObjectExpression,
|
|
115
|
+
predicate,
|
|
116
|
+
)
|
|
117
|
+
} else {
|
|
118
|
+
// Otherwise, we simply spread the second parameter in the newly created object expression.
|
|
119
|
+
createdObjectExpression.properties.push(
|
|
120
|
+
jscodeshift.spreadElement(secondParameter),
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// The rest of the parameters can be simply pushed to the parameters object so all will be kept.
|
|
126
|
+
parameters.push(...node.arguments.slice(2))
|
|
127
|
+
|
|
128
|
+
return jscodeshift.callExpression(node.original.callee, parameters)
|
|
129
|
+
} catch (error) {
|
|
130
|
+
utils.warn(
|
|
131
|
+
error.name === UnknownUsageError.name
|
|
132
|
+
? error.message
|
|
133
|
+
: `An unknown error occurred while processing the "${filePath}" file. Please review this file, because the codemod couldn't be applied.`,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
return node
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
createQueryClientTransformer({ jscodeshift, utils, root }).execute(
|
|
141
|
+
config.queryClientMethods,
|
|
142
|
+
replacer,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
createUseQueryLikeTransformer({ jscodeshift, utils, root }).execute(
|
|
146
|
+
config.hooks,
|
|
147
|
+
replacer,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
createQueryCacheTransformer({ jscodeshift, utils, root }).execute(replacer)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
module.exports = transformFilterAwareUsages
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
+
const createV5UtilsObject = require('../utils')
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
4
|
+
const UnknownUsageError = require('../utils/unknown-usage-error')
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
6
|
+
const createQueryClientTransformer = require('../../../utils/transformers/query-client-transformer')
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {import('jscodeshift').api} jscodeshift
|
|
10
|
+
* @param {Object} utils
|
|
11
|
+
* @param {import('jscodeshift').Collection} root
|
|
12
|
+
* @param {string} filePath
|
|
13
|
+
* @param {{keyName: "mutationKey"|"queryKey", queryClientMethods: ReadonlyArray<string>, hooks: ReadonlyArray<string>}} config
|
|
14
|
+
*/
|
|
15
|
+
const transformQueryFnAwareUsages = ({
|
|
16
|
+
jscodeshift,
|
|
17
|
+
utils,
|
|
18
|
+
root,
|
|
19
|
+
filePath,
|
|
20
|
+
config,
|
|
21
|
+
}) => {
|
|
22
|
+
const v5Utils = createV5UtilsObject({ jscodeshift, utils })
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {import('jscodeshift').CallExpression} node
|
|
26
|
+
* @returns {boolean}
|
|
27
|
+
*/
|
|
28
|
+
const canSkipReplacement = (node) => {
|
|
29
|
+
const callArguments = node.arguments
|
|
30
|
+
|
|
31
|
+
const hasKeyProperty = () =>
|
|
32
|
+
callArguments[0].properties.some(
|
|
33
|
+
(property) =>
|
|
34
|
+
utils.isObjectProperty(property) &&
|
|
35
|
+
[config.keyName, 'queryFn'].includes(property.key.name),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
callArguments.length > 0 &&
|
|
40
|
+
utils.isObjectExpression(callArguments[0]) &&
|
|
41
|
+
hasKeyProperty()
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const predicate = (property) => {
|
|
46
|
+
const isSpreadElement = utils.isSpreadElement(property)
|
|
47
|
+
const isObjectProperty = utils.isObjectProperty(property)
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
isSpreadElement ||
|
|
51
|
+
(isObjectProperty && property.key.name !== config.keyName)
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const transformArgumentToQueryFunction = (path, node) => {
|
|
56
|
+
const isIdentifier = utils.isIdentifier(node)
|
|
57
|
+
const isFunctionDefinition = utils.isFunctionDefinition(node)
|
|
58
|
+
|
|
59
|
+
if (!isIdentifier && !isFunctionDefinition) {
|
|
60
|
+
return undefined
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (isFunctionDefinition) {
|
|
64
|
+
return jscodeshift.property(
|
|
65
|
+
'init',
|
|
66
|
+
jscodeshift.identifier('queryFn'),
|
|
67
|
+
node,
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const binding = v5Utils.getBindingFromScope(path, node.name, filePath)
|
|
72
|
+
const initializer = v5Utils.getInitializerByDeclarator(binding)
|
|
73
|
+
|
|
74
|
+
if (!utils.isFunctionDefinition(initializer)) {
|
|
75
|
+
return undefined
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return jscodeshift.property(
|
|
79
|
+
'init',
|
|
80
|
+
jscodeshift.identifier('queryFn'),
|
|
81
|
+
binding.id,
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const transformArgumentToOptionsObject = (path, node) => {
|
|
86
|
+
if (!utils.isIdentifier(node)) {
|
|
87
|
+
return undefined
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const binding = v5Utils.getBindingFromScope(path, node.name, filePath)
|
|
91
|
+
const initializer = v5Utils.getInitializerByDeclarator(binding)
|
|
92
|
+
|
|
93
|
+
if (utils.isObjectExpression(initializer)) {
|
|
94
|
+
return jscodeshift.spreadElement(binding.id)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const replacer = (path) => {
|
|
99
|
+
const node = path.node
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
// If the given method/function call matches certain criteria, the node doesn't need to be replaced, this step can be skipped.
|
|
103
|
+
if (canSkipReplacement(node)) {
|
|
104
|
+
return node
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const keyProperty = v5Utils.transformArgumentToKey(
|
|
108
|
+
path,
|
|
109
|
+
node.arguments[0],
|
|
110
|
+
config.keyName,
|
|
111
|
+
filePath,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
if (!keyProperty) {
|
|
115
|
+
throw new UnknownUsageError(node, filePath)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const parameters = [jscodeshift.objectExpression([keyProperty])]
|
|
119
|
+
const createdObjectExpression = parameters[0]
|
|
120
|
+
const secondParameter = node.arguments[1]
|
|
121
|
+
|
|
122
|
+
if (secondParameter) {
|
|
123
|
+
const queryFnProperty = transformArgumentToQueryFunction(
|
|
124
|
+
path,
|
|
125
|
+
secondParameter,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
if (queryFnProperty) {
|
|
129
|
+
createdObjectExpression.properties.push(queryFnProperty)
|
|
130
|
+
|
|
131
|
+
const thirdParameter = node.arguments[2]
|
|
132
|
+
|
|
133
|
+
if (utils.isObjectExpression(thirdParameter)) {
|
|
134
|
+
v5Utils.copyPropertiesFromSource(
|
|
135
|
+
thirdParameter,
|
|
136
|
+
createdObjectExpression,
|
|
137
|
+
predicate,
|
|
138
|
+
)
|
|
139
|
+
} else {
|
|
140
|
+
createdObjectExpression.properties.push(
|
|
141
|
+
jscodeshift.spreadElement(thirdParameter),
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return jscodeshift.callExpression(node.original.callee, parameters)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const optionsProperty = transformArgumentToOptionsObject(
|
|
149
|
+
path,
|
|
150
|
+
secondParameter,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
if (optionsProperty) {
|
|
154
|
+
createdObjectExpression.properties.push(optionsProperty)
|
|
155
|
+
|
|
156
|
+
return jscodeshift.callExpression(node.original.callee, parameters)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (utils.isObjectExpression(secondParameter)) {
|
|
160
|
+
v5Utils.copyPropertiesFromSource(
|
|
161
|
+
secondParameter,
|
|
162
|
+
createdObjectExpression,
|
|
163
|
+
predicate,
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return jscodeshift.callExpression(node.original.callee, parameters)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return jscodeshift.callExpression(node.original.callee, parameters)
|
|
171
|
+
} catch (error) {
|
|
172
|
+
utils.warn(
|
|
173
|
+
error.name === UnknownUsageError.name
|
|
174
|
+
? error.message
|
|
175
|
+
: `An unknown error occurred while processing the "${filePath}" file. Please review this file, because the codemod couldn't be applied.`,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
return node
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
createQueryClientTransformer({ jscodeshift, utils, root }).execute(
|
|
183
|
+
config.queryClientMethods,
|
|
184
|
+
replacer,
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
module.exports = transformQueryFnAwareUsages
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
+
const UnknownUsageError = require('./unknown-usage-error')
|
|
3
|
+
|
|
4
|
+
module.exports = ({ jscodeshift, utils }) => {
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {import('jscodeshift').ObjectExpression} source
|
|
8
|
+
* @param {import('jscodeshift').ObjectExpression} target
|
|
9
|
+
* @param {(node: import('jscodeshift').Node) => boolean} predicate
|
|
10
|
+
*/
|
|
11
|
+
const copyPropertiesFromSource = (source, target, predicate) => {
|
|
12
|
+
source.properties.forEach((property) => {
|
|
13
|
+
if (predicate(property)) {
|
|
14
|
+
target.properties.push(property)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {import('jscodeshift').NodePath} path
|
|
21
|
+
* @param {string} argumentName
|
|
22
|
+
* @param {string} filePath
|
|
23
|
+
* @returns {*}
|
|
24
|
+
*/
|
|
25
|
+
const getBindingFromScope = (path, argumentName, filePath) => {
|
|
26
|
+
/**
|
|
27
|
+
* If the current scope contains the declaration then we can use the actual one else we attempt to find the
|
|
28
|
+
* binding from above.
|
|
29
|
+
*/
|
|
30
|
+
const scope = path.scope.declares(argumentName)
|
|
31
|
+
? path.scope
|
|
32
|
+
: path.scope.lookup(argumentName)
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The declaration couldn't be found for some reason, time to move on. We warn the user it needs to be rewritten
|
|
36
|
+
* by themselves.
|
|
37
|
+
*/
|
|
38
|
+
if (!scope) {
|
|
39
|
+
return undefined
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const binding = scope.bindings[argumentName]
|
|
43
|
+
.filter((item) => utils.isIdentifier(item.value))
|
|
44
|
+
.map((item) => item.parentPath.value)
|
|
45
|
+
.at(0)
|
|
46
|
+
|
|
47
|
+
if (!binding) {
|
|
48
|
+
throw new UnknownUsageError(path.node, filePath)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return binding
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {import('jscodeshift').VariableDeclarator} binding
|
|
56
|
+
* @returns {import('jscodeshift').Node|undefined}
|
|
57
|
+
*/
|
|
58
|
+
const getInitializerByDeclarator = (binding) => {
|
|
59
|
+
const isVariableDeclaration = jscodeshift.match(binding, {
|
|
60
|
+
type: jscodeshift.VariableDeclarator.name,
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
if (!isVariableDeclaration) {
|
|
64
|
+
return undefined
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const isTSAsExpression = jscodeshift.match(binding.init, {
|
|
68
|
+
type: jscodeshift.TSAsExpression.name,
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
return isTSAsExpression ? binding.init.expression : binding.init
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {import('jscodeshift').Node} node
|
|
76
|
+
* @returns {boolean}
|
|
77
|
+
*/
|
|
78
|
+
const isArrayExpressionVariable = (node) =>
|
|
79
|
+
jscodeshift.match(node, {
|
|
80
|
+
type: jscodeshift.VariableDeclarator.name,
|
|
81
|
+
init: {
|
|
82
|
+
type: jscodeshift.ArrayExpression.name,
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {import('jscodeshift').NodePath} path
|
|
88
|
+
* @param {import('jscodeshift').Node} node
|
|
89
|
+
* @param {"queryKey"|"mutationKey"} keyName
|
|
90
|
+
* @param {string} filePath
|
|
91
|
+
* @returns {import('jscodeshift').Property|undefined}
|
|
92
|
+
*/
|
|
93
|
+
const transformArgumentToKey = (path, node, keyName, filePath) => {
|
|
94
|
+
// If the first argument is an identifier we have to infer its type if possible.
|
|
95
|
+
if (utils.isIdentifier(node)) {
|
|
96
|
+
const binding = getBindingFromScope(path, node.name, filePath)
|
|
97
|
+
|
|
98
|
+
if (isArrayExpressionVariable(binding)) {
|
|
99
|
+
return jscodeshift.property(
|
|
100
|
+
'init',
|
|
101
|
+
jscodeshift.identifier(keyName),
|
|
102
|
+
jscodeshift.identifier(binding.id.name),
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// If the first argument is an array, then it matches the following overload:
|
|
108
|
+
// methodName(queryKey?: QueryKey, firstObject?: TFirstObject, secondObject?: TSecondObject)
|
|
109
|
+
if (utils.isArrayExpression(node)) {
|
|
110
|
+
// Then we create the 'queryKey' property based on it, because it will be passed to the first argument
|
|
111
|
+
// that should be an object according to the new signature.
|
|
112
|
+
return jscodeshift.property('init', jscodeshift.identifier(keyName), node)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return undefined
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
copyPropertiesFromSource,
|
|
120
|
+
getInitializerByDeclarator,
|
|
121
|
+
getBindingFromScope,
|
|
122
|
+
transformArgumentToKey,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class UnknownUsageError extends Error {
|
|
2
|
+
/**
|
|
3
|
+
* @param {import('jscodeshift').CallExpression} callExpression
|
|
4
|
+
* @param {string} filePath
|
|
5
|
+
*/
|
|
6
|
+
constructor(callExpression, filePath) {
|
|
7
|
+
super('')
|
|
8
|
+
this.message = this.buildMessage(callExpression, filePath)
|
|
9
|
+
this.name = 'UnknownUsageError'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {import('jscodeshift').CallExpression} callExpression
|
|
15
|
+
* @param {string} filePath
|
|
16
|
+
* @returns {string}
|
|
17
|
+
*/
|
|
18
|
+
buildMessage(callExpression, filePath) {
|
|
19
|
+
const location = callExpression.callee.loc
|
|
20
|
+
const start = location.start.line
|
|
21
|
+
const end = location.end.line
|
|
22
|
+
|
|
23
|
+
return `The usage in file "${filePath}" at line ${start}:${end} could not be transformed into the new syntax. Please do this manually.`
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = UnknownUsageError
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module.exports = (file, api) => {
|
|
2
|
+
const jscodeshift = api.jscodeshift
|
|
3
|
+
const root = jscodeshift(file.source)
|
|
4
|
+
|
|
5
|
+
const importSpecifiers = root
|
|
6
|
+
.find(jscodeshift.ImportDeclaration, {
|
|
7
|
+
source: {
|
|
8
|
+
value: '@tanstack/react-query',
|
|
9
|
+
},
|
|
10
|
+
})
|
|
11
|
+
.find(jscodeshift.ImportSpecifier, {
|
|
12
|
+
imported: {
|
|
13
|
+
name: 'Hydrate',
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
if (importSpecifiers.length > 0) {
|
|
18
|
+
const names = {
|
|
19
|
+
searched: 'Hydrate', // By default, we want to replace the `Hydrate` usages.
|
|
20
|
+
target: 'HydrationBoundary', // We want to replace them with `HydrationBoundary`.
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
importSpecifiers.replaceWith(({ node: mutableNode }) => {
|
|
24
|
+
/**
|
|
25
|
+
* When the local and imported names match which means the code doesn't contain import aliases, we need
|
|
26
|
+
* to replace only the import specifier.
|
|
27
|
+
* @type {boolean}
|
|
28
|
+
*/
|
|
29
|
+
const usesDefaultImport =
|
|
30
|
+
mutableNode.local.name === mutableNode.imported.name
|
|
31
|
+
|
|
32
|
+
if (!usesDefaultImport) {
|
|
33
|
+
// If the code uses import aliases, we must re-use the alias.
|
|
34
|
+
names.searched = mutableNode.local.name
|
|
35
|
+
names.target = mutableNode.local.name
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Override the import specifier.
|
|
39
|
+
mutableNode.imported.name = 'HydrationBoundary'
|
|
40
|
+
|
|
41
|
+
return mutableNode
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
root
|
|
45
|
+
.findJSXElements(names.searched)
|
|
46
|
+
.replaceWith(({ node: mutableNode }) => {
|
|
47
|
+
mutableNode.openingElement.name.name = names.target
|
|
48
|
+
mutableNode.closingElement.name.name = names.target
|
|
49
|
+
|
|
50
|
+
return mutableNode
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return root.toSource({ quote: 'single', lineTerminator: '\n' })
|
|
55
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module.exports = (file, api) => {
|
|
2
|
+
const jscodeshift = api.jscodeshift
|
|
3
|
+
const root = jscodeshift(file.source)
|
|
4
|
+
|
|
5
|
+
const baseRenameLogic = (kind, from, to) => {
|
|
6
|
+
root
|
|
7
|
+
.find(kind, (node) => {
|
|
8
|
+
return (
|
|
9
|
+
node.computed === false &&
|
|
10
|
+
(node.key?.name === from || node.key?.value === from)
|
|
11
|
+
)
|
|
12
|
+
})
|
|
13
|
+
.replaceWith(({ node: mutableNode }) => {
|
|
14
|
+
if (mutableNode.key.name !== undefined) {
|
|
15
|
+
mutableNode.key.name = to
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (mutableNode.key.value !== undefined) {
|
|
19
|
+
mutableNode.key.value = to
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return mutableNode
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const renameObjectProperty = (from, to) => {
|
|
27
|
+
baseRenameLogic(jscodeshift.ObjectProperty, from, to)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const renameTypeScriptPropertySignature = (from, to) => {
|
|
31
|
+
baseRenameLogic(jscodeshift.TSPropertySignature, from, to)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
renameObjectProperty('cacheTime', 'gcTime')
|
|
35
|
+
renameObjectProperty('useErrorBoundary', 'throwOnError')
|
|
36
|
+
|
|
37
|
+
renameTypeScriptPropertySignature('cacheTime', 'gcTime')
|
|
38
|
+
renameTypeScriptPropertySignature('useErrorBoundary', 'throwOnError')
|
|
39
|
+
|
|
40
|
+
return root.toSource({ quote: 'single', lineTerminator: '\n' })
|
|
41
|
+
}
|