@kubb/plugin-vue-query 5.0.0-alpha.8 → 5.0.0-beta.3
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/LICENSE +17 -10
- package/README.md +1 -3
- package/dist/components-D1UhYFgY.js +1277 -0
- package/dist/components-D1UhYFgY.js.map +1 -0
- package/dist/components-qfOFRSoM.cjs +1367 -0
- package/dist/components-qfOFRSoM.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +118 -109
- package/dist/components.js +1 -1
- package/dist/generators-C4gs_P1i.cjs +726 -0
- package/dist/generators-C4gs_P1i.cjs.map +1 -0
- package/dist/generators-CbnIVBgY.js +709 -0
- package/dist/generators-CbnIVBgY.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +5 -472
- package/dist/generators.js +1 -1
- package/dist/index.cjs +106 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +102 -121
- package/dist/index.js.map +1 -1
- package/dist/types-nVDTfuS1.d.ts +194 -0
- package/package.json +61 -64
- package/src/components/InfiniteQuery.tsx +104 -153
- package/src/components/InfiniteQueryOptions.tsx +122 -162
- package/src/components/Mutation.tsx +110 -136
- package/src/components/Query.tsx +102 -151
- package/src/components/QueryKey.tsx +68 -58
- package/src/components/QueryOptions.tsx +147 -139
- package/src/generators/infiniteQueryGenerator.tsx +165 -170
- package/src/generators/mutationGenerator.tsx +117 -124
- package/src/generators/queryGenerator.tsx +138 -136
- package/src/index.ts +1 -1
- package/src/plugin.ts +124 -175
- package/src/resolvers/resolverVueQuery.ts +19 -0
- package/src/types.ts +68 -48
- package/src/utils.ts +37 -0
- package/dist/components-Yjoe78Y7.cjs +0 -1119
- package/dist/components-Yjoe78Y7.cjs.map +0 -1
- package/dist/components-_AMBl0g-.js +0 -1029
- package/dist/components-_AMBl0g-.js.map +0 -1
- package/dist/generators-CR34GjVu.js +0 -661
- package/dist/generators-CR34GjVu.js.map +0 -1
- package/dist/generators-DH8VkK1q.cjs +0 -678
- package/dist/generators-DH8VkK1q.cjs.map +0 -1
- package/dist/types-CgDFUvfZ.d.ts +0 -211
package/src/plugin.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import { camelCase
|
|
3
|
-
import {
|
|
2
|
+
import { camelCase } from '@internals/utils'
|
|
3
|
+
import { ast, definePlugin, type Group } from '@kubb/core'
|
|
4
4
|
import { pluginClientName } from '@kubb/plugin-client'
|
|
5
5
|
import { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'
|
|
6
6
|
import { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'
|
|
7
7
|
import { source as configSource } from '@kubb/plugin-client/templates/config.source'
|
|
8
|
-
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
9
8
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
10
9
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
11
|
-
import { MutationKey
|
|
10
|
+
import { MutationKey } from './components/MutationKey.tsx'
|
|
11
|
+
import { QueryKey } from './components/QueryKey.tsx'
|
|
12
12
|
import { infiniteQueryGenerator, mutationGenerator, queryGenerator } from './generators'
|
|
13
|
+
import { resolverVueQuery } from './resolvers/resolverVueQuery.ts'
|
|
13
14
|
import type { PluginVueQuery } from './types.ts'
|
|
14
15
|
|
|
15
16
|
export const pluginVueQueryName = 'plugin-vue-query' satisfies PluginVueQuery['name']
|
|
16
17
|
|
|
17
|
-
export const pluginVueQuery =
|
|
18
|
+
export const pluginVueQuery = definePlugin<PluginVueQuery>((options) => {
|
|
18
19
|
const {
|
|
19
20
|
output = { path: 'hooks', barrelType: 'named' },
|
|
20
21
|
group,
|
|
@@ -22,197 +23,145 @@ export const pluginVueQuery = createPlugin<PluginVueQuery>((options) => {
|
|
|
22
23
|
include,
|
|
23
24
|
override = [],
|
|
24
25
|
parser = 'client',
|
|
25
|
-
infinite,
|
|
26
|
+
infinite = false,
|
|
26
27
|
transformers = {},
|
|
27
28
|
paramsType = 'inline',
|
|
28
29
|
pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',
|
|
29
30
|
mutation = {},
|
|
30
31
|
query = {},
|
|
31
|
-
paramsCasing,
|
|
32
32
|
mutationKey = MutationKey.getTransformer,
|
|
33
33
|
queryKey = QueryKey.getTransformer,
|
|
34
|
-
|
|
35
|
-
contentType,
|
|
34
|
+
paramsCasing,
|
|
36
35
|
client,
|
|
36
|
+
resolver: userResolver,
|
|
37
|
+
transformer: userTransformer,
|
|
38
|
+
generators: userGenerators = [],
|
|
37
39
|
} = options
|
|
38
40
|
|
|
39
41
|
const clientName = client?.client ?? 'axios'
|
|
40
42
|
const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
name: pluginVueQueryName,
|
|
44
|
-
options: {
|
|
45
|
-
output,
|
|
46
|
-
client: {
|
|
47
|
-
bundle: client?.bundle,
|
|
48
|
-
baseURL: client?.baseURL,
|
|
49
|
-
client: clientName,
|
|
50
|
-
clientType: client?.clientType ?? 'function',
|
|
51
|
-
dataReturnType: client?.dataReturnType ?? 'data',
|
|
52
|
-
pathParamsType,
|
|
53
|
-
importPath: clientImportPath,
|
|
54
|
-
paramsCasing,
|
|
55
|
-
},
|
|
56
|
-
infinite: infinite
|
|
57
|
-
? {
|
|
58
|
-
queryParam: 'id',
|
|
59
|
-
initialPageParam: 0,
|
|
60
|
-
cursorParam: undefined,
|
|
61
|
-
nextParam: undefined,
|
|
62
|
-
previousParam: undefined,
|
|
63
|
-
...infinite,
|
|
64
|
-
}
|
|
65
|
-
: false,
|
|
66
|
-
queryKey,
|
|
67
|
-
query:
|
|
68
|
-
query === false
|
|
69
|
-
? false
|
|
70
|
-
: {
|
|
71
|
-
methods: ['get'],
|
|
72
|
-
importPath: '@tanstack/vue-query',
|
|
73
|
-
...query,
|
|
74
|
-
},
|
|
75
|
-
mutationKey,
|
|
76
|
-
mutation:
|
|
77
|
-
mutation === false
|
|
78
|
-
? false
|
|
79
|
-
: {
|
|
80
|
-
methods: ['post', 'put', 'patch', 'delete'],
|
|
81
|
-
importPath: '@tanstack/vue-query',
|
|
82
|
-
...mutation,
|
|
83
|
-
},
|
|
84
|
-
paramsType,
|
|
85
|
-
pathParamsType,
|
|
86
|
-
parser,
|
|
87
|
-
paramsCasing,
|
|
88
|
-
group,
|
|
89
|
-
},
|
|
90
|
-
pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
|
91
|
-
resolvePath(baseName, pathMode, options) {
|
|
92
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
93
|
-
const mode = pathMode ?? getMode(path.resolve(root, output.path))
|
|
94
|
-
|
|
95
|
-
if (mode === 'single') {
|
|
96
|
-
/**
|
|
97
|
-
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
98
|
-
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
99
|
-
*/
|
|
100
|
-
return path.resolve(root, output.path)
|
|
101
|
-
}
|
|
44
|
+
const selectedGenerators = options.generators ?? [queryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean)
|
|
102
45
|
|
|
103
|
-
|
|
104
|
-
|
|
46
|
+
const groupConfig = group
|
|
47
|
+
? ({
|
|
48
|
+
...group,
|
|
49
|
+
name: group.name
|
|
105
50
|
? group.name
|
|
106
|
-
: (ctx) => {
|
|
107
|
-
if (group
|
|
51
|
+
: (ctx: { group: string }) => {
|
|
52
|
+
if (group.type === 'path') {
|
|
108
53
|
return `${ctx.group.split('/')[1]}`
|
|
109
54
|
}
|
|
110
55
|
return `${camelCase(ctx.group)}Controller`
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return path.resolve(
|
|
114
|
-
root,
|
|
115
|
-
output.path,
|
|
116
|
-
groupName({
|
|
117
|
-
group: group.type === 'path' ? options.group.path! : options.group.tag!,
|
|
118
|
-
}),
|
|
119
|
-
baseName,
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return path.resolve(root, output.path, baseName)
|
|
124
|
-
},
|
|
125
|
-
resolveName(name, type) {
|
|
126
|
-
let resolvedName = camelCase(name)
|
|
127
|
-
|
|
128
|
-
if (type === 'file' || type === 'function') {
|
|
129
|
-
resolvedName = camelCase(name, {
|
|
130
|
-
isFile: type === 'file',
|
|
131
|
-
})
|
|
132
|
-
}
|
|
133
|
-
if (type === 'type') {
|
|
134
|
-
resolvedName = pascalCase(name)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (type) {
|
|
138
|
-
return transformers?.name?.(resolvedName, type) || resolvedName
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return resolvedName
|
|
142
|
-
},
|
|
143
|
-
async install() {
|
|
144
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
145
|
-
const mode = getMode(path.resolve(root, output.path))
|
|
146
|
-
const oas = await this.getOas()
|
|
147
|
-
const baseURL = await this.getBaseURL()
|
|
148
|
-
|
|
149
|
-
if (baseURL) {
|
|
150
|
-
this.plugin.options.client.baseURL = baseURL
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const hasClientPlugin = !!this.driver.getPluginByName(pluginClientName)
|
|
154
|
-
|
|
155
|
-
if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {
|
|
156
|
-
// pre add bundled
|
|
157
|
-
await this.upsertFile({
|
|
158
|
-
baseName: 'fetch.ts',
|
|
159
|
-
path: path.resolve(root, '.kubb/fetch.ts'),
|
|
160
|
-
sources: [
|
|
161
|
-
{
|
|
162
|
-
name: 'fetch',
|
|
163
|
-
value: this.plugin.options.client.client === 'fetch' ? fetchClientSource : axiosClientSource,
|
|
164
|
-
isExportable: true,
|
|
165
|
-
isIndexable: true,
|
|
166
56
|
},
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
exports: [],
|
|
170
|
-
})
|
|
171
|
-
}
|
|
57
|
+
} satisfies Group)
|
|
58
|
+
: undefined
|
|
172
59
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
60
|
+
return {
|
|
61
|
+
name: pluginVueQueryName,
|
|
62
|
+
options,
|
|
63
|
+
dependencies: [pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
|
64
|
+
hooks: {
|
|
65
|
+
'kubb:plugin:setup'(ctx) {
|
|
66
|
+
const resolver = userResolver ? { ...resolverVueQuery, ...userResolver } : resolverVueQuery
|
|
67
|
+
|
|
68
|
+
ctx.setOptions({
|
|
69
|
+
output,
|
|
70
|
+
transformers,
|
|
71
|
+
client: {
|
|
72
|
+
bundle: client?.bundle,
|
|
73
|
+
baseURL: client?.baseURL,
|
|
74
|
+
client: clientName,
|
|
75
|
+
clientType: client?.clientType ?? 'function',
|
|
76
|
+
importPath: clientImportPath,
|
|
77
|
+
dataReturnType: client?.dataReturnType ?? 'data',
|
|
78
|
+
paramsCasing,
|
|
79
|
+
},
|
|
80
|
+
queryKey,
|
|
81
|
+
query:
|
|
82
|
+
query === false
|
|
83
|
+
? false
|
|
84
|
+
: {
|
|
85
|
+
importPath: '@tanstack/vue-query',
|
|
86
|
+
methods: ['get'],
|
|
87
|
+
...query,
|
|
88
|
+
},
|
|
89
|
+
mutationKey,
|
|
90
|
+
mutation:
|
|
91
|
+
mutation === false
|
|
92
|
+
? false
|
|
93
|
+
: {
|
|
94
|
+
importPath: '@tanstack/vue-query',
|
|
95
|
+
methods: ['post', 'put', 'patch', 'delete'],
|
|
96
|
+
...mutation,
|
|
97
|
+
},
|
|
98
|
+
infinite: infinite
|
|
99
|
+
? {
|
|
100
|
+
queryParam: 'id',
|
|
101
|
+
initialPageParam: 0,
|
|
102
|
+
cursorParam: undefined,
|
|
103
|
+
nextParam: undefined,
|
|
104
|
+
previousParam: undefined,
|
|
105
|
+
...infinite,
|
|
106
|
+
}
|
|
107
|
+
: false,
|
|
108
|
+
parser,
|
|
109
|
+
paramsType,
|
|
110
|
+
pathParamsType,
|
|
111
|
+
paramsCasing,
|
|
112
|
+
group: groupConfig,
|
|
113
|
+
exclude,
|
|
114
|
+
include,
|
|
115
|
+
override,
|
|
116
|
+
resolver,
|
|
187
117
|
})
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
118
|
+
ctx.setResolver(resolver)
|
|
119
|
+
if (userTransformer) {
|
|
120
|
+
ctx.setTransformer(userTransformer)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
for (const gen of selectedGenerators) {
|
|
124
|
+
ctx.addGenerator(gen)
|
|
125
|
+
}
|
|
126
|
+
for (const gen of userGenerators) {
|
|
127
|
+
ctx.addGenerator(gen)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const root = path.resolve(ctx.config.root, ctx.config.output.path)
|
|
131
|
+
const hasClientPlugin = !!ctx.config.plugins?.some((p) => (p as { name?: string }).name === pluginClientName)
|
|
132
|
+
|
|
133
|
+
if (client?.bundle && !hasClientPlugin && !clientImportPath) {
|
|
134
|
+
ctx.injectFile({
|
|
135
|
+
baseName: 'fetch.ts',
|
|
136
|
+
path: path.resolve(root, '.kubb/fetch.ts'),
|
|
137
|
+
sources: [
|
|
138
|
+
ast.createSource({
|
|
139
|
+
name: 'fetch',
|
|
140
|
+
nodes: [ast.createText(clientName === 'fetch' ? fetchClientSource : axiosClientSource)],
|
|
141
|
+
isExportable: true,
|
|
142
|
+
isIndexable: true,
|
|
143
|
+
}),
|
|
144
|
+
],
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (!hasClientPlugin) {
|
|
149
|
+
ctx.injectFile({
|
|
150
|
+
baseName: 'config.ts',
|
|
151
|
+
path: path.resolve(root, '.kubb/config.ts'),
|
|
152
|
+
sources: [
|
|
153
|
+
ast.createSource({
|
|
154
|
+
name: 'config',
|
|
155
|
+
nodes: [ast.createText(configSource)],
|
|
156
|
+
isExportable: false,
|
|
157
|
+
isIndexable: false,
|
|
158
|
+
}),
|
|
159
|
+
],
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
},
|
|
216
163
|
},
|
|
217
164
|
}
|
|
218
165
|
})
|
|
166
|
+
|
|
167
|
+
export default pluginVueQuery
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { camelCase } from '@internals/utils'
|
|
2
|
+
import { defineResolver } from '@kubb/core'
|
|
3
|
+
import type { PluginVueQuery } from '../types.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Naming convention resolver for Vue Query plugin.
|
|
7
|
+
*
|
|
8
|
+
* Provides default naming helpers using camelCase for functions and file paths.
|
|
9
|
+
*/
|
|
10
|
+
export const resolverVueQuery = defineResolver<PluginVueQuery>((ctx) => ({
|
|
11
|
+
name: 'default',
|
|
12
|
+
pluginName: 'plugin-vue-query',
|
|
13
|
+
default(name, type) {
|
|
14
|
+
return camelCase(name, { isFile: type === 'file' })
|
|
15
|
+
},
|
|
16
|
+
resolveName(name) {
|
|
17
|
+
return ctx.default(name, 'function')
|
|
18
|
+
},
|
|
19
|
+
}))
|
package/src/types.ts
CHANGED
|
@@ -1,50 +1,58 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
3
|
-
import type { contentType, HttpMethod, Oas } from '@kubb/oas'
|
|
1
|
+
import type { ast, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver } from '@kubb/core'
|
|
4
2
|
import type { ClientImportPath, PluginClient } from '@kubb/plugin-client'
|
|
5
|
-
import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
6
|
-
import type { Generator } from '@kubb/plugin-oas/generators'
|
|
7
3
|
|
|
8
|
-
export type {
|
|
4
|
+
export type Transformer = (props: { node: ast.OperationNode; casing: 'camelcase' | undefined }) => unknown[]
|
|
9
5
|
|
|
10
6
|
/**
|
|
11
|
-
*
|
|
7
|
+
* Resolver for Vue Query that provides naming methods for hook functions.
|
|
8
|
+
*/
|
|
9
|
+
export type ResolverVueQuery = Resolver & {
|
|
10
|
+
/**
|
|
11
|
+
* Resolves the hook function name for an operation.
|
|
12
|
+
*/
|
|
13
|
+
resolveName(this: ResolverVueQuery, name: string): string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Customize the queryKey.
|
|
12
18
|
*/
|
|
13
19
|
type QueryKey = Transformer
|
|
14
20
|
|
|
15
21
|
/**
|
|
16
|
-
* Customize the mutationKey
|
|
22
|
+
* Customize the mutationKey.
|
|
17
23
|
*/
|
|
18
24
|
type MutationKey = Transformer
|
|
19
25
|
|
|
20
26
|
type Query = {
|
|
21
27
|
/**
|
|
22
|
-
*
|
|
28
|
+
* HTTP methods to use for queries.
|
|
29
|
+
*
|
|
23
30
|
* @default ['get']
|
|
24
31
|
*/
|
|
25
|
-
methods
|
|
32
|
+
methods?: Array<string>
|
|
26
33
|
/**
|
|
27
34
|
* Path to the useQuery hook for useQuery functionality.
|
|
28
35
|
* Used as `import { useQuery } from '${importPath}'`.
|
|
29
36
|
* Accepts relative and absolute paths.
|
|
30
37
|
* Path is used as-is; relative paths are based on the generated file location.
|
|
31
|
-
* @default '@tanstack/
|
|
38
|
+
* @default '@tanstack/vue-query'
|
|
32
39
|
*/
|
|
33
40
|
importPath?: string
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
type Mutation = {
|
|
37
44
|
/**
|
|
38
|
-
*
|
|
45
|
+
* HTTP methods to use for mutations.
|
|
46
|
+
*
|
|
39
47
|
* @default ['post', 'put', 'delete']
|
|
40
48
|
*/
|
|
41
|
-
methods
|
|
49
|
+
methods?: Array<string>
|
|
42
50
|
/**
|
|
43
|
-
* Path to the
|
|
44
|
-
* Used as `import {
|
|
51
|
+
* Path to the useMutation hook for useMutation functionality.
|
|
52
|
+
* Used as `import { useMutation } from '${importPath}'`.
|
|
45
53
|
* Accepts relative and absolute paths.
|
|
46
54
|
* Path is used as-is; relative paths are based on the generated file location.
|
|
47
|
-
* @default '@tanstack/
|
|
55
|
+
* @default '@tanstack/vue-query'
|
|
48
56
|
*/
|
|
49
57
|
importPath?: string
|
|
50
58
|
}
|
|
@@ -52,7 +60,7 @@ type Mutation = {
|
|
|
52
60
|
export type Infinite = {
|
|
53
61
|
/**
|
|
54
62
|
* Specify the params key used for `pageParam`.
|
|
55
|
-
* @default
|
|
63
|
+
* @default 'id'
|
|
56
64
|
*/
|
|
57
65
|
queryParam: string
|
|
58
66
|
/**
|
|
@@ -72,7 +80,7 @@ export type Infinite = {
|
|
|
72
80
|
previousParam?: string | string[] | undefined
|
|
73
81
|
/**
|
|
74
82
|
* The initial value, the value of the first page.
|
|
75
|
-
* @default
|
|
83
|
+
* @default 0
|
|
76
84
|
*/
|
|
77
85
|
initialPageParam: unknown
|
|
78
86
|
}
|
|
@@ -82,95 +90,107 @@ export type Options = {
|
|
|
82
90
|
* Specify the export location for the files and define the behavior of the output
|
|
83
91
|
* @default { path: 'hooks', barrelType: 'named' }
|
|
84
92
|
*/
|
|
85
|
-
output?: Output
|
|
86
|
-
/**
|
|
87
|
-
* Define which contentType should be used.
|
|
88
|
-
* By default, the first JSON valid mediaType is used
|
|
89
|
-
*/
|
|
90
|
-
contentType?: contentType
|
|
93
|
+
output?: Output
|
|
91
94
|
/**
|
|
92
95
|
* Group the @tanstack/query hooks based on the provided name.
|
|
93
96
|
*/
|
|
94
97
|
group?: Group
|
|
95
98
|
client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>
|
|
96
99
|
/**
|
|
97
|
-
*
|
|
100
|
+
* Tags, operations, or paths to exclude from generation.
|
|
98
101
|
*/
|
|
99
102
|
exclude?: Array<Exclude>
|
|
100
103
|
/**
|
|
101
|
-
*
|
|
104
|
+
* Tags, operations, or paths to include in generation.
|
|
102
105
|
*/
|
|
103
106
|
include?: Array<Include>
|
|
104
107
|
/**
|
|
105
|
-
*
|
|
108
|
+
* Override options for specific tags, operations, or paths.
|
|
106
109
|
*/
|
|
107
110
|
override?: Array<Override<ResolvedOptions>>
|
|
108
111
|
/**
|
|
109
|
-
*
|
|
110
|
-
* - 'camelcase' uses camelcase for the params names
|
|
112
|
+
* Apply casing to parameter names.
|
|
111
113
|
*/
|
|
112
114
|
paramsCasing?: 'camelcase'
|
|
113
115
|
/**
|
|
114
|
-
* How
|
|
115
|
-
*
|
|
116
|
-
* - 'inline' returns the params as comma separated params.
|
|
116
|
+
* How parameters are passed: grouped in an object or spread inline.
|
|
117
|
+
*
|
|
117
118
|
* @default 'inline'
|
|
118
119
|
*/
|
|
119
120
|
paramsType?: 'object' | 'inline'
|
|
120
121
|
/**
|
|
121
|
-
* How
|
|
122
|
-
*
|
|
123
|
-
* - 'inline': returns the pathParams as comma separated params.
|
|
122
|
+
* How path parameters are passed: grouped in an object or spread inline.
|
|
123
|
+
*
|
|
124
124
|
* @default 'inline'
|
|
125
125
|
*/
|
|
126
126
|
pathParamsType?: PluginClient['options']['pathParamsType']
|
|
127
127
|
/**
|
|
128
|
-
*
|
|
128
|
+
* Add infinite query hooks.
|
|
129
129
|
*/
|
|
130
130
|
infinite?: Partial<Infinite> | false
|
|
131
131
|
queryKey?: QueryKey
|
|
132
132
|
/**
|
|
133
|
-
*
|
|
133
|
+
* Configure useQuery behavior.
|
|
134
134
|
*/
|
|
135
135
|
query?: Partial<Query> | false
|
|
136
136
|
mutationKey?: MutationKey
|
|
137
137
|
/**
|
|
138
|
-
*
|
|
138
|
+
* Configure useMutation behavior.
|
|
139
139
|
*/
|
|
140
140
|
mutation?: Partial<Mutation> | false
|
|
141
141
|
/**
|
|
142
|
-
*
|
|
143
|
-
* `'zod'` uses `@kubb/plugin-zod` to parse the data.
|
|
142
|
+
* Parser to use for validating response data.
|
|
144
143
|
*/
|
|
145
144
|
parser?: PluginClient['options']['parser']
|
|
146
145
|
transformers?: {
|
|
147
146
|
/**
|
|
148
|
-
*
|
|
147
|
+
* Override the default naming for hooks.
|
|
149
148
|
*/
|
|
150
|
-
name?: (name:
|
|
149
|
+
name?: (name: string, type?: string) => string
|
|
151
150
|
}
|
|
152
151
|
/**
|
|
153
|
-
*
|
|
152
|
+
* Override naming conventions for function names and types.
|
|
153
|
+
*/
|
|
154
|
+
resolver?: Partial<ResolverVueQuery> & ThisType<ResolverVueQuery>
|
|
155
|
+
/**
|
|
156
|
+
* AST visitor to transform generated nodes.
|
|
157
|
+
*/
|
|
158
|
+
transformer?: ast.Visitor
|
|
159
|
+
/**
|
|
160
|
+
* Additional generators alongside the default generators.
|
|
154
161
|
*/
|
|
155
162
|
generators?: Array<Generator<PluginVueQuery>>
|
|
156
163
|
}
|
|
157
164
|
|
|
158
165
|
type ResolvedOptions = {
|
|
159
|
-
output: Output
|
|
160
|
-
group:
|
|
166
|
+
output: Output
|
|
167
|
+
group: Group | undefined
|
|
168
|
+
exclude: NonNullable<Options['exclude']>
|
|
169
|
+
include: Options['include']
|
|
170
|
+
override: NonNullable<Options['override']>
|
|
161
171
|
client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>
|
|
162
172
|
parser: Required<NonNullable<Options['parser']>>
|
|
173
|
+
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
163
174
|
paramsCasing: Options['paramsCasing']
|
|
164
175
|
paramsType: NonNullable<Options['paramsType']>
|
|
165
|
-
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
166
176
|
/**
|
|
167
|
-
* Only used
|
|
177
|
+
* Only used for infinite
|
|
168
178
|
*/
|
|
169
179
|
infinite: NonNullable<Infinite> | false
|
|
170
180
|
queryKey: QueryKey | undefined
|
|
171
181
|
query: NonNullable<Required<Query>> | false
|
|
172
182
|
mutationKey: MutationKey | undefined
|
|
173
183
|
mutation: NonNullable<Required<Mutation>> | false
|
|
184
|
+
resolver: ResolverVueQuery
|
|
185
|
+
transformers: NonNullable<Options['transformers']>
|
|
174
186
|
}
|
|
175
187
|
|
|
176
|
-
export type PluginVueQuery = PluginFactoryOptions<'plugin-vue-query', Options, ResolvedOptions,
|
|
188
|
+
export type PluginVueQuery = PluginFactoryOptions<'plugin-vue-query', Options, ResolvedOptions, ResolverVueQuery>
|
|
189
|
+
|
|
190
|
+
declare global {
|
|
191
|
+
namespace Kubb {
|
|
192
|
+
interface PluginRegistry {
|
|
193
|
+
'plugin-vue-query': PluginVueQuery
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ast } from '@kubb/core'
|
|
2
|
+
import type { PluginVueQuery } from './types.ts'
|
|
3
|
+
|
|
4
|
+
export {
|
|
5
|
+
buildGroupParam,
|
|
6
|
+
buildMutationArgParams,
|
|
7
|
+
buildQueryKeyParams,
|
|
8
|
+
getComments,
|
|
9
|
+
resolveErrorNames,
|
|
10
|
+
resolveHeaderGroupType,
|
|
11
|
+
resolvePathParamType,
|
|
12
|
+
resolveQueryGroupType,
|
|
13
|
+
resolveStatusCodeNames,
|
|
14
|
+
} from '@internals/tanstack-query'
|
|
15
|
+
|
|
16
|
+
export function transformName(name: string, type: string, transformers?: PluginVueQuery['resolvedOptions']['transformers']): string {
|
|
17
|
+
return transformers?.name?.(name, type) || name
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function matchesPattern(node: ast.OperationNode, ov: { type: string; pattern: string | RegExp }): boolean {
|
|
21
|
+
const { type, pattern } = ov
|
|
22
|
+
const matches = (value: string) => (typeof pattern === 'string' ? value === pattern : pattern.test(value))
|
|
23
|
+
if (type === 'operationId') return matches(node.operationId)
|
|
24
|
+
if (type === 'tag') return node.tags.some((t) => matches(t))
|
|
25
|
+
if (type === 'path') return matches(node.path)
|
|
26
|
+
if (type === 'method') return matches(node.method)
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function resolveOperationOverrides(
|
|
31
|
+
node: ast.OperationNode,
|
|
32
|
+
override?: PluginVueQuery['resolvedOptions']['override'],
|
|
33
|
+
): Partial<PluginVueQuery['resolvedOptions']> {
|
|
34
|
+
if (!override) return {}
|
|
35
|
+
const match = override.find((ov) => matchesPattern(node, ov as { type: string; pattern: string | RegExp }))
|
|
36
|
+
return (match as { options?: Partial<PluginVueQuery['resolvedOptions']> })?.options ?? {}
|
|
37
|
+
}
|