@kubb/plugin-vue-query 5.0.0-alpha.9 → 5.0.0-beta.4
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 +1 -3
- package/dist/components-D1UhYFgY.js +1277 -0
- package/dist/components-D1UhYFgY.js.map +1 -0
- package/dist/components-qfOFRSoM.cjs +1367 -0
- package/dist/components-qfOFRSoM.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +118 -109
- package/dist/components.js +1 -1
- package/dist/generators-C4gs_P1i.cjs +726 -0
- package/dist/generators-C4gs_P1i.cjs.map +1 -0
- package/dist/generators-CbnIVBgY.js +709 -0
- package/dist/generators-CbnIVBgY.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +5 -501
- package/dist/generators.js +1 -1
- package/dist/index.cjs +106 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +102 -121
- package/dist/index.js.map +1 -1
- package/dist/types-nVDTfuS1.d.ts +194 -0
- package/extension.yaml +793 -0
- package/package.json +61 -64
- package/src/components/InfiniteQuery.tsx +104 -153
- package/src/components/InfiniteQueryOptions.tsx +122 -162
- package/src/components/Mutation.tsx +110 -136
- package/src/components/Query.tsx +102 -151
- package/src/components/QueryKey.tsx +68 -58
- package/src/components/QueryOptions.tsx +147 -139
- package/src/generators/infiniteQueryGenerator.tsx +165 -170
- package/src/generators/mutationGenerator.tsx +117 -124
- package/src/generators/queryGenerator.tsx +138 -136
- package/src/index.ts +1 -1
- package/src/plugin.ts +124 -175
- package/src/resolvers/resolverVueQuery.ts +19 -0
- package/src/types.ts +68 -48
- package/src/utils.ts +37 -0
- package/dist/components-Yjoe78Y7.cjs +0 -1119
- package/dist/components-Yjoe78Y7.cjs.map +0 -1
- package/dist/components-_AMBl0g-.js +0 -1029
- package/dist/components-_AMBl0g-.js.map +0 -1
- package/dist/generators-CR34GjVu.js +0 -661
- package/dist/generators-CR34GjVu.js.map +0 -1
- package/dist/generators-DH8VkK1q.cjs +0 -678
- package/dist/generators-DH8VkK1q.cjs.map +0 -1
- package/dist/types-CgDFUvfZ.d.ts +0 -211
|
@@ -1,172 +1,165 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import {
|
|
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/
|
|
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 =
|
|
16
|
-
name: 'vue-query',
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
25
|
-
|
|
19
|
+
const pluginTs = driver.getPlugin(pluginTsName)
|
|
20
|
+
if (!pluginTs) return null
|
|
21
|
+
const tsResolver = driver.getResolver(pluginTsName)
|
|
26
22
|
|
|
27
|
-
const isQuery = !!
|
|
23
|
+
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
28
24
|
const isMutation =
|
|
29
|
-
|
|
25
|
+
mutation !== false &&
|
|
30
26
|
!isQuery &&
|
|
31
|
-
difference(
|
|
27
|
+
difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase())
|
|
32
28
|
|
|
33
|
-
|
|
29
|
+
if (!isMutation) return null
|
|
34
30
|
|
|
35
|
-
const
|
|
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
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
48
|
-
file:
|
|
49
|
-
|
|
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
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
const
|
|
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
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
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={
|
|
79
|
-
path={
|
|
80
|
-
meta={
|
|
81
|
-
banner={
|
|
82
|
-
footer={
|
|
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
|
-
{
|
|
85
|
-
<File.Import name={[
|
|
101
|
+
{parser === 'zod' && fileZod && zodSchemaNames.length > 0 && (
|
|
102
|
+
<File.Import name={zodSchemaNames as string[]} root={meta.file.path} path={fileZod.path} />
|
|
86
103
|
)}
|
|
87
|
-
{
|
|
104
|
+
{clientOptions.importPath ? (
|
|
88
105
|
<>
|
|
89
|
-
{!shouldUseClientPlugin && <File.Import name={'fetch'} path={
|
|
90
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={
|
|
91
|
-
{
|
|
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={
|
|
101
|
-
path={path.resolve(
|
|
115
|
+
root={meta.file.path}
|
|
116
|
+
path={path.resolve(root, '.kubb/fetch.ts')}
|
|
102
117
|
isTypeOnly
|
|
103
118
|
/>
|
|
104
|
-
{
|
|
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={[
|
|
116
|
-
{!shouldUseClientPlugin && (
|
|
117
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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={
|
|
144
|
-
baseURL={
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
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={
|
|
161
|
-
clientName={
|
|
162
|
-
typeName={
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
paramsCasing={
|
|
166
|
-
dataReturnType={
|
|
167
|
-
paramsType={
|
|
168
|
-
pathParamsType={
|
|
169
|
-
mutationKeyName={
|
|
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 {
|
|
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/
|
|
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 =
|
|
12
|
+
export const queryGenerator = defineGenerator<PluginVueQuery>({
|
|
16
13
|
name: 'vue-query',
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
55
|
-
name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),
|
|
56
|
-
}
|
|
29
|
+
if (!isQuery || isMutation) return null
|
|
57
30
|
|
|
58
|
-
const
|
|
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
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
73
|
-
file:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
81
|
-
|
|
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={
|
|
87
|
-
path={
|
|
88
|
-
meta={
|
|
89
|
-
banner={
|
|
90
|
-
footer={
|
|
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
|
-
{
|
|
93
|
-
<File.Import name={[
|
|
102
|
+
{parser === 'zod' && fileZod && zodSchemaNames.length > 0 && (
|
|
103
|
+
<File.Import name={zodSchemaNames as string[]} root={meta.file.path} path={fileZod.path} />
|
|
94
104
|
)}
|
|
95
|
-
{
|
|
105
|
+
{clientOptions.importPath ? (
|
|
96
106
|
<>
|
|
97
|
-
{!shouldUseClientPlugin && <File.Import name={'fetch'} path={
|
|
98
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={
|
|
99
|
-
{
|
|
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={
|
|
109
|
-
path={path.resolve(
|
|
116
|
+
root={meta.file.path}
|
|
117
|
+
path={path.resolve(root, '.kubb/fetch.ts')}
|
|
110
118
|
isTypeOnly
|
|
111
119
|
/>
|
|
112
|
-
{
|
|
113
|
-
<File.Import name={['ResponseConfig']} root={
|
|
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={[
|
|
120
|
-
{!shouldUseClientPlugin && (
|
|
121
|
-
|
|
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
|
-
|
|
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={
|
|
138
|
-
typeName={
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
pathParamsType={
|
|
142
|
-
|
|
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={
|
|
148
|
-
baseURL={
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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={
|
|
162
|
-
clientName={
|
|
163
|
-
queryKeyName={
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
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={
|
|
176
|
-
queryOptionsName={
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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'
|