@kubb/plugin-vue-query 5.0.0-alpha.8 → 5.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -10
- package/README.md +26 -7
- package/dist/components-B6jAb2as.js +1150 -0
- package/dist/components-B6jAb2as.js.map +1 -0
- package/dist/components-X0P-3W2G.cjs +1264 -0
- package/dist/components-X0P-3W2G.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +66 -121
- package/dist/components.js +1 -1
- package/dist/generators-B33PbKzu.js +681 -0
- package/dist/generators-B33PbKzu.js.map +1 -0
- package/dist/generators-BE3KD0IR.cjs +698 -0
- package/dist/generators-BE3KD0IR.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +5 -472
- package/dist/generators.js +1 -1
- package/dist/index.cjs +150 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +146 -121
- package/dist/index.js.map +1 -1
- package/dist/types-Bkm7bWT3.d.ts +243 -0
- package/extension.yaml +732 -0
- package/package.json +60 -65
- package/src/components/InfiniteQuery.tsx +71 -159
- package/src/components/InfiniteQueryOptions.tsx +115 -163
- package/src/components/Mutation.tsx +97 -134
- package/src/components/Query.tsx +68 -157
- package/src/components/QueryKey.tsx +23 -66
- package/src/components/QueryOptions.tsx +92 -143
- package/src/generators/infiniteQueryGenerator.tsx +152 -171
- package/src/generators/mutationGenerator.tsx +102 -125
- package/src/generators/queryGenerator.tsx +125 -137
- package/src/index.ts +1 -1
- package/src/plugin.ts +126 -177
- package/src/resolvers/resolverVueQuery.ts +65 -0
- package/src/types.ts +121 -52
- package/src/utils.ts +49 -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,187 +1,175 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
7
|
-
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
2
|
+
import { resolveOperationTypeNames } from '@internals/shared'
|
|
3
|
+
import { resolveZodSchemaNames } from '@internals/tanstack-query'
|
|
4
|
+
import { defineGenerator } from '@kubb/core'
|
|
5
|
+
import { Client, pluginClientName } from '@kubb/plugin-client'
|
|
8
6
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
9
7
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
10
|
-
import { File } from '@kubb/
|
|
8
|
+
import { File, jsxRenderer } from '@kubb/renderer-jsx'
|
|
11
9
|
import { difference } from 'remeda'
|
|
12
10
|
import { Query, QueryKey, QueryOptions } from '../components'
|
|
13
11
|
import type { PluginVueQuery } from '../types'
|
|
14
12
|
|
|
15
|
-
export const queryGenerator =
|
|
13
|
+
export const queryGenerator = defineGenerator<PluginVueQuery>({
|
|
16
14
|
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'
|
|
15
|
+
renderer: jsxRenderer,
|
|
16
|
+
operation(node, ctx) {
|
|
17
|
+
const { adapter, config, driver, resolver, root } = ctx
|
|
18
|
+
const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group } = ctx.options
|
|
32
19
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
file: getFile(operation, { prefix: 'use' }),
|
|
37
|
-
}
|
|
20
|
+
const pluginTs = driver.getPlugin(pluginTsName)
|
|
21
|
+
if (!pluginTs) return null
|
|
22
|
+
const tsResolver = driver.getResolver(pluginTsName)
|
|
38
23
|
|
|
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
|
-
}
|
|
24
|
+
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
25
|
+
const isMutation =
|
|
26
|
+
mutation !== false &&
|
|
27
|
+
!isQuery &&
|
|
28
|
+
difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase())
|
|
53
29
|
|
|
54
|
-
|
|
55
|
-
name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),
|
|
56
|
-
}
|
|
30
|
+
if (!isQuery || isMutation) return null
|
|
57
31
|
|
|
58
|
-
const
|
|
59
|
-
name: getName(operation, { type: 'const', suffix: 'QueryKey' }),
|
|
60
|
-
typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),
|
|
61
|
-
}
|
|
32
|
+
const importPath = query ? query.importPath : '@tanstack/vue-query'
|
|
62
33
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
type: 'type',
|
|
69
|
-
}),
|
|
70
|
-
}
|
|
34
|
+
const queryName = resolver.resolveQueryName(node)
|
|
35
|
+
const queryOptionsName = resolver.resolveQueryOptionsName(node)
|
|
36
|
+
const queryKeyName = resolver.resolveQueryKeyName(node)
|
|
37
|
+
const queryKeyTypeName = resolver.resolveQueryKeyTypeName(node)
|
|
38
|
+
const clientName = resolver.resolveClientName(node)
|
|
71
39
|
|
|
72
|
-
const
|
|
73
|
-
file:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
40
|
+
const meta = {
|
|
41
|
+
file: resolver.resolveFile({ name: queryName, 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
|
+
),
|
|
78
46
|
}
|
|
79
47
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
48
|
+
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
49
|
+
paramsCasing,
|
|
50
|
+
exclude: [queryKeyTypeName],
|
|
51
|
+
order: 'body-response-first',
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : undefined
|
|
55
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : undefined
|
|
56
|
+
const fileZod = zodResolver
|
|
57
|
+
? zodResolver.resolveFile(
|
|
58
|
+
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
59
|
+
{ root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
|
|
60
|
+
)
|
|
61
|
+
: undefined
|
|
62
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
|
|
63
|
+
|
|
64
|
+
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
65
|
+
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
66
|
+
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
67
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : undefined
|
|
68
|
+
|
|
69
|
+
const clientFile = shouldUseClientPlugin
|
|
70
|
+
? clientResolver?.resolveFile(
|
|
71
|
+
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
72
|
+
{
|
|
73
|
+
root,
|
|
74
|
+
output: clientPlugin?.options?.output ?? output,
|
|
75
|
+
group: clientPlugin?.options?.group,
|
|
76
|
+
},
|
|
77
|
+
)
|
|
78
|
+
: undefined
|
|
79
|
+
|
|
80
|
+
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientName) : clientName
|
|
83
81
|
|
|
84
82
|
return (
|
|
85
83
|
<File
|
|
86
|
-
baseName={
|
|
87
|
-
path={
|
|
88
|
-
meta={
|
|
89
|
-
banner={
|
|
90
|
-
footer={
|
|
84
|
+
baseName={meta.file.baseName}
|
|
85
|
+
path={meta.file.path}
|
|
86
|
+
meta={meta.file.meta}
|
|
87
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
88
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
91
89
|
>
|
|
92
|
-
{
|
|
93
|
-
|
|
94
|
-
)}
|
|
95
|
-
{options.client.importPath ? (
|
|
90
|
+
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
91
|
+
{clientOptions.importPath ? (
|
|
96
92
|
<>
|
|
97
|
-
{!shouldUseClientPlugin && <File.Import name={'fetch'} path={
|
|
98
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={
|
|
99
|
-
{
|
|
93
|
+
{!shouldUseClientPlugin && <File.Import name={'fetch'} path={clientOptions.importPath} />}
|
|
94
|
+
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
95
|
+
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
100
96
|
</>
|
|
101
97
|
) : (
|
|
102
98
|
<>
|
|
103
|
-
{!shouldUseClientPlugin && (
|
|
104
|
-
<File.Import name={['fetch']} root={query.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />
|
|
105
|
-
)}
|
|
99
|
+
{!shouldUseClientPlugin && <File.Import name={['fetch']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} />}
|
|
106
100
|
<File.Import
|
|
107
101
|
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
108
|
-
root={
|
|
109
|
-
path={path.resolve(
|
|
102
|
+
root={meta.file.path}
|
|
103
|
+
path={path.resolve(root, '.kubb/fetch.ts')}
|
|
110
104
|
isTypeOnly
|
|
111
105
|
/>
|
|
112
|
-
{
|
|
113
|
-
<File.Import name={['ResponseConfig']} root={
|
|
106
|
+
{clientOptions.dataReturnType === 'full' && (
|
|
107
|
+
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} isTypeOnly />
|
|
114
108
|
)}
|
|
115
109
|
</>
|
|
116
110
|
)}
|
|
117
111
|
<File.Import name={['toValue']} path="vue" />
|
|
118
112
|
<File.Import name={['MaybeRefOrGetter']} path="vue" isTypeOnly />
|
|
119
|
-
{shouldUseClientPlugin && <File.Import name={[
|
|
120
|
-
{!shouldUseClientPlugin && (
|
|
121
|
-
|
|
113
|
+
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
114
|
+
{!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
|
|
115
|
+
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
116
|
+
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
122
117
|
)}
|
|
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
|
-
/>
|
|
118
|
+
|
|
136
119
|
<QueryKey
|
|
137
|
-
name={
|
|
138
|
-
typeName={
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
pathParamsType={
|
|
142
|
-
|
|
143
|
-
transformer={options.queryKey}
|
|
120
|
+
name={queryKeyName}
|
|
121
|
+
typeName={queryKeyTypeName}
|
|
122
|
+
node={node}
|
|
123
|
+
tsResolver={tsResolver}
|
|
124
|
+
pathParamsType={pathParamsType}
|
|
125
|
+
paramsCasing={paramsCasing}
|
|
126
|
+
transformer={ctx.options.queryKey}
|
|
144
127
|
/>
|
|
128
|
+
|
|
145
129
|
{!shouldUseClientPlugin && (
|
|
146
130
|
<Client
|
|
147
|
-
name={
|
|
148
|
-
baseURL={
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
131
|
+
name={resolvedClientName}
|
|
132
|
+
baseURL={clientOptions.baseURL}
|
|
133
|
+
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
134
|
+
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
135
|
+
paramsType={paramsType}
|
|
136
|
+
pathParamsType={pathParamsType}
|
|
137
|
+
parser={parser}
|
|
138
|
+
node={node}
|
|
139
|
+
tsResolver={tsResolver}
|
|
140
|
+
zodResolver={zodResolver}
|
|
157
141
|
/>
|
|
158
142
|
)}
|
|
143
|
+
|
|
159
144
|
<File.Import name={['queryOptions']} path={importPath} />
|
|
145
|
+
|
|
160
146
|
<QueryOptions
|
|
161
|
-
name={
|
|
162
|
-
clientName={
|
|
163
|
-
queryKeyName={
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
147
|
+
name={queryOptionsName}
|
|
148
|
+
clientName={resolvedClientName}
|
|
149
|
+
queryKeyName={queryKeyName}
|
|
150
|
+
node={node}
|
|
151
|
+
tsResolver={tsResolver}
|
|
152
|
+
paramsCasing={paramsCasing}
|
|
153
|
+
paramsType={paramsType}
|
|
154
|
+
pathParamsType={pathParamsType}
|
|
155
|
+
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
169
156
|
/>
|
|
170
|
-
|
|
157
|
+
|
|
158
|
+
{query && (
|
|
171
159
|
<>
|
|
172
160
|
<File.Import name={['useQuery']} path={importPath} />
|
|
173
161
|
<File.Import name={['QueryKey', 'QueryClient', 'UseQueryOptions', 'UseQueryReturnType']} path={importPath} isTypeOnly />
|
|
174
162
|
<Query
|
|
175
|
-
name={
|
|
176
|
-
queryOptionsName={
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
163
|
+
name={queryName}
|
|
164
|
+
queryOptionsName={queryOptionsName}
|
|
165
|
+
queryKeyName={queryKeyName}
|
|
166
|
+
queryKeyTypeName={queryKeyTypeName}
|
|
167
|
+
node={node}
|
|
168
|
+
tsResolver={tsResolver}
|
|
169
|
+
paramsCasing={paramsCasing}
|
|
170
|
+
paramsType={paramsType}
|
|
171
|
+
pathParamsType={pathParamsType}
|
|
172
|
+
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
185
173
|
/>
|
|
186
174
|
</>
|
|
187
175
|
)}
|
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'
|
package/src/plugin.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import { camelCase
|
|
3
|
-
import {
|
|
2
|
+
import { camelCase } from '@internals/utils'
|
|
3
|
+
import { ast, definePlugin, type Group } from '@kubb/core'
|
|
4
4
|
import { pluginClientName } from '@kubb/plugin-client'
|
|
5
5
|
import { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'
|
|
6
6
|
import { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'
|
|
7
7
|
import { source as configSource } from '@kubb/plugin-client/templates/config.source'
|
|
8
|
-
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
9
8
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
10
9
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
11
|
-
import {
|
|
10
|
+
import { mutationKeyTransformer } from '@internals/tanstack-query'
|
|
11
|
+
import { queryKeyTransformer } from '@internals/tanstack-query'
|
|
12
12
|
import { infiniteQueryGenerator, mutationGenerator, queryGenerator } from './generators'
|
|
13
|
+
import { resolverVueQuery } from './resolvers/resolverVueQuery.ts'
|
|
13
14
|
import type { PluginVueQuery } from './types.ts'
|
|
14
15
|
|
|
15
16
|
export const pluginVueQueryName = 'plugin-vue-query' satisfies PluginVueQuery['name']
|
|
16
17
|
|
|
17
|
-
export const pluginVueQuery =
|
|
18
|
+
export const pluginVueQuery = definePlugin<PluginVueQuery>((options) => {
|
|
18
19
|
const {
|
|
19
20
|
output = { path: 'hooks', barrelType: 'named' },
|
|
20
21
|
group,
|
|
@@ -22,197 +23,145 @@ export const pluginVueQuery = createPlugin<PluginVueQuery>((options) => {
|
|
|
22
23
|
include,
|
|
23
24
|
override = [],
|
|
24
25
|
parser = 'client',
|
|
25
|
-
infinite,
|
|
26
|
-
transformers = {},
|
|
26
|
+
infinite = false,
|
|
27
27
|
paramsType = 'inline',
|
|
28
28
|
pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',
|
|
29
29
|
mutation = {},
|
|
30
30
|
query = {},
|
|
31
|
+
mutationKey = mutationKeyTransformer,
|
|
32
|
+
queryKey = queryKeyTransformer,
|
|
31
33
|
paramsCasing,
|
|
32
|
-
mutationKey = MutationKey.getTransformer,
|
|
33
|
-
queryKey = QueryKey.getTransformer,
|
|
34
|
-
generators = [queryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),
|
|
35
|
-
contentType,
|
|
36
34
|
client,
|
|
35
|
+
resolver: userResolver,
|
|
36
|
+
transformer: userTransformer,
|
|
37
|
+
generators: userGenerators = [],
|
|
37
38
|
} = options
|
|
38
39
|
|
|
39
40
|
const clientName = client?.client ?? 'axios'
|
|
40
41
|
const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
output,
|
|
46
|
-
client: {
|
|
47
|
-
bundle: client?.bundle,
|
|
48
|
-
baseURL: client?.baseURL,
|
|
49
|
-
client: clientName,
|
|
50
|
-
clientType: client?.clientType ?? 'function',
|
|
51
|
-
dataReturnType: client?.dataReturnType ?? 'data',
|
|
52
|
-
pathParamsType,
|
|
53
|
-
importPath: clientImportPath,
|
|
54
|
-
paramsCasing,
|
|
55
|
-
},
|
|
56
|
-
infinite: infinite
|
|
57
|
-
? {
|
|
58
|
-
queryParam: 'id',
|
|
59
|
-
initialPageParam: 0,
|
|
60
|
-
cursorParam: undefined,
|
|
61
|
-
nextParam: undefined,
|
|
62
|
-
previousParam: undefined,
|
|
63
|
-
...infinite,
|
|
64
|
-
}
|
|
65
|
-
: false,
|
|
66
|
-
queryKey,
|
|
67
|
-
query:
|
|
68
|
-
query === false
|
|
69
|
-
? false
|
|
70
|
-
: {
|
|
71
|
-
methods: ['get'],
|
|
72
|
-
importPath: '@tanstack/vue-query',
|
|
73
|
-
...query,
|
|
74
|
-
},
|
|
75
|
-
mutationKey,
|
|
76
|
-
mutation:
|
|
77
|
-
mutation === false
|
|
78
|
-
? false
|
|
79
|
-
: {
|
|
80
|
-
methods: ['post', 'put', 'patch', 'delete'],
|
|
81
|
-
importPath: '@tanstack/vue-query',
|
|
82
|
-
...mutation,
|
|
83
|
-
},
|
|
84
|
-
paramsType,
|
|
85
|
-
pathParamsType,
|
|
86
|
-
parser,
|
|
87
|
-
paramsCasing,
|
|
88
|
-
group,
|
|
89
|
-
},
|
|
90
|
-
pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
|
91
|
-
resolvePath(baseName, pathMode, options) {
|
|
92
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
93
|
-
const mode = pathMode ?? getMode(path.resolve(root, output.path))
|
|
43
|
+
const selectedGenerators =
|
|
44
|
+
options.generators ??
|
|
45
|
+
[queryGenerator, infiniteQueryGenerator, mutationGenerator].filter((generator): generator is NonNullable<typeof generator> => Boolean(generator))
|
|
94
46
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*/
|
|
100
|
-
return path.resolve(root, output.path)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (group && (options?.group?.path || options?.group?.tag)) {
|
|
104
|
-
const groupName: Group['name'] = group?.name
|
|
47
|
+
const groupConfig = group
|
|
48
|
+
? ({
|
|
49
|
+
...group,
|
|
50
|
+
name: group.name
|
|
105
51
|
? group.name
|
|
106
|
-
: (ctx) => {
|
|
107
|
-
if (group
|
|
52
|
+
: (ctx: { group: string }) => {
|
|
53
|
+
if (group.type === 'path') {
|
|
108
54
|
return `${ctx.group.split('/')[1]}`
|
|
109
55
|
}
|
|
110
56
|
return `${camelCase(ctx.group)}Controller`
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return path.resolve(
|
|
114
|
-
root,
|
|
115
|
-
output.path,
|
|
116
|
-
groupName({
|
|
117
|
-
group: group.type === 'path' ? options.group.path! : options.group.tag!,
|
|
118
|
-
}),
|
|
119
|
-
baseName,
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return path.resolve(root, output.path, baseName)
|
|
124
|
-
},
|
|
125
|
-
resolveName(name, type) {
|
|
126
|
-
let resolvedName = camelCase(name)
|
|
127
|
-
|
|
128
|
-
if (type === 'file' || type === 'function') {
|
|
129
|
-
resolvedName = camelCase(name, {
|
|
130
|
-
isFile: type === 'file',
|
|
131
|
-
})
|
|
132
|
-
}
|
|
133
|
-
if (type === 'type') {
|
|
134
|
-
resolvedName = pascalCase(name)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (type) {
|
|
138
|
-
return transformers?.name?.(resolvedName, type) || resolvedName
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return resolvedName
|
|
142
|
-
},
|
|
143
|
-
async install() {
|
|
144
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
145
|
-
const mode = getMode(path.resolve(root, output.path))
|
|
146
|
-
const oas = await this.getOas()
|
|
147
|
-
const baseURL = await this.getBaseURL()
|
|
148
|
-
|
|
149
|
-
if (baseURL) {
|
|
150
|
-
this.plugin.options.client.baseURL = baseURL
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const hasClientPlugin = !!this.driver.getPluginByName(pluginClientName)
|
|
154
|
-
|
|
155
|
-
if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {
|
|
156
|
-
// pre add bundled
|
|
157
|
-
await this.upsertFile({
|
|
158
|
-
baseName: 'fetch.ts',
|
|
159
|
-
path: path.resolve(root, '.kubb/fetch.ts'),
|
|
160
|
-
sources: [
|
|
161
|
-
{
|
|
162
|
-
name: 'fetch',
|
|
163
|
-
value: this.plugin.options.client.client === 'fetch' ? fetchClientSource : axiosClientSource,
|
|
164
|
-
isExportable: true,
|
|
165
|
-
isIndexable: true,
|
|
166
57
|
},
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
exports: [],
|
|
170
|
-
})
|
|
171
|
-
}
|
|
58
|
+
} satisfies Group)
|
|
59
|
+
: undefined
|
|
172
60
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
61
|
+
return {
|
|
62
|
+
name: pluginVueQueryName,
|
|
63
|
+
options,
|
|
64
|
+
dependencies: [pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter((dependency): dependency is string => Boolean(dependency)),
|
|
65
|
+
hooks: {
|
|
66
|
+
'kubb:plugin:setup'(ctx) {
|
|
67
|
+
const resolver = userResolver ? { ...resolverVueQuery, ...userResolver } : resolverVueQuery
|
|
68
|
+
|
|
69
|
+
ctx.setOptions({
|
|
70
|
+
output,
|
|
71
|
+
client: {
|
|
72
|
+
bundle: client?.bundle,
|
|
73
|
+
baseURL: client?.baseURL,
|
|
74
|
+
client: clientName,
|
|
75
|
+
clientType: client?.clientType ?? 'function',
|
|
76
|
+
importPath: clientImportPath,
|
|
77
|
+
dataReturnType: client?.dataReturnType ?? 'data',
|
|
78
|
+
paramsCasing,
|
|
79
|
+
},
|
|
80
|
+
queryKey,
|
|
81
|
+
query:
|
|
82
|
+
query === false
|
|
83
|
+
? false
|
|
84
|
+
: {
|
|
85
|
+
importPath: '@tanstack/vue-query',
|
|
86
|
+
methods: ['get'],
|
|
87
|
+
...query,
|
|
88
|
+
},
|
|
89
|
+
mutationKey,
|
|
90
|
+
mutation:
|
|
91
|
+
mutation === false
|
|
92
|
+
? false
|
|
93
|
+
: {
|
|
94
|
+
importPath: '@tanstack/vue-query',
|
|
95
|
+
methods: ['post', 'put', 'patch', 'delete'],
|
|
96
|
+
...mutation,
|
|
97
|
+
},
|
|
98
|
+
infinite: infinite
|
|
99
|
+
? {
|
|
100
|
+
queryParam: 'id',
|
|
101
|
+
initialPageParam: 0,
|
|
102
|
+
cursorParam: undefined,
|
|
103
|
+
nextParam: undefined,
|
|
104
|
+
previousParam: undefined,
|
|
105
|
+
...infinite,
|
|
106
|
+
}
|
|
107
|
+
: false,
|
|
108
|
+
parser,
|
|
109
|
+
paramsType,
|
|
110
|
+
pathParamsType,
|
|
111
|
+
paramsCasing,
|
|
112
|
+
group: groupConfig,
|
|
113
|
+
exclude,
|
|
114
|
+
include,
|
|
115
|
+
override,
|
|
116
|
+
resolver,
|
|
187
117
|
})
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
118
|
+
ctx.setResolver(resolver)
|
|
119
|
+
if (userTransformer) {
|
|
120
|
+
ctx.setTransformer(userTransformer)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
for (const gen of selectedGenerators) {
|
|
124
|
+
ctx.addGenerator(gen)
|
|
125
|
+
}
|
|
126
|
+
for (const gen of userGenerators) {
|
|
127
|
+
ctx.addGenerator(gen)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const root = path.resolve(ctx.config.root, ctx.config.output.path)
|
|
131
|
+
const hasClientPlugin = !!ctx.config.plugins?.some((p) => (p as { name?: string }).name === pluginClientName)
|
|
132
|
+
|
|
133
|
+
if (client?.bundle && !hasClientPlugin && !clientImportPath) {
|
|
134
|
+
ctx.injectFile({
|
|
135
|
+
baseName: 'fetch.ts',
|
|
136
|
+
path: path.resolve(root, '.kubb/fetch.ts'),
|
|
137
|
+
sources: [
|
|
138
|
+
ast.createSource({
|
|
139
|
+
name: 'fetch',
|
|
140
|
+
nodes: [ast.createText(clientName === 'fetch' ? fetchClientSource : axiosClientSource)],
|
|
141
|
+
isExportable: true,
|
|
142
|
+
isIndexable: true,
|
|
143
|
+
}),
|
|
144
|
+
],
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (!hasClientPlugin) {
|
|
149
|
+
ctx.injectFile({
|
|
150
|
+
baseName: 'config.ts',
|
|
151
|
+
path: path.resolve(root, '.kubb/config.ts'),
|
|
152
|
+
sources: [
|
|
153
|
+
ast.createSource({
|
|
154
|
+
name: 'config',
|
|
155
|
+
nodes: [ast.createText(configSource)],
|
|
156
|
+
isExportable: false,
|
|
157
|
+
isIndexable: false,
|
|
158
|
+
}),
|
|
159
|
+
],
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
},
|
|
216
163
|
},
|
|
217
164
|
}
|
|
218
165
|
})
|
|
166
|
+
|
|
167
|
+
export default pluginVueQuery
|