@kubb/plugin-client 0.0.0-canary-20241104172400

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 (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/client.ts +65 -0
  4. package/dist/chunk-I2NEG5CE.js +222 -0
  5. package/dist/chunk-I2NEG5CE.js.map +1 -0
  6. package/dist/chunk-IIY26RTZ.cjs +232 -0
  7. package/dist/chunk-IIY26RTZ.cjs.map +1 -0
  8. package/dist/chunk-PHUXTZZT.js +159 -0
  9. package/dist/chunk-PHUXTZZT.js.map +1 -0
  10. package/dist/chunk-UBMTYBLG.cjs +162 -0
  11. package/dist/chunk-UBMTYBLG.cjs.map +1 -0
  12. package/dist/client.cjs +45 -0
  13. package/dist/client.cjs.map +1 -0
  14. package/dist/client.d.cts +35 -0
  15. package/dist/client.d.ts +35 -0
  16. package/dist/client.js +33 -0
  17. package/dist/client.js.map +1 -0
  18. package/dist/components.cjs +16 -0
  19. package/dist/components.cjs.map +1 -0
  20. package/dist/components.d.cts +40 -0
  21. package/dist/components.d.ts +40 -0
  22. package/dist/components.js +3 -0
  23. package/dist/components.js.map +1 -0
  24. package/dist/generators.cjs +21 -0
  25. package/dist/generators.cjs.map +1 -0
  26. package/dist/generators.d.cts +11 -0
  27. package/dist/generators.d.ts +11 -0
  28. package/dist/generators.js +4 -0
  29. package/dist/generators.js.map +1 -0
  30. package/dist/index.cjs +17 -0
  31. package/dist/index.cjs.map +1 -0
  32. package/dist/index.d.cts +8 -0
  33. package/dist/index.d.ts +8 -0
  34. package/dist/index.js +4 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/types-DXab6SYO.d.cts +92 -0
  37. package/dist/types-DXab6SYO.d.ts +92 -0
  38. package/package.json +117 -0
  39. package/src/components/Client.tsx +199 -0
  40. package/src/components/Operations.tsx +28 -0
  41. package/src/components/index.ts +2 -0
  42. package/src/generators/__snapshots__/deletePet.ts +13 -0
  43. package/src/generators/__snapshots__/deletePetObject.ts +13 -0
  44. package/src/generators/__snapshots__/findByTags.ts +13 -0
  45. package/src/generators/__snapshots__/findByTagsFull.ts +13 -0
  46. package/src/generators/__snapshots__/findByTagsObject.ts +15 -0
  47. package/src/generators/__snapshots__/findByTagsWithZod.ts +13 -0
  48. package/src/generators/__snapshots__/findByTagsWithZodFull.ts +13 -0
  49. package/src/generators/__snapshots__/importPath.ts +13 -0
  50. package/src/generators/__snapshots__/operations.ts +82 -0
  51. package/src/generators/__snapshots__/updatePetById.ts +12 -0
  52. package/src/generators/clientGenerator.tsx +67 -0
  53. package/src/generators/groupedClientGenerator.tsx +70 -0
  54. package/src/generators/index.ts +3 -0
  55. package/src/generators/operationsGenerator.tsx +26 -0
  56. package/src/index.ts +2 -0
  57. package/src/plugin.ts +122 -0
  58. package/src/types.ts +93 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Stijn Van Hulle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ <div align="center">
2
+
3
+ <!-- <img src="assets/logo.png" alt="logo" width="200" height="auto" /> -->
4
+ <h1>@kubb/plugin-client</h1>
5
+
6
+ <p>
7
+ Swagger integration for Axios to generate all the different clients based on an OpenAPI specification.
8
+ </p>
9
+ <img src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/banner.png" alt="logo" height="auto" />
10
+
11
+ [![npm version][npm-version-src]][npm-version-href]
12
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
13
+ [![Coverage][coverage-src]][coverage-href]
14
+ [![License][license-src]][license-href]
15
+
16
+ <h4>
17
+ <a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
18
+ <span> · </span>
19
+ <a href="https://kubb.dev/" target="_blank">Documentation</a>
20
+ <span> · </span>
21
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
22
+ <span> · </span>
23
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
24
+ </h4>
25
+ </div>
26
+
27
+ ## Supporting Kubb
28
+
29
+ Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
30
+
31
+ - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
32
+
33
+ <p align="center">
34
+ <a href="https://github.com/sponsors/stijnvanhulle">
35
+ <img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
36
+ </a>
37
+ </p>
38
+
39
+
40
+ <!-- Badges -->
41
+
42
+ [npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-client?flat&colorA=18181B&colorB=f58517
43
+ [npm-version-href]: https://npmjs.com/package/@kubb/plugin-client
44
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/plugin-client?flat&colorA=18181B&colorB=f58517
45
+ [npm-downloads-href]: https://npmjs.com/package/@kubb/plugin-client
46
+ [license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
47
+ [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
48
+ [build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
49
+ [build-href]: https://www.npmjs.com/package/@kubb/plugin-client
50
+ [minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-client?style=flat&colorA=18181B&colorB=f58517
51
+ [minified-href]: https://www.npmjs.com/package/@kubb/plugin-client
52
+ [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
53
+ [coverage-href]: https://www.npmjs.com/package/@kubb/plugin-client
package/client.ts ADDED
@@ -0,0 +1,65 @@
1
+ import axios from 'axios'
2
+
3
+ import type { AxiosError, AxiosHeaders, AxiosRequestConfig, AxiosResponse } from 'axios'
4
+
5
+ declare const AXIOS_BASE: string
6
+ declare const AXIOS_HEADERS: string
7
+
8
+ /**
9
+ * Subset of AxiosRequestConfig
10
+ */
11
+ export type RequestConfig<TData = unknown> = {
12
+ baseURL?: string
13
+ url?: string
14
+ method: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS'
15
+ params?: unknown
16
+ data?: TData | FormData
17
+ responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'
18
+ signal?: AbortSignal
19
+ headers?: AxiosRequestConfig['headers']
20
+ }
21
+ /**
22
+ * Subset of AxiosResponse
23
+ */
24
+ export type ResponseConfig<TData = unknown> = {
25
+ data: TData
26
+ status: number
27
+ statusText: string
28
+ headers?: AxiosResponse['headers']
29
+ }
30
+
31
+ let _config: Partial<RequestConfig> = {
32
+ baseURL: typeof AXIOS_BASE !== 'undefined' ? AXIOS_BASE : undefined,
33
+ headers: typeof AXIOS_HEADERS !== 'undefined' ? (JSON.parse(AXIOS_HEADERS) as AxiosHeaders) : undefined,
34
+ }
35
+
36
+ export const getConfig = () => _config
37
+
38
+ export const setConfig = (config: RequestConfig) => {
39
+ _config = config
40
+ return getConfig()
41
+ }
42
+
43
+ export const axiosInstance = axios.create(getConfig())
44
+
45
+ export const axiosClient = async <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>> => {
46
+ const globalConfig = getConfig()
47
+
48
+ return axiosInstance
49
+ .request<TData, ResponseConfig<TData>>({
50
+ ...globalConfig,
51
+ ...config,
52
+ headers: {
53
+ ...globalConfig.headers,
54
+ ...config.headers,
55
+ },
56
+ })
57
+ .catch((e: AxiosError<TError>) => {
58
+ throw e
59
+ })
60
+ }
61
+
62
+ axiosClient.getConfig = getConfig
63
+ axiosClient.setConfig = setConfig
64
+
65
+ export default axiosClient
@@ -0,0 +1,222 @@
1
+ import { Client, Operations } from './chunk-PHUXTZZT.js';
2
+ import { createReactGenerator, pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
3
+ import { useOperationManager } from '@kubb/plugin-oas/hooks';
4
+ import { pluginTsName } from '@kubb/plugin-ts';
5
+ import { pluginZodName } from '@kubb/plugin-zod';
6
+ import { useApp, File, Function } from '@kubb/react';
7
+ import { jsxs, jsx } from '@kubb/react/jsx-runtime';
8
+ import path from 'node:path';
9
+ import { createPlugin, FileManager, PluginManager } from '@kubb/core';
10
+ import { camelCase } from '@kubb/core/transformers';
11
+
12
+ var clientGenerator = createReactGenerator({
13
+ name: "client",
14
+ Operation({ options, operation }) {
15
+ const {
16
+ plugin: {
17
+ options: { output }
18
+ }
19
+ } = useApp();
20
+ const { getSchemas, getName, getFile } = useOperationManager();
21
+ const client = {
22
+ name: getName(operation, { type: "function" }),
23
+ file: getFile(operation)
24
+ };
25
+ const type = {
26
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
27
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
28
+ };
29
+ const zod = {
30
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
31
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
32
+ };
33
+ return /* @__PURE__ */ jsxs(File, { baseName: client.file.baseName, path: client.file.path, meta: client.file.meta, banner: output?.banner, footer: output?.footer, children: [
34
+ /* @__PURE__ */ jsx(File.Import, { name: "client", path: options.importPath }),
35
+ /* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig"], path: options.importPath, isTypeOnly: true }),
36
+ options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { name: [zod.schemas.response.name], root: client.file.path, path: zod.file.path }),
37
+ /* @__PURE__ */ jsx(
38
+ File.Import,
39
+ {
40
+ name: [
41
+ type.schemas.request?.name,
42
+ type.schemas.response.name,
43
+ type.schemas.pathParams?.name,
44
+ type.schemas.queryParams?.name,
45
+ type.schemas.headerParams?.name,
46
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
47
+ ].filter(Boolean),
48
+ root: client.file.path,
49
+ path: type.file.path,
50
+ isTypeOnly: true
51
+ }
52
+ ),
53
+ /* @__PURE__ */ jsx(
54
+ Client,
55
+ {
56
+ name: client.name,
57
+ baseURL: options.baseURL,
58
+ dataReturnType: options.dataReturnType,
59
+ pathParamsType: options.pathParamsType,
60
+ paramsType: options.paramsType,
61
+ typeSchemas: type.schemas,
62
+ operation,
63
+ parser: options.parser,
64
+ zodSchemas: zod.schemas
65
+ }
66
+ )
67
+ ] });
68
+ }
69
+ });
70
+ var groupedClientGenerator = createReactGenerator({
71
+ name: "groupedClient",
72
+ Operations({ operations }) {
73
+ const {
74
+ pluginManager,
75
+ plugin: { options }
76
+ } = useApp();
77
+ const { getName, getFile } = useOperationManager();
78
+ const controllers = operations.reduce(
79
+ (acc, operation) => {
80
+ if (options.group?.type === "tag") {
81
+ const tag = operation.getTags().at(0)?.name;
82
+ const name = tag ? options.group?.name?.({ group: camelCase(tag) }) : void 0;
83
+ if (!tag || !name) {
84
+ return acc;
85
+ }
86
+ const file = pluginManager.getFile({
87
+ name,
88
+ extname: ".ts",
89
+ pluginKey: [pluginClientName],
90
+ options: { tag }
91
+ });
92
+ const client = {
93
+ name: getName(operation, { type: "function" }),
94
+ file: getFile(operation)
95
+ };
96
+ const previousFile = acc.find((item) => item.file.path === file.path);
97
+ if (previousFile) {
98
+ previousFile.clients.push(client);
99
+ } else {
100
+ acc.push({ name, file, clients: [client] });
101
+ }
102
+ }
103
+ return acc;
104
+ },
105
+ []
106
+ );
107
+ return controllers.map(({ name, file, clients }) => {
108
+ return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: options.output?.banner, footer: options.output?.footer, children: [
109
+ clients.map((client) => /* @__PURE__ */ jsx(File.Import, { name: [client.name], root: file.path, path: client.file.path }, client.name)),
110
+ /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function, { export: true, name, children: `return { ${clients.map((client) => client.name).join(", ")} }` }) })
111
+ ] }, file.path);
112
+ });
113
+ }
114
+ });
115
+
116
+ // src/plugin.ts
117
+ var pluginClientName = "plugin-client";
118
+ var pluginClient = createPlugin((options) => {
119
+ const {
120
+ output = { path: "clients", barrelType: "named" },
121
+ group,
122
+ exclude = [],
123
+ include,
124
+ override = [],
125
+ transformers = {},
126
+ dataReturnType = "data",
127
+ pathParamsType = "inline",
128
+ paramsType = "inline",
129
+ operations = false,
130
+ baseURL,
131
+ generators = [clientGenerator, group ? groupedClientGenerator : void 0, operations ? operationsGenerator : void 0].filter(Boolean),
132
+ importPath = "@kubb/plugin-client/client",
133
+ parser = "client"
134
+ } = options;
135
+ return {
136
+ name: pluginClientName,
137
+ options: {
138
+ output,
139
+ group,
140
+ parser,
141
+ dataReturnType,
142
+ importPath,
143
+ paramsType,
144
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType,
145
+ baseURL
146
+ },
147
+ pre: [pluginOasName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
148
+ resolvePath(baseName, pathMode, options2) {
149
+ const root = path.resolve(this.config.root, this.config.output.path);
150
+ const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
151
+ if (options2?.tag && group?.type === "tag") {
152
+ const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
153
+ return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
154
+ }
155
+ if (mode === "single") {
156
+ return path.resolve(root, output.path);
157
+ }
158
+ return path.resolve(root, output.path, baseName);
159
+ },
160
+ resolveName(name, type) {
161
+ const resolvedName = camelCase(name, { isFile: type === "file" });
162
+ if (type) {
163
+ return transformers?.name?.(resolvedName, type) || resolvedName;
164
+ }
165
+ return resolvedName;
166
+ },
167
+ async buildStart() {
168
+ const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
169
+ const oas = await swaggerPlugin.context.getOas();
170
+ const root = path.resolve(this.config.root, this.config.output.path);
171
+ const mode = FileManager.getMode(path.resolve(root, output.path));
172
+ const baseURL2 = await swaggerPlugin.context.getBaseURL();
173
+ const operationGenerator = new OperationGenerator(
174
+ baseURL2 ? {
175
+ ...this.plugin.options,
176
+ baseURL: baseURL2
177
+ } : this.plugin.options,
178
+ {
179
+ oas,
180
+ pluginManager: this.pluginManager,
181
+ plugin: this.plugin,
182
+ contentType: swaggerPlugin.context.contentType,
183
+ exclude,
184
+ include,
185
+ override,
186
+ mode
187
+ }
188
+ );
189
+ const files = await operationGenerator.build(...generators);
190
+ await this.addFile(...files);
191
+ const barrelFiles = await this.fileManager.getBarrelFiles({
192
+ type: output.barrelType ?? "named",
193
+ root,
194
+ output,
195
+ files: this.fileManager.files,
196
+ meta: {
197
+ pluginKey: this.plugin.key
198
+ },
199
+ logger: this.logger
200
+ });
201
+ await this.addFile(...barrelFiles);
202
+ }
203
+ };
204
+ });
205
+ var operationsGenerator = createReactGenerator({
206
+ name: "client",
207
+ Operations({ operations }) {
208
+ const {
209
+ pluginManager,
210
+ plugin: {
211
+ options: { output }
212
+ }
213
+ } = useApp();
214
+ const name = "operations";
215
+ const file = pluginManager.getFile({ name, extname: ".ts", pluginKey: [pluginClientName] });
216
+ return /* @__PURE__ */ jsx(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output?.banner, footer: output?.footer, children: /* @__PURE__ */ jsx(Operations, { name, operations }) });
217
+ }
218
+ });
219
+
220
+ export { clientGenerator, groupedClientGenerator, operationsGenerator, pluginClient, pluginClientName };
221
+ //# sourceMappingURL=chunk-I2NEG5CE.js.map
222
+ //# sourceMappingURL=chunk-I2NEG5CE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generators/clientGenerator.tsx","../src/generators/groupedClientGenerator.tsx","../src/plugin.ts","../src/generators/operationsGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","jsxs","File","jsx","pluginZodName","options","camelCase","baseURL"],"mappings":";;;;;;;;;;;AAQO,IAAM,kBAAkB,oBAAmC,CAAA;AAAA,EAChE,IAAM,EAAA,QAAA;AAAA,EACN,SAAU,CAAA,EAAE,OAAS,EAAA,SAAA,EAAa,EAAA;AAChC,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAO;AAAA;AACpB,QACE,MAAqB,EAAA;AACzB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA;AAE7D,IAAA,MAAM,MAAS,GAAA;AAAA,MACb,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAAC,YAAY,GAAG,CAAA;AAAA,MACtD,OAAA,EAAS,UAAW,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAAC,YAAY,CAAA,EAAG,IAAM,EAAA,MAAA,EAAQ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,EAAM,OAAS,EAAA,KAAA,EAAO,SAAW,EAAA,CAAC,gBAAgB,CAAA,EAAG,CAAA;AAE1F,IACE,uBAAAI,GAACD,CAAAA,IAAAA,EAAA,EAAK,QAAA,EAAU,KAAK,QAAU,EAAA,IAAA,EAAM,IAAK,CAAA,IAAA,EAAM,IAAM,EAAA,IAAA,CAAK,MAAM,MAAQ,EAAA,MAAA,EAAQ,MAAQ,EAAA,MAAA,EAAQ,MAAQ,EAAA,MAAA,EACvG,0BAAAC,GAAC,CAAA,UAAA,EAAA,EAAW,IAAY,EAAA,UAAA,EAAwB,CAClD,EAAA,CAAA;AAAA;AAGN,CAAC","file":"chunk-I2NEG5CE.js","sourcesContent":["import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { Client } from '../components/Client'\nimport type { PluginClient } from '../types'\n\nexport const clientGenerator = createReactGenerator<PluginClient>({\n name: 'client',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginClient>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const client = {\n name: getName(operation, { type: 'function' }),\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 return (\n <File baseName={client.file.baseName} path={client.file.path} meta={client.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={'client'} path={options.importPath} />\n <File.Import name={['RequestConfig']} path={options.importPath} isTypeOnly />\n {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={client.file.path} path={zod.file.path} />}\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 <Client\n name={client.name}\n baseURL={options.baseURL}\n dataReturnType={options.dataReturnType}\n pathParamsType={options.pathParamsType}\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 { camelCase } from '@kubb/core/transformers'\nimport type * as KubbFile from '@kubb/fs/types'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, Function, useApp } from '@kubb/react'\nimport type { PluginClient } from '../types'\n\nexport const groupedClientGenerator = createReactGenerator<PluginClient>({\n name: 'groupedClient',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: { options },\n } = useApp<PluginClient>()\n const { getName, getFile } = useOperationManager()\n\n const controllers = operations.reduce(\n (acc, operation) => {\n if (options.group?.type === 'tag') {\n const tag = operation.getTags().at(0)?.name\n const name = tag ? options.group?.name?.({ group: camelCase(tag) }) : undefined\n\n if (!tag || !name) {\n return acc\n }\n\n const file = pluginManager.getFile({\n name,\n extname: '.ts',\n pluginKey: [pluginClientName],\n options: { tag },\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 key={file.path} baseName={file.baseName} path={file.path} meta={file.meta} banner={options.output?.banner} footer={options.output?.footer}>\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 path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { operationsGenerator } from './generators'\nimport { clientGenerator } from './generators/clientGenerator.tsx'\nimport { groupedClientGenerator } from './generators/groupedClientGenerator.tsx'\nimport type { PluginClient } from './types.ts'\n\nexport const pluginClientName = 'plugin-client' satisfies PluginClient['name']\n\nexport const pluginClient = createPlugin<PluginClient>((options) => {\n const {\n output = { path: 'clients', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n pathParamsType = 'inline',\n paramsType = 'inline',\n operations = false,\n baseURL,\n generators = [clientGenerator, group ? groupedClientGenerator : undefined, operations ? operationsGenerator : undefined].filter(Boolean),\n importPath = '@kubb/plugin-client/client',\n parser = 'client',\n } = options\n\n return {\n name: pluginClientName,\n options: {\n output,\n group,\n parser,\n dataReturnType,\n importPath,\n paramsType,\n pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,\n baseURL,\n },\n pre: [pluginOasName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n const operationGenerator = new OperationGenerator(\n baseURL\n ? {\n ...this.plugin.options,\n baseURL,\n }\n : this.plugin.options,\n {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n },\n )\n\n const files = await operationGenerator.build(...generators)\n\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n","import { pluginClientName } from '@kubb/plugin-client'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginClient } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginClient>({\n name: 'client',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n options: { output },\n },\n } = useApp<PluginClient>()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey: [pluginClientName] })\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={output?.banner} footer={output?.footer}>\n <Operations name={name} operations={operations} />\n </File>\n )\n },\n})\n"]}
@@ -0,0 +1,232 @@
1
+ 'use strict';
2
+
3
+ var chunkUBMTYBLG_cjs = require('./chunk-UBMTYBLG.cjs');
4
+ var pluginOas = require('@kubb/plugin-oas');
5
+ var hooks = require('@kubb/plugin-oas/hooks');
6
+ var pluginTs = require('@kubb/plugin-ts');
7
+ var pluginZod = require('@kubb/plugin-zod');
8
+ var react = require('@kubb/react');
9
+ var jsxRuntime = require('@kubb/react/jsx-runtime');
10
+ var path = require('path');
11
+ var core = require('@kubb/core');
12
+ var transformers = require('@kubb/core/transformers');
13
+
14
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
+
16
+ var path__default = /*#__PURE__*/_interopDefault(path);
17
+
18
+ var clientGenerator = pluginOas.createReactGenerator({
19
+ name: "client",
20
+ Operation({ options, operation }) {
21
+ const {
22
+ plugin: {
23
+ options: { output }
24
+ }
25
+ } = react.useApp();
26
+ const { getSchemas, getName, getFile } = hooks.useOperationManager();
27
+ const client = {
28
+ name: getName(operation, { type: "function" }),
29
+ file: getFile(operation)
30
+ };
31
+ const type = {
32
+ file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
33
+ schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
34
+ };
35
+ const zod = {
36
+ file: getFile(operation, { pluginKey: [pluginZod.pluginZodName] }),
37
+ schemas: getSchemas(operation, { pluginKey: [pluginZod.pluginZodName], type: "function" })
38
+ };
39
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: client.file.baseName, path: client.file.path, meta: client.file.meta, banner: output?.banner, footer: output?.footer, children: [
40
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "client", path: options.importPath }),
41
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["RequestConfig"], path: options.importPath, isTypeOnly: true }),
42
+ options.parser === "zod" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [zod.schemas.response.name], root: client.file.path, path: zod.file.path }),
43
+ /* @__PURE__ */ jsxRuntime.jsx(
44
+ react.File.Import,
45
+ {
46
+ name: [
47
+ type.schemas.request?.name,
48
+ type.schemas.response.name,
49
+ type.schemas.pathParams?.name,
50
+ type.schemas.queryParams?.name,
51
+ type.schemas.headerParams?.name,
52
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
53
+ ].filter(Boolean),
54
+ root: client.file.path,
55
+ path: type.file.path,
56
+ isTypeOnly: true
57
+ }
58
+ ),
59
+ /* @__PURE__ */ jsxRuntime.jsx(
60
+ chunkUBMTYBLG_cjs.Client,
61
+ {
62
+ name: client.name,
63
+ baseURL: options.baseURL,
64
+ dataReturnType: options.dataReturnType,
65
+ pathParamsType: options.pathParamsType,
66
+ paramsType: options.paramsType,
67
+ typeSchemas: type.schemas,
68
+ operation,
69
+ parser: options.parser,
70
+ zodSchemas: zod.schemas
71
+ }
72
+ )
73
+ ] });
74
+ }
75
+ });
76
+ var groupedClientGenerator = pluginOas.createReactGenerator({
77
+ name: "groupedClient",
78
+ Operations({ operations }) {
79
+ const {
80
+ pluginManager,
81
+ plugin: { options }
82
+ } = react.useApp();
83
+ const { getName, getFile } = hooks.useOperationManager();
84
+ const controllers = operations.reduce(
85
+ (acc, operation) => {
86
+ if (options.group?.type === "tag") {
87
+ const tag = operation.getTags().at(0)?.name;
88
+ const name = tag ? options.group?.name?.({ group: transformers.camelCase(tag) }) : void 0;
89
+ if (!tag || !name) {
90
+ return acc;
91
+ }
92
+ const file = pluginManager.getFile({
93
+ name,
94
+ extname: ".ts",
95
+ pluginKey: [pluginClientName],
96
+ options: { tag }
97
+ });
98
+ const client = {
99
+ name: getName(operation, { type: "function" }),
100
+ file: getFile(operation)
101
+ };
102
+ const previousFile = acc.find((item) => item.file.path === file.path);
103
+ if (previousFile) {
104
+ previousFile.clients.push(client);
105
+ } else {
106
+ acc.push({ name, file, clients: [client] });
107
+ }
108
+ }
109
+ return acc;
110
+ },
111
+ []
112
+ );
113
+ return controllers.map(({ name, file, clients }) => {
114
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: options.output?.banner, footer: options.output?.footer, children: [
115
+ clients.map((client) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [client.name], root: file.path, path: client.file.path }, client.name)),
116
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { export: true, name, children: `return { ${clients.map((client) => client.name).join(", ")} }` }) })
117
+ ] }, file.path);
118
+ });
119
+ }
120
+ });
121
+
122
+ // src/plugin.ts
123
+ var pluginClientName = "plugin-client";
124
+ var pluginClient = core.createPlugin((options) => {
125
+ const {
126
+ output = { path: "clients", barrelType: "named" },
127
+ group,
128
+ exclude = [],
129
+ include,
130
+ override = [],
131
+ transformers: transformers$1 = {},
132
+ dataReturnType = "data",
133
+ pathParamsType = "inline",
134
+ paramsType = "inline",
135
+ operations = false,
136
+ baseURL,
137
+ generators = [clientGenerator, group ? groupedClientGenerator : void 0, operations ? operationsGenerator : void 0].filter(Boolean),
138
+ importPath = "@kubb/plugin-client/client",
139
+ parser = "client"
140
+ } = options;
141
+ return {
142
+ name: pluginClientName,
143
+ options: {
144
+ output,
145
+ group,
146
+ parser,
147
+ dataReturnType,
148
+ importPath,
149
+ paramsType,
150
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType,
151
+ baseURL
152
+ },
153
+ pre: [pluginOas.pluginOasName, parser === "zod" ? pluginZod.pluginZodName : void 0].filter(Boolean),
154
+ resolvePath(baseName, pathMode, options2) {
155
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
156
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
157
+ if (options2?.tag && group?.type === "tag") {
158
+ const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
159
+ return path__default.default.resolve(root, output.path, groupName({ group: transformers.camelCase(options2.tag) }), baseName);
160
+ }
161
+ if (mode === "single") {
162
+ return path__default.default.resolve(root, output.path);
163
+ }
164
+ return path__default.default.resolve(root, output.path, baseName);
165
+ },
166
+ resolveName(name, type) {
167
+ const resolvedName = transformers.camelCase(name, { isFile: type === "file" });
168
+ if (type) {
169
+ return transformers$1?.name?.(resolvedName, type) || resolvedName;
170
+ }
171
+ return resolvedName;
172
+ },
173
+ async buildStart() {
174
+ const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
175
+ const oas = await swaggerPlugin.context.getOas();
176
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
177
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
178
+ const baseURL2 = await swaggerPlugin.context.getBaseURL();
179
+ const operationGenerator = new pluginOas.OperationGenerator(
180
+ baseURL2 ? {
181
+ ...this.plugin.options,
182
+ baseURL: baseURL2
183
+ } : this.plugin.options,
184
+ {
185
+ oas,
186
+ pluginManager: this.pluginManager,
187
+ plugin: this.plugin,
188
+ contentType: swaggerPlugin.context.contentType,
189
+ exclude,
190
+ include,
191
+ override,
192
+ mode
193
+ }
194
+ );
195
+ const files = await operationGenerator.build(...generators);
196
+ await this.addFile(...files);
197
+ const barrelFiles = await this.fileManager.getBarrelFiles({
198
+ type: output.barrelType ?? "named",
199
+ root,
200
+ output,
201
+ files: this.fileManager.files,
202
+ meta: {
203
+ pluginKey: this.plugin.key
204
+ },
205
+ logger: this.logger
206
+ });
207
+ await this.addFile(...barrelFiles);
208
+ }
209
+ };
210
+ });
211
+ var operationsGenerator = pluginOas.createReactGenerator({
212
+ name: "client",
213
+ Operations({ operations }) {
214
+ const {
215
+ pluginManager,
216
+ plugin: {
217
+ options: { output }
218
+ }
219
+ } = react.useApp();
220
+ const name = "operations";
221
+ const file = pluginManager.getFile({ name, extname: ".ts", pluginKey: [pluginClientName] });
222
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output?.banner, footer: output?.footer, children: /* @__PURE__ */ jsxRuntime.jsx(chunkUBMTYBLG_cjs.Operations, { name, operations }) });
223
+ }
224
+ });
225
+
226
+ exports.clientGenerator = clientGenerator;
227
+ exports.groupedClientGenerator = groupedClientGenerator;
228
+ exports.operationsGenerator = operationsGenerator;
229
+ exports.pluginClient = pluginClient;
230
+ exports.pluginClientName = pluginClientName;
231
+ //# sourceMappingURL=chunk-IIY26RTZ.cjs.map
232
+ //# sourceMappingURL=chunk-IIY26RTZ.cjs.map