@tanstack/preact-query 0.0.1 → 5.91.0
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/LICENSE +21 -0
- package/README.md +48 -45
- package/build/codemods/src/utils/index.cjs +208 -0
- package/build/codemods/src/utils/transformers/query-cache-transformer.cjs +124 -0
- package/build/codemods/src/utils/transformers/query-client-transformer.cjs +53 -0
- package/build/codemods/src/utils/transformers/use-query-like-transformer.cjs +38 -0
- package/build/codemods/src/v4/key-transformation.cjs +181 -0
- package/build/codemods/src/v4/replace-import-specifier.cjs +25 -0
- package/build/codemods/src/v4/utils/replacers/key-replacer.cjs +164 -0
- package/build/codemods/src/v5/is-loading/is-loading.cjs +244 -0
- package/build/codemods/src/v5/keep-previous-data/README.md +32 -0
- package/build/codemods/src/v5/keep-previous-data/keep-previous-data.cjs +271 -0
- package/build/codemods/src/v5/keep-previous-data/utils/already-has-placeholder-data-property.cjs +26 -0
- package/build/codemods/src/v5/remove-overloads/remove-overloads.cjs +58 -0
- package/build/codemods/src/v5/remove-overloads/transformers/filter-aware-usage-transformer.cjs +271 -0
- package/build/codemods/src/v5/remove-overloads/transformers/query-fn-aware-usage-transformer.cjs +185 -0
- package/build/codemods/src/v5/remove-overloads/utils/index.cjs +123 -0
- package/build/codemods/src/v5/remove-overloads/utils/unknown-usage-error.cjs +27 -0
- package/build/codemods/src/v5/rename-hydrate/rename-hydrate.cjs +55 -0
- package/build/codemods/src/v5/rename-properties/rename-properties.cjs +41 -0
- package/build/legacy/HydrationBoundary.cjs +80 -0
- package/build/legacy/HydrationBoundary.cjs.map +1 -0
- package/build/legacy/HydrationBoundary.d.cts +14 -0
- package/build/legacy/HydrationBoundary.d.ts +14 -0
- package/build/legacy/HydrationBoundary.js +55 -0
- package/build/legacy/HydrationBoundary.js.map +1 -0
- package/build/legacy/IsRestoringProvider.cjs +37 -0
- package/build/legacy/IsRestoringProvider.cjs.map +1 -0
- package/build/legacy/IsRestoringProvider.d.cts +6 -0
- package/build/legacy/IsRestoringProvider.d.ts +6 -0
- package/build/legacy/IsRestoringProvider.js +11 -0
- package/build/legacy/IsRestoringProvider.js.map +1 -0
- package/build/legacy/QueryClientProvider.cjs +62 -0
- package/build/legacy/QueryClientProvider.cjs.map +1 -0
- package/build/legacy/QueryClientProvider.d.cts +13 -0
- package/build/legacy/QueryClientProvider.d.ts +13 -0
- package/build/legacy/QueryClientProvider.js +35 -0
- package/build/legacy/QueryClientProvider.js.map +1 -0
- package/build/legacy/QueryErrorResetBoundary.cjs +57 -0
- package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -0
- package/build/legacy/QueryErrorResetBoundary.d.cts +19 -0
- package/build/legacy/QueryErrorResetBoundary.d.ts +19 -0
- package/build/legacy/QueryErrorResetBoundary.js +31 -0
- package/build/legacy/QueryErrorResetBoundary.js.map +1 -0
- package/build/legacy/errorBoundaryUtils.cjs +57 -0
- package/build/legacy/errorBoundaryUtils.cjs.map +1 -0
- package/build/legacy/errorBoundaryUtils.d.cts +15 -0
- package/build/legacy/errorBoundaryUtils.d.ts +15 -0
- package/build/legacy/errorBoundaryUtils.js +30 -0
- package/build/legacy/errorBoundaryUtils.js.map +1 -0
- package/build/legacy/index.cjs +97 -0
- package/build/legacy/index.cjs.map +1 -0
- package/build/legacy/index.d.cts +21 -0
- package/build/legacy/index.d.ts +21 -0
- package/build/legacy/index.js +54 -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 +23 -0
- package/build/legacy/infiniteQueryOptions.d.ts +23 -0
- package/build/legacy/infiniteQueryOptions.js +8 -0
- package/build/legacy/infiniteQueryOptions.js.map +1 -0
- package/build/legacy/mutationOptions.cjs +33 -0
- package/build/legacy/mutationOptions.cjs.map +1 -0
- package/build/legacy/mutationOptions.d.cts +7 -0
- package/build/legacy/mutationOptions.d.ts +7 -0
- package/build/legacy/mutationOptions.js +8 -0
- package/build/legacy/mutationOptions.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 +24 -0
- package/build/legacy/queryOptions.d.ts +24 -0
- package/build/legacy/queryOptions.js +8 -0
- package/build/legacy/queryOptions.js.map +1 -0
- package/build/legacy/suspense.cjs +58 -0
- package/build/legacy/suspense.cjs.map +1 -0
- package/build/legacy/suspense.d.cts +11 -0
- package/build/legacy/suspense.d.ts +11 -0
- package/build/legacy/suspense.js +29 -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 +52 -0
- package/build/legacy/types.d.ts +52 -0
- package/build/legacy/types.js +1 -0
- package/build/legacy/types.js.map +1 -0
- package/build/legacy/useBaseQuery.cjs +121 -0
- package/build/legacy/useBaseQuery.cjs.map +1 -0
- package/build/legacy/useBaseQuery.d.cts +6 -0
- package/build/legacy/useBaseQuery.d.ts +6 -0
- package/build/legacy/useBaseQuery.js +105 -0
- package/build/legacy/useBaseQuery.js.map +1 -0
- package/build/legacy/useInfiniteQuery.cjs +39 -0
- package/build/legacy/useInfiniteQuery.cjs.map +1 -0
- package/build/legacy/useInfiniteQuery.d.cts +9 -0
- package/build/legacy/useInfiniteQuery.d.ts +9 -0
- package/build/legacy/useInfiniteQuery.js +14 -0
- package/build/legacy/useInfiniteQuery.js.map +1 -0
- package/build/legacy/useIsFetching.cjs +45 -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 +20 -0
- package/build/legacy/useIsFetching.js.map +1 -0
- package/build/legacy/useMutation.cjs +63 -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 +75 -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 +49 -0
- package/build/legacy/useMutationState.js.map +1 -0
- package/build/legacy/usePrefetchInfiniteQuery.cjs +37 -0
- package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -0
- package/build/legacy/usePrefetchInfiniteQuery.d.cts +5 -0
- package/build/legacy/usePrefetchInfiniteQuery.d.ts +5 -0
- package/build/legacy/usePrefetchInfiniteQuery.js +12 -0
- package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -0
- package/build/legacy/usePrefetchQuery.cjs +37 -0
- package/build/legacy/usePrefetchQuery.cjs.map +1 -0
- package/build/legacy/usePrefetchQuery.d.cts +6 -0
- package/build/legacy/usePrefetchQuery.d.ts +6 -0
- package/build/legacy/usePrefetchQuery.js +12 -0
- package/build/legacy/usePrefetchQuery.js.map +1 -0
- package/build/legacy/useQueries.cjs +120 -0
- package/build/legacy/useQueries.cjs.map +1 -0
- package/build/legacy/useQueries.d.cts +76 -0
- package/build/legacy/useQueries.d.ts +76 -0
- package/build/legacy/useQueries.js +109 -0
- package/build/legacy/useQueries.js.map +1 -0
- package/build/legacy/useQuery.cjs +35 -0
- package/build/legacy/useQuery.cjs.map +1 -0
- package/build/legacy/useQuery.d.cts +9 -0
- package/build/legacy/useQuery.d.ts +9 -0
- package/build/legacy/useQuery.js +10 -0
- package/build/legacy/useQuery.js.map +1 -0
- package/build/legacy/useSuspenseInfiniteQuery.cjs +50 -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 +25 -0
- package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -0
- package/build/legacy/useSuspenseQueries.cjs +55 -0
- package/build/legacy/useSuspenseQueries.cjs.map +1 -0
- package/build/legacy/useSuspenseQueries.d.cts +79 -0
- package/build/legacy/useSuspenseQueries.d.ts +79 -0
- package/build/legacy/useSuspenseQueries.js +30 -0
- package/build/legacy/useSuspenseQueries.js.map +1 -0
- package/build/legacy/useSuspenseQuery.cjs +51 -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 +26 -0
- package/build/legacy/useSuspenseQuery.js.map +1 -0
- package/build/legacy/utils.cjs +79 -0
- package/build/legacy/utils.cjs.map +1 -0
- package/build/legacy/utils.d.cts +4 -0
- package/build/legacy/utils.d.ts +4 -0
- package/build/legacy/utils.js +53 -0
- package/build/legacy/utils.js.map +1 -0
- package/build/modern/HydrationBoundary.cjs +80 -0
- package/build/modern/HydrationBoundary.cjs.map +1 -0
- package/build/modern/HydrationBoundary.d.cts +14 -0
- package/build/modern/HydrationBoundary.d.ts +14 -0
- package/build/modern/HydrationBoundary.js +55 -0
- package/build/modern/HydrationBoundary.js.map +1 -0
- package/build/modern/IsRestoringProvider.cjs +37 -0
- package/build/modern/IsRestoringProvider.cjs.map +1 -0
- package/build/modern/IsRestoringProvider.d.cts +6 -0
- package/build/modern/IsRestoringProvider.d.ts +6 -0
- package/build/modern/IsRestoringProvider.js +11 -0
- package/build/modern/IsRestoringProvider.js.map +1 -0
- package/build/modern/QueryClientProvider.cjs +62 -0
- package/build/modern/QueryClientProvider.cjs.map +1 -0
- package/build/modern/QueryClientProvider.d.cts +13 -0
- package/build/modern/QueryClientProvider.d.ts +13 -0
- package/build/modern/QueryClientProvider.js +35 -0
- package/build/modern/QueryClientProvider.js.map +1 -0
- package/build/modern/QueryErrorResetBoundary.cjs +57 -0
- package/build/modern/QueryErrorResetBoundary.cjs.map +1 -0
- package/build/modern/QueryErrorResetBoundary.d.cts +19 -0
- package/build/modern/QueryErrorResetBoundary.d.ts +19 -0
- package/build/modern/QueryErrorResetBoundary.js +31 -0
- package/build/modern/QueryErrorResetBoundary.js.map +1 -0
- package/build/modern/errorBoundaryUtils.cjs +57 -0
- package/build/modern/errorBoundaryUtils.cjs.map +1 -0
- package/build/modern/errorBoundaryUtils.d.cts +15 -0
- package/build/modern/errorBoundaryUtils.d.ts +15 -0
- package/build/modern/errorBoundaryUtils.js +30 -0
- package/build/modern/errorBoundaryUtils.js.map +1 -0
- package/build/modern/index.cjs +97 -0
- package/build/modern/index.cjs.map +1 -0
- package/build/modern/index.d.cts +21 -0
- package/build/modern/index.d.ts +21 -0
- package/build/modern/index.js +54 -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 +23 -0
- package/build/modern/infiniteQueryOptions.d.ts +23 -0
- package/build/modern/infiniteQueryOptions.js +8 -0
- package/build/modern/infiniteQueryOptions.js.map +1 -0
- package/build/modern/mutationOptions.cjs +33 -0
- package/build/modern/mutationOptions.cjs.map +1 -0
- package/build/modern/mutationOptions.d.cts +7 -0
- package/build/modern/mutationOptions.d.ts +7 -0
- package/build/modern/mutationOptions.js +8 -0
- package/build/modern/mutationOptions.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 +24 -0
- package/build/modern/queryOptions.d.ts +24 -0
- package/build/modern/queryOptions.js +8 -0
- package/build/modern/queryOptions.js.map +1 -0
- package/build/modern/suspense.cjs +58 -0
- package/build/modern/suspense.cjs.map +1 -0
- package/build/modern/suspense.d.cts +11 -0
- package/build/modern/suspense.d.ts +11 -0
- package/build/modern/suspense.js +29 -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 +52 -0
- package/build/modern/types.d.ts +52 -0
- package/build/modern/types.js +1 -0
- package/build/modern/types.js.map +1 -0
- package/build/modern/useBaseQuery.cjs +118 -0
- package/build/modern/useBaseQuery.cjs.map +1 -0
- package/build/modern/useBaseQuery.d.cts +6 -0
- package/build/modern/useBaseQuery.d.ts +6 -0
- package/build/modern/useBaseQuery.js +102 -0
- package/build/modern/useBaseQuery.js.map +1 -0
- package/build/modern/useInfiniteQuery.cjs +39 -0
- package/build/modern/useInfiniteQuery.cjs.map +1 -0
- package/build/modern/useInfiniteQuery.d.cts +9 -0
- package/build/modern/useInfiniteQuery.d.ts +9 -0
- package/build/modern/useInfiniteQuery.js +14 -0
- package/build/modern/useInfiniteQuery.js.map +1 -0
- package/build/modern/useIsFetching.cjs +45 -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 +20 -0
- package/build/modern/useIsFetching.js.map +1 -0
- package/build/modern/useMutation.cjs +63 -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 +75 -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 +49 -0
- package/build/modern/useMutationState.js.map +1 -0
- package/build/modern/usePrefetchInfiniteQuery.cjs +37 -0
- package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -0
- package/build/modern/usePrefetchInfiniteQuery.d.cts +5 -0
- package/build/modern/usePrefetchInfiniteQuery.d.ts +5 -0
- package/build/modern/usePrefetchInfiniteQuery.js +12 -0
- package/build/modern/usePrefetchInfiniteQuery.js.map +1 -0
- package/build/modern/usePrefetchQuery.cjs +37 -0
- package/build/modern/usePrefetchQuery.cjs.map +1 -0
- package/build/modern/usePrefetchQuery.d.cts +6 -0
- package/build/modern/usePrefetchQuery.d.ts +6 -0
- package/build/modern/usePrefetchQuery.js +12 -0
- package/build/modern/usePrefetchQuery.js.map +1 -0
- package/build/modern/useQueries.cjs +120 -0
- package/build/modern/useQueries.cjs.map +1 -0
- package/build/modern/useQueries.d.cts +76 -0
- package/build/modern/useQueries.d.ts +76 -0
- package/build/modern/useQueries.js +109 -0
- package/build/modern/useQueries.js.map +1 -0
- package/build/modern/useQuery.cjs +35 -0
- package/build/modern/useQuery.cjs.map +1 -0
- package/build/modern/useQuery.d.cts +9 -0
- package/build/modern/useQuery.d.ts +9 -0
- package/build/modern/useQuery.js +10 -0
- package/build/modern/useQuery.js.map +1 -0
- package/build/modern/useSuspenseInfiniteQuery.cjs +50 -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 +25 -0
- package/build/modern/useSuspenseInfiniteQuery.js.map +1 -0
- package/build/modern/useSuspenseQueries.cjs +55 -0
- package/build/modern/useSuspenseQueries.cjs.map +1 -0
- package/build/modern/useSuspenseQueries.d.cts +79 -0
- package/build/modern/useSuspenseQueries.d.ts +79 -0
- package/build/modern/useSuspenseQueries.js +30 -0
- package/build/modern/useSuspenseQueries.js.map +1 -0
- package/build/modern/useSuspenseQuery.cjs +51 -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 +26 -0
- package/build/modern/useSuspenseQuery.js.map +1 -0
- package/build/modern/utils.cjs +79 -0
- package/build/modern/utils.cjs.map +1 -0
- package/build/modern/utils.d.cts +4 -0
- package/build/modern/utils.d.ts +4 -0
- package/build/modern/utils.js +53 -0
- package/build/modern/utils.js.map +1 -0
- package/build/query-codemods/eslint.config.js +18 -0
- package/build/query-codemods/package.json +38 -0
- package/build/query-codemods/root.eslint.config.js +64 -0
- package/build/query-codemods/tsconfig.json +8 -0
- package/build/query-codemods/vite.config.ts +30 -0
- package/package.json +82 -8
- package/src/HydrationBoundary.tsx +108 -0
- package/src/IsRestoringProvider.ts +7 -0
- package/src/QueryClientProvider.tsx +45 -0
- package/src/QueryErrorResetBoundary.tsx +57 -0
- package/src/errorBoundaryUtils.ts +76 -0
- package/src/index.ts +56 -0
- package/src/infiniteQueryOptions.ts +150 -0
- package/src/mutationOptions.ts +42 -0
- package/src/queryOptions.ts +88 -0
- package/src/suspense.ts +81 -0
- package/src/types.ts +241 -0
- package/src/useBaseQuery.ts +169 -0
- package/src/useInfiniteQuery.ts +81 -0
- package/src/useIsFetching.ts +23 -0
- package/src/useMutation.ts +69 -0
- package/src/useMutationState.ts +74 -0
- package/src/usePrefetchInfiniteQuery.tsx +31 -0
- package/src/usePrefetchQuery.tsx +20 -0
- package/src/useQueries.ts +331 -0
- package/src/useQuery.ts +52 -0
- package/src/useSuspenseInfiniteQuery.ts +50 -0
- package/src/useSuspenseQueries.ts +211 -0
- package/src/useSuspenseQuery.ts +34 -0
- package/src/utils.ts +88 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
const createUtilsObject = require('../utils/index.cjs')
|
|
2
|
+
const createKeyReplacer = require('./utils/replacers/key-replacer.cjs')
|
|
3
|
+
const createUseQueryLikeTransformer = require('../utils/transformers/use-query-like-transformer.cjs')
|
|
4
|
+
const createQueryClientTransformer = require('../utils/transformers/query-client-transformer.cjs')
|
|
5
|
+
const createQueryCacheTransformer = require('../utils/transformers/query-cache-transformer.cjs')
|
|
6
|
+
|
|
7
|
+
const transformQueryClientUsages = ({
|
|
8
|
+
jscodeshift,
|
|
9
|
+
utils,
|
|
10
|
+
root,
|
|
11
|
+
filePath,
|
|
12
|
+
packageName,
|
|
13
|
+
}) => {
|
|
14
|
+
const transformer = createQueryClientTransformer({
|
|
15
|
+
jscodeshift,
|
|
16
|
+
utils,
|
|
17
|
+
root,
|
|
18
|
+
packageName,
|
|
19
|
+
})
|
|
20
|
+
const replacer = createKeyReplacer({ jscodeshift, root, filePath })
|
|
21
|
+
|
|
22
|
+
transformer.execute(
|
|
23
|
+
[
|
|
24
|
+
// Not object syntax-aware methods.
|
|
25
|
+
'getMutationDefaults',
|
|
26
|
+
'getQueriesData',
|
|
27
|
+
'getQueryData',
|
|
28
|
+
'getQueryDefaults',
|
|
29
|
+
'getQueryState',
|
|
30
|
+
'isFetching',
|
|
31
|
+
'setMutationDefaults',
|
|
32
|
+
'setQueriesData',
|
|
33
|
+
'setQueryData',
|
|
34
|
+
'setQueryDefaults',
|
|
35
|
+
// Object syntax-aware methods.
|
|
36
|
+
'cancelQueries',
|
|
37
|
+
'fetchInfiniteQuery',
|
|
38
|
+
'fetchQuery',
|
|
39
|
+
'invalidateQueries',
|
|
40
|
+
'prefetchInfiniteQuery',
|
|
41
|
+
'prefetchQuery',
|
|
42
|
+
'refetchQueries',
|
|
43
|
+
'removeQueries',
|
|
44
|
+
'resetQueries',
|
|
45
|
+
],
|
|
46
|
+
replacer,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const transformUseQueriesUsages = ({
|
|
51
|
+
jscodeshift,
|
|
52
|
+
utils,
|
|
53
|
+
root,
|
|
54
|
+
packageName,
|
|
55
|
+
}) => {
|
|
56
|
+
const transformer = createUseQueryLikeTransformer({
|
|
57
|
+
jscodeshift,
|
|
58
|
+
utils,
|
|
59
|
+
root,
|
|
60
|
+
packageName,
|
|
61
|
+
})
|
|
62
|
+
const replacer = ({ node }) => {
|
|
63
|
+
/**
|
|
64
|
+
* When the node doesn't have the 'original' property, that means the codemod has been already applied,
|
|
65
|
+
* so we don't need to do any changes.
|
|
66
|
+
*/
|
|
67
|
+
if (!node.original) {
|
|
68
|
+
return node
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const newCallExpression = jscodeshift.callExpression(node.original.callee, [
|
|
72
|
+
jscodeshift.objectExpression([
|
|
73
|
+
jscodeshift.property(
|
|
74
|
+
'init',
|
|
75
|
+
jscodeshift.identifier('queries'),
|
|
76
|
+
node.original.arguments[0],
|
|
77
|
+
),
|
|
78
|
+
]),
|
|
79
|
+
])
|
|
80
|
+
|
|
81
|
+
// TODO: This should be part of one function!
|
|
82
|
+
if (node.typeParameters) {
|
|
83
|
+
newCallExpression.typeArguments = node.typeParameters
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return newCallExpression
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
transformer.execute(['useQueries'], replacer)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const transformUseQueryLikeUsages = ({
|
|
93
|
+
jscodeshift,
|
|
94
|
+
utils,
|
|
95
|
+
root,
|
|
96
|
+
filePath,
|
|
97
|
+
packageName,
|
|
98
|
+
}) => {
|
|
99
|
+
const transformer = createUseQueryLikeTransformer({
|
|
100
|
+
jscodeshift,
|
|
101
|
+
utils,
|
|
102
|
+
root,
|
|
103
|
+
packageName,
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
transformer.execute(
|
|
107
|
+
['useQuery', 'useInfiniteQuery', 'useIsFetching', 'useIsMutating'],
|
|
108
|
+
createKeyReplacer({
|
|
109
|
+
jscodeshift,
|
|
110
|
+
root,
|
|
111
|
+
filePath,
|
|
112
|
+
keyName: 'queryKey',
|
|
113
|
+
}),
|
|
114
|
+
)
|
|
115
|
+
transformer.execute(
|
|
116
|
+
['useMutation'],
|
|
117
|
+
createKeyReplacer({
|
|
118
|
+
jscodeshift,
|
|
119
|
+
root,
|
|
120
|
+
filePath,
|
|
121
|
+
keyName: 'mutationKey',
|
|
122
|
+
}),
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const transformQueryCacheUsages = ({
|
|
127
|
+
jscodeshift,
|
|
128
|
+
utils,
|
|
129
|
+
root,
|
|
130
|
+
filePath,
|
|
131
|
+
packageName,
|
|
132
|
+
}) => {
|
|
133
|
+
const transformer = createQueryCacheTransformer({
|
|
134
|
+
jscodeshift,
|
|
135
|
+
utils,
|
|
136
|
+
root,
|
|
137
|
+
packageName,
|
|
138
|
+
})
|
|
139
|
+
const replacer = createKeyReplacer({ jscodeshift, root, filePath })
|
|
140
|
+
|
|
141
|
+
transformer.execute(replacer)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
module.exports = (file, api) => {
|
|
145
|
+
const jscodeshift = api.jscodeshift
|
|
146
|
+
const root = jscodeshift(file.source)
|
|
147
|
+
|
|
148
|
+
// TODO: Execute the transformers only when it contains a `react-query` import!
|
|
149
|
+
|
|
150
|
+
const utils = createUtilsObject({ root, jscodeshift })
|
|
151
|
+
const filePath = file.path
|
|
152
|
+
const packageName = 'react-query'
|
|
153
|
+
|
|
154
|
+
// This function transforms usages like `useQuery` and `useMutation`.
|
|
155
|
+
transformUseQueryLikeUsages({
|
|
156
|
+
jscodeshift,
|
|
157
|
+
utils,
|
|
158
|
+
root,
|
|
159
|
+
filePath,
|
|
160
|
+
packageName,
|
|
161
|
+
})
|
|
162
|
+
// This function transforms usages of `useQueries`.
|
|
163
|
+
transformUseQueriesUsages({
|
|
164
|
+
jscodeshift,
|
|
165
|
+
utils,
|
|
166
|
+
root,
|
|
167
|
+
packageName,
|
|
168
|
+
})
|
|
169
|
+
// This function transforms usages of `QueryClient`.
|
|
170
|
+
transformQueryClientUsages({
|
|
171
|
+
jscodeshift,
|
|
172
|
+
utils,
|
|
173
|
+
root,
|
|
174
|
+
filePath,
|
|
175
|
+
packageName,
|
|
176
|
+
})
|
|
177
|
+
// This function transforms usages of `QueryCache`.
|
|
178
|
+
transformQueryCacheUsages({ jscodeshift, utils, root, filePath, packageName })
|
|
179
|
+
|
|
180
|
+
return root.toSource({ quote: 'single', lineTerminator: '\n' })
|
|
181
|
+
}
|
|
@@ -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,164 @@
|
|
|
1
|
+
class UnprocessableKeyError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message)
|
|
4
|
+
this.name = 'UnprocessableKeyError'
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
module.exports = ({ jscodeshift, root, filePath, keyName = 'queryKey' }) => {
|
|
9
|
+
const isArrayExpression = (node) =>
|
|
10
|
+
jscodeshift.match(node, { type: jscodeshift.ArrayExpression.name })
|
|
11
|
+
|
|
12
|
+
const isStringLiteral = (node) =>
|
|
13
|
+
jscodeshift.match(node, { type: jscodeshift.StringLiteral.name }) ||
|
|
14
|
+
jscodeshift.match(node, { type: jscodeshift.Literal.name })
|
|
15
|
+
|
|
16
|
+
const isTemplateLiteral = (node) =>
|
|
17
|
+
jscodeshift.match(node, { type: jscodeshift.TemplateLiteral.name })
|
|
18
|
+
|
|
19
|
+
const findVariableDeclaration = (node) => {
|
|
20
|
+
const declarations = root
|
|
21
|
+
.find(jscodeshift.VariableDeclarator, {
|
|
22
|
+
id: {
|
|
23
|
+
type: jscodeshift.Identifier.name,
|
|
24
|
+
name: node.name,
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
.paths()
|
|
28
|
+
|
|
29
|
+
return declarations.length > 0 ? declarations[0] : null
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const createKeyValue = (node) => {
|
|
33
|
+
// When the node is a string literal we convert it into an array of strings.
|
|
34
|
+
if (isStringLiteral(node)) {
|
|
35
|
+
return jscodeshift.arrayExpression([
|
|
36
|
+
jscodeshift.stringLiteral(node.value),
|
|
37
|
+
])
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// When the node is a template literal we convert it into an array of template literals.
|
|
41
|
+
if (isTemplateLiteral(node)) {
|
|
42
|
+
return jscodeshift.arrayExpression([
|
|
43
|
+
jscodeshift.templateLiteral(node.quasis, node.expressions),
|
|
44
|
+
])
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (jscodeshift.match(node, { type: jscodeshift.Identifier.name })) {
|
|
48
|
+
// When the node is an identifier at first, we try to find its declaration, because we will try
|
|
49
|
+
// to guess its type.
|
|
50
|
+
const variableDeclaration = findVariableDeclaration(node)
|
|
51
|
+
|
|
52
|
+
if (!variableDeclaration) {
|
|
53
|
+
throw new UnprocessableKeyError(
|
|
54
|
+
`In file ${filePath} at line ${node.loc.start.line} the type of identifier \`${node.name}\` couldn't be recognized, so the codemod couldn't be applied. Please migrate manually.`,
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const initializer = variableDeclaration.value.init
|
|
59
|
+
|
|
60
|
+
// When it's a string, we just wrap it into an array expression.
|
|
61
|
+
if (isStringLiteral(initializer) || isTemplateLiteral(initializer)) {
|
|
62
|
+
return jscodeshift.arrayExpression([node])
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
throw new UnprocessableKeyError(
|
|
67
|
+
`In file ${filePath} at line ${node.loc.start.line} the type of the \`${keyName}\` couldn't be recognized, so the codemod couldn't be applied. Please migrate manually.`,
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const createKeyProperty = (node) =>
|
|
72
|
+
jscodeshift.property(
|
|
73
|
+
'init',
|
|
74
|
+
jscodeshift.identifier(keyName),
|
|
75
|
+
createKeyValue(node),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
const getPropertyFromObjectExpression = (objectExpression, propertyName) =>
|
|
79
|
+
objectExpression.properties.find(
|
|
80
|
+
(property) => property.key.name === propertyName,
|
|
81
|
+
) ?? null
|
|
82
|
+
|
|
83
|
+
const buildWithTypeArguments = (node, builder) => {
|
|
84
|
+
const newNode = builder(node)
|
|
85
|
+
|
|
86
|
+
if (node.typeParameters) {
|
|
87
|
+
newNode.typeArguments = node.typeParameters
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return newNode
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return ({ node }) => {
|
|
94
|
+
// When the node doesn't have the 'original' property, that means the codemod has been already applied,
|
|
95
|
+
// so we don't need to do any changes.
|
|
96
|
+
if (!node.original) {
|
|
97
|
+
return node
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const methodArguments = node.arguments
|
|
101
|
+
|
|
102
|
+
// The method call doesn't have any arguments, we have nothing to do in this case.
|
|
103
|
+
if (methodArguments.length === 0) {
|
|
104
|
+
return node
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const [firstArgument, ...restOfTheArguments] = methodArguments
|
|
109
|
+
|
|
110
|
+
if (
|
|
111
|
+
jscodeshift.match(firstArgument, {
|
|
112
|
+
type: jscodeshift.ObjectExpression.name,
|
|
113
|
+
})
|
|
114
|
+
) {
|
|
115
|
+
const originalKey = getPropertyFromObjectExpression(
|
|
116
|
+
firstArgument,
|
|
117
|
+
keyName,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
if (!originalKey) {
|
|
121
|
+
throw new UnprocessableKeyError(
|
|
122
|
+
`In file ${filePath} at line ${node.loc.start.line} the \`${keyName}\` couldn't be found. Did you forget to add it?`,
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const restOfTheProperties = firstArgument.properties.filter(
|
|
127
|
+
(item) => item.key.name !== keyName,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
return buildWithTypeArguments(node, (originalNode) =>
|
|
131
|
+
jscodeshift.callExpression(originalNode.original.callee, [
|
|
132
|
+
jscodeshift.objectExpression([
|
|
133
|
+
createKeyProperty(originalKey.value),
|
|
134
|
+
...restOfTheProperties,
|
|
135
|
+
]),
|
|
136
|
+
...restOfTheArguments,
|
|
137
|
+
]),
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// When the node is an array expression we just simply return it because we want query keys to be arrays.
|
|
142
|
+
if (isArrayExpression(firstArgument)) {
|
|
143
|
+
return node
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return buildWithTypeArguments(node, (originalNode) =>
|
|
147
|
+
jscodeshift.callExpression(originalNode.original.callee, [
|
|
148
|
+
createKeyValue(firstArgument),
|
|
149
|
+
...restOfTheArguments,
|
|
150
|
+
]),
|
|
151
|
+
)
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (error.name === 'UnprocessableKeyError') {
|
|
154
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
155
|
+
console.warn(error.message)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return node
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
throw error
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
const createUtilsObject = require('../../utils/index.cjs')
|
|
2
|
+
const createUseQueryLikeTransformer = require('../../utils/transformers/use-query-like-transformer.cjs')
|
|
3
|
+
const createQueryClientTransformer = require('../../utils/transformers/query-client-transformer.cjs')
|
|
4
|
+
|
|
5
|
+
const originalName = 'isLoading'
|
|
6
|
+
const newName = 'isPending'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {import('jscodeshift')} 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 transformUsages = ({ jscodeshift, utils, root, filePath, config }) => {
|
|
16
|
+
/**
|
|
17
|
+
* @param {import('jscodeshift').CallExpression | import('jscodeshift').ExpressionStatement} node
|
|
18
|
+
* @returns {{start: number, end: number}}
|
|
19
|
+
*/
|
|
20
|
+
const getNodeLocation = (node) => {
|
|
21
|
+
const location = utils.isCallExpression(node) ? node.callee.loc : node.loc
|
|
22
|
+
const start = location.start.line
|
|
23
|
+
const end = location.end.line
|
|
24
|
+
|
|
25
|
+
return { start, end }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {import('jscodeshift').ASTNode} node
|
|
30
|
+
* @returns {boolean}
|
|
31
|
+
*/
|
|
32
|
+
const isObjectExpression = (node) => {
|
|
33
|
+
return jscodeshift.match(node, {
|
|
34
|
+
type: jscodeshift.ObjectExpression.name,
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {import('jscodeshift').ASTNode} node
|
|
40
|
+
* @returns {boolean}
|
|
41
|
+
*/
|
|
42
|
+
const isObjectPattern = (node) => {
|
|
43
|
+
return jscodeshift.match(node, {
|
|
44
|
+
type: jscodeshift.ObjectPattern.name,
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {import('jscodeshift').ASTNode} node
|
|
50
|
+
* @returns {boolean}
|
|
51
|
+
*/
|
|
52
|
+
const isVariableDeclarator = (node) => {
|
|
53
|
+
return jscodeshift.match(node, {
|
|
54
|
+
type: jscodeshift.VariableDeclarator.name,
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {import('jscodeshift').Node} node
|
|
60
|
+
* @param {import('jscodeshift').Identifier} identifier
|
|
61
|
+
* @returns {Collection<import('jscodeshift').MemberExpression>}
|
|
62
|
+
*/
|
|
63
|
+
const findIsLoadingPropertiesOfIdentifier = (node, identifier) => {
|
|
64
|
+
return jscodeshift(node).find(jscodeshift.MemberExpression, {
|
|
65
|
+
object: {
|
|
66
|
+
type: jscodeshift.Identifier.name,
|
|
67
|
+
name: identifier.name,
|
|
68
|
+
},
|
|
69
|
+
property: {
|
|
70
|
+
type: jscodeshift.Identifier.name,
|
|
71
|
+
name: originalName,
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @param {import('jscodeshift').ObjectPattern} node
|
|
78
|
+
* @returns {import('jscodeshift').ObjectProperty|null}
|
|
79
|
+
*/
|
|
80
|
+
const findIsLoadingObjectPropertyInObjectPattern = (node) => {
|
|
81
|
+
return (
|
|
82
|
+
node.properties.find((property) =>
|
|
83
|
+
jscodeshift.match(property, {
|
|
84
|
+
key: {
|
|
85
|
+
type: jscodeshift.Identifier.name,
|
|
86
|
+
name: originalName,
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
) ?? null
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {import('jscodeshift').ObjectPattern} node
|
|
95
|
+
* @returns {import('jscodeshift').RestElement|null}
|
|
96
|
+
*/
|
|
97
|
+
const findRestElementInObjectPattern = (node) => {
|
|
98
|
+
return (
|
|
99
|
+
node.properties.find((property) =>
|
|
100
|
+
jscodeshift.match(property, {
|
|
101
|
+
type: jscodeshift.RestElement.name,
|
|
102
|
+
}),
|
|
103
|
+
) ?? null
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const replacer = (path, transformNode) => {
|
|
108
|
+
const node = path.node
|
|
109
|
+
const parentNode = path.parentPath.value
|
|
110
|
+
const { start, end } = getNodeLocation(node)
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
if (!isVariableDeclarator(parentNode)) {
|
|
114
|
+
// The parent node is not a variable declarator, the transformation will be skipped.
|
|
115
|
+
return node
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const lookupNode = path.scope.node
|
|
119
|
+
const variableDeclaratorId = parentNode.id
|
|
120
|
+
|
|
121
|
+
if (isObjectPattern(variableDeclaratorId)) {
|
|
122
|
+
const isLoadingObjectProperty =
|
|
123
|
+
findIsLoadingObjectPropertyInObjectPattern(variableDeclaratorId)
|
|
124
|
+
|
|
125
|
+
if (isLoadingObjectProperty) {
|
|
126
|
+
jscodeshift(lookupNode)
|
|
127
|
+
.find(jscodeshift.ObjectProperty, {
|
|
128
|
+
key: {
|
|
129
|
+
type: jscodeshift.Identifier.name,
|
|
130
|
+
name: originalName,
|
|
131
|
+
},
|
|
132
|
+
})
|
|
133
|
+
.replaceWith((mutablePath) => {
|
|
134
|
+
if (isObjectPattern(mutablePath.parent)) {
|
|
135
|
+
const affectedProperty = mutablePath.value.value.shorthand
|
|
136
|
+
? 'value'
|
|
137
|
+
: 'key'
|
|
138
|
+
|
|
139
|
+
mutablePath.value[affectedProperty].name = newName
|
|
140
|
+
|
|
141
|
+
return mutablePath.value
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (isObjectExpression(mutablePath.parent)) {
|
|
145
|
+
const affectedProperty = mutablePath.value.value.shorthand
|
|
146
|
+
? 'key'
|
|
147
|
+
: 'value'
|
|
148
|
+
|
|
149
|
+
mutablePath.value[affectedProperty].name = newName
|
|
150
|
+
|
|
151
|
+
return mutablePath.value
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return mutablePath.value
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
// Renaming all other 'isLoading' references that are object properties.
|
|
158
|
+
jscodeshift(lookupNode)
|
|
159
|
+
.find(jscodeshift.Identifier, { name: originalName })
|
|
160
|
+
.replaceWith((mutablePath) => {
|
|
161
|
+
if (
|
|
162
|
+
!jscodeshift.match(mutablePath.parent, {
|
|
163
|
+
type: jscodeshift.ObjectProperty.name,
|
|
164
|
+
})
|
|
165
|
+
) {
|
|
166
|
+
mutablePath.value.name = newName
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return mutablePath.value
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const restElement = findRestElementInObjectPattern(variableDeclaratorId)
|
|
174
|
+
|
|
175
|
+
if (restElement) {
|
|
176
|
+
findIsLoadingPropertiesOfIdentifier(
|
|
177
|
+
lookupNode,
|
|
178
|
+
restElement.argument,
|
|
179
|
+
).replaceWith(({ node: mutableNode }) => {
|
|
180
|
+
mutableNode.property.name = newName
|
|
181
|
+
|
|
182
|
+
return mutableNode
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return node
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (utils.isIdentifier(variableDeclaratorId)) {
|
|
190
|
+
findIsLoadingPropertiesOfIdentifier(
|
|
191
|
+
lookupNode,
|
|
192
|
+
variableDeclaratorId,
|
|
193
|
+
).replaceWith(({ node: mutableNode }) => {
|
|
194
|
+
mutableNode.property.name = newName
|
|
195
|
+
|
|
196
|
+
return mutableNode
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
return node
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
utils.warn(
|
|
203
|
+
`The usage in file "${filePath}" at line ${start}:${end} could not be transformed. Please migrate this usage manually.`,
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
return node
|
|
207
|
+
} catch (error) {
|
|
208
|
+
utils.warn(
|
|
209
|
+
`An unknown error occurred while processing the "${filePath}" file. Please review this file, because the codemod couldn't be applied.`,
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
return node
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
createUseQueryLikeTransformer({ jscodeshift, utils, root }).execute(
|
|
217
|
+
config.hooks,
|
|
218
|
+
replacer,
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
createQueryClientTransformer({ jscodeshift, utils, root }).execute(
|
|
222
|
+
config.queryClientMethods,
|
|
223
|
+
replacer,
|
|
224
|
+
)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
module.exports = (file, api) => {
|
|
228
|
+
const jscodeshift = api.jscodeshift
|
|
229
|
+
const root = jscodeshift(file.source)
|
|
230
|
+
const utils = createUtilsObject({ root, jscodeshift })
|
|
231
|
+
const filePath = file.path
|
|
232
|
+
|
|
233
|
+
const dependencies = { jscodeshift, utils, root, filePath }
|
|
234
|
+
|
|
235
|
+
transformUsages({
|
|
236
|
+
...dependencies,
|
|
237
|
+
config: {
|
|
238
|
+
hooks: ['useQuery', 'useMutation'],
|
|
239
|
+
queryClientMethods: [],
|
|
240
|
+
},
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
return root.toSource({ quote: 'single', lineTerminator: '\n' })
|
|
244
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
### Intro
|
|
2
|
+
|
|
3
|
+
The prerequisite for this code mod is to migrate your usages to the new syntax, so overloads for hooks and `QueryClient` methods shouldn't be available anymore.
|
|
4
|
+
|
|
5
|
+
### Affected usages
|
|
6
|
+
|
|
7
|
+
Please note, this code mod transforms usages only where the first argument is an object expression.
|
|
8
|
+
|
|
9
|
+
The following usage should be transformed by the code mod:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const { data } = useQuery({
|
|
13
|
+
queryKey: ['posts'],
|
|
14
|
+
queryFn: queryFn,
|
|
15
|
+
keepPreviousData: true,
|
|
16
|
+
})
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
But the following usage won't be transformed by the code mod, because the first argument an identifier:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
const hookArgument = {
|
|
23
|
+
queryKey: ['posts'],
|
|
24
|
+
queryFn: queryFn,
|
|
25
|
+
keepPreviousData: true,
|
|
26
|
+
}
|
|
27
|
+
const { data } = useQuery(hookArgument)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Troubleshooting
|
|
31
|
+
|
|
32
|
+
In case of any errors, feel free to reach us out via Discord or open an issue. If you open an issue, please provide a code snippet as well, because without a snippet we cannot find the bug in the code mod.
|