@kubb/plugin-vue-query 5.0.0-alpha.9 → 5.0.0-beta.15

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 (47) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +26 -7
  3. package/dist/components-1cEftHJm.cjs +1276 -0
  4. package/dist/components-1cEftHJm.cjs.map +1 -0
  5. package/dist/components-DTSvTMEo.js +1162 -0
  6. package/dist/components-DTSvTMEo.js.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +66 -121
  9. package/dist/components.js +1 -1
  10. package/dist/generators-BEiWCS-U.cjs +698 -0
  11. package/dist/generators-BEiWCS-U.cjs.map +1 -0
  12. package/dist/generators-F6_EduRU.js +681 -0
  13. package/dist/generators-F6_EduRU.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +5 -501
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +150 -121
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +146 -121
  21. package/dist/index.js.map +1 -1
  22. package/dist/types-Bkm7bWT3.d.ts +243 -0
  23. package/extension.yaml +749 -0
  24. package/package.json +60 -65
  25. package/src/components/InfiniteQuery.tsx +71 -159
  26. package/src/components/InfiniteQueryOptions.tsx +120 -163
  27. package/src/components/Mutation.tsx +97 -134
  28. package/src/components/Query.tsx +68 -157
  29. package/src/components/QueryKey.tsx +23 -66
  30. package/src/components/QueryOptions.tsx +97 -143
  31. package/src/generators/infiniteQueryGenerator.tsx +152 -171
  32. package/src/generators/mutationGenerator.tsx +102 -125
  33. package/src/generators/queryGenerator.tsx +125 -137
  34. package/src/index.ts +1 -1
  35. package/src/plugin.ts +126 -177
  36. package/src/resolvers/resolverVueQuery.ts +65 -0
  37. package/src/types.ts +121 -52
  38. package/src/utils.ts +49 -0
  39. package/dist/components-Yjoe78Y7.cjs +0 -1119
  40. package/dist/components-Yjoe78Y7.cjs.map +0 -1
  41. package/dist/components-_AMBl0g-.js +0 -1029
  42. package/dist/components-_AMBl0g-.js.map +0 -1
  43. package/dist/generators-CR34GjVu.js +0 -661
  44. package/dist/generators-CR34GjVu.js.map +0 -1
  45. package/dist/generators-DH8VkK1q.cjs +0 -678
  46. package/dist/generators-DH8VkK1q.cjs.map +0 -1
  47. package/dist/types-CgDFUvfZ.d.ts +0 -211
@@ -0,0 +1,65 @@
1
+ import { camelCase } from '@internals/utils'
2
+ import { defineResolver } from '@kubb/core'
3
+ import type { PluginVueQuery } from '../types.ts'
4
+
5
+ function capitalize(name: string): string {
6
+ return `${name.charAt(0).toUpperCase()}${name.slice(1)}`
7
+ }
8
+
9
+ /**
10
+ * Naming convention resolver for Vue Query plugin.
11
+ *
12
+ * Provides default naming helpers using camelCase for functions and file paths.
13
+ */
14
+ export const resolverVueQuery = defineResolver<PluginVueQuery>(() => ({
15
+ name: 'default',
16
+ pluginName: 'plugin-vue-query',
17
+ default(name, type) {
18
+ return camelCase(name, { isFile: type === 'file' })
19
+ },
20
+ resolveName(name) {
21
+ return this.default(name, 'function')
22
+ },
23
+ resolvePathName(name, type) {
24
+ return this.default(name, type)
25
+ },
26
+ resolveQueryName(node) {
27
+ return `use${capitalize(this.resolveName(node.operationId))}`
28
+ },
29
+ resolveInfiniteQueryName(node) {
30
+ return `use${capitalize(this.resolveName(node.operationId))}Infinite`
31
+ },
32
+ resolveMutationName(node) {
33
+ return `use${capitalize(this.resolveName(node.operationId))}`
34
+ },
35
+ resolveQueryOptionsName(node) {
36
+ return `${this.resolveName(node.operationId)}QueryOptions`
37
+ },
38
+ resolveInfiniteQueryOptionsName(node) {
39
+ return `${this.resolveName(node.operationId)}InfiniteQueryOptions`
40
+ },
41
+ resolveQueryKeyName(node) {
42
+ return `${this.resolveName(node.operationId)}QueryKey`
43
+ },
44
+ resolveInfiniteQueryKeyName(node) {
45
+ return `${this.resolveName(node.operationId)}InfiniteQueryKey`
46
+ },
47
+ resolveMutationKeyName(node) {
48
+ return `${this.resolveName(node.operationId)}MutationKey`
49
+ },
50
+ resolveQueryKeyTypeName(node) {
51
+ return `${capitalize(this.resolveName(node.operationId))}QueryKey`
52
+ },
53
+ resolveInfiniteQueryKeyTypeName(node) {
54
+ return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`
55
+ },
56
+ resolveMutationTypeName(node) {
57
+ return capitalize(this.resolveName(node.operationId))
58
+ },
59
+ resolveClientName(node) {
60
+ return this.resolveName(node.operationId)
61
+ },
62
+ resolveInfiniteClientName(node) {
63
+ return `${this.resolveName(node.operationId)}Infinite`
64
+ },
65
+ }))
package/src/types.ts CHANGED
@@ -1,50 +1,114 @@
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'
1
+ import type { ast, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver } from '@kubb/core'
4
2
  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
3
 
8
- export type { Transformer } from '@internals/tanstack-query'
4
+ export type Transformer = (props: { node: ast.OperationNode; casing: 'camelcase' | undefined }) => unknown[]
9
5
 
10
6
  /**
11
- * Customize the queryKey
7
+ * Resolver for Vue Query that provides naming methods for hook functions.
8
+ */
9
+ export type ResolverVueQuery = Resolver & {
10
+ /**
11
+ * Resolves the base function name for an operation.
12
+ */
13
+ resolveName(this: ResolverVueQuery, name: string): string
14
+ /**
15
+ * Resolves the output file name for a hook module.
16
+ */
17
+ resolvePathName(this: ResolverVueQuery, name: string, type?: 'file' | 'function' | 'type' | 'const'): string
18
+ /**
19
+ * Resolves a query hook function name.
20
+ */
21
+ resolveQueryName(this: ResolverVueQuery, node: ast.OperationNode): string
22
+ /**
23
+ * Resolves an infinite query hook function name.
24
+ */
25
+ resolveInfiniteQueryName(this: ResolverVueQuery, node: ast.OperationNode): string
26
+ /**
27
+ * Resolves a mutation hook function name.
28
+ */
29
+ resolveMutationName(this: ResolverVueQuery, node: ast.OperationNode): string
30
+ /**
31
+ * Resolves the query options helper name.
32
+ */
33
+ resolveQueryOptionsName(this: ResolverVueQuery, node: ast.OperationNode): string
34
+ /**
35
+ * Resolves the infinite query options helper name.
36
+ */
37
+ resolveInfiniteQueryOptionsName(this: ResolverVueQuery, node: ast.OperationNode): string
38
+ /**
39
+ * Resolves the query key helper name.
40
+ */
41
+ resolveQueryKeyName(this: ResolverVueQuery, node: ast.OperationNode): string
42
+ /**
43
+ * Resolves the infinite query key helper name.
44
+ */
45
+ resolveInfiniteQueryKeyName(this: ResolverVueQuery, node: ast.OperationNode): string
46
+ /**
47
+ * Resolves the mutation key helper name.
48
+ */
49
+ resolveMutationKeyName(this: ResolverVueQuery, node: ast.OperationNode): string
50
+ /**
51
+ * Resolves the query key type name.
52
+ */
53
+ resolveQueryKeyTypeName(this: ResolverVueQuery, node: ast.OperationNode): string
54
+ /**
55
+ * Resolves the infinite query key type name.
56
+ */
57
+ resolveInfiniteQueryKeyTypeName(this: ResolverVueQuery, node: ast.OperationNode): string
58
+ /**
59
+ * Resolves the mutation type name.
60
+ */
61
+ resolveMutationTypeName(this: ResolverVueQuery, node: ast.OperationNode): string
62
+ /**
63
+ * Resolves the client function name generated inline by query hooks.
64
+ */
65
+ resolveClientName(this: ResolverVueQuery, node: ast.OperationNode): string
66
+ /**
67
+ * Resolves the client function name generated inline by infinite query hooks.
68
+ */
69
+ resolveInfiniteClientName(this: ResolverVueQuery, node: ast.OperationNode): string
70
+ }
71
+
72
+ /**
73
+ * Customize the queryKey.
12
74
  */
13
75
  type QueryKey = Transformer
14
76
 
15
77
  /**
16
- * Customize the mutationKey
78
+ * Customize the mutationKey.
17
79
  */
18
80
  type MutationKey = Transformer
19
81
 
20
82
  type Query = {
21
83
  /**
22
- * Define which HttpMethods can be used for queries
84
+ * HTTP methods to use for queries.
85
+ *
23
86
  * @default ['get']
24
87
  */
25
- methods: Array<HttpMethod>
88
+ methods?: Array<string>
26
89
  /**
27
90
  * Path to the useQuery hook for useQuery functionality.
28
91
  * Used as `import { useQuery } from '${importPath}'`.
29
92
  * Accepts relative and absolute paths.
30
93
  * Path is used as-is; relative paths are based on the generated file location.
31
- * @default '@tanstack/react-query'
94
+ * @default '@tanstack/vue-query'
32
95
  */
33
96
  importPath?: string
34
97
  }
35
98
 
36
99
  type Mutation = {
37
100
  /**
38
- * Define which HttpMethods can be used for mutations
101
+ * HTTP methods to use for mutations.
102
+ *
39
103
  * @default ['post', 'put', 'delete']
40
104
  */
41
- methods: Array<HttpMethod>
105
+ methods?: Array<string>
42
106
  /**
43
- * Path to the useQuery hook for useQuery functionality.
44
- * Used as `import { useQuery } from '${importPath}'`.
107
+ * Path to the useMutation hook for useMutation functionality.
108
+ * Used as `import { useMutation } from '${importPath}'`.
45
109
  * Accepts relative and absolute paths.
46
110
  * Path is used as-is; relative paths are based on the generated file location.
47
- * @default '@tanstack/react-query'
111
+ * @default '@tanstack/vue-query'
48
112
  */
49
113
  importPath?: string
50
114
  }
@@ -52,7 +116,7 @@ type Mutation = {
52
116
  export type Infinite = {
53
117
  /**
54
118
  * Specify the params key used for `pageParam`.
55
- * @default `'id'`
119
+ * @default 'id'
56
120
  */
57
121
  queryParam: string
58
122
  /**
@@ -72,7 +136,7 @@ export type Infinite = {
72
136
  previousParam?: string | string[] | undefined
73
137
  /**
74
138
  * The initial value, the value of the first page.
75
- * @default `0`
139
+ * @default 0
76
140
  */
77
141
  initialPageParam: unknown
78
142
  }
@@ -82,95 +146,100 @@ export type Options = {
82
146
  * Specify the export location for the files and define the behavior of the output
83
147
  * @default { path: 'hooks', barrelType: 'named' }
84
148
  */
85
- output?: Output<Oas>
86
- /**
87
- * Define which contentType should be used.
88
- * By default, the first JSON valid mediaType is used
89
- */
90
- contentType?: contentType
149
+ output?: Output
91
150
  /**
92
151
  * Group the @tanstack/query hooks based on the provided name.
93
152
  */
94
153
  group?: Group
95
154
  client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>
96
155
  /**
97
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
156
+ * Tags, operations, or paths to exclude from generation.
98
157
  */
99
158
  exclude?: Array<Exclude>
100
159
  /**
101
- * Array containing include parameters to include tags/operations/methods/paths.
160
+ * Tags, operations, or paths to include in generation.
102
161
  */
103
162
  include?: Array<Include>
104
163
  /**
105
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
164
+ * Override options for specific tags, operations, or paths.
106
165
  */
107
166
  override?: Array<Override<ResolvedOptions>>
108
167
  /**
109
- * How to style your params, by default no casing is applied
110
- * - 'camelcase' uses camelcase for the params names
168
+ * Apply casing to parameter names.
111
169
  */
112
170
  paramsCasing?: 'camelcase'
113
171
  /**
114
- * How to pass your params
115
- * - 'object' returns the params and pathParams as an object.
116
- * - 'inline' returns the params as comma separated params.
172
+ * How parameters are passed: grouped in an object or spread inline.
173
+ *
117
174
  * @default 'inline'
118
175
  */
119
176
  paramsType?: 'object' | 'inline'
120
177
  /**
121
- * How to pass your pathParams.
122
- * - 'object' returns the pathParams as an object.
123
- * - 'inline': returns the pathParams as comma separated params.
178
+ * How path parameters are passed: grouped in an object or spread inline.
179
+ *
124
180
  * @default 'inline'
125
181
  */
126
182
  pathParamsType?: PluginClient['options']['pathParamsType']
127
183
  /**
128
- * When set, an infiniteQuery hooks is added.
184
+ * Add infinite query hooks.
129
185
  */
130
186
  infinite?: Partial<Infinite> | false
131
187
  queryKey?: QueryKey
132
188
  /**
133
- * Override some useQuery behaviors.
189
+ * Configure useQuery behavior.
134
190
  */
135
191
  query?: Partial<Query> | false
136
192
  mutationKey?: MutationKey
137
193
  /**
138
- * Override some useMutation behaviors.
194
+ * Configure useMutation behavior.
139
195
  */
140
196
  mutation?: Partial<Mutation> | false
141
197
  /**
142
- * Which parser should be used before returning the data to `@tanstack/query`.
143
- * `'zod'` uses `@kubb/plugin-zod` to parse the data.
198
+ * Parser to use for validating response data.
144
199
  */
145
200
  parser?: PluginClient['options']['parser']
146
- transformers?: {
147
- /**
148
- * Customize the names based on the type that is provided by the plugin.
149
- */
150
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
151
- }
152
201
  /**
153
- * Define some generators next to the vue-query generators
202
+ * Override naming conventions for function names and types.
203
+ */
204
+ resolver?: Partial<ResolverVueQuery> & ThisType<ResolverVueQuery>
205
+ /**
206
+ * AST visitor to transform generated nodes.
207
+ */
208
+ transformer?: ast.Visitor
209
+ /**
210
+ * Additional generators alongside the default generators.
154
211
  */
155
212
  generators?: Array<Generator<PluginVueQuery>>
156
213
  }
157
214
 
158
215
  type ResolvedOptions = {
159
- output: Output<Oas>
160
- group: Options['group']
216
+ output: Output
217
+ group: Group | undefined
218
+ exclude: NonNullable<Options['exclude']>
219
+ include: Options['include']
220
+ override: NonNullable<Options['override']>
161
221
  client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>
162
222
  parser: Required<NonNullable<Options['parser']>>
223
+ pathParamsType: NonNullable<Options['pathParamsType']>
163
224
  paramsCasing: Options['paramsCasing']
164
225
  paramsType: NonNullable<Options['paramsType']>
165
- pathParamsType: NonNullable<Options['pathParamsType']>
166
226
  /**
167
- * Only used of infinite
227
+ * Only used for infinite
168
228
  */
169
229
  infinite: NonNullable<Infinite> | false
170
230
  queryKey: QueryKey | undefined
171
231
  query: NonNullable<Required<Query>> | false
172
232
  mutationKey: MutationKey | undefined
173
233
  mutation: NonNullable<Required<Mutation>> | false
234
+ resolver: ResolverVueQuery
174
235
  }
175
236
 
176
- export type PluginVueQuery = PluginFactoryOptions<'plugin-vue-query', Options, ResolvedOptions, never, ResolvePathOptions>
237
+ export type PluginVueQuery = PluginFactoryOptions<'plugin-vue-query', Options, ResolvedOptions, ResolverVueQuery>
238
+
239
+ declare global {
240
+ namespace Kubb {
241
+ interface PluginRegistry {
242
+ 'plugin-vue-query': PluginVueQuery
243
+ }
244
+ }
245
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,49 @@
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'
11
+
12
+ import { ast } from '@kubb/core'
13
+
14
+ export function printType(typeNode: ast.ParamsTypeNode | undefined): string {
15
+ if (!typeNode) return 'unknown'
16
+ if (typeNode.variant === 'reference') return typeNode.name
17
+ if (typeNode.variant === 'member') return `${typeNode.base}['${typeNode.key}']`
18
+ if (typeNode.variant === 'struct') {
19
+ const parts = typeNode.properties.map((p) => {
20
+ const typeStr = printType(p.type)
21
+ const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name)
22
+ return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`
23
+ })
24
+ return `{ ${parts.join('; ')} }`
25
+ }
26
+ return 'unknown'
27
+ }
28
+
29
+ export function wrapWithMaybeRefOrGetter(paramsNode: ast.FunctionParametersNode, skip?: (name: string) => boolean): ast.FunctionParametersNode {
30
+ const wrappedParams = paramsNode.params.map((param) => {
31
+ if ('kind' in param && (param as ast.ParameterGroupNode).kind === 'ParameterGroup') {
32
+ const group = param as ast.ParameterGroupNode
33
+ return {
34
+ ...group,
35
+ properties: group.properties.map((p) => ({
36
+ ...p,
37
+ type: p.type ? ast.createParamsType({ variant: 'reference', name: `MaybeRefOrGetter<${printType(p.type)}>` }) : p.type,
38
+ })),
39
+ }
40
+ }
41
+ const fp = param as ast.FunctionParameterNode
42
+ if (skip?.(fp.name)) return fp
43
+ return {
44
+ ...fp,
45
+ type: fp.type ? ast.createParamsType({ variant: 'reference', name: `MaybeRefOrGetter<${printType(fp.type)}>` }) : fp.type,
46
+ }
47
+ })
48
+ return ast.createFunctionParameters({ params: wrappedParams })
49
+ }