@kubb/plugin-client 5.0.0-alpha.9 → 5.0.0-beta.10
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 +27 -7
- package/dist/clients/axios.cjs +10 -3
- package/dist/clients/axios.cjs.map +1 -1
- package/dist/clients/axios.d.ts +5 -4
- package/dist/clients/axios.js +9 -2
- package/dist/clients/axios.js.map +1 -1
- package/dist/clients/fetch.cjs +5 -2
- package/dist/clients/fetch.cjs.map +1 -1
- package/dist/clients/fetch.d.ts +3 -2
- package/dist/clients/fetch.js +5 -2
- package/dist/clients/fetch.js.map +1 -1
- package/dist/index.cjs +1818 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +330 -4
- package/dist/index.js +1804 -95
- package/dist/index.js.map +1 -1
- package/dist/templates/clients/axios.source.cjs +1 -1
- package/dist/templates/clients/axios.source.js +1 -1
- package/dist/templates/clients/fetch.source.cjs +1 -1
- package/dist/templates/clients/fetch.source.js +1 -1
- package/extension.yaml +776 -0
- package/package.json +62 -85
- package/src/clients/axios.ts +19 -4
- package/src/clients/fetch.ts +10 -2
- package/src/components/ClassClient.tsx +46 -145
- package/src/components/Client.tsx +109 -139
- package/src/components/Operations.tsx +10 -10
- package/src/components/StaticClassClient.tsx +46 -142
- package/src/components/Url.tsx +38 -50
- package/src/components/WrapperClient.tsx +11 -7
- package/src/functionParams.ts +118 -0
- package/src/generators/classClientGenerator.tsx +143 -172
- package/src/generators/clientGenerator.tsx +83 -81
- package/src/generators/groupedClientGenerator.tsx +50 -52
- package/src/generators/operationsGenerator.tsx +11 -18
- package/src/generators/staticClassClientGenerator.tsx +172 -184
- package/src/index.ts +9 -2
- package/src/plugin.ts +115 -145
- package/src/resolvers/resolverClient.ts +38 -0
- package/src/types.ts +128 -44
- package/src/utils.ts +156 -0
- package/dist/StaticClassClient-By-aMAe4.cjs +0 -677
- package/dist/StaticClassClient-By-aMAe4.cjs.map +0 -1
- package/dist/StaticClassClient-CCn9g9eF.js +0 -636
- package/dist/StaticClassClient-CCn9g9eF.js.map +0 -1
- package/dist/components.cjs +0 -7
- package/dist/components.d.ts +0 -216
- package/dist/components.js +0 -2
- package/dist/generators-BYUJaeZP.js +0 -723
- package/dist/generators-BYUJaeZP.js.map +0 -1
- package/dist/generators-DTxD9FDY.cjs +0 -753
- package/dist/generators-DTxD9FDY.cjs.map +0 -1
- package/dist/generators.cjs +0 -7
- package/dist/generators.d.ts +0 -517
- package/dist/generators.js +0 -2
- package/dist/types-DBQdg-BV.d.ts +0 -169
- package/src/components/index.ts +0 -5
- package/src/generators/index.ts +0 -5
- package/templates/clients/axios.ts +0 -70
- package/templates/clients/fetch.ts +0 -93
- package/templates/config.ts +0 -43
|
@@ -1,47 +1,41 @@
|
|
|
1
1
|
import { camelCase } from '@internals/utils'
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
6
|
-
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
7
|
-
import { File, Function } from '@kubb/react-fabric'
|
|
2
|
+
import type { ast } from '@kubb/core'
|
|
3
|
+
import { defineGenerator } from '@kubb/core'
|
|
4
|
+
import { File, Function, jsxRenderer } from '@kubb/renderer-jsx'
|
|
8
5
|
import type { PluginClient } from '../types'
|
|
9
6
|
|
|
10
|
-
export const groupedClientGenerator =
|
|
7
|
+
export const groupedClientGenerator = defineGenerator<PluginClient>({
|
|
11
8
|
name: 'groupedClient',
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
9
|
+
renderer: jsxRenderer,
|
|
10
|
+
operations(nodes, ctx) {
|
|
11
|
+
const { config, resolver, adapter, root } = ctx
|
|
12
|
+
const { output, group } = ctx.options
|
|
15
13
|
|
|
16
|
-
const
|
|
17
|
-
|
|
14
|
+
const controllers = nodes.reduce(
|
|
15
|
+
(acc, operationNode) => {
|
|
16
|
+
if (group?.type === 'tag') {
|
|
17
|
+
const tag = operationNode.tags[0]
|
|
18
|
+
const name = tag ? group?.name?.({ group: camelCase(tag) }) : undefined
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
(acc, operation) => {
|
|
21
|
-
if (options.group?.type === 'tag') {
|
|
22
|
-
const group = getGroup(operation)
|
|
23
|
-
const name = group?.tag ? options.group?.name?.({ group: camelCase(group.tag) }) : undefined
|
|
24
|
-
|
|
25
|
-
if (!group?.tag || !name) {
|
|
20
|
+
if (!tag || !name) {
|
|
26
21
|
return acc
|
|
27
22
|
}
|
|
28
23
|
|
|
29
|
-
const file =
|
|
30
|
-
|
|
31
|
-
extname: '.ts',
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
})
|
|
24
|
+
const file = resolver.resolveFile({ name, extname: '.ts', tag }, { root, output, group })
|
|
25
|
+
const clientFile = resolver.resolveFile(
|
|
26
|
+
{ name: operationNode.operationId, extname: '.ts', tag: operationNode.tags[0] ?? 'default', path: operationNode.path },
|
|
27
|
+
{ root, output, group },
|
|
28
|
+
)
|
|
35
29
|
|
|
36
30
|
const client = {
|
|
37
|
-
name:
|
|
38
|
-
file:
|
|
31
|
+
name: resolver.resolveName(operationNode.operationId),
|
|
32
|
+
file: clientFile,
|
|
39
33
|
}
|
|
40
34
|
|
|
41
|
-
const
|
|
35
|
+
const previous = acc.find((item) => item.file.path === file.path)
|
|
42
36
|
|
|
43
|
-
if (
|
|
44
|
-
|
|
37
|
+
if (previous) {
|
|
38
|
+
previous.clients.push(client)
|
|
45
39
|
} else {
|
|
46
40
|
acc.push({ name, file, clients: [client] })
|
|
47
41
|
}
|
|
@@ -49,30 +43,34 @@ export const groupedClientGenerator = createReactGenerator<PluginClient>({
|
|
|
49
43
|
|
|
50
44
|
return acc
|
|
51
45
|
},
|
|
52
|
-
[] as Array<{ name: string; file:
|
|
46
|
+
[] as Array<{ name: string; file: ast.FileNode; clients: Array<{ name: string; file: ast.FileNode }> }>,
|
|
53
47
|
)
|
|
54
48
|
|
|
55
|
-
return
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
return (
|
|
50
|
+
<>
|
|
51
|
+
{controllers.map(({ name, file, clients }) => {
|
|
52
|
+
return (
|
|
53
|
+
<File
|
|
54
|
+
key={file.path}
|
|
55
|
+
baseName={file.baseName}
|
|
56
|
+
path={file.path}
|
|
57
|
+
meta={file.meta}
|
|
58
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
59
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
60
|
+
>
|
|
61
|
+
{clients.map((client) => (
|
|
62
|
+
<File.Import key={client.name} name={[client.name]} root={file.path} path={client.file.path} />
|
|
63
|
+
))}
|
|
68
64
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
65
|
+
<File.Source name={name} isExportable isIndexable>
|
|
66
|
+
<Function export name={name}>
|
|
67
|
+
{`return { ${clients.map((client) => client.name).join(', ')} }`}
|
|
68
|
+
</Function>
|
|
69
|
+
</File.Source>
|
|
70
|
+
</File>
|
|
71
|
+
)
|
|
72
|
+
})}
|
|
73
|
+
</>
|
|
74
|
+
)
|
|
77
75
|
},
|
|
78
76
|
})
|
|
@@ -1,34 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { useOas } from '@kubb/plugin-oas/hooks'
|
|
4
|
-
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
5
|
-
import { File } from '@kubb/react-fabric'
|
|
1
|
+
import { defineGenerator } from '@kubb/core'
|
|
2
|
+
import { File, jsxRenderer } from '@kubb/renderer-jsx'
|
|
6
3
|
import { Operations } from '../components/Operations'
|
|
7
4
|
import type { PluginClient } from '../types'
|
|
8
5
|
|
|
9
|
-
export const operationsGenerator =
|
|
6
|
+
export const operationsGenerator = defineGenerator<PluginClient>({
|
|
10
7
|
name: 'client',
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} = plugin
|
|
16
|
-
const driver = usePluginDriver()
|
|
17
|
-
|
|
18
|
-
const oas = useOas()
|
|
8
|
+
renderer: jsxRenderer,
|
|
9
|
+
operations(nodes, ctx) {
|
|
10
|
+
const { config, resolver, adapter, root } = ctx
|
|
11
|
+
const { output, group } = ctx.options
|
|
19
12
|
|
|
20
13
|
const name = 'operations'
|
|
21
|
-
const file =
|
|
14
|
+
const file = resolver.resolveFile({ name, extname: '.ts' }, { root, output, group })
|
|
22
15
|
|
|
23
16
|
return (
|
|
24
17
|
<File
|
|
25
18
|
baseName={file.baseName}
|
|
26
19
|
path={file.path}
|
|
27
20
|
meta={file.meta}
|
|
28
|
-
banner={
|
|
29
|
-
footer={
|
|
21
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
22
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
30
23
|
>
|
|
31
|
-
<Operations name={name}
|
|
24
|
+
<Operations name={name} nodes={nodes} />
|
|
32
25
|
</File>
|
|
33
26
|
)
|
|
34
27
|
},
|
|
@@ -1,132 +1,127 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import
|
|
6
|
-
import type {
|
|
7
|
-
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
8
|
-
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
9
|
-
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
2
|
+
import { resolveOperationTypeNames } from '@internals/shared'
|
|
3
|
+
import { camelCase } from '@internals/utils'
|
|
4
|
+
import type { ast } from '@kubb/core'
|
|
5
|
+
import { defineGenerator } from '@kubb/core'
|
|
6
|
+
import type { ResolverTs } from '@kubb/plugin-ts'
|
|
10
7
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
8
|
+
import type { ResolverZod } from '@kubb/plugin-zod'
|
|
11
9
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
12
|
-
import { File } from '@kubb/
|
|
10
|
+
import { File, jsxRenderer } from '@kubb/renderer-jsx'
|
|
13
11
|
import { StaticClassClient } from '../components/StaticClassClient'
|
|
14
12
|
import type { PluginClient } from '../types'
|
|
15
13
|
|
|
16
14
|
type OperationData = {
|
|
17
|
-
|
|
15
|
+
node: ast.OperationNode
|
|
18
16
|
name: string
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
typeFile:
|
|
22
|
-
zodFile:
|
|
17
|
+
tsResolver: ResolverTs
|
|
18
|
+
zodResolver: ResolverZod | undefined
|
|
19
|
+
typeFile: ast.FileNode
|
|
20
|
+
zodFile: ast.FileNode | undefined
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
type Controller = {
|
|
26
24
|
name: string
|
|
27
|
-
file:
|
|
25
|
+
file: ast.FileNode
|
|
28
26
|
operations: Array<OperationData>
|
|
29
27
|
}
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const { options, name: pluginName } = plugin
|
|
35
|
-
const driver = usePluginDriver()
|
|
36
|
-
|
|
37
|
-
const oas = useOas()
|
|
38
|
-
const { getName, getFile, getGroup, getSchemas } = useOperationManager(generator)
|
|
29
|
+
function resolveTypeImportNames(node: ast.OperationNode, tsResolver: ResolverTs): Array<string> {
|
|
30
|
+
return resolveOperationTypeNames(node, tsResolver, { order: 'body-response-first' })
|
|
31
|
+
}
|
|
39
32
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
function resolveZodImportNames(node: ast.OperationNode, zodResolver: ResolverZod): Array<string> {
|
|
34
|
+
const names: Array<string | undefined> = [
|
|
35
|
+
zodResolver.resolveResponseName?.(node),
|
|
36
|
+
node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : undefined,
|
|
37
|
+
]
|
|
38
|
+
return names.filter((n): n is string => Boolean(n))
|
|
39
|
+
}
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
export const staticClassClientGenerator = defineGenerator<PluginClient>({
|
|
42
|
+
name: 'staticClassClient',
|
|
43
|
+
renderer: jsxRenderer,
|
|
44
|
+
operations(nodes, ctx) {
|
|
45
|
+
const { adapter, config, driver, resolver, root } = ctx
|
|
46
|
+
const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath } = ctx.options
|
|
47
|
+
const baseURL = ctx.options.baseURL ?? adapter.inputNode?.meta?.baseURL
|
|
48
|
+
|
|
49
|
+
const pluginTs = driver.getPlugin(pluginTsName)
|
|
50
|
+
if (!pluginTs) return null
|
|
51
|
+
|
|
52
|
+
const tsResolver = driver.getResolver(pluginTsName)
|
|
53
|
+
const tsPluginOptions = pluginTs.options
|
|
54
|
+
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : undefined
|
|
55
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : undefined
|
|
56
|
+
|
|
57
|
+
function buildOperationData(node: ast.OperationNode): OperationData {
|
|
58
|
+
const typeFile = tsResolver.resolveFile(
|
|
59
|
+
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
60
|
+
{ root, output: tsPluginOptions?.output ?? output, group: tsPluginOptions?.group },
|
|
61
|
+
)
|
|
62
|
+
const zodFile =
|
|
63
|
+
zodResolver && pluginZod?.options
|
|
64
|
+
? zodResolver.resolveFile(
|
|
65
|
+
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
66
|
+
{ root, output: pluginZod.options?.output ?? output, group: pluginZod.options?.group },
|
|
67
|
+
)
|
|
68
|
+
: undefined
|
|
50
69
|
|
|
51
70
|
return {
|
|
52
|
-
|
|
53
|
-
name:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
typeFile
|
|
57
|
-
zodFile
|
|
71
|
+
node: node,
|
|
72
|
+
name: resolver.resolveName(node.operationId),
|
|
73
|
+
tsResolver,
|
|
74
|
+
zodResolver,
|
|
75
|
+
typeFile,
|
|
76
|
+
zodFile,
|
|
58
77
|
}
|
|
59
78
|
}
|
|
60
79
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
const operationData = buildOperationData(operation)
|
|
77
|
-
const previousFile = acc.find((item) => item.file.path === file.path)
|
|
78
|
-
|
|
79
|
-
if (previousFile) {
|
|
80
|
-
previousFile.operations.push(operationData)
|
|
81
|
-
} else {
|
|
82
|
-
acc.push({ name, file, operations: [operationData] })
|
|
83
|
-
}
|
|
84
|
-
} else if (group?.tag) {
|
|
85
|
-
// Group by tag
|
|
86
|
-
const name = groupName
|
|
87
|
-
const file = driver.getFile({
|
|
88
|
-
name,
|
|
89
|
-
extname: '.ts',
|
|
90
|
-
pluginName,
|
|
91
|
-
options: { group },
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
const operationData = buildOperationData(operation)
|
|
95
|
-
const previousFile = acc.find((item) => item.file.path === file.path)
|
|
96
|
-
|
|
97
|
-
if (previousFile) {
|
|
98
|
-
previousFile.operations.push(operationData)
|
|
99
|
-
} else {
|
|
100
|
-
acc.push({ name, file, operations: [operationData] })
|
|
101
|
-
}
|
|
80
|
+
const controllers = nodes.reduce((acc, operationNode) => {
|
|
81
|
+
const tag = operationNode.tags[0]
|
|
82
|
+
const groupName = tag ? (group?.name?.({ group: camelCase(tag) }) ?? resolver.resolveGroupName(tag)) : resolver.resolveGroupName('Client')
|
|
83
|
+
|
|
84
|
+
if (!tag && !group) {
|
|
85
|
+
const name = resolver.resolveClassName('ApiClient')
|
|
86
|
+
const file = resolver.resolveFile({ name, extname: '.ts' }, { root, output, group })
|
|
87
|
+
const operationData = buildOperationData(operationNode)
|
|
88
|
+
const previous = acc.find((item) => item.file.path === file.path)
|
|
89
|
+
|
|
90
|
+
if (previous) {
|
|
91
|
+
previous.operations.push(operationData)
|
|
92
|
+
} else {
|
|
93
|
+
acc.push({ name, file, operations: [operationData] })
|
|
102
94
|
}
|
|
95
|
+
} else if (tag) {
|
|
96
|
+
const name = groupName
|
|
97
|
+
const file = resolver.resolveFile({ name, extname: '.ts', tag }, { root, output, group })
|
|
98
|
+
const operationData = buildOperationData(operationNode)
|
|
99
|
+
const previous = acc.find((item) => item.file.path === file.path)
|
|
100
|
+
|
|
101
|
+
if (previous) {
|
|
102
|
+
previous.operations.push(operationData)
|
|
103
|
+
} else {
|
|
104
|
+
acc.push({ name, file, operations: [operationData] })
|
|
105
|
+
}
|
|
106
|
+
}
|
|
103
107
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
[] as Array<Controller>,
|
|
107
|
-
)
|
|
108
|
+
return acc
|
|
109
|
+
}, [] as Array<Controller>)
|
|
108
110
|
|
|
109
111
|
function collectTypeImports(ops: Array<OperationData>) {
|
|
110
112
|
const typeImportsByFile = new Map<string, Set<string>>()
|
|
111
|
-
const typeFilesByPath = new Map<string,
|
|
113
|
+
const typeFilesByPath = new Map<string, ast.FileNode>()
|
|
112
114
|
|
|
113
115
|
ops.forEach((op) => {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
typeImportsByFile.set(typeFile.path, new Set())
|
|
116
|
+
const names = resolveTypeImportNames(op.node, tsResolver)
|
|
117
|
+
if (!typeImportsByFile.has(op.typeFile.path)) {
|
|
118
|
+
typeImportsByFile.set(op.typeFile.path, new Set())
|
|
118
119
|
}
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (typeSchemas.response?.name) typeImports.add(typeSchemas.response.name)
|
|
123
|
-
if (typeSchemas.pathParams?.name) typeImports.add(typeSchemas.pathParams.name)
|
|
124
|
-
if (typeSchemas.queryParams?.name) typeImports.add(typeSchemas.queryParams.name)
|
|
125
|
-
if (typeSchemas.headerParams?.name) typeImports.add(typeSchemas.headerParams.name)
|
|
126
|
-
typeSchemas.statusCodes?.forEach((item) => {
|
|
127
|
-
if (item?.name) typeImports.add(item.name)
|
|
120
|
+
const imports = typeImportsByFile.get(op.typeFile.path)!
|
|
121
|
+
names.forEach((n) => {
|
|
122
|
+
imports.add(n)
|
|
128
123
|
})
|
|
129
|
-
typeFilesByPath.set(typeFile.path, typeFile)
|
|
124
|
+
typeFilesByPath.set(op.typeFile.path, op.typeFile)
|
|
130
125
|
})
|
|
131
126
|
|
|
132
127
|
return { typeImportsByFile, typeFilesByPath }
|
|
@@ -134,100 +129,93 @@ export const staticClassClientGenerator = createReactGenerator<PluginClient>({
|
|
|
134
129
|
|
|
135
130
|
function collectZodImports(ops: Array<OperationData>) {
|
|
136
131
|
const zodImportsByFile = new Map<string, Set<string>>()
|
|
137
|
-
const zodFilesByPath = new Map<string,
|
|
132
|
+
const zodFilesByPath = new Map<string, ast.FileNode>()
|
|
138
133
|
|
|
139
134
|
ops.forEach((op) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (!zodImportsByFile.has(zodFile.path)) {
|
|
143
|
-
zodImportsByFile.set(zodFile.path, new Set())
|
|
135
|
+
if (!op.zodFile || !zodResolver) return
|
|
136
|
+
const names = resolveZodImportNames(op.node, zodResolver)
|
|
137
|
+
if (!zodImportsByFile.has(op.zodFile.path)) {
|
|
138
|
+
zodImportsByFile.set(op.zodFile.path, new Set())
|
|
144
139
|
}
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
zodFilesByPath.set(zodFile.path, zodFile)
|
|
140
|
+
const imports = zodImportsByFile.get(op.zodFile.path)!
|
|
141
|
+
names.forEach((n) => {
|
|
142
|
+
imports.add(n)
|
|
143
|
+
})
|
|
144
|
+
zodFilesByPath.set(op.zodFile.path, op.zodFile)
|
|
150
145
|
})
|
|
151
146
|
|
|
152
147
|
return { zodImportsByFile, zodFilesByPath }
|
|
153
148
|
}
|
|
154
149
|
|
|
155
|
-
return
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
150
|
+
return (
|
|
151
|
+
<>
|
|
152
|
+
{controllers.map(({ name, file, operations: ops }) => {
|
|
153
|
+
const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops)
|
|
154
|
+
const { zodImportsByFile, zodFilesByPath } =
|
|
155
|
+
parser === 'zod' ? collectZodImports(ops) : { zodImportsByFile: new Map<string, Set<string>>(), zodFilesByPath: new Map<string, ast.FileNode>() }
|
|
156
|
+
const hasFormData = ops.some((op) => op.node.requestBody?.content?.some((e) => e.contentType === 'multipart/form-data') ?? false)
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<File
|
|
160
|
+
key={file.path}
|
|
161
|
+
baseName={file.baseName}
|
|
162
|
+
path={file.path}
|
|
163
|
+
meta={file.meta}
|
|
164
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
165
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
166
|
+
>
|
|
167
|
+
{importPath ? (
|
|
168
|
+
<>
|
|
169
|
+
<File.Import name={'fetch'} path={importPath} />
|
|
170
|
+
<File.Import name={['mergeConfig']} path={importPath} />
|
|
171
|
+
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={importPath} isTypeOnly />
|
|
172
|
+
</>
|
|
173
|
+
) : (
|
|
174
|
+
<>
|
|
175
|
+
<File.Import name={['fetch']} root={file.path} path={path.resolve(root, '.kubb/client.ts')} />
|
|
176
|
+
<File.Import name={['mergeConfig']} root={file.path} path={path.resolve(root, '.kubb/client.ts')} />
|
|
177
|
+
<File.Import
|
|
178
|
+
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
179
|
+
root={file.path}
|
|
180
|
+
path={path.resolve(root, '.kubb/client.ts')}
|
|
181
|
+
isTypeOnly
|
|
182
|
+
/>
|
|
183
|
+
</>
|
|
184
|
+
)}
|
|
185
|
+
|
|
186
|
+
{hasFormData && <File.Import name={['buildFormData']} root={file.path} path={path.resolve(root, '.kubb/config.ts')} />}
|
|
187
|
+
|
|
188
|
+
{Array.from(typeImportsByFile.entries()).map(([filePath, importSet]) => {
|
|
189
|
+
const typeFile = typeFilesByPath.get(filePath)
|
|
190
|
+
if (!typeFile) return null
|
|
191
|
+
const importNames = Array.from(importSet).filter(Boolean)
|
|
192
|
+
if (importNames.length === 0) return null
|
|
193
|
+
return <File.Import key={filePath} name={importNames} root={file.path} path={typeFile.path} isTypeOnly />
|
|
194
|
+
})}
|
|
195
|
+
|
|
196
|
+
{parser === 'zod' &&
|
|
197
|
+
Array.from(zodImportsByFile.entries()).map(([filePath, importSet]) => {
|
|
198
|
+
const zodFile = zodFilesByPath.get(filePath)
|
|
199
|
+
if (!zodFile) return null
|
|
200
|
+
const importNames = Array.from(importSet).filter(Boolean)
|
|
201
|
+
if (importNames.length === 0) return null
|
|
202
|
+
return <File.Import key={filePath} name={importNames} root={file.path} path={zodFile.path} />
|
|
203
|
+
})}
|
|
204
|
+
|
|
205
|
+
<StaticClassClient
|
|
206
|
+
name={name}
|
|
207
|
+
operations={ops}
|
|
208
|
+
baseURL={baseURL}
|
|
209
|
+
dataReturnType={dataReturnType}
|
|
210
|
+
pathParamsType={pathParamsType}
|
|
211
|
+
paramsCasing={paramsCasing}
|
|
212
|
+
paramsType={paramsType}
|
|
213
|
+
parser={parser}
|
|
187
214
|
/>
|
|
188
|
-
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
{Array.from(typeImportsByFile.entries()).map(([filePath, imports]) => {
|
|
194
|
-
const typeFile = typeFilesByPath.get(filePath)
|
|
195
|
-
if (!typeFile) {
|
|
196
|
-
return null
|
|
197
|
-
}
|
|
198
|
-
const importNames = Array.from(imports).filter(Boolean)
|
|
199
|
-
if (importNames.length === 0) {
|
|
200
|
-
return null
|
|
201
|
-
}
|
|
202
|
-
return <File.Import key={filePath} name={importNames} root={file.path} path={typeFile.path} isTypeOnly />
|
|
203
|
-
})}
|
|
204
|
-
|
|
205
|
-
{options.parser === 'zod' &&
|
|
206
|
-
Array.from(zodImportsByFile.entries()).map(([filePath, imports]) => {
|
|
207
|
-
const zodFile = zodFilesByPath.get(filePath)
|
|
208
|
-
if (!zodFile) {
|
|
209
|
-
return null
|
|
210
|
-
}
|
|
211
|
-
const importNames = Array.from(imports).filter(Boolean)
|
|
212
|
-
if (importNames.length === 0) {
|
|
213
|
-
return null
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return <File.Import key={filePath} name={importNames} root={file.path} path={zodFile.path} />
|
|
217
|
-
})}
|
|
218
|
-
|
|
219
|
-
<StaticClassClient
|
|
220
|
-
name={name}
|
|
221
|
-
operations={ops}
|
|
222
|
-
baseURL={options.baseURL}
|
|
223
|
-
dataReturnType={options.dataReturnType}
|
|
224
|
-
pathParamsType={options.pathParamsType}
|
|
225
|
-
paramsCasing={options.paramsCasing}
|
|
226
|
-
paramsType={options.paramsType}
|
|
227
|
-
parser={options.parser}
|
|
228
|
-
/>
|
|
229
|
-
</File>
|
|
230
|
-
)
|
|
231
|
-
})
|
|
215
|
+
</File>
|
|
216
|
+
)
|
|
217
|
+
})}
|
|
218
|
+
</>
|
|
219
|
+
)
|
|
232
220
|
},
|
|
233
221
|
})
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
1
|
+
export { Client } from './components/Client.tsx'
|
|
2
|
+
export { classClientGenerator } from './generators/classClientGenerator.tsx'
|
|
3
|
+
export { clientGenerator } from './generators/clientGenerator.tsx'
|
|
4
|
+
export { groupedClientGenerator } from './generators/groupedClientGenerator.tsx'
|
|
5
|
+
export { operationsGenerator } from './generators/operationsGenerator.tsx'
|
|
6
|
+
export { staticClassClientGenerator } from './generators/staticClassClientGenerator.tsx'
|
|
7
|
+
export { default, pluginClient, pluginClientName } from './plugin.ts'
|
|
8
|
+
export { resolverClient } from './resolvers/resolverClient.ts'
|
|
9
|
+
export type { ClientImportPath, PluginClient, ResolverClient } from './types.ts'
|