@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,271 @@
|
|
|
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
|
+
const AlreadyHasPlaceholderDataProperty = require('./utils/already-has-placeholder-data-property.cjs')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {import('jscodeshift')} jscodeshift
|
|
8
|
+
* @param {Object} utils
|
|
9
|
+
* @param {import('jscodeshift').Collection} root
|
|
10
|
+
* @param {string} filePath
|
|
11
|
+
* @param {{keyName: "mutationKey"|"queryKey", queryClientMethods: ReadonlyArray<string>, hooks: ReadonlyArray<string>}} config
|
|
12
|
+
*/
|
|
13
|
+
const transformUsages = ({ jscodeshift, utils, root, filePath, config }) => {
|
|
14
|
+
/**
|
|
15
|
+
* @param {import('jscodeshift').CallExpression | import('jscodeshift').ExpressionStatement} node
|
|
16
|
+
* @returns {{start: number, end: number}}
|
|
17
|
+
*/
|
|
18
|
+
const getNodeLocation = (node) => {
|
|
19
|
+
const location = utils.isCallExpression(node) ? node.callee.loc : node.loc
|
|
20
|
+
const start = location.start.line
|
|
21
|
+
const end = location.end.line
|
|
22
|
+
|
|
23
|
+
return { start, end }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {import('jscodeshift').ObjectProperty} objectProperty
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
30
|
+
const isKeepPreviousDataObjectProperty = (objectProperty) => {
|
|
31
|
+
return jscodeshift.match(objectProperty.key, {
|
|
32
|
+
type: jscodeshift.Identifier.name,
|
|
33
|
+
name: 'keepPreviousData',
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {import('jscodeshift').ObjectProperty} objectProperty
|
|
39
|
+
* @returns {boolean}
|
|
40
|
+
*/
|
|
41
|
+
const isObjectPropertyHasTrueBooleanLiteralValue = (objectProperty) => {
|
|
42
|
+
return jscodeshift.match(objectProperty.value, {
|
|
43
|
+
type: jscodeshift.BooleanLiteral.name,
|
|
44
|
+
value: true,
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {import('jscodeshift').ObjectExpression} objectExpression
|
|
50
|
+
* @returns {Array<import('jscodeshift').ObjectProperty>}
|
|
51
|
+
*/
|
|
52
|
+
const filterKeepPreviousDataProperty = (objectExpression) => {
|
|
53
|
+
return objectExpression.properties.filter((objectProperty) => {
|
|
54
|
+
return !isKeepPreviousDataObjectProperty(objectProperty)
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const createPlaceholderDataObjectProperty = () => {
|
|
59
|
+
return jscodeshift.objectProperty(
|
|
60
|
+
jscodeshift.identifier('placeholderData'),
|
|
61
|
+
jscodeshift.identifier('keepPreviousData'),
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param {import('jscodeshift').ObjectExpression} objectExpression
|
|
67
|
+
* @returns {boolean}
|
|
68
|
+
*/
|
|
69
|
+
const hasPlaceholderDataProperty = (objectExpression) => {
|
|
70
|
+
return (
|
|
71
|
+
objectExpression.properties.findIndex((objectProperty) => {
|
|
72
|
+
return jscodeshift.match(objectProperty.key, {
|
|
73
|
+
type: jscodeshift.Identifier.name,
|
|
74
|
+
name: 'placeholderData',
|
|
75
|
+
})
|
|
76
|
+
}) !== -1
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @param {import('jscodeshift').ObjectExpression} objectExpression
|
|
82
|
+
* @returns {import('jscodeshift').ObjectProperty | undefined}
|
|
83
|
+
*/
|
|
84
|
+
const getKeepPreviousDataProperty = (objectExpression) => {
|
|
85
|
+
return objectExpression.properties.find(isKeepPreviousDataObjectProperty)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let shouldAddKeepPreviousDataImport = false
|
|
89
|
+
|
|
90
|
+
const replacer = (path, resolveTargetArgument, transformNode) => {
|
|
91
|
+
const node = path.node
|
|
92
|
+
const { start, end } = getNodeLocation(node)
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const targetArgument = resolveTargetArgument(node)
|
|
96
|
+
|
|
97
|
+
if (targetArgument && utils.isObjectExpression(targetArgument)) {
|
|
98
|
+
const isPlaceholderDataPropertyPresent =
|
|
99
|
+
hasPlaceholderDataProperty(targetArgument)
|
|
100
|
+
|
|
101
|
+
if (hasPlaceholderDataProperty(targetArgument)) {
|
|
102
|
+
throw new AlreadyHasPlaceholderDataProperty(node, filePath)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const keepPreviousDataProperty =
|
|
106
|
+
getKeepPreviousDataProperty(targetArgument)
|
|
107
|
+
|
|
108
|
+
const keepPreviousDataPropertyHasTrueValue =
|
|
109
|
+
isObjectPropertyHasTrueBooleanLiteralValue(keepPreviousDataProperty)
|
|
110
|
+
|
|
111
|
+
if (!keepPreviousDataPropertyHasTrueValue) {
|
|
112
|
+
utils.warn(
|
|
113
|
+
`The usage in file "${filePath}" at line ${start}:${end} already contains a "keepPreviousData" property but its value is not "true". Please migrate this usage manually.`,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
return node
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (keepPreviousDataPropertyHasTrueValue) {
|
|
120
|
+
// Removing the `keepPreviousData` property from the object.
|
|
121
|
+
const mutableObjectExpressionProperties =
|
|
122
|
+
filterKeepPreviousDataProperty(targetArgument)
|
|
123
|
+
|
|
124
|
+
if (!isPlaceholderDataPropertyPresent) {
|
|
125
|
+
shouldAddKeepPreviousDataImport = true
|
|
126
|
+
|
|
127
|
+
// When the `placeholderData` property is not present, the `placeholderData: keepPreviousData` property will be added.
|
|
128
|
+
mutableObjectExpressionProperties.push(
|
|
129
|
+
createPlaceholderDataObjectProperty(),
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return transformNode(
|
|
134
|
+
node,
|
|
135
|
+
jscodeshift.objectExpression(mutableObjectExpressionProperties),
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
utils.warn(
|
|
141
|
+
`The usage in file "${filePath}" at line ${start}:${end} could not be transformed, because the first parameter is not an object expression. Please migrate this usage manually.`,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
return node
|
|
145
|
+
} catch (error) {
|
|
146
|
+
utils.warn(
|
|
147
|
+
error.name === AlreadyHasPlaceholderDataProperty.name
|
|
148
|
+
? error.message
|
|
149
|
+
: `An unknown error occurred while processing the "${filePath}" file. Please review this file, because the codemod couldn't be applied.`,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
return node
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
createUseQueryLikeTransformer({ jscodeshift, utils, root }).execute(
|
|
157
|
+
config.hooks,
|
|
158
|
+
(path) => {
|
|
159
|
+
const resolveTargetArgument = (node) => node.arguments[0] ?? null
|
|
160
|
+
const transformNode = (node, transformedArgument) =>
|
|
161
|
+
jscodeshift.callExpression(node.original.callee, [transformedArgument])
|
|
162
|
+
|
|
163
|
+
return replacer(path, resolveTargetArgument, transformNode)
|
|
164
|
+
},
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
createQueryClientTransformer({ jscodeshift, utils, root }).execute(
|
|
168
|
+
config.queryClientMethods,
|
|
169
|
+
(path) => {
|
|
170
|
+
const resolveTargetArgument = (node) => node.arguments[1] ?? null
|
|
171
|
+
const transformNode = (node, transformedArgument) => {
|
|
172
|
+
return jscodeshift.callExpression(node.original.callee, [
|
|
173
|
+
node.arguments[0],
|
|
174
|
+
transformedArgument,
|
|
175
|
+
...node.arguments.slice(2, 0),
|
|
176
|
+
])
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return replacer(path, resolveTargetArgument, transformNode)
|
|
180
|
+
},
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
const importIdentifierOfQueryClient = utils.getSelectorByImports(
|
|
184
|
+
utils.locateImports(['QueryClient']),
|
|
185
|
+
'QueryClient',
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
root
|
|
189
|
+
.find(jscodeshift.ExpressionStatement, {
|
|
190
|
+
expression: {
|
|
191
|
+
type: jscodeshift.NewExpression.name,
|
|
192
|
+
callee: {
|
|
193
|
+
type: jscodeshift.Identifier.name,
|
|
194
|
+
name: importIdentifierOfQueryClient,
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
})
|
|
198
|
+
.filter((path) => path.node.expression)
|
|
199
|
+
.replaceWith((path) => {
|
|
200
|
+
const resolveTargetArgument = (node) => {
|
|
201
|
+
const paths = jscodeshift(node)
|
|
202
|
+
.find(jscodeshift.ObjectProperty, {
|
|
203
|
+
key: {
|
|
204
|
+
type: jscodeshift.Identifier.name,
|
|
205
|
+
name: 'keepPreviousData',
|
|
206
|
+
},
|
|
207
|
+
})
|
|
208
|
+
.paths()
|
|
209
|
+
|
|
210
|
+
return paths.length > 0 ? paths[0].parent.node : null
|
|
211
|
+
}
|
|
212
|
+
const transformNode = (node, transformedArgument) => {
|
|
213
|
+
jscodeshift(node.expression)
|
|
214
|
+
.find(jscodeshift.ObjectProperty, {
|
|
215
|
+
key: {
|
|
216
|
+
type: jscodeshift.Identifier.name,
|
|
217
|
+
name: 'queries',
|
|
218
|
+
},
|
|
219
|
+
})
|
|
220
|
+
.replaceWith(({ node: mutableNode }) => {
|
|
221
|
+
mutableNode.value.properties = transformedArgument.properties
|
|
222
|
+
|
|
223
|
+
return mutableNode
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
return node
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return replacer(path, resolveTargetArgument, transformNode)
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
return { shouldAddKeepPreviousDataImport }
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
module.exports = (file, api) => {
|
|
236
|
+
const jscodeshift = api.jscodeshift
|
|
237
|
+
const root = jscodeshift(file.source)
|
|
238
|
+
const utils = createUtilsObject({ root, jscodeshift })
|
|
239
|
+
const filePath = file.path
|
|
240
|
+
|
|
241
|
+
const dependencies = { jscodeshift, utils, root, filePath }
|
|
242
|
+
|
|
243
|
+
const { shouldAddKeepPreviousDataImport } = transformUsages({
|
|
244
|
+
...dependencies,
|
|
245
|
+
config: {
|
|
246
|
+
hooks: ['useInfiniteQuery', 'useQueries', 'useQuery'],
|
|
247
|
+
queryClientMethods: ['setQueryDefaults'],
|
|
248
|
+
},
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
if (shouldAddKeepPreviousDataImport) {
|
|
252
|
+
root
|
|
253
|
+
.find(jscodeshift.ImportDeclaration, {
|
|
254
|
+
source: {
|
|
255
|
+
value: '@tanstack/react-query',
|
|
256
|
+
},
|
|
257
|
+
})
|
|
258
|
+
.replaceWith(({ node: mutableNode }) => {
|
|
259
|
+
mutableNode.specifiers = [
|
|
260
|
+
jscodeshift.importSpecifier(
|
|
261
|
+
jscodeshift.identifier('keepPreviousData'),
|
|
262
|
+
),
|
|
263
|
+
...mutableNode.specifiers,
|
|
264
|
+
]
|
|
265
|
+
|
|
266
|
+
return mutableNode
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return root.toSource({ quote: 'single', lineTerminator: '\n' })
|
|
271
|
+
}
|
package/build/codemods/src/v5/keep-previous-data/utils/already-has-placeholder-data-property.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class AlreadyHasPlaceholderDataProperty 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 = 'AlreadyHasPlaceholderDataProperty'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {import('jscodeshift').CallExpression} callExpression
|
|
14
|
+
* @param {string} filePath
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
buildMessage(callExpression, filePath) {
|
|
18
|
+
const location = callExpression.callee.loc
|
|
19
|
+
const start = location.start.line
|
|
20
|
+
const end = location.end.line
|
|
21
|
+
|
|
22
|
+
return `The usage in file "${filePath}" at line ${start}:${end} already contains a a "placeholderData" property. Please migrate this usage manually.`
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = AlreadyHasPlaceholderDataProperty
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const createUtilsObject = require('../../utils/index.cjs')
|
|
2
|
+
const transformFilterAwareUsages = require('./transformers/filter-aware-usage-transformer.cjs')
|
|
3
|
+
const transformQueryFnAwareUsages = require('./transformers/query-fn-aware-usage-transformer.cjs')
|
|
4
|
+
|
|
5
|
+
module.exports = (file, api) => {
|
|
6
|
+
const jscodeshift = api.jscodeshift
|
|
7
|
+
const root = jscodeshift(file.source)
|
|
8
|
+
const utils = createUtilsObject({ root, jscodeshift })
|
|
9
|
+
const filePath = file.path
|
|
10
|
+
|
|
11
|
+
const dependencies = { jscodeshift, utils, root, filePath }
|
|
12
|
+
|
|
13
|
+
transformFilterAwareUsages({
|
|
14
|
+
...dependencies,
|
|
15
|
+
config: {
|
|
16
|
+
keyName: 'queryKey',
|
|
17
|
+
fnName: 'queryFn',
|
|
18
|
+
queryClientMethods: [
|
|
19
|
+
'cancelQueries',
|
|
20
|
+
'getQueriesData',
|
|
21
|
+
'invalidateQueries',
|
|
22
|
+
'isFetching',
|
|
23
|
+
'refetchQueries',
|
|
24
|
+
'removeQueries',
|
|
25
|
+
'resetQueries',
|
|
26
|
+
// 'setQueriesData',
|
|
27
|
+
],
|
|
28
|
+
hooks: ['useIsFetching', 'useQuery'],
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
transformFilterAwareUsages({
|
|
33
|
+
...dependencies,
|
|
34
|
+
config: {
|
|
35
|
+
keyName: 'mutationKey',
|
|
36
|
+
fnName: 'mutationFn',
|
|
37
|
+
queryClientMethods: [],
|
|
38
|
+
hooks: ['useIsMutating', 'useMutation'],
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
transformQueryFnAwareUsages({
|
|
43
|
+
...dependencies,
|
|
44
|
+
config: {
|
|
45
|
+
keyName: 'queryKey',
|
|
46
|
+
queryClientMethods: [
|
|
47
|
+
'ensureQueryData',
|
|
48
|
+
'fetchQuery',
|
|
49
|
+
'prefetchQuery',
|
|
50
|
+
'fetchInfiniteQuery',
|
|
51
|
+
'prefetchInfiniteQuery',
|
|
52
|
+
],
|
|
53
|
+
hooks: [],
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
return root.toSource({ quote: 'single', lineTerminator: '\n' })
|
|
58
|
+
}
|
package/build/codemods/src/v5/remove-overloads/transformers/filter-aware-usage-transformer.cjs
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
const createV5UtilsObject = require('../utils/index.cjs')
|
|
2
|
+
const UnknownUsageError = require('../utils/unknown-usage-error.cjs')
|
|
3
|
+
const createQueryClientTransformer = require('../../../utils/transformers/query-client-transformer.cjs')
|
|
4
|
+
const createQueryCacheTransformer = require('../../../utils/transformers/query-cache-transformer.cjs')
|
|
5
|
+
const createUseQueryLikeTransformer = require('../../../utils/transformers/use-query-like-transformer.cjs')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {import('jscodeshift').api} jscodeshift
|
|
9
|
+
* @param {Object} utils
|
|
10
|
+
* @param {import('jscodeshift').Collection} root
|
|
11
|
+
* @param {string} filePath
|
|
12
|
+
* @param {{keyName: "mutationKey"|"queryKey", fnName: "mutationFn"|"queryFn", queryClientMethods: ReadonlyArray<string>, hooks: ReadonlyArray<string>}} config
|
|
13
|
+
*/
|
|
14
|
+
const transformFilterAwareUsages = ({
|
|
15
|
+
jscodeshift,
|
|
16
|
+
utils,
|
|
17
|
+
root,
|
|
18
|
+
filePath,
|
|
19
|
+
config,
|
|
20
|
+
}) => {
|
|
21
|
+
const v5Utils = createV5UtilsObject({ jscodeshift, utils })
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {import('jscodeshift').CallExpression} node
|
|
25
|
+
* @param {"mutationKey"|"queryKey"} keyName
|
|
26
|
+
* @param {"mutationFn"|"queryFn"} fnName
|
|
27
|
+
* @returns {boolean}
|
|
28
|
+
*/
|
|
29
|
+
const canSkipReplacement = (node, keyName, fnName) => {
|
|
30
|
+
const callArguments = node.arguments
|
|
31
|
+
|
|
32
|
+
const hasKeyOrFnProperty = () =>
|
|
33
|
+
callArguments[0].properties.some(
|
|
34
|
+
(property) =>
|
|
35
|
+
utils.isObjectProperty(property) &&
|
|
36
|
+
property.key.name !== keyName &&
|
|
37
|
+
property.key.name !== fnName,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* This call has at least one argument. If it's an object expression and contains the "queryKey" or "mutationKey"
|
|
42
|
+
* field, the transformation can be skipped, because it's already matching the expected signature.
|
|
43
|
+
*/
|
|
44
|
+
return (
|
|
45
|
+
callArguments.length > 0 &&
|
|
46
|
+
utils.isObjectExpression(callArguments[0]) &&
|
|
47
|
+
hasKeyOrFnProperty()
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* This function checks whether the given object property is a spread element or a property that's not named
|
|
53
|
+
* "queryKey" or "mutationKey".
|
|
54
|
+
*
|
|
55
|
+
* @param {import('jscodeshift').ObjectProperty} property
|
|
56
|
+
* @returns {boolean}
|
|
57
|
+
*/
|
|
58
|
+
const predicate = (property) => {
|
|
59
|
+
const isSpreadElement = utils.isSpreadElement(property)
|
|
60
|
+
const isObjectProperty = utils.isObjectProperty(property)
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
isSpreadElement ||
|
|
64
|
+
(isObjectProperty && property.key.name !== config.keyName)
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const replacer = (path) => {
|
|
69
|
+
const node = path.node
|
|
70
|
+
|
|
71
|
+
const isFunctionDefinition = (functionArgument) => {
|
|
72
|
+
if (utils.isFunctionDefinition(functionArgument)) {
|
|
73
|
+
return true
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (utils.isIdentifier(functionArgument)) {
|
|
77
|
+
const binding = v5Utils.getBindingFromScope(
|
|
78
|
+
path,
|
|
79
|
+
functionArgument.name,
|
|
80
|
+
filePath,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
const isVariableDeclarator = jscodeshift.match(binding, {
|
|
84
|
+
type: jscodeshift.VariableDeclarator.name,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
return isVariableDeclarator && utils.isFunctionDefinition(binding.init)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
// If the given method/function call matches certain criteria, the node doesn't need to be replaced, this step can be skipped.
|
|
93
|
+
if (canSkipReplacement(node, config.keyName, config.fnName)) {
|
|
94
|
+
return node
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Here we attempt to determine the first parameter of the function call.
|
|
99
|
+
* If it's a function definition, we can create an object property from it (the mutation fn).
|
|
100
|
+
*/
|
|
101
|
+
const firstArgument = node.arguments[0]
|
|
102
|
+
if (isFunctionDefinition(firstArgument)) {
|
|
103
|
+
const objectExpression = jscodeshift.objectExpression([
|
|
104
|
+
jscodeshift.property(
|
|
105
|
+
'init',
|
|
106
|
+
jscodeshift.identifier(config.fnName),
|
|
107
|
+
firstArgument,
|
|
108
|
+
),
|
|
109
|
+
])
|
|
110
|
+
|
|
111
|
+
const secondArgument = node.arguments[1]
|
|
112
|
+
|
|
113
|
+
if (secondArgument) {
|
|
114
|
+
// If it's an object expression, we can copy the properties from it to the newly created object expression.
|
|
115
|
+
if (utils.isObjectExpression(secondArgument)) {
|
|
116
|
+
v5Utils.copyPropertiesFromSource(
|
|
117
|
+
secondArgument,
|
|
118
|
+
objectExpression,
|
|
119
|
+
predicate,
|
|
120
|
+
)
|
|
121
|
+
} else {
|
|
122
|
+
// Otherwise, we simply spread the second argument in the newly created object expression.
|
|
123
|
+
objectExpression.properties.push(
|
|
124
|
+
jscodeshift.spreadElement(secondArgument),
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return jscodeshift.callExpression(node.original.callee, [
|
|
130
|
+
objectExpression,
|
|
131
|
+
])
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* If, instead, the first parameter is an array expression or an identifier that references
|
|
136
|
+
* an array expression, then we create an object property from it (the query or mutation key).
|
|
137
|
+
*
|
|
138
|
+
* @type {import('jscodeshift').Property|undefined}
|
|
139
|
+
*/
|
|
140
|
+
const keyProperty = v5Utils.transformArgumentToKey(
|
|
141
|
+
path,
|
|
142
|
+
node.arguments[0],
|
|
143
|
+
config.keyName,
|
|
144
|
+
filePath,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The first parameter couldn't be transformed into an object property, so it's time to throw an exception,
|
|
149
|
+
* it will notify the consumers that they need to rewrite this usage manually.
|
|
150
|
+
*/
|
|
151
|
+
if (!keyProperty) {
|
|
152
|
+
const secondArgument =
|
|
153
|
+
node.arguments.length > 1 ? node.arguments[1] : null
|
|
154
|
+
|
|
155
|
+
if (!secondArgument) {
|
|
156
|
+
throw new UnknownUsageError(node, filePath)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (utils.isFunctionDefinition(secondArgument)) {
|
|
160
|
+
const originalArguments = node.arguments
|
|
161
|
+
const firstArgument = jscodeshift.objectExpression([
|
|
162
|
+
jscodeshift.property(
|
|
163
|
+
'init',
|
|
164
|
+
jscodeshift.identifier(config.keyName),
|
|
165
|
+
originalArguments[0],
|
|
166
|
+
),
|
|
167
|
+
jscodeshift.property(
|
|
168
|
+
'init',
|
|
169
|
+
jscodeshift.identifier(config.fnName),
|
|
170
|
+
secondArgument,
|
|
171
|
+
),
|
|
172
|
+
])
|
|
173
|
+
|
|
174
|
+
return jscodeshift.callExpression(node.original.callee, [
|
|
175
|
+
firstArgument,
|
|
176
|
+
...originalArguments.slice(2),
|
|
177
|
+
])
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const functionArguments = [jscodeshift.objectExpression([keyProperty])]
|
|
182
|
+
const secondParameter = node.arguments[1]
|
|
183
|
+
|
|
184
|
+
if (secondParameter) {
|
|
185
|
+
const createdObjectExpression = functionArguments[0]
|
|
186
|
+
|
|
187
|
+
if (isFunctionDefinition(secondParameter)) {
|
|
188
|
+
const objectExpression = jscodeshift.objectExpression([
|
|
189
|
+
jscodeshift.property(
|
|
190
|
+
'init',
|
|
191
|
+
jscodeshift.identifier(config.keyName),
|
|
192
|
+
node.arguments[0],
|
|
193
|
+
),
|
|
194
|
+
jscodeshift.property(
|
|
195
|
+
'init',
|
|
196
|
+
jscodeshift.identifier(config.fnName),
|
|
197
|
+
secondParameter,
|
|
198
|
+
),
|
|
199
|
+
])
|
|
200
|
+
|
|
201
|
+
const thirdArgument = node.arguments[2]
|
|
202
|
+
|
|
203
|
+
if (thirdArgument) {
|
|
204
|
+
// If it's an object expression, we can copy the properties from it to the newly created object expression.
|
|
205
|
+
if (utils.isObjectExpression(thirdArgument)) {
|
|
206
|
+
v5Utils.copyPropertiesFromSource(
|
|
207
|
+
thirdArgument,
|
|
208
|
+
objectExpression,
|
|
209
|
+
predicate,
|
|
210
|
+
)
|
|
211
|
+
} else {
|
|
212
|
+
// Otherwise, we simply spread the third argument in the newly created object expression.
|
|
213
|
+
objectExpression.properties.push(
|
|
214
|
+
jscodeshift.spreadElement(thirdArgument),
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return jscodeshift.callExpression(node.original.callee, [
|
|
220
|
+
objectExpression,
|
|
221
|
+
])
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* If it has a second argument, and it's an object expression, then we get the properties from it
|
|
226
|
+
* (except the "queryKey" or "mutationKey" properties), because these arguments will also be moved to the
|
|
227
|
+
* newly created object expression.
|
|
228
|
+
*/
|
|
229
|
+
if (utils.isObjectExpression(secondParameter)) {
|
|
230
|
+
v5Utils.copyPropertiesFromSource(
|
|
231
|
+
secondParameter,
|
|
232
|
+
createdObjectExpression,
|
|
233
|
+
predicate,
|
|
234
|
+
)
|
|
235
|
+
} else {
|
|
236
|
+
// Otherwise, we simply spread the second parameter in the newly created object expression.
|
|
237
|
+
createdObjectExpression.properties.push(
|
|
238
|
+
jscodeshift.spreadElement(secondParameter),
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// The rest of the function arguments can be simply pushed to the function arguments object so all will be kept.
|
|
244
|
+
functionArguments.push(...node.arguments.slice(2))
|
|
245
|
+
|
|
246
|
+
return jscodeshift.callExpression(node.original.callee, functionArguments)
|
|
247
|
+
} catch (error) {
|
|
248
|
+
utils.warn(
|
|
249
|
+
error.name === UnknownUsageError.name
|
|
250
|
+
? error.message
|
|
251
|
+
: `An unknown error occurred while processing the "${filePath}" file. Please review this file, because the codemod couldn't be applied.`,
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
return node
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
createQueryClientTransformer({ jscodeshift, utils, root }).execute(
|
|
259
|
+
config.queryClientMethods,
|
|
260
|
+
replacer,
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
createUseQueryLikeTransformer({ jscodeshift, utils, root }).execute(
|
|
264
|
+
config.hooks,
|
|
265
|
+
replacer,
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
createQueryCacheTransformer({ jscodeshift, utils, root }).execute(replacer)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
module.exports = transformFilterAwareUsages
|