@tanstack/react-query
Advanced tools
Comparing version 5.28.9 to 5.28.12
@@ -20,2 +20,3 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
keyName: 'queryKey', | ||
fnName: 'queryFn', | ||
queryClientMethods: [ | ||
@@ -39,4 +40,5 @@ 'cancelQueries', | ||
keyName: 'mutationKey', | ||
fnName: 'mutationFn', | ||
queryClientMethods: [], | ||
hooks: ['useIsMutating'], | ||
hooks: ['useIsMutating', 'useMutation'], | ||
}, | ||
@@ -43,0 +45,0 @@ }) |
@@ -17,3 +17,3 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
* @param {string} filePath | ||
* @param {{keyName: "mutationKey"|"queryKey", queryClientMethods: ReadonlyArray<string>, hooks: ReadonlyArray<string>}} config | ||
* @param {{keyName: "mutationKey"|"queryKey", fnName: "mutationFn"|"queryFn", queryClientMethods: ReadonlyArray<string>, hooks: ReadonlyArray<string>}} config | ||
*/ | ||
@@ -32,11 +32,14 @@ const transformFilterAwareUsages = ({ | ||
* @param {"mutationKey"|"queryKey"} keyName | ||
* @param {"mutationFn"|"queryFn"} fnName | ||
* @returns {boolean} | ||
*/ | ||
const canSkipReplacement = (node, keyName) => { | ||
const canSkipReplacement = (node, keyName, fnName) => { | ||
const callArguments = node.arguments | ||
const hasKeyProperty = () => | ||
const hasKeyOrFnProperty = () => | ||
callArguments[0].properties.some( | ||
(property) => | ||
utils.isObjectProperty(property) && property.key.name !== keyName, | ||
utils.isObjectProperty(property) && | ||
property.key.name !== keyName && | ||
property.key.name !== fnName, | ||
) | ||
@@ -51,3 +54,3 @@ | ||
utils.isObjectExpression(callArguments[0]) && | ||
hasKeyProperty() | ||
hasKeyOrFnProperty() | ||
) | ||
@@ -98,3 +101,3 @@ } | ||
// If the given method/function call matches certain criteria, the node doesn't need to be replaced, this step can be skipped. | ||
if (canSkipReplacement(node, config.keyName)) { | ||
if (canSkipReplacement(node, config.keyName, config.fnName)) { | ||
return node | ||
@@ -104,4 +107,41 @@ } | ||
/** | ||
* Here we attempt to determine the first parameter of the function call. If it's an array expression or an | ||
* identifier that references an array expression then we create an object property from it. | ||
* Here we attempt to determine the first parameter of the function call. | ||
* If it's a function definition, we can create an object property from it (the mutation fn). | ||
*/ | ||
const firstArgument = node.arguments[0] | ||
if (isFunctionDefinition(firstArgument)) { | ||
const objectExpression = jscodeshift.objectExpression([ | ||
jscodeshift.property( | ||
'init', | ||
jscodeshift.identifier(config.fnName), | ||
firstArgument, | ||
), | ||
]) | ||
const secondArgument = node.arguments[1] | ||
if (secondArgument) { | ||
// If it's an object expression, we can copy the properties from it to the newly created object expression. | ||
if (utils.isObjectExpression(secondArgument)) { | ||
v5Utils.copyPropertiesFromSource( | ||
secondArgument, | ||
objectExpression, | ||
predicate, | ||
) | ||
} else { | ||
// Otherwise, we simply spread the second argument in the newly created object expression. | ||
objectExpression.properties.push( | ||
jscodeshift.spreadElement(secondArgument), | ||
) | ||
} | ||
} | ||
return jscodeshift.callExpression(node.original.callee, [ | ||
objectExpression, | ||
]) | ||
} | ||
/** | ||
* If, instead, the first parameter is an array expression or an identifier that references | ||
* an array expression, then we create an object property from it (the query or mutation key). | ||
* | ||
@@ -134,3 +174,3 @@ * @type {import('jscodeshift').Property|undefined} | ||
'init', | ||
jscodeshift.identifier('queryKey'), | ||
jscodeshift.identifier(config.keyName), | ||
originalArguments[0], | ||
@@ -140,3 +180,3 @@ ), | ||
'init', | ||
jscodeshift.identifier('queryFn'), | ||
jscodeshift.identifier(config.fnName), | ||
secondArgument, | ||
@@ -163,3 +203,3 @@ ), | ||
'init', | ||
jscodeshift.identifier('queryKey'), | ||
jscodeshift.identifier(config.keyName), | ||
node.arguments[0], | ||
@@ -169,3 +209,3 @@ ), | ||
'init', | ||
jscodeshift.identifier('queryFn'), | ||
jscodeshift.identifier(config.fnName), | ||
secondParameter, | ||
@@ -172,0 +212,0 @@ ), |
{ | ||
"name": "@tanstack/react-query", | ||
"version": "5.28.9", | ||
"version": "5.28.12", | ||
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React", | ||
@@ -44,3 +44,3 @@ "author": "tannerlinsley", | ||
"dependencies": { | ||
"@tanstack/query-core": "5.28.9" | ||
"@tanstack/query-core": "5.28.12" | ||
}, | ||
@@ -47,0 +47,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1944998
22427
+ Added@tanstack/query-core@5.28.12(transitive)
- Removed@tanstack/query-core@5.28.9(transitive)
Updated@tanstack/query-core@5.28.12