@kubb/plugin-swr 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-CD7ZoS3B.cjs → components-DxWGjLWg.cjs} +231 -313
- package/dist/components-DxWGjLWg.cjs.map +1 -0
- package/dist/{components-BuLagnaM.js → components-mWBRE6E4.js} +232 -314
- package/dist/components-mWBRE6E4.js.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-D_Cz5DDw.cjs → generators-CJ4ziuNk.cjs} +66 -90
- package/dist/generators-CJ4ziuNk.cjs.map +1 -0
- package/dist/{generators-CSinCSzM.js → generators-D2blgLOY.js} +67 -91
- package/dist/generators-D2blgLOY.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +6 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +68 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +69 -19
- package/dist/index.js.map +1 -1
- package/dist/{types-BoANASs2.d.ts → types-DcBaH0gA.d.ts} +13 -16
- package/package.json +10 -18
- package/dist/components-BuLagnaM.js.map +0 -1
- package/dist/components-CD7ZoS3B.cjs.map +0 -1
- package/dist/generators-CSinCSzM.js.map +0 -1
- package/dist/generators-D_Cz5DDw.cjs.map +0 -1
- package/extension.yaml +0 -199
- package/src/components/Mutation.tsx +0 -155
- package/src/components/MutationKey.tsx +0 -25
- package/src/components/Query.tsx +0 -128
- package/src/components/QueryKey.tsx +0 -1
- package/src/components/QueryOptions.tsx +0 -74
- package/src/components/index.ts +0 -5
- package/src/generators/index.ts +0 -2
- package/src/generators/mutationGenerator.tsx +0 -162
- package/src/generators/queryGenerator.tsx +0 -174
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -154
- package/src/resolvers/resolverSwr.ts +0 -56
- package/src/types.ts +0 -197
- package/src/utils.ts +0 -10
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { 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, jsxRenderer } from '@kubb/renderer-jsx'
|
|
9
|
-
import { Query, QueryKey, QueryOptions } from '../components'
|
|
10
|
-
import type { PluginSwr } from '../types'
|
|
11
|
-
|
|
12
|
-
export const queryGenerator = defineGenerator<PluginSwr>({
|
|
13
|
-
name: 'swr-query',
|
|
14
|
-
renderer: jsxRenderer,
|
|
15
|
-
operation(node, ctx) {
|
|
16
|
-
if (!ast.isHttpOperationNode(node)) return null
|
|
17
|
-
const { config, driver, resolver, root } = ctx
|
|
18
|
-
const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group } = ctx.options
|
|
19
|
-
|
|
20
|
-
const pluginTs = driver.getPlugin(pluginTsName)
|
|
21
|
-
if (!pluginTs) return null
|
|
22
|
-
const tsResolver = driver.getResolver(pluginTsName)
|
|
23
|
-
|
|
24
|
-
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
25
|
-
const queryMethods = new Set(query ? query.methods : [])
|
|
26
|
-
const isMutation =
|
|
27
|
-
mutation !== false &&
|
|
28
|
-
!isQuery &&
|
|
29
|
-
(mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
|
|
30
|
-
|
|
31
|
-
if (!isQuery || isMutation) return null
|
|
32
|
-
|
|
33
|
-
const importPath = query ? query.importPath : 'swr'
|
|
34
|
-
|
|
35
|
-
const queryName = resolver.resolveQueryName(node)
|
|
36
|
-
const queryOptionsName = resolver.resolveQueryOptionsName(node)
|
|
37
|
-
const queryKeyName = resolver.resolveQueryKeyName(node)
|
|
38
|
-
const queryKeyTypeName = resolver.resolveQueryKeyTypeName(node)
|
|
39
|
-
const clientName = resolver.resolveClientName(node)
|
|
40
|
-
|
|
41
|
-
const meta = {
|
|
42
|
-
file: resolver.resolveFile({ name: queryName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
|
|
43
|
-
fileTs: tsResolver.resolveFile(
|
|
44
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
45
|
-
{ root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group },
|
|
46
|
-
),
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
50
|
-
paramsCasing,
|
|
51
|
-
exclude: [queryKeyTypeName],
|
|
52
|
-
order: 'body-response-first',
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : undefined
|
|
56
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : undefined
|
|
57
|
-
const fileZod = zodResolver
|
|
58
|
-
? zodResolver.resolveFile(
|
|
59
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
60
|
-
{ root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
|
|
61
|
-
)
|
|
62
|
-
: undefined
|
|
63
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
|
|
64
|
-
|
|
65
|
-
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
66
|
-
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
67
|
-
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
68
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : undefined
|
|
69
|
-
|
|
70
|
-
const clientFile = shouldUseClientPlugin
|
|
71
|
-
? clientResolver?.resolveFile(
|
|
72
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
73
|
-
{
|
|
74
|
-
root,
|
|
75
|
-
output: clientPlugin?.options?.output ?? output,
|
|
76
|
-
group: clientPlugin?.options?.group,
|
|
77
|
-
},
|
|
78
|
-
)
|
|
79
|
-
: undefined
|
|
80
|
-
|
|
81
|
-
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientName) : clientName
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<File
|
|
85
|
-
baseName={meta.file.baseName}
|
|
86
|
-
path={meta.file.path}
|
|
87
|
-
meta={meta.file.meta}
|
|
88
|
-
banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
89
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
90
|
-
>
|
|
91
|
-
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
92
|
-
{clientOptions.importPath ? (
|
|
93
|
-
<>
|
|
94
|
-
{!shouldUseClientPlugin && <File.Import name={'client'} path={clientOptions.importPath} />}
|
|
95
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
96
|
-
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
97
|
-
</>
|
|
98
|
-
) : (
|
|
99
|
-
<>
|
|
100
|
-
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
101
|
-
<File.Import
|
|
102
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
103
|
-
root={meta.file.path}
|
|
104
|
-
path={path.resolve(root, '.kubb/client.ts')}
|
|
105
|
-
isTypeOnly
|
|
106
|
-
/>
|
|
107
|
-
{clientOptions.dataReturnType === 'full' && (
|
|
108
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} isTypeOnly />
|
|
109
|
-
)}
|
|
110
|
-
</>
|
|
111
|
-
)}
|
|
112
|
-
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
113
|
-
{!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
|
|
114
|
-
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
115
|
-
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
116
|
-
)}
|
|
117
|
-
|
|
118
|
-
<QueryKey
|
|
119
|
-
name={queryKeyName}
|
|
120
|
-
typeName={queryKeyTypeName}
|
|
121
|
-
node={node}
|
|
122
|
-
tsResolver={tsResolver}
|
|
123
|
-
pathParamsType={pathParamsType}
|
|
124
|
-
paramsCasing={paramsCasing}
|
|
125
|
-
transformer={ctx.options.queryKey}
|
|
126
|
-
/>
|
|
127
|
-
|
|
128
|
-
{!shouldUseClientPlugin && (
|
|
129
|
-
<Client
|
|
130
|
-
name={resolvedClientName}
|
|
131
|
-
baseURL={clientOptions.baseURL}
|
|
132
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
133
|
-
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
134
|
-
paramsType={paramsType}
|
|
135
|
-
pathParamsType={pathParamsType}
|
|
136
|
-
parser={parser}
|
|
137
|
-
node={node}
|
|
138
|
-
tsResolver={tsResolver}
|
|
139
|
-
zodResolver={zodResolver}
|
|
140
|
-
/>
|
|
141
|
-
)}
|
|
142
|
-
|
|
143
|
-
<QueryOptions
|
|
144
|
-
name={queryOptionsName}
|
|
145
|
-
clientName={resolvedClientName}
|
|
146
|
-
node={node}
|
|
147
|
-
tsResolver={tsResolver}
|
|
148
|
-
paramsCasing={paramsCasing}
|
|
149
|
-
paramsType={paramsType}
|
|
150
|
-
pathParamsType={pathParamsType}
|
|
151
|
-
/>
|
|
152
|
-
|
|
153
|
-
{query && (
|
|
154
|
-
<>
|
|
155
|
-
<File.Import name={'useSWR'} path={importPath} />
|
|
156
|
-
<File.Import name={['SWRConfiguration']} path={importPath} isTypeOnly />
|
|
157
|
-
<Query
|
|
158
|
-
name={queryName}
|
|
159
|
-
queryOptionsName={queryOptionsName}
|
|
160
|
-
queryKeyName={queryKeyName}
|
|
161
|
-
queryKeyTypeName={queryKeyTypeName}
|
|
162
|
-
node={node}
|
|
163
|
-
tsResolver={tsResolver}
|
|
164
|
-
paramsCasing={paramsCasing}
|
|
165
|
-
paramsType={paramsType}
|
|
166
|
-
pathParamsType={pathParamsType}
|
|
167
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
168
|
-
/>
|
|
169
|
-
</>
|
|
170
|
-
)}
|
|
171
|
-
</File>
|
|
172
|
-
)
|
|
173
|
-
},
|
|
174
|
-
})
|
package/src/index.ts
DELETED
package/src/plugin.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { camelCase } from '@internals/utils'
|
|
3
|
-
import { ast, definePlugin, type Group } 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, queryKeyTransformer } from '@internals/tanstack-query'
|
|
11
|
-
import { mutationGenerator, queryGenerator } from './generators'
|
|
12
|
-
import { resolverSwr } from './resolvers/resolverSwr.ts'
|
|
13
|
-
import type { PluginSwr } from './types.ts'
|
|
14
|
-
|
|
15
|
-
export const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']
|
|
16
|
-
|
|
17
|
-
export const pluginSwr = definePlugin<PluginSwr>((options) => {
|
|
18
|
-
const {
|
|
19
|
-
output = { path: 'hooks', barrelType: 'named' },
|
|
20
|
-
group,
|
|
21
|
-
exclude = [],
|
|
22
|
-
include,
|
|
23
|
-
override = [],
|
|
24
|
-
parser = false,
|
|
25
|
-
paramsType = 'inline',
|
|
26
|
-
pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',
|
|
27
|
-
mutation = {},
|
|
28
|
-
query = {},
|
|
29
|
-
mutationKey = mutationKeyTransformer,
|
|
30
|
-
queryKey = queryKeyTransformer,
|
|
31
|
-
paramsCasing,
|
|
32
|
-
client,
|
|
33
|
-
resolver: userResolver,
|
|
34
|
-
transformer: userTransformer,
|
|
35
|
-
generators: userGenerators = [],
|
|
36
|
-
} = options
|
|
37
|
-
|
|
38
|
-
const clientName = client?.client ?? 'axios'
|
|
39
|
-
const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)
|
|
40
|
-
|
|
41
|
-
const selectedGenerators =
|
|
42
|
-
options.generators ?? [queryGenerator, mutationGenerator].filter((generator): generator is NonNullable<typeof generator> => Boolean(generator))
|
|
43
|
-
|
|
44
|
-
const groupConfig = group
|
|
45
|
-
? ({
|
|
46
|
-
...group,
|
|
47
|
-
name: group.name
|
|
48
|
-
? group.name
|
|
49
|
-
: (ctx: { group: string }) => {
|
|
50
|
-
if (group.type === 'path') {
|
|
51
|
-
return `${ctx.group.split('/')[1]}`
|
|
52
|
-
}
|
|
53
|
-
return `${camelCase(ctx.group)}Controller`
|
|
54
|
-
},
|
|
55
|
-
} satisfies Group)
|
|
56
|
-
: undefined
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
name: pluginSwrName,
|
|
60
|
-
options,
|
|
61
|
-
dependencies: [pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter((dependency): dependency is string => Boolean(dependency)),
|
|
62
|
-
hooks: {
|
|
63
|
-
'kubb:plugin:setup'(ctx) {
|
|
64
|
-
const resolver = userResolver ? { ...resolverSwr, ...userResolver } : resolverSwr
|
|
65
|
-
|
|
66
|
-
ctx.setOptions({
|
|
67
|
-
output,
|
|
68
|
-
client: {
|
|
69
|
-
bundle: client?.bundle,
|
|
70
|
-
baseURL: client?.baseURL,
|
|
71
|
-
client: clientName,
|
|
72
|
-
clientType: client?.clientType ?? 'function',
|
|
73
|
-
importPath: clientImportPath,
|
|
74
|
-
dataReturnType: client?.dataReturnType ?? 'data',
|
|
75
|
-
paramsCasing,
|
|
76
|
-
},
|
|
77
|
-
queryKey,
|
|
78
|
-
query:
|
|
79
|
-
query === false
|
|
80
|
-
? false
|
|
81
|
-
: {
|
|
82
|
-
importPath: 'swr',
|
|
83
|
-
methods: ['get'],
|
|
84
|
-
...query,
|
|
85
|
-
},
|
|
86
|
-
mutationKey,
|
|
87
|
-
mutation:
|
|
88
|
-
mutation === false
|
|
89
|
-
? false
|
|
90
|
-
: {
|
|
91
|
-
importPath: 'swr/mutation',
|
|
92
|
-
methods: ['post', 'put', 'patch', 'delete'],
|
|
93
|
-
...mutation,
|
|
94
|
-
},
|
|
95
|
-
parser,
|
|
96
|
-
paramsType,
|
|
97
|
-
pathParamsType,
|
|
98
|
-
paramsCasing,
|
|
99
|
-
group: groupConfig,
|
|
100
|
-
exclude,
|
|
101
|
-
include,
|
|
102
|
-
override,
|
|
103
|
-
resolver,
|
|
104
|
-
})
|
|
105
|
-
ctx.setResolver(resolver)
|
|
106
|
-
if (userTransformer) {
|
|
107
|
-
ctx.setTransformer(userTransformer)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
for (const gen of selectedGenerators) {
|
|
111
|
-
ctx.addGenerator(gen)
|
|
112
|
-
}
|
|
113
|
-
for (const gen of userGenerators) {
|
|
114
|
-
ctx.addGenerator(gen)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const root = path.resolve(ctx.config.root, ctx.config.output.path)
|
|
118
|
-
const hasClientPlugin = !!ctx.config.plugins?.some((p) => (p as { name?: string }).name === pluginClientName)
|
|
119
|
-
|
|
120
|
-
if (client?.bundle && !hasClientPlugin && !clientImportPath) {
|
|
121
|
-
ctx.injectFile({
|
|
122
|
-
baseName: 'client.ts',
|
|
123
|
-
path: path.resolve(root, '.kubb/client.ts'),
|
|
124
|
-
sources: [
|
|
125
|
-
ast.createSource({
|
|
126
|
-
name: 'client',
|
|
127
|
-
nodes: [ast.createText(clientName === 'fetch' ? fetchClientSource : axiosClientSource)],
|
|
128
|
-
isExportable: true,
|
|
129
|
-
isIndexable: true,
|
|
130
|
-
}),
|
|
131
|
-
],
|
|
132
|
-
})
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (!hasClientPlugin) {
|
|
136
|
-
ctx.injectFile({
|
|
137
|
-
baseName: 'config.ts',
|
|
138
|
-
path: path.resolve(root, '.kubb/config.ts'),
|
|
139
|
-
sources: [
|
|
140
|
-
ast.createSource({
|
|
141
|
-
name: 'config',
|
|
142
|
-
nodes: [ast.createText(configSource)],
|
|
143
|
-
isExportable: false,
|
|
144
|
-
isIndexable: false,
|
|
145
|
-
}),
|
|
146
|
-
],
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
export default pluginSwr
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { camelCase } from '@internals/utils'
|
|
2
|
-
import { defineResolver } from '@kubb/core'
|
|
3
|
-
import type { PluginSwr } from '../types.ts'
|
|
4
|
-
|
|
5
|
-
function capitalize(name: string): string {
|
|
6
|
-
return `${name.charAt(0).toUpperCase()}${name.slice(1)}`
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Naming convention resolver for the SWR plugin.
|
|
11
|
-
*
|
|
12
|
-
* Provides default naming helpers using camelCase for functions and file paths.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* `resolverSwr.default('list pets', 'function') // → 'listPets'`
|
|
16
|
-
*/
|
|
17
|
-
export const resolverSwr = defineResolver<PluginSwr>(() => ({
|
|
18
|
-
name: 'default',
|
|
19
|
-
pluginName: 'plugin-swr',
|
|
20
|
-
default(name, type) {
|
|
21
|
-
return camelCase(name, { isFile: type === 'file' })
|
|
22
|
-
},
|
|
23
|
-
resolveName(name) {
|
|
24
|
-
return this.default(name, 'function')
|
|
25
|
-
},
|
|
26
|
-
resolvePathName(name, type) {
|
|
27
|
-
return this.default(name, type)
|
|
28
|
-
},
|
|
29
|
-
resolveQueryName(node) {
|
|
30
|
-
return `use${capitalize(this.resolveName(node.operationId))}`
|
|
31
|
-
},
|
|
32
|
-
resolveMutationName(node) {
|
|
33
|
-
return `use${capitalize(this.resolveName(node.operationId))}`
|
|
34
|
-
},
|
|
35
|
-
resolveQueryOptionsName(node) {
|
|
36
|
-
return `${this.resolveName(node.operationId)}QueryOptions`
|
|
37
|
-
},
|
|
38
|
-
resolveQueryKeyName(node) {
|
|
39
|
-
return `${this.resolveName(node.operationId)}QueryKey`
|
|
40
|
-
},
|
|
41
|
-
resolveMutationKeyName(node) {
|
|
42
|
-
return `${this.resolveName(node.operationId)}MutationKey`
|
|
43
|
-
},
|
|
44
|
-
resolveQueryKeyTypeName(node) {
|
|
45
|
-
return `${capitalize(this.resolveName(node.operationId))}QueryKey`
|
|
46
|
-
},
|
|
47
|
-
resolveMutationKeyTypeName(node) {
|
|
48
|
-
return `${capitalize(this.resolveName(node.operationId))}MutationKey`
|
|
49
|
-
},
|
|
50
|
-
resolveMutationArgTypeName(node) {
|
|
51
|
-
return `${capitalize(this.resolveName(node.operationId))}MutationArg`
|
|
52
|
-
},
|
|
53
|
-
resolveClientName(node) {
|
|
54
|
-
return this.resolveName(node.operationId)
|
|
55
|
-
},
|
|
56
|
-
}))
|
package/src/types.ts
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import type { Transformer } from '@internals/tanstack-query'
|
|
2
|
-
import type { ast, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver } from '@kubb/core'
|
|
3
|
-
import type { ClientImportPath, PluginClient } from '@kubb/plugin-client'
|
|
4
|
-
|
|
5
|
-
export type { Transformer } from '@internals/tanstack-query'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Resolver for SWR that provides naming methods for hook functions.
|
|
9
|
-
*/
|
|
10
|
-
export type ResolverSwr = Resolver & {
|
|
11
|
-
/**
|
|
12
|
-
* Resolves the base function name for an operation.
|
|
13
|
-
*
|
|
14
|
-
* @example Resolving base operation names
|
|
15
|
-
* `resolver.resolveName('show pet by id') // -> 'showPetById'`
|
|
16
|
-
*/
|
|
17
|
-
resolveName(this: ResolverSwr, name: string): string
|
|
18
|
-
/**
|
|
19
|
-
* Resolves the output file name for a hook module.
|
|
20
|
-
*/
|
|
21
|
-
resolvePathName(this: ResolverSwr, name: string, type?: 'file' | 'function' | 'type' | 'const'): string
|
|
22
|
-
/**
|
|
23
|
-
* Resolves a query hook function name.
|
|
24
|
-
*/
|
|
25
|
-
resolveQueryName(this: ResolverSwr, node: ast.OperationNode): string
|
|
26
|
-
/**
|
|
27
|
-
* Resolves a mutation hook function name.
|
|
28
|
-
*/
|
|
29
|
-
resolveMutationName(this: ResolverSwr, node: ast.OperationNode): string
|
|
30
|
-
/**
|
|
31
|
-
* Resolves the query options helper name.
|
|
32
|
-
*/
|
|
33
|
-
resolveQueryOptionsName(this: ResolverSwr, node: ast.OperationNode): string
|
|
34
|
-
/**
|
|
35
|
-
* Resolves the query key helper name.
|
|
36
|
-
*/
|
|
37
|
-
resolveQueryKeyName(this: ResolverSwr, node: ast.OperationNode): string
|
|
38
|
-
/**
|
|
39
|
-
* Resolves the mutation key helper name.
|
|
40
|
-
*/
|
|
41
|
-
resolveMutationKeyName(this: ResolverSwr, node: ast.OperationNode): string
|
|
42
|
-
/**
|
|
43
|
-
* Resolves the query key type name.
|
|
44
|
-
*/
|
|
45
|
-
resolveQueryKeyTypeName(this: ResolverSwr, node: ast.OperationNode): string
|
|
46
|
-
/**
|
|
47
|
-
* Resolves the mutation key type name.
|
|
48
|
-
*/
|
|
49
|
-
resolveMutationKeyTypeName(this: ResolverSwr, node: ast.OperationNode): string
|
|
50
|
-
/**
|
|
51
|
-
* Resolves the mutation argument type name emitted alongside the mutation hook.
|
|
52
|
-
*/
|
|
53
|
-
resolveMutationArgTypeName(this: ResolverSwr, node: ast.OperationNode): string
|
|
54
|
-
/**
|
|
55
|
-
* Resolves the client function name generated inline by query hooks.
|
|
56
|
-
*/
|
|
57
|
-
resolveClientName(this: ResolverSwr, node: ast.OperationNode): string
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Customize the queryKey.
|
|
62
|
-
*/
|
|
63
|
-
type QueryKey = Transformer
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Customize the mutationKey.
|
|
67
|
-
*/
|
|
68
|
-
type MutationKey = Transformer
|
|
69
|
-
|
|
70
|
-
type Query = {
|
|
71
|
-
/**
|
|
72
|
-
* HTTP methods to use for queries.
|
|
73
|
-
*
|
|
74
|
-
* @default ['get']
|
|
75
|
-
*/
|
|
76
|
-
methods?: Array<string>
|
|
77
|
-
/**
|
|
78
|
-
* Path to the useSWR hook for useSWR functionality.
|
|
79
|
-
* Used as `import useSWR from '${importPath}'`.
|
|
80
|
-
* Accepts relative and absolute paths.
|
|
81
|
-
* Path is used as-is; relative paths are based on the generated file location.
|
|
82
|
-
* @default 'swr'
|
|
83
|
-
*/
|
|
84
|
-
importPath?: string
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
type Mutation = {
|
|
88
|
-
/**
|
|
89
|
-
* HTTP methods to use for mutations.
|
|
90
|
-
*
|
|
91
|
-
* @default ['post', 'put', 'delete', 'patch']
|
|
92
|
-
*/
|
|
93
|
-
methods?: Array<string>
|
|
94
|
-
/**
|
|
95
|
-
* Path to the useSWRMutation hook for useSWRMutation functionality.
|
|
96
|
-
* Used as `import useSWRMutation from '${importPath}'`.
|
|
97
|
-
* Accepts relative and absolute paths.
|
|
98
|
-
* Path is used as-is; relative paths are based on the generated file location.
|
|
99
|
-
* @default 'swr/mutation'
|
|
100
|
-
*/
|
|
101
|
-
importPath?: string
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export type Options = {
|
|
105
|
-
/**
|
|
106
|
-
* Specify the export location for the files and define the behavior of the output
|
|
107
|
-
* @default { path: 'hooks', barrelType: 'named' }
|
|
108
|
-
*/
|
|
109
|
-
output?: Output
|
|
110
|
-
/**
|
|
111
|
-
* Group the SWR hooks based on the provided name.
|
|
112
|
-
*/
|
|
113
|
-
group?: Group
|
|
114
|
-
client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>
|
|
115
|
-
/**
|
|
116
|
-
* Tags, operations, or paths to exclude from generation.
|
|
117
|
-
*/
|
|
118
|
-
exclude?: Array<Exclude>
|
|
119
|
-
/**
|
|
120
|
-
* Tags, operations, or paths to include in generation.
|
|
121
|
-
*/
|
|
122
|
-
include?: Array<Include>
|
|
123
|
-
/**
|
|
124
|
-
* Override options for specific tags, operations, or paths.
|
|
125
|
-
*/
|
|
126
|
-
override?: Array<Override<ResolvedOptions>>
|
|
127
|
-
/**
|
|
128
|
-
* Apply casing to parameter names.
|
|
129
|
-
*/
|
|
130
|
-
paramsCasing?: 'camelcase'
|
|
131
|
-
/**
|
|
132
|
-
* How parameters are passed: grouped in an object or spread inline.
|
|
133
|
-
*
|
|
134
|
-
* @default 'inline'
|
|
135
|
-
*/
|
|
136
|
-
paramsType?: 'object' | 'inline'
|
|
137
|
-
/**
|
|
138
|
-
* How path parameters are passed: grouped in an object or spread inline.
|
|
139
|
-
*
|
|
140
|
-
* @default 'inline'
|
|
141
|
-
*/
|
|
142
|
-
pathParamsType?: PluginClient['options']['pathParamsType']
|
|
143
|
-
queryKey?: QueryKey
|
|
144
|
-
/**
|
|
145
|
-
* Configure useSWR behavior.
|
|
146
|
-
*/
|
|
147
|
-
query?: Partial<Query> | false
|
|
148
|
-
mutationKey?: MutationKey
|
|
149
|
-
/**
|
|
150
|
-
* Configure useSWRMutation behavior.
|
|
151
|
-
*/
|
|
152
|
-
mutation?: Partial<Mutation> | false
|
|
153
|
-
/**
|
|
154
|
-
* Parser to use for validating response data.
|
|
155
|
-
*/
|
|
156
|
-
parser?: PluginClient['options']['parser']
|
|
157
|
-
/**
|
|
158
|
-
* Override naming conventions for function names and types.
|
|
159
|
-
*/
|
|
160
|
-
resolver?: Partial<ResolverSwr> & ThisType<ResolverSwr>
|
|
161
|
-
/**
|
|
162
|
-
* AST visitor to transform generated nodes.
|
|
163
|
-
*/
|
|
164
|
-
transformer?: ast.Visitor
|
|
165
|
-
/**
|
|
166
|
-
* Additional generators alongside the default generators.
|
|
167
|
-
*/
|
|
168
|
-
generators?: Array<Generator<PluginSwr>>
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
type ResolvedOptions = {
|
|
172
|
-
output: Output
|
|
173
|
-
group: Group | undefined
|
|
174
|
-
exclude: NonNullable<Options['exclude']>
|
|
175
|
-
include: Options['include']
|
|
176
|
-
override: NonNullable<Options['override']>
|
|
177
|
-
client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>
|
|
178
|
-
parser: Required<NonNullable<Options['parser']>>
|
|
179
|
-
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
180
|
-
paramsCasing: Options['paramsCasing']
|
|
181
|
-
paramsType: NonNullable<Options['paramsType']>
|
|
182
|
-
queryKey: QueryKey | undefined
|
|
183
|
-
query: NonNullable<Required<Query>> | false
|
|
184
|
-
mutationKey: MutationKey | undefined
|
|
185
|
-
mutation: NonNullable<Required<Mutation>> | false
|
|
186
|
-
resolver: ResolverSwr
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export type PluginSwr = PluginFactoryOptions<'plugin-swr', Options, ResolvedOptions, ResolverSwr>
|
|
190
|
-
|
|
191
|
-
declare global {
|
|
192
|
-
namespace Kubb {
|
|
193
|
-
interface PluginRegistry {
|
|
194
|
-
'plugin-swr': PluginSwr
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,10 +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 { buildOperationComments as getComments, buildRequestConfigType, getContentTypeInfo, resolveErrorNames, resolveStatusCodeNames } from '@internals/shared'
|