@kubb/plugin-vue-query 5.0.0-beta.56 → 5.0.0-beta.73
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 +2 -2
- package/dist/index.cjs +1638 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +430 -3
- package/dist/index.js +1610 -49
- package/dist/index.js.map +1 -1
- package/package.json +10 -20
- package/dist/components-B79Gljyl.js +0 -1195
- package/dist/components-B79Gljyl.js.map +0 -1
- package/dist/components-D3xIZ9FA.cjs +0 -1315
- package/dist/components-D3xIZ9FA.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-BTtcGtUY.cjs +0 -637
- package/dist/generators-BTtcGtUY.cjs.map +0 -1
- package/dist/generators-D95ddIFV.js +0 -620
- package/dist/generators-D95ddIFV.js.map +0 -1
- package/dist/generators.cjs +0 -5
- package/dist/generators.d.ts +0 -30
- package/dist/generators.js +0 -2
- package/dist/types-CwabLiFK.d.ts +0 -266
- package/src/components/InfiniteQuery.tsx +0 -127
- package/src/components/InfiniteQueryOptions.tsx +0 -191
- 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 -116
- package/src/components/index.ts +0 -7
- package/src/generators/index.ts +0 -3
- package/src/generators/infiniteQueryGenerator.tsx +0 -196
- package/src/generators/mutationGenerator.tsx +0 -157
- package/src/generators/queryGenerator.tsx +0 -180
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -183
- package/src/resolvers/resolverVueQuery.ts +0 -76
- package/src/types.ts +0 -268
- package/src/utils.ts +0 -57
- /package/dist/{chunk-C0LytTxp.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/src/plugin.ts
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { createGroupConfig } from '@internals/shared'
|
|
3
|
-
import { ast, definePlugin } from '@kubb/core'
|
|
4
|
-
import { isParserEnabled, pluginClientName } from '@kubb/plugin-client'
|
|
5
|
-
import { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'
|
|
6
|
-
import { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'
|
|
7
|
-
import { source as configSource } from '@kubb/plugin-client/templates/config.source'
|
|
8
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
9
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
10
|
-
import { mutationKeyTransformer } from '@internals/tanstack-query'
|
|
11
|
-
import { queryKeyTransformer } from '@internals/tanstack-query'
|
|
12
|
-
import { infiniteQueryGenerator, mutationGenerator, queryGenerator } from './generators'
|
|
13
|
-
import { resolverVueQuery } from './resolvers/resolverVueQuery.ts'
|
|
14
|
-
import type { PluginVueQuery } from './types.ts'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Canonical plugin name for `@kubb/plugin-vue-query`. Used for driver lookups
|
|
18
|
-
* and cross-plugin dependency references.
|
|
19
|
-
*/
|
|
20
|
-
export const pluginVueQueryName = 'plugin-vue-query' satisfies PluginVueQuery['name']
|
|
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
|
-
*/
|
|
46
|
-
export const pluginVueQuery = definePlugin<PluginVueQuery>((options) => {
|
|
47
|
-
const {
|
|
48
|
-
output = { path: 'hooks', barrel: { type: 'named' } },
|
|
49
|
-
group,
|
|
50
|
-
exclude = [],
|
|
51
|
-
include,
|
|
52
|
-
override = [],
|
|
53
|
-
parser = false,
|
|
54
|
-
infinite = false,
|
|
55
|
-
paramsType = 'inline',
|
|
56
|
-
pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',
|
|
57
|
-
mutation = {},
|
|
58
|
-
query = {},
|
|
59
|
-
mutationKey = mutationKeyTransformer,
|
|
60
|
-
queryKey = queryKeyTransformer,
|
|
61
|
-
paramsCasing,
|
|
62
|
-
client,
|
|
63
|
-
resolver: userResolver,
|
|
64
|
-
transformer: userTransformer,
|
|
65
|
-
generators: userGenerators = [],
|
|
66
|
-
} = options
|
|
67
|
-
|
|
68
|
-
const clientName = client?.client ?? 'axios'
|
|
69
|
-
const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)
|
|
70
|
-
|
|
71
|
-
const selectedGenerators =
|
|
72
|
-
options.generators ??
|
|
73
|
-
[queryGenerator, infiniteQueryGenerator, mutationGenerator].filter((generator): generator is NonNullable<typeof generator> => Boolean(generator))
|
|
74
|
-
|
|
75
|
-
const groupConfig = createGroupConfig(group)
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
name: pluginVueQueryName,
|
|
79
|
-
options,
|
|
80
|
-
dependencies: [pluginTsName, isParserEnabled(parser) ? pluginZodName : undefined].filter((dependency): dependency is string => Boolean(dependency)),
|
|
81
|
-
hooks: {
|
|
82
|
-
'kubb:plugin:setup'(ctx) {
|
|
83
|
-
const resolver = userResolver ? { ...resolverVueQuery, ...userResolver } : resolverVueQuery
|
|
84
|
-
|
|
85
|
-
ctx.setOptions({
|
|
86
|
-
output,
|
|
87
|
-
client: {
|
|
88
|
-
bundle: client?.bundle,
|
|
89
|
-
baseURL: client?.baseURL,
|
|
90
|
-
client: clientName,
|
|
91
|
-
clientType: client?.clientType ?? 'function',
|
|
92
|
-
importPath: clientImportPath,
|
|
93
|
-
dataReturnType: client?.dataReturnType ?? 'data',
|
|
94
|
-
paramsCasing,
|
|
95
|
-
},
|
|
96
|
-
queryKey,
|
|
97
|
-
query:
|
|
98
|
-
query === false
|
|
99
|
-
? false
|
|
100
|
-
: {
|
|
101
|
-
importPath: '@tanstack/vue-query',
|
|
102
|
-
methods: ['get'],
|
|
103
|
-
...query,
|
|
104
|
-
},
|
|
105
|
-
mutationKey,
|
|
106
|
-
mutation:
|
|
107
|
-
mutation === false
|
|
108
|
-
? false
|
|
109
|
-
: {
|
|
110
|
-
importPath: '@tanstack/vue-query',
|
|
111
|
-
methods: ['post', 'put', 'patch', 'delete'],
|
|
112
|
-
...mutation,
|
|
113
|
-
},
|
|
114
|
-
infinite: infinite
|
|
115
|
-
? {
|
|
116
|
-
queryParam: 'id',
|
|
117
|
-
initialPageParam: 0,
|
|
118
|
-
cursorParam: null,
|
|
119
|
-
nextParam: null,
|
|
120
|
-
previousParam: null,
|
|
121
|
-
...infinite,
|
|
122
|
-
}
|
|
123
|
-
: false,
|
|
124
|
-
parser,
|
|
125
|
-
paramsType,
|
|
126
|
-
pathParamsType,
|
|
127
|
-
paramsCasing,
|
|
128
|
-
group: groupConfig,
|
|
129
|
-
exclude,
|
|
130
|
-
include,
|
|
131
|
-
override,
|
|
132
|
-
resolver,
|
|
133
|
-
})
|
|
134
|
-
ctx.setResolver(resolver)
|
|
135
|
-
if (userTransformer) {
|
|
136
|
-
ctx.setTransformer(userTransformer)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
for (const gen of selectedGenerators) {
|
|
140
|
-
ctx.addGenerator(gen)
|
|
141
|
-
}
|
|
142
|
-
for (const gen of userGenerators) {
|
|
143
|
-
ctx.addGenerator(gen)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const root = path.resolve(ctx.config.root, ctx.config.output.path)
|
|
147
|
-
const hasClientPlugin = !!ctx.config.plugins?.some((p) => (p as { name?: string }).name === pluginClientName)
|
|
148
|
-
|
|
149
|
-
if (client?.bundle && !hasClientPlugin && !clientImportPath) {
|
|
150
|
-
ctx.injectFile({
|
|
151
|
-
baseName: 'client.ts',
|
|
152
|
-
path: path.resolve(root, '.kubb/client.ts'),
|
|
153
|
-
sources: [
|
|
154
|
-
ast.createSource({
|
|
155
|
-
name: 'client',
|
|
156
|
-
nodes: [ast.createText(clientName === 'fetch' ? fetchClientSource : axiosClientSource)],
|
|
157
|
-
isExportable: true,
|
|
158
|
-
isIndexable: true,
|
|
159
|
-
}),
|
|
160
|
-
],
|
|
161
|
-
})
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (!hasClientPlugin) {
|
|
165
|
-
ctx.injectFile({
|
|
166
|
-
baseName: 'config.ts',
|
|
167
|
-
path: path.resolve(root, '.kubb/config.ts'),
|
|
168
|
-
sources: [
|
|
169
|
-
ast.createSource({
|
|
170
|
-
name: 'config',
|
|
171
|
-
nodes: [ast.createText(configSource)],
|
|
172
|
-
isExportable: false,
|
|
173
|
-
isIndexable: false,
|
|
174
|
-
}),
|
|
175
|
-
],
|
|
176
|
-
})
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
export default pluginVueQuery
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { camelCase, toFilePath } from '@internals/utils'
|
|
2
|
-
import { defineResolver } from '@kubb/core'
|
|
3
|
-
import type { PluginVueQuery } from '../types.ts'
|
|
4
|
-
|
|
5
|
-
function capitalize(name: string): string {
|
|
6
|
-
return `${name.charAt(0).toUpperCase()}${name.slice(1)}`
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
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.
|
|
13
|
-
*
|
|
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
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export const resolverVueQuery = defineResolver<PluginVueQuery>(() => ({
|
|
26
|
-
name: 'default',
|
|
27
|
-
pluginName: 'plugin-vue-query',
|
|
28
|
-
default(name, type) {
|
|
29
|
-
return type === 'file' ? toFilePath(name) : camelCase(name)
|
|
30
|
-
},
|
|
31
|
-
resolveName(name) {
|
|
32
|
-
return this.default(name, 'function')
|
|
33
|
-
},
|
|
34
|
-
resolvePathName(name, type) {
|
|
35
|
-
return this.default(name, type)
|
|
36
|
-
},
|
|
37
|
-
resolveQueryName(node) {
|
|
38
|
-
return `use${capitalize(this.resolveName(node.operationId))}`
|
|
39
|
-
},
|
|
40
|
-
resolveInfiniteQueryName(node) {
|
|
41
|
-
return `use${capitalize(this.resolveName(node.operationId))}Infinite`
|
|
42
|
-
},
|
|
43
|
-
resolveMutationName(node) {
|
|
44
|
-
return `use${capitalize(this.resolveName(node.operationId))}`
|
|
45
|
-
},
|
|
46
|
-
resolveQueryOptionsName(node) {
|
|
47
|
-
return `${this.resolveName(node.operationId)}QueryOptions`
|
|
48
|
-
},
|
|
49
|
-
resolveInfiniteQueryOptionsName(node) {
|
|
50
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryOptions`
|
|
51
|
-
},
|
|
52
|
-
resolveQueryKeyName(node) {
|
|
53
|
-
return `${this.resolveName(node.operationId)}QueryKey`
|
|
54
|
-
},
|
|
55
|
-
resolveInfiniteQueryKeyName(node) {
|
|
56
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryKey`
|
|
57
|
-
},
|
|
58
|
-
resolveMutationKeyName(node) {
|
|
59
|
-
return `${this.resolveName(node.operationId)}MutationKey`
|
|
60
|
-
},
|
|
61
|
-
resolveQueryKeyTypeName(node) {
|
|
62
|
-
return `${capitalize(this.resolveName(node.operationId))}QueryKey`
|
|
63
|
-
},
|
|
64
|
-
resolveInfiniteQueryKeyTypeName(node) {
|
|
65
|
-
return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`
|
|
66
|
-
},
|
|
67
|
-
resolveMutationTypeName(node) {
|
|
68
|
-
return capitalize(this.resolveName(node.operationId))
|
|
69
|
-
},
|
|
70
|
-
resolveClientName(node) {
|
|
71
|
-
return this.resolveName(node.operationId)
|
|
72
|
-
},
|
|
73
|
-
resolveInfiniteClientName(node) {
|
|
74
|
-
return `${this.resolveName(node.operationId)}Infinite`
|
|
75
|
-
},
|
|
76
|
-
}))
|
package/src/types.ts
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import type { ast, Exclude, Generator, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver } from '@kubb/core'
|
|
2
|
-
import type { ClientImportPath, PluginClient } from '@kubb/plugin-client'
|
|
3
|
-
|
|
4
|
-
export type Transformer = (props: { node: ast.OperationNode; casing: 'camelcase' | undefined }) => Array<unknown>
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Resolver for Vue Query that provides naming methods for hook functions.
|
|
8
|
-
*/
|
|
9
|
-
export type ResolverVueQuery = Resolver & {
|
|
10
|
-
/**
|
|
11
|
-
* Resolves the base function name for an operation.
|
|
12
|
-
*/
|
|
13
|
-
resolveName(this: ResolverVueQuery, name: string): string
|
|
14
|
-
/**
|
|
15
|
-
* Resolves the output file name for a hook module.
|
|
16
|
-
*/
|
|
17
|
-
resolvePathName(this: ResolverVueQuery, name: string, type?: 'file' | 'function' | 'type' | 'const'): string
|
|
18
|
-
/**
|
|
19
|
-
* Resolves a query hook function name.
|
|
20
|
-
*/
|
|
21
|
-
resolveQueryName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
22
|
-
/**
|
|
23
|
-
* Resolves an infinite query hook function name.
|
|
24
|
-
*/
|
|
25
|
-
resolveInfiniteQueryName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
26
|
-
/**
|
|
27
|
-
* Resolves a mutation hook function name.
|
|
28
|
-
*/
|
|
29
|
-
resolveMutationName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
30
|
-
/**
|
|
31
|
-
* Resolves the query options helper name.
|
|
32
|
-
*/
|
|
33
|
-
resolveQueryOptionsName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
34
|
-
/**
|
|
35
|
-
* Resolves the infinite query options helper name.
|
|
36
|
-
*/
|
|
37
|
-
resolveInfiniteQueryOptionsName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
38
|
-
/**
|
|
39
|
-
* Resolves the query key helper name.
|
|
40
|
-
*/
|
|
41
|
-
resolveQueryKeyName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
42
|
-
/**
|
|
43
|
-
* Resolves the infinite query key helper name.
|
|
44
|
-
*/
|
|
45
|
-
resolveInfiniteQueryKeyName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
46
|
-
/**
|
|
47
|
-
* Resolves the mutation key helper name.
|
|
48
|
-
*/
|
|
49
|
-
resolveMutationKeyName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
50
|
-
/**
|
|
51
|
-
* Resolves the query key type name.
|
|
52
|
-
*/
|
|
53
|
-
resolveQueryKeyTypeName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
54
|
-
/**
|
|
55
|
-
* Resolves the infinite query key type name.
|
|
56
|
-
*/
|
|
57
|
-
resolveInfiniteQueryKeyTypeName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
58
|
-
/**
|
|
59
|
-
* Resolves the mutation type name.
|
|
60
|
-
*/
|
|
61
|
-
resolveMutationTypeName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
62
|
-
/**
|
|
63
|
-
* Resolves the client function name generated inline by query hooks.
|
|
64
|
-
*/
|
|
65
|
-
resolveClientName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
66
|
-
/**
|
|
67
|
-
* Resolves the client function name generated inline by infinite query hooks.
|
|
68
|
-
*/
|
|
69
|
-
resolveInfiniteClientName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Builds the `queryKey` used by each generated query composable.
|
|
74
|
-
*
|
|
75
|
-
* @note String values are inlined verbatim into generated code. Wrap literal
|
|
76
|
-
* strings in `JSON.stringify(...)`.
|
|
77
|
-
*/
|
|
78
|
-
type QueryKey = Transformer
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Builds the `mutationKey` used by each generated mutation composable.
|
|
82
|
-
*
|
|
83
|
-
* @note String values are inlined verbatim into generated code. Wrap literal
|
|
84
|
-
* strings in `JSON.stringify(...)`.
|
|
85
|
-
*/
|
|
86
|
-
type MutationKey = Transformer
|
|
87
|
-
|
|
88
|
-
type Query = {
|
|
89
|
-
/**
|
|
90
|
-
* HTTP methods treated as queries.
|
|
91
|
-
*
|
|
92
|
-
* @default ['get']
|
|
93
|
-
*/
|
|
94
|
-
methods?: Array<string>
|
|
95
|
-
/**
|
|
96
|
-
* Module specifier used in the `import { useQuery } from '...'` statement at
|
|
97
|
-
* the top of every generated composable file.
|
|
98
|
-
*
|
|
99
|
-
* @default '@tanstack/vue-query'
|
|
100
|
-
*/
|
|
101
|
-
importPath?: string
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
type Mutation = {
|
|
105
|
-
/**
|
|
106
|
-
* HTTP methods treated as mutations.
|
|
107
|
-
*
|
|
108
|
-
* @default ['post', 'put', 'delete']
|
|
109
|
-
*/
|
|
110
|
-
methods?: Array<string>
|
|
111
|
-
/**
|
|
112
|
-
* Module specifier used in the `import { useMutation } from '...'` statement
|
|
113
|
-
* at the top of every generated composable file.
|
|
114
|
-
*
|
|
115
|
-
* @default '@tanstack/vue-query'
|
|
116
|
-
*/
|
|
117
|
-
importPath?: string
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export type Infinite = {
|
|
121
|
-
/**
|
|
122
|
-
* Name of the query parameter that holds the page cursor.
|
|
123
|
-
*
|
|
124
|
-
* @default 'id'
|
|
125
|
-
*/
|
|
126
|
-
queryParam?: string
|
|
127
|
-
/**
|
|
128
|
-
* Path to the cursor field on the response. Leave undefined when the cursor
|
|
129
|
-
* is not known.
|
|
130
|
-
*
|
|
131
|
-
* @deprecated Use `nextParam` and `previousParam` for richer pagination control.
|
|
132
|
-
*/
|
|
133
|
-
cursorParam?: string | null
|
|
134
|
-
/**
|
|
135
|
-
* Path to the next-page cursor on the response. Supports dot notation
|
|
136
|
-
* (`'pagination.next.id'`) or array form.
|
|
137
|
-
*/
|
|
138
|
-
nextParam?: string | Array<string> | null
|
|
139
|
-
/**
|
|
140
|
-
* Path to the previous-page cursor on the response. Supports dot notation
|
|
141
|
-
* or array form.
|
|
142
|
-
*/
|
|
143
|
-
previousParam?: string | Array<string> | null
|
|
144
|
-
/**
|
|
145
|
-
* Initial value for `pageParam` on the first fetch.
|
|
146
|
-
*
|
|
147
|
-
* @default 0
|
|
148
|
-
*/
|
|
149
|
-
initialPageParam?: unknown
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Where the generated composables are written and how they are exported, plus the optional
|
|
154
|
-
* `group` strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
|
|
155
|
-
*
|
|
156
|
-
* @default { path: 'hooks', barrel: { type: 'named' } }
|
|
157
|
-
*/
|
|
158
|
-
export type Options = OutputOptions & {
|
|
159
|
-
/**
|
|
160
|
-
* HTTP client used inside every generated composable. Mirrors a subset of
|
|
161
|
-
* `pluginClient` options.
|
|
162
|
-
*/
|
|
163
|
-
client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>
|
|
164
|
-
/**
|
|
165
|
-
* Skip operations matching at least one entry in the list.
|
|
166
|
-
*/
|
|
167
|
-
exclude?: Array<Exclude>
|
|
168
|
-
/**
|
|
169
|
-
* Restrict generation to operations matching at least one entry in the list.
|
|
170
|
-
*/
|
|
171
|
-
include?: Array<Include>
|
|
172
|
-
/**
|
|
173
|
-
* Apply a different options object to operations matching a pattern.
|
|
174
|
-
*/
|
|
175
|
-
override?: Array<Override<ResolvedOptions>>
|
|
176
|
-
/**
|
|
177
|
-
* Rename parameter properties in the generated composables.
|
|
178
|
-
*
|
|
179
|
-
* @note Must match the value of `paramsCasing` on `@kubb/plugin-ts`.
|
|
180
|
-
*/
|
|
181
|
-
paramsCasing?: 'camelcase'
|
|
182
|
-
/**
|
|
183
|
-
* How operation parameters appear in the generated composable signature.
|
|
184
|
-
*
|
|
185
|
-
* @default 'inline'
|
|
186
|
-
*/
|
|
187
|
-
paramsType?: 'object' | 'inline'
|
|
188
|
-
/**
|
|
189
|
-
* How URL path parameters are arranged inside the inline argument list.
|
|
190
|
-
*
|
|
191
|
-
* @default 'inline'
|
|
192
|
-
*/
|
|
193
|
-
pathParamsType?: PluginClient['options']['pathParamsType']
|
|
194
|
-
/**
|
|
195
|
-
* Enables `useInfiniteQuery` composables for cursor- or page-based pagination.
|
|
196
|
-
* Pass an object to configure how the cursor is read; pass `false` to skip.
|
|
197
|
-
*
|
|
198
|
-
* @default false
|
|
199
|
-
*/
|
|
200
|
-
infinite?: Partial<Infinite> | false
|
|
201
|
-
/**
|
|
202
|
-
* Custom `queryKey` builder.
|
|
203
|
-
*/
|
|
204
|
-
queryKey?: QueryKey
|
|
205
|
-
/**
|
|
206
|
-
* Configures query composables. Set to `false` to skip composable generation
|
|
207
|
-
* and emit only `queryOptions(...)` helpers.
|
|
208
|
-
*/
|
|
209
|
-
query?: Partial<Query> | false
|
|
210
|
-
/**
|
|
211
|
-
* Custom `mutationKey` builder.
|
|
212
|
-
*/
|
|
213
|
-
mutationKey?: MutationKey
|
|
214
|
-
/**
|
|
215
|
-
* Configures mutation composables. Set to `false` to skip mutation generation.
|
|
216
|
-
*/
|
|
217
|
-
mutation?: Partial<Mutation> | false
|
|
218
|
-
/**
|
|
219
|
-
* Validator applied to response bodies before they reach the caller.
|
|
220
|
-
* - `'client'` — no validation.
|
|
221
|
-
* - `'zod'` — pipes responses through schemas from `@kubb/plugin-zod`.
|
|
222
|
-
*/
|
|
223
|
-
parser?: PluginClient['options']['parser']
|
|
224
|
-
/**
|
|
225
|
-
* Override how composable names and file paths are built.
|
|
226
|
-
*/
|
|
227
|
-
resolver?: Partial<ResolverVueQuery> & ThisType<ResolverVueQuery>
|
|
228
|
-
/**
|
|
229
|
-
* AST visitor applied to each operation node before printing.
|
|
230
|
-
*/
|
|
231
|
-
transformer?: ast.Visitor
|
|
232
|
-
/**
|
|
233
|
-
* Custom generators that run alongside the built-in Vue Query generators.
|
|
234
|
-
*/
|
|
235
|
-
generators?: Array<Generator<PluginVueQuery>>
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
type ResolvedOptions = {
|
|
239
|
-
output: Output
|
|
240
|
-
group: Group | null
|
|
241
|
-
exclude: NonNullable<Options['exclude']>
|
|
242
|
-
include: Options['include']
|
|
243
|
-
override: NonNullable<Options['override']>
|
|
244
|
-
client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>
|
|
245
|
-
parser: NonNullable<Options['parser']>
|
|
246
|
-
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
247
|
-
paramsCasing: Options['paramsCasing']
|
|
248
|
-
paramsType: NonNullable<Options['paramsType']>
|
|
249
|
-
/**
|
|
250
|
-
* Only used for infinite
|
|
251
|
-
*/
|
|
252
|
-
infinite: NonNullable<Infinite> | false
|
|
253
|
-
queryKey: QueryKey | null
|
|
254
|
-
query: NonNullable<Required<Query>> | false
|
|
255
|
-
mutationKey: MutationKey | null
|
|
256
|
-
mutation: NonNullable<Required<Mutation>> | false
|
|
257
|
-
resolver: ResolverVueQuery
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export type PluginVueQuery = PluginFactoryOptions<'plugin-vue-query', Options, ResolvedOptions, ResolverVueQuery>
|
|
261
|
-
|
|
262
|
-
declare global {
|
|
263
|
-
namespace Kubb {
|
|
264
|
-
interface PluginRegistry {
|
|
265
|
-
'plugin-vue-query': PluginVueQuery
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
buildGroupParam,
|
|
3
|
-
buildQueryKeyParams,
|
|
4
|
-
resolveHeaderGroupType,
|
|
5
|
-
resolveOperationOverrides,
|
|
6
|
-
resolvePathParamType,
|
|
7
|
-
resolveQueryGroupType,
|
|
8
|
-
resolveZodSchemaNames,
|
|
9
|
-
} from '@internals/tanstack-query'
|
|
10
|
-
export {
|
|
11
|
-
buildOperationComments as getComments,
|
|
12
|
-
buildRequestConfigType,
|
|
13
|
-
buildStatusUnionType,
|
|
14
|
-
getContentTypeInfo,
|
|
15
|
-
resolveErrorNames,
|
|
16
|
-
resolveStatusCodeNames,
|
|
17
|
-
resolveSuccessNames,
|
|
18
|
-
} from '@internals/shared'
|
|
19
|
-
|
|
20
|
-
import { ast } from '@kubb/core'
|
|
21
|
-
|
|
22
|
-
export function printType(typeNode: ast.ParamsTypeNode | undefined): string {
|
|
23
|
-
if (!typeNode) return 'unknown'
|
|
24
|
-
if (typeNode.variant === 'reference') return typeNode.name
|
|
25
|
-
if (typeNode.variant === 'member') return `${typeNode.base}['${typeNode.key}']`
|
|
26
|
-
if (typeNode.variant === 'struct') {
|
|
27
|
-
const parts = typeNode.properties.map((p) => {
|
|
28
|
-
const typeStr = printType(p.type)
|
|
29
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name)
|
|
30
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`
|
|
31
|
-
})
|
|
32
|
-
return `{ ${parts.join('; ')} }`
|
|
33
|
-
}
|
|
34
|
-
return 'unknown'
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function wrapWithMaybeRefOrGetter(paramsNode: ast.FunctionParametersNode, skip?: (name: string) => boolean): ast.FunctionParametersNode {
|
|
38
|
-
const wrappedParams = paramsNode.params.map((param) => {
|
|
39
|
-
if ('kind' in param && (param as ast.ParameterGroupNode).kind === 'ParameterGroup') {
|
|
40
|
-
const group = param as ast.ParameterGroupNode
|
|
41
|
-
return {
|
|
42
|
-
...group,
|
|
43
|
-
properties: group.properties.map((p) => ({
|
|
44
|
-
...p,
|
|
45
|
-
type: p.type ? ast.createParamsType({ variant: 'reference', name: `MaybeRefOrGetter<${printType(p.type)}>` }) : p.type,
|
|
46
|
-
})),
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const fp = param as ast.FunctionParameterNode
|
|
50
|
-
if (skip?.(fp.name)) return fp
|
|
51
|
-
return {
|
|
52
|
-
...fp,
|
|
53
|
-
type: fp.type ? ast.createParamsType({ variant: 'reference', name: `MaybeRefOrGetter<${printType(fp.type)}>` }) : fp.type,
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
return ast.createFunctionParameters({ params: wrappedParams })
|
|
57
|
-
}
|
|
File without changes
|