@kubb/plugin-react-query 5.0.0-alpha.8 → 5.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -10
- package/README.md +34 -85
- package/dist/components-Dow6tde8.js +1459 -0
- package/dist/components-Dow6tde8.js.map +1 -0
- package/dist/components-HwdCDefj.cjs +1603 -0
- package/dist/components-HwdCDefj.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +49 -179
- package/dist/components.js +1 -1
- package/dist/generators-CcOmnTPa.cjs +1454 -0
- package/dist/generators-CcOmnTPa.cjs.map +1 -0
- package/dist/generators-yfZr_qfT.js +1412 -0
- package/dist/generators-yfZr_qfT.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +9 -476
- package/dist/generators.js +1 -1
- package/dist/index.cjs +197 -126
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +193 -126
- package/dist/index.js.map +1 -1
- package/dist/types-DG_OxOym.d.ts +363 -0
- package/extension.yaml +911 -0
- package/package.json +59 -64
- package/src/components/InfiniteQuery.tsx +79 -138
- package/src/components/InfiniteQueryOptions.tsx +55 -166
- package/src/components/Mutation.tsx +74 -111
- package/src/components/MutationOptions.tsx +61 -80
- package/src/components/Query.tsx +66 -142
- package/src/components/QueryOptions.tsx +56 -138
- package/src/components/SuspenseInfiniteQuery.tsx +79 -138
- package/src/components/SuspenseInfiniteQueryOptions.tsx +55 -166
- package/src/components/SuspenseQuery.tsx +66 -152
- package/src/generators/customHookOptionsFileGenerator.tsx +37 -51
- package/src/generators/hookOptionsGenerator.tsx +111 -174
- package/src/generators/infiniteQueryGenerator.tsx +158 -178
- package/src/generators/mutationGenerator.tsx +112 -139
- package/src/generators/queryGenerator.tsx +128 -142
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +157 -156
- package/src/generators/suspenseQueryGenerator.tsx +126 -152
- package/src/index.ts +1 -1
- package/src/plugin.ts +134 -187
- package/src/resolvers/resolverReactQuery.ts +107 -0
- package/src/types.ts +172 -49
- package/src/utils.ts +10 -0
- package/dist/components-BHQT9ZLc.cjs +0 -1634
- package/dist/components-BHQT9ZLc.cjs.map +0 -1
- package/dist/components-CpyHYGOw.js +0 -1520
- package/dist/components-CpyHYGOw.js.map +0 -1
- package/dist/generators-DP07m3rH.cjs +0 -1469
- package/dist/generators-DP07m3rH.cjs.map +0 -1
- package/dist/generators-DkQwKTc2.js +0 -1427
- package/dist/generators-DkQwKTc2.js.map +0 -1
- package/dist/types-D5S7Ny9r.d.ts +0 -270
package/src/types.ts
CHANGED
|
@@ -1,30 +1,149 @@
|
|
|
1
1
|
import type { Transformer } from '@internals/tanstack-query'
|
|
2
|
-
import type { Group, Output, PluginFactoryOptions,
|
|
3
|
-
import type { contentType, HttpMethod, Oas } from '@kubb/oas'
|
|
2
|
+
import type { ast, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver } from '@kubb/core'
|
|
4
3
|
import type { ClientImportPath, PluginClient } from '@kubb/plugin-client'
|
|
5
|
-
import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
6
|
-
import type { Generator } from '@kubb/plugin-oas/generators'
|
|
7
4
|
|
|
8
5
|
export type { Transformer } from '@internals/tanstack-query'
|
|
9
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Resolver for React Query that provides naming methods for hook functions.
|
|
9
|
+
*/
|
|
10
|
+
export type ResolverReactQuery = Resolver & {
|
|
11
|
+
/**
|
|
12
|
+
* Resolves the base function name for an operation.
|
|
13
|
+
*
|
|
14
|
+
* @example Resolving base operation names
|
|
15
|
+
* `resolver.resolveName('show pet by id') // -> 'showPetById'`
|
|
16
|
+
*/
|
|
17
|
+
resolveName(this: ResolverReactQuery, name: string): string
|
|
18
|
+
/**
|
|
19
|
+
* Resolves the output file name for a hook module.
|
|
20
|
+
*/
|
|
21
|
+
resolvePathName(this: ResolverReactQuery, name: string, type?: 'file' | 'function' | 'type' | 'const'): string
|
|
22
|
+
/**
|
|
23
|
+
* Resolves a query hook function name.
|
|
24
|
+
*/
|
|
25
|
+
resolveQueryName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
26
|
+
/**
|
|
27
|
+
* Resolves a suspense query hook function name.
|
|
28
|
+
*/
|
|
29
|
+
resolveSuspenseQueryName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
30
|
+
/**
|
|
31
|
+
* Resolves an infinite query hook function name.
|
|
32
|
+
*/
|
|
33
|
+
resolveInfiniteQueryName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
34
|
+
/**
|
|
35
|
+
* Resolves a suspense infinite query hook function name.
|
|
36
|
+
*/
|
|
37
|
+
resolveSuspenseInfiniteQueryName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
38
|
+
/**
|
|
39
|
+
* Resolves a mutation hook function name.
|
|
40
|
+
*/
|
|
41
|
+
resolveMutationName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
42
|
+
/**
|
|
43
|
+
* Resolves the query options helper name.
|
|
44
|
+
*/
|
|
45
|
+
resolveQueryOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
46
|
+
/**
|
|
47
|
+
* Resolves the suspense query options helper name.
|
|
48
|
+
*/
|
|
49
|
+
resolveSuspenseQueryOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
50
|
+
/**
|
|
51
|
+
* Resolves the infinite query options helper name.
|
|
52
|
+
*/
|
|
53
|
+
resolveInfiniteQueryOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
54
|
+
/**
|
|
55
|
+
* Resolves the suspense infinite query options helper name.
|
|
56
|
+
*/
|
|
57
|
+
resolveSuspenseInfiniteQueryOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
58
|
+
/**
|
|
59
|
+
* Resolves the mutation options helper name.
|
|
60
|
+
*/
|
|
61
|
+
resolveMutationOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
62
|
+
/**
|
|
63
|
+
* Resolves the query key helper name.
|
|
64
|
+
*/
|
|
65
|
+
resolveQueryKeyName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
66
|
+
/**
|
|
67
|
+
* Resolves the suspense query key helper name.
|
|
68
|
+
*/
|
|
69
|
+
resolveSuspenseQueryKeyName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
70
|
+
/**
|
|
71
|
+
* Resolves the infinite query key helper name.
|
|
72
|
+
*/
|
|
73
|
+
resolveInfiniteQueryKeyName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
74
|
+
/**
|
|
75
|
+
* Resolves the suspense infinite query key helper name.
|
|
76
|
+
*/
|
|
77
|
+
resolveSuspenseInfiniteQueryKeyName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
78
|
+
/**
|
|
79
|
+
* Resolves the mutation key helper name.
|
|
80
|
+
*/
|
|
81
|
+
resolveMutationKeyName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
82
|
+
/**
|
|
83
|
+
* Resolves the query key type name.
|
|
84
|
+
*/
|
|
85
|
+
resolveQueryKeyTypeName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
86
|
+
/**
|
|
87
|
+
* Resolves the suspense query key type name.
|
|
88
|
+
*/
|
|
89
|
+
resolveSuspenseQueryKeyTypeName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
90
|
+
/**
|
|
91
|
+
* Resolves the infinite query key type name.
|
|
92
|
+
*/
|
|
93
|
+
resolveInfiniteQueryKeyTypeName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
94
|
+
/**
|
|
95
|
+
* Resolves the suspense infinite query key type name.
|
|
96
|
+
*/
|
|
97
|
+
resolveSuspenseInfiniteQueryKeyTypeName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
98
|
+
/**
|
|
99
|
+
* Resolves the mutation type name.
|
|
100
|
+
*/
|
|
101
|
+
resolveMutationTypeName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
102
|
+
/**
|
|
103
|
+
* Resolves the client function name generated inline by query hooks.
|
|
104
|
+
*/
|
|
105
|
+
resolveClientName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
106
|
+
/**
|
|
107
|
+
* Resolves the client function name generated inline by suspense query hooks.
|
|
108
|
+
*/
|
|
109
|
+
resolveSuspenseClientName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
110
|
+
/**
|
|
111
|
+
* Resolves the client function name generated inline by infinite query hooks.
|
|
112
|
+
*/
|
|
113
|
+
resolveInfiniteClientName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
114
|
+
/**
|
|
115
|
+
* Resolves the client function name generated inline by suspense infinite query hooks.
|
|
116
|
+
*/
|
|
117
|
+
resolveSuspenseInfiniteClientName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
118
|
+
/**
|
|
119
|
+
* Resolves the generated custom hook options map type name.
|
|
120
|
+
*/
|
|
121
|
+
resolveHookOptionsName(this: ResolverReactQuery): string
|
|
122
|
+
/**
|
|
123
|
+
* Resolves the helper function name used inside the custom hook options file.
|
|
124
|
+
*/
|
|
125
|
+
resolveCustomHookOptionsName(this: ResolverReactQuery): string
|
|
126
|
+
}
|
|
127
|
+
|
|
10
128
|
type Suspense = object
|
|
11
129
|
|
|
12
130
|
/**
|
|
13
|
-
* Customize the queryKey
|
|
131
|
+
* Customize the queryKey.
|
|
14
132
|
*/
|
|
15
133
|
type QueryKey = Transformer
|
|
16
134
|
|
|
17
135
|
/**
|
|
18
|
-
* Customize the mutationKey
|
|
136
|
+
* Customize the mutationKey.
|
|
19
137
|
*/
|
|
20
138
|
type MutationKey = Transformer
|
|
21
139
|
|
|
22
140
|
type Query = {
|
|
23
141
|
/**
|
|
24
|
-
*
|
|
142
|
+
* HTTP methods to use for queries.
|
|
143
|
+
*
|
|
25
144
|
* @default ['get']
|
|
26
145
|
*/
|
|
27
|
-
methods
|
|
146
|
+
methods?: Array<string>
|
|
28
147
|
/**
|
|
29
148
|
* Path to the useQuery hook for useQuery functionality.
|
|
30
149
|
* Used as `import { useQuery } from '${importPath}'`.
|
|
@@ -37,13 +156,14 @@ type Query = {
|
|
|
37
156
|
|
|
38
157
|
type Mutation = {
|
|
39
158
|
/**
|
|
40
|
-
*
|
|
159
|
+
* HTTP methods to use for mutations.
|
|
160
|
+
*
|
|
41
161
|
* @default ['post', 'put', 'delete']
|
|
42
162
|
*/
|
|
43
|
-
methods
|
|
163
|
+
methods?: Array<string>
|
|
44
164
|
/**
|
|
45
|
-
* Path to the
|
|
46
|
-
* Used as `import {
|
|
165
|
+
* Path to the useMutation hook for useMutation functionality.
|
|
166
|
+
* Used as `import { useMutation } from '${importPath}'`.
|
|
47
167
|
* Accepts relative and absolute paths.
|
|
48
168
|
* Path is used as-is; relative paths are based on the generated file location.
|
|
49
169
|
* @default '@tanstack/react-query'
|
|
@@ -99,99 +219,93 @@ export type Options = {
|
|
|
99
219
|
* Specify the export location for the files and define the behavior of the output
|
|
100
220
|
* @default { path: 'hooks', barrelType: 'named' }
|
|
101
221
|
*/
|
|
102
|
-
output?: Output
|
|
103
|
-
/**
|
|
104
|
-
* Define which contentType should be used.
|
|
105
|
-
* By default, the first JSON valid mediaType is used
|
|
106
|
-
*/
|
|
107
|
-
contentType?: contentType
|
|
222
|
+
output?: Output
|
|
108
223
|
/**
|
|
109
224
|
* Group the @tanstack/query hooks based on the provided name.
|
|
110
225
|
*/
|
|
111
226
|
group?: Group
|
|
112
227
|
client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>
|
|
113
228
|
/**
|
|
114
|
-
*
|
|
229
|
+
* Tags, operations, or paths to exclude from generation.
|
|
115
230
|
*/
|
|
116
231
|
exclude?: Array<Exclude>
|
|
117
232
|
/**
|
|
118
|
-
*
|
|
233
|
+
* Tags, operations, or paths to include in generation.
|
|
119
234
|
*/
|
|
120
235
|
include?: Array<Include>
|
|
121
236
|
/**
|
|
122
|
-
*
|
|
237
|
+
* Override options for specific tags, operations, or paths.
|
|
123
238
|
*/
|
|
124
239
|
override?: Array<Override<ResolvedOptions>>
|
|
125
240
|
/**
|
|
126
|
-
*
|
|
127
|
-
* - 'camelcase' uses camelcase for the params names
|
|
241
|
+
* Apply casing to parameter names.
|
|
128
242
|
*/
|
|
129
243
|
paramsCasing?: 'camelcase'
|
|
130
244
|
/**
|
|
131
|
-
* How
|
|
132
|
-
*
|
|
133
|
-
* - 'inline' returns the params as comma separated params.
|
|
245
|
+
* How parameters are passed: grouped in an object or spread inline.
|
|
246
|
+
*
|
|
134
247
|
* @default 'inline'
|
|
135
248
|
*/
|
|
136
249
|
paramsType?: 'object' | 'inline'
|
|
137
250
|
/**
|
|
138
|
-
* How
|
|
139
|
-
*
|
|
140
|
-
* - 'inline': returns the pathParams as comma separated params.
|
|
251
|
+
* How path parameters are passed: grouped in an object or spread inline.
|
|
252
|
+
*
|
|
141
253
|
* @default 'inline'
|
|
142
254
|
*/
|
|
143
255
|
pathParamsType?: PluginClient['options']['pathParamsType']
|
|
144
|
-
|
|
145
256
|
/**
|
|
146
|
-
*
|
|
257
|
+
* Add infinite query hooks.
|
|
147
258
|
*/
|
|
148
259
|
infinite?: Partial<Infinite> | false
|
|
149
260
|
/**
|
|
150
|
-
*
|
|
261
|
+
* Add suspense query hooks.
|
|
151
262
|
*/
|
|
152
263
|
suspense?: Partial<Suspense> | false
|
|
153
264
|
queryKey?: QueryKey
|
|
154
265
|
/**
|
|
155
|
-
*
|
|
266
|
+
* Configure useQuery behavior.
|
|
156
267
|
*/
|
|
157
268
|
query?: Partial<Query> | false
|
|
158
269
|
mutationKey?: MutationKey
|
|
159
270
|
/**
|
|
160
|
-
*
|
|
271
|
+
* Configure useMutation behavior.
|
|
161
272
|
*/
|
|
162
273
|
mutation?: Partial<Mutation> | false
|
|
163
274
|
/**
|
|
164
|
-
*
|
|
165
|
-
* It will also generate a `HookOptions` type that can be used to type the custom options of each hook for type-safety.
|
|
275
|
+
* Use a custom hook to customize hook options and generate a HookOptions type.
|
|
166
276
|
*/
|
|
167
277
|
customOptions?: CustomOptions
|
|
168
278
|
/**
|
|
169
|
-
*
|
|
170
|
-
* `'zod'` uses `@kubb/plugin-zod` to parse the data.
|
|
279
|
+
* Parser to use for validating response data.
|
|
171
280
|
*/
|
|
172
281
|
parser?: PluginClient['options']['parser']
|
|
173
|
-
transformers?: {
|
|
174
|
-
/**
|
|
175
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
176
|
-
*/
|
|
177
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
|
178
|
-
}
|
|
179
282
|
/**
|
|
180
|
-
*
|
|
283
|
+
* Override naming conventions for function names and types.
|
|
284
|
+
*/
|
|
285
|
+
resolver?: Partial<ResolverReactQuery> & ThisType<ResolverReactQuery>
|
|
286
|
+
/**
|
|
287
|
+
* AST visitor to transform generated nodes.
|
|
288
|
+
*/
|
|
289
|
+
transformer?: ast.Visitor
|
|
290
|
+
/**
|
|
291
|
+
* Additional generators alongside the default generators.
|
|
181
292
|
*/
|
|
182
293
|
generators?: Array<Generator<PluginReactQuery>>
|
|
183
294
|
}
|
|
184
295
|
|
|
185
296
|
type ResolvedOptions = {
|
|
186
|
-
output: Output
|
|
187
|
-
group:
|
|
297
|
+
output: Output
|
|
298
|
+
group: Group | undefined
|
|
299
|
+
exclude: NonNullable<Options['exclude']>
|
|
300
|
+
include: Options['include']
|
|
301
|
+
override: NonNullable<Options['override']>
|
|
188
302
|
client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>
|
|
189
303
|
parser: Required<NonNullable<Options['parser']>>
|
|
190
304
|
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
191
305
|
paramsCasing: Options['paramsCasing']
|
|
192
306
|
paramsType: NonNullable<Options['paramsType']>
|
|
193
307
|
/**
|
|
194
|
-
* Only used
|
|
308
|
+
* Only used for infinite
|
|
195
309
|
*/
|
|
196
310
|
infinite: NonNullable<Infinite> | false
|
|
197
311
|
suspense: Suspense | false
|
|
@@ -200,6 +314,15 @@ type ResolvedOptions = {
|
|
|
200
314
|
mutationKey: MutationKey | undefined
|
|
201
315
|
mutation: NonNullable<Required<Mutation>> | false
|
|
202
316
|
customOptions: NonNullable<Required<CustomOptions>> | undefined
|
|
317
|
+
resolver: ResolverReactQuery
|
|
203
318
|
}
|
|
204
319
|
|
|
205
|
-
export type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions,
|
|
320
|
+
export type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, ResolverReactQuery>
|
|
321
|
+
|
|
322
|
+
declare global {
|
|
323
|
+
namespace Kubb {
|
|
324
|
+
interface PluginRegistry {
|
|
325
|
+
'plugin-react-query': PluginReactQuery
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export {
|
|
2
|
+
buildGroupParam,
|
|
3
|
+
buildQueryKeyParams,
|
|
4
|
+
resolveHeaderGroupType,
|
|
5
|
+
resolveOperationOverrides,
|
|
6
|
+
resolvePathParamType,
|
|
7
|
+
resolveQueryGroupType,
|
|
8
|
+
resolveZodSchemaNames,
|
|
9
|
+
} from '@internals/tanstack-query'
|
|
10
|
+
export { buildOperationComments as getComments, buildRequestConfigType, getContentTypeInfo, resolveErrorNames, resolveStatusCodeNames } from '@internals/shared'
|