@kubb/plugin-vue-query 5.0.0-alpha.8 → 5.0.0-beta.3

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 (46) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +1 -3
  3. package/dist/components-D1UhYFgY.js +1277 -0
  4. package/dist/components-D1UhYFgY.js.map +1 -0
  5. package/dist/components-qfOFRSoM.cjs +1367 -0
  6. package/dist/components-qfOFRSoM.cjs.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +118 -109
  9. package/dist/components.js +1 -1
  10. package/dist/generators-C4gs_P1i.cjs +726 -0
  11. package/dist/generators-C4gs_P1i.cjs.map +1 -0
  12. package/dist/generators-CbnIVBgY.js +709 -0
  13. package/dist/generators-CbnIVBgY.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +5 -472
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +106 -121
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +102 -121
  21. package/dist/index.js.map +1 -1
  22. package/dist/types-nVDTfuS1.d.ts +194 -0
  23. package/package.json +61 -64
  24. package/src/components/InfiniteQuery.tsx +104 -153
  25. package/src/components/InfiniteQueryOptions.tsx +122 -162
  26. package/src/components/Mutation.tsx +110 -136
  27. package/src/components/Query.tsx +102 -151
  28. package/src/components/QueryKey.tsx +68 -58
  29. package/src/components/QueryOptions.tsx +147 -139
  30. package/src/generators/infiniteQueryGenerator.tsx +165 -170
  31. package/src/generators/mutationGenerator.tsx +117 -124
  32. package/src/generators/queryGenerator.tsx +138 -136
  33. package/src/index.ts +1 -1
  34. package/src/plugin.ts +124 -175
  35. package/src/resolvers/resolverVueQuery.ts +19 -0
  36. package/src/types.ts +68 -48
  37. package/src/utils.ts +37 -0
  38. package/dist/components-Yjoe78Y7.cjs +0 -1119
  39. package/dist/components-Yjoe78Y7.cjs.map +0 -1
  40. package/dist/components-_AMBl0g-.js +0 -1029
  41. package/dist/components-_AMBl0g-.js.map +0 -1
  42. package/dist/generators-CR34GjVu.js +0 -661
  43. package/dist/generators-CR34GjVu.js.map +0 -1
  44. package/dist/generators-DH8VkK1q.cjs +0 -678
  45. package/dist/generators-DH8VkK1q.cjs.map +0 -1
  46. package/dist/types-CgDFUvfZ.d.ts +0 -211
@@ -1,172 +1,165 @@
1
1
  import path from 'node:path'
2
- import { usePluginDriver } from '@kubb/core/hooks'
3
- import { pluginClientName } from '@kubb/plugin-client'
4
- import { Client } from '@kubb/plugin-client/components'
5
- import { createReactGenerator } from '@kubb/plugin-oas/generators'
6
- import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
7
- import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
2
+ import { ast, defineGenerator } from '@kubb/core'
3
+ import { Client, pluginClientName } from '@kubb/plugin-client'
8
4
  import { pluginTsName } from '@kubb/plugin-ts'
9
5
  import { pluginZodName } from '@kubb/plugin-zod'
10
- import { File } from '@kubb/react-fabric'
6
+ import { File, jsxRenderer } from '@kubb/renderer-jsx'
11
7
  import { difference } from 'remeda'
12
8
  import { Mutation, MutationKey } from '../components'
13
9
  import type { PluginVueQuery } from '../types'
10
+ import { transformName } from '../utils.ts'
14
11
 
15
- export const mutationGenerator = createReactGenerator<PluginVueQuery>({
16
- name: 'vue-query',
17
- Operation({ config, operation, generator, plugin }) {
18
- const {
19
- options,
20
- options: { output },
21
- } = plugin
22
- const driver = usePluginDriver()
12
+ export const mutationGenerator = defineGenerator<PluginVueQuery>({
13
+ name: 'vue-query-mutation',
14
+ renderer: jsxRenderer,
15
+ operation(node, ctx) {
16
+ const { adapter, config, driver, resolver, root } = ctx
17
+ const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, transformers } = ctx.options
23
18
 
24
- const oas = useOas()
25
- const { getSchemas, getName, getFile } = useOperationManager(generator)
19
+ const pluginTs = driver.getPlugin(pluginTsName)
20
+ if (!pluginTs) return null
21
+ const tsResolver = driver.getResolver(pluginTsName)
26
22
 
27
- const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method)
23
+ const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
28
24
  const isMutation =
29
- options.mutation !== false &&
25
+ mutation !== false &&
30
26
  !isQuery &&
31
- difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method)
27
+ difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase())
32
28
 
33
- const importPath = options.mutation ? options.mutation.importPath : '@tanstack/vue-query'
29
+ if (!isMutation) return null
34
30
 
35
- const mutation = {
36
- name: getName(operation, { type: 'function', prefix: 'use' }),
37
- typeName: getName(operation, { type: 'type' }),
38
- file: getFile(operation, { prefix: 'use' }),
39
- }
31
+ const importPath = mutation ? mutation.importPath : '@tanstack/vue-query'
40
32
 
41
- const type = {
42
- file: getFile(operation, { pluginName: pluginTsName }),
43
- //todo remove type?
44
- schemas: getSchemas(operation, { pluginName: pluginTsName, type: 'type' }),
45
- }
33
+ const baseName = resolver.resolveName(node.operationId)
34
+ const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1)
35
+ const mutationHookName = transformName(`use${capitalize(baseName)}`, 'function', transformers)
36
+ const mutationTypeName = transformName(`${capitalize(baseName)}`, 'type', transformers)
37
+ const mutationKeyName = transformName(`${baseName}MutationKey`, 'const', transformers)
38
+ const clientName = transformName(baseName, 'function', transformers)
46
39
 
47
- const zod = {
48
- file: getFile(operation, { pluginName: pluginZodName }),
49
- schemas: getSchemas(operation, { pluginName: pluginZodName, type: 'function' }),
40
+ const meta = {
41
+ file: resolver.resolveFile({ name: mutationHookName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
42
+ fileTs: tsResolver.resolveFile(
43
+ { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
44
+ { root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group },
45
+ ),
50
46
  }
51
47
 
52
- const hasClientPlugin = !!driver.getPluginByName(pluginClientName)
53
- // Class-based clients are not compatible with query hooks, so we generate inline clients
54
- const shouldUseClientPlugin = hasClientPlugin && options.client.clientType !== 'class'
55
- const client = {
56
- name: shouldUseClientPlugin
57
- ? getName(operation, {
58
- type: 'function',
59
- pluginName: pluginClientName,
60
- })
61
- : getName(operation, {
62
- type: 'function',
63
- }),
64
- file: getFile(operation, { pluginName: pluginClientName }),
65
- }
48
+ const casedParams = ast.caseParams(node.parameters, paramsCasing)
49
+ const pathParams = casedParams.filter((p) => p.in === 'path')
50
+ const queryParams = casedParams.filter((p) => p.in === 'query')
51
+ const headerParams = casedParams.filter((p) => p.in === 'header')
66
52
 
67
- const mutationKey = {
68
- name: getName(operation, { type: 'const', suffix: 'MutationKey' }),
69
- typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
70
- }
53
+ const importedTypeNames = [
54
+ node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : undefined,
55
+ tsResolver.resolveResponseName(node),
56
+ ...pathParams.map((p) => tsResolver.resolvePathParamsName(node, p)),
57
+ ...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
58
+ ...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
59
+ ...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode)),
60
+ ].filter((name): name is string => !!name)
71
61
 
72
- if (!isMutation) {
73
- return null
74
- }
62
+ const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : undefined
63
+ const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : undefined
64
+ const fileZod = zodResolver
65
+ ? zodResolver.resolveFile(
66
+ { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
67
+ { root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
68
+ )
69
+ : undefined
70
+ const zodSchemaNames =
71
+ zodResolver && parser === 'zod'
72
+ ? [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : undefined].filter(Boolean)
73
+ : []
74
+
75
+ const clientPlugin = driver.getPlugin(pluginClientName)
76
+ const hasClientPlugin = clientPlugin?.name === pluginClientName
77
+ const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
78
+ const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : undefined
79
+
80
+ const clientFile = shouldUseClientPlugin
81
+ ? clientResolver?.resolveFile(
82
+ { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
83
+ {
84
+ root,
85
+ output: clientPlugin?.options?.output ?? output,
86
+ group: clientPlugin?.options?.group,
87
+ },
88
+ )
89
+ : undefined
90
+
91
+ const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientName) : clientName
75
92
 
76
93
  return (
77
94
  <File
78
- baseName={mutation.file.baseName}
79
- path={mutation.file.path}
80
- meta={mutation.file.meta}
81
- banner={getBanner({ oas, output, config: driver.config })}
82
- footer={getFooter({ oas, output })}
95
+ baseName={meta.file.baseName}
96
+ path={meta.file.path}
97
+ meta={meta.file.meta}
98
+ banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
99
+ footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
83
100
  >
84
- {options.parser === 'zod' && (
85
- <File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={mutation.file.path} path={zod.file.path} />
101
+ {parser === 'zod' && fileZod && zodSchemaNames.length > 0 && (
102
+ <File.Import name={zodSchemaNames as string[]} root={meta.file.path} path={fileZod.path} />
86
103
  )}
87
- {options.client.importPath ? (
104
+ {clientOptions.importPath ? (
88
105
  <>
89
- {!shouldUseClientPlugin && <File.Import name={'fetch'} path={options.client.importPath} />}
90
- <File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />
91
- {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
106
+ {!shouldUseClientPlugin && <File.Import name={'fetch'} path={clientOptions.importPath} />}
107
+ <File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
108
+ {clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
92
109
  </>
93
110
  ) : (
94
111
  <>
95
- {!shouldUseClientPlugin && (
96
- <File.Import name={['fetch']} root={mutation.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />
97
- )}
112
+ {!shouldUseClientPlugin && <File.Import name={['fetch']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} />}
98
113
  <File.Import
99
114
  name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
100
- root={mutation.file.path}
101
- path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}
115
+ root={meta.file.path}
116
+ path={path.resolve(root, '.kubb/fetch.ts')}
102
117
  isTypeOnly
103
118
  />
104
- {options.client.dataReturnType === 'full' && (
105
- <File.Import
106
- name={['ResponseConfig']}
107
- root={mutation.file.path}
108
- path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}
109
- isTypeOnly
110
- />
119
+ {clientOptions.dataReturnType === 'full' && (
120
+ <File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} isTypeOnly />
111
121
  )}
112
122
  </>
113
123
  )}
114
124
  <File.Import name={['MaybeRefOrGetter']} path="vue" isTypeOnly />
115
- {shouldUseClientPlugin && <File.Import name={[client.name]} root={mutation.file.path} path={client.file.path} />}
116
- {!shouldUseClientPlugin && (
117
- <File.Import name={['buildFormData']} root={mutation.file.path} path={path.resolve(config.root, config.output.path, '.kubb/config.ts')} />
125
+ {shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
126
+ {!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
127
+ {meta.fileTs && importedTypeNames.length > 0 && (
128
+ <File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
118
129
  )}
119
- <File.Import
120
- name={[
121
- type.schemas.request?.name,
122
- type.schemas.response.name,
123
- type.schemas.pathParams?.name,
124
- type.schemas.queryParams?.name,
125
- type.schemas.headerParams?.name,
126
- ...(type.schemas.statusCodes?.map((item) => item.name) || []),
127
- ].filter(Boolean)}
128
- root={mutation.file.path}
129
- path={type.file.path}
130
- isTypeOnly
131
- />
132
- <MutationKey
133
- name={mutationKey.name}
134
- typeName={mutationKey.typeName}
135
- operation={operation}
136
- pathParamsType={options.pathParamsType}
137
- paramsCasing={options.paramsCasing}
138
- typeSchemas={type.schemas}
139
- transformer={options.mutationKey}
140
- />
130
+
131
+ <MutationKey name={mutationKeyName} node={node} pathParamsType={pathParamsType} paramsCasing={paramsCasing} transformer={ctx.options.mutationKey} />
132
+
141
133
  {!shouldUseClientPlugin && (
142
134
  <Client
143
- name={client.name}
144
- baseURL={options.client.baseURL}
145
- operation={operation}
146
- typeSchemas={type.schemas}
147
- zodSchemas={zod.schemas}
148
- dataReturnType={options.client.dataReturnType || 'data'}
149
- paramsCasing={options.client?.paramsCasing || options.paramsCasing}
150
- paramsType={options.paramsType}
151
- pathParamsType={options.pathParamsType}
152
- parser={options.parser}
135
+ name={resolvedClientName}
136
+ baseURL={clientOptions.baseURL}
137
+ dataReturnType={clientOptions.dataReturnType || 'data'}
138
+ paramsCasing={clientOptions.paramsCasing || paramsCasing}
139
+ paramsType={paramsType}
140
+ pathParamsType={pathParamsType}
141
+ parser={parser}
142
+ node={node}
143
+ tsResolver={tsResolver}
144
+ zodResolver={zodResolver}
153
145
  />
154
146
  )}
155
- {options.mutation && (
147
+
148
+ {mutation && (
156
149
  <>
157
150
  <File.Import name={['useMutation']} path={importPath} />
158
151
  <File.Import name={['MutationObserverOptions', 'QueryClient']} path={importPath} isTypeOnly />
159
152
  <Mutation
160
- name={mutation.name}
161
- clientName={client.name}
162
- typeName={mutation.typeName}
163
- typeSchemas={type.schemas}
164
- operation={operation}
165
- paramsCasing={options.paramsCasing}
166
- dataReturnType={options.client.dataReturnType || 'data'}
167
- paramsType={options.paramsType}
168
- pathParamsType={options.pathParamsType}
169
- mutationKeyName={mutationKey.name}
153
+ name={mutationHookName}
154
+ clientName={resolvedClientName}
155
+ typeName={mutationTypeName}
156
+ node={node}
157
+ tsResolver={tsResolver}
158
+ paramsCasing={paramsCasing}
159
+ dataReturnType={clientOptions.dataReturnType || 'data'}
160
+ paramsType={paramsType}
161
+ pathParamsType={pathParamsType}
162
+ mutationKeyName={mutationKeyName}
170
163
  />
171
164
  </>
172
165
  )}
@@ -1,187 +1,189 @@
1
1
  import path from 'node:path'
2
- import { usePluginDriver } from '@kubb/core/hooks'
3
- import { pluginClientName } from '@kubb/plugin-client'
4
- import { Client } from '@kubb/plugin-client/components'
5
- import { createReactGenerator } from '@kubb/plugin-oas/generators'
6
- import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
7
- import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
2
+ import { ast, defineGenerator } from '@kubb/core'
3
+ import { Client, pluginClientName } from '@kubb/plugin-client'
8
4
  import { pluginTsName } from '@kubb/plugin-ts'
9
5
  import { pluginZodName } from '@kubb/plugin-zod'
10
- import { File } from '@kubb/react-fabric'
6
+ import { File, jsxRenderer } from '@kubb/renderer-jsx'
11
7
  import { difference } from 'remeda'
12
8
  import { Query, QueryKey, QueryOptions } from '../components'
13
9
  import type { PluginVueQuery } from '../types'
10
+ import { transformName } from '../utils.ts'
14
11
 
15
- export const queryGenerator = createReactGenerator<PluginVueQuery>({
12
+ export const queryGenerator = defineGenerator<PluginVueQuery>({
16
13
  name: 'vue-query',
17
- Operation({ config, operation, generator, plugin }) {
18
- const {
19
- options,
20
- options: { output },
21
- } = plugin
22
- const driver = usePluginDriver()
23
-
24
- const oas = useOas()
25
- const { getSchemas, getName, getFile } = useOperationManager(generator)
26
-
27
- const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
28
- const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some(
29
- (method) => operation.method === method,
30
- )
31
- const importPath = options.query ? options.query.importPath : '@tanstack/vue-query'
14
+ renderer: jsxRenderer,
15
+ operation(node, ctx) {
16
+ const { adapter, config, driver, resolver, root } = ctx
17
+ const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, transformers } = ctx.options
32
18
 
33
- const query = {
34
- name: getName(operation, { type: 'function', prefix: 'use' }),
35
- typeName: getName(operation, { type: 'type' }),
36
- file: getFile(operation, { prefix: 'use' }),
37
- }
19
+ const pluginTs = driver.getPlugin(pluginTsName)
20
+ if (!pluginTs) return null
21
+ const tsResolver = driver.getResolver(pluginTsName)
38
22
 
39
- const hasClientPlugin = !!driver.getPluginByName(pluginClientName)
40
- // Class-based clients are not compatible with query hooks, so we generate inline clients
41
- const shouldUseClientPlugin = hasClientPlugin && options.client.clientType !== 'class'
42
- const client = {
43
- name: shouldUseClientPlugin
44
- ? getName(operation, {
45
- type: 'function',
46
- pluginName: pluginClientName,
47
- })
48
- : getName(operation, {
49
- type: 'function',
50
- }),
51
- file: getFile(operation, { pluginName: pluginClientName }),
52
- }
23
+ const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
24
+ const isMutation =
25
+ mutation !== false &&
26
+ !isQuery &&
27
+ difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase())
53
28
 
54
- const queryOptions = {
55
- name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),
56
- }
29
+ if (!isQuery || isMutation) return null
57
30
 
58
- const queryKey = {
59
- name: getName(operation, { type: 'const', suffix: 'QueryKey' }),
60
- typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),
61
- }
31
+ const importPath = query ? query.importPath : '@tanstack/vue-query'
62
32
 
63
- const type = {
64
- file: getFile(operation, { pluginName: pluginTsName }),
65
- //todo remove type?
66
- schemas: getSchemas(operation, {
67
- pluginName: pluginTsName,
68
- type: 'type',
69
- }),
70
- }
33
+ const baseName = resolver.resolveName(node.operationId)
34
+ const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1)
35
+ const queryName = transformName(`use${capitalize(baseName)}`, 'function', transformers)
36
+ const queryOptionsName = transformName(`${baseName}QueryOptions`, 'function', transformers)
37
+ const queryKeyName = transformName(`${baseName}QueryKey`, 'const', transformers)
38
+ const queryKeyTypeName = transformName(`${capitalize(baseName)}QueryKey`, 'type', transformers)
39
+ const clientName = transformName(baseName, 'function', transformers)
71
40
 
72
- const zod = {
73
- file: getFile(operation, { pluginName: pluginZodName }),
74
- schemas: getSchemas(operation, {
75
- pluginName: pluginZodName,
76
- type: 'function',
77
- }),
41
+ const meta = {
42
+ file: resolver.resolveFile({ name: queryName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
43
+ fileTs: tsResolver.resolveFile(
44
+ { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
45
+ { root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group },
46
+ ),
78
47
  }
79
48
 
80
- if (!isQuery || isMutation) {
81
- return null
82
- }
49
+ const casedParams = ast.caseParams(node.parameters, paramsCasing)
50
+ const pathParams = casedParams.filter((p) => p.in === 'path')
51
+ const queryParams = casedParams.filter((p) => p.in === 'query')
52
+ const headerParams = casedParams.filter((p) => p.in === 'header')
53
+
54
+ const importedTypeNames = [
55
+ node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : undefined,
56
+ tsResolver.resolveResponseName(node),
57
+ ...pathParams.map((p) => tsResolver.resolvePathParamsName(node, p)),
58
+ ...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
59
+ ...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
60
+ ...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode)),
61
+ ].filter((name): name is string => !!name && name !== queryKeyTypeName)
62
+
63
+ const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : undefined
64
+ const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : undefined
65
+ const fileZod = zodResolver
66
+ ? zodResolver.resolveFile(
67
+ { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
68
+ { root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
69
+ )
70
+ : undefined
71
+ const zodSchemaNames =
72
+ zodResolver && parser === 'zod'
73
+ ? [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : undefined].filter(Boolean)
74
+ : []
75
+
76
+ const clientPlugin = driver.getPlugin(pluginClientName)
77
+ const hasClientPlugin = clientPlugin?.name === pluginClientName
78
+ const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
79
+ const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : undefined
80
+
81
+ const clientFile = shouldUseClientPlugin
82
+ ? clientResolver?.resolveFile(
83
+ { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
84
+ {
85
+ root,
86
+ output: clientPlugin?.options?.output ?? output,
87
+ group: clientPlugin?.options?.group,
88
+ },
89
+ )
90
+ : undefined
91
+
92
+ const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientName) : clientName
83
93
 
84
94
  return (
85
95
  <File
86
- baseName={query.file.baseName}
87
- path={query.file.path}
88
- meta={query.file.meta}
89
- banner={getBanner({ oas, output, config: driver.config })}
90
- footer={getFooter({ oas, output })}
96
+ baseName={meta.file.baseName}
97
+ path={meta.file.path}
98
+ meta={meta.file.meta}
99
+ banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
100
+ footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
91
101
  >
92
- {options.parser === 'zod' && (
93
- <File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={query.file.path} path={zod.file.path} />
102
+ {parser === 'zod' && fileZod && zodSchemaNames.length > 0 && (
103
+ <File.Import name={zodSchemaNames as string[]} root={meta.file.path} path={fileZod.path} />
94
104
  )}
95
- {options.client.importPath ? (
105
+ {clientOptions.importPath ? (
96
106
  <>
97
- {!shouldUseClientPlugin && <File.Import name={'fetch'} path={options.client.importPath} />}
98
- <File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />
99
- {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
107
+ {!shouldUseClientPlugin && <File.Import name={'fetch'} path={clientOptions.importPath} />}
108
+ <File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
109
+ {clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
100
110
  </>
101
111
  ) : (
102
112
  <>
103
- {!shouldUseClientPlugin && (
104
- <File.Import name={['fetch']} root={query.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />
105
- )}
113
+ {!shouldUseClientPlugin && <File.Import name={['fetch']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} />}
106
114
  <File.Import
107
115
  name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
108
- root={query.file.path}
109
- path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}
116
+ root={meta.file.path}
117
+ path={path.resolve(root, '.kubb/fetch.ts')}
110
118
  isTypeOnly
111
119
  />
112
- {options.client.dataReturnType === 'full' && (
113
- <File.Import name={['ResponseConfig']} root={query.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} isTypeOnly />
120
+ {clientOptions.dataReturnType === 'full' && (
121
+ <File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} isTypeOnly />
114
122
  )}
115
123
  </>
116
124
  )}
117
125
  <File.Import name={['toValue']} path="vue" />
118
126
  <File.Import name={['MaybeRefOrGetter']} path="vue" isTypeOnly />
119
- {shouldUseClientPlugin && <File.Import name={[client.name]} root={query.file.path} path={client.file.path} />}
120
- {!shouldUseClientPlugin && (
121
- <File.Import name={['buildFormData']} root={query.file.path} path={path.resolve(config.root, config.output.path, '.kubb/config.ts')} />
127
+ {shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
128
+ {!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
129
+ {meta.fileTs && importedTypeNames.length > 0 && (
130
+ <File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
122
131
  )}
123
- <File.Import
124
- name={[
125
- type.schemas.request?.name,
126
- type.schemas.response.name,
127
- type.schemas.pathParams?.name,
128
- type.schemas.queryParams?.name,
129
- type.schemas.headerParams?.name,
130
- ...(type.schemas.statusCodes?.map((item) => item.name) || []),
131
- ].filter(Boolean)}
132
- root={query.file.path}
133
- path={type.file.path}
134
- isTypeOnly
135
- />
132
+
136
133
  <QueryKey
137
- name={queryKey.name}
138
- typeName={queryKey.typeName}
139
- operation={operation}
140
- paramsCasing={options.paramsCasing}
141
- pathParamsType={options.pathParamsType}
142
- typeSchemas={type.schemas}
143
- transformer={options.queryKey}
134
+ name={queryKeyName}
135
+ typeName={queryKeyTypeName}
136
+ node={node}
137
+ tsResolver={tsResolver}
138
+ pathParamsType={pathParamsType}
139
+ paramsCasing={paramsCasing}
140
+ transformer={ctx.options.queryKey}
144
141
  />
142
+
145
143
  {!shouldUseClientPlugin && (
146
144
  <Client
147
- name={client.name}
148
- baseURL={options.client.baseURL}
149
- operation={operation}
150
- typeSchemas={type.schemas}
151
- zodSchemas={zod.schemas}
152
- dataReturnType={options.client.dataReturnType || 'data'}
153
- paramsCasing={options.client?.paramsCasing || options.paramsCasing}
154
- paramsType={options.paramsType}
155
- pathParamsType={options.pathParamsType}
156
- parser={options.parser}
145
+ name={resolvedClientName}
146
+ baseURL={clientOptions.baseURL}
147
+ dataReturnType={clientOptions.dataReturnType || 'data'}
148
+ paramsCasing={clientOptions.paramsCasing || paramsCasing}
149
+ paramsType={paramsType}
150
+ pathParamsType={pathParamsType}
151
+ parser={parser}
152
+ node={node}
153
+ tsResolver={tsResolver}
154
+ zodResolver={zodResolver}
157
155
  />
158
156
  )}
157
+
159
158
  <File.Import name={['queryOptions']} path={importPath} />
159
+
160
160
  <QueryOptions
161
- name={queryOptions.name}
162
- clientName={client.name}
163
- queryKeyName={queryKey.name}
164
- paramsCasing={options.paramsCasing}
165
- typeSchemas={type.schemas}
166
- paramsType={options.paramsType}
167
- pathParamsType={options.pathParamsType}
168
- dataReturnType={options.client.dataReturnType || 'data'}
161
+ name={queryOptionsName}
162
+ clientName={resolvedClientName}
163
+ queryKeyName={queryKeyName}
164
+ node={node}
165
+ tsResolver={tsResolver}
166
+ paramsCasing={paramsCasing}
167
+ paramsType={paramsType}
168
+ pathParamsType={pathParamsType}
169
+ dataReturnType={clientOptions.dataReturnType || 'data'}
169
170
  />
170
- {options.query && (
171
+
172
+ {query && (
171
173
  <>
172
174
  <File.Import name={['useQuery']} path={importPath} />
173
175
  <File.Import name={['QueryKey', 'QueryClient', 'UseQueryOptions', 'UseQueryReturnType']} path={importPath} isTypeOnly />
174
176
  <Query
175
- name={query.name}
176
- queryOptionsName={queryOptions.name}
177
- typeSchemas={type.schemas}
178
- paramsCasing={options.paramsCasing}
179
- paramsType={options.paramsType}
180
- pathParamsType={options.pathParamsType}
181
- operation={operation}
182
- dataReturnType={options.client.dataReturnType || 'data'}
183
- queryKeyName={queryKey.name}
184
- queryKeyTypeName={queryKey.typeName}
177
+ name={queryName}
178
+ queryOptionsName={queryOptionsName}
179
+ queryKeyName={queryKeyName}
180
+ queryKeyTypeName={queryKeyTypeName}
181
+ node={node}
182
+ tsResolver={tsResolver}
183
+ paramsCasing={paramsCasing}
184
+ paramsType={paramsType}
185
+ pathParamsType={pathParamsType}
186
+ dataReturnType={clientOptions.dataReturnType || 'data'}
185
187
  />
186
188
  </>
187
189
  )}
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { pluginVueQuery, pluginVueQueryName } from './plugin.ts'
1
+ export { default, pluginVueQuery, pluginVueQueryName } from './plugin.ts'
2
2
  export type { PluginVueQuery } from './types.ts'