@depup/tanstack__react-query 5.91.0-depup.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.
Files changed (330) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/build/codemods/src/utils/index.cjs +208 -0
  4. package/build/codemods/src/utils/transformers/query-cache-transformer.cjs +124 -0
  5. package/build/codemods/src/utils/transformers/query-client-transformer.cjs +53 -0
  6. package/build/codemods/src/utils/transformers/use-query-like-transformer.cjs +38 -0
  7. package/build/codemods/src/v4/key-transformation.cjs +181 -0
  8. package/build/codemods/src/v4/replace-import-specifier.cjs +25 -0
  9. package/build/codemods/src/v4/utils/replacers/key-replacer.cjs +164 -0
  10. package/build/codemods/src/v5/is-loading/is-loading.cjs +244 -0
  11. package/build/codemods/src/v5/keep-previous-data/README.md +32 -0
  12. package/build/codemods/src/v5/keep-previous-data/keep-previous-data.cjs +271 -0
  13. package/build/codemods/src/v5/keep-previous-data/utils/already-has-placeholder-data-property.cjs +26 -0
  14. package/build/codemods/src/v5/remove-overloads/remove-overloads.cjs +58 -0
  15. package/build/codemods/src/v5/remove-overloads/transformers/filter-aware-usage-transformer.cjs +271 -0
  16. package/build/codemods/src/v5/remove-overloads/transformers/query-fn-aware-usage-transformer.cjs +185 -0
  17. package/build/codemods/src/v5/remove-overloads/utils/index.cjs +123 -0
  18. package/build/codemods/src/v5/remove-overloads/utils/unknown-usage-error.cjs +27 -0
  19. package/build/codemods/src/v5/rename-hydrate/rename-hydrate.cjs +55 -0
  20. package/build/codemods/src/v5/rename-properties/rename-properties.cjs +41 -0
  21. package/build/legacy/HydrationBoundary.cjs +91 -0
  22. package/build/legacy/HydrationBoundary.cjs.map +1 -0
  23. package/build/legacy/HydrationBoundary.d.cts +2 -0
  24. package/build/legacy/HydrationBoundary.d.ts +2 -0
  25. package/build/legacy/HydrationBoundary.js +57 -0
  26. package/build/legacy/HydrationBoundary.js.map +1 -0
  27. package/build/legacy/IsRestoringProvider.cjs +47 -0
  28. package/build/legacy/IsRestoringProvider.cjs.map +1 -0
  29. package/build/legacy/IsRestoringProvider.d.cts +2 -0
  30. package/build/legacy/IsRestoringProvider.d.ts +2 -0
  31. package/build/legacy/IsRestoringProvider.js +12 -0
  32. package/build/legacy/IsRestoringProvider.js.map +1 -0
  33. package/build/legacy/QueryClientProvider.cjs +72 -0
  34. package/build/legacy/QueryClientProvider.cjs.map +1 -0
  35. package/build/legacy/QueryClientProvider.d.cts +4 -0
  36. package/build/legacy/QueryClientProvider.d.ts +4 -0
  37. package/build/legacy/QueryClientProvider.js +36 -0
  38. package/build/legacy/QueryClientProvider.js.map +1 -0
  39. package/build/legacy/QueryErrorResetBoundary.cjs +67 -0
  40. package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -0
  41. package/build/legacy/QueryErrorResetBoundary.d.cts +8 -0
  42. package/build/legacy/QueryErrorResetBoundary.d.ts +8 -0
  43. package/build/legacy/QueryErrorResetBoundary.js +32 -0
  44. package/build/legacy/QueryErrorResetBoundary.js.map +1 -0
  45. package/build/legacy/_tsup-dts-rollup.d.cts +993 -0
  46. package/build/legacy/_tsup-dts-rollup.d.ts +993 -0
  47. package/build/legacy/errorBoundaryUtils.cjs +69 -0
  48. package/build/legacy/errorBoundaryUtils.cjs.map +1 -0
  49. package/build/legacy/errorBoundaryUtils.d.cts +3 -0
  50. package/build/legacy/errorBoundaryUtils.d.ts +3 -0
  51. package/build/legacy/errorBoundaryUtils.js +33 -0
  52. package/build/legacy/errorBoundaryUtils.js.map +1 -0
  53. package/build/legacy/index.cjs +97 -0
  54. package/build/legacy/index.cjs.map +1 -0
  55. package/build/legacy/index.d.cts +206 -0
  56. package/build/legacy/index.d.ts +206 -0
  57. package/build/legacy/index.js +54 -0
  58. package/build/legacy/index.js.map +1 -0
  59. package/build/legacy/infiniteQueryOptions.cjs +33 -0
  60. package/build/legacy/infiniteQueryOptions.cjs.map +1 -0
  61. package/build/legacy/infiniteQueryOptions.d.cts +4 -0
  62. package/build/legacy/infiniteQueryOptions.d.ts +4 -0
  63. package/build/legacy/infiniteQueryOptions.js +8 -0
  64. package/build/legacy/infiniteQueryOptions.js.map +1 -0
  65. package/build/legacy/mutationOptions.cjs +33 -0
  66. package/build/legacy/mutationOptions.cjs.map +1 -0
  67. package/build/legacy/mutationOptions.d.cts +1 -0
  68. package/build/legacy/mutationOptions.d.ts +1 -0
  69. package/build/legacy/mutationOptions.js +8 -0
  70. package/build/legacy/mutationOptions.js.map +1 -0
  71. package/build/legacy/queryOptions.cjs +33 -0
  72. package/build/legacy/queryOptions.cjs.map +1 -0
  73. package/build/legacy/queryOptions.d.cts +4 -0
  74. package/build/legacy/queryOptions.d.ts +4 -0
  75. package/build/legacy/queryOptions.js +8 -0
  76. package/build/legacy/queryOptions.js.map +1 -0
  77. package/build/legacy/suspense.cjs +58 -0
  78. package/build/legacy/suspense.cjs.map +1 -0
  79. package/build/legacy/suspense.d.cts +5 -0
  80. package/build/legacy/suspense.d.ts +5 -0
  81. package/build/legacy/suspense.js +29 -0
  82. package/build/legacy/suspense.js.map +1 -0
  83. package/build/legacy/types.cjs +19 -0
  84. package/build/legacy/types.cjs.map +1 -0
  85. package/build/legacy/types.d.cts +24 -0
  86. package/build/legacy/types.d.ts +24 -0
  87. package/build/legacy/types.js +1 -0
  88. package/build/legacy/types.js.map +1 -0
  89. package/build/legacy/useBaseQuery.cjs +133 -0
  90. package/build/legacy/useBaseQuery.cjs.map +1 -0
  91. package/build/legacy/useBaseQuery.d.cts +1 -0
  92. package/build/legacy/useBaseQuery.d.ts +1 -0
  93. package/build/legacy/useBaseQuery.js +108 -0
  94. package/build/legacy/useBaseQuery.js.map +1 -0
  95. package/build/legacy/useInfiniteQuery.cjs +40 -0
  96. package/build/legacy/useInfiniteQuery.cjs.map +1 -0
  97. package/build/legacy/useInfiniteQuery.d.cts +1 -0
  98. package/build/legacy/useInfiniteQuery.d.ts +1 -0
  99. package/build/legacy/useInfiniteQuery.js +16 -0
  100. package/build/legacy/useInfiniteQuery.js.map +1 -0
  101. package/build/legacy/useIsFetching.cjs +56 -0
  102. package/build/legacy/useIsFetching.cjs.map +1 -0
  103. package/build/legacy/useIsFetching.d.cts +1 -0
  104. package/build/legacy/useIsFetching.d.ts +1 -0
  105. package/build/legacy/useIsFetching.js +22 -0
  106. package/build/legacy/useIsFetching.js.map +1 -0
  107. package/build/legacy/useMutation.cjs +74 -0
  108. package/build/legacy/useMutation.cjs.map +1 -0
  109. package/build/legacy/useMutation.d.cts +1 -0
  110. package/build/legacy/useMutation.d.ts +1 -0
  111. package/build/legacy/useMutation.js +45 -0
  112. package/build/legacy/useMutation.js.map +1 -0
  113. package/build/legacy/useMutationState.cjs +86 -0
  114. package/build/legacy/useMutationState.cjs.map +1 -0
  115. package/build/legacy/useMutationState.d.cts +2 -0
  116. package/build/legacy/useMutationState.d.ts +2 -0
  117. package/build/legacy/useMutationState.js +51 -0
  118. package/build/legacy/useMutationState.js.map +1 -0
  119. package/build/legacy/usePrefetchInfiniteQuery.cjs +37 -0
  120. package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -0
  121. package/build/legacy/usePrefetchInfiniteQuery.d.cts +1 -0
  122. package/build/legacy/usePrefetchInfiniteQuery.d.ts +1 -0
  123. package/build/legacy/usePrefetchInfiniteQuery.js +12 -0
  124. package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -0
  125. package/build/legacy/usePrefetchQuery.cjs +37 -0
  126. package/build/legacy/usePrefetchQuery.cjs.map +1 -0
  127. package/build/legacy/usePrefetchQuery.d.cts +1 -0
  128. package/build/legacy/usePrefetchQuery.d.ts +1 -0
  129. package/build/legacy/usePrefetchQuery.js +12 -0
  130. package/build/legacy/usePrefetchQuery.js.map +1 -0
  131. package/build/legacy/useQueries.cjs +128 -0
  132. package/build/legacy/useQueries.cjs.map +1 -0
  133. package/build/legacy/useQueries.d.cts +3 -0
  134. package/build/legacy/useQueries.d.ts +3 -0
  135. package/build/legacy/useQueries.js +107 -0
  136. package/build/legacy/useQueries.js.map +1 -0
  137. package/build/legacy/useQuery.cjs +36 -0
  138. package/build/legacy/useQuery.cjs.map +1 -0
  139. package/build/legacy/useQuery.d.cts +1 -0
  140. package/build/legacy/useQuery.d.ts +1 -0
  141. package/build/legacy/useQuery.js +12 -0
  142. package/build/legacy/useQuery.js.map +1 -0
  143. package/build/legacy/useSuspenseInfiniteQuery.cjs +51 -0
  144. package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -0
  145. package/build/legacy/useSuspenseInfiniteQuery.d.cts +1 -0
  146. package/build/legacy/useSuspenseInfiniteQuery.d.ts +1 -0
  147. package/build/legacy/useSuspenseInfiniteQuery.js +27 -0
  148. package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -0
  149. package/build/legacy/useSuspenseQueries.cjs +56 -0
  150. package/build/legacy/useSuspenseQueries.cjs.map +1 -0
  151. package/build/legacy/useSuspenseQueries.d.cts +3 -0
  152. package/build/legacy/useSuspenseQueries.d.ts +3 -0
  153. package/build/legacy/useSuspenseQueries.js +32 -0
  154. package/build/legacy/useSuspenseQueries.js.map +1 -0
  155. package/build/legacy/useSuspenseQuery.cjs +52 -0
  156. package/build/legacy/useSuspenseQuery.cjs.map +1 -0
  157. package/build/legacy/useSuspenseQuery.d.cts +1 -0
  158. package/build/legacy/useSuspenseQuery.d.ts +1 -0
  159. package/build/legacy/useSuspenseQuery.js +28 -0
  160. package/build/legacy/useSuspenseQuery.js.map +1 -0
  161. package/build/modern/HydrationBoundary.cjs +91 -0
  162. package/build/modern/HydrationBoundary.cjs.map +1 -0
  163. package/build/modern/HydrationBoundary.d.cts +2 -0
  164. package/build/modern/HydrationBoundary.d.ts +2 -0
  165. package/build/modern/HydrationBoundary.js +57 -0
  166. package/build/modern/HydrationBoundary.js.map +1 -0
  167. package/build/modern/IsRestoringProvider.cjs +47 -0
  168. package/build/modern/IsRestoringProvider.cjs.map +1 -0
  169. package/build/modern/IsRestoringProvider.d.cts +2 -0
  170. package/build/modern/IsRestoringProvider.d.ts +2 -0
  171. package/build/modern/IsRestoringProvider.js +12 -0
  172. package/build/modern/IsRestoringProvider.js.map +1 -0
  173. package/build/modern/QueryClientProvider.cjs +72 -0
  174. package/build/modern/QueryClientProvider.cjs.map +1 -0
  175. package/build/modern/QueryClientProvider.d.cts +4 -0
  176. package/build/modern/QueryClientProvider.d.ts +4 -0
  177. package/build/modern/QueryClientProvider.js +36 -0
  178. package/build/modern/QueryClientProvider.js.map +1 -0
  179. package/build/modern/QueryErrorResetBoundary.cjs +67 -0
  180. package/build/modern/QueryErrorResetBoundary.cjs.map +1 -0
  181. package/build/modern/QueryErrorResetBoundary.d.cts +8 -0
  182. package/build/modern/QueryErrorResetBoundary.d.ts +8 -0
  183. package/build/modern/QueryErrorResetBoundary.js +32 -0
  184. package/build/modern/QueryErrorResetBoundary.js.map +1 -0
  185. package/build/modern/_tsup-dts-rollup.d.cts +993 -0
  186. package/build/modern/_tsup-dts-rollup.d.ts +993 -0
  187. package/build/modern/errorBoundaryUtils.cjs +69 -0
  188. package/build/modern/errorBoundaryUtils.cjs.map +1 -0
  189. package/build/modern/errorBoundaryUtils.d.cts +3 -0
  190. package/build/modern/errorBoundaryUtils.d.ts +3 -0
  191. package/build/modern/errorBoundaryUtils.js +33 -0
  192. package/build/modern/errorBoundaryUtils.js.map +1 -0
  193. package/build/modern/index.cjs +97 -0
  194. package/build/modern/index.cjs.map +1 -0
  195. package/build/modern/index.d.cts +206 -0
  196. package/build/modern/index.d.ts +206 -0
  197. package/build/modern/index.js +54 -0
  198. package/build/modern/index.js.map +1 -0
  199. package/build/modern/infiniteQueryOptions.cjs +33 -0
  200. package/build/modern/infiniteQueryOptions.cjs.map +1 -0
  201. package/build/modern/infiniteQueryOptions.d.cts +4 -0
  202. package/build/modern/infiniteQueryOptions.d.ts +4 -0
  203. package/build/modern/infiniteQueryOptions.js +8 -0
  204. package/build/modern/infiniteQueryOptions.js.map +1 -0
  205. package/build/modern/mutationOptions.cjs +33 -0
  206. package/build/modern/mutationOptions.cjs.map +1 -0
  207. package/build/modern/mutationOptions.d.cts +1 -0
  208. package/build/modern/mutationOptions.d.ts +1 -0
  209. package/build/modern/mutationOptions.js +8 -0
  210. package/build/modern/mutationOptions.js.map +1 -0
  211. package/build/modern/queryOptions.cjs +33 -0
  212. package/build/modern/queryOptions.cjs.map +1 -0
  213. package/build/modern/queryOptions.d.cts +4 -0
  214. package/build/modern/queryOptions.d.ts +4 -0
  215. package/build/modern/queryOptions.js +8 -0
  216. package/build/modern/queryOptions.js.map +1 -0
  217. package/build/modern/suspense.cjs +58 -0
  218. package/build/modern/suspense.cjs.map +1 -0
  219. package/build/modern/suspense.d.cts +5 -0
  220. package/build/modern/suspense.d.ts +5 -0
  221. package/build/modern/suspense.js +29 -0
  222. package/build/modern/suspense.js.map +1 -0
  223. package/build/modern/types.cjs +19 -0
  224. package/build/modern/types.cjs.map +1 -0
  225. package/build/modern/types.d.cts +24 -0
  226. package/build/modern/types.d.ts +24 -0
  227. package/build/modern/types.js +1 -0
  228. package/build/modern/types.js.map +1 -0
  229. package/build/modern/useBaseQuery.cjs +130 -0
  230. package/build/modern/useBaseQuery.cjs.map +1 -0
  231. package/build/modern/useBaseQuery.d.cts +1 -0
  232. package/build/modern/useBaseQuery.d.ts +1 -0
  233. package/build/modern/useBaseQuery.js +105 -0
  234. package/build/modern/useBaseQuery.js.map +1 -0
  235. package/build/modern/useInfiniteQuery.cjs +40 -0
  236. package/build/modern/useInfiniteQuery.cjs.map +1 -0
  237. package/build/modern/useInfiniteQuery.d.cts +1 -0
  238. package/build/modern/useInfiniteQuery.d.ts +1 -0
  239. package/build/modern/useInfiniteQuery.js +16 -0
  240. package/build/modern/useInfiniteQuery.js.map +1 -0
  241. package/build/modern/useIsFetching.cjs +56 -0
  242. package/build/modern/useIsFetching.cjs.map +1 -0
  243. package/build/modern/useIsFetching.d.cts +1 -0
  244. package/build/modern/useIsFetching.d.ts +1 -0
  245. package/build/modern/useIsFetching.js +22 -0
  246. package/build/modern/useIsFetching.js.map +1 -0
  247. package/build/modern/useMutation.cjs +74 -0
  248. package/build/modern/useMutation.cjs.map +1 -0
  249. package/build/modern/useMutation.d.cts +1 -0
  250. package/build/modern/useMutation.d.ts +1 -0
  251. package/build/modern/useMutation.js +45 -0
  252. package/build/modern/useMutation.js.map +1 -0
  253. package/build/modern/useMutationState.cjs +86 -0
  254. package/build/modern/useMutationState.cjs.map +1 -0
  255. package/build/modern/useMutationState.d.cts +2 -0
  256. package/build/modern/useMutationState.d.ts +2 -0
  257. package/build/modern/useMutationState.js +51 -0
  258. package/build/modern/useMutationState.js.map +1 -0
  259. package/build/modern/usePrefetchInfiniteQuery.cjs +37 -0
  260. package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -0
  261. package/build/modern/usePrefetchInfiniteQuery.d.cts +1 -0
  262. package/build/modern/usePrefetchInfiniteQuery.d.ts +1 -0
  263. package/build/modern/usePrefetchInfiniteQuery.js +12 -0
  264. package/build/modern/usePrefetchInfiniteQuery.js.map +1 -0
  265. package/build/modern/usePrefetchQuery.cjs +37 -0
  266. package/build/modern/usePrefetchQuery.cjs.map +1 -0
  267. package/build/modern/usePrefetchQuery.d.cts +1 -0
  268. package/build/modern/usePrefetchQuery.d.ts +1 -0
  269. package/build/modern/usePrefetchQuery.js +12 -0
  270. package/build/modern/usePrefetchQuery.js.map +1 -0
  271. package/build/modern/useQueries.cjs +128 -0
  272. package/build/modern/useQueries.cjs.map +1 -0
  273. package/build/modern/useQueries.d.cts +3 -0
  274. package/build/modern/useQueries.d.ts +3 -0
  275. package/build/modern/useQueries.js +107 -0
  276. package/build/modern/useQueries.js.map +1 -0
  277. package/build/modern/useQuery.cjs +36 -0
  278. package/build/modern/useQuery.cjs.map +1 -0
  279. package/build/modern/useQuery.d.cts +1 -0
  280. package/build/modern/useQuery.d.ts +1 -0
  281. package/build/modern/useQuery.js +12 -0
  282. package/build/modern/useQuery.js.map +1 -0
  283. package/build/modern/useSuspenseInfiniteQuery.cjs +51 -0
  284. package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -0
  285. package/build/modern/useSuspenseInfiniteQuery.d.cts +1 -0
  286. package/build/modern/useSuspenseInfiniteQuery.d.ts +1 -0
  287. package/build/modern/useSuspenseInfiniteQuery.js +27 -0
  288. package/build/modern/useSuspenseInfiniteQuery.js.map +1 -0
  289. package/build/modern/useSuspenseQueries.cjs +56 -0
  290. package/build/modern/useSuspenseQueries.cjs.map +1 -0
  291. package/build/modern/useSuspenseQueries.d.cts +3 -0
  292. package/build/modern/useSuspenseQueries.d.ts +3 -0
  293. package/build/modern/useSuspenseQueries.js +32 -0
  294. package/build/modern/useSuspenseQueries.js.map +1 -0
  295. package/build/modern/useSuspenseQuery.cjs +52 -0
  296. package/build/modern/useSuspenseQuery.cjs.map +1 -0
  297. package/build/modern/useSuspenseQuery.d.cts +1 -0
  298. package/build/modern/useSuspenseQuery.d.ts +1 -0
  299. package/build/modern/useSuspenseQuery.js +28 -0
  300. package/build/modern/useSuspenseQuery.js.map +1 -0
  301. package/build/query-codemods/eslint.config.js +18 -0
  302. package/build/query-codemods/package.json +38 -0
  303. package/build/query-codemods/root.eslint.config.js +64 -0
  304. package/build/query-codemods/tsconfig.json +8 -0
  305. package/build/query-codemods/vite.config.ts +30 -0
  306. package/changes.json +5 -0
  307. package/package.json +104 -0
  308. package/src/HydrationBoundary.tsx +111 -0
  309. package/src/IsRestoringProvider.ts +7 -0
  310. package/src/QueryClientProvider.tsx +45 -0
  311. package/src/QueryErrorResetBoundary.tsx +56 -0
  312. package/src/errorBoundaryUtils.ts +82 -0
  313. package/src/index.ts +56 -0
  314. package/src/infiniteQueryOptions.ts +149 -0
  315. package/src/mutationOptions.ts +41 -0
  316. package/src/queryOptions.ts +87 -0
  317. package/src/suspense.ts +80 -0
  318. package/src/types.ts +242 -0
  319. package/src/useBaseQuery.ts +170 -0
  320. package/src/useInfiniteQuery.ts +81 -0
  321. package/src/useIsFetching.ts +24 -0
  322. package/src/useMutation.ts +69 -0
  323. package/src/useMutationState.ts +75 -0
  324. package/src/usePrefetchInfiniteQuery.tsx +30 -0
  325. package/src/usePrefetchQuery.tsx +19 -0
  326. package/src/useQueries.ts +328 -0
  327. package/src/useQuery.ts +52 -0
  328. package/src/useSuspenseInfiniteQuery.ts +50 -0
  329. package/src/useSuspenseQueries.ts +211 -0
  330. package/src/useSuspenseQuery.ts +34 -0
@@ -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 "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
+ }
@@ -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
@@ -0,0 +1,185 @@
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
+
5
+ /**
6
+ * @param {import('jscodeshift').api} jscodeshift
7
+ * @param {Object} utils
8
+ * @param {import('jscodeshift').Collection} root
9
+ * @param {string} filePath
10
+ * @param {{keyName: "mutationKey"|"queryKey", queryClientMethods: ReadonlyArray<string>, hooks: ReadonlyArray<string>}} config
11
+ */
12
+ const transformQueryFnAwareUsages = ({
13
+ jscodeshift,
14
+ utils,
15
+ root,
16
+ filePath,
17
+ config,
18
+ }) => {
19
+ const v5Utils = createV5UtilsObject({ jscodeshift, utils })
20
+
21
+ /**
22
+ * @param {import('jscodeshift').CallExpression} node
23
+ * @returns {boolean}
24
+ */
25
+ const canSkipReplacement = (node) => {
26
+ const callArguments = node.arguments
27
+
28
+ const hasKeyProperty = () =>
29
+ callArguments[0].properties.some(
30
+ (property) =>
31
+ utils.isObjectProperty(property) &&
32
+ [config.keyName, 'queryFn'].includes(property.key.name),
33
+ )
34
+
35
+ return (
36
+ callArguments.length > 0 &&
37
+ utils.isObjectExpression(callArguments[0]) &&
38
+ hasKeyProperty()
39
+ )
40
+ }
41
+
42
+ const predicate = (property) => {
43
+ const isSpreadElement = utils.isSpreadElement(property)
44
+ const isObjectProperty = utils.isObjectProperty(property)
45
+
46
+ return (
47
+ isSpreadElement ||
48
+ (isObjectProperty && property.key.name !== config.keyName)
49
+ )
50
+ }
51
+
52
+ const transformArgumentToQueryFunction = (path, node) => {
53
+ const isIdentifier = utils.isIdentifier(node)
54
+ const isFunctionDefinition = utils.isFunctionDefinition(node)
55
+
56
+ if (!isIdentifier && !isFunctionDefinition) {
57
+ return undefined
58
+ }
59
+
60
+ if (isFunctionDefinition) {
61
+ return jscodeshift.property(
62
+ 'init',
63
+ jscodeshift.identifier('queryFn'),
64
+ node,
65
+ )
66
+ }
67
+
68
+ const binding = v5Utils.getBindingFromScope(path, node.name, filePath)
69
+ const initializer = v5Utils.getInitializerByDeclarator(binding)
70
+
71
+ if (!utils.isFunctionDefinition(initializer)) {
72
+ return undefined
73
+ }
74
+
75
+ return jscodeshift.property(
76
+ 'init',
77
+ jscodeshift.identifier('queryFn'),
78
+ binding.id,
79
+ )
80
+ }
81
+
82
+ const transformArgumentToOptionsObject = (path, node) => {
83
+ if (!utils.isIdentifier(node)) {
84
+ return undefined
85
+ }
86
+
87
+ const binding = v5Utils.getBindingFromScope(path, node.name, filePath)
88
+ const initializer = v5Utils.getInitializerByDeclarator(binding)
89
+
90
+ if (utils.isObjectExpression(initializer)) {
91
+ return jscodeshift.spreadElement(binding.id)
92
+ }
93
+ }
94
+
95
+ const replacer = (path) => {
96
+ const node = path.node
97
+
98
+ try {
99
+ // If the given method/function call matches certain criteria, the node doesn't need to be replaced, this step can be skipped.
100
+ if (canSkipReplacement(node)) {
101
+ return node
102
+ }
103
+
104
+ const keyProperty = v5Utils.transformArgumentToKey(
105
+ path,
106
+ node.arguments[0],
107
+ config.keyName,
108
+ filePath,
109
+ )
110
+
111
+ if (!keyProperty) {
112
+ throw new UnknownUsageError(node, filePath)
113
+ }
114
+
115
+ const parameters = [jscodeshift.objectExpression([keyProperty])]
116
+ const createdObjectExpression = parameters[0]
117
+ const secondParameter = node.arguments[1]
118
+
119
+ if (secondParameter) {
120
+ const queryFnProperty = transformArgumentToQueryFunction(
121
+ path,
122
+ secondParameter,
123
+ )
124
+
125
+ if (queryFnProperty) {
126
+ createdObjectExpression.properties.push(queryFnProperty)
127
+
128
+ const thirdParameter = node.arguments[2]
129
+
130
+ if (utils.isObjectExpression(thirdParameter)) {
131
+ v5Utils.copyPropertiesFromSource(
132
+ thirdParameter,
133
+ createdObjectExpression,
134
+ predicate,
135
+ )
136
+ } else {
137
+ createdObjectExpression.properties.push(
138
+ jscodeshift.spreadElement(thirdParameter),
139
+ )
140
+ }
141
+
142
+ return jscodeshift.callExpression(node.original.callee, parameters)
143
+ }
144
+
145
+ const optionsProperty = transformArgumentToOptionsObject(
146
+ path,
147
+ secondParameter,
148
+ )
149
+
150
+ if (optionsProperty) {
151
+ createdObjectExpression.properties.push(optionsProperty)
152
+
153
+ return jscodeshift.callExpression(node.original.callee, parameters)
154
+ }
155
+
156
+ if (utils.isObjectExpression(secondParameter)) {
157
+ v5Utils.copyPropertiesFromSource(
158
+ secondParameter,
159
+ createdObjectExpression,
160
+ predicate,
161
+ )
162
+ }
163
+
164
+ return jscodeshift.callExpression(node.original.callee, parameters)
165
+ }
166
+
167
+ return jscodeshift.callExpression(node.original.callee, parameters)
168
+ } catch (error) {
169
+ utils.warn(
170
+ error.name === UnknownUsageError.name
171
+ ? error.message
172
+ : `An unknown error occurred while processing the "${filePath}" file. Please review this file, because the codemod couldn't be applied.`,
173
+ )
174
+
175
+ return node
176
+ }
177
+ }
178
+
179
+ createQueryClientTransformer({ jscodeshift, utils, root }).execute(
180
+ config.queryClientMethods,
181
+ replacer,
182
+ )
183
+ }
184
+
185
+ module.exports = transformQueryFnAwareUsages
@@ -0,0 +1,123 @@
1
+ const UnknownUsageError = require('./unknown-usage-error.cjs')
2
+
3
+ module.exports = ({ jscodeshift, utils }) => {
4
+ /**
5
+ *
6
+ * @param {import('jscodeshift').ObjectExpression} source
7
+ * @param {import('jscodeshift').ObjectExpression} target
8
+ * @param {(node: import('jscodeshift').Node) => boolean} predicate
9
+ */
10
+ const copyPropertiesFromSource = (source, target, predicate) => {
11
+ source.properties.forEach((property) => {
12
+ if (predicate(property)) {
13
+ target.properties.push(property)
14
+ }
15
+ })
16
+ }
17
+
18
+ /**
19
+ * @param {import('jscodeshift').NodePath} path
20
+ * @param {string} argumentName
21
+ * @param {string} filePath
22
+ * @returns {*}
23
+ */
24
+ const getBindingFromScope = (path, argumentName, filePath) => {
25
+ /**
26
+ * If the current scope contains the declaration then we can use the actual one else we attempt to find the
27
+ * binding from above.
28
+ */
29
+ const scope = path.scope.declares(argumentName)
30
+ ? path.scope
31
+ : path.scope.lookup(argumentName)
32
+
33
+ /**
34
+ * The declaration couldn't be found for some reason, time to move on. We warn the user it needs to be rewritten
35
+ * by themselves.
36
+ */
37
+ if (!scope) {
38
+ return undefined
39
+ }
40
+
41
+ const binding = scope.bindings[argumentName]
42
+ .filter((item) => utils.isIdentifier(item.value))
43
+ .map((item) => item.parentPath.value)
44
+ .at(0)
45
+
46
+ if (!binding) {
47
+ throw new UnknownUsageError(path.node, filePath)
48
+ }
49
+
50
+ return binding
51
+ }
52
+
53
+ /**
54
+ * @param {import('jscodeshift').VariableDeclarator} binding
55
+ * @returns {import('jscodeshift').Node|undefined}
56
+ */
57
+ const getInitializerByDeclarator = (binding) => {
58
+ const isVariableDeclaration = jscodeshift.match(binding, {
59
+ type: jscodeshift.VariableDeclarator.name,
60
+ })
61
+
62
+ if (!isVariableDeclaration) {
63
+ return undefined
64
+ }
65
+
66
+ const isTSAsExpression = jscodeshift.match(binding.init, {
67
+ type: jscodeshift.TSAsExpression.name,
68
+ })
69
+
70
+ return isTSAsExpression ? binding.init.expression : binding.init
71
+ }
72
+
73
+ /**
74
+ * @param {import('jscodeshift').Node} node
75
+ * @returns {boolean}
76
+ */
77
+ const isArrayExpressionVariable = (node) =>
78
+ jscodeshift.match(node, {
79
+ type: jscodeshift.VariableDeclarator.name,
80
+ init: {
81
+ type: jscodeshift.ArrayExpression.name,
82
+ },
83
+ })
84
+
85
+ /**
86
+ * @param {import('jscodeshift').NodePath} path
87
+ * @param {import('jscodeshift').Node} node
88
+ * @param {"queryKey"|"mutationKey"} keyName
89
+ * @param {string} filePath
90
+ * @returns {import('jscodeshift').Property|undefined}
91
+ */
92
+ const transformArgumentToKey = (path, node, keyName, filePath) => {
93
+ // If the first argument is an identifier we have to infer its type if possible.
94
+ if (utils.isIdentifier(node)) {
95
+ const binding = getBindingFromScope(path, node.name, filePath)
96
+
97
+ if (isArrayExpressionVariable(binding)) {
98
+ return jscodeshift.property(
99
+ 'init',
100
+ jscodeshift.identifier(keyName),
101
+ jscodeshift.identifier(binding.id.name),
102
+ )
103
+ }
104
+ }
105
+
106
+ // If the first argument is an array, then it matches the following overload:
107
+ // methodName(queryKey?: QueryKey, firstObject?: TFirstObject, secondObject?: TSecondObject)
108
+ if (utils.isArrayExpression(node)) {
109
+ // Then we create the 'queryKey' property based on it, because it will be passed to the first argument
110
+ // that should be an object according to the new signature.
111
+ return jscodeshift.property('init', jscodeshift.identifier(keyName), node)
112
+ }
113
+
114
+ return undefined
115
+ }
116
+
117
+ return {
118
+ copyPropertiesFromSource,
119
+ getInitializerByDeclarator,
120
+ getBindingFromScope,
121
+ transformArgumentToKey,
122
+ }
123
+ }
@@ -0,0 +1,27 @@
1
+ class UnknownUsageError extends Error {
2
+ /**
3
+ * @param {import('jscodeshift').CallExpression} callExpression
4
+ * @param {string} filePath
5
+ */
6
+ constructor(callExpression, filePath) {
7
+ super('')
8
+ this.message = this.buildMessage(callExpression, filePath)
9
+ this.name = 'UnknownUsageError'
10
+ }
11
+
12
+ /**
13
+ *
14
+ * @param {import('jscodeshift').CallExpression} callExpression
15
+ * @param {string} filePath
16
+ * @returns {string}
17
+ */
18
+ buildMessage(callExpression, filePath) {
19
+ const location = callExpression.callee.loc
20
+ const start = location.start.line
21
+ const end = location.end.line
22
+
23
+ return `The usage in file "${filePath}" at line ${start}:${end} could not be transformed into the new syntax. Please do this manually.`
24
+ }
25
+ }
26
+
27
+ module.exports = UnknownUsageError