@kubb/plugin-client 3.0.0-alpha.13 → 3.0.0-alpha.15
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/{chunk-QBFKND4S.js → chunk-BAX6ZFGY.js} +3 -3
- package/dist/chunk-BAX6ZFGY.js.map +1 -0
- package/dist/chunk-H2OOHGK2.js +147 -0
- package/dist/chunk-H2OOHGK2.js.map +1 -0
- package/dist/chunk-TNO4CNBR.cjs +156 -0
- package/dist/chunk-TNO4CNBR.cjs.map +1 -0
- package/dist/{chunk-PO22ZUSH.cjs → chunk-XDWPA5EL.cjs} +3 -3
- package/dist/chunk-XDWPA5EL.cjs.map +1 -0
- package/dist/components.cjs +3 -4
- package/dist/components.d.cts +10 -2
- package/dist/components.d.ts +10 -2
- package/dist/components.js +1 -2
- package/dist/generators.cjs +8 -4
- package/dist/generators.d.cts +5 -3
- package/dist/generators.d.ts +5 -3
- package/dist/generators.js +2 -2
- package/dist/index.cjs +9 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -106
- package/dist/index.js.map +1 -1
- package/dist/{types-DETYKDFZ.d.cts → types-CzL-44IA.d.cts} +18 -34
- package/dist/{types-DETYKDFZ.d.ts → types-CzL-44IA.d.ts} +18 -34
- package/package.json +12 -12
- package/src/components/Client.tsx +2 -2
- package/src/generators/{axiosGenerator.tsx → clientGenerator.tsx} +9 -26
- package/src/generators/index.ts +2 -1
- package/src/generators/operationsGenerator.tsx +21 -0
- package/src/plugin.ts +8 -15
- package/src/types.ts +17 -28
- package/dist/chunk-3NQF7BGA.cjs +0 -58
- package/dist/chunk-3NQF7BGA.cjs.map +0 -1
- package/dist/chunk-AZDWYBLW.cjs +0 -4
- package/dist/chunk-AZDWYBLW.cjs.map +0 -1
- package/dist/chunk-PO22ZUSH.cjs.map +0 -1
- package/dist/chunk-QBFKND4S.js.map +0 -1
- package/dist/chunk-QLVGX3VO.js +0 -56
- package/dist/chunk-QLVGX3VO.js.map +0 -1
- package/dist/chunk-YJOVLRSC.js +0 -3
- package/dist/chunk-YJOVLRSC.js.map +0 -1
|
@@ -7,7 +7,7 @@ import { jsx, jsxs } from '@kubb/react/jsx-runtime';
|
|
|
7
7
|
// src/components/Client.tsx
|
|
8
8
|
function Client({ name, options, typedSchemas, operation }) {
|
|
9
9
|
const contentType = operation.getContentType();
|
|
10
|
-
const baseURL = options.
|
|
10
|
+
const baseURL = options.baseURL;
|
|
11
11
|
const path = new URLPath(operation.path);
|
|
12
12
|
const isFormData = contentType === "multipart/form-data";
|
|
13
13
|
const headers = [
|
|
@@ -118,5 +118,5 @@ function Operations({ name, operations }) {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
export { Client, Operations };
|
|
121
|
-
//# sourceMappingURL=chunk-
|
|
122
|
-
//# sourceMappingURL=chunk-
|
|
121
|
+
//# sourceMappingURL=chunk-BAX6ZFGY.js.map
|
|
122
|
+
//# sourceMappingURL=chunk-BAX6ZFGY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Client.tsx","../src/components/Operations.tsx"],"names":["URLPath","jsx","File"],"mappings":";;;;;;;AAmBO,SAAS,OAAO,EAAE,IAAA,EAAM,OAAS,EAAA,YAAA,EAAc,WAA8B,EAAA;AAClF,EAAM,MAAA,WAAA,GAAc,UAAU,cAAe,EAAA,CAAA;AAC7C,EAAA,MAAM,UAAU,OAAQ,CAAA,OAAA,CAAA;AACxB,EAAA,MAAM,IAAO,GAAA,IAAI,OAAQ,CAAA,SAAA,CAAU,IAAI,CAAA,CAAA;AACvC,EAAA,MAAM,aAAa,WAAgB,KAAA,qBAAA,CAAA;AACnC,EAAA,MAAM,OAAU,GAAA;AAAA,IACd,WAAgB,KAAA,kBAAA,GAAqB,CAAoB,iBAAA,EAAA,WAAW,CAAM,CAAA,CAAA,GAAA,KAAA,CAAA;AAAA,IAC1E,YAA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AA,IAAIA,OAAQ,CAAA,SAAA,CAAU,IAAI,CAAE,CAAA,GAAA;AAAA,MAClC,QAAQ,SAAU,CAAA,MAAA;AAAA,KACpB,CAAA;AAAA,GACD,CAAA,CAAA;AAED,EACE,uBAAAC,GAACC,CAAAA,IAAAA,CAAK,MAAL,EAAA,EAAY,MAAY,YAAY,EAAA,IAAA,EAAC,WAAW,EAAA,IAAA,EAC/C,QAAAD,kBAAAA,GAAAA,CAAC,SAAM,IAAY,EAAA,MAAA,EAAM,IAAC,EAAA,OAAA,EAAO,IAC9B,EAAA,QAAA,EAAA,IAAA,CAAK,UAAU,gBAAkB,EAAA,KAAA,CAAA,EAAW,CAAC,CAAA,EAChD,CACF,EAAA,CAAA,CAAA;AAEJ","file":"chunk-BAX6ZFGY.js","sourcesContent":["import { URLPath } from '@kubb/core/utils'\n\nimport { type Operation, isOptional } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments, getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, createFunctionParams } from '@kubb/react'\nimport type { KubbNode } from '@kubb/react/types'\nimport type { PluginClient } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n options: PluginClient['resolvedOptions']\n typedSchemas: OperationSchemas\n operation: Operation\n}\n\nexport function Client({ name, options, typedSchemas, operation }: Props): KubbNode {\n const contentType = operation.getContentType()\n const baseURL = options.baseURL\n const path = new URLPath(operation.path)\n const isFormData = contentType === 'multipart/form-data'\n const headers = [\n contentType !== 'application/json' ? `'Content-Type': '${contentType}'` : undefined,\n typedSchemas.headerParams?.name ? '...headers' : undefined,\n ].filter(Boolean)\n\n const params = createFunctionParams({\n pathParams: {\n mode: options.pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typedSchemas.pathParams, { typed: true }),\n },\n data: typedSchemas.request?.name\n ? {\n type: typedSchemas.request?.name,\n optional: isOptional(typedSchemas.request?.schema),\n }\n : undefined,\n params: typedSchemas.queryParams?.name\n ? {\n type: typedSchemas.queryParams?.name,\n optional: isOptional(typedSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typedSchemas.headerParams?.name\n ? {\n type: typedSchemas.headerParams?.name,\n optional: isOptional(typedSchemas.headerParams?.schema),\n }\n : undefined,\n options: {\n type: 'Partial<Parameters<typeof client>[0]>',\n default: '{}',\n },\n })\n\n const clientParams = createFunctionParams({\n data: {\n mode: 'object',\n children: {\n method: {\n type: 'string',\n value: JSON.stringify(operation.method),\n },\n url: {\n type: 'string',\n value: path.template,\n },\n baseURL: baseURL\n ? {\n type: 'string',\n value: JSON.stringify(baseURL),\n }\n : undefined,\n params: typedSchemas.queryParams?.name\n ? {\n type: 'any',\n }\n : undefined,\n data: typedSchemas.request?.name\n ? {\n type: 'any',\n value: isFormData ? 'formData' : undefined,\n }\n : undefined,\n headers: headers.length\n ? {\n type: 'any',\n value: headers.length ? `{ ${headers.join(', ')}, ...options.headers }` : undefined,\n }\n : undefined,\n options: {\n type: 'any',\n mode: 'inlineSpread',\n },\n },\n },\n })\n\n const formData = isFormData\n ? `\n const formData = new FormData()\n if(data) {\n Object.keys(data).forEach((key) => {\n const value = data[key];\n if (typeof key === \"string\" && (typeof value === \"string\" || value instanceof Blob)) {\n formData.append(key, value);\n }\n })\n }\n `\n : undefined\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n name={name}\n async\n export\n returnType={\n options.dataReturnType === 'data' ? `ResponseConfig<${typedSchemas.response.name}>[\"data\"]` : `ResponseConfig<${typedSchemas.response.name}>`\n }\n params={params}\n JSDoc={{\n comments: getComments(operation),\n }}\n >\n {formData || ''}\n <Function.Call\n name=\"res\"\n to={<Function name=\"client\" async generics={[typedSchemas.response.name, typedSchemas.request?.name].filter(Boolean)} params={clientParams} />}\n />\n <Function.Return>{options.dataReturnType === 'data' ? 'res.data' : 'res'}</Function.Return>\n </Function>\n </File.Source>\n )\n}\n","import { URLPath } from '@kubb/core/utils'\nimport { Const, File } from '@kubb/react'\n\nimport type { HttpMethod, Operation } from '@kubb/oas'\n\ntype OperationsProps = {\n name: string\n operations: Array<Operation>\n}\n\nexport function Operations({ name, operations }: OperationsProps) {\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 asConst>\n {JSON.stringify(operationsObject, undefined, 2)}\n </Const>\n </File.Source>\n )\n}\n"]}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Client, Operations } from './chunk-BAX6ZFGY.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 { useApp, File } from '@kubb/react';
|
|
6
|
+
import { jsxs, jsx } from '@kubb/react/jsx-runtime';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
9
|
+
import { camelCase } from '@kubb/core/transformers';
|
|
10
|
+
import { renderTemplate } from '@kubb/core/utils';
|
|
11
|
+
|
|
12
|
+
var clientGenerator = createReactGenerator({
|
|
13
|
+
name: "plugin-client",
|
|
14
|
+
Operation({ options, operation }) {
|
|
15
|
+
const { plugin } = useApp();
|
|
16
|
+
const { getSchemas, getName, getFile } = useOperationManager();
|
|
17
|
+
const name = getName(operation, { type: "function" });
|
|
18
|
+
const typedSchemas = getSchemas(operation, { pluginKey: [pluginTsName], type: "type" });
|
|
19
|
+
const file = getFile(operation);
|
|
20
|
+
const typedFile = getFile(operation, { pluginKey: [pluginTsName] });
|
|
21
|
+
if (!options.template) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const Template = options.template || Client;
|
|
25
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
26
|
+
/* @__PURE__ */ jsx(File.Import, { name: "client", path: options.importPath || "@kubb/plugin-client/client" }),
|
|
27
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["ResponseConfig"], path: options.importPath || "@kubb/plugin-client/client", isTypeOnly: true }),
|
|
28
|
+
/* @__PURE__ */ jsx(
|
|
29
|
+
File.Import,
|
|
30
|
+
{
|
|
31
|
+
extName: plugin.output?.extName,
|
|
32
|
+
name: [
|
|
33
|
+
typedSchemas.request?.name,
|
|
34
|
+
typedSchemas.response.name,
|
|
35
|
+
typedSchemas.pathParams?.name,
|
|
36
|
+
typedSchemas.queryParams?.name,
|
|
37
|
+
typedSchemas.headerParams?.name
|
|
38
|
+
].filter(Boolean),
|
|
39
|
+
root: file.path,
|
|
40
|
+
path: typedFile.path,
|
|
41
|
+
isTypeOnly: true
|
|
42
|
+
}
|
|
43
|
+
),
|
|
44
|
+
/* @__PURE__ */ jsx(Template, { name, options, typedSchemas, operation })
|
|
45
|
+
] });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
var pluginClientName = "plugin-client";
|
|
49
|
+
var pluginClient = createPlugin((options) => {
|
|
50
|
+
const {
|
|
51
|
+
output = { path: "clients" },
|
|
52
|
+
group,
|
|
53
|
+
exclude = [],
|
|
54
|
+
include,
|
|
55
|
+
override = [],
|
|
56
|
+
transformers = {},
|
|
57
|
+
dataReturnType = "data",
|
|
58
|
+
pathParamsType = "inline",
|
|
59
|
+
operations = false,
|
|
60
|
+
importPath = "@kubb/plugin-client/client"
|
|
61
|
+
} = options;
|
|
62
|
+
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
63
|
+
return {
|
|
64
|
+
name: pluginClientName,
|
|
65
|
+
output: {
|
|
66
|
+
exportType: "barrelNamed",
|
|
67
|
+
...output
|
|
68
|
+
},
|
|
69
|
+
options: {
|
|
70
|
+
dataReturnType,
|
|
71
|
+
importPath,
|
|
72
|
+
template: options.template || Client,
|
|
73
|
+
pathParamsType,
|
|
74
|
+
baseURL: void 0
|
|
75
|
+
},
|
|
76
|
+
pre: [pluginOasName],
|
|
77
|
+
resolvePath(baseName, pathMode, options2) {
|
|
78
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
79
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
80
|
+
if (mode === "single") {
|
|
81
|
+
return path.resolve(root, output.path);
|
|
82
|
+
}
|
|
83
|
+
if (options2?.tag && group?.type === "tag") {
|
|
84
|
+
const tag = camelCase(options2.tag);
|
|
85
|
+
return path.resolve(root, renderTemplate(template, { tag }), baseName);
|
|
86
|
+
}
|
|
87
|
+
return path.resolve(root, output.path, baseName);
|
|
88
|
+
},
|
|
89
|
+
resolveName(name, type) {
|
|
90
|
+
const resolvedName = camelCase(name, { isFile: type === "file" });
|
|
91
|
+
if (type) {
|
|
92
|
+
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
93
|
+
}
|
|
94
|
+
return resolvedName;
|
|
95
|
+
},
|
|
96
|
+
async buildStart() {
|
|
97
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
98
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
99
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
100
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
101
|
+
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
102
|
+
const operationGenerator = new OperationGenerator(
|
|
103
|
+
{
|
|
104
|
+
...this.plugin.options,
|
|
105
|
+
baseURL
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
oas,
|
|
109
|
+
pluginManager: this.pluginManager,
|
|
110
|
+
plugin: this.plugin,
|
|
111
|
+
contentType: swaggerPlugin.context.contentType,
|
|
112
|
+
exclude,
|
|
113
|
+
include,
|
|
114
|
+
override,
|
|
115
|
+
mode
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
const files = await operationGenerator.build(...[clientGenerator, operations ? operationsGenerator : void 0].filter(Boolean));
|
|
119
|
+
await this.addFile(...files);
|
|
120
|
+
if (this.config.output.exportType) {
|
|
121
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
122
|
+
root,
|
|
123
|
+
output,
|
|
124
|
+
files: this.fileManager.files,
|
|
125
|
+
meta: {
|
|
126
|
+
pluginKey: this.plugin.key
|
|
127
|
+
},
|
|
128
|
+
logger: this.logger
|
|
129
|
+
});
|
|
130
|
+
await this.addFile(...barrelFiles);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
var operationsGenerator = createReactGenerator({
|
|
136
|
+
name: "plugin-client",
|
|
137
|
+
Operations({ operations }) {
|
|
138
|
+
const { pluginManager } = useApp();
|
|
139
|
+
const name = "operations";
|
|
140
|
+
const file = pluginManager.getFile({ name, extName: ".ts", pluginKey: [pluginClientName] });
|
|
141
|
+
return /* @__PURE__ */ jsx(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: /* @__PURE__ */ jsx(Operations, { name, operations }) });
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
export { clientGenerator, operationsGenerator, pluginClient, pluginClientName };
|
|
146
|
+
//# sourceMappingURL=chunk-H2OOHGK2.js.map
|
|
147
|
+
//# sourceMappingURL=chunk-H2OOHGK2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/clientGenerator.tsx","../src/plugin.ts","../src/generators/operationsGenerator.tsx"],"names":["options","createReactGenerator","useApp","jsx","File"],"mappings":";;;;;;;;;;;AAOO,IAAM,kBAAkB,oBAAmC,CAAA;AAAA,EAChE,IAAM,EAAA,eAAA;AAAA,EACN,SAAU,CAAA,EAAE,OAAS,EAAA,SAAA,EAAa,EAAA;AAChC,IAAM,MAAA,EAAE,MAAO,EAAA,GAAI,MAAqB,EAAA,CAAA;AACxC,IAAA,MAAM,EAAE,UAA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AA;AACjC,QAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,UACxD,IAAA;AAAA,UACA,MAAA;AAAA,UACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,UACxB,IAAM,EAAA;AAAA,YACJ,SAAA,EAAW,KAAK,MAAO,CAAA,GAAA;AAAA,WACzB;AAAA,UACA,QAAQ,IAAK,CAAA,MAAA;AAAA,SACd,CAAA,CAAA;AAED,QAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA,CAAA;AAAA,OACnC;AAAA,KACF;AAAA,GACF,CAAA;AACF,CAAC,EAAA;AClHM,IAAM,sBAAsBC,oBAAmC,CAAA;AAAA,EACpE,IAAM,EAAA,eAAA;AAAA,EACN,UAAA,CAAW,EAAE,UAAA,EAAc,EAAA;AACzB,IAAM,MAAA,EAAE,aAAc,EAAA,GAAIC,MAAqB,EAAA,CAAA;AAE/C,IAAA,MAAM,IAAO,GAAA,YAAA,CAAA;AACb,IAAM,MAAA,IAAA,GAAO,aAAc,CAAA,OAAA,CAAQ,EAAE,IAAA,EAAM,OAAS,EAAA,KAAA,EAAO,SAAW,EAAA,CAAC,gBAAgB,CAAA,EAAG,CAAA,CAAA;AAE1F,IAAA,uBACEC,GAACC,CAAAA,IAAAA,EAAA,EAAK,QAAU,EAAA,IAAA,CAAK,UAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IACzD,EAAA,QAAA,kBAAAD,IAAC,UAAW,EAAA,EAAA,IAAA,EAAY,YAAwB,CAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-H2OOHGK2.js","sourcesContent":["import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Client } from '../components/Client'\nimport type { PluginClient } from '../types'\n\nexport const clientGenerator = createReactGenerator<PluginClient>({\n name: 'plugin-client',\n Operation({ options, operation }) {\n const { plugin } = useApp<PluginClient>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const name = getName(operation, { type: 'function' })\n const typedSchemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })\n const file = getFile(operation)\n const typedFile = getFile(operation, { pluginKey: [pluginTsName] })\n\n if (!options.template) {\n return null\n }\n\n const Template = options.template || Client\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={'client'} path={options.importPath || '@kubb/plugin-client/client'} />\n <File.Import name={['ResponseConfig']} path={options.importPath || '@kubb/plugin-client/client'} isTypeOnly />\n <File.Import\n extName={plugin.output?.extName}\n name={[\n typedSchemas.request?.name,\n typedSchemas.response.name,\n typedSchemas.pathParams?.name,\n typedSchemas.queryParams?.name,\n typedSchemas.headerParams?.name,\n ].filter(Boolean)}\n root={file.path}\n path={typedFile.path}\n isTypeOnly\n />\n <Template name={name} options={options} typedSchemas={typedSchemas} operation={operation} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { Client } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { clientGenerator } from './generators/clientGenerator.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' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n pathParamsType = 'inline',\n operations = false,\n importPath = '@kubb/plugin-client/client',\n } = options\n\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginClientName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n dataReturnType,\n importPath,\n template: options.template || Client,\n pathParamsType,\n baseURL: undefined,\n },\n pre: [pluginOasName],\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 (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 if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\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 {\n ...this.plugin.options,\n baseURL,\n },\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(...[clientGenerator, operations ? operationsGenerator : undefined].filter(Boolean))\n\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\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})\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: 'plugin-client',\n Operations({ operations }) {\n const { pluginManager } = 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}>\n <Operations name={name} operations={operations} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkXDWPA5EL_cjs = require('./chunk-XDWPA5EL.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 react = require('@kubb/react');
|
|
8
|
+
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
9
|
+
var path = require('path');
|
|
10
|
+
var core = require('@kubb/core');
|
|
11
|
+
var transformers = require('@kubb/core/transformers');
|
|
12
|
+
var utils = require('@kubb/core/utils');
|
|
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: "plugin-client",
|
|
20
|
+
Operation({ options, operation }) {
|
|
21
|
+
const { plugin } = react.useApp();
|
|
22
|
+
const { getSchemas, getName, getFile } = hooks.useOperationManager();
|
|
23
|
+
const name = getName(operation, { type: "function" });
|
|
24
|
+
const typedSchemas = getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" });
|
|
25
|
+
const file = getFile(operation);
|
|
26
|
+
const typedFile = getFile(operation, { pluginKey: [pluginTs.pluginTsName] });
|
|
27
|
+
if (!options.template) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const Template = options.template || chunkXDWPA5EL_cjs.Client;
|
|
31
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
32
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "client", path: options.importPath || "@kubb/plugin-client/client" }),
|
|
33
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["ResponseConfig"], path: options.importPath || "@kubb/plugin-client/client", isTypeOnly: true }),
|
|
34
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
35
|
+
react.File.Import,
|
|
36
|
+
{
|
|
37
|
+
extName: plugin.output?.extName,
|
|
38
|
+
name: [
|
|
39
|
+
typedSchemas.request?.name,
|
|
40
|
+
typedSchemas.response.name,
|
|
41
|
+
typedSchemas.pathParams?.name,
|
|
42
|
+
typedSchemas.queryParams?.name,
|
|
43
|
+
typedSchemas.headerParams?.name
|
|
44
|
+
].filter(Boolean),
|
|
45
|
+
root: file.path,
|
|
46
|
+
path: typedFile.path,
|
|
47
|
+
isTypeOnly: true
|
|
48
|
+
}
|
|
49
|
+
),
|
|
50
|
+
/* @__PURE__ */ jsxRuntime.jsx(Template, { name, options, typedSchemas, operation })
|
|
51
|
+
] });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
var pluginClientName = "plugin-client";
|
|
55
|
+
var pluginClient = core.createPlugin((options) => {
|
|
56
|
+
const {
|
|
57
|
+
output = { path: "clients" },
|
|
58
|
+
group,
|
|
59
|
+
exclude = [],
|
|
60
|
+
include,
|
|
61
|
+
override = [],
|
|
62
|
+
transformers: transformers$1 = {},
|
|
63
|
+
dataReturnType = "data",
|
|
64
|
+
pathParamsType = "inline",
|
|
65
|
+
operations = false,
|
|
66
|
+
importPath = "@kubb/plugin-client/client"
|
|
67
|
+
} = options;
|
|
68
|
+
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
69
|
+
return {
|
|
70
|
+
name: pluginClientName,
|
|
71
|
+
output: {
|
|
72
|
+
exportType: "barrelNamed",
|
|
73
|
+
...output
|
|
74
|
+
},
|
|
75
|
+
options: {
|
|
76
|
+
dataReturnType,
|
|
77
|
+
importPath,
|
|
78
|
+
template: options.template || chunkXDWPA5EL_cjs.Client,
|
|
79
|
+
pathParamsType,
|
|
80
|
+
baseURL: void 0
|
|
81
|
+
},
|
|
82
|
+
pre: [pluginOas.pluginOasName],
|
|
83
|
+
resolvePath(baseName, pathMode, options2) {
|
|
84
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
85
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
86
|
+
if (mode === "single") {
|
|
87
|
+
return path__default.default.resolve(root, output.path);
|
|
88
|
+
}
|
|
89
|
+
if (options2?.tag && group?.type === "tag") {
|
|
90
|
+
const tag = transformers.camelCase(options2.tag);
|
|
91
|
+
return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
|
|
92
|
+
}
|
|
93
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
94
|
+
},
|
|
95
|
+
resolveName(name, type) {
|
|
96
|
+
const resolvedName = transformers.camelCase(name, { isFile: type === "file" });
|
|
97
|
+
if (type) {
|
|
98
|
+
return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
99
|
+
}
|
|
100
|
+
return resolvedName;
|
|
101
|
+
},
|
|
102
|
+
async buildStart() {
|
|
103
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
104
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
105
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
106
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
107
|
+
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
108
|
+
const operationGenerator = new pluginOas.OperationGenerator(
|
|
109
|
+
{
|
|
110
|
+
...this.plugin.options,
|
|
111
|
+
baseURL
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
oas,
|
|
115
|
+
pluginManager: this.pluginManager,
|
|
116
|
+
plugin: this.plugin,
|
|
117
|
+
contentType: swaggerPlugin.context.contentType,
|
|
118
|
+
exclude,
|
|
119
|
+
include,
|
|
120
|
+
override,
|
|
121
|
+
mode
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
const files = await operationGenerator.build(...[clientGenerator, operations ? operationsGenerator : void 0].filter(Boolean));
|
|
125
|
+
await this.addFile(...files);
|
|
126
|
+
if (this.config.output.exportType) {
|
|
127
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
128
|
+
root,
|
|
129
|
+
output,
|
|
130
|
+
files: this.fileManager.files,
|
|
131
|
+
meta: {
|
|
132
|
+
pluginKey: this.plugin.key
|
|
133
|
+
},
|
|
134
|
+
logger: this.logger
|
|
135
|
+
});
|
|
136
|
+
await this.addFile(...barrelFiles);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
var operationsGenerator = pluginOas.createReactGenerator({
|
|
142
|
+
name: "plugin-client",
|
|
143
|
+
Operations({ operations }) {
|
|
144
|
+
const { pluginManager } = react.useApp();
|
|
145
|
+
const name = "operations";
|
|
146
|
+
const file = pluginManager.getFile({ name, extName: ".ts", pluginKey: [pluginClientName] });
|
|
147
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: /* @__PURE__ */ jsxRuntime.jsx(chunkXDWPA5EL_cjs.Operations, { name, operations }) });
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
exports.clientGenerator = clientGenerator;
|
|
152
|
+
exports.operationsGenerator = operationsGenerator;
|
|
153
|
+
exports.pluginClient = pluginClient;
|
|
154
|
+
exports.pluginClientName = pluginClientName;
|
|
155
|
+
//# sourceMappingURL=chunk-TNO4CNBR.cjs.map
|
|
156
|
+
//# sourceMappingURL=chunk-TNO4CNBR.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/clientGenerator.tsx","../src/plugin.ts","../src/generators/operationsGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","pluginTsName","Client","jsxs","File","jsx","createPlugin","transformers","pluginOasName","options","path","FileManager","camelCase","renderTemplate","PluginManager","OperationGenerator","Operations"],"mappings":";;;;;;;;;;;;;;;;;AAOO,IAAM,kBAAkBA,8BAAmC,CAAA;AAAA,EAChE,IAAM,EAAA,eAAA;AAAA,EACN,SAAU,CAAA,EAAE,OAAS,EAAA,SAAA,EAAa,EAAA;AAChC,IAAM,MAAA,EAAE,MAAO,EAAA,GAAIC,YAAqB,EAAA,CAAA;AACxC,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAYC,yBAAoB,EAAA,CAAA;AAE7D,IAAA,MAAM,OAAO,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA,CAAA;AACpD,IAAM,MAAA,YAAA,GAAe,UAAW,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAACC,qBAAY,CAAA,EAAG,IAAM,EAAA,MAAA,EAAQ,CAAA,CAAA;AACtF,IAAM,MAAA,IAAA,GAAO,QAAQ,SAAS,CAAA,CAAA;AAC9B,IAAM,MAAA,SAAA,GAAY,QAAQ,SAAW,EAAA,EAAE,WAAW,CAACA,qBAAY,GAAG,CAAA,CAAA;AAElE,IAAI,IAAA,CAAC,QAAQ,QAAU,EAAA;AACrB,MAAO,OAAA,IAAA,CAAA;AAAA,KACT;AAEA,IAAM,MAAA,QAAA,GAAW,QAAQ,QAAY,IAAAC,wBAAA,CAAA;AAErC,IACE,uBAAAC,eAAA,CAACC,UAAK,EAAA,EAAA,QAAA,EAAU,IAAK,CAAA,QAAA,EAAU,MAAM,I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A,MAAM,IAAO,GAAA,YAAA,CAAA;AACb,IAAM,MAAA,IAAA,GAAO,aAAc,CAAA,OAAA,CAAQ,EAAE,IAAA,EAAM,OAAS,EAAA,KAAA,EAAO,SAAW,EAAA,CAAC,gBAAgB,CAAA,EAAG,CAAA,CAAA;AAE1F,IAAA,uBACEM,cAACD,CAAAA,UAAAA,EAAA,EAAK,QAAU,EAAA,IAAA,CAAK,UAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IACzD,EAAA,QAAA,kBAAAC,eAACW,4BAAW,EAAA,EAAA,IAAA,EAAY,YAAwB,CAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-TNO4CNBR.cjs","sourcesContent":["import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Client } from '../components/Client'\nimport type { PluginClient } from '../types'\n\nexport const clientGenerator = createReactGenerator<PluginClient>({\n name: 'plugin-client',\n Operation({ options, operation }) {\n const { plugin } = useApp<PluginClient>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const name = getName(operation, { type: 'function' })\n const typedSchemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })\n const file = getFile(operation)\n const typedFile = getFile(operation, { pluginKey: [pluginTsName] })\n\n if (!options.template) {\n return null\n }\n\n const Template = options.template || Client\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={'client'} path={options.importPath || '@kubb/plugin-client/client'} />\n <File.Import name={['ResponseConfig']} path={options.importPath || '@kubb/plugin-client/client'} isTypeOnly />\n <File.Import\n extName={plugin.output?.extName}\n name={[\n typedSchemas.request?.name,\n typedSchemas.response.name,\n typedSchemas.pathParams?.name,\n typedSchemas.queryParams?.name,\n typedSchemas.headerParams?.name,\n ].filter(Boolean)}\n root={file.path}\n path={typedFile.path}\n isTypeOnly\n />\n <Template name={name} options={options} typedSchemas={typedSchemas} operation={operation} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { Client } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { clientGenerator } from './generators/clientGenerator.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' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n pathParamsType = 'inline',\n operations = false,\n importPath = '@kubb/plugin-client/client',\n } = options\n\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginClientName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n dataReturnType,\n importPath,\n template: options.template || Client,\n pathParamsType,\n baseURL: undefined,\n },\n pre: [pluginOasName],\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 (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 if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\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 {\n ...this.plugin.options,\n baseURL,\n },\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(...[clientGenerator, operations ? operationsGenerator : undefined].filter(Boolean))\n\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\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})\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: 'plugin-client',\n Operations({ operations }) {\n const { pluginManager } = 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}>\n <Operations name={name} operations={operations} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -9,7 +9,7 @@ var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
|
9
9
|
// src/components/Client.tsx
|
|
10
10
|
function Client({ name, options, typedSchemas, operation }) {
|
|
11
11
|
const contentType = operation.getContentType();
|
|
12
|
-
const baseURL = options.
|
|
12
|
+
const baseURL = options.baseURL;
|
|
13
13
|
const path = new utils.URLPath(operation.path);
|
|
14
14
|
const isFormData = contentType === "multipart/form-data";
|
|
15
15
|
const headers = [
|
|
@@ -121,5 +121,5 @@ function Operations({ name, operations }) {
|
|
|
121
121
|
|
|
122
122
|
exports.Client = Client;
|
|
123
123
|
exports.Operations = Operations;
|
|
124
|
-
//# sourceMappingURL=chunk-
|
|
125
|
-
//# sourceMappingURL=chunk-
|
|
124
|
+
//# sourceMappingURL=chunk-XDWPA5EL.cjs.map
|
|
125
|
+
//# sourceMappingURL=chunk-XDWPA5EL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Client.tsx","../src/components/Operations.tsx"],"names":["URLPath","createFunctionParams","getPathParams","isOptional","jsx","File","jsxs","Function","getComments","Const"],"mappings":";;;;;;;;;AAmBO,SAAS,OAAO,EAAE,IAAA,EAAM,OAAS,EAAA,YAAA,EAAc,WAA8B,EAAA;AAClF,EAAM,MAAA,WAAA,GAAc,UAAU,cAAe,EAAA,CAAA;AAC7C,EAAA,MAAM,UAAU,OAAQ,CAAA,OAAA,CAAA;AACxB,EAAA,MAAM,IAAO,GAAA,IAAIA,aAAQ,CAAA,SAAA,CAAU,IAAI,CAAA,CAAA;AACvC,EAAA,MAAM,aAAa,WAAgB,KAAA,qBAAA,CAAA;AACnC,EAAA,MAAM,OAAU,GAAA;AAAA,IACd,WAAgB,KAAA,kBAAA,GAAqB,CAAoB,iBAAA,EAAA,WAAW,CAAM,CAAA,CAAA,GAAA,KAAA,CAAA;AAAA,IAC1E,YAAA,CAAa,YAAc,EAAA,IAAA,GAAO,YAAe,GAAA,KAAA,CAAA;AAAA,GACnD,CAAE,OAAO,OAAO,CAAA,CAAA;AAEhB,EAAA,MAAM,SAASC,0BAAqB,CAAA;AAAA,IAClC,UAAY,EAAA;AAAA,MACV,IAAM,EAAA,OAAA,CAAQ,cAAmB,KAAA,QAAA,GAAW,QAAW,GAAA,cAAA;AAAA,MACvD,UAAUC,qBAAc,CAAA,YAAA,CAAa,YAAY,EAAE,KAAA,EAAO,MAAM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AAA,MAAA,EAAM,IAAC,EAAA,OAAA,EAAO,IAC9B,EAAA,QAAA,EAAA,IAAA,CAAK,UAAU,gBAAkB,EAAA,KAAA,CAAA,EAAW,CAAC,CAAA,EAChD,CACF,EAAA,CAAA,CAAA;AAEJ","file":"chunk-XDWPA5EL.cjs","sourcesContent":["import { URLPath } from '@kubb/core/utils'\n\nimport { type Operation, isOptional } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments, getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, createFunctionParams } from '@kubb/react'\nimport type { KubbNode } from '@kubb/react/types'\nimport type { PluginClient } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n options: PluginClient['resolvedOptions']\n typedSchemas: OperationSchemas\n operation: Operation\n}\n\nexport function Client({ name, options, typedSchemas, operation }: Props): KubbNode {\n const contentType = operation.getContentType()\n const baseURL = options.baseURL\n const path = new URLPath(operation.path)\n const isFormData = contentType === 'multipart/form-data'\n const headers = [\n contentType !== 'application/json' ? `'Content-Type': '${contentType}'` : undefined,\n typedSchemas.headerParams?.name ? '...headers' : undefined,\n ].filter(Boolean)\n\n const params = createFunctionParams({\n pathParams: {\n mode: options.pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typedSchemas.pathParams, { typed: true }),\n },\n data: typedSchemas.request?.name\n ? {\n type: typedSchemas.request?.name,\n optional: isOptional(typedSchemas.request?.schema),\n }\n : undefined,\n params: typedSchemas.queryParams?.name\n ? {\n type: typedSchemas.queryParams?.name,\n optional: isOptional(typedSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typedSchemas.headerParams?.name\n ? {\n type: typedSchemas.headerParams?.name,\n optional: isOptional(typedSchemas.headerParams?.schema),\n }\n : undefined,\n options: {\n type: 'Partial<Parameters<typeof client>[0]>',\n default: '{}',\n },\n })\n\n const clientParams = createFunctionParams({\n data: {\n mode: 'object',\n children: {\n method: {\n type: 'string',\n value: JSON.stringify(operation.method),\n },\n url: {\n type: 'string',\n value: path.template,\n },\n baseURL: baseURL\n ? {\n type: 'string',\n value: JSON.stringify(baseURL),\n }\n : undefined,\n params: typedSchemas.queryParams?.name\n ? {\n type: 'any',\n }\n : undefined,\n data: typedSchemas.request?.name\n ? {\n type: 'any',\n value: isFormData ? 'formData' : undefined,\n }\n : undefined,\n headers: headers.length\n ? {\n type: 'any',\n value: headers.length ? `{ ${headers.join(', ')}, ...options.headers }` : undefined,\n }\n : undefined,\n options: {\n type: 'any',\n mode: 'inlineSpread',\n },\n },\n },\n })\n\n const formData = isFormData\n ? `\n const formData = new FormData()\n if(data) {\n Object.keys(data).forEach((key) => {\n const value = data[key];\n if (typeof key === \"string\" && (typeof value === \"string\" || value instanceof Blob)) {\n formData.append(key, value);\n }\n })\n }\n `\n : undefined\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n name={name}\n async\n export\n returnType={\n options.dataReturnType === 'data' ? `ResponseConfig<${typedSchemas.response.name}>[\"data\"]` : `ResponseConfig<${typedSchemas.response.name}>`\n }\n params={params}\n JSDoc={{\n comments: getComments(operation),\n }}\n >\n {formData || ''}\n <Function.Call\n name=\"res\"\n to={<Function name=\"client\" async generics={[typedSchemas.response.name, typedSchemas.request?.name].filter(Boolean)} params={clientParams} />}\n />\n <Function.Return>{options.dataReturnType === 'data' ? 'res.data' : 'res'}</Function.Return>\n </Function>\n </File.Source>\n )\n}\n","import { URLPath } from '@kubb/core/utils'\nimport { Const, File } from '@kubb/react'\n\nimport type { HttpMethod, Operation } from '@kubb/oas'\n\ntype OperationsProps = {\n name: string\n operations: Array<Operation>\n}\n\nexport function Operations({ name, operations }: OperationsProps) {\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 asConst>\n {JSON.stringify(operationsObject, undefined, 2)}\n </Const>\n </File.Source>\n )\n}\n"]}
|
package/dist/components.cjs
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./chunk-
|
|
4
|
-
var chunkPO22ZUSH_cjs = require('./chunk-PO22ZUSH.cjs');
|
|
3
|
+
var chunkXDWPA5EL_cjs = require('./chunk-XDWPA5EL.cjs');
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
Object.defineProperty(exports, "Client", {
|
|
9
8
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkXDWPA5EL_cjs.Client; }
|
|
11
10
|
});
|
|
12
11
|
Object.defineProperty(exports, "Operations", {
|
|
13
12
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkXDWPA5EL_cjs.Operations; }
|
|
15
14
|
});
|
|
16
15
|
//# sourceMappingURL=components.cjs.map
|
|
17
16
|
//# sourceMappingURL=components.cjs.map
|
package/dist/components.d.cts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
export { C as Client
|
|
1
|
+
export { C as Client } from './types-CzL-44IA.cjs';
|
|
2
|
+
import { Operation } from '@kubb/oas';
|
|
2
3
|
import '@kubb/core';
|
|
3
4
|
import '@kubb/fs/types';
|
|
4
|
-
import '@kubb/oas';
|
|
5
5
|
import '@kubb/plugin-oas';
|
|
6
6
|
import '@kubb/react/types';
|
|
7
|
+
|
|
8
|
+
type OperationsProps = {
|
|
9
|
+
name: string;
|
|
10
|
+
operations: Array<Operation>;
|
|
11
|
+
};
|
|
12
|
+
declare function Operations({ name, operations }: OperationsProps): JSX.Element;
|
|
13
|
+
|
|
14
|
+
export { Operations };
|
package/dist/components.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
export { C as Client
|
|
1
|
+
export { C as Client } from './types-CzL-44IA.js';
|
|
2
|
+
import { Operation } from '@kubb/oas';
|
|
2
3
|
import '@kubb/core';
|
|
3
4
|
import '@kubb/fs/types';
|
|
4
|
-
import '@kubb/oas';
|
|
5
5
|
import '@kubb/plugin-oas';
|
|
6
6
|
import '@kubb/react/types';
|
|
7
|
+
|
|
8
|
+
type OperationsProps = {
|
|
9
|
+
name: string;
|
|
10
|
+
operations: Array<Operation>;
|
|
11
|
+
};
|
|
12
|
+
declare function Operations({ name, operations }: OperationsProps): JSX.Element;
|
|
13
|
+
|
|
14
|
+
export { Operations };
|
package/dist/components.js
CHANGED
package/dist/generators.cjs
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkTNO4CNBR_cjs = require('./chunk-TNO4CNBR.cjs');
|
|
4
|
+
require('./chunk-XDWPA5EL.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
Object.defineProperty(exports, "
|
|
8
|
+
Object.defineProperty(exports, "clientGenerator", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkTNO4CNBR_cjs.clientGenerator; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "operationsGenerator", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkTNO4CNBR_cjs.operationsGenerator; }
|
|
11
15
|
});
|
|
12
16
|
//# sourceMappingURL=generators.cjs.map
|
|
13
17
|
//# sourceMappingURL=generators.cjs.map
|
package/dist/generators.d.cts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as _kubb_plugin_oas from '@kubb/plugin-oas';
|
|
2
|
-
import { P as PluginClient } from './types-
|
|
2
|
+
import { P as PluginClient } from './types-CzL-44IA.cjs';
|
|
3
3
|
import '@kubb/core';
|
|
4
4
|
import '@kubb/fs/types';
|
|
5
5
|
import '@kubb/oas';
|
|
6
6
|
import '@kubb/react/types';
|
|
7
7
|
|
|
8
|
-
declare const
|
|
8
|
+
declare const clientGenerator: _kubb_plugin_oas.Generator<PluginClient>;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
declare const operationsGenerator: _kubb_plugin_oas.Generator<PluginClient>;
|
|
11
|
+
|
|
12
|
+
export { clientGenerator, operationsGenerator };
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as _kubb_plugin_oas from '@kubb/plugin-oas';
|
|
2
|
-
import { P as PluginClient } from './types-
|
|
2
|
+
import { P as PluginClient } from './types-CzL-44IA.js';
|
|
3
3
|
import '@kubb/core';
|
|
4
4
|
import '@kubb/fs/types';
|
|
5
5
|
import '@kubb/oas';
|
|
6
6
|
import '@kubb/react/types';
|
|
7
7
|
|
|
8
|
-
declare const
|
|
8
|
+
declare const clientGenerator: _kubb_plugin_oas.Generator<PluginClient>;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
declare const operationsGenerator: _kubb_plugin_oas.Generator<PluginClient>;
|
|
11
|
+
|
|
12
|
+
export { clientGenerator, operationsGenerator };
|
package/dist/generators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { clientGenerator, operationsGenerator } from './chunk-H2OOHGK2.js';
|
|
2
|
+
import './chunk-BAX6ZFGY.js';
|
|
3
3
|
//# sourceMappingURL=generators.js.map
|
|
4
4
|
//# sourceMappingURL=generators.js.map
|