@kubb/plugin-vue-query 5.0.0-beta.42 → 5.0.0-beta.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{components-Bxe1EuWf.js → components-CAlEf7Oh.js} +273 -388
- package/dist/components-CAlEf7Oh.js.map +1 -0
- package/dist/{components-BwFPMwK7.cjs → components-CfU59l8V.cjs} +274 -389
- package/dist/components-CfU59l8V.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-BSN6A0ED.cjs → generators-DpMLVmyi.cjs} +91 -137
- package/dist/generators-DpMLVmyi.cjs.map +1 -0
- package/dist/{generators-D9TUvYRN.js → generators-fWBjs0CN.js} +93 -139
- package/dist/generators-fWBjs0CN.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +41 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +42 -19
- package/dist/index.js.map +1 -1
- package/dist/{types-HHnnlEhK.d.ts → types-C6a_58nb.d.ts} +12 -16
- package/package.json +10 -18
- package/dist/components-BwFPMwK7.cjs.map +0 -1
- package/dist/components-Bxe1EuWf.js.map +0 -1
- package/dist/generators-BSN6A0ED.cjs.map +0 -1
- package/dist/generators-D9TUvYRN.js.map +0 -1
- package/extension.yaml +0 -1248
- package/src/components/InfiniteQuery.tsx +0 -127
- package/src/components/InfiniteQueryOptions.tsx +0 -194
- package/src/components/Mutation.tsx +0 -150
- package/src/components/MutationKey.tsx +0 -1
- package/src/components/Query.tsx +0 -126
- package/src/components/QueryKey.tsx +0 -52
- package/src/components/QueryOptions.tsx +0 -137
- package/src/components/index.ts +0 -7
- package/src/generators/index.ts +0 -3
- package/src/generators/infiniteQueryGenerator.tsx +0 -200
- package/src/generators/mutationGenerator.tsx +0 -158
- package/src/generators/queryGenerator.tsx +0 -184
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -183
- package/src/resolvers/resolverVueQuery.ts +0 -76
- package/src/types.ts +0 -272
- package/src/utils.ts +0 -56
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { operationFileEntry, resolveOperationTypeNames } from '@internals/shared'
|
|
3
|
-
import { resolveZodSchemaNames } from '@internals/tanstack-query'
|
|
4
|
-
import { ast, defineGenerator } from '@kubb/core'
|
|
5
|
-
import { Client, pluginClientName } from '@kubb/plugin-client'
|
|
6
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
8
|
-
import { File, jsxRendererSync } from '@kubb/renderer-jsx'
|
|
9
|
-
import { 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: jsxRendererSync,
|
|
20
|
-
operation(node, ctx) {
|
|
21
|
-
if (!ast.isHttpOperationNode(node)) return null
|
|
22
|
-
const { config, driver, resolver, root } = ctx
|
|
23
|
-
const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group } = ctx.options
|
|
24
|
-
|
|
25
|
-
const pluginTs = driver.getPlugin(pluginTsName)
|
|
26
|
-
if (!pluginTs) return null
|
|
27
|
-
const tsResolver = driver.getResolver(pluginTsName)
|
|
28
|
-
|
|
29
|
-
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
30
|
-
const queryMethods = new Set(query ? query.methods : [])
|
|
31
|
-
const isMutation =
|
|
32
|
-
mutation !== false &&
|
|
33
|
-
!isQuery &&
|
|
34
|
-
(mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
|
|
35
|
-
|
|
36
|
-
if (!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 = parser === 'zod' ? 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)
|
|
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
|
-
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
101
|
-
</>
|
|
102
|
-
) : (
|
|
103
|
-
<>
|
|
104
|
-
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
105
|
-
<File.Import
|
|
106
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
107
|
-
root={meta.file.path}
|
|
108
|
-
path={path.resolve(root, '.kubb/client.ts')}
|
|
109
|
-
isTypeOnly
|
|
110
|
-
/>
|
|
111
|
-
{clientOptions.dataReturnType === 'full' && (
|
|
112
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} isTypeOnly />
|
|
113
|
-
)}
|
|
114
|
-
</>
|
|
115
|
-
)}
|
|
116
|
-
<File.Import name={['toValue']} path="vue" />
|
|
117
|
-
<File.Import name={['MaybeRefOrGetter']} path="vue" isTypeOnly />
|
|
118
|
-
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
119
|
-
{!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
|
|
120
|
-
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
121
|
-
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
122
|
-
)}
|
|
123
|
-
|
|
124
|
-
<QueryKey
|
|
125
|
-
name={queryKeyName}
|
|
126
|
-
typeName={queryKeyTypeName}
|
|
127
|
-
node={node}
|
|
128
|
-
tsResolver={tsResolver}
|
|
129
|
-
pathParamsType={pathParamsType}
|
|
130
|
-
paramsCasing={paramsCasing}
|
|
131
|
-
transformer={ctx.options.queryKey}
|
|
132
|
-
/>
|
|
133
|
-
|
|
134
|
-
{!shouldUseClientPlugin && (
|
|
135
|
-
<Client
|
|
136
|
-
name={resolvedClientName}
|
|
137
|
-
baseURL={clientOptions.baseURL}
|
|
138
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
139
|
-
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
140
|
-
paramsType={paramsType}
|
|
141
|
-
pathParamsType={pathParamsType}
|
|
142
|
-
parser={parser}
|
|
143
|
-
node={node}
|
|
144
|
-
tsResolver={tsResolver}
|
|
145
|
-
zodResolver={zodResolver}
|
|
146
|
-
/>
|
|
147
|
-
)}
|
|
148
|
-
|
|
149
|
-
<File.Import name={['queryOptions']} path={importPath} />
|
|
150
|
-
|
|
151
|
-
<QueryOptions
|
|
152
|
-
name={queryOptionsName}
|
|
153
|
-
clientName={resolvedClientName}
|
|
154
|
-
queryKeyName={queryKeyName}
|
|
155
|
-
node={node}
|
|
156
|
-
tsResolver={tsResolver}
|
|
157
|
-
paramsCasing={paramsCasing}
|
|
158
|
-
paramsType={paramsType}
|
|
159
|
-
pathParamsType={pathParamsType}
|
|
160
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
161
|
-
/>
|
|
162
|
-
|
|
163
|
-
{query && (
|
|
164
|
-
<>
|
|
165
|
-
<File.Import name={['useQuery']} path={importPath} />
|
|
166
|
-
<File.Import name={['QueryKey', 'QueryClient', 'UseQueryOptions', 'UseQueryReturnType']} path={importPath} isTypeOnly />
|
|
167
|
-
<Query
|
|
168
|
-
name={queryName}
|
|
169
|
-
queryOptionsName={queryOptionsName}
|
|
170
|
-
queryKeyName={queryKeyName}
|
|
171
|
-
queryKeyTypeName={queryKeyTypeName}
|
|
172
|
-
node={node}
|
|
173
|
-
tsResolver={tsResolver}
|
|
174
|
-
paramsCasing={paramsCasing}
|
|
175
|
-
paramsType={paramsType}
|
|
176
|
-
pathParamsType={pathParamsType}
|
|
177
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
178
|
-
/>
|
|
179
|
-
</>
|
|
180
|
-
)}
|
|
181
|
-
</File>
|
|
182
|
-
)
|
|
183
|
-
},
|
|
184
|
-
})
|
package/src/index.ts
DELETED
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 { 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', barrelType: '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, { suffix: 'Controller' })
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
name: pluginVueQueryName,
|
|
79
|
-
options,
|
|
80
|
-
dependencies: [pluginTsName, parser === 'zod' ? 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 } 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 camelCase(name, { isFile: type === 'file' })
|
|
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
|
-
}))
|