@kubb/plugin-vue-query 5.0.0-beta.42 → 5.0.0-beta.64
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/dist/{components-Bxe1EuWf.js → components-CAlEf7Oh.js} +273 -388
- package/dist/components-CAlEf7Oh.js.map +1 -0
- package/dist/{components-BwFPMwK7.cjs → components-CfU59l8V.cjs} +274 -389
- package/dist/components-CfU59l8V.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-BSN6A0ED.cjs → generators-DpMLVmyi.cjs} +91 -137
- package/dist/generators-DpMLVmyi.cjs.map +1 -0
- package/dist/{generators-D9TUvYRN.js → generators-fWBjs0CN.js} +93 -139
- package/dist/generators-fWBjs0CN.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +41 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +42 -19
- package/dist/index.js.map +1 -1
- package/dist/{types-HHnnlEhK.d.ts → types-C6a_58nb.d.ts} +12 -16
- package/package.json +10 -18
- package/dist/components-BwFPMwK7.cjs.map +0 -1
- package/dist/components-Bxe1EuWf.js.map +0 -1
- package/dist/generators-BSN6A0ED.cjs.map +0 -1
- package/dist/generators-D9TUvYRN.js.map +0 -1
- package/extension.yaml +0 -1248
- package/src/components/InfiniteQuery.tsx +0 -127
- package/src/components/InfiniteQueryOptions.tsx +0 -194
- package/src/components/Mutation.tsx +0 -150
- package/src/components/MutationKey.tsx +0 -1
- package/src/components/Query.tsx +0 -126
- package/src/components/QueryKey.tsx +0 -52
- package/src/components/QueryOptions.tsx +0 -137
- package/src/components/index.ts +0 -7
- package/src/generators/index.ts +0 -3
- package/src/generators/infiniteQueryGenerator.tsx +0 -200
- package/src/generators/mutationGenerator.tsx +0 -158
- package/src/generators/queryGenerator.tsx +0 -184
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -183
- package/src/resolvers/resolverVueQuery.ts +0 -76
- package/src/types.ts +0 -272
- package/src/utils.ts +0 -56
|
@@ -1,137 +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 { getEnabledParamNames, markParamsOptional } from '@internals/tanstack-query'
|
|
7
|
-
import type { PluginVueQuery } from '../types.ts'
|
|
8
|
-
import { resolveErrorNames, resolveSuccessNames, 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) : null
|
|
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 successNames = resolveSuccessNames(node, tsResolver)
|
|
70
|
-
const responseName = successNames.length > 0 ? successNames.join(' | ') : tsResolver.resolveResponseName(node)
|
|
71
|
-
const errorNames = resolveErrorNames(node, tsResolver)
|
|
72
|
-
|
|
73
|
-
const TData = dataReturnType === 'data' ? responseName : `ResponseConfig<${responseName}>`
|
|
74
|
-
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
75
|
-
|
|
76
|
-
const queryKeyParamsNode = buildQueryKeyParamsNode(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
77
|
-
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? ''
|
|
78
|
-
|
|
79
|
-
const enabledNames = getEnabledParamNames(queryKeyParamsNode)
|
|
80
|
-
const enabledText = enabledNames.length ? `enabled: () => ${enabledNames.map((n) => `!!toValue(${n})`).join(' && ')},` : ''
|
|
81
|
-
|
|
82
|
-
const paramsNode = markParamsOptional(getQueryOptionsParams(node, { paramsType, paramsCasing, pathParamsType, resolver: tsResolver }), enabledNames)
|
|
83
|
-
const paramsSignature = declarationPrinter.print(paramsNode) ?? ''
|
|
84
|
-
const rawParamsCall = callPrinter.print(paramsNode) ?? ''
|
|
85
|
-
|
|
86
|
-
// Transform: wrap non-config params with toValue(), add signal to config
|
|
87
|
-
const clientCallStr = rawParamsCall.replace(/\bconfig\b(?=[^,]*$)/, '{ ...config, signal: config.signal ?? signal }')
|
|
88
|
-
|
|
89
|
-
return (
|
|
90
|
-
<File.Source name={name} isExportable isIndexable>
|
|
91
|
-
<Function name={name} export params={paramsSignature}>
|
|
92
|
-
{`
|
|
93
|
-
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
94
|
-
return queryOptions<${TData}, ${TError}, ${TData}>({
|
|
95
|
-
${enabledText}
|
|
96
|
-
queryKey,
|
|
97
|
-
queryFn: async ({ signal }) => {
|
|
98
|
-
return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
|
|
99
|
-
},
|
|
100
|
-
})
|
|
101
|
-
`}
|
|
102
|
-
</Function>
|
|
103
|
-
</File.Source>
|
|
104
|
-
)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Wraps parameter names with `toValue()` in the client call string,
|
|
109
|
-
* except for 'config'-related params (which are already plain objects).
|
|
110
|
-
*
|
|
111
|
-
* Handles both inline params (`petId, config`) and object shorthand
|
|
112
|
-
* params (`{ petId }, config`) by expanding to `{ petId: toValue(petId) }`.
|
|
113
|
-
*/
|
|
114
|
-
function addToValueCalls(callStr: string, enabledNames: ReadonlyArray<string> = []): string {
|
|
115
|
-
const optional = new Set(enabledNames)
|
|
116
|
-
// Step 1: Transform shorthand object params like { petId } → { petId: toValue(petId) }
|
|
117
|
-
// Params that drive the `enabled` guard are optional, so assert non-null: toValue(petId!)
|
|
118
|
-
let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner: string) => {
|
|
119
|
-
// Only transform simple shorthand (no colons, no spread)
|
|
120
|
-
if (inner.includes(':') || inner.includes('...')) return match
|
|
121
|
-
const keys = inner
|
|
122
|
-
.split(',')
|
|
123
|
-
.map((k: string) => k.trim())
|
|
124
|
-
.filter(Boolean)
|
|
125
|
-
const wrapped = keys.map((k: string) => `${k}: toValue(${optional.has(k) ? `${k}!` : k})`).join(', ')
|
|
126
|
-
return `{ ${wrapped} }`
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
// Step 2: Handle standalone identifiers like `data, params`
|
|
130
|
-
result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name: string) => {
|
|
131
|
-
if (name === 'config' || name === 'signal' || name === 'undefined') return match
|
|
132
|
-
if (match.includes('toValue(')) return match
|
|
133
|
-
return `toValue(${optional.has(name) ? `${name}!` : name})`
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
return result
|
|
137
|
-
}
|
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,200 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { getOperationParameters, operationFileEntry, resolveOperationTypeNames } from '@internals/shared'
|
|
3
|
-
import { resolveZodSchemaNames } from '@internals/tanstack-query'
|
|
4
|
-
import { ast, 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, jsxRendererSync } from '@kubb/renderer-jsx'
|
|
9
|
-
import { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components'
|
|
10
|
-
import type { PluginVueQuery } from '../types'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Built-in generator for `useInfiniteQuery` composables. Enabled when
|
|
14
|
-
* `pluginVueQuery({ infinite: { ... } })`. Emits one `useFooInfiniteQuery`
|
|
15
|
-
* composable per query operation, wiring the configured cursor path into
|
|
16
|
-
* TanStack Query's cursor-based pagination.
|
|
17
|
-
*/
|
|
18
|
-
export const infiniteQueryGenerator = defineGenerator<PluginVueQuery>({
|
|
19
|
-
name: 'vue-query-infinite',
|
|
20
|
-
renderer: jsxRendererSync,
|
|
21
|
-
operation(node, ctx) {
|
|
22
|
-
if (!ast.isHttpOperationNode(node)) return null
|
|
23
|
-
const { config, driver, resolver, root } = ctx
|
|
24
|
-
const { output, query, mutation, infinite, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group } = ctx.options
|
|
25
|
-
|
|
26
|
-
const pluginTs = driver.getPlugin(pluginTsName)
|
|
27
|
-
if (!pluginTs) return null
|
|
28
|
-
const tsResolver = driver.getResolver(pluginTsName)
|
|
29
|
-
|
|
30
|
-
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
31
|
-
const queryMethods = new Set(query ? query.methods : [])
|
|
32
|
-
const isMutation =
|
|
33
|
-
mutation !== false &&
|
|
34
|
-
!isQuery &&
|
|
35
|
-
(mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
|
|
36
|
-
const infiniteOptions = infinite && typeof infinite === 'object' ? infinite : null
|
|
37
|
-
|
|
38
|
-
if (!isQuery || isMutation || !infiniteOptions) return null
|
|
39
|
-
|
|
40
|
-
// Validate queryParam exists in operation's query parameters
|
|
41
|
-
const normalizeKey = (key: string) => key.replace(/\?$/, '')
|
|
42
|
-
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name)
|
|
43
|
-
const hasQueryParam = infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false
|
|
44
|
-
// cursorParam validation against response schema keys is skipped in v5 (complex schema inspection)
|
|
45
|
-
const hasCursorParam = !infiniteOptions.cursorParam || true
|
|
46
|
-
|
|
47
|
-
if (!hasQueryParam || !hasCursorParam) return null
|
|
48
|
-
|
|
49
|
-
const importPath = query ? query.importPath : '@tanstack/vue-query'
|
|
50
|
-
|
|
51
|
-
const queryName = resolver.resolveInfiniteQueryName(node)
|
|
52
|
-
const queryOptionsName = resolver.resolveInfiniteQueryOptionsName(node)
|
|
53
|
-
const queryKeyName = resolver.resolveInfiniteQueryKeyName(node)
|
|
54
|
-
const queryKeyTypeName = resolver.resolveInfiniteQueryKeyTypeName(node)
|
|
55
|
-
const clientBaseName = resolver.resolveInfiniteClientName(node)
|
|
56
|
-
|
|
57
|
-
const meta = {
|
|
58
|
-
file: resolver.resolveFile(operationFileEntry(node, queryName), { root, output, group: group ?? undefined }),
|
|
59
|
-
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
60
|
-
root,
|
|
61
|
-
output: pluginTs.options?.output ?? output,
|
|
62
|
-
group: pluginTs.options?.group ?? undefined,
|
|
63
|
-
}),
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
67
|
-
paramsCasing,
|
|
68
|
-
exclude: [queryKeyTypeName],
|
|
69
|
-
order: 'body-response-first',
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : null
|
|
73
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null
|
|
74
|
-
const fileZod = zodResolver
|
|
75
|
-
? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
76
|
-
root,
|
|
77
|
-
output: pluginZod?.options?.output ?? output,
|
|
78
|
-
group: pluginZod?.options?.group ?? undefined,
|
|
79
|
-
})
|
|
80
|
-
: null
|
|
81
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
|
|
82
|
-
|
|
83
|
-
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
84
|
-
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
85
|
-
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
86
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null
|
|
87
|
-
|
|
88
|
-
const clientFile = shouldUseClientPlugin
|
|
89
|
-
? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
90
|
-
root,
|
|
91
|
-
output: clientPlugin?.options?.output ?? output,
|
|
92
|
-
group: clientPlugin?.options?.group ?? undefined,
|
|
93
|
-
})
|
|
94
|
-
: null
|
|
95
|
-
|
|
96
|
-
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientBaseName) : clientBaseName
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
<File
|
|
100
|
-
baseName={meta.file.baseName}
|
|
101
|
-
path={meta.file.path}
|
|
102
|
-
meta={meta.file.meta}
|
|
103
|
-
banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
104
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
105
|
-
>
|
|
106
|
-
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
107
|
-
{clientOptions.importPath ? (
|
|
108
|
-
<>
|
|
109
|
-
{!shouldUseClientPlugin && <File.Import name={'client'} path={clientOptions.importPath} />}
|
|
110
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
111
|
-
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
112
|
-
</>
|
|
113
|
-
) : (
|
|
114
|
-
<>
|
|
115
|
-
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
116
|
-
<File.Import
|
|
117
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
118
|
-
root={meta.file.path}
|
|
119
|
-
path={path.resolve(root, '.kubb/client.ts')}
|
|
120
|
-
isTypeOnly
|
|
121
|
-
/>
|
|
122
|
-
{clientOptions.dataReturnType === 'full' && (
|
|
123
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} isTypeOnly />
|
|
124
|
-
)}
|
|
125
|
-
</>
|
|
126
|
-
)}
|
|
127
|
-
<File.Import name={['toValue']} path="vue" />
|
|
128
|
-
<File.Import name={['MaybeRefOrGetter']} path="vue" isTypeOnly />
|
|
129
|
-
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
130
|
-
{!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
|
|
131
|
-
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
132
|
-
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
133
|
-
)}
|
|
134
|
-
|
|
135
|
-
<QueryKey
|
|
136
|
-
name={queryKeyName}
|
|
137
|
-
typeName={queryKeyTypeName}
|
|
138
|
-
node={node}
|
|
139
|
-
tsResolver={tsResolver}
|
|
140
|
-
pathParamsType={pathParamsType}
|
|
141
|
-
paramsCasing={paramsCasing}
|
|
142
|
-
transformer={ctx.options.queryKey}
|
|
143
|
-
/>
|
|
144
|
-
|
|
145
|
-
{!shouldUseClientPlugin && (
|
|
146
|
-
<Client
|
|
147
|
-
name={resolvedClientName}
|
|
148
|
-
baseURL={clientOptions.baseURL}
|
|
149
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
150
|
-
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
151
|
-
paramsType={paramsType}
|
|
152
|
-
pathParamsType={pathParamsType}
|
|
153
|
-
parser={parser}
|
|
154
|
-
node={node}
|
|
155
|
-
tsResolver={tsResolver}
|
|
156
|
-
zodResolver={zodResolver}
|
|
157
|
-
/>
|
|
158
|
-
)}
|
|
159
|
-
|
|
160
|
-
<File.Import name={['InfiniteData']} isTypeOnly path={importPath} />
|
|
161
|
-
<File.Import name={['infiniteQueryOptions']} path={importPath} />
|
|
162
|
-
|
|
163
|
-
<InfiniteQueryOptions
|
|
164
|
-
name={queryOptionsName}
|
|
165
|
-
clientName={resolvedClientName}
|
|
166
|
-
queryKeyName={queryKeyName}
|
|
167
|
-
node={node}
|
|
168
|
-
tsResolver={tsResolver}
|
|
169
|
-
paramsCasing={paramsCasing}
|
|
170
|
-
paramsType={paramsType}
|
|
171
|
-
pathParamsType={pathParamsType}
|
|
172
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
173
|
-
cursorParam={infiniteOptions.cursorParam}
|
|
174
|
-
nextParam={infiniteOptions.nextParam}
|
|
175
|
-
previousParam={infiniteOptions.previousParam}
|
|
176
|
-
initialPageParam={infiniteOptions.initialPageParam}
|
|
177
|
-
queryParam={infiniteOptions.queryParam}
|
|
178
|
-
/>
|
|
179
|
-
|
|
180
|
-
<File.Import name={['useInfiniteQuery']} path={importPath} />
|
|
181
|
-
<File.Import name={['QueryKey', 'QueryClient', 'UseInfiniteQueryOptions', 'UseInfiniteQueryReturnType']} path={importPath} isTypeOnly />
|
|
182
|
-
|
|
183
|
-
<InfiniteQuery
|
|
184
|
-
name={queryName}
|
|
185
|
-
queryOptionsName={queryOptionsName}
|
|
186
|
-
queryKeyName={queryKeyName}
|
|
187
|
-
queryKeyTypeName={queryKeyTypeName}
|
|
188
|
-
node={node}
|
|
189
|
-
tsResolver={tsResolver}
|
|
190
|
-
paramsCasing={paramsCasing}
|
|
191
|
-
paramsType={paramsType}
|
|
192
|
-
pathParamsType={pathParamsType}
|
|
193
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
194
|
-
initialPageParam={infiniteOptions.initialPageParam}
|
|
195
|
-
queryParam={infiniteOptions.queryParam}
|
|
196
|
-
/>
|
|
197
|
-
</File>
|
|
198
|
-
)
|
|
199
|
-
},
|
|
200
|
-
})
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { operationFileEntry, resolveOperationTypeNames } from '@internals/shared'
|
|
3
|
-
import { resolveZodSchemaNames } from '@internals/tanstack-query'
|
|
4
|
-
import { ast, 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, jsxRendererSync } from '@kubb/renderer-jsx'
|
|
9
|
-
import { Mutation, MutationKey } from '../components'
|
|
10
|
-
import type { PluginVueQuery } from '../types'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Built-in generator for `useMutation` composables. Emits one
|
|
14
|
-
* `useFooMutation` composable per POST/PUT/DELETE operation (configurable
|
|
15
|
-
* via `mutation.methods`) plus the matching `fooMutationKey` helper.
|
|
16
|
-
*/
|
|
17
|
-
export const mutationGenerator = defineGenerator<PluginVueQuery>({
|
|
18
|
-
name: 'vue-query-mutation',
|
|
19
|
-
renderer: jsxRendererSync,
|
|
20
|
-
operation(node, ctx) {
|
|
21
|
-
if (!ast.isHttpOperationNode(node)) return null
|
|
22
|
-
const { config, driver, resolver, root } = ctx
|
|
23
|
-
const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group } = ctx.options
|
|
24
|
-
|
|
25
|
-
const pluginTs = driver.getPlugin(pluginTsName)
|
|
26
|
-
if (!pluginTs) return null
|
|
27
|
-
const tsResolver = driver.getResolver(pluginTsName)
|
|
28
|
-
|
|
29
|
-
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
30
|
-
const queryMethods = new Set(query ? query.methods : [])
|
|
31
|
-
const isMutation =
|
|
32
|
-
mutation !== false &&
|
|
33
|
-
!isQuery &&
|
|
34
|
-
(mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
|
|
35
|
-
|
|
36
|
-
if (!isMutation) return null
|
|
37
|
-
|
|
38
|
-
const importPath = mutation ? mutation.importPath : '@tanstack/vue-query'
|
|
39
|
-
|
|
40
|
-
const mutationHookName = resolver.resolveMutationName(node)
|
|
41
|
-
const mutationTypeName = resolver.resolveMutationTypeName(node)
|
|
42
|
-
const mutationKeyName = resolver.resolveMutationKeyName(node)
|
|
43
|
-
const clientName = resolver.resolveClientName(node)
|
|
44
|
-
|
|
45
|
-
const meta = {
|
|
46
|
-
file: resolver.resolveFile(operationFileEntry(node, mutationHookName), { root, output, group: group ?? undefined }),
|
|
47
|
-
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
48
|
-
root,
|
|
49
|
-
output: pluginTs.options?.output ?? output,
|
|
50
|
-
group: pluginTs.options?.group ?? undefined,
|
|
51
|
-
}),
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, { paramsCasing, order: 'body-response-first' })
|
|
55
|
-
|
|
56
|
-
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : null
|
|
57
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null
|
|
58
|
-
const fileZod = zodResolver
|
|
59
|
-
? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
60
|
-
root,
|
|
61
|
-
output: pluginZod?.options?.output ?? output,
|
|
62
|
-
group: pluginZod?.options?.group ?? undefined,
|
|
63
|
-
})
|
|
64
|
-
: null
|
|
65
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
|
|
66
|
-
|
|
67
|
-
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
68
|
-
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
69
|
-
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
70
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null
|
|
71
|
-
|
|
72
|
-
const clientFile = shouldUseClientPlugin
|
|
73
|
-
? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
74
|
-
root,
|
|
75
|
-
output: clientPlugin?.options?.output ?? output,
|
|
76
|
-
group: clientPlugin?.options?.group ?? undefined,
|
|
77
|
-
})
|
|
78
|
-
: null
|
|
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(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
88
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
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={'client'} 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={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
100
|
-
<File.Import
|
|
101
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
102
|
-
root={meta.file.path}
|
|
103
|
-
path={path.resolve(root, '.kubb/client.ts')}
|
|
104
|
-
isTypeOnly
|
|
105
|
-
/>
|
|
106
|
-
{clientOptions.dataReturnType === 'full' && (
|
|
107
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} isTypeOnly />
|
|
108
|
-
)}
|
|
109
|
-
</>
|
|
110
|
-
)}
|
|
111
|
-
<File.Import name={['MaybeRefOrGetter']} path="vue" isTypeOnly />
|
|
112
|
-
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
113
|
-
{!shouldUseClientPlugin && node.requestBody?.content?.some((e) => e.contentType === 'multipart/form-data') && (
|
|
114
|
-
<File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />
|
|
115
|
-
)}
|
|
116
|
-
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
117
|
-
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
118
|
-
)}
|
|
119
|
-
|
|
120
|
-
<MutationKey name={mutationKeyName} node={node} pathParamsType={pathParamsType} paramsCasing={paramsCasing} transformer={ctx.options.mutationKey} />
|
|
121
|
-
|
|
122
|
-
{!shouldUseClientPlugin && (
|
|
123
|
-
<Client
|
|
124
|
-
name={resolvedClientName}
|
|
125
|
-
baseURL={clientOptions.baseURL}
|
|
126
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
127
|
-
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
128
|
-
paramsType={paramsType}
|
|
129
|
-
pathParamsType={pathParamsType}
|
|
130
|
-
parser={parser}
|
|
131
|
-
node={node}
|
|
132
|
-
tsResolver={tsResolver}
|
|
133
|
-
zodResolver={zodResolver}
|
|
134
|
-
/>
|
|
135
|
-
)}
|
|
136
|
-
|
|
137
|
-
{mutation && (
|
|
138
|
-
<>
|
|
139
|
-
<File.Import name={['useMutation']} path={importPath} />
|
|
140
|
-
<File.Import name={['MutationObserverOptions', 'QueryClient']} path={importPath} isTypeOnly />
|
|
141
|
-
<Mutation
|
|
142
|
-
name={mutationHookName}
|
|
143
|
-
clientName={resolvedClientName}
|
|
144
|
-
typeName={mutationTypeName}
|
|
145
|
-
node={node}
|
|
146
|
-
tsResolver={tsResolver}
|
|
147
|
-
paramsCasing={paramsCasing}
|
|
148
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
149
|
-
paramsType={paramsType}
|
|
150
|
-
pathParamsType={pathParamsType}
|
|
151
|
-
mutationKeyName={mutationKeyName}
|
|
152
|
-
/>
|
|
153
|
-
</>
|
|
154
|
-
)}
|
|
155
|
-
</File>
|
|
156
|
-
)
|
|
157
|
-
},
|
|
158
|
-
})
|