@kubb/plugin-vue-query 5.0.0-alpha.9 → 5.0.0-beta.100
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 +38 -23
- package/dist/index.cjs +1651 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +358 -6
- package/dist/index.js +1618 -138
- package/dist/index.js.map +1 -1
- package/package.json +48 -76
- 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/components.cjs +0 -9
- package/dist/components.d.ts +0 -242
- package/dist/components.js +0 -2
- 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/generators.cjs +0 -5
- package/dist/generators.d.ts +0 -511
- package/dist/generators.js +0 -2
- package/dist/types-CgDFUvfZ.d.ts +0 -211
- package/src/components/InfiniteQuery.tsx +0 -208
- package/src/components/InfiniteQueryOptions.tsx +0 -249
- package/src/components/Mutation.tsx +0 -185
- package/src/components/MutationKey.tsx +0 -1
- package/src/components/Query.tsx +0 -208
- package/src/components/QueryKey.tsx +0 -94
- package/src/components/QueryOptions.tsx +0 -185
- package/src/components/index.ts +0 -7
- package/src/generators/index.ts +0 -3
- package/src/generators/infiniteQueryGenerator.tsx +0 -213
- package/src/generators/mutationGenerator.tsx +0 -176
- package/src/generators/queryGenerator.tsx +0 -191
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -218
- package/src/types.ts +0 -176
- /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
|
@@ -1,213 +0,0 @@
|
|
|
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'
|
|
8
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
9
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
10
|
-
import { File } from '@kubb/react-fabric'
|
|
11
|
-
import { difference } from 'remeda'
|
|
12
|
-
import { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components'
|
|
13
|
-
import type { PluginVueQuery } from '../types'
|
|
14
|
-
|
|
15
|
-
export const infiniteQueryGenerator = createReactGenerator<PluginVueQuery>({
|
|
16
|
-
name: 'vue-infinite-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 isInfinite = isQuery && !!options.infinite
|
|
32
|
-
const importPath = options.query ? options.query.importPath : '@tanstack/vue-query'
|
|
33
|
-
|
|
34
|
-
const query = {
|
|
35
|
-
name: getName(operation, {
|
|
36
|
-
type: 'function',
|
|
37
|
-
prefix: 'use',
|
|
38
|
-
suffix: 'infinite',
|
|
39
|
-
}),
|
|
40
|
-
typeName: getName(operation, { type: 'type' }),
|
|
41
|
-
file: getFile(operation, { prefix: 'use', suffix: 'infinite' }),
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const hasClientPlugin = !!driver.getPluginByName(pluginClientName)
|
|
45
|
-
// Class-based clients are not compatible with query hooks, so we generate inline clients
|
|
46
|
-
const shouldUseClientPlugin = hasClientPlugin && options.client.clientType !== 'class'
|
|
47
|
-
const client = {
|
|
48
|
-
name: shouldUseClientPlugin
|
|
49
|
-
? getName(operation, {
|
|
50
|
-
type: 'function',
|
|
51
|
-
pluginName: pluginClientName,
|
|
52
|
-
})
|
|
53
|
-
: getName(operation, {
|
|
54
|
-
type: 'function',
|
|
55
|
-
suffix: 'infinite',
|
|
56
|
-
}),
|
|
57
|
-
file: getFile(operation, { pluginName: pluginClientName }),
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const queryOptions = {
|
|
61
|
-
name: getName(operation, {
|
|
62
|
-
type: 'function',
|
|
63
|
-
suffix: 'InfiniteQueryOptions',
|
|
64
|
-
}),
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const queryKey = {
|
|
68
|
-
name: getName(operation, { type: 'const', suffix: 'InfiniteQueryKey' }),
|
|
69
|
-
typeName: getName(operation, {
|
|
70
|
-
type: 'type',
|
|
71
|
-
suffix: 'InfiniteQueryKey',
|
|
72
|
-
}),
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const type = {
|
|
76
|
-
file: getFile(operation, { pluginName: pluginTsName }),
|
|
77
|
-
//todo remove type?
|
|
78
|
-
schemas: getSchemas(operation, {
|
|
79
|
-
pluginName: pluginTsName,
|
|
80
|
-
type: 'type',
|
|
81
|
-
}),
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const zod = {
|
|
85
|
-
file: getFile(operation, { pluginName: pluginZodName }),
|
|
86
|
-
schemas: getSchemas(operation, {
|
|
87
|
-
pluginName: pluginZodName,
|
|
88
|
-
type: 'function',
|
|
89
|
-
}),
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (!isQuery || isMutation || !isInfinite) {
|
|
93
|
-
return null
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
<File
|
|
98
|
-
baseName={query.file.baseName}
|
|
99
|
-
path={query.file.path}
|
|
100
|
-
meta={query.file.meta}
|
|
101
|
-
banner={getBanner({ oas, output, config: driver.config })}
|
|
102
|
-
footer={getFooter({ oas, output })}
|
|
103
|
-
>
|
|
104
|
-
{options.parser === 'zod' && (
|
|
105
|
-
<File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={query.file.path} path={zod.file.path} />
|
|
106
|
-
)}
|
|
107
|
-
{options.client.importPath ? (
|
|
108
|
-
<>
|
|
109
|
-
{!shouldUseClientPlugin && <File.Import name={'fetch'} path={options.client.importPath} />}
|
|
110
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />
|
|
111
|
-
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
|
112
|
-
</>
|
|
113
|
-
) : (
|
|
114
|
-
<>
|
|
115
|
-
{!shouldUseClientPlugin && (
|
|
116
|
-
<File.Import name={['fetch']} root={query.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />
|
|
117
|
-
)}
|
|
118
|
-
<File.Import
|
|
119
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
120
|
-
root={query.file.path}
|
|
121
|
-
path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}
|
|
122
|
-
isTypeOnly
|
|
123
|
-
/>
|
|
124
|
-
{options.client.dataReturnType === 'full' && (
|
|
125
|
-
<File.Import name={['ResponseConfig']} root={query.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} isTypeOnly />
|
|
126
|
-
)}
|
|
127
|
-
</>
|
|
128
|
-
)}
|
|
129
|
-
<File.Import name={['toValue']} path="vue" />
|
|
130
|
-
<File.Import name={['MaybeRefOrGetter']} path="vue" isTypeOnly />
|
|
131
|
-
{shouldUseClientPlugin && <File.Import name={[client.name]} root={query.file.path} path={client.file.path} />}
|
|
132
|
-
{!shouldUseClientPlugin && (
|
|
133
|
-
<File.Import name={['buildFormData']} root={query.file.path} path={path.resolve(config.root, config.output.path, '.kubb/config.ts')} />
|
|
134
|
-
)}
|
|
135
|
-
<File.Import
|
|
136
|
-
name={[
|
|
137
|
-
type.schemas.request?.name,
|
|
138
|
-
type.schemas.response.name,
|
|
139
|
-
type.schemas.pathParams?.name,
|
|
140
|
-
type.schemas.queryParams?.name,
|
|
141
|
-
type.schemas.headerParams?.name,
|
|
142
|
-
...(type.schemas.statusCodes?.map((item) => item.name) || []),
|
|
143
|
-
].filter(Boolean)}
|
|
144
|
-
root={query.file.path}
|
|
145
|
-
path={type.file.path}
|
|
146
|
-
isTypeOnly
|
|
147
|
-
/>
|
|
148
|
-
<QueryKey
|
|
149
|
-
name={queryKey.name}
|
|
150
|
-
typeName={queryKey.typeName}
|
|
151
|
-
operation={operation}
|
|
152
|
-
paramsCasing={options.paramsCasing}
|
|
153
|
-
pathParamsType={options.pathParamsType}
|
|
154
|
-
typeSchemas={type.schemas}
|
|
155
|
-
transformer={options.queryKey}
|
|
156
|
-
/>
|
|
157
|
-
{!shouldUseClientPlugin && (
|
|
158
|
-
<Client
|
|
159
|
-
name={client.name}
|
|
160
|
-
baseURL={options.client.baseURL}
|
|
161
|
-
operation={operation}
|
|
162
|
-
typeSchemas={type.schemas}
|
|
163
|
-
zodSchemas={zod.schemas}
|
|
164
|
-
dataReturnType={options.client.dataReturnType || 'data'}
|
|
165
|
-
paramsCasing={options.client?.paramsCasing || options.paramsCasing}
|
|
166
|
-
paramsType={options.paramsType}
|
|
167
|
-
pathParamsType={options.pathParamsType}
|
|
168
|
-
parser={options.parser}
|
|
169
|
-
/>
|
|
170
|
-
)}
|
|
171
|
-
{options.infinite && (
|
|
172
|
-
<>
|
|
173
|
-
<File.Import name={['InfiniteData']} isTypeOnly path={importPath} />
|
|
174
|
-
<File.Import name={['infiniteQueryOptions']} path={importPath} />
|
|
175
|
-
<InfiniteQueryOptions
|
|
176
|
-
name={queryOptions.name}
|
|
177
|
-
clientName={client.name}
|
|
178
|
-
queryKeyName={queryKey.name}
|
|
179
|
-
typeSchemas={type.schemas}
|
|
180
|
-
paramsType={options.paramsType}
|
|
181
|
-
paramsCasing={options.paramsCasing}
|
|
182
|
-
pathParamsType={options.pathParamsType}
|
|
183
|
-
dataReturnType={options.client.dataReturnType || 'data'}
|
|
184
|
-
cursorParam={options.infinite.cursorParam}
|
|
185
|
-
nextParam={options.infinite.nextParam}
|
|
186
|
-
previousParam={options.infinite.previousParam}
|
|
187
|
-
initialPageParam={options.infinite.initialPageParam}
|
|
188
|
-
queryParam={options.infinite.queryParam}
|
|
189
|
-
/>
|
|
190
|
-
</>
|
|
191
|
-
)}
|
|
192
|
-
{options.infinite && (
|
|
193
|
-
<>
|
|
194
|
-
<File.Import name={['useInfiniteQuery']} path={importPath} />
|
|
195
|
-
<File.Import name={['QueryKey', 'QueryClient', 'UseInfiniteQueryOptions', 'UseInfiniteQueryReturnType']} path={importPath} isTypeOnly />
|
|
196
|
-
<InfiniteQuery
|
|
197
|
-
name={query.name}
|
|
198
|
-
queryOptionsName={queryOptions.name}
|
|
199
|
-
typeSchemas={type.schemas}
|
|
200
|
-
paramsCasing={options.paramsCasing}
|
|
201
|
-
paramsType={options.paramsType}
|
|
202
|
-
pathParamsType={options.pathParamsType}
|
|
203
|
-
operation={operation}
|
|
204
|
-
dataReturnType={options.client.dataReturnType || 'data'}
|
|
205
|
-
queryKeyName={queryKey.name}
|
|
206
|
-
queryKeyTypeName={queryKey.typeName}
|
|
207
|
-
/>
|
|
208
|
-
</>
|
|
209
|
-
)}
|
|
210
|
-
</File>
|
|
211
|
-
)
|
|
212
|
-
},
|
|
213
|
-
})
|
|
@@ -1,176 +0,0 @@
|
|
|
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'
|
|
8
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
9
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
10
|
-
import { File } from '@kubb/react-fabric'
|
|
11
|
-
import { difference } from 'remeda'
|
|
12
|
-
import { Mutation, MutationKey } from '../components'
|
|
13
|
-
import type { PluginVueQuery } from '../types'
|
|
14
|
-
|
|
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()
|
|
23
|
-
|
|
24
|
-
const oas = useOas()
|
|
25
|
-
const { getSchemas, getName, getFile } = useOperationManager(generator)
|
|
26
|
-
|
|
27
|
-
const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method)
|
|
28
|
-
const isMutation =
|
|
29
|
-
options.mutation !== false &&
|
|
30
|
-
!isQuery &&
|
|
31
|
-
difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method)
|
|
32
|
-
|
|
33
|
-
const importPath = options.mutation ? options.mutation.importPath : '@tanstack/vue-query'
|
|
34
|
-
|
|
35
|
-
const mutation = {
|
|
36
|
-
name: getName(operation, { type: 'function', prefix: 'use' }),
|
|
37
|
-
typeName: getName(operation, { type: 'type' }),
|
|
38
|
-
file: getFile(operation, { prefix: 'use' }),
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const type = {
|
|
42
|
-
file: getFile(operation, { pluginName: pluginTsName }),
|
|
43
|
-
//todo remove type?
|
|
44
|
-
schemas: getSchemas(operation, { pluginName: pluginTsName, type: 'type' }),
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const zod = {
|
|
48
|
-
file: getFile(operation, { pluginName: pluginZodName }),
|
|
49
|
-
schemas: getSchemas(operation, { pluginName: pluginZodName, type: 'function' }),
|
|
50
|
-
}
|
|
51
|
-
|
|
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
|
-
}
|
|
66
|
-
|
|
67
|
-
const mutationKey = {
|
|
68
|
-
name: getName(operation, { type: 'const', suffix: 'MutationKey' }),
|
|
69
|
-
typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (!isMutation) {
|
|
73
|
-
return null
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return (
|
|
77
|
-
<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 })}
|
|
83
|
-
>
|
|
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} />
|
|
86
|
-
)}
|
|
87
|
-
{options.client.importPath ? (
|
|
88
|
-
<>
|
|
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 />}
|
|
92
|
-
</>
|
|
93
|
-
) : (
|
|
94
|
-
<>
|
|
95
|
-
{!shouldUseClientPlugin && (
|
|
96
|
-
<File.Import name={['fetch']} root={mutation.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />
|
|
97
|
-
)}
|
|
98
|
-
<File.Import
|
|
99
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
100
|
-
root={mutation.file.path}
|
|
101
|
-
path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}
|
|
102
|
-
isTypeOnly
|
|
103
|
-
/>
|
|
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
|
-
/>
|
|
111
|
-
)}
|
|
112
|
-
</>
|
|
113
|
-
)}
|
|
114
|
-
<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')} />
|
|
118
|
-
)}
|
|
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
|
-
/>
|
|
141
|
-
{!shouldUseClientPlugin && (
|
|
142
|
-
<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}
|
|
153
|
-
/>
|
|
154
|
-
)}
|
|
155
|
-
{options.mutation && (
|
|
156
|
-
<>
|
|
157
|
-
<File.Import name={['useMutation']} path={importPath} />
|
|
158
|
-
<File.Import name={['MutationObserverOptions', 'QueryClient']} path={importPath} isTypeOnly />
|
|
159
|
-
<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}
|
|
170
|
-
/>
|
|
171
|
-
</>
|
|
172
|
-
)}
|
|
173
|
-
</File>
|
|
174
|
-
)
|
|
175
|
-
},
|
|
176
|
-
})
|
|
@@ -1,191 +0,0 @@
|
|
|
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'
|
|
8
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
9
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
10
|
-
import { File } from '@kubb/react-fabric'
|
|
11
|
-
import { difference } from 'remeda'
|
|
12
|
-
import { Query, QueryKey, QueryOptions } from '../components'
|
|
13
|
-
import type { PluginVueQuery } from '../types'
|
|
14
|
-
|
|
15
|
-
export const queryGenerator = 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()
|
|
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'
|
|
32
|
-
|
|
33
|
-
const query = {
|
|
34
|
-
name: getName(operation, { type: 'function', prefix: 'use' }),
|
|
35
|
-
typeName: getName(operation, { type: 'type' }),
|
|
36
|
-
file: getFile(operation, { prefix: 'use' }),
|
|
37
|
-
}
|
|
38
|
-
|
|
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
|
-
}
|
|
53
|
-
|
|
54
|
-
const queryOptions = {
|
|
55
|
-
name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const queryKey = {
|
|
59
|
-
name: getName(operation, { type: 'const', suffix: 'QueryKey' }),
|
|
60
|
-
typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),
|
|
61
|
-
}
|
|
62
|
-
|
|
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
|
-
}
|
|
71
|
-
|
|
72
|
-
const zod = {
|
|
73
|
-
file: getFile(operation, { pluginName: pluginZodName }),
|
|
74
|
-
schemas: getSchemas(operation, {
|
|
75
|
-
pluginName: pluginZodName,
|
|
76
|
-
type: 'function',
|
|
77
|
-
}),
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!isQuery || isMutation) {
|
|
81
|
-
return null
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<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 })}
|
|
91
|
-
>
|
|
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} />
|
|
94
|
-
)}
|
|
95
|
-
{options.client.importPath ? (
|
|
96
|
-
<>
|
|
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 />}
|
|
100
|
-
</>
|
|
101
|
-
) : (
|
|
102
|
-
<>
|
|
103
|
-
{!shouldUseClientPlugin && (
|
|
104
|
-
<File.Import name={['fetch']} root={query.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />
|
|
105
|
-
)}
|
|
106
|
-
<File.Import
|
|
107
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
108
|
-
root={query.file.path}
|
|
109
|
-
path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}
|
|
110
|
-
isTypeOnly
|
|
111
|
-
/>
|
|
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 />
|
|
114
|
-
)}
|
|
115
|
-
</>
|
|
116
|
-
)}
|
|
117
|
-
<File.Import name={['toValue']} path="vue" />
|
|
118
|
-
<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')} />
|
|
122
|
-
)}
|
|
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
|
-
/>
|
|
136
|
-
<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}
|
|
144
|
-
/>
|
|
145
|
-
{!shouldUseClientPlugin && (
|
|
146
|
-
<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}
|
|
157
|
-
/>
|
|
158
|
-
)}
|
|
159
|
-
<File.Import name={['queryOptions']} path={importPath} />
|
|
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'}
|
|
169
|
-
/>
|
|
170
|
-
{options.query && (
|
|
171
|
-
<>
|
|
172
|
-
<File.Import name={['useQuery']} path={importPath} />
|
|
173
|
-
<File.Import name={['QueryKey', 'QueryClient', 'UseQueryOptions', 'UseQueryReturnType']} path={importPath} isTypeOnly />
|
|
174
|
-
<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}
|
|
185
|
-
/>
|
|
186
|
-
</>
|
|
187
|
-
)}
|
|
188
|
-
</File>
|
|
189
|
-
)
|
|
190
|
-
},
|
|
191
|
-
})
|
package/src/index.ts
DELETED