@kubb/plugin-vue-query 5.0.0-beta.22 → 5.0.0-beta.25
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-DycYiYNM.cjs → components-CeZrYaZj.cjs} +35 -35
- package/dist/components-CeZrYaZj.cjs.map +1 -0
- package/dist/{components-CARlYXLX.js → components-CpTXuQiK.js} +35 -35
- package/dist/components-CpTXuQiK.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +3 -3
- package/dist/components.js +1 -1
- package/dist/{generators-DX8VWz4a.cjs → generators-BSMwPpbh.cjs} +46 -30
- package/dist/generators-BSMwPpbh.cjs.map +1 -0
- package/dist/{generators-BuDRi6qN.js → generators-Cb5_nhMY.js} +46 -30
- package/dist/generators-Cb5_nhMY.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +17 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +47 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +47 -8
- package/dist/index.js.map +1 -1
- package/dist/{types-Bkm7bWT3.d.ts → types-D-LjzI_Q.d.ts} +73 -46
- package/extension.yaml +779 -255
- package/package.json +7 -7
- package/src/components/InfiniteQuery.tsx +1 -1
- package/src/components/InfiniteQueryOptions.tsx +8 -8
- package/src/components/Mutation.tsx +2 -2
- package/src/components/Query.tsx +1 -1
- package/src/components/QueryKey.tsx +3 -3
- package/src/components/QueryOptions.tsx +1 -1
- package/src/generators/infiniteQueryGenerator.tsx +19 -10
- package/src/generators/mutationGenerator.tsx +17 -9
- package/src/generators/queryGenerator.tsx +17 -9
- package/src/plugin.ts +32 -4
- package/src/resolvers/resolverVueQuery.ts +13 -2
- package/src/types.ts +72 -45
- package/dist/components-CARlYXLX.js.map +0 -1
- package/dist/components-DycYiYNM.cjs.map +0 -1
- package/dist/generators-BuDRi6qN.js.map +0 -1
- package/dist/generators-DX8VWz4a.cjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-vue-query",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.25",
|
|
4
4
|
"description": "Generate type-safe TanStack Query (Vue Query) composables from your OpenAPI specification. Covers useQuery, useMutation, useInfiniteQuery, and queryOptions with Vue 3 Composition API support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code-generation",
|
|
@@ -70,12 +70,12 @@
|
|
|
70
70
|
"registry": "https://registry.npmjs.org/"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@kubb/core": "5.0.0-beta.
|
|
74
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
73
|
+
"@kubb/core": "5.0.0-beta.25",
|
|
74
|
+
"@kubb/renderer-jsx": "5.0.0-beta.25",
|
|
75
75
|
"remeda": "^2.34.1",
|
|
76
|
-
"@kubb/plugin-client": "5.0.0-beta.
|
|
77
|
-
"@kubb/plugin-ts": "5.0.0-beta.
|
|
78
|
-
"@kubb/plugin-zod": "5.0.0-beta.
|
|
76
|
+
"@kubb/plugin-client": "5.0.0-beta.25",
|
|
77
|
+
"@kubb/plugin-ts": "5.0.0-beta.25",
|
|
78
|
+
"@kubb/plugin-zod": "5.0.0-beta.25"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@internals/shared": "0.0.0",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"@internals/utils": "0.0.0"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
86
|
+
"@kubb/renderer-jsx": "5.0.0-beta.25"
|
|
87
87
|
},
|
|
88
88
|
"size-limit": [
|
|
89
89
|
{
|
|
@@ -38,7 +38,7 @@ function buildInfiniteQueryParamsNode(
|
|
|
38
38
|
): ast.FunctionParametersNode {
|
|
39
39
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options
|
|
40
40
|
const responseName = resolver.resolveResponseName(node)
|
|
41
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
41
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null
|
|
42
42
|
const errorNames = resolveErrorNames(node, resolver)
|
|
43
43
|
|
|
44
44
|
const TData = dataReturnType === 'data' ? responseName : `ResponseConfig<${responseName}>`
|
|
@@ -73,11 +73,11 @@ export function InfiniteQueryOptions({
|
|
|
73
73
|
? (() => {
|
|
74
74
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]!)
|
|
75
75
|
const individualName = tsResolver.resolveParamName(node, rawQueryParams[0]!)
|
|
76
|
-
return groupName !== individualName ? groupName :
|
|
76
|
+
return groupName !== individualName ? groupName : null
|
|
77
77
|
})()
|
|
78
|
-
:
|
|
78
|
+
: null
|
|
79
79
|
|
|
80
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
80
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null
|
|
81
81
|
const pageParamType = queryParamType ? (isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType) : fallbackPageParamType
|
|
82
82
|
|
|
83
83
|
const paramsNode = getQueryOptionsParams(node, { paramsType, paramsCasing, pathParamsType, resolver: tsResolver })
|
|
@@ -96,15 +96,15 @@ export function InfiniteQueryOptions({
|
|
|
96
96
|
.join(' && ')},`
|
|
97
97
|
: ''
|
|
98
98
|
|
|
99
|
-
const hasNewParams = nextParam
|
|
99
|
+
const hasNewParams = nextParam != null || previousParam != null
|
|
100
100
|
|
|
101
101
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
102
102
|
if (hasNewParams) {
|
|
103
|
-
const nextAccessor = nextParam ? getNestedAccessor(nextParam, 'lastPage') :
|
|
104
|
-
const prevAccessor = previousParam ? getNestedAccessor(previousParam, 'firstPage') :
|
|
103
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, 'lastPage') : null
|
|
104
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, 'firstPage') : null
|
|
105
105
|
return [
|
|
106
|
-
nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` :
|
|
107
|
-
prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` :
|
|
106
|
+
nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null,
|
|
107
|
+
prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null,
|
|
108
108
|
] as const
|
|
109
109
|
}
|
|
110
110
|
if (cursorParam) {
|
|
@@ -65,7 +65,7 @@ function buildMutationParamsNode(
|
|
|
65
65
|
type: ast.createParamsType({
|
|
66
66
|
variant: 'reference',
|
|
67
67
|
name: `{
|
|
68
|
-
mutation?: MutationObserverOptions<${[TData, TError, TRequestWrapped ? `{${TRequestWrapped}}` : '
|
|
68
|
+
mutation?: MutationObserverOptions<${[TData, TError, TRequestWrapped ? `{${TRequestWrapped}}` : 'undefined', 'TContext'].join(', ')}> & { client?: QueryClient },
|
|
69
69
|
client?: ${buildRequestConfigType(node, resolver)},
|
|
70
70
|
}`,
|
|
71
71
|
}),
|
|
@@ -100,7 +100,7 @@ export function Mutation({
|
|
|
100
100
|
const TRequest = hasMutationParams ? (declarationPrinter.print(mutationArgParamsNode) ?? '') : ''
|
|
101
101
|
const argKeysStr = hasMutationParams ? (keysPrinter.print(mutationArgParamsNode) ?? '') : ''
|
|
102
102
|
|
|
103
|
-
const generics = [TData, TError, TRequest ? `{${TRequest}}` : '
|
|
103
|
+
const generics = [TData, TError, TRequest ? `{${TRequest}}` : 'undefined', 'TContext'].join(', ')
|
|
104
104
|
|
|
105
105
|
const mutationKeyParamsNode = ast.createFunctionParameters({ params: [] })
|
|
106
106
|
const mutationKeyParamsCall = callPrinter.print(mutationKeyParamsNode) ?? ''
|
package/src/components/Query.tsx
CHANGED
|
@@ -36,7 +36,7 @@ function buildQueryParamsNode(
|
|
|
36
36
|
): ast.FunctionParametersNode {
|
|
37
37
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options
|
|
38
38
|
const responseName = resolver.resolveResponseName(node)
|
|
39
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
39
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null
|
|
40
40
|
const errorNames = resolveErrorNames(node, resolver)
|
|
41
41
|
|
|
42
42
|
const TData = dataReturnType === 'data' ? responseName : `ResponseConfig<${responseName}>`
|
|
@@ -14,7 +14,7 @@ type Props = {
|
|
|
14
14
|
tsResolver: ResolverTs
|
|
15
15
|
paramsCasing: 'camelcase' | undefined
|
|
16
16
|
pathParamsType: 'object' | 'inline'
|
|
17
|
-
transformer: Transformer | undefined
|
|
17
|
+
transformer: Transformer | null | undefined
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const declarationPrinter = functionPrinter({ mode: 'declaration' })
|
|
@@ -26,10 +26,10 @@ export function buildQueryKeyParamsNode(
|
|
|
26
26
|
return wrapWithMaybeRefOrGetter(buildQueryKeyParams(node, options))
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer
|
|
29
|
+
export function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }: Props): KubbReactNode {
|
|
30
30
|
const paramsNode = buildQueryKeyParamsNode(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
31
31
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? ''
|
|
32
|
-
const keys = transformer({
|
|
32
|
+
const keys = (transformer ?? queryKeyTransformer)({
|
|
33
33
|
node,
|
|
34
34
|
casing: paramsCasing,
|
|
35
35
|
})
|
|
@@ -33,7 +33,7 @@ export function getQueryOptionsParams(
|
|
|
33
33
|
},
|
|
34
34
|
): ast.FunctionParametersNode {
|
|
35
35
|
const { paramsType, paramsCasing, pathParamsType, resolver } = options
|
|
36
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
36
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null
|
|
37
37
|
|
|
38
38
|
const baseParams = ast.createOperationParams(node, {
|
|
39
39
|
paramsType,
|
|
@@ -10,6 +10,12 @@ import { difference } from 'remeda'
|
|
|
10
10
|
import { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components'
|
|
11
11
|
import type { PluginVueQuery } from '../types'
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Built-in generator for `useInfiniteQuery` composables. Enabled when
|
|
15
|
+
* `pluginVueQuery({ infinite: { ... } })`. Emits one `useFooInfiniteQuery`
|
|
16
|
+
* composable per query operation, wiring the configured cursor path into
|
|
17
|
+
* TanStack Query's cursor-based pagination.
|
|
18
|
+
*/
|
|
13
19
|
export const infiniteQueryGenerator = defineGenerator<PluginVueQuery>({
|
|
14
20
|
name: 'vue-query-infinite',
|
|
15
21
|
renderer: jsxRendererSync,
|
|
@@ -26,7 +32,7 @@ export const infiniteQueryGenerator = defineGenerator<PluginVueQuery>({
|
|
|
26
32
|
mutation !== false &&
|
|
27
33
|
!isQuery &&
|
|
28
34
|
difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase())
|
|
29
|
-
const infiniteOptions = infinite && typeof infinite === 'object' ? infinite :
|
|
35
|
+
const infiniteOptions = infinite && typeof infinite === 'object' ? infinite : null
|
|
30
36
|
|
|
31
37
|
if (!isQuery || isMutation || !infiniteOptions) return null
|
|
32
38
|
|
|
@@ -48,10 +54,13 @@ export const infiniteQueryGenerator = defineGenerator<PluginVueQuery>({
|
|
|
48
54
|
const clientBaseName = resolver.resolveInfiniteClientName(node)
|
|
49
55
|
|
|
50
56
|
const meta = {
|
|
51
|
-
file: resolver.resolveFile(
|
|
57
|
+
file: resolver.resolveFile(
|
|
58
|
+
{ name: queryName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
59
|
+
{ root, output, group: group ?? undefined },
|
|
60
|
+
),
|
|
52
61
|
fileTs: tsResolver.resolveFile(
|
|
53
62
|
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
54
|
-
{ root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group },
|
|
63
|
+
{ root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group ?? undefined },
|
|
55
64
|
),
|
|
56
65
|
}
|
|
57
66
|
|
|
@@ -61,20 +70,20 @@ export const infiniteQueryGenerator = defineGenerator<PluginVueQuery>({
|
|
|
61
70
|
order: 'body-response-first',
|
|
62
71
|
})
|
|
63
72
|
|
|
64
|
-
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) :
|
|
65
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) :
|
|
73
|
+
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : null
|
|
74
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null
|
|
66
75
|
const fileZod = zodResolver
|
|
67
76
|
? zodResolver.resolveFile(
|
|
68
77
|
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
69
|
-
{ root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
|
|
78
|
+
{ root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group ?? undefined },
|
|
70
79
|
)
|
|
71
|
-
:
|
|
80
|
+
: null
|
|
72
81
|
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
|
|
73
82
|
|
|
74
83
|
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
75
84
|
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
76
85
|
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
77
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) :
|
|
86
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null
|
|
78
87
|
|
|
79
88
|
const clientFile = shouldUseClientPlugin
|
|
80
89
|
? clientResolver?.resolveFile(
|
|
@@ -82,10 +91,10 @@ export const infiniteQueryGenerator = defineGenerator<PluginVueQuery>({
|
|
|
82
91
|
{
|
|
83
92
|
root,
|
|
84
93
|
output: clientPlugin?.options?.output ?? output,
|
|
85
|
-
group: clientPlugin?.options?.group,
|
|
94
|
+
group: clientPlugin?.options?.group ?? undefined,
|
|
86
95
|
},
|
|
87
96
|
)
|
|
88
|
-
:
|
|
97
|
+
: null
|
|
89
98
|
|
|
90
99
|
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientBaseName) : clientBaseName
|
|
91
100
|
|
|
@@ -10,6 +10,11 @@ import { difference } from 'remeda'
|
|
|
10
10
|
import { Mutation, MutationKey } from '../components'
|
|
11
11
|
import type { PluginVueQuery } from '../types'
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Built-in generator for `useMutation` composables. Emits one
|
|
15
|
+
* `useFooMutation` composable per POST/PUT/DELETE operation (configurable
|
|
16
|
+
* via `mutation.methods`) plus the matching `fooMutationKey` helper.
|
|
17
|
+
*/
|
|
13
18
|
export const mutationGenerator = defineGenerator<PluginVueQuery>({
|
|
14
19
|
name: 'vue-query-mutation',
|
|
15
20
|
renderer: jsxRendererSync,
|
|
@@ -37,29 +42,32 @@ export const mutationGenerator = defineGenerator<PluginVueQuery>({
|
|
|
37
42
|
const clientName = resolver.resolveClientName(node)
|
|
38
43
|
|
|
39
44
|
const meta = {
|
|
40
|
-
file: resolver.resolveFile(
|
|
45
|
+
file: resolver.resolveFile(
|
|
46
|
+
{ name: mutationHookName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
47
|
+
{ root, output, group: group ?? undefined },
|
|
48
|
+
),
|
|
41
49
|
fileTs: tsResolver.resolveFile(
|
|
42
50
|
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
43
|
-
{ root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group },
|
|
51
|
+
{ root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group ?? undefined },
|
|
44
52
|
),
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, { paramsCasing, order: 'body-response-first' })
|
|
48
56
|
|
|
49
|
-
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) :
|
|
50
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) :
|
|
57
|
+
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : null
|
|
58
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null
|
|
51
59
|
const fileZod = zodResolver
|
|
52
60
|
? zodResolver.resolveFile(
|
|
53
61
|
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
54
|
-
{ root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
|
|
62
|
+
{ root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group ?? undefined },
|
|
55
63
|
)
|
|
56
|
-
:
|
|
64
|
+
: null
|
|
57
65
|
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
|
|
58
66
|
|
|
59
67
|
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
60
68
|
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
61
69
|
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
62
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) :
|
|
70
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null
|
|
63
71
|
|
|
64
72
|
const clientFile = shouldUseClientPlugin
|
|
65
73
|
? clientResolver?.resolveFile(
|
|
@@ -67,10 +75,10 @@ export const mutationGenerator = defineGenerator<PluginVueQuery>({
|
|
|
67
75
|
{
|
|
68
76
|
root,
|
|
69
77
|
output: clientPlugin?.options?.output ?? output,
|
|
70
|
-
group: clientPlugin?.options?.group,
|
|
78
|
+
group: clientPlugin?.options?.group ?? undefined,
|
|
71
79
|
},
|
|
72
80
|
)
|
|
73
|
-
:
|
|
81
|
+
: null
|
|
74
82
|
|
|
75
83
|
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientName) : clientName
|
|
76
84
|
|
|
@@ -10,6 +10,11 @@ import { difference } from 'remeda'
|
|
|
10
10
|
import { Query, QueryKey, QueryOptions } from '../components'
|
|
11
11
|
import type { PluginVueQuery } from '../types'
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Built-in generator for `useQuery` composables. Emits one `useFooQuery`
|
|
15
|
+
* composable per GET operation (configurable via `query.methods`) plus the
|
|
16
|
+
* matching `fooQueryKey` / `fooQueryOptions` helpers.
|
|
17
|
+
*/
|
|
13
18
|
export const queryGenerator = defineGenerator<PluginVueQuery>({
|
|
14
19
|
name: 'vue-query',
|
|
15
20
|
renderer: jsxRendererSync,
|
|
@@ -38,10 +43,13 @@ export const queryGenerator = defineGenerator<PluginVueQuery>({
|
|
|
38
43
|
const clientName = resolver.resolveClientName(node)
|
|
39
44
|
|
|
40
45
|
const meta = {
|
|
41
|
-
file: resolver.resolveFile(
|
|
46
|
+
file: resolver.resolveFile(
|
|
47
|
+
{ name: queryName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
48
|
+
{ root, output, group: group ?? undefined },
|
|
49
|
+
),
|
|
42
50
|
fileTs: tsResolver.resolveFile(
|
|
43
51
|
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
44
|
-
{ root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group },
|
|
52
|
+
{ root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group ?? undefined },
|
|
45
53
|
),
|
|
46
54
|
}
|
|
47
55
|
|
|
@@ -51,20 +59,20 @@ export const queryGenerator = defineGenerator<PluginVueQuery>({
|
|
|
51
59
|
order: 'body-response-first',
|
|
52
60
|
})
|
|
53
61
|
|
|
54
|
-
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) :
|
|
55
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) :
|
|
62
|
+
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : null
|
|
63
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null
|
|
56
64
|
const fileZod = zodResolver
|
|
57
65
|
? zodResolver.resolveFile(
|
|
58
66
|
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
59
|
-
{ root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
|
|
67
|
+
{ root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group ?? undefined },
|
|
60
68
|
)
|
|
61
|
-
:
|
|
69
|
+
: null
|
|
62
70
|
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
|
|
63
71
|
|
|
64
72
|
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
65
73
|
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
66
74
|
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
67
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) :
|
|
75
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null
|
|
68
76
|
|
|
69
77
|
const clientFile = shouldUseClientPlugin
|
|
70
78
|
? clientResolver?.resolveFile(
|
|
@@ -72,10 +80,10 @@ export const queryGenerator = defineGenerator<PluginVueQuery>({
|
|
|
72
80
|
{
|
|
73
81
|
root,
|
|
74
82
|
output: clientPlugin?.options?.output ?? output,
|
|
75
|
-
group: clientPlugin?.options?.group,
|
|
83
|
+
group: clientPlugin?.options?.group ?? undefined,
|
|
76
84
|
},
|
|
77
85
|
)
|
|
78
|
-
:
|
|
86
|
+
: null
|
|
79
87
|
|
|
80
88
|
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientName) : clientName
|
|
81
89
|
|
package/src/plugin.ts
CHANGED
|
@@ -13,8 +13,36 @@ import { infiniteQueryGenerator, mutationGenerator, queryGenerator } from './gen
|
|
|
13
13
|
import { resolverVueQuery } from './resolvers/resolverVueQuery.ts'
|
|
14
14
|
import type { PluginVueQuery } from './types.ts'
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Canonical plugin name for `@kubb/plugin-vue-query`. Used for driver lookups
|
|
18
|
+
* and cross-plugin dependency references.
|
|
19
|
+
*/
|
|
16
20
|
export const pluginVueQueryName = 'plugin-vue-query' satisfies PluginVueQuery['name']
|
|
17
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Generates one TanStack Query composable per OpenAPI operation for Vue's
|
|
24
|
+
* Composition API. Queries become `useFooQuery` (and optionally
|
|
25
|
+
* `useFooInfiniteQuery`); mutations become `useFooMutation`. Each composable
|
|
26
|
+
* is fully typed end to end.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { defineConfig } from 'kubb'
|
|
31
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
32
|
+
* import { pluginVueQuery } from '@kubb/plugin-vue-query'
|
|
33
|
+
*
|
|
34
|
+
* export default defineConfig({
|
|
35
|
+
* input: { path: './petStore.yaml' },
|
|
36
|
+
* output: { path: './src/gen' },
|
|
37
|
+
* plugins: [
|
|
38
|
+
* pluginTs(),
|
|
39
|
+
* pluginVueQuery({
|
|
40
|
+
* output: { path: './hooks' },
|
|
41
|
+
* }),
|
|
42
|
+
* ],
|
|
43
|
+
* })
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
18
46
|
export const pluginVueQuery = definePlugin<PluginVueQuery>((options) => {
|
|
19
47
|
const {
|
|
20
48
|
output = { path: 'hooks', barrelType: 'named' },
|
|
@@ -56,7 +84,7 @@ export const pluginVueQuery = definePlugin<PluginVueQuery>((options) => {
|
|
|
56
84
|
return `${camelCase(ctx.group)}Controller`
|
|
57
85
|
},
|
|
58
86
|
} satisfies Group)
|
|
59
|
-
:
|
|
87
|
+
: null
|
|
60
88
|
|
|
61
89
|
return {
|
|
62
90
|
name: pluginVueQueryName,
|
|
@@ -99,9 +127,9 @@ export const pluginVueQuery = definePlugin<PluginVueQuery>((options) => {
|
|
|
99
127
|
? {
|
|
100
128
|
queryParam: 'id',
|
|
101
129
|
initialPageParam: 0,
|
|
102
|
-
cursorParam:
|
|
103
|
-
nextParam:
|
|
104
|
-
previousParam:
|
|
130
|
+
cursorParam: null,
|
|
131
|
+
nextParam: null,
|
|
132
|
+
previousParam: null,
|
|
105
133
|
...infinite,
|
|
106
134
|
}
|
|
107
135
|
: false,
|
|
@@ -7,9 +7,20 @@ function capitalize(name: string): string {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Default resolver used by `@kubb/plugin-vue-query`. Decides the names and
|
|
11
|
+
* file paths for every generated TanStack Query composable (`useFooQuery`,
|
|
12
|
+
* `useFooMutation`, `useFooInfiniteQuery`) and its companion helpers.
|
|
11
13
|
*
|
|
12
|
-
*
|
|
14
|
+
* Functions and files use camelCase; composables get the `use` prefix.
|
|
15
|
+
*
|
|
16
|
+
* @example Resolve composable and helper names
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { resolverVueQuery } from '@kubb/plugin-vue-query'
|
|
19
|
+
*
|
|
20
|
+
* resolverVueQuery.resolveQueryName(operationNode) // 'useGetPetById'
|
|
21
|
+
* resolverVueQuery.resolveQueryKeyName(operationNode) // 'getPetByIdQueryKey'
|
|
22
|
+
* resolverVueQuery.resolveQueryOptionsName(operationNode) // 'getPetByIdQueryOptions'
|
|
23
|
+
* ```
|
|
13
24
|
*/
|
|
14
25
|
export const resolverVueQuery = defineResolver<PluginVueQuery>(() => ({
|
|
15
26
|
name: 'default',
|