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