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