@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.
Files changed (54) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +34 -85
  3. package/dist/components-Dow6tde8.js +1459 -0
  4. package/dist/components-Dow6tde8.js.map +1 -0
  5. package/dist/components-HwdCDefj.cjs +1603 -0
  6. package/dist/components-HwdCDefj.cjs.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +49 -179
  9. package/dist/components.js +1 -1
  10. package/dist/generators-CcOmnTPa.cjs +1454 -0
  11. package/dist/generators-CcOmnTPa.cjs.map +1 -0
  12. package/dist/generators-yfZr_qfT.js +1412 -0
  13. package/dist/generators-yfZr_qfT.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +9 -476
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +197 -126
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +193 -126
  21. package/dist/index.js.map +1 -1
  22. package/dist/types-DG_OxOym.d.ts +363 -0
  23. package/extension.yaml +911 -0
  24. package/package.json +59 -64
  25. package/src/components/InfiniteQuery.tsx +79 -138
  26. package/src/components/InfiniteQueryOptions.tsx +55 -166
  27. package/src/components/Mutation.tsx +74 -111
  28. package/src/components/MutationOptions.tsx +61 -80
  29. package/src/components/Query.tsx +66 -142
  30. package/src/components/QueryOptions.tsx +56 -138
  31. package/src/components/SuspenseInfiniteQuery.tsx +79 -138
  32. package/src/components/SuspenseInfiniteQueryOptions.tsx +55 -166
  33. package/src/components/SuspenseQuery.tsx +66 -152
  34. package/src/generators/customHookOptionsFileGenerator.tsx +37 -51
  35. package/src/generators/hookOptionsGenerator.tsx +111 -174
  36. package/src/generators/infiniteQueryGenerator.tsx +158 -178
  37. package/src/generators/mutationGenerator.tsx +112 -139
  38. package/src/generators/queryGenerator.tsx +128 -142
  39. package/src/generators/suspenseInfiniteQueryGenerator.tsx +157 -156
  40. package/src/generators/suspenseQueryGenerator.tsx +126 -152
  41. package/src/index.ts +1 -1
  42. package/src/plugin.ts +134 -187
  43. package/src/resolvers/resolverReactQuery.ts +107 -0
  44. package/src/types.ts +172 -49
  45. package/src/utils.ts +10 -0
  46. package/dist/components-BHQT9ZLc.cjs +0 -1634
  47. package/dist/components-BHQT9ZLc.cjs.map +0 -1
  48. package/dist/components-CpyHYGOw.js +0 -1520
  49. package/dist/components-CpyHYGOw.js.map +0 -1
  50. package/dist/generators-DP07m3rH.cjs +0 -1469
  51. package/dist/generators-DP07m3rH.cjs.map +0 -1
  52. package/dist/generators-DkQwKTc2.js +0 -1427
  53. package/dist/generators-DkQwKTc2.js.map +0 -1
  54. 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, ResolveNameParams } from '@kubb/core'
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
- * Define which HttpMethods can be used for queries
142
+ * HTTP methods to use for queries.
143
+ *
25
144
  * @default ['get']
26
145
  */
27
- methods: Array<HttpMethod>
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
- * Define which HttpMethods can be used for mutations
159
+ * HTTP methods to use for mutations.
160
+ *
41
161
  * @default ['post', 'put', 'delete']
42
162
  */
43
- methods: Array<HttpMethod>
163
+ methods?: Array<string>
44
164
  /**
45
- * Path to the useQuery hook for useQuery functionality.
46
- * Used as `import { useQuery } from '${importPath}'`.
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<Oas>
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
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
229
+ * Tags, operations, or paths to exclude from generation.
115
230
  */
116
231
  exclude?: Array<Exclude>
117
232
  /**
118
- * Array containing include parameters to include tags/operations/methods/paths.
233
+ * Tags, operations, or paths to include in generation.
119
234
  */
120
235
  include?: Array<Include>
121
236
  /**
122
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
237
+ * Override options for specific tags, operations, or paths.
123
238
  */
124
239
  override?: Array<Override<ResolvedOptions>>
125
240
  /**
126
- * How to style your params, by default no casing is applied
127
- * - 'camelcase' uses camelcase for the params names
241
+ * Apply casing to parameter names.
128
242
  */
129
243
  paramsCasing?: 'camelcase'
130
244
  /**
131
- * How to pass your params.
132
- * - 'object' returns the params and pathParams as an object.
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 to pass your pathParams.
139
- * - 'object' returns the pathParams as an object.
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
- * When set, an infiniteQuery hooks is added.
257
+ * Add infinite query hooks.
147
258
  */
148
259
  infinite?: Partial<Infinite> | false
149
260
  /**
150
- * When set, a suspenseQuery hooks is added.
261
+ * Add suspense query hooks.
151
262
  */
152
263
  suspense?: Partial<Suspense> | false
153
264
  queryKey?: QueryKey
154
265
  /**
155
- * Override some useQuery behaviors.
266
+ * Configure useQuery behavior.
156
267
  */
157
268
  query?: Partial<Query> | false
158
269
  mutationKey?: MutationKey
159
270
  /**
160
- * Override some useMutation behaviors.
271
+ * Configure useMutation behavior.
161
272
  */
162
273
  mutation?: Partial<Mutation> | false
163
274
  /**
164
- * When set, a custom hook is used to customize the options of the generated hooks.
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
- * Which parser should be used before returning the data to `@tanstack/query`.
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
- * Define some generators next to the react-query generators
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<Oas>
187
- group: Options['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 of infinite
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, never, ResolvePathOptions>
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'