@tanstack/react-query 5.0.0-alpha.6 → 5.0.0-alpha.61

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 (232) hide show
  1. package/build/codemods/__testfixtures__/default-import.input.tsx +94 -0
  2. package/build/codemods/__testfixtures__/default-import.output.tsx +96 -0
  3. package/build/codemods/__testfixtures__/named-import.input.tsx +96 -0
  4. package/build/codemods/__testfixtures__/named-import.output.tsx +98 -0
  5. package/build/codemods/__testfixtures__/namespaced-import.input.tsx +86 -0
  6. package/build/codemods/__testfixtures__/namespaced-import.output.tsx +88 -0
  7. package/build/codemods/__testfixtures__/parameter-is-identifier.input.tsx +49 -0
  8. package/build/codemods/__testfixtures__/parameter-is-identifier.output.tsx +49 -0
  9. package/build/codemods/__testfixtures__/parameter-is-object-expression.input.tsx +128 -0
  10. package/build/codemods/__testfixtures__/parameter-is-object-expression.output.tsx +175 -0
  11. package/build/codemods/__testfixtures__/replace-import-specifier.input.tsx +10 -0
  12. package/build/codemods/__testfixtures__/replace-import-specifier.output.tsx +10 -0
  13. package/build/codemods/__testfixtures__/type-arguments.input.tsx +25 -0
  14. package/build/codemods/__testfixtures__/type-arguments.output.tsx +31 -0
  15. package/build/codemods/__tests__/key-transformation.test.js +32 -0
  16. package/build/codemods/__tests__/replace-import-specifier.test.js +12 -0
  17. package/build/codemods/remove-overloads/__testfixtures__/default-import.input.tsx +199 -0
  18. package/build/codemods/remove-overloads/__testfixtures__/default-import.output.tsx +484 -0
  19. package/build/codemods/remove-overloads/__tests__/remove-overloads.test.js +6 -0
  20. package/build/codemods/remove-overloads/remove-overloads.js +59 -0
  21. package/build/codemods/remove-overloads/transformers/filter-aware-usage-transformer.js +153 -0
  22. package/build/codemods/remove-overloads/transformers/query-fn-aware-usage-transformer.js +188 -0
  23. package/build/codemods/remove-overloads/utils/index.js +124 -0
  24. package/build/codemods/remove-overloads/utils/unknown-usage-error.js +27 -0
  25. package/build/codemods/src/utils/index.js +205 -0
  26. package/build/codemods/src/v4/key-transformation.js +138 -0
  27. package/build/codemods/src/v4/replace-import-specifier.js +25 -0
  28. package/build/codemods/transformers/query-cache-transformer.js +116 -0
  29. package/build/codemods/transformers/query-client-transformer.js +48 -0
  30. package/build/codemods/transformers/use-query-like-transformer.js +32 -0
  31. package/build/codemods/utils/replacers/key-replacer.js +164 -0
  32. package/build/lib/HydrationBoundary.cjs +50 -0
  33. package/build/lib/{HydrationBoundary.mjs.map → HydrationBoundary.cjs.map} +1 -1
  34. package/build/lib/HydrationBoundary.d.ts +1 -0
  35. package/build/lib/HydrationBoundary.d.ts.map +1 -0
  36. package/build/lib/HydrationBoundary.js +9 -29
  37. package/build/lib/HydrationBoundary.js.map +1 -1
  38. package/build/lib/QueryClientProvider.cjs +54 -0
  39. package/build/lib/QueryClientProvider.cjs.map +1 -0
  40. package/build/lib/QueryClientProvider.d.ts +2 -1
  41. package/build/lib/QueryClientProvider.d.ts.map +1 -0
  42. package/build/lib/QueryClientProvider.js +7 -29
  43. package/build/lib/QueryClientProvider.js.map +1 -1
  44. package/build/lib/QueryErrorResetBoundary.cjs +60 -0
  45. package/build/lib/{QueryErrorResetBoundary.mjs.map → QueryErrorResetBoundary.cjs.map} +1 -1
  46. package/build/lib/QueryErrorResetBoundary.d.ts +2 -1
  47. package/build/lib/QueryErrorResetBoundary.d.ts.map +1 -0
  48. package/build/lib/QueryErrorResetBoundary.js +7 -28
  49. package/build/lib/QueryErrorResetBoundary.js.map +1 -1
  50. package/build/lib/__tests__/HydrationBoundary.test.d.ts +1 -0
  51. package/build/lib/__tests__/HydrationBoundary.test.d.ts.map +1 -0
  52. package/build/lib/__tests__/QueryClientProvider.test.d.ts +1 -0
  53. package/build/lib/__tests__/QueryClientProvider.test.d.ts.map +1 -0
  54. package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts +1 -0
  55. package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts.map +1 -0
  56. package/build/lib/__tests__/ssr-hydration.test.d.ts +1 -0
  57. package/build/lib/__tests__/ssr-hydration.test.d.ts.map +1 -0
  58. package/build/lib/__tests__/ssr.test.d.ts +1 -0
  59. package/build/lib/__tests__/ssr.test.d.ts.map +1 -0
  60. package/build/lib/__tests__/suspense.test.d.ts +1 -0
  61. package/build/lib/__tests__/suspense.test.d.ts.map +1 -0
  62. package/build/lib/__tests__/useInfiniteQuery.test.d.ts +1 -0
  63. package/build/lib/__tests__/useInfiniteQuery.test.d.ts.map +1 -0
  64. package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts +1 -0
  65. package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts.map +1 -0
  66. package/build/lib/__tests__/useIsFetching.test.d.ts +1 -0
  67. package/build/lib/__tests__/useIsFetching.test.d.ts.map +1 -0
  68. package/build/lib/__tests__/useMutation.test.d.ts +1 -0
  69. package/build/lib/__tests__/useMutation.test.d.ts.map +1 -0
  70. package/build/lib/__tests__/useMutationState.test.d.ts +1 -0
  71. package/build/lib/__tests__/useMutationState.test.d.ts.map +1 -0
  72. package/build/lib/__tests__/useQueries.test.d.ts +1 -0
  73. package/build/lib/__tests__/useQueries.test.d.ts.map +1 -0
  74. package/build/lib/__tests__/useQuery.test.d.ts +1 -0
  75. package/build/lib/__tests__/useQuery.test.d.ts.map +1 -0
  76. package/build/lib/__tests__/useQuery.types.test.d.ts +1 -0
  77. package/build/lib/__tests__/useQuery.types.test.d.ts.map +1 -0
  78. package/build/lib/__tests__/utils.d.ts +6 -5
  79. package/build/lib/__tests__/utils.d.ts.map +1 -0
  80. package/build/lib/errorBoundaryUtils.cjs +51 -0
  81. package/build/lib/errorBoundaryUtils.cjs.map +1 -0
  82. package/build/lib/errorBoundaryUtils.d.ts +4 -3
  83. package/build/lib/errorBoundaryUtils.d.ts.map +1 -0
  84. package/build/lib/errorBoundaryUtils.js +8 -30
  85. package/build/lib/errorBoundaryUtils.js.map +1 -1
  86. package/build/lib/index.cjs +39 -0
  87. package/build/lib/index.cjs.map +1 -0
  88. package/build/lib/index.d.ts +2 -1
  89. package/build/lib/index.d.ts.map +1 -0
  90. package/build/lib/index.js +11 -37
  91. package/build/lib/index.js.map +1 -1
  92. package/build/lib/isRestoring.cjs +31 -0
  93. package/build/lib/isRestoring.cjs.map +1 -0
  94. package/build/lib/isRestoring.d.ts +1 -0
  95. package/build/lib/isRestoring.d.ts.map +1 -0
  96. package/build/lib/isRestoring.js +5 -26
  97. package/build/lib/isRestoring.js.map +1 -1
  98. package/build/lib/{suspense.mjs → suspense.cjs} +8 -10
  99. package/build/lib/suspense.cjs.map +1 -0
  100. package/build/lib/suspense.d.ts +3 -5
  101. package/build/lib/suspense.d.ts.map +1 -0
  102. package/build/lib/suspense.js +3 -15
  103. package/build/lib/suspense.js.map +1 -1
  104. package/build/lib/types.d.ts +11 -10
  105. package/build/lib/types.d.ts.map +1 -0
  106. package/build/lib/useBaseQuery.cjs +80 -0
  107. package/build/lib/useBaseQuery.cjs.map +1 -0
  108. package/build/lib/useBaseQuery.d.ts +1 -0
  109. package/build/lib/useBaseQuery.d.ts.map +1 -0
  110. package/build/lib/useBaseQuery.js +30 -54
  111. package/build/lib/useBaseQuery.js.map +1 -1
  112. package/build/lib/useInfiniteQuery.cjs +15 -0
  113. package/build/lib/useInfiniteQuery.cjs.map +1 -0
  114. package/build/lib/useInfiniteQuery.d.ts +1 -0
  115. package/build/lib/useInfiniteQuery.d.ts.map +1 -0
  116. package/build/lib/useInfiniteQuery.js +6 -7
  117. package/build/lib/useInfiniteQuery.js.map +1 -1
  118. package/build/lib/useIsFetching.cjs +34 -0
  119. package/build/lib/useIsFetching.cjs.map +1 -0
  120. package/build/lib/useIsFetching.d.ts +1 -0
  121. package/build/lib/useIsFetching.d.ts.map +1 -0
  122. package/build/lib/useIsFetching.js +7 -27
  123. package/build/lib/useIsFetching.js.map +1 -1
  124. package/build/lib/useMutation.cjs +54 -0
  125. package/build/lib/useMutation.cjs.map +1 -0
  126. package/build/lib/useMutation.d.ts +1 -0
  127. package/build/lib/useMutation.d.ts.map +1 -0
  128. package/build/lib/useMutation.js +12 -32
  129. package/build/lib/useMutation.js.map +1 -1
  130. package/build/lib/useMutationState.cjs +60 -0
  131. package/build/lib/useMutationState.cjs.map +1 -0
  132. package/build/lib/useMutationState.d.ts +4 -3
  133. package/build/lib/useMutationState.d.ts.map +1 -0
  134. package/build/lib/useMutationState.js +13 -34
  135. package/build/lib/useMutationState.js.map +1 -1
  136. package/build/lib/useQueries.cjs +99 -0
  137. package/build/lib/useQueries.cjs.map +1 -0
  138. package/build/lib/useQueries.d.ts +10 -8
  139. package/build/lib/useQueries.d.ts.map +1 -0
  140. package/build/lib/useQueries.js +52 -67
  141. package/build/lib/useQueries.js.map +1 -1
  142. package/build/lib/useQuery.cjs +19 -0
  143. package/build/lib/useQuery.cjs.map +1 -0
  144. package/build/lib/useQuery.d.ts +5 -2
  145. package/build/lib/useQuery.d.ts.map +1 -0
  146. package/build/lib/useQuery.js +8 -5
  147. package/build/lib/useQuery.js.map +1 -1
  148. package/build/lib/{utils.esm.js → utils.cjs} +4 -2
  149. package/build/lib/{utils.mjs.map → utils.cjs.map} +1 -1
  150. package/build/lib/utils.d.ts +1 -0
  151. package/build/lib/utils.d.ts.map +1 -0
  152. package/build/lib/utils.js +1 -3
  153. package/build/lib/utils.js.map +1 -1
  154. package/package.json +24 -15
  155. package/src/__tests__/QueryResetErrorBoundary.test.tsx +752 -620
  156. package/src/__tests__/ssr-hydration.test.tsx +2 -2
  157. package/src/__tests__/suspense.test.tsx +6 -88
  158. package/src/__tests__/useInfiniteQuery.type.test.tsx +0 -27
  159. package/src/__tests__/useMutation.test.tsx +4 -4
  160. package/src/__tests__/useMutationState.test.tsx +23 -0
  161. package/src/__tests__/useQueries.test.tsx +206 -83
  162. package/src/__tests__/useQuery.test.tsx +246 -338
  163. package/src/__tests__/useQuery.types.test.tsx +21 -1
  164. package/src/errorBoundaryUtils.ts +6 -5
  165. package/src/index.ts +1 -1
  166. package/src/suspense.ts +9 -15
  167. package/src/useBaseQuery.ts +12 -23
  168. package/src/useInfiniteQuery.ts +1 -0
  169. package/src/useIsFetching.ts +1 -0
  170. package/src/useMutation.ts +2 -1
  171. package/src/useMutationState.ts +4 -3
  172. package/src/useQueries.ts +44 -26
  173. package/src/useQuery.ts +23 -0
  174. package/build/lib/HydrationBoundary.esm.js +0 -28
  175. package/build/lib/HydrationBoundary.esm.js.map +0 -1
  176. package/build/lib/HydrationBoundary.mjs +0 -28
  177. package/build/lib/QueryClientProvider.esm.js +0 -30
  178. package/build/lib/QueryClientProvider.esm.js.map +0 -1
  179. package/build/lib/QueryClientProvider.mjs +0 -30
  180. package/build/lib/QueryClientProvider.mjs.map +0 -1
  181. package/build/lib/QueryErrorResetBoundary.esm.js +0 -37
  182. package/build/lib/QueryErrorResetBoundary.esm.js.map +0 -1
  183. package/build/lib/QueryErrorResetBoundary.mjs +0 -37
  184. package/build/lib/errorBoundaryUtils.esm.js +0 -27
  185. package/build/lib/errorBoundaryUtils.esm.js.map +0 -1
  186. package/build/lib/errorBoundaryUtils.mjs +0 -27
  187. package/build/lib/errorBoundaryUtils.mjs.map +0 -1
  188. package/build/lib/index.esm.js +0 -12
  189. package/build/lib/index.esm.js.map +0 -1
  190. package/build/lib/index.mjs +0 -12
  191. package/build/lib/index.mjs.map +0 -1
  192. package/build/lib/isRestoring.esm.js +0 -8
  193. package/build/lib/isRestoring.esm.js.map +0 -1
  194. package/build/lib/isRestoring.mjs +0 -8
  195. package/build/lib/isRestoring.mjs.map +0 -1
  196. package/build/lib/suspense.esm.js +0 -24
  197. package/build/lib/suspense.esm.js.map +0 -1
  198. package/build/lib/suspense.mjs.map +0 -1
  199. package/build/lib/useBaseQuery.esm.js +0 -62
  200. package/build/lib/useBaseQuery.esm.js.map +0 -1
  201. package/build/lib/useBaseQuery.mjs +0 -62
  202. package/build/lib/useBaseQuery.mjs.map +0 -1
  203. package/build/lib/useInfiniteQuery.esm.js +0 -12
  204. package/build/lib/useInfiniteQuery.esm.js.map +0 -1
  205. package/build/lib/useInfiniteQuery.mjs +0 -12
  206. package/build/lib/useInfiniteQuery.mjs.map +0 -1
  207. package/build/lib/useIsFetching.esm.js +0 -12
  208. package/build/lib/useIsFetching.esm.js.map +0 -1
  209. package/build/lib/useIsFetching.mjs +0 -12
  210. package/build/lib/useIsFetching.mjs.map +0 -1
  211. package/build/lib/useMutation.esm.js +0 -32
  212. package/build/lib/useMutation.esm.js.map +0 -1
  213. package/build/lib/useMutation.mjs +0 -32
  214. package/build/lib/useMutation.mjs.map +0 -1
  215. package/build/lib/useMutationState.esm.js +0 -37
  216. package/build/lib/useMutationState.esm.js.map +0 -1
  217. package/build/lib/useMutationState.mjs +0 -37
  218. package/build/lib/useMutationState.mjs.map +0 -1
  219. package/build/lib/useQueries.esm.js +0 -72
  220. package/build/lib/useQueries.esm.js.map +0 -1
  221. package/build/lib/useQueries.mjs +0 -69
  222. package/build/lib/useQueries.mjs.map +0 -1
  223. package/build/lib/useQuery.esm.js +0 -11
  224. package/build/lib/useQuery.esm.js.map +0 -1
  225. package/build/lib/useQuery.mjs +0 -11
  226. package/build/lib/useQuery.mjs.map +0 -1
  227. package/build/lib/utils.esm.js.map +0 -1
  228. package/build/lib/utils.mjs +0 -10
  229. package/build/umd/index.development.js +0 -3040
  230. package/build/umd/index.development.js.map +0 -1
  231. package/build/umd/index.production.js +0 -2
  232. package/build/umd/index.production.js.map +0 -1
@@ -0,0 +1,116 @@
1
+ module.exports = ({ jscodeshift, utils, root }) => {
2
+ const isGetQueryCacheMethodCall = (
3
+ initializer,
4
+ importIdentifiers,
5
+ knownQueryClientIds,
6
+ ) => {
7
+ const isKnownQueryClient = (node) =>
8
+ utils.isIdentifier(node) && knownQueryClientIds.includes(node.name)
9
+
10
+ const isGetQueryCacheIdentifier = (node) =>
11
+ utils.isIdentifier(node) && node.name === 'getQueryCache'
12
+
13
+ const isValidInitializer = (node) =>
14
+ utils.isCallExpression(node) && utils.isMemberExpression(node.callee)
15
+
16
+ if (isValidInitializer(initializer)) {
17
+ const instance = initializer.callee.object
18
+
19
+ return (
20
+ isGetQueryCacheIdentifier(initializer.callee.property) &&
21
+ (isKnownQueryClient(instance) ||
22
+ utils.isFunctionCallOf(
23
+ instance,
24
+ utils.getSelectorByImports(importIdentifiers, 'useQueryClient'),
25
+ ))
26
+ )
27
+ }
28
+
29
+ return false
30
+ }
31
+
32
+ const findQueryCacheInstantiations = (
33
+ importIdentifiers,
34
+ knownQueryClientIds,
35
+ ) =>
36
+ root.find(jscodeshift.VariableDeclarator, {}).filter((node) => {
37
+ if (node.value.init) {
38
+ const initializer = node.value.init
39
+
40
+ return (
41
+ utils.isClassInstantiationOf(
42
+ initializer,
43
+ utils.getSelectorByImports(importIdentifiers, 'QueryCache'),
44
+ ) ||
45
+ isGetQueryCacheMethodCall(
46
+ initializer,
47
+ importIdentifiers,
48
+ knownQueryClientIds,
49
+ )
50
+ )
51
+ }
52
+
53
+ return false
54
+ })
55
+
56
+ const filterQueryCacheMethodCalls = (node) =>
57
+ utils.isIdentifier(node) && ['find', 'findAll'].includes(node.name)
58
+
59
+ const findQueryCacheMethodCalls = (importIdentifiers) => {
60
+ /**
61
+ * Here we collect all query client instantiations. We have to make aware of them because the query cache can be
62
+ * accessed by the query client as well.
63
+ */
64
+ const queryClientIdentifiers =
65
+ utils.queryClient.findQueryClientIdentifiers(importIdentifiers)
66
+ /**
67
+ * Here we collect all query cache instantiations. The reason is simple: the methods can be called on query cache
68
+ * instances, to locate the possible usages we need to be aware of the identifier names.
69
+ */
70
+ const queryCacheIdentifiers = findQueryCacheInstantiations(
71
+ importIdentifiers,
72
+ queryClientIdentifiers,
73
+ )
74
+ .paths()
75
+ .map((node) => node.value.id.name)
76
+
77
+ return (
78
+ utils
79
+ // First, we need to find all method calls.
80
+ .findAllMethodCalls()
81
+ // Then we narrow the collection to all `fetch` and `fetchAll` methods.
82
+ .filter((node) =>
83
+ filterQueryCacheMethodCalls(node.value.callee.property),
84
+ )
85
+ .filter((node) => {
86
+ const object = node.value.callee.object
87
+
88
+ // If the method is called on a `QueryCache` instance, we keep it in the collection.
89
+ if (utils.isIdentifier(object)) {
90
+ return queryCacheIdentifiers.includes(object.name)
91
+ }
92
+
93
+ // If the method is called on a `QueryClient` instance, we keep it in the collection.
94
+ if (utils.isCallExpression(object)) {
95
+ return isGetQueryCacheMethodCall(
96
+ object,
97
+ importIdentifiers,
98
+ queryClientIdentifiers,
99
+ )
100
+ }
101
+
102
+ return false
103
+ })
104
+ )
105
+ }
106
+
107
+ const execute = (replacer) => {
108
+ findQueryCacheMethodCalls(
109
+ utils.locateImports(['QueryCache', 'QueryClient', 'useQueryClient']),
110
+ ).replaceWith(replacer)
111
+ }
112
+
113
+ return {
114
+ execute,
115
+ }
116
+ }
@@ -0,0 +1,48 @@
1
+ module.exports = ({ jscodeshift, utils, root }) => {
2
+ const filterQueryClientMethodCalls = (node, methods) =>
3
+ utils.isIdentifier(node) && methods.includes(node.name)
4
+
5
+ const findQueryClientMethodCalls = (importIdentifiers, methods) => {
6
+ /**
7
+ * Here we collect all query client instantiations. We have to make aware of them because some method calls might
8
+ * be invoked on these instances.
9
+ */
10
+ const queryClientIdentifiers =
11
+ utils.queryClient.findQueryClientIdentifiers(importIdentifiers)
12
+
13
+ return (
14
+ utils
15
+ // First, we need to find all method calls.
16
+ .findAllMethodCalls()
17
+ // Then we narrow the collection to `QueryClient` methods.
18
+ .filter((node) =>
19
+ filterQueryClientMethodCalls(node.value.callee.property, methods),
20
+ )
21
+ .filter((node) => {
22
+ const object = node.value.callee.object
23
+
24
+ // If the method is called on a `QueryClient` instance, we keep it in the collection.
25
+ if (utils.isIdentifier(object)) {
26
+ return queryClientIdentifiers.includes(object.name)
27
+ }
28
+
29
+ // If the method is called on the return value of `useQueryClient` hook, we keep it in the collection.
30
+ return utils.isFunctionCallOf(
31
+ object,
32
+ utils.getSelectorByImports(importIdentifiers, 'useQueryClient'),
33
+ )
34
+ })
35
+ )
36
+ }
37
+
38
+ const execute = (methods, replacer) => {
39
+ findQueryClientMethodCalls(
40
+ utils.locateImports(['QueryClient', 'useQueryClient']),
41
+ methods,
42
+ ).replaceWith(replacer)
43
+ }
44
+
45
+ return {
46
+ execute,
47
+ }
48
+ }
@@ -0,0 +1,32 @@
1
+ module.exports = ({ jscodeshift, utils, root }) => {
2
+ const filterUseQueryLikeHookCalls = (node, importIdentifiers, hooks) => {
3
+ for (const hook of hooks) {
4
+ const selector = utils.getSelectorByImports(importIdentifiers, hook)
5
+
6
+ if (utils.isFunctionCallOf(node, selector)) {
7
+ return true
8
+ }
9
+ }
10
+
11
+ return false
12
+ }
13
+
14
+ const findUseQueryLikeHookCalls = (importIdentifiers, hooks) =>
15
+ root
16
+ // First, we need to find all call expressions.
17
+ .find(jscodeshift.CallExpression, {})
18
+ // Then we narrow the collection to the `useQuery` like hook calls.
19
+ .filter((node) =>
20
+ filterUseQueryLikeHookCalls(node.value, importIdentifiers, hooks),
21
+ )
22
+
23
+ const execute = (hooks, replacer) => {
24
+ findUseQueryLikeHookCalls(utils.locateImports(hooks), hooks).replaceWith(
25
+ replacer,
26
+ )
27
+ }
28
+
29
+ return {
30
+ execute,
31
+ }
32
+ }
@@ -0,0 +1,164 @@
1
+ class UnprocessableKeyError extends Error {
2
+ constructor(message) {
3
+ super(message)
4
+ this.name = 'UnprocessableKeyError'
5
+ }
6
+ }
7
+
8
+ module.exports = ({ jscodeshift, root, filePath, keyName = 'queryKey' }) => {
9
+ const isArrayExpression = (node) =>
10
+ jscodeshift.match(node, { type: jscodeshift.ArrayExpression.name })
11
+
12
+ const isStringLiteral = (node) =>
13
+ jscodeshift.match(node, { type: jscodeshift.StringLiteral.name }) ||
14
+ jscodeshift.match(node, { type: jscodeshift.Literal.name })
15
+
16
+ const isTemplateLiteral = (node) =>
17
+ jscodeshift.match(node, { type: jscodeshift.TemplateLiteral.name })
18
+
19
+ const findVariableDeclaration = (node) => {
20
+ const declarations = root
21
+ .find(jscodeshift.VariableDeclarator, {
22
+ id: {
23
+ type: jscodeshift.Identifier.name,
24
+ name: node.name,
25
+ },
26
+ })
27
+ .paths()
28
+
29
+ return declarations.length > 0 ? declarations[0] : null
30
+ }
31
+
32
+ const createKeyValue = (node) => {
33
+ // When the node is a string literal we convert it into an array of strings.
34
+ if (isStringLiteral(node)) {
35
+ return jscodeshift.arrayExpression([
36
+ jscodeshift.stringLiteral(node.value),
37
+ ])
38
+ }
39
+
40
+ // When the node is a template literal we convert it into an array of template literals.
41
+ if (isTemplateLiteral(node)) {
42
+ return jscodeshift.arrayExpression([
43
+ jscodeshift.templateLiteral(node.quasis, node.expressions),
44
+ ])
45
+ }
46
+
47
+ if (jscodeshift.match(node, { type: jscodeshift.Identifier.name })) {
48
+ // When the node is an identifier at first, we try to find its declaration, because we will try
49
+ // to guess its type.
50
+ const variableDeclaration = findVariableDeclaration(node)
51
+
52
+ if (!variableDeclaration) {
53
+ throw new UnprocessableKeyError(
54
+ `In file ${filePath} at line ${node.loc.start.line} the type of identifier \`${node.name}\` couldn't be recognized, so the codemod couldn't be applied. Please migrate manually.`,
55
+ )
56
+ }
57
+
58
+ const initializer = variableDeclaration.value.init
59
+
60
+ // When it's a string, we just wrap it into an array expression.
61
+ if (isStringLiteral(initializer) || isTemplateLiteral(initializer)) {
62
+ return jscodeshift.arrayExpression([node])
63
+ }
64
+ }
65
+
66
+ throw new UnprocessableKeyError(
67
+ `In file ${filePath} at line ${node.loc.start.line} the type of the \`${keyName}\` couldn't be recognized, so the codemod couldn't be applied. Please migrate manually.`,
68
+ )
69
+ }
70
+
71
+ const createKeyProperty = (node) =>
72
+ jscodeshift.property(
73
+ 'init',
74
+ jscodeshift.identifier(keyName),
75
+ createKeyValue(node),
76
+ )
77
+
78
+ const getPropertyFromObjectExpression = (objectExpression, propertyName) =>
79
+ objectExpression.properties.find(
80
+ (property) => property.key.name === propertyName,
81
+ ) ?? null
82
+
83
+ const buildWithTypeArguments = (node, builder) => {
84
+ const newNode = builder(node)
85
+
86
+ if (node.typeParameters) {
87
+ newNode.typeArguments = node.typeParameters
88
+ }
89
+
90
+ return newNode
91
+ }
92
+
93
+ return ({ node }) => {
94
+ // When the node doesn't have the 'original' property, that means the codemod has been already applied,
95
+ // so we don't need to do any changes.
96
+ if (!node.original) {
97
+ return node
98
+ }
99
+
100
+ const methodArguments = node.arguments
101
+
102
+ // The method call doesn't have any arguments, we have nothing to do in this case.
103
+ if (methodArguments.length === 0) {
104
+ return node
105
+ }
106
+
107
+ try {
108
+ const [firstArgument, ...restOfTheArguments] = methodArguments
109
+
110
+ if (
111
+ jscodeshift.match(firstArgument, {
112
+ type: jscodeshift.ObjectExpression.name,
113
+ })
114
+ ) {
115
+ const originalKey = getPropertyFromObjectExpression(
116
+ firstArgument,
117
+ keyName,
118
+ )
119
+
120
+ if (!originalKey) {
121
+ throw new UnprocessableKeyError(
122
+ `In file ${filePath} at line ${node.loc.start.line} the \`${keyName}\` couldn't be found. Did you forget to add it?`,
123
+ )
124
+ }
125
+
126
+ const restOfTheProperties = firstArgument.properties.filter(
127
+ (item) => item.key.name !== keyName,
128
+ )
129
+
130
+ return buildWithTypeArguments(node, (originalNode) =>
131
+ jscodeshift.callExpression(originalNode.original.callee, [
132
+ jscodeshift.objectExpression([
133
+ createKeyProperty(originalKey.value),
134
+ ...restOfTheProperties,
135
+ ]),
136
+ ...restOfTheArguments,
137
+ ]),
138
+ )
139
+ }
140
+
141
+ // When the node is an array expression we just simply return it because we want query keys to be arrays.
142
+ if (isArrayExpression(firstArgument)) {
143
+ return node
144
+ }
145
+
146
+ return buildWithTypeArguments(node, (originalNode) =>
147
+ jscodeshift.callExpression(originalNode.original.callee, [
148
+ createKeyValue(firstArgument),
149
+ ...restOfTheArguments,
150
+ ]),
151
+ )
152
+ } catch (error) {
153
+ if (error.name === 'UnprocessableKeyError') {
154
+ if (process.env.NODE_ENV !== 'test') {
155
+ console.warn(error.message)
156
+ }
157
+
158
+ return node
159
+ }
160
+
161
+ throw error
162
+ }
163
+ }
164
+ }
@@ -0,0 +1,50 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ var React = require('react');
5
+ var queryCore = require('@tanstack/query-core');
6
+ var QueryClientProvider = require('./QueryClientProvider.cjs');
7
+
8
+ function _interopNamespaceDefault(e) {
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n.default = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
26
+
27
+ const HydrationBoundary = ({
28
+ children,
29
+ options = {},
30
+ state,
31
+ queryClient
32
+ }) => {
33
+ const client = QueryClientProvider.useQueryClient(queryClient);
34
+ const optionsRef = React__namespace.useRef(options);
35
+ optionsRef.current = options;
36
+
37
+ // Running hydrate again with the same queries is safe,
38
+ // it wont overwrite or initialize existing queries,
39
+ // relying on useMemo here is only a performance optimization.
40
+ // hydrate can and should be run *during* render here for SSR to work properly
41
+ React__namespace.useMemo(() => {
42
+ if (state) {
43
+ queryCore.hydrate(client, state, optionsRef.current);
44
+ }
45
+ }, [client, state]);
46
+ return children;
47
+ };
48
+
49
+ exports.HydrationBoundary = HydrationBoundary;
50
+ //# sourceMappingURL=HydrationBoundary.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"HydrationBoundary.mjs","sources":["../../src/HydrationBoundary.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { HydrateOptions, QueryClient } from '@tanstack/query-core'\nimport { hydrate } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nexport interface HydrationBoundaryProps {\n state?: unknown\n options?: HydrateOptions\n children?: React.ReactNode\n queryClient?: QueryClient\n}\n\nexport const HydrationBoundary = ({\n children,\n options = {},\n state,\n queryClient,\n}: HydrationBoundaryProps) => {\n const client = useQueryClient(queryClient)\n\n const optionsRef = React.useRef(options)\n optionsRef.current = options\n\n // Running hydrate again with the same queries is safe,\n // it wont overwrite or initialize existing queries,\n // relying on useMemo here is only a performance optimization.\n // hydrate can and should be run *during* render here for SSR to work properly\n React.useMemo(() => {\n if (state) {\n hydrate(client, state, optionsRef.current)\n }\n }, [client, state])\n\n return children as React.ReactElement\n}\n"],"names":["HydrationBoundary","children","options","state","queryClient","client","useQueryClient","optionsRef","React","useRef","current","useMemo","hydrate"],"mappings":";;;;AAcO,MAAMA,iBAAiB,GAAG,CAAC;EAChCC,QAAQ;EACRC,OAAO,GAAG,EAAE;EACZC,KAAK;AACLC,EAAAA,WAAAA;AACsB,CAAC,KAAK;AAC5B,EAAA,MAAMC,MAAM,GAAGC,cAAc,CAACF,WAAW,CAAC,CAAA;AAE1C,EAAA,MAAMG,UAAU,GAAGC,KAAK,CAACC,MAAM,CAACP,OAAO,CAAC,CAAA;EACxCK,UAAU,CAACG,OAAO,GAAGR,OAAO,CAAA;;AAE5B;AACA;AACA;AACA;EACAM,KAAK,CAACG,OAAO,CAAC,MAAM;AAClB,IAAA,IAAIR,KAAK,EAAE;MACTS,OAAO,CAACP,MAAM,EAAEF,KAAK,EAAEI,UAAU,CAACG,OAAO,CAAC,CAAA;AAC5C,KAAA;AACF,GAAC,EAAE,CAACL,MAAM,EAAEF,KAAK,CAAC,CAAC,CAAA;AAEnB,EAAA,OAAOF,QAAQ,CAAA;AACjB;;;;"}
1
+ {"version":3,"file":"HydrationBoundary.cjs","sources":["../../src/HydrationBoundary.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { HydrateOptions, QueryClient } from '@tanstack/query-core'\nimport { hydrate } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nexport interface HydrationBoundaryProps {\n state?: unknown\n options?: HydrateOptions\n children?: React.ReactNode\n queryClient?: QueryClient\n}\n\nexport const HydrationBoundary = ({\n children,\n options = {},\n state,\n queryClient,\n}: HydrationBoundaryProps) => {\n const client = useQueryClient(queryClient)\n\n const optionsRef = React.useRef(options)\n optionsRef.current = options\n\n // Running hydrate again with the same queries is safe,\n // it wont overwrite or initialize existing queries,\n // relying on useMemo here is only a performance optimization.\n // hydrate can and should be run *during* render here for SSR to work properly\n React.useMemo(() => {\n if (state) {\n hydrate(client, state, optionsRef.current)\n }\n }, [client, state])\n\n return children as React.ReactElement\n}\n"],"names":["queryClient"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAcO;;;;AAILA;AACsB;AACtB;AAEA;;;AAGA;AACA;AACA;AACA;;AAEE;;AAEA;AACF;AAEA;AACF;;"}
@@ -7,3 +7,4 @@ export interface HydrationBoundaryProps {
7
7
  queryClient?: QueryClient;
8
8
  }
9
9
  export declare const HydrationBoundary: ({ children, options, state, queryClient, }: HydrationBoundaryProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
10
+ //# sourceMappingURL=HydrationBoundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HydrationBoundary.d.ts","sourceRoot":"","sources":["../../src/HydrationBoundary.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAIvE,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAA;CAC1B;AAED,eAAO,MAAM,iBAAiB,+CAK3B,sBAAsB,uEAiBxB,CAAA"}
@@ -1,27 +1,7 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
- var queryCore = require('@tanstack/query-core');
5
- var QueryClientProvider = require('./QueryClientProvider.js');
6
-
7
- function _interopNamespaceDefault(e) {
8
- var n = Object.create(null);
9
- if (e) {
10
- Object.keys(e).forEach(function (k) {
11
- if (k !== 'default') {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () { return e[k]; }
16
- });
17
- }
18
- });
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
-
24
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
1
+ 'use client';
2
+ import * as React from 'react';
3
+ import { hydrate } from '@tanstack/query-core';
4
+ import { useQueryClient } from './QueryClientProvider.js';
25
5
 
26
6
  const HydrationBoundary = ({
27
7
  children,
@@ -29,21 +9,21 @@ const HydrationBoundary = ({
29
9
  state,
30
10
  queryClient
31
11
  }) => {
32
- const client = QueryClientProvider.useQueryClient(queryClient);
33
- const optionsRef = React__namespace.useRef(options);
12
+ const client = useQueryClient(queryClient);
13
+ const optionsRef = React.useRef(options);
34
14
  optionsRef.current = options;
35
15
 
36
16
  // Running hydrate again with the same queries is safe,
37
17
  // it wont overwrite or initialize existing queries,
38
18
  // relying on useMemo here is only a performance optimization.
39
19
  // hydrate can and should be run *during* render here for SSR to work properly
40
- React__namespace.useMemo(() => {
20
+ React.useMemo(() => {
41
21
  if (state) {
42
- queryCore.hydrate(client, state, optionsRef.current);
22
+ hydrate(client, state, optionsRef.current);
43
23
  }
44
24
  }, [client, state]);
45
25
  return children;
46
26
  };
47
27
 
48
- exports.HydrationBoundary = HydrationBoundary;
28
+ export { HydrationBoundary };
49
29
  //# sourceMappingURL=HydrationBoundary.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HydrationBoundary.js","sources":["../../src/HydrationBoundary.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { HydrateOptions, QueryClient } from '@tanstack/query-core'\nimport { hydrate } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nexport interface HydrationBoundaryProps {\n state?: unknown\n options?: HydrateOptions\n children?: React.ReactNode\n queryClient?: QueryClient\n}\n\nexport const HydrationBoundary = ({\n children,\n options = {},\n state,\n queryClient,\n}: HydrationBoundaryProps) => {\n const client = useQueryClient(queryClient)\n\n const optionsRef = React.useRef(options)\n optionsRef.current = options\n\n // Running hydrate again with the same queries is safe,\n // it wont overwrite or initialize existing queries,\n // relying on useMemo here is only a performance optimization.\n // hydrate can and should be run *during* render here for SSR to work properly\n React.useMemo(() => {\n if (state) {\n hydrate(client, state, optionsRef.current)\n }\n }, [client, state])\n\n return children as React.ReactElement\n}\n"],"names":["HydrationBoundary","children","options","state","queryClient","client","useQueryClient","optionsRef","React","useRef","current","useMemo","hydrate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAcO,MAAMA,iBAAiB,GAAG,CAAC;EAChCC,QAAQ;EACRC,OAAO,GAAG,EAAE;EACZC,KAAK;AACLC,EAAAA,WAAAA;AACsB,CAAC,KAAK;AAC5B,EAAA,MAAMC,MAAM,GAAGC,kCAAc,CAACF,WAAW,CAAC,CAAA;AAE1C,EAAA,MAAMG,UAAU,GAAGC,gBAAK,CAACC,MAAM,CAACP,OAAO,CAAC,CAAA;EACxCK,UAAU,CAACG,OAAO,GAAGR,OAAO,CAAA;;AAE5B;AACA;AACA;AACA;EACAM,gBAAK,CAACG,OAAO,CAAC,MAAM;AAClB,IAAA,IAAIR,KAAK,EAAE;MACTS,iBAAO,CAACP,MAAM,EAAEF,KAAK,EAAEI,UAAU,CAACG,OAAO,CAAC,CAAA;AAC5C,KAAA;AACF,GAAC,EAAE,CAACL,MAAM,EAAEF,KAAK,CAAC,CAAC,CAAA;AAEnB,EAAA,OAAOF,QAAQ,CAAA;AACjB;;;;"}
1
+ {"version":3,"file":"HydrationBoundary.js","sources":["../../src/HydrationBoundary.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { HydrateOptions, QueryClient } from '@tanstack/query-core'\nimport { hydrate } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nexport interface HydrationBoundaryProps {\n state?: unknown\n options?: HydrateOptions\n children?: React.ReactNode\n queryClient?: QueryClient\n}\n\nexport const HydrationBoundary = ({\n children,\n options = {},\n state,\n queryClient,\n}: HydrationBoundaryProps) => {\n const client = useQueryClient(queryClient)\n\n const optionsRef = React.useRef(options)\n optionsRef.current = options\n\n // Running hydrate again with the same queries is safe,\n // it wont overwrite or initialize existing queries,\n // relying on useMemo here is only a performance optimization.\n // hydrate can and should be run *during* render here for SSR to work properly\n React.useMemo(() => {\n if (state) {\n hydrate(client, state, optionsRef.current)\n }\n }, [client, state])\n\n return children as React.ReactElement\n}\n"],"names":["queryClient"],"mappings":";;;;;AAcO;;;;AAILA;AACsB;AACtB;AAEA;;;AAGA;AACA;AACA;AACA;;AAEE;;AAEA;AACF;AAEA;AACF;;"}
@@ -0,0 +1,54 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ var React = require('react');
5
+
6
+ function _interopNamespaceDefault(e) {
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default') {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n.default = e;
20
+ return Object.freeze(n);
21
+ }
22
+
23
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
24
+
25
+ const QueryClientContext = /*#__PURE__*/React__namespace.createContext(undefined);
26
+ const useQueryClient = queryClient => {
27
+ const client = React__namespace.useContext(QueryClientContext);
28
+ if (queryClient) {
29
+ return queryClient;
30
+ }
31
+ if (!client) {
32
+ throw new Error('No QueryClient set, use QueryClientProvider to set one');
33
+ }
34
+ return client;
35
+ };
36
+ const QueryClientProvider = ({
37
+ client,
38
+ children
39
+ }) => {
40
+ React__namespace.useEffect(() => {
41
+ client.mount();
42
+ return () => {
43
+ client.unmount();
44
+ };
45
+ }, [client]);
46
+ return /*#__PURE__*/React__namespace.createElement(QueryClientContext.Provider, {
47
+ value: client
48
+ }, children);
49
+ };
50
+
51
+ exports.QueryClientContext = QueryClientContext;
52
+ exports.QueryClientProvider = QueryClientProvider;
53
+ exports.useQueryClient = useQueryClient;
54
+ //# sourceMappingURL=QueryClientProvider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryClientProvider.cjs","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { QueryClient } from '@tanstack/query-core'\n\nexport const QueryClientContext = React.createContext<QueryClient | undefined>(\n undefined,\n)\n\nexport const useQueryClient = (queryClient?: QueryClient) => {\n const client = React.useContext(QueryClientContext)\n\n if (queryClient) {\n return queryClient\n }\n\n if (!client) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return client\n}\n\nexport type QueryClientProviderProps = {\n client: QueryClient\n children?: React.ReactNode\n}\n\nexport const QueryClientProvider = ({\n client,\n children,\n}: QueryClientProviderProps): JSX.Element => {\n React.useEffect(() => {\n client.mount()\n return () => {\n client.unmount()\n }\n }, [client])\n\n return (\n <QueryClientContext.Provider value={client}>\n {children}\n </QueryClientContext.Provider>\n )\n}\n"],"names":["useQueryClient","children","value"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAKO;AAIMA;AACX;AAEA;AACE;AACF;;AAGE;AACF;AAEA;AACF;AAOO;;AAELC;AACwB;;;AAGtB;;;AAGF;AAEA;AAC+BC;AAAc;AAI/C;;;;"}
@@ -2,8 +2,9 @@ import * as React from 'react';
2
2
  import type { QueryClient } from '@tanstack/query-core';
3
3
  export declare const QueryClientContext: React.Context<QueryClient | undefined>;
4
4
  export declare const useQueryClient: (queryClient?: QueryClient) => QueryClient;
5
- export declare type QueryClientProviderProps = {
5
+ export type QueryClientProviderProps = {
6
6
  client: QueryClient;
7
7
  children?: React.ReactNode;
8
8
  };
9
9
  export declare const QueryClientProvider: ({ client, children, }: QueryClientProviderProps) => JSX.Element;
10
+ //# sourceMappingURL=QueryClientProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryClientProvider.d.ts","sourceRoot":"","sources":["../../src/QueryClientProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD,eAAO,MAAM,kBAAkB,wCAE9B,CAAA;AAED,eAAO,MAAM,cAAc,iBAAkB,WAAW,gBAYvD,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE,WAAW,CAAA;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,mBAAmB,0BAG7B,wBAAwB,KAAG,WAa7B,CAAA"}
@@ -1,29 +1,9 @@
1
- 'use strict';
1
+ 'use client';
2
+ import * as React from 'react';
2
3
 
3
- var React = require('react');
4
-
5
- function _interopNamespaceDefault(e) {
6
- var n = Object.create(null);
7
- if (e) {
8
- Object.keys(e).forEach(function (k) {
9
- if (k !== 'default') {
10
- var d = Object.getOwnPropertyDescriptor(e, k);
11
- Object.defineProperty(n, k, d.get ? d : {
12
- enumerable: true,
13
- get: function () { return e[k]; }
14
- });
15
- }
16
- });
17
- }
18
- n.default = e;
19
- return Object.freeze(n);
20
- }
21
-
22
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
23
-
24
- const QueryClientContext = /*#__PURE__*/React__namespace.createContext(undefined);
4
+ const QueryClientContext = /*#__PURE__*/React.createContext(undefined);
25
5
  const useQueryClient = queryClient => {
26
- const client = React__namespace.useContext(QueryClientContext);
6
+ const client = React.useContext(QueryClientContext);
27
7
  if (queryClient) {
28
8
  return queryClient;
29
9
  }
@@ -36,18 +16,16 @@ const QueryClientProvider = ({
36
16
  client,
37
17
  children
38
18
  }) => {
39
- React__namespace.useEffect(() => {
19
+ React.useEffect(() => {
40
20
  client.mount();
41
21
  return () => {
42
22
  client.unmount();
43
23
  };
44
24
  }, [client]);
45
- return /*#__PURE__*/React__namespace.createElement(QueryClientContext.Provider, {
25
+ return /*#__PURE__*/React.createElement(QueryClientContext.Provider, {
46
26
  value: client
47
27
  }, children);
48
28
  };
49
29
 
50
- exports.QueryClientContext = QueryClientContext;
51
- exports.QueryClientProvider = QueryClientProvider;
52
- exports.useQueryClient = useQueryClient;
30
+ export { QueryClientContext, QueryClientProvider, useQueryClient };
53
31
  //# sourceMappingURL=QueryClientProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"QueryClientProvider.js","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { QueryClient } from '@tanstack/query-core'\n\nexport const QueryClientContext = React.createContext<QueryClient | undefined>(\n undefined,\n)\n\nexport const useQueryClient = (queryClient?: QueryClient) => {\n const client = React.useContext(QueryClientContext)\n\n if (queryClient) {\n return queryClient\n }\n\n if (!client) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return client\n}\n\nexport type QueryClientProviderProps = {\n client: QueryClient\n children?: React.ReactNode\n}\n\nexport const QueryClientProvider = ({\n client,\n children,\n}: QueryClientProviderProps): JSX.Element => {\n React.useEffect(() => {\n client.mount()\n return () => {\n client.unmount()\n }\n }, [client])\n\n return (\n <QueryClientContext.Provider value={client}>\n {children}\n </QueryClientContext.Provider>\n )\n}\n"],"names":["QueryClientContext","React","createContext","undefined","useQueryClient","queryClient","client","useContext","Error","QueryClientProvider","children","useEffect","mount","unmount"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAKO,MAAMA,kBAAkB,gBAAGC,gBAAK,CAACC,aAAa,CACnDC,SAAS,EACV;AAEYC,MAAAA,cAAc,GAAIC,WAAyB,IAAK;AAC3D,EAAA,MAAMC,MAAM,GAAGL,gBAAK,CAACM,UAAU,CAACP,kBAAkB,CAAC,CAAA;AAEnD,EAAA,IAAIK,WAAW,EAAE;AACf,IAAA,OAAOA,WAAW,CAAA;AACpB,GAAA;EAEA,IAAI,CAACC,MAAM,EAAE;AACX,IAAA,MAAM,IAAIE,KAAK,CAAC,wDAAwD,CAAC,CAAA;AAC3E,GAAA;AAEA,EAAA,OAAOF,MAAM,CAAA;AACf,EAAC;AAOM,MAAMG,mBAAmB,GAAG,CAAC;EAClCH,MAAM;AACNI,EAAAA,QAAAA;AACwB,CAAC,KAAkB;EAC3CT,gBAAK,CAACU,SAAS,CAAC,MAAM;IACpBL,MAAM,CAACM,KAAK,EAAE,CAAA;AACd,IAAA,OAAO,MAAM;MACXN,MAAM,CAACO,OAAO,EAAE,CAAA;KACjB,CAAA;AACH,GAAC,EAAE,CAACP,MAAM,CAAC,CAAC,CAAA;EAEZ,oBACEL,gBAAA,CAAA,aAAA,CAAC,kBAAkB,CAAC,QAAQ,EAAA;AAAC,IAAA,KAAK,EAAEK,MAAAA;AAAO,GAAA,EACxCI,QAAQ,CACmB,CAAA;AAElC;;;;;;"}
1
+ {"version":3,"file":"QueryClientProvider.js","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { QueryClient } from '@tanstack/query-core'\n\nexport const QueryClientContext = React.createContext<QueryClient | undefined>(\n undefined,\n)\n\nexport const useQueryClient = (queryClient?: QueryClient) => {\n const client = React.useContext(QueryClientContext)\n\n if (queryClient) {\n return queryClient\n }\n\n if (!client) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return client\n}\n\nexport type QueryClientProviderProps = {\n client: QueryClient\n children?: React.ReactNode\n}\n\nexport const QueryClientProvider = ({\n client,\n children,\n}: QueryClientProviderProps): JSX.Element => {\n React.useEffect(() => {\n client.mount()\n return () => {\n client.unmount()\n }\n }, [client])\n\n return (\n <QueryClientContext.Provider value={client}>\n {children}\n </QueryClientContext.Provider>\n )\n}\n"],"names":["useQueryClient","children","value"],"mappings":";;;AAKO;AAIMA;AACX;AAEA;AACE;AACF;;AAGE;AACF;AAEA;AACF;AAOO;;AAELC;AACwB;;;AAGtB;;;AAGF;AAEA;AAC+BC;AAAc;AAI/C;;"}