@kubb/plugin-vue-query 5.0.0-beta.10 → 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/README.md +22 -26
- package/dist/index.cjs +1629 -147
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +358 -6
- package/dist/index.js +1600 -145
- package/dist/index.js.map +1 -1
- package/package.json +9 -32
- package/dist/components-B6jAb2as.js +0 -1150
- package/dist/components-B6jAb2as.js.map +0 -1
- package/dist/components-X0P-3W2G.cjs +0 -1264
- package/dist/components-X0P-3W2G.cjs.map +0 -1
- package/dist/components.cjs +0 -9
- package/dist/components.d.ts +0 -187
- package/dist/components.js +0 -2
- package/dist/generators-B33PbKzu.js +0 -681
- package/dist/generators-B33PbKzu.js.map +0 -1
- package/dist/generators-BE3KD0IR.cjs +0 -698
- package/dist/generators-BE3KD0IR.cjs.map +0 -1
- package/dist/generators.cjs +0 -5
- package/dist/generators.d.ts +0 -15
- package/dist/generators.js +0 -2
- package/dist/types-Bkm7bWT3.d.ts +0 -243
- package/extension.yaml +0 -732
- package/src/components/InfiniteQuery.tsx +0 -120
- package/src/components/InfiniteQueryOptions.tsx +0 -201
- package/src/components/Mutation.tsx +0 -148
- package/src/components/MutationKey.tsx +0 -1
- package/src/components/Query.tsx +0 -119
- package/src/components/QueryKey.tsx +0 -51
- package/src/components/QueryOptions.tsx +0 -134
- package/src/components/index.ts +0 -7
- package/src/generators/index.ts +0 -3
- package/src/generators/infiniteQueryGenerator.tsx +0 -194
- package/src/generators/mutationGenerator.tsx +0 -153
- package/src/generators/queryGenerator.tsx +0 -179
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -167
- package/src/resolvers/resolverVueQuery.ts +0 -65
- package/src/types.ts +0 -245
- package/src/utils.ts +0 -49
- /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { ast } from '@kubb/core'
|
|
2
|
-
import type { ResolverTs } from '@kubb/plugin-ts'
|
|
3
|
-
import { functionPrinter } from '@kubb/plugin-ts'
|
|
4
|
-
import { File, Function } from '@kubb/renderer-jsx'
|
|
5
|
-
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
6
|
-
import { buildEnabledCheck } from '@internals/tanstack-query'
|
|
7
|
-
import type { PluginVueQuery } from '../types.ts'
|
|
8
|
-
import { resolveErrorNames, wrapWithMaybeRefOrGetter } from '../utils.ts'
|
|
9
|
-
import { buildQueryKeyParamsNode } from './QueryKey.tsx'
|
|
10
|
-
|
|
11
|
-
type Props = {
|
|
12
|
-
name: string
|
|
13
|
-
clientName: string
|
|
14
|
-
queryKeyName: string
|
|
15
|
-
node: ast.OperationNode
|
|
16
|
-
tsResolver: ResolverTs
|
|
17
|
-
paramsCasing: PluginVueQuery['resolvedOptions']['paramsCasing']
|
|
18
|
-
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
19
|
-
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
20
|
-
dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const declarationPrinter = functionPrinter({ mode: 'declaration' })
|
|
24
|
-
const callPrinter = functionPrinter({ mode: 'call' })
|
|
25
|
-
|
|
26
|
-
export function getQueryOptionsParams(
|
|
27
|
-
node: ast.OperationNode,
|
|
28
|
-
options: {
|
|
29
|
-
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
30
|
-
paramsCasing: PluginVueQuery['resolvedOptions']['paramsCasing']
|
|
31
|
-
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
32
|
-
resolver: ResolverTs
|
|
33
|
-
},
|
|
34
|
-
): ast.FunctionParametersNode {
|
|
35
|
-
const { paramsType, paramsCasing, pathParamsType, resolver } = options
|
|
36
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : undefined
|
|
37
|
-
|
|
38
|
-
const baseParams = ast.createOperationParams(node, {
|
|
39
|
-
paramsType,
|
|
40
|
-
pathParamsType: paramsType === 'object' ? 'object' : pathParamsType === 'object' ? 'object' : 'inline',
|
|
41
|
-
paramsCasing,
|
|
42
|
-
resolver,
|
|
43
|
-
extraParams: [
|
|
44
|
-
ast.createFunctionParameter({
|
|
45
|
-
name: 'config',
|
|
46
|
-
type: ast.createParamsType({
|
|
47
|
-
variant: 'reference',
|
|
48
|
-
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }',
|
|
49
|
-
}),
|
|
50
|
-
default: '{}',
|
|
51
|
-
}),
|
|
52
|
-
],
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
return wrapWithMaybeRefOrGetter(baseParams, (name) => name === 'config')
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function QueryOptions({
|
|
59
|
-
name,
|
|
60
|
-
clientName,
|
|
61
|
-
dataReturnType,
|
|
62
|
-
node,
|
|
63
|
-
tsResolver,
|
|
64
|
-
paramsCasing,
|
|
65
|
-
paramsType,
|
|
66
|
-
pathParamsType,
|
|
67
|
-
queryKeyName,
|
|
68
|
-
}: Props): KubbReactNode {
|
|
69
|
-
const responseName = tsResolver.resolveResponseName(node)
|
|
70
|
-
const errorNames = resolveErrorNames(node, tsResolver)
|
|
71
|
-
|
|
72
|
-
const TData = dataReturnType === 'data' ? responseName : `ResponseConfig<${responseName}>`
|
|
73
|
-
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
74
|
-
|
|
75
|
-
const paramsNode = getQueryOptionsParams(node, { paramsType, paramsCasing, pathParamsType, resolver: tsResolver })
|
|
76
|
-
const paramsSignature = declarationPrinter.print(paramsNode) ?? ''
|
|
77
|
-
const rawParamsCall = callPrinter.print(paramsNode) ?? ''
|
|
78
|
-
|
|
79
|
-
// Transform: wrap non-config params with toValue(), add signal to config
|
|
80
|
-
const clientCallStr = rawParamsCall.replace(/\bconfig\b(?=[^,]*$)/, '{ ...config, signal: config.signal ?? signal }')
|
|
81
|
-
|
|
82
|
-
const queryKeyParamsNode = buildQueryKeyParamsNode(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
83
|
-
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? ''
|
|
84
|
-
|
|
85
|
-
const enabledSource = buildEnabledCheck(queryKeyParamsNode)
|
|
86
|
-
const enabledText = enabledSource ? `enabled: () => !!(${enabledSource}),` : ''
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<File.Source name={name} isExportable isIndexable>
|
|
90
|
-
<Function name={name} export params={paramsSignature}>
|
|
91
|
-
{`
|
|
92
|
-
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
93
|
-
return queryOptions<${TData}, ${TError}, ${TData}>({
|
|
94
|
-
${enabledText}
|
|
95
|
-
queryKey,
|
|
96
|
-
queryFn: async ({ signal }) => {
|
|
97
|
-
return ${clientName}(${addToValueCalls(clientCallStr)})
|
|
98
|
-
},
|
|
99
|
-
})
|
|
100
|
-
`}
|
|
101
|
-
</Function>
|
|
102
|
-
</File.Source>
|
|
103
|
-
)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Wraps parameter names with `toValue()` in the client call string,
|
|
108
|
-
* except for 'config'-related params (which are already plain objects).
|
|
109
|
-
*
|
|
110
|
-
* Handles both inline params (`petId, config`) and object shorthand
|
|
111
|
-
* params (`{ petId }, config`) by expanding to `{ petId: toValue(petId) }`.
|
|
112
|
-
*/
|
|
113
|
-
function addToValueCalls(callStr: string): string {
|
|
114
|
-
// Step 1: Transform shorthand object params like { petId } → { petId: toValue(petId) }
|
|
115
|
-
let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner: string) => {
|
|
116
|
-
// Only transform simple shorthand (no colons, no spread)
|
|
117
|
-
if (inner.includes(':') || inner.includes('...')) return match
|
|
118
|
-
const keys = inner
|
|
119
|
-
.split(',')
|
|
120
|
-
.map((k: string) => k.trim())
|
|
121
|
-
.filter(Boolean)
|
|
122
|
-
const wrapped = keys.map((k: string) => `${k}: toValue(${k})`).join(', ')
|
|
123
|
-
return `{ ${wrapped} }`
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
// Step 2: Handle standalone identifiers like `data, params`
|
|
127
|
-
result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name: string) => {
|
|
128
|
-
if (name === 'config' || name === 'signal' || name === 'undefined') return match
|
|
129
|
-
if (match.includes('toValue(')) return match
|
|
130
|
-
return `toValue(${name})`
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
return result
|
|
134
|
-
}
|
package/src/components/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { InfiniteQuery } from './InfiniteQuery.tsx'
|
|
2
|
-
export { InfiniteQueryOptions } from './InfiniteQueryOptions.tsx'
|
|
3
|
-
export { Mutation } from './Mutation.tsx'
|
|
4
|
-
export { MutationKey } from './MutationKey.tsx'
|
|
5
|
-
export { Query } from './Query.tsx'
|
|
6
|
-
export { QueryKey } from './QueryKey.tsx'
|
|
7
|
-
export { QueryOptions } from './QueryOptions.tsx'
|
package/src/generators/index.ts
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { getOperationParameters, 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'
|
|
6
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
8
|
-
import { File, jsxRenderer } from '@kubb/renderer-jsx'
|
|
9
|
-
import { difference } from 'remeda'
|
|
10
|
-
import { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components'
|
|
11
|
-
import type { PluginVueQuery } from '../types'
|
|
12
|
-
|
|
13
|
-
export const infiniteQueryGenerator = defineGenerator<PluginVueQuery>({
|
|
14
|
-
name: 'vue-query-infinite',
|
|
15
|
-
renderer: jsxRenderer,
|
|
16
|
-
operation(node, ctx) {
|
|
17
|
-
const { adapter, config, driver, resolver, root } = ctx
|
|
18
|
-
const { output, query, mutation, infinite, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group } = ctx.options
|
|
19
|
-
|
|
20
|
-
const pluginTs = driver.getPlugin(pluginTsName)
|
|
21
|
-
if (!pluginTs) return null
|
|
22
|
-
const tsResolver = driver.getResolver(pluginTsName)
|
|
23
|
-
|
|
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())
|
|
29
|
-
const infiniteOptions = infinite && typeof infinite === 'object' ? infinite : undefined
|
|
30
|
-
|
|
31
|
-
if (!isQuery || isMutation || !infiniteOptions) return null
|
|
32
|
-
|
|
33
|
-
// Validate queryParam exists in operation's query parameters
|
|
34
|
-
const normalizeKey = (key: string) => key.replace(/\?$/, '')
|
|
35
|
-
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name)
|
|
36
|
-
const hasQueryParam = infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false
|
|
37
|
-
// cursorParam validation against response schema keys is skipped in v5 (complex schema inspection)
|
|
38
|
-
const hasCursorParam = !infiniteOptions.cursorParam || true
|
|
39
|
-
|
|
40
|
-
if (!hasQueryParam || !hasCursorParam) return null
|
|
41
|
-
|
|
42
|
-
const importPath = query ? query.importPath : '@tanstack/vue-query'
|
|
43
|
-
|
|
44
|
-
const queryName = resolver.resolveInfiniteQueryName(node)
|
|
45
|
-
const queryOptionsName = resolver.resolveInfiniteQueryOptionsName(node)
|
|
46
|
-
const queryKeyName = resolver.resolveInfiniteQueryKeyName(node)
|
|
47
|
-
const queryKeyTypeName = resolver.resolveInfiniteQueryKeyTypeName(node)
|
|
48
|
-
const clientBaseName = resolver.resolveInfiniteClientName(node)
|
|
49
|
-
|
|
50
|
-
const meta = {
|
|
51
|
-
file: resolver.resolveFile({ name: queryName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
|
|
52
|
-
fileTs: tsResolver.resolveFile(
|
|
53
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
54
|
-
{ root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group },
|
|
55
|
-
),
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
59
|
-
paramsCasing,
|
|
60
|
-
exclude: [queryKeyTypeName],
|
|
61
|
-
order: 'body-response-first',
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : undefined
|
|
65
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : undefined
|
|
66
|
-
const fileZod = zodResolver
|
|
67
|
-
? zodResolver.resolveFile(
|
|
68
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
69
|
-
{ root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
|
|
70
|
-
)
|
|
71
|
-
: undefined
|
|
72
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
|
|
73
|
-
|
|
74
|
-
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
75
|
-
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
76
|
-
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
77
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : undefined
|
|
78
|
-
|
|
79
|
-
const clientFile = shouldUseClientPlugin
|
|
80
|
-
? clientResolver?.resolveFile(
|
|
81
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
82
|
-
{
|
|
83
|
-
root,
|
|
84
|
-
output: clientPlugin?.options?.output ?? output,
|
|
85
|
-
group: clientPlugin?.options?.group,
|
|
86
|
-
},
|
|
87
|
-
)
|
|
88
|
-
: undefined
|
|
89
|
-
|
|
90
|
-
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientBaseName) : clientBaseName
|
|
91
|
-
|
|
92
|
-
return (
|
|
93
|
-
<File
|
|
94
|
-
baseName={meta.file.baseName}
|
|
95
|
-
path={meta.file.path}
|
|
96
|
-
meta={meta.file.meta}
|
|
97
|
-
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
98
|
-
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
99
|
-
>
|
|
100
|
-
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
101
|
-
{clientOptions.importPath ? (
|
|
102
|
-
<>
|
|
103
|
-
{!shouldUseClientPlugin && <File.Import name={'fetch'} path={clientOptions.importPath} />}
|
|
104
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
105
|
-
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
106
|
-
</>
|
|
107
|
-
) : (
|
|
108
|
-
<>
|
|
109
|
-
{!shouldUseClientPlugin && <File.Import name={['fetch']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} />}
|
|
110
|
-
<File.Import
|
|
111
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
112
|
-
root={meta.file.path}
|
|
113
|
-
path={path.resolve(root, '.kubb/fetch.ts')}
|
|
114
|
-
isTypeOnly
|
|
115
|
-
/>
|
|
116
|
-
{clientOptions.dataReturnType === 'full' && (
|
|
117
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} isTypeOnly />
|
|
118
|
-
)}
|
|
119
|
-
</>
|
|
120
|
-
)}
|
|
121
|
-
<File.Import name={['toValue']} path="vue" />
|
|
122
|
-
<File.Import name={['MaybeRefOrGetter']} path="vue" isTypeOnly />
|
|
123
|
-
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
124
|
-
{!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
|
|
125
|
-
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
126
|
-
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
127
|
-
)}
|
|
128
|
-
|
|
129
|
-
<QueryKey
|
|
130
|
-
name={queryKeyName}
|
|
131
|
-
typeName={queryKeyTypeName}
|
|
132
|
-
node={node}
|
|
133
|
-
tsResolver={tsResolver}
|
|
134
|
-
pathParamsType={pathParamsType}
|
|
135
|
-
paramsCasing={paramsCasing}
|
|
136
|
-
transformer={ctx.options.queryKey}
|
|
137
|
-
/>
|
|
138
|
-
|
|
139
|
-
{!shouldUseClientPlugin && (
|
|
140
|
-
<Client
|
|
141
|
-
name={resolvedClientName}
|
|
142
|
-
baseURL={clientOptions.baseURL}
|
|
143
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
144
|
-
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
145
|
-
paramsType={paramsType}
|
|
146
|
-
pathParamsType={pathParamsType}
|
|
147
|
-
parser={parser}
|
|
148
|
-
node={node}
|
|
149
|
-
tsResolver={tsResolver}
|
|
150
|
-
zodResolver={zodResolver}
|
|
151
|
-
/>
|
|
152
|
-
)}
|
|
153
|
-
|
|
154
|
-
<File.Import name={['InfiniteData']} isTypeOnly path={importPath} />
|
|
155
|
-
<File.Import name={['infiniteQueryOptions']} path={importPath} />
|
|
156
|
-
|
|
157
|
-
<InfiniteQueryOptions
|
|
158
|
-
name={queryOptionsName}
|
|
159
|
-
clientName={resolvedClientName}
|
|
160
|
-
queryKeyName={queryKeyName}
|
|
161
|
-
node={node}
|
|
162
|
-
tsResolver={tsResolver}
|
|
163
|
-
paramsCasing={paramsCasing}
|
|
164
|
-
paramsType={paramsType}
|
|
165
|
-
pathParamsType={pathParamsType}
|
|
166
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
167
|
-
cursorParam={infiniteOptions.cursorParam}
|
|
168
|
-
nextParam={infiniteOptions.nextParam}
|
|
169
|
-
previousParam={infiniteOptions.previousParam}
|
|
170
|
-
initialPageParam={infiniteOptions.initialPageParam}
|
|
171
|
-
queryParam={infiniteOptions.queryParam}
|
|
172
|
-
/>
|
|
173
|
-
|
|
174
|
-
<File.Import name={['useInfiniteQuery']} path={importPath} />
|
|
175
|
-
<File.Import name={['QueryKey', 'QueryClient', 'UseInfiniteQueryOptions', 'UseInfiniteQueryReturnType']} path={importPath} isTypeOnly />
|
|
176
|
-
|
|
177
|
-
<InfiniteQuery
|
|
178
|
-
name={queryName}
|
|
179
|
-
queryOptionsName={queryOptionsName}
|
|
180
|
-
queryKeyName={queryKeyName}
|
|
181
|
-
queryKeyTypeName={queryKeyTypeName}
|
|
182
|
-
node={node}
|
|
183
|
-
tsResolver={tsResolver}
|
|
184
|
-
paramsCasing={paramsCasing}
|
|
185
|
-
paramsType={paramsType}
|
|
186
|
-
pathParamsType={pathParamsType}
|
|
187
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
188
|
-
initialPageParam={infiniteOptions.initialPageParam}
|
|
189
|
-
queryParam={infiniteOptions.queryParam}
|
|
190
|
-
/>
|
|
191
|
-
</File>
|
|
192
|
-
)
|
|
193
|
-
},
|
|
194
|
-
})
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
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'
|
|
6
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
8
|
-
import { File, jsxRenderer } from '@kubb/renderer-jsx'
|
|
9
|
-
import { difference } from 'remeda'
|
|
10
|
-
import { Mutation, MutationKey } from '../components'
|
|
11
|
-
import type { PluginVueQuery } from '../types'
|
|
12
|
-
|
|
13
|
-
export const mutationGenerator = defineGenerator<PluginVueQuery>({
|
|
14
|
-
name: 'vue-query-mutation',
|
|
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
|
|
19
|
-
|
|
20
|
-
const pluginTs = driver.getPlugin(pluginTsName)
|
|
21
|
-
if (!pluginTs) return null
|
|
22
|
-
const tsResolver = driver.getResolver(pluginTsName)
|
|
23
|
-
|
|
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())
|
|
29
|
-
|
|
30
|
-
if (!isMutation) return null
|
|
31
|
-
|
|
32
|
-
const importPath = mutation ? mutation.importPath : '@tanstack/vue-query'
|
|
33
|
-
|
|
34
|
-
const mutationHookName = resolver.resolveMutationName(node)
|
|
35
|
-
const mutationTypeName = resolver.resolveMutationTypeName(node)
|
|
36
|
-
const mutationKeyName = resolver.resolveMutationKeyName(node)
|
|
37
|
-
const clientName = resolver.resolveClientName(node)
|
|
38
|
-
|
|
39
|
-
const meta = {
|
|
40
|
-
file: resolver.resolveFile({ name: mutationHookName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
|
|
41
|
-
fileTs: tsResolver.resolveFile(
|
|
42
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
43
|
-
{ root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group },
|
|
44
|
-
),
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, { paramsCasing, order: 'body-response-first' })
|
|
48
|
-
|
|
49
|
-
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : undefined
|
|
50
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : undefined
|
|
51
|
-
const fileZod = zodResolver
|
|
52
|
-
? zodResolver.resolveFile(
|
|
53
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
54
|
-
{ root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
|
|
55
|
-
)
|
|
56
|
-
: undefined
|
|
57
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
|
|
58
|
-
|
|
59
|
-
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
60
|
-
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
61
|
-
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
62
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : undefined
|
|
63
|
-
|
|
64
|
-
const clientFile = shouldUseClientPlugin
|
|
65
|
-
? clientResolver?.resolveFile(
|
|
66
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
67
|
-
{
|
|
68
|
-
root,
|
|
69
|
-
output: clientPlugin?.options?.output ?? output,
|
|
70
|
-
group: clientPlugin?.options?.group,
|
|
71
|
-
},
|
|
72
|
-
)
|
|
73
|
-
: undefined
|
|
74
|
-
|
|
75
|
-
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientName) : clientName
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<File
|
|
79
|
-
baseName={meta.file.baseName}
|
|
80
|
-
path={meta.file.path}
|
|
81
|
-
meta={meta.file.meta}
|
|
82
|
-
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
83
|
-
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
84
|
-
>
|
|
85
|
-
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
86
|
-
{clientOptions.importPath ? (
|
|
87
|
-
<>
|
|
88
|
-
{!shouldUseClientPlugin && <File.Import name={'fetch'} path={clientOptions.importPath} />}
|
|
89
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
90
|
-
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
91
|
-
</>
|
|
92
|
-
) : (
|
|
93
|
-
<>
|
|
94
|
-
{!shouldUseClientPlugin && <File.Import name={['fetch']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} />}
|
|
95
|
-
<File.Import
|
|
96
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
97
|
-
root={meta.file.path}
|
|
98
|
-
path={path.resolve(root, '.kubb/fetch.ts')}
|
|
99
|
-
isTypeOnly
|
|
100
|
-
/>
|
|
101
|
-
{clientOptions.dataReturnType === 'full' && (
|
|
102
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} isTypeOnly />
|
|
103
|
-
)}
|
|
104
|
-
</>
|
|
105
|
-
)}
|
|
106
|
-
<File.Import name={['MaybeRefOrGetter']} path="vue" isTypeOnly />
|
|
107
|
-
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
108
|
-
{!shouldUseClientPlugin && node.requestBody?.content?.some((e) => e.contentType === 'multipart/form-data') && (
|
|
109
|
-
<File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />
|
|
110
|
-
)}
|
|
111
|
-
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
112
|
-
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
113
|
-
)}
|
|
114
|
-
|
|
115
|
-
<MutationKey name={mutationKeyName} node={node} pathParamsType={pathParamsType} paramsCasing={paramsCasing} transformer={ctx.options.mutationKey} />
|
|
116
|
-
|
|
117
|
-
{!shouldUseClientPlugin && (
|
|
118
|
-
<Client
|
|
119
|
-
name={resolvedClientName}
|
|
120
|
-
baseURL={clientOptions.baseURL}
|
|
121
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
122
|
-
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
123
|
-
paramsType={paramsType}
|
|
124
|
-
pathParamsType={pathParamsType}
|
|
125
|
-
parser={parser}
|
|
126
|
-
node={node}
|
|
127
|
-
tsResolver={tsResolver}
|
|
128
|
-
zodResolver={zodResolver}
|
|
129
|
-
/>
|
|
130
|
-
)}
|
|
131
|
-
|
|
132
|
-
{mutation && (
|
|
133
|
-
<>
|
|
134
|
-
<File.Import name={['useMutation']} path={importPath} />
|
|
135
|
-
<File.Import name={['MutationObserverOptions', 'QueryClient']} path={importPath} isTypeOnly />
|
|
136
|
-
<Mutation
|
|
137
|
-
name={mutationHookName}
|
|
138
|
-
clientName={resolvedClientName}
|
|
139
|
-
typeName={mutationTypeName}
|
|
140
|
-
node={node}
|
|
141
|
-
tsResolver={tsResolver}
|
|
142
|
-
paramsCasing={paramsCasing}
|
|
143
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
144
|
-
paramsType={paramsType}
|
|
145
|
-
pathParamsType={pathParamsType}
|
|
146
|
-
mutationKeyName={mutationKeyName}
|
|
147
|
-
/>
|
|
148
|
-
</>
|
|
149
|
-
)}
|
|
150
|
-
</File>
|
|
151
|
-
)
|
|
152
|
-
},
|
|
153
|
-
})
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
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'
|
|
6
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
8
|
-
import { File, jsxRenderer } from '@kubb/renderer-jsx'
|
|
9
|
-
import { difference } from 'remeda'
|
|
10
|
-
import { Query, QueryKey, QueryOptions } from '../components'
|
|
11
|
-
import type { PluginVueQuery } from '../types'
|
|
12
|
-
|
|
13
|
-
export const queryGenerator = defineGenerator<PluginVueQuery>({
|
|
14
|
-
name: '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
|
|
19
|
-
|
|
20
|
-
const pluginTs = driver.getPlugin(pluginTsName)
|
|
21
|
-
if (!pluginTs) return null
|
|
22
|
-
const tsResolver = driver.getResolver(pluginTsName)
|
|
23
|
-
|
|
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())
|
|
29
|
-
|
|
30
|
-
if (!isQuery || isMutation) return null
|
|
31
|
-
|
|
32
|
-
const importPath = query ? query.importPath : '@tanstack/vue-query'
|
|
33
|
-
|
|
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)
|
|
39
|
-
|
|
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
|
-
),
|
|
46
|
-
}
|
|
47
|
-
|
|
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
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<File
|
|
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 })}
|
|
89
|
-
>
|
|
90
|
-
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
91
|
-
{clientOptions.importPath ? (
|
|
92
|
-
<>
|
|
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 />}
|
|
96
|
-
</>
|
|
97
|
-
) : (
|
|
98
|
-
<>
|
|
99
|
-
{!shouldUseClientPlugin && <File.Import name={['fetch']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} />}
|
|
100
|
-
<File.Import
|
|
101
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
102
|
-
root={meta.file.path}
|
|
103
|
-
path={path.resolve(root, '.kubb/fetch.ts')}
|
|
104
|
-
isTypeOnly
|
|
105
|
-
/>
|
|
106
|
-
{clientOptions.dataReturnType === 'full' && (
|
|
107
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} isTypeOnly />
|
|
108
|
-
)}
|
|
109
|
-
</>
|
|
110
|
-
)}
|
|
111
|
-
<File.Import name={['toValue']} path="vue" />
|
|
112
|
-
<File.Import name={['MaybeRefOrGetter']} path="vue" isTypeOnly />
|
|
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 />
|
|
117
|
-
)}
|
|
118
|
-
|
|
119
|
-
<QueryKey
|
|
120
|
-
name={queryKeyName}
|
|
121
|
-
typeName={queryKeyTypeName}
|
|
122
|
-
node={node}
|
|
123
|
-
tsResolver={tsResolver}
|
|
124
|
-
pathParamsType={pathParamsType}
|
|
125
|
-
paramsCasing={paramsCasing}
|
|
126
|
-
transformer={ctx.options.queryKey}
|
|
127
|
-
/>
|
|
128
|
-
|
|
129
|
-
{!shouldUseClientPlugin && (
|
|
130
|
-
<Client
|
|
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}
|
|
141
|
-
/>
|
|
142
|
-
)}
|
|
143
|
-
|
|
144
|
-
<File.Import name={['queryOptions']} path={importPath} />
|
|
145
|
-
|
|
146
|
-
<QueryOptions
|
|
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'}
|
|
156
|
-
/>
|
|
157
|
-
|
|
158
|
-
{query && (
|
|
159
|
-
<>
|
|
160
|
-
<File.Import name={['useQuery']} path={importPath} />
|
|
161
|
-
<File.Import name={['QueryKey', 'QueryClient', 'UseQueryOptions', 'UseQueryReturnType']} path={importPath} isTypeOnly />
|
|
162
|
-
<Query
|
|
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'}
|
|
173
|
-
/>
|
|
174
|
-
</>
|
|
175
|
-
)}
|
|
176
|
-
</File>
|
|
177
|
-
)
|
|
178
|
-
},
|
|
179
|
-
})
|
package/src/index.ts
DELETED