@tanstack/react-query 5.28.9 → 5.28.12
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/coverage/clover.xml +74 -55
- package/build/codemods/coverage/coverage-final.json +4 -4
- package/build/codemods/coverage/index.html +11 -11
- package/build/codemods/coverage/utils/index.html +1 -1
- package/build/codemods/coverage/utils/index.js.html +1 -1
- package/build/codemods/coverage/utils/transformers/index.html +1 -1
- package/build/codemods/coverage/utils/transformers/query-cache-transformer.js.html +1 -1
- package/build/codemods/coverage/utils/transformers/query-client-transformer.js.html +1 -1
- package/build/codemods/coverage/utils/transformers/use-query-like-transformer.js.html +1 -1
- package/build/codemods/coverage/v4/index.html +1 -1
- package/build/codemods/coverage/v4/key-transformation.js.html +1 -1
- package/build/codemods/coverage/v4/replace-import-specifier.js.html +1 -1
- package/build/codemods/coverage/v4/utils/replacers/index.html +1 -1
- package/build/codemods/coverage/v4/utils/replacers/key-replacer.js.html +1 -1
- package/build/codemods/coverage/v5/is-loading/index.html +1 -1
- package/build/codemods/coverage/v5/is-loading/is-loading.js.html +1 -1
- package/build/codemods/coverage/v5/keep-previous-data/index.html +1 -1
- package/build/codemods/coverage/v5/keep-previous-data/keep-previous-data.js.html +1 -1
- package/build/codemods/coverage/v5/keep-previous-data/utils/already-has-placeholder-data-property.js.html +1 -1
- package/build/codemods/coverage/v5/keep-previous-data/utils/index.html +1 -1
- package/build/codemods/coverage/v5/remove-overloads/index.html +1 -1
- package/build/codemods/coverage/v5/remove-overloads/remove-overloads.js.html +9 -3
- package/build/codemods/coverage/v5/remove-overloads/transformers/filter-aware-usage-transformer.js.html +137 -17
- package/build/codemods/coverage/v5/remove-overloads/transformers/index.html +7 -7
- package/build/codemods/coverage/v5/remove-overloads/transformers/query-fn-aware-usage-transformer.js.html +1 -1
- package/build/codemods/coverage/v5/remove-overloads/utils/index.html +1 -1
- package/build/codemods/coverage/v5/remove-overloads/utils/index.js.html +1 -1
- package/build/codemods/coverage/v5/remove-overloads/utils/unknown-usage-error.js.html +1 -1
- package/build/codemods/coverage/v5/rename-hydrate/index.html +1 -1
- package/build/codemods/coverage/v5/rename-hydrate/rename-hydrate.js.html +1 -1
- package/build/codemods/coverage/v5/rename-properties/index.html +1 -1
- package/build/codemods/coverage/v5/rename-properties/rename-properties.js.html +1 -1
- package/build/codemods/src/v5/remove-overloads/remove-overloads.js +3 -1
- package/build/codemods/src/v5/remove-overloads/transformers/filter-aware-usage-transformer.js +52 -12
- package/package.json +2 -2
- package/src/__tests__/useInfiniteQuery.test-d.tsx +0 -21
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
102
102
|
Code coverage generated by
|
|
103
103
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
104
|
-
at 2024-
|
|
104
|
+
at 2024-04-02T07:01:10.683Z
|
|
105
105
|
</div>
|
|
106
106
|
<script src="../../prettify.js"></script>
|
|
107
107
|
<script>
|
|
@@ -193,7 +193,7 @@
|
|
|
193
193
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
194
194
|
Code coverage generated by
|
|
195
195
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
196
|
-
at 2024-
|
|
196
|
+
at 2024-04-02T07:01:10.683Z
|
|
197
197
|
</div>
|
|
198
198
|
<script src="../../prettify.js"></script>
|
|
199
199
|
<script>
|
|
@@ -17,6 +17,7 @@ module.exports = (file, api) => {
|
|
|
17
17
|
...dependencies,
|
|
18
18
|
config: {
|
|
19
19
|
keyName: 'queryKey',
|
|
20
|
+
fnName: 'queryFn',
|
|
20
21
|
queryClientMethods: [
|
|
21
22
|
'cancelQueries',
|
|
22
23
|
'getQueriesData',
|
|
@@ -35,8 +36,9 @@ module.exports = (file, api) => {
|
|
|
35
36
|
...dependencies,
|
|
36
37
|
config: {
|
|
37
38
|
keyName: 'mutationKey',
|
|
39
|
+
fnName: 'mutationFn',
|
|
38
40
|
queryClientMethods: [],
|
|
39
|
-
hooks: ['useIsMutating'],
|
|
41
|
+
hooks: ['useIsMutating', 'useMutation'],
|
|
40
42
|
},
|
|
41
43
|
})
|
|
42
44
|
|
package/build/codemods/src/v5/remove-overloads/transformers/filter-aware-usage-transformer.js
CHANGED
|
@@ -14,7 +14,7 @@ const createUseQueryLikeTransformer = require('../../../utils/transformers/use-q
|
|
|
14
14
|
* @param {Object} utils
|
|
15
15
|
* @param {import('jscodeshift').Collection} root
|
|
16
16
|
* @param {string} filePath
|
|
17
|
-
* @param {{keyName: "mutationKey"|"queryKey", queryClientMethods: ReadonlyArray<string>, hooks: ReadonlyArray<string>}} config
|
|
17
|
+
* @param {{keyName: "mutationKey"|"queryKey", fnName: "mutationFn"|"queryFn", queryClientMethods: ReadonlyArray<string>, hooks: ReadonlyArray<string>}} config
|
|
18
18
|
*/
|
|
19
19
|
const transformFilterAwareUsages = ({
|
|
20
20
|
jscodeshift,
|
|
@@ -28,15 +28,18 @@ const transformFilterAwareUsages = ({
|
|
|
28
28
|
/**
|
|
29
29
|
* @param {import('jscodeshift').CallExpression} node
|
|
30
30
|
* @param {"mutationKey"|"queryKey"} keyName
|
|
31
|
+
* @param {"mutationFn"|"queryFn"} fnName
|
|
31
32
|
* @returns {boolean}
|
|
32
33
|
*/
|
|
33
|
-
const canSkipReplacement = (node, keyName) => {
|
|
34
|
+
const canSkipReplacement = (node, keyName, fnName) => {
|
|
34
35
|
const callArguments = node.arguments
|
|
35
36
|
|
|
36
|
-
const
|
|
37
|
+
const hasKeyOrFnProperty = () =>
|
|
37
38
|
callArguments[0].properties.some(
|
|
38
39
|
(property) =>
|
|
39
|
-
utils.isObjectProperty(property) &&
|
|
40
|
+
utils.isObjectProperty(property) &&
|
|
41
|
+
property.key.name !== keyName &&
|
|
42
|
+
property.key.name !== fnName,
|
|
40
43
|
)
|
|
41
44
|
|
|
42
45
|
/**
|
|
@@ -46,7 +49,7 @@ const transformFilterAwareUsages = ({
|
|
|
46
49
|
return (
|
|
47
50
|
callArguments.length > 0 &&
|
|
48
51
|
utils.isObjectExpression(callArguments[0]) &&
|
|
49
|
-
|
|
52
|
+
hasKeyOrFnProperty()
|
|
50
53
|
)
|
|
51
54
|
}
|
|
52
55
|
|
|
@@ -92,13 +95,50 @@ const transformFilterAwareUsages = ({
|
|
|
92
95
|
|
|
93
96
|
try {
|
|
94
97
|
// If the given method/function call matches certain criteria, the node doesn't need to be replaced, this step can be skipped.
|
|
95
|
-
if (canSkipReplacement(node, config.keyName)) {
|
|
98
|
+
if (canSkipReplacement(node, config.keyName, config.fnName)) {
|
|
96
99
|
return node
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
/**
|
|
100
|
-
* Here we attempt to determine the first parameter of the function call.
|
|
101
|
-
*
|
|
103
|
+
* Here we attempt to determine the first parameter of the function call.
|
|
104
|
+
* If it's a function definition, we can create an object property from it (the mutation fn).
|
|
105
|
+
*/
|
|
106
|
+
const firstArgument = node.arguments[0]
|
|
107
|
+
if (isFunctionDefinition(firstArgument)) {
|
|
108
|
+
const objectExpression = jscodeshift.objectExpression([
|
|
109
|
+
jscodeshift.property(
|
|
110
|
+
'init',
|
|
111
|
+
jscodeshift.identifier(config.fnName),
|
|
112
|
+
firstArgument,
|
|
113
|
+
),
|
|
114
|
+
])
|
|
115
|
+
|
|
116
|
+
const secondArgument = node.arguments[1]
|
|
117
|
+
|
|
118
|
+
if (secondArgument) {
|
|
119
|
+
// If it's an object expression, we can copy the properties from it to the newly created object expression.
|
|
120
|
+
if (utils.isObjectExpression(secondArgument)) {
|
|
121
|
+
v5Utils.copyPropertiesFromSource(
|
|
122
|
+
secondArgument,
|
|
123
|
+
objectExpression,
|
|
124
|
+
predicate,
|
|
125
|
+
)
|
|
126
|
+
} else {
|
|
127
|
+
// Otherwise, we simply spread the second argument in the newly created object expression.
|
|
128
|
+
objectExpression.properties.push(
|
|
129
|
+
jscodeshift.spreadElement(secondArgument),
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return jscodeshift.callExpression(node.original.callee, [
|
|
135
|
+
objectExpression,
|
|
136
|
+
])
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* If, instead, the first parameter is an array expression or an identifier that references
|
|
141
|
+
* an array expression, then we create an object property from it (the query or mutation key).
|
|
102
142
|
*
|
|
103
143
|
* @type {import('jscodeshift').Property|undefined}
|
|
104
144
|
*/
|
|
@@ -126,12 +166,12 @@ const transformFilterAwareUsages = ({
|
|
|
126
166
|
const firstArgument = jscodeshift.objectExpression([
|
|
127
167
|
jscodeshift.property(
|
|
128
168
|
'init',
|
|
129
|
-
jscodeshift.identifier(
|
|
169
|
+
jscodeshift.identifier(config.keyName),
|
|
130
170
|
originalArguments[0],
|
|
131
171
|
),
|
|
132
172
|
jscodeshift.property(
|
|
133
173
|
'init',
|
|
134
|
-
jscodeshift.identifier(
|
|
174
|
+
jscodeshift.identifier(config.fnName),
|
|
135
175
|
secondArgument,
|
|
136
176
|
),
|
|
137
177
|
])
|
|
@@ -153,12 +193,12 @@ const transformFilterAwareUsages = ({
|
|
|
153
193
|
const objectExpression = jscodeshift.objectExpression([
|
|
154
194
|
jscodeshift.property(
|
|
155
195
|
'init',
|
|
156
|
-
jscodeshift.identifier(
|
|
196
|
+
jscodeshift.identifier(config.keyName),
|
|
157
197
|
node.arguments[0],
|
|
158
198
|
),
|
|
159
199
|
jscodeshift.property(
|
|
160
200
|
'init',
|
|
161
|
-
jscodeshift.identifier(
|
|
201
|
+
jscodeshift.identifier(config.fnName),
|
|
162
202
|
secondParameter,
|
|
163
203
|
),
|
|
164
204
|
])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query",
|
|
3
|
-
"version": "5.28.
|
|
3
|
+
"version": "5.28.12",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"!build/codemods/**/__tests__"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@tanstack/query-core": "5.28.
|
|
44
|
+
"@tanstack/query-core": "5.28.12"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/react": "^18.2.55",
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { describe, expectTypeOf, it } from 'vitest'
|
|
2
2
|
import { QueryClient } from '@tanstack/query-core'
|
|
3
3
|
import { useInfiniteQuery } from '../useInfiniteQuery'
|
|
4
|
-
import { useQuery } from '../useQuery'
|
|
5
4
|
import type { InfiniteData } from '@tanstack/query-core'
|
|
6
5
|
|
|
7
6
|
describe('pageParam', () => {
|
|
@@ -27,26 +26,6 @@ describe('pageParam', () => {
|
|
|
27
26
|
})
|
|
28
27
|
})
|
|
29
28
|
|
|
30
|
-
it('there should be no pageParam passed to the queryFn of useQuery', () => {
|
|
31
|
-
useQuery({
|
|
32
|
-
queryKey: ['key'],
|
|
33
|
-
// @ts-expect-error there should be no pageParam passed to queryFn of useQuery
|
|
34
|
-
queryFn: ({ pageParam }) => {
|
|
35
|
-
return String(pageParam)
|
|
36
|
-
},
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('there should be no direction passed to the queryFn of useQuery', () => {
|
|
41
|
-
useQuery({
|
|
42
|
-
queryKey: ['key'],
|
|
43
|
-
// @ts-expect-error there should be no pageParam passed to queryFn of useQuery
|
|
44
|
-
queryFn: ({ direction }) => {
|
|
45
|
-
return String(direction)
|
|
46
|
-
},
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
|
|
50
29
|
it('initialPageParam should define type of param passed to queryFunctionContext for fetchInfiniteQuery', () => {
|
|
51
30
|
const queryClient = new QueryClient()
|
|
52
31
|
queryClient.fetchInfiniteQuery({
|