@kubb/plugin-client 4.8.0 → 4.9.0

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.
Files changed (40) hide show
  1. package/dist/{Operations-BCvft948.js → Operations-B6I1tCOx.js} +118 -5
  2. package/dist/Operations-B6I1tCOx.js.map +1 -0
  3. package/dist/{Operations-CP_QErFp.cjs → Operations-BVIrtQ0H.cjs} +122 -3
  4. package/dist/Operations-BVIrtQ0H.cjs.map +1 -0
  5. package/dist/components.cjs +2 -1
  6. package/dist/components.d.cts +53 -2
  7. package/dist/components.d.ts +53 -2
  8. package/dist/components.js +2 -2
  9. package/dist/generators-CsFgdAtO.js +424 -0
  10. package/dist/generators-CsFgdAtO.js.map +1 -0
  11. package/dist/{generators-9lVWKcq3.cjs → generators-dDr1GP7q.cjs} +198 -2
  12. package/dist/generators-dDr1GP7q.cjs.map +1 -0
  13. package/dist/generators.cjs +3 -2
  14. package/dist/generators.d.cts +5 -2
  15. package/dist/generators.d.ts +5 -2
  16. package/dist/generators.js +3 -3
  17. package/dist/index.cjs +11 -7
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +11 -7
  22. package/dist/index.js.map +1 -1
  23. package/dist/{types-CRHoY-hv.d.ts → types-DDd1VM_Z.d.ts} +9 -1
  24. package/dist/{types-DxXfO6iR.d.cts → types-MSth0FPg.d.cts} +9 -1
  25. package/package.json +6 -6
  26. package/src/components/ClassClient.tsx +235 -0
  27. package/src/components/Client.tsx +3 -2
  28. package/src/components/index.ts +1 -0
  29. package/src/generators/__snapshots__/Pet.ts +186 -0
  30. package/src/generators/__snapshots__/Store.ts +109 -0
  31. package/src/generators/__snapshots__/User.ts +147 -0
  32. package/src/generators/classClientGenerator.tsx +231 -0
  33. package/src/generators/index.ts +1 -0
  34. package/src/plugin.ts +10 -2
  35. package/src/types.ts +8 -0
  36. package/dist/Operations-BCvft948.js.map +0 -1
  37. package/dist/Operations-CP_QErFp.cjs.map +0 -1
  38. package/dist/generators-9lVWKcq3.cjs.map +0 -1
  39. package/dist/generators-BQlm15sh.js +0 -234
  40. package/dist/generators-BQlm15sh.js.map +0 -1
@@ -0,0 +1,231 @@
1
+ import path from 'node:path'
2
+ import { usePluginManager } from '@kubb/core/hooks'
3
+ import { camelCase, pascalCase } from '@kubb/core/transformers'
4
+ import type { KubbFile } from '@kubb/fabric-core/types'
5
+ import type { Operation } from '@kubb/oas'
6
+ import { createReactGenerator } from '@kubb/plugin-oas/generators'
7
+ import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
8
+ import type { OperationSchemas } from '@kubb/plugin-oas'
9
+ import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
10
+ import { pluginTsName } from '@kubb/plugin-ts'
11
+ import { pluginZodName } from '@kubb/plugin-zod'
12
+ import { File } from '@kubb/react-fabric'
13
+ import { ClassClient } from '../components/ClassClient'
14
+ import type { PluginClient } from '../types'
15
+
16
+ type OperationData = {
17
+ operation: Operation
18
+ name: string
19
+ typeSchemas: OperationSchemas
20
+ zodSchemas: OperationSchemas | undefined
21
+ typeFile: KubbFile.File
22
+ zodFile: KubbFile.File
23
+ }
24
+
25
+ type Controller = {
26
+ name: string
27
+ file: KubbFile.File
28
+ operations: Array<OperationData>
29
+ }
30
+
31
+ export const classClientGenerator = createReactGenerator<PluginClient>({
32
+ name: 'classClient',
33
+ Operations({ operations, generator, plugin, config }) {
34
+ const { options, key: pluginKey } = plugin
35
+ const pluginManager = usePluginManager()
36
+
37
+ const oas = useOas()
38
+ const { getName, getFile, getGroup, getSchemas } = useOperationManager(generator)
39
+
40
+ function buildOperationData(operation: Operation): OperationData {
41
+ const type = {
42
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
43
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
44
+ }
45
+
46
+ const zod = {
47
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
48
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
49
+ }
50
+
51
+ return {
52
+ operation,
53
+ name: getName(operation, { type: 'function' }),
54
+ typeSchemas: type.schemas,
55
+ zodSchemas: zod.schemas,
56
+ typeFile: type.file,
57
+ zodFile: zod.file,
58
+ }
59
+ }
60
+
61
+ // Group operations by tag
62
+ const controllers = operations.reduce(
63
+ (acc, operation) => {
64
+ const group = getGroup(operation)
65
+ const groupName = group?.tag ? (options.group?.name?.({ group: camelCase(group.tag) }) ?? pascalCase(group.tag)) : 'Client'
66
+
67
+ if (!group?.tag && !options.group) {
68
+ // If no grouping, put all operations in a single class
69
+ const name = 'ApiClient'
70
+ const file = pluginManager.getFile({
71
+ name,
72
+ extname: '.ts',
73
+ pluginKey,
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 = pluginManager.getFile({
88
+ name,
89
+ extname: '.ts',
90
+ pluginKey,
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
+ }
102
+ }
103
+
104
+ return acc
105
+ },
106
+ [] as Array<Controller>,
107
+ )
108
+
109
+ function collectTypeImports(ops: Array<OperationData>) {
110
+ const typeImportsByFile = new Map<string, Set<string>>()
111
+ const typeFilesByPath = new Map<string, KubbFile.File>()
112
+
113
+ ops.forEach((op) => {
114
+ const { typeSchemas, typeFile } = op
115
+
116
+ if (!typeImportsByFile.has(typeFile.path)) {
117
+ typeImportsByFile.set(typeFile.path, new Set())
118
+ }
119
+ const typeImports = typeImportsByFile.get(typeFile.path)!
120
+
121
+ if (typeSchemas.request?.name) typeImports.add(typeSchemas.request.name)
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)
128
+ })
129
+ typeFilesByPath.set(typeFile.path, typeFile)
130
+ })
131
+
132
+ return { typeImportsByFile, typeFilesByPath }
133
+ }
134
+
135
+ function collectZodImports(ops: Array<OperationData>) {
136
+ const zodImportsByFile = new Map<string, Set<string>>()
137
+ const zodFilesByPath = new Map<string, KubbFile.File>()
138
+
139
+ ops.forEach((op) => {
140
+ const { zodSchemas, zodFile } = op
141
+
142
+ if (!zodImportsByFile.has(zodFile.path)) {
143
+ zodImportsByFile.set(zodFile.path, new Set())
144
+ }
145
+ const zodImports = zodImportsByFile.get(zodFile.path)!
146
+
147
+ if (zodSchemas?.response?.name) zodImports.add(zodSchemas.response.name)
148
+ if (zodSchemas?.request?.name) zodImports.add(zodSchemas.request.name)
149
+ zodFilesByPath.set(zodFile.path, zodFile)
150
+ })
151
+
152
+ return { zodImportsByFile, zodFilesByPath }
153
+ }
154
+
155
+ return controllers.map(({ name, file, operations: ops }) => {
156
+ const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops)
157
+ const { zodImportsByFile, zodFilesByPath } =
158
+ options.parser === 'zod'
159
+ ? collectZodImports(ops)
160
+ : { zodImportsByFile: new Map<string, Set<string>>(), zodFilesByPath: new Map<string, KubbFile.File>() }
161
+ const hasFormData = ops.some((op) => op.operation.getContentType() === 'multipart/form-data')
162
+
163
+ return (
164
+ <File
165
+ key={file.path}
166
+ baseName={file.baseName}
167
+ path={file.path}
168
+ meta={file.meta}
169
+ banner={getBanner({ oas, output: options.output, config: pluginManager.config })}
170
+ footer={getFooter({ oas, output: options.output })}
171
+ >
172
+ {options.importPath ? (
173
+ <>
174
+ <File.Import name={'fetch'} path={options.importPath} />
175
+ <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.importPath} isTypeOnly />
176
+ </>
177
+ ) : (
178
+ <>
179
+ <File.Import name={['fetch']} root={file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />
180
+ <File.Import
181
+ name={['RequestConfig', 'ResponseErrorConfig']}
182
+ root={file.path}
183
+ path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}
184
+ isTypeOnly
185
+ />
186
+ </>
187
+ )}
188
+
189
+ {hasFormData && <File.Import name={['buildFormData']} root={file.path} path={path.resolve(config.root, config.output.path, '.kubb/config.ts')} />}
190
+
191
+ {Array.from(typeImportsByFile.entries()).map(([filePath, imports]) => {
192
+ const typeFile = typeFilesByPath.get(filePath)
193
+ if (!typeFile) {
194
+ return null
195
+ }
196
+ const importNames = Array.from(imports).filter(Boolean)
197
+ if (importNames.length === 0) {
198
+ return null
199
+ }
200
+ return <File.Import key={filePath} name={importNames} root={file.path} path={typeFile.path} isTypeOnly />
201
+ })}
202
+
203
+ {options.parser === 'zod' &&
204
+ Array.from(zodImportsByFile.entries()).map(([filePath, imports]) => {
205
+ const zodFile = zodFilesByPath.get(filePath)
206
+ if (!zodFile) {
207
+ return null
208
+ }
209
+ const importNames = Array.from(imports).filter(Boolean)
210
+ if (importNames.length === 0) {
211
+ return null
212
+ }
213
+
214
+ return <File.Import key={filePath} name={importNames} root={file.path} path={zodFile.path} />
215
+ })}
216
+
217
+ <ClassClient
218
+ name={name}
219
+ operations={ops}
220
+ baseURL={options.baseURL}
221
+ dataReturnType={options.dataReturnType}
222
+ pathParamsType={options.pathParamsType}
223
+ paramsCasing={options.paramsCasing}
224
+ paramsType={options.paramsType}
225
+ parser={options.parser}
226
+ />
227
+ </File>
228
+ )
229
+ })
230
+ },
231
+ })
@@ -1,3 +1,4 @@
1
+ export { classClientGenerator } from './classClientGenerator.tsx'
1
2
  export { clientGenerator } from './clientGenerator.tsx'
2
3
  export { groupedClientGenerator } from './groupedClientGenerator.tsx'
3
4
  export { operationsGenerator } from './operationsGenerator.tsx'
package/src/plugin.ts CHANGED
@@ -4,7 +4,7 @@ import { camelCase } from '@kubb/core/transformers'
4
4
  import { resolveModuleSource } from '@kubb/core/utils'
5
5
  import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
6
6
  import { pluginZodName } from '@kubb/plugin-zod'
7
- import { operationsGenerator } from './generators'
7
+ import { classClientGenerator, operationsGenerator } from './generators'
8
8
  import { clientGenerator } from './generators/clientGenerator.tsx'
9
9
  import { groupedClientGenerator } from './generators/groupedClientGenerator.tsx'
10
10
  import type { PluginClient } from './types.ts'
@@ -26,7 +26,7 @@ export const pluginClient = definePlugin<PluginClient>((options) => {
26
26
  operations = false,
27
27
  baseURL,
28
28
  paramsCasing,
29
- generators = [clientGenerator, group ? groupedClientGenerator : undefined, operations ? operationsGenerator : undefined].filter(Boolean),
29
+ clientType = 'function',
30
30
  parser = 'client',
31
31
  client = 'axios',
32
32
  importPath,
@@ -35,11 +35,19 @@ export const pluginClient = definePlugin<PluginClient>((options) => {
35
35
  } = options
36
36
 
37
37
  const resolvedImportPath = importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : undefined)
38
+ const defaultGenerators = [
39
+ clientType === 'class' ? classClientGenerator : clientGenerator,
40
+ group && clientType !== 'class' ? groupedClientGenerator : undefined,
41
+ operations ? operationsGenerator : undefined,
42
+ ].filter(Boolean)
43
+
44
+ const generators = options.generators ?? defaultGenerators
38
45
 
39
46
  return {
40
47
  name: pluginClientName,
41
48
  options: {
42
49
  client,
50
+ clientType,
43
51
  bundle,
44
52
  output,
45
53
  group,
package/src/types.ts CHANGED
@@ -92,6 +92,13 @@ export type Options = {
92
92
  * @default 'axios'
93
93
  */
94
94
  client?: 'axios' | 'fetch'
95
+ /**
96
+ * How to generate the client code
97
+ * - 'function' will generate standalone functions for each operation.
98
+ * - 'class' will generate a class with methods for each operation.
99
+ * @default 'function'
100
+ */
101
+ clientType?: 'function' | 'class'
95
102
  /**
96
103
  * Bundle the selected client into the generated `.kubb` directory.
97
104
  * When disabled the generated clients will import the shared runtime from `@kubb/plugin-client/clients/*`.
@@ -116,6 +123,7 @@ type ResolvedOptions = {
116
123
  group?: Options['group']
117
124
  baseURL: string | undefined
118
125
  client: Options['client']
126
+ clientType: NonNullable<Options['clientType']>
119
127
  bundle: NonNullable<Options['bundle']>
120
128
  parser: NonNullable<Options['parser']>
121
129
  urlType: NonNullable<Options['urlType']>
@@ -1 +0,0 @@
1
- {"version":3,"file":"Operations-BCvft948.js","names":["getParams","operationsObject: Record<string, { path: string; method: HttpMethod }>"],"sources":["../src/components/Url.tsx","../src/components/Client.tsx","../src/components/Operations.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\n\nimport { isOptional, type Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getPathParams } from '@kubb/plugin-oas/utils'\nimport { Const, File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginClient } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n isExportable?: boolean\n isIndexable?: boolean\n\n baseURL: string | undefined\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['pathParamsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n operation: Operation\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['paramsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n },\n },\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\n })\n}\n\nexport function Url({\n name,\n isExportable = true,\n isIndexable = true,\n typeSchemas,\n baseURL,\n paramsType,\n paramsCasing,\n pathParamsType,\n operation,\n}: Props): KubbNode {\n const path = new URLPath(operation.path, { casing: paramsCasing })\n const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n <Function name={name} export={isExportable} params={params.toConstructor()}>\n <Const name={'res'}>{`{ method: '${operation.method.toUpperCase()}', url: ${path.toTemplateString({ prefix: baseURL })} as const }`}</Const>\n <br />\n return res\n </Function>\n </File.Source>\n )\n}\n\nUrl.getParams = getParams\n","import { URLPath } from '@kubb/core/utils'\n\nimport { isOptional, type Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments, getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginClient } from '../types.ts'\nimport { Url } from './Url.tsx'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n urlName?: string\n isExportable?: boolean\n isIndexable?: boolean\n isConfigurable?: boolean\n returnType?: string\n\n baseURL: string | undefined\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['pathParamsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n typeSchemas: OperationSchemas\n zodSchemas: OperationSchemas | undefined\n operation: Operation\n children?: KubbNode\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['paramsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n isConfigurable: boolean\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable }: GetParamsProps) {\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n },\n },\n config: isConfigurable\n ? {\n type: typeSchemas.request?.name\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n }\n : undefined,\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n config: isConfigurable\n ? {\n type: typeSchemas.request?.name\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n }\n : undefined,\n })\n}\n\nexport function Client({\n name,\n isExportable = true,\n isIndexable = true,\n returnType,\n typeSchemas,\n baseURL,\n dataReturnType,\n parser,\n zodSchemas,\n paramsType,\n paramsCasing,\n pathParamsType,\n operation,\n urlName,\n children,\n isConfigurable = true,\n}: Props): KubbNode {\n const path = new URLPath(operation.path, { casing: paramsCasing })\n const contentType = operation.getContentType()\n const isFormData = contentType === 'multipart/form-data'\n const headers = [\n contentType !== 'application/json' && contentType !== 'multipart/form-data' ? `'Content-Type': '${contentType}'` : undefined,\n typeSchemas.headerParams?.name ? '...headers' : undefined,\n ].filter(Boolean)\n\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n\n const generics = [typeSchemas.response.name, TError, typeSchemas.request?.name || 'unknown'].filter(Boolean)\n const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable })\n const urlParams = Url.getParams({\n paramsType,\n paramsCasing,\n pathParamsType,\n typeSchemas,\n })\n const clientParams = FunctionParams.factory({\n config: {\n mode: 'object',\n children: {\n method: {\n value: JSON.stringify(operation.method.toUpperCase()),\n },\n url: {\n value: urlName ? `${urlName}(${urlParams.toCall()}).url.toString()` : path.template,\n },\n baseURL:\n baseURL && !urlName\n ? {\n value: JSON.stringify(baseURL),\n }\n : undefined,\n params: typeSchemas.queryParams?.name ? {} : undefined,\n data: typeSchemas.request?.name\n ? {\n value: isFormData ? 'formData as FormData' : 'requestData',\n }\n : undefined,\n requestConfig: isConfigurable\n ? {\n mode: 'inlineSpread',\n }\n : undefined,\n headers: headers.length\n ? {\n value: isConfigurable ? `{ ${headers.join(', ')}, ...requestConfig.headers }` : `{ ${headers.join(', ')} }`,\n }\n : undefined,\n },\n },\n })\n\n const childrenElement = children ? (\n children\n ) : (\n <>\n {dataReturnType === 'full' && parser === 'zod' && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`}\n {dataReturnType === 'data' && parser === 'zod' && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`}\n {dataReturnType === 'full' && parser === 'client' && 'return res'}\n {dataReturnType === 'data' && parser === 'client' && 'return res.data'}\n </>\n )\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n <Function\n name={name}\n async\n export={isExportable}\n params={params.toConstructor()}\n JSDoc={{\n comments: getComments(operation),\n }}\n returnType={returnType}\n >\n {isConfigurable ? 'const { client: request = fetch, ...requestConfig } = config' : ''}\n <br />\n <br />\n {parser === 'zod' && zodSchemas?.request?.name && `const requestData = ${zodSchemas.request.name}.parse(data)`}\n {parser === 'client' && typeSchemas?.request?.name && 'const requestData = data'}\n <br />\n {isFormData && typeSchemas?.request?.name && 'const formData = buildFormData(requestData)'}\n <br />\n {isConfigurable\n ? `const res = await request<${generics.join(', ')}>(${clientParams.toCall()})`\n : `const res = await fetch<${generics.join(', ')}>(${clientParams.toCall()})`}\n <br />\n {childrenElement}\n </Function>\n </File.Source>\n )\n}\n\nClient.getParams = getParams\n","import { URLPath } from '@kubb/core/utils'\nimport type { HttpMethod, Operation } from '@kubb/oas'\nimport { Const, File } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\n\ntype OperationsProps = {\n name: string\n operations: Array<Operation>\n}\n\nexport function Operations({ name, operations }: OperationsProps): KubbNode {\n const operationsObject: Record<string, { path: string; method: HttpMethod }> = {}\n\n operations.forEach((operation) => {\n operationsObject[operation.getOperationId()] = {\n path: new URLPath(operation.path).URL,\n method: operation.method,\n }\n })\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Const name={name} export>\n {JSON.stringify(operationsObject, undefined, 2)}\n </Const>\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;AAgCA,SAASA,YAAU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YAAY;KACpD;AAGL,QACE,oBAAC,KAAK;EAAa;EAAoB;EAA2B;YAChE,qBAAC;GACO;GACN;GACA,QAAQ;GACR,QAAQ,OAAO,eAAe;GAC9B,OAAO,EACL,UAAU,YAAY,UAAU,EACjC;GACW;;IAEX,iBAAiB,iEAAiE;IACnF,oBAAC,SAAK;IACN,oBAAC,SAAK;IACL,WAAW,SAAS,YAAY,SAAS,QAAQ,uBAAuB,WAAW,QAAQ,KAAK;IAChG,WAAW,YAAY,aAAa,SAAS,QAAQ;IACtD,oBAAC,SAAK;IACL,cAAc,aAAa,SAAS,QAAQ;IAC7C,oBAAC,SAAK;IACL,iBACG,6BAA6B,SAAS,KAAK,KAAK,CAAC,IAAI,aAAa,QAAQ,CAAC,KAC3E,2BAA2B,SAAS,KAAK,KAAK,CAAC,IAAI,aAAa,QAAQ,CAAC;IAC7E,oBAAC,SAAK;IACL;;IACQ;GACC;;AAIlB,OAAO,YAAY;;;;AC3NnB,SAAgB,WAAW,EAAE,MAAM,cAAyC;CAC1E,MAAMC,mBAAyE,EAAE;AAEjF,YAAW,SAAS,cAAc;AAChC,mBAAiB,UAAU,gBAAgB,IAAI;GAC7C,MAAM,IAAI,QAAQ,UAAU,KAAK,CAAC;GAClC,QAAQ,UAAU;GACnB;GACD;AAEF,QACE,oBAAC,KAAK;EAAa;EAAM;EAAa;YACpC,oBAAC;GAAY;GAAM;aAChB,KAAK,UAAU,kBAAkB,QAAW,EAAE;IACzC;GACI"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Operations-CP_QErFp.cjs","names":["getParams","FunctionParams","URLPath","File","Function","Const","FunctionParams","URLPath","File","Function","operationsObject: Record<string, { path: string; method: HttpMethod }>","URLPath","File","Const"],"sources":["../src/components/Url.tsx","../src/components/Client.tsx","../src/components/Operations.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\n\nimport { isOptional, type Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getPathParams } from '@kubb/plugin-oas/utils'\nimport { Const, File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginClient } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n isExportable?: boolean\n isIndexable?: boolean\n\n baseURL: string | undefined\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['pathParamsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n operation: Operation\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['paramsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n },\n },\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\n })\n}\n\nexport function Url({\n name,\n isExportable = true,\n isIndexable = true,\n typeSchemas,\n baseURL,\n paramsType,\n paramsCasing,\n pathParamsType,\n operation,\n}: Props): KubbNode {\n const path = new URLPath(operation.path, { casing: paramsCasing })\n const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n <Function name={name} export={isExportable} params={params.toConstructor()}>\n <Const name={'res'}>{`{ method: '${operation.method.toUpperCase()}', url: ${path.toTemplateString({ prefix: baseURL })} as const }`}</Const>\n <br />\n return res\n </Function>\n </File.Source>\n )\n}\n\nUrl.getParams = getParams\n","import { URLPath } from '@kubb/core/utils'\n\nimport { isOptional, type Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments, getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginClient } from '../types.ts'\nimport { Url } from './Url.tsx'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n urlName?: string\n isExportable?: boolean\n isIndexable?: boolean\n isConfigurable?: boolean\n returnType?: string\n\n baseURL: string | undefined\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['pathParamsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n typeSchemas: OperationSchemas\n zodSchemas: OperationSchemas | undefined\n operation: Operation\n children?: KubbNode\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['paramsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n isConfigurable: boolean\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable }: GetParamsProps) {\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n },\n },\n config: isConfigurable\n ? {\n type: typeSchemas.request?.name\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n }\n : undefined,\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n config: isConfigurable\n ? {\n type: typeSchemas.request?.name\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n }\n : undefined,\n })\n}\n\nexport function Client({\n name,\n isExportable = true,\n isIndexable = true,\n returnType,\n typeSchemas,\n baseURL,\n dataReturnType,\n parser,\n zodSchemas,\n paramsType,\n paramsCasing,\n pathParamsType,\n operation,\n urlName,\n children,\n isConfigurable = true,\n}: Props): KubbNode {\n const path = new URLPath(operation.path, { casing: paramsCasing })\n const contentType = operation.getContentType()\n const isFormData = contentType === 'multipart/form-data'\n const headers = [\n contentType !== 'application/json' && contentType !== 'multipart/form-data' ? `'Content-Type': '${contentType}'` : undefined,\n typeSchemas.headerParams?.name ? '...headers' : undefined,\n ].filter(Boolean)\n\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n\n const generics = [typeSchemas.response.name, TError, typeSchemas.request?.name || 'unknown'].filter(Boolean)\n const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable })\n const urlParams = Url.getParams({\n paramsType,\n paramsCasing,\n pathParamsType,\n typeSchemas,\n })\n const clientParams = FunctionParams.factory({\n config: {\n mode: 'object',\n children: {\n method: {\n value: JSON.stringify(operation.method.toUpperCase()),\n },\n url: {\n value: urlName ? `${urlName}(${urlParams.toCall()}).url.toString()` : path.template,\n },\n baseURL:\n baseURL && !urlName\n ? {\n value: JSON.stringify(baseURL),\n }\n : undefined,\n params: typeSchemas.queryParams?.name ? {} : undefined,\n data: typeSchemas.request?.name\n ? {\n value: isFormData ? 'formData as FormData' : 'requestData',\n }\n : undefined,\n requestConfig: isConfigurable\n ? {\n mode: 'inlineSpread',\n }\n : undefined,\n headers: headers.length\n ? {\n value: isConfigurable ? `{ ${headers.join(', ')}, ...requestConfig.headers }` : `{ ${headers.join(', ')} }`,\n }\n : undefined,\n },\n },\n })\n\n const childrenElement = children ? (\n children\n ) : (\n <>\n {dataReturnType === 'full' && parser === 'zod' && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`}\n {dataReturnType === 'data' && parser === 'zod' && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`}\n {dataReturnType === 'full' && parser === 'client' && 'return res'}\n {dataReturnType === 'data' && parser === 'client' && 'return res.data'}\n </>\n )\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n <Function\n name={name}\n async\n export={isExportable}\n params={params.toConstructor()}\n JSDoc={{\n comments: getComments(operation),\n }}\n returnType={returnType}\n >\n {isConfigurable ? 'const { client: request = fetch, ...requestConfig } = config' : ''}\n <br />\n <br />\n {parser === 'zod' && zodSchemas?.request?.name && `const requestData = ${zodSchemas.request.name}.parse(data)`}\n {parser === 'client' && typeSchemas?.request?.name && 'const requestData = data'}\n <br />\n {isFormData && typeSchemas?.request?.name && 'const formData = buildFormData(requestData)'}\n <br />\n {isConfigurable\n ? `const res = await request<${generics.join(', ')}>(${clientParams.toCall()})`\n : `const res = await fetch<${generics.join(', ')}>(${clientParams.toCall()})`}\n <br />\n {childrenElement}\n </Function>\n </File.Source>\n )\n}\n\nClient.getParams = getParams\n","import { URLPath } from '@kubb/core/utils'\nimport type { HttpMethod, Operation } from '@kubb/oas'\nimport { Const, File } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\n\ntype OperationsProps = {\n name: string\n operations: Array<Operation>\n}\n\nexport function Operations({ name, operations }: OperationsProps): KubbNode {\n const operationsObject: Record<string, { path: string; method: HttpMethod }> = {}\n\n operations.forEach((operation) => {\n operationsObject[operation.getOperationId()] = {\n path: new URLPath(operation.path).URL,\n method: operation.method,\n }\n })\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Const name={name} export>\n {JSON.stringify(operationsObject, undefined, 2)}\n </Const>\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;;AAgCA,SAASA,YAAU,EAAE,YAAY,cAAc,gBAAgB,eAA+B;AAC5F,KAAI,eAAe,SACjB,QAAOC,mCAAe,QAAQ,EAC5B,MAAM;EACJ,MAAM;EACN,UAAU,EACR,8CAAiB,YAAY,YAAY;GAAE,OAAO;GAAM,QAAQ;GAAc,CAAC,EAChF;EACF,EACF,CAAC;AAGJ,QAAOA,mCAAe,QAAQ,EAC5B,YAAY,YAAY,YAAY,OAChC;EACE,MAAM,mBAAmB,WAAW,WAAW;EAC/C,qDAAwB,YAAY,YAAY;GAAE,OAAO;GAAM,QAAQ;GAAc,CAAC;EACtF,qCAAqB,YAAY,YAAY,OAAO;EACrD,GACD,QACL,CAAC;;AAGJ,SAAgB,IAAI,EAClB,MACA,eAAe,MACf,cAAc,MACd,aACA,SACA,YACA,cACA,gBACA,aACkB;CAClB,MAAM,OAAO,IAAIC,0BAAQ,UAAU,MAAM,EAAE,QAAQ,cAAc,CAAC;CAClE,MAAM,SAASF,YAAU;EAAE;EAAY;EAAc;EAAgB;EAAa,CAAC;AAEnF,QACE,y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,SAAS,cAAc;AAChC,mBAAiB,UAAU,gBAAgB,IAAI;GAC7C,MAAM,IAAIC,0BAAQ,UAAU,KAAK,CAAC;GAClC,QAAQ,UAAU;GACnB;GACD;AAEF,QACE,yDAACC,yBAAK;EAAa;EAAM;EAAa;YACpC,yDAACC;GAAY;GAAM;aAChB,KAAK,UAAU,kBAAkB,QAAW,EAAE;IACzC;GACI"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators-9lVWKcq3.cjs","names":["pluginTsName","pluginZodName","File","path","Url","Client","File","Function","File","Operations"],"sources":["../src/generators/clientGenerator.tsx","../src/generators/groupedClientGenerator.tsx","../src/generators/operationsGenerator.tsx"],"sourcesContent":["import path from 'node:path'\nimport { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File } from '@kubb/react-fabric'\nimport { Client } from '../components/Client'\nimport { Url } from '../components/Url.tsx'\nimport type { PluginClient } from '../types'\n\nexport const clientGenerator = createReactGenerator<PluginClient>({\n name: 'client',\n Operation({ config, plugin, operation, generator }) {\n const pluginManager = usePluginManager()\n const {\n options,\n options: { output, urlType },\n } = plugin\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const client = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const url = {\n name: getName(operation, { type: 'function', suffix: 'url', prefix: 'get' }),\n file: getFile(operation),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n const isFormData = operation.getContentType() === 'multipart/form-data'\n\n return (\n <File\n baseName={client.file.baseName}\n path={client.file.path}\n meta={client.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {options.importPath ? (\n <>\n <File.Import name={'fetch'} path={options.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.importPath} isTypeOnly />\n </>\n ) : (\n <>\n <File.Import name={['fetch']} root={client.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />\n <File.Import\n name={['RequestConfig', 'ResponseErrorConfig']}\n root={client.file.path}\n path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}\n isTypeOnly\n />\n </>\n )}\n\n {isFormData && type.schemas.request?.name && (\n <File.Import name={['buildFormData']} root={client.file.path} path={path.resolve(config.root, config.output.path, '.kubb/config.ts')} />\n )}\n\n {options.parser === 'zod' && (\n <File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={client.file.path} path={zod.file.path} />\n )}\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={client.file.path}\n path={type.file.path}\n isTypeOnly\n />\n\n <Url\n name={url.name}\n baseURL={options.baseURL}\n pathParamsType={options.pathParamsType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n typeSchemas={type.schemas}\n operation={operation}\n isIndexable={urlType === 'export'}\n isExportable={urlType === 'export'}\n />\n\n <Client\n name={client.name}\n urlName={url.name}\n baseURL={options.baseURL}\n dataReturnType={options.dataReturnType}\n pathParamsType={options.pathParamsType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n typeSchemas={type.schemas}\n operation={operation}\n parser={options.parser}\n zodSchemas={zod.schemas}\n />\n </File>\n )\n },\n})\n","import { usePluginManager } from '@kubb/core/hooks'\nimport { camelCase } from '@kubb/core/transformers'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, Function } from '@kubb/react-fabric'\nimport type { PluginClient } from '../types'\n\nexport const groupedClientGenerator = createReactGenerator<PluginClient>({\n name: 'groupedClient',\n Operations({ operations, generator, plugin }) {\n const { options, key: pluginKey } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getName, getFile, getGroup } = useOperationManager(generator)\n\n const controllers = operations.reduce(\n (acc, operation) => {\n if (options.group?.type === 'tag') {\n const group = getGroup(operation)\n const name = group?.tag ? options.group?.name?.({ group: camelCase(group.tag) }) : undefined\n\n if (!group?.tag || !name) {\n return acc\n }\n\n const file = pluginManager.getFile({\n name,\n extname: '.ts',\n pluginKey,\n options: { group },\n })\n\n const client = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const previousFile = acc.find((item) => item.file.path === file.path)\n\n if (previousFile) {\n previousFile.clients.push(client)\n } else {\n acc.push({ name, file, clients: [client] })\n }\n }\n\n return acc\n },\n [] as Array<{ name: string; file: KubbFile.File; clients: Array<{ name: string; file: KubbFile.File }> }>,\n )\n\n return controllers.map(({ name, file, clients }) => {\n return (\n <File\n key={file.path}\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: options.output })}\n >\n {clients.map((client) => (\n <File.Import key={client.name} name={[client.name]} root={file.path} path={client.file.path} />\n ))}\n\n <File.Source name={name} isExportable isIndexable>\n <Function export name={name}>\n {`return { ${clients.map((client) => client.name).join(', ')} }`}\n </Function>\n </File.Source>\n </File>\n )\n })\n },\n})\n","import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Operations } from '../components/Operations'\nimport type { PluginClient } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginClient>({\n name: 'client',\n Operations({ operations, plugin }) {\n const {\n key: pluginKey,\n options: { output },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <Operations name={name} operations={operations} />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;AAYA,MAAa,yEAAqD;CAChE,MAAM;CACN,UAAU,EAAE,QAAQ,QAAQ,WAAW,aAAa;EAClD,MAAM,yDAAkC;EACxC,MAAM,EACJ,SACA,SAAS,EAAE,QAAQ,cACjB;EAEJ,MAAM,2CAAc;EACpB,MAAM,EAAE,YAAY,SAAS,6DAAgC,UAAU;EAEvE,MAAM,SAAS;GACb,MAAM,QAAQ,WAAW,EAAE,MAAM,YAAY,CAAC;GAC9C,MAAM,QAAQ,UAAU;GACzB;EAED,MAAM,MAAM;GACV,MAAM,QAAQ,WAAW;IAAE,MAAM;IAAY,QAAQ;IAAO,QAAQ;IAAO,CAAC;GAC5E,MAAM,QAAQ,UAAU;GACzB;EAED,MAAM,OAAO;GACX,MAAM,QAAQ,WAAW,EAAE,WAAW,CAACA,8BAAa,EAAE,CAAC;GACvD,SAAS,WAAW,WAAW;IAAE,WAAW,CAACA,8BAAa;IAAE,MAAM;IAAQ,CAAC;GAC5E;EAED,MAAM,MAAM;GACV,MAAM,QAAQ,WAAW,EAAE,WAAW,CAACC,gCAAc,EAAE,CAAC;GACxD,SAAS,WAAW,WAAW;IAAE,WAAW,CAACA,gCAAc;IAAE,MAAM;IAAY,CAAC;GACjF;EAED,MAAM,aAAa,UAA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from "node:path";
3
- import { camelCase } from "@kubb/core/transformers";
4
- import { pluginZodName } from "@kubb/plugin-zod";
5
- import { usePluginManager } from "@kubb/core/hooks";
6
- import { createReactGenerator } from "@kubb/plugin-oas/generators";
7
- import { useOas, useOperationManager } from "@kubb/plugin-oas/hooks";
8
- import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
9
- import { pluginTsName } from "@kubb/plugin-ts";
10
- import { File, Function } from "@kubb/react-fabric";
11
- import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
12
-
13
- //#region src/generators/clientGenerator.tsx
14
- const clientGenerator = createReactGenerator({
15
- name: "client",
16
- Operation({ config, plugin, operation, generator }) {
17
- const pluginManager = usePluginManager();
18
- const { options, options: { output, urlType } } = plugin;
19
- const oas = useOas();
20
- const { getSchemas, getName, getFile } = useOperationManager(generator);
21
- const client = {
22
- name: getName(operation, { type: "function" }),
23
- file: getFile(operation)
24
- };
25
- const url = {
26
- name: getName(operation, {
27
- type: "function",
28
- suffix: "url",
29
- prefix: "get"
30
- }),
31
- file: getFile(operation)
32
- };
33
- const type = {
34
- file: getFile(operation, { pluginKey: [pluginTsName] }),
35
- schemas: getSchemas(operation, {
36
- pluginKey: [pluginTsName],
37
- type: "type"
38
- })
39
- };
40
- const zod = {
41
- file: getFile(operation, { pluginKey: [pluginZodName] }),
42
- schemas: getSchemas(operation, {
43
- pluginKey: [pluginZodName],
44
- type: "function"
45
- })
46
- };
47
- const isFormData = operation.getContentType() === "multipart/form-data";
48
- return /* @__PURE__ */ jsxs(File, {
49
- baseName: client.file.baseName,
50
- path: client.file.path,
51
- meta: client.file.meta,
52
- banner: getBanner({
53
- oas,
54
- output,
55
- config: pluginManager.config
56
- }),
57
- footer: getFooter({
58
- oas,
59
- output
60
- }),
61
- children: [
62
- options.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
63
- name: "fetch",
64
- path: options.importPath
65
- }), /* @__PURE__ */ jsx(File.Import, {
66
- name: ["RequestConfig", "ResponseErrorConfig"],
67
- path: options.importPath,
68
- isTypeOnly: true
69
- })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
70
- name: ["fetch"],
71
- root: client.file.path,
72
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts")
73
- }), /* @__PURE__ */ jsx(File.Import, {
74
- name: ["RequestConfig", "ResponseErrorConfig"],
75
- root: client.file.path,
76
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
77
- isTypeOnly: true
78
- })] }),
79
- isFormData && type.schemas.request?.name && /* @__PURE__ */ jsx(File.Import, {
80
- name: ["buildFormData"],
81
- root: client.file.path,
82
- path: path.resolve(config.root, config.output.path, ".kubb/config.ts")
83
- }),
84
- options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, {
85
- name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
86
- root: client.file.path,
87
- path: zod.file.path
88
- }),
89
- /* @__PURE__ */ jsx(File.Import, {
90
- name: [
91
- type.schemas.request?.name,
92
- type.schemas.response.name,
93
- type.schemas.pathParams?.name,
94
- type.schemas.queryParams?.name,
95
- type.schemas.headerParams?.name,
96
- ...type.schemas.statusCodes?.map((item) => item.name) || []
97
- ].filter(Boolean),
98
- root: client.file.path,
99
- path: type.file.path,
100
- isTypeOnly: true
101
- }),
102
- /* @__PURE__ */ jsx(Url, {
103
- name: url.name,
104
- baseURL: options.baseURL,
105
- pathParamsType: options.pathParamsType,
106
- paramsCasing: options.paramsCasing,
107
- paramsType: options.paramsType,
108
- typeSchemas: type.schemas,
109
- operation,
110
- isIndexable: urlType === "export",
111
- isExportable: urlType === "export"
112
- }),
113
- /* @__PURE__ */ jsx(Client, {
114
- name: client.name,
115
- urlName: url.name,
116
- baseURL: options.baseURL,
117
- dataReturnType: options.dataReturnType,
118
- pathParamsType: options.pathParamsType,
119
- paramsCasing: options.paramsCasing,
120
- paramsType: options.paramsType,
121
- typeSchemas: type.schemas,
122
- operation,
123
- parser: options.parser,
124
- zodSchemas: zod.schemas
125
- })
126
- ]
127
- });
128
- }
129
- });
130
-
131
- //#endregion
132
- //#region src/generators/groupedClientGenerator.tsx
133
- const groupedClientGenerator = createReactGenerator({
134
- name: "groupedClient",
135
- Operations({ operations, generator, plugin }) {
136
- const { options, key: pluginKey } = plugin;
137
- const pluginManager = usePluginManager();
138
- const oas = useOas();
139
- const { getName, getFile, getGroup } = useOperationManager(generator);
140
- return operations.reduce((acc, operation) => {
141
- if (options.group?.type === "tag") {
142
- const group = getGroup(operation);
143
- const name = group?.tag ? options.group?.name?.({ group: camelCase(group.tag) }) : void 0;
144
- if (!group?.tag || !name) return acc;
145
- const file = pluginManager.getFile({
146
- name,
147
- extname: ".ts",
148
- pluginKey,
149
- options: { group }
150
- });
151
- const client = {
152
- name: getName(operation, { type: "function" }),
153
- file: getFile(operation)
154
- };
155
- const previousFile = acc.find((item) => item.file.path === file.path);
156
- if (previousFile) previousFile.clients.push(client);
157
- else acc.push({
158
- name,
159
- file,
160
- clients: [client]
161
- });
162
- }
163
- return acc;
164
- }, []).map(({ name, file, clients }) => {
165
- return /* @__PURE__ */ jsxs(File, {
166
- baseName: file.baseName,
167
- path: file.path,
168
- meta: file.meta,
169
- banner: getBanner({
170
- oas,
171
- output: options.output,
172
- config: pluginManager.config
173
- }),
174
- footer: getFooter({
175
- oas,
176
- output: options.output
177
- }),
178
- children: [clients.map((client) => /* @__PURE__ */ jsx(File.Import, {
179
- name: [client.name],
180
- root: file.path,
181
- path: client.file.path
182
- }, client.name)), /* @__PURE__ */ jsx(File.Source, {
183
- name,
184
- isExportable: true,
185
- isIndexable: true,
186
- children: /* @__PURE__ */ jsx(Function, {
187
- export: true,
188
- name,
189
- children: `return { ${clients.map((client) => client.name).join(", ")} }`
190
- })
191
- })]
192
- }, file.path);
193
- });
194
- }
195
- });
196
-
197
- //#endregion
198
- //#region src/generators/operationsGenerator.tsx
199
- const operationsGenerator = createReactGenerator({
200
- name: "client",
201
- Operations({ operations, plugin }) {
202
- const { key: pluginKey, options: { output } } = plugin;
203
- const pluginManager = usePluginManager();
204
- const oas = useOas();
205
- const name = "operations";
206
- const file = pluginManager.getFile({
207
- name,
208
- extname: ".ts",
209
- pluginKey
210
- });
211
- return /* @__PURE__ */ jsx(File, {
212
- baseName: file.baseName,
213
- path: file.path,
214
- meta: file.meta,
215
- banner: getBanner({
216
- oas,
217
- output,
218
- config: pluginManager.config
219
- }),
220
- footer: getFooter({
221
- oas,
222
- output
223
- }),
224
- children: /* @__PURE__ */ jsx(Operations, {
225
- name,
226
- operations
227
- })
228
- });
229
- }
230
- });
231
-
232
- //#endregion
233
- export { groupedClientGenerator as n, clientGenerator as r, operationsGenerator as t };
234
- //# sourceMappingURL=generators-BQlm15sh.js.map