@kubb/plugin-client 4.8.1 → 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.
- package/dist/{Operations-CWBBycN7.js → Operations-B6I1tCOx.js} +117 -3
- package/dist/Operations-B6I1tCOx.js.map +1 -0
- package/dist/{Operations-gqLBimA6.cjs → Operations-BVIrtQ0H.cjs} +121 -1
- package/dist/Operations-BVIrtQ0H.cjs.map +1 -0
- package/dist/components.cjs +2 -1
- package/dist/components.d.cts +53 -2
- package/dist/components.d.ts +53 -2
- package/dist/components.js +2 -2
- package/dist/generators-CsFgdAtO.js +424 -0
- package/dist/generators-CsFgdAtO.js.map +1 -0
- package/dist/{generators-BDkH5Y4W.cjs → generators-dDr1GP7q.cjs} +198 -2
- package/dist/generators-dDr1GP7q.cjs.map +1 -0
- package/dist/generators.cjs +3 -2
- package/dist/generators.d.cts +5 -2
- package/dist/generators.d.ts +5 -2
- package/dist/generators.js +3 -3
- package/dist/index.cjs +11 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -7
- package/dist/index.js.map +1 -1
- package/dist/{types-CRHoY-hv.d.ts → types-DDd1VM_Z.d.ts} +9 -1
- package/dist/{types-DxXfO6iR.d.cts → types-MSth0FPg.d.cts} +9 -1
- package/package.json +6 -6
- package/src/components/ClassClient.tsx +235 -0
- package/src/components/index.ts +1 -0
- package/src/generators/__snapshots__/Pet.ts +186 -0
- package/src/generators/__snapshots__/Store.ts +109 -0
- package/src/generators/__snapshots__/User.ts +147 -0
- package/src/generators/classClientGenerator.tsx +231 -0
- package/src/generators/index.ts +1 -0
- package/src/plugin.ts +10 -2
- package/src/types.ts +8 -0
- package/dist/Operations-CWBBycN7.js.map +0 -1
- package/dist/Operations-gqLBimA6.cjs.map +0 -1
- package/dist/generators-BDkH5Y4W.cjs.map +0 -1
- package/dist/generators-CJTPFQ2P.js +0 -234
- package/dist/generators-CJTPFQ2P.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { URLPath } from "@kubb/core/utils";
|
|
1
|
+
import { URLPath, buildJSDoc } from "@kubb/core/utils";
|
|
2
2
|
import { getComments, getPathParams } from "@kubb/plugin-oas/utils";
|
|
3
3
|
import { Const, File, Function, FunctionParams } from "@kubb/react-fabric";
|
|
4
4
|
import { isOptional } from "@kubb/oas";
|
|
@@ -178,6 +178,120 @@ function Client({ name, isExportable = true, isIndexable = true, returnType, typ
|
|
|
178
178
|
}
|
|
179
179
|
Client.getParams = getParams;
|
|
180
180
|
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/components/ClassClient.tsx
|
|
183
|
+
function buildHeaders(contentType, hasHeaderParams) {
|
|
184
|
+
return [contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0, hasHeaderParams ? "...headers" : void 0].filter(Boolean);
|
|
185
|
+
}
|
|
186
|
+
function buildGenerics(typeSchemas) {
|
|
187
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
188
|
+
return [
|
|
189
|
+
typeSchemas.response.name,
|
|
190
|
+
TError,
|
|
191
|
+
typeSchemas.request?.name || "unknown"
|
|
192
|
+
].filter(Boolean);
|
|
193
|
+
}
|
|
194
|
+
function buildClientParams({ operation, path, baseURL, typeSchemas, isFormData, headers }) {
|
|
195
|
+
return FunctionParams.factory({ config: {
|
|
196
|
+
mode: "object",
|
|
197
|
+
children: {
|
|
198
|
+
method: { value: JSON.stringify(operation.method.toUpperCase()) },
|
|
199
|
+
url: { value: path.template },
|
|
200
|
+
baseURL: baseURL ? { value: JSON.stringify(baseURL) } : void 0,
|
|
201
|
+
params: typeSchemas.queryParams?.name ? {} : void 0,
|
|
202
|
+
data: typeSchemas.request?.name ? { value: isFormData ? "formData as FormData" : "requestData" } : void 0,
|
|
203
|
+
requestConfig: { mode: "inlineSpread" },
|
|
204
|
+
headers: headers.length ? { value: `{ ${headers.join(", ")}, ...requestConfig.headers }` } : void 0
|
|
205
|
+
}
|
|
206
|
+
} });
|
|
207
|
+
}
|
|
208
|
+
function buildRequestDataLine({ parser, zodSchemas, typeSchemas }) {
|
|
209
|
+
if (parser === "zod" && zodSchemas?.request?.name) return `const requestData = ${zodSchemas.request.name}.parse(data)`;
|
|
210
|
+
if (typeSchemas?.request?.name) return "const requestData = data";
|
|
211
|
+
return "";
|
|
212
|
+
}
|
|
213
|
+
function buildFormDataLine(isFormData, hasRequest) {
|
|
214
|
+
return isFormData && hasRequest ? "const formData = buildFormData(requestData)" : "";
|
|
215
|
+
}
|
|
216
|
+
function buildReturnStatement({ dataReturnType, parser, zodSchemas }) {
|
|
217
|
+
if (dataReturnType === "full" && parser === "zod" && zodSchemas) return `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`;
|
|
218
|
+
if (dataReturnType === "data" && parser === "zod" && zodSchemas) return `return ${zodSchemas.response.name}.parse(res.data)`;
|
|
219
|
+
if (dataReturnType === "full" && parser === "client") return "return res";
|
|
220
|
+
return "return res.data";
|
|
221
|
+
}
|
|
222
|
+
function generateMethod({ operation, name, typeSchemas, zodSchemas, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType }) {
|
|
223
|
+
const path = new URLPath(operation.path, { casing: paramsCasing });
|
|
224
|
+
const contentType = operation.getContentType();
|
|
225
|
+
const isFormData = contentType === "multipart/form-data";
|
|
226
|
+
const headers = buildHeaders(contentType, !!typeSchemas.headerParams?.name);
|
|
227
|
+
const generics = buildGenerics(typeSchemas);
|
|
228
|
+
const params = ClassClient.getParams({
|
|
229
|
+
paramsType,
|
|
230
|
+
paramsCasing,
|
|
231
|
+
pathParamsType,
|
|
232
|
+
typeSchemas,
|
|
233
|
+
isConfigurable: true
|
|
234
|
+
});
|
|
235
|
+
const clientParams = buildClientParams({
|
|
236
|
+
operation,
|
|
237
|
+
path,
|
|
238
|
+
baseURL,
|
|
239
|
+
typeSchemas,
|
|
240
|
+
isFormData,
|
|
241
|
+
headers
|
|
242
|
+
});
|
|
243
|
+
const jsdoc = buildJSDoc(getComments(operation));
|
|
244
|
+
const requestDataLine = buildRequestDataLine({
|
|
245
|
+
parser,
|
|
246
|
+
zodSchemas,
|
|
247
|
+
typeSchemas
|
|
248
|
+
});
|
|
249
|
+
const formDataLine = buildFormDataLine(isFormData, !!typeSchemas?.request?.name);
|
|
250
|
+
const returnStatement = buildReturnStatement({
|
|
251
|
+
dataReturnType,
|
|
252
|
+
parser,
|
|
253
|
+
zodSchemas
|
|
254
|
+
});
|
|
255
|
+
const methodBody = [
|
|
256
|
+
"const { client: request = this.#client, ...requestConfig } = config",
|
|
257
|
+
"",
|
|
258
|
+
requestDataLine,
|
|
259
|
+
formDataLine,
|
|
260
|
+
`const res = await request<${generics.join(", ")}>(${clientParams.toCall()})`,
|
|
261
|
+
returnStatement
|
|
262
|
+
].filter(Boolean).map((line) => ` ${line}`).join("\n");
|
|
263
|
+
return `${jsdoc}async ${name}(${params.toConstructor()}) {\n${methodBody}\n }`;
|
|
264
|
+
}
|
|
265
|
+
function ClassClient({ name, isExportable = true, isIndexable = true, operations, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType, children }) {
|
|
266
|
+
const classCode = `export class ${name} {
|
|
267
|
+
#client: typeof fetch
|
|
268
|
+
|
|
269
|
+
constructor(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
270
|
+
this.#client = config.client || fetch
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
${operations.map(({ operation, name: methodName, typeSchemas, zodSchemas }) => generateMethod({
|
|
274
|
+
operation,
|
|
275
|
+
name: methodName,
|
|
276
|
+
typeSchemas,
|
|
277
|
+
zodSchemas,
|
|
278
|
+
baseURL,
|
|
279
|
+
dataReturnType,
|
|
280
|
+
parser,
|
|
281
|
+
paramsType,
|
|
282
|
+
paramsCasing,
|
|
283
|
+
pathParamsType
|
|
284
|
+
})).join("\n\n")}
|
|
285
|
+
}`;
|
|
286
|
+
return /* @__PURE__ */ jsxs(File.Source, {
|
|
287
|
+
name,
|
|
288
|
+
isExportable,
|
|
289
|
+
isIndexable,
|
|
290
|
+
children: [classCode, children]
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
ClassClient.getParams = Client.getParams;
|
|
294
|
+
|
|
181
295
|
//#endregion
|
|
182
296
|
//#region src/components/Operations.tsx
|
|
183
297
|
function Operations({ name, operations }) {
|
|
@@ -201,5 +315,5 @@ function Operations({ name, operations }) {
|
|
|
201
315
|
}
|
|
202
316
|
|
|
203
317
|
//#endregion
|
|
204
|
-
export {
|
|
205
|
-
//# sourceMappingURL=Operations-
|
|
318
|
+
export { Url as i, ClassClient as n, Client as r, Operations as t };
|
|
319
|
+
//# sourceMappingURL=Operations-B6I1tCOx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Operations-B6I1tCOx.js","names":["getParams","operationsObject: Record<string, { path: string; method: HttpMethod }>"],"sources":["../src/components/Url.tsx","../src/components/Client.tsx","../src/components/ClassClient.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\n ? `const requestData = ${zodSchemas.request.name}.parse(data)`\n : 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 { buildJSDoc, URLPath } from '@kubb/core/utils'\nimport type { Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments } from '@kubb/plugin-oas/utils'\nimport { File, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginClient } from '../types.ts'\n\nimport { Client } from './Client.tsx'\n\ntype Props = {\n /**\n * Name of the class\n */\n name: string\n isExportable?: boolean\n isIndexable?: boolean\n operations: Array<{\n operation: Operation\n name: string\n typeSchemas: OperationSchemas\n zodSchemas: OperationSchemas | undefined\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 children?: KubbNode\n}\n\ntype GenerateMethodProps = {\n operation: Operation\n name: string\n typeSchemas: OperationSchemas\n zodSchemas: OperationSchemas | undefined\n baseURL: string | undefined\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n paramsType: PluginClient['resolvedOptions']['paramsType']\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n}\n\nfunction buildHeaders(contentType: string, hasHeaderParams: boolean): Array<string> {\n return [\n contentType !== 'application/json' && contentType !== 'multipart/form-data' ? `'Content-Type': '${contentType}'` : undefined,\n hasHeaderParams ? '...headers' : undefined,\n ].filter(Boolean) as Array<string>\n}\n\nfunction buildGenerics(typeSchemas: OperationSchemas): Array<string> {\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n return [typeSchemas.response.name, TError, typeSchemas.request?.name || 'unknown'].filter(Boolean)\n}\n\nfunction buildClientParams({\n operation,\n path,\n baseURL,\n typeSchemas,\n isFormData,\n headers,\n}: {\n operation: Operation\n path: URLPath\n baseURL: string | undefined\n typeSchemas: OperationSchemas\n isFormData: boolean\n headers: Array<string>\n}) {\n return FunctionParams.factory({\n config: {\n mode: 'object',\n children: {\n method: {\n value: JSON.stringify(operation.method.toUpperCase()),\n },\n url: {\n value: path.template,\n },\n baseURL: baseURL\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: {\n mode: 'inlineSpread',\n },\n headers: headers.length\n ? {\n value: `{ ${headers.join(', ')}, ...requestConfig.headers }`,\n }\n : undefined,\n },\n },\n })\n}\n\nfunction buildRequestDataLine({\n parser,\n zodSchemas,\n typeSchemas,\n}: {\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n zodSchemas: OperationSchemas | undefined\n typeSchemas: OperationSchemas\n}): string {\n if (parser === 'zod' && zodSchemas?.request?.name) {\n return `const requestData = ${zodSchemas.request.name}.parse(data)`\n }\n if (typeSchemas?.request?.name) {\n return 'const requestData = data'\n }\n return ''\n}\n\nfunction buildFormDataLine(isFormData: boolean, hasRequest: boolean): string {\n return isFormData && hasRequest ? 'const formData = buildFormData(requestData)' : ''\n}\n\nfunction buildReturnStatement({\n dataReturnType,\n parser,\n zodSchemas,\n}: {\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n zodSchemas: OperationSchemas | undefined\n}): string {\n if (dataReturnType === 'full' && parser === 'zod' && zodSchemas) {\n return `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`\n }\n if (dataReturnType === 'data' && parser === 'zod' && zodSchemas) {\n return `return ${zodSchemas.response.name}.parse(res.data)`\n }\n if (dataReturnType === 'full' && parser === 'client') {\n return 'return res'\n }\n return 'return res.data'\n}\n\nfunction generateMethod({\n operation,\n name,\n typeSchemas,\n zodSchemas,\n baseURL,\n dataReturnType,\n parser,\n paramsType,\n paramsCasing,\n pathParamsType,\n}: GenerateMethodProps): string {\n const path = new URLPath(operation.path, { casing: paramsCasing })\n const contentType = operation.getContentType()\n const isFormData = contentType === 'multipart/form-data'\n const headers = buildHeaders(contentType, !!typeSchemas.headerParams?.name)\n const generics = buildGenerics(typeSchemas)\n const params = ClassClient.getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable: true })\n const clientParams = buildClientParams({ operation, path, baseURL, typeSchemas, isFormData, headers })\n const jsdoc = buildJSDoc(getComments(operation))\n\n const requestDataLine = buildRequestDataLine({ parser, zodSchemas, typeSchemas })\n const formDataLine = buildFormDataLine(isFormData, !!typeSchemas?.request?.name)\n const returnStatement = buildReturnStatement({ dataReturnType, parser, zodSchemas })\n\n const methodBody = [\n 'const { client: request = this.#client, ...requestConfig } = config',\n '',\n requestDataLine,\n formDataLine,\n `const res = await request<${generics.join(', ')}>(${clientParams.toCall()})`,\n returnStatement,\n ]\n .filter(Boolean)\n .map((line) => ` ${line}`)\n .join('\\n')\n\n return `${jsdoc}async ${name}(${params.toConstructor()}) {\\n${methodBody}\\n }`\n}\n\nexport function ClassClient({\n name,\n isExportable = true,\n isIndexable = true,\n operations,\n baseURL,\n dataReturnType,\n parser,\n paramsType,\n paramsCasing,\n pathParamsType,\n children,\n}: Props): KubbNode {\n const methods = operations.map(({ operation, name: methodName, typeSchemas, zodSchemas }) =>\n generateMethod({\n operation,\n name: methodName,\n typeSchemas,\n zodSchemas,\n baseURL,\n dataReturnType,\n parser,\n paramsType,\n paramsCasing,\n pathParamsType,\n }),\n )\n\n const classCode = `export class ${name} {\n #client: typeof fetch\n\n constructor(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {\n this.#client = config.client || fetch\n }\n\n${methods.join('\\n\\n')}\n}`\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n {classCode}\n {children}\n </File.Source>\n )\n}\nClassClient.getParams = Client.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,QAAO,eAAe,QAAQ,EAC5B,MAAM;EACJ,MAAM;EACN,UAAU,EACR,GAAG,cAAc,YAAY,YAAY;GAAE,OAAO;GAAM,QAAQ;GAAc,CAAC,EAChF;EACF,EACF,CAAC;AAGJ,QAAO,eAAe,QAAQ,EAC5B,YAAY,YAAY,YAAY,OAChC;EACE,MAAM,mBAAmB,WAAW,WAAW;EAC/C,UAAU,cAAc,YAAY,YAAY;GAAE,OAAO;GAAM,QAAQ;GAAc,CAAC;EACtF,UAAU,WAAW,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,IAAI,QAAQ,UAAU,MAAM,EAAE,QAAQ,cAAc,CAAC;CAClE,MAAM,SAASA,YAAU;EAAE;EAAY;EAAc;EAAgB;EAAa,CAAC;AAEnF,QACE,oBAAC,KAAK;EAAa;EAAoB;EAA2B;YAChE,qBAAC;GAAe;GAAM,QAAQ;GAAc,QAAQ,OAAO,eAAe;;IACxE,oBAAC;KAAM,MAAM;eAAQ,cAAc,UAAU,OAAO,aAAa,CAAC,UAAU,KAAK,iBAAiB,EAAE,QAAQ,SAAS,CAAC,CAAC;MAAqB;IAC5I,oBAAC,SAAK;;;IAEG;GACC;;AAIlB,IAAI,YAAYA;;;;ACvChB,SAAS,UAAU,EAAE,YAAY,cAAc,gBAAgB,aAAa,kBAAkC;AAC5G,KAAI,eAAe,SACjB,QAAO,eAAe,QAAQ;EAC5B,MAAM;GACJ,MAAM;GACN,UAAU;IACR,GAAG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AAC;GAAY;GAAM;aAChB,KAAK,UAAU,kBAAkB,QAAW,EAAE;IACzC;GACI"}
|
|
@@ -179,6 +179,120 @@ function Client({ name, isExportable = true, isIndexable = true, returnType, typ
|
|
|
179
179
|
}
|
|
180
180
|
Client.getParams = getParams;
|
|
181
181
|
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/components/ClassClient.tsx
|
|
184
|
+
function buildHeaders(contentType, hasHeaderParams) {
|
|
185
|
+
return [contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0, hasHeaderParams ? "...headers" : void 0].filter(Boolean);
|
|
186
|
+
}
|
|
187
|
+
function buildGenerics(typeSchemas) {
|
|
188
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
189
|
+
return [
|
|
190
|
+
typeSchemas.response.name,
|
|
191
|
+
TError,
|
|
192
|
+
typeSchemas.request?.name || "unknown"
|
|
193
|
+
].filter(Boolean);
|
|
194
|
+
}
|
|
195
|
+
function buildClientParams({ operation, path, baseURL, typeSchemas, isFormData, headers }) {
|
|
196
|
+
return __kubb_react_fabric.FunctionParams.factory({ config: {
|
|
197
|
+
mode: "object",
|
|
198
|
+
children: {
|
|
199
|
+
method: { value: JSON.stringify(operation.method.toUpperCase()) },
|
|
200
|
+
url: { value: path.template },
|
|
201
|
+
baseURL: baseURL ? { value: JSON.stringify(baseURL) } : void 0,
|
|
202
|
+
params: typeSchemas.queryParams?.name ? {} : void 0,
|
|
203
|
+
data: typeSchemas.request?.name ? { value: isFormData ? "formData as FormData" : "requestData" } : void 0,
|
|
204
|
+
requestConfig: { mode: "inlineSpread" },
|
|
205
|
+
headers: headers.length ? { value: `{ ${headers.join(", ")}, ...requestConfig.headers }` } : void 0
|
|
206
|
+
}
|
|
207
|
+
} });
|
|
208
|
+
}
|
|
209
|
+
function buildRequestDataLine({ parser, zodSchemas, typeSchemas }) {
|
|
210
|
+
if (parser === "zod" && zodSchemas?.request?.name) return `const requestData = ${zodSchemas.request.name}.parse(data)`;
|
|
211
|
+
if (typeSchemas?.request?.name) return "const requestData = data";
|
|
212
|
+
return "";
|
|
213
|
+
}
|
|
214
|
+
function buildFormDataLine(isFormData, hasRequest) {
|
|
215
|
+
return isFormData && hasRequest ? "const formData = buildFormData(requestData)" : "";
|
|
216
|
+
}
|
|
217
|
+
function buildReturnStatement({ dataReturnType, parser, zodSchemas }) {
|
|
218
|
+
if (dataReturnType === "full" && parser === "zod" && zodSchemas) return `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`;
|
|
219
|
+
if (dataReturnType === "data" && parser === "zod" && zodSchemas) return `return ${zodSchemas.response.name}.parse(res.data)`;
|
|
220
|
+
if (dataReturnType === "full" && parser === "client") return "return res";
|
|
221
|
+
return "return res.data";
|
|
222
|
+
}
|
|
223
|
+
function generateMethod({ operation, name, typeSchemas, zodSchemas, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType }) {
|
|
224
|
+
const path = new __kubb_core_utils.URLPath(operation.path, { casing: paramsCasing });
|
|
225
|
+
const contentType = operation.getContentType();
|
|
226
|
+
const isFormData = contentType === "multipart/form-data";
|
|
227
|
+
const headers = buildHeaders(contentType, !!typeSchemas.headerParams?.name);
|
|
228
|
+
const generics = buildGenerics(typeSchemas);
|
|
229
|
+
const params = ClassClient.getParams({
|
|
230
|
+
paramsType,
|
|
231
|
+
paramsCasing,
|
|
232
|
+
pathParamsType,
|
|
233
|
+
typeSchemas,
|
|
234
|
+
isConfigurable: true
|
|
235
|
+
});
|
|
236
|
+
const clientParams = buildClientParams({
|
|
237
|
+
operation,
|
|
238
|
+
path,
|
|
239
|
+
baseURL,
|
|
240
|
+
typeSchemas,
|
|
241
|
+
isFormData,
|
|
242
|
+
headers
|
|
243
|
+
});
|
|
244
|
+
const jsdoc = (0, __kubb_core_utils.buildJSDoc)((0, __kubb_plugin_oas_utils.getComments)(operation));
|
|
245
|
+
const requestDataLine = buildRequestDataLine({
|
|
246
|
+
parser,
|
|
247
|
+
zodSchemas,
|
|
248
|
+
typeSchemas
|
|
249
|
+
});
|
|
250
|
+
const formDataLine = buildFormDataLine(isFormData, !!typeSchemas?.request?.name);
|
|
251
|
+
const returnStatement = buildReturnStatement({
|
|
252
|
+
dataReturnType,
|
|
253
|
+
parser,
|
|
254
|
+
zodSchemas
|
|
255
|
+
});
|
|
256
|
+
const methodBody = [
|
|
257
|
+
"const { client: request = this.#client, ...requestConfig } = config",
|
|
258
|
+
"",
|
|
259
|
+
requestDataLine,
|
|
260
|
+
formDataLine,
|
|
261
|
+
`const res = await request<${generics.join(", ")}>(${clientParams.toCall()})`,
|
|
262
|
+
returnStatement
|
|
263
|
+
].filter(Boolean).map((line) => ` ${line}`).join("\n");
|
|
264
|
+
return `${jsdoc}async ${name}(${params.toConstructor()}) {\n${methodBody}\n }`;
|
|
265
|
+
}
|
|
266
|
+
function ClassClient({ name, isExportable = true, isIndexable = true, operations, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType, children }) {
|
|
267
|
+
const classCode = `export class ${name} {
|
|
268
|
+
#client: typeof fetch
|
|
269
|
+
|
|
270
|
+
constructor(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
271
|
+
this.#client = config.client || fetch
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
${operations.map(({ operation, name: methodName, typeSchemas, zodSchemas }) => generateMethod({
|
|
275
|
+
operation,
|
|
276
|
+
name: methodName,
|
|
277
|
+
typeSchemas,
|
|
278
|
+
zodSchemas,
|
|
279
|
+
baseURL,
|
|
280
|
+
dataReturnType,
|
|
281
|
+
parser,
|
|
282
|
+
paramsType,
|
|
283
|
+
paramsCasing,
|
|
284
|
+
pathParamsType
|
|
285
|
+
})).join("\n\n")}
|
|
286
|
+
}`;
|
|
287
|
+
return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_react_fabric.File.Source, {
|
|
288
|
+
name,
|
|
289
|
+
isExportable,
|
|
290
|
+
isIndexable,
|
|
291
|
+
children: [classCode, children]
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
ClassClient.getParams = Client.getParams;
|
|
295
|
+
|
|
182
296
|
//#endregion
|
|
183
297
|
//#region src/components/Operations.tsx
|
|
184
298
|
function Operations({ name, operations }) {
|
|
@@ -202,6 +316,12 @@ function Operations({ name, operations }) {
|
|
|
202
316
|
}
|
|
203
317
|
|
|
204
318
|
//#endregion
|
|
319
|
+
Object.defineProperty(exports, 'ClassClient', {
|
|
320
|
+
enumerable: true,
|
|
321
|
+
get: function () {
|
|
322
|
+
return ClassClient;
|
|
323
|
+
}
|
|
324
|
+
});
|
|
205
325
|
Object.defineProperty(exports, 'Client', {
|
|
206
326
|
enumerable: true,
|
|
207
327
|
get: function () {
|
|
@@ -220,4 +340,4 @@ Object.defineProperty(exports, 'Url', {
|
|
|
220
340
|
return Url;
|
|
221
341
|
}
|
|
222
342
|
});
|
|
223
|
-
//# sourceMappingURL=Operations-
|
|
343
|
+
//# sourceMappingURL=Operations-BVIrtQ0H.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Operations-BVIrtQ0H.cjs","names":["getParams","FunctionParams","URLPath","File","Function","Const","FunctionParams","URLPath","File","Function","FunctionParams","URLPath","File","operationsObject: Record<string, { path: string; method: HttpMethod }>","URLPath","File","Const"],"sources":["../src/components/Url.tsx","../src/components/Client.tsx","../src/components/ClassClient.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\n ? `const requestData = ${zodSchemas.request.name}.parse(data)`\n : 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 { buildJSDoc, URLPath } from '@kubb/core/utils'\nimport type { Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments } from '@kubb/plugin-oas/utils'\nimport { File, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginClient } from '../types.ts'\n\nimport { Client } from './Client.tsx'\n\ntype Props = {\n /**\n * Name of the class\n */\n name: string\n isExportable?: boolean\n isIndexable?: boolean\n operations: Array<{\n operation: Operation\n name: string\n typeSchemas: OperationSchemas\n zodSchemas: OperationSchemas | undefined\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 children?: KubbNode\n}\n\ntype GenerateMethodProps = {\n operation: Operation\n name: string\n typeSchemas: OperationSchemas\n zodSchemas: OperationSchemas | undefined\n baseURL: string | undefined\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n paramsType: PluginClient['resolvedOptions']['paramsType']\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n}\n\nfunction buildHeaders(contentType: string, hasHeaderParams: boolean): Array<string> {\n return [\n contentType !== 'application/json' && contentType !== 'multipart/form-data' ? `'Content-Type': '${contentType}'` : undefined,\n hasHeaderParams ? '...headers' : undefined,\n ].filter(Boolean) as Array<string>\n}\n\nfunction buildGenerics(typeSchemas: OperationSchemas): Array<string> {\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n return [typeSchemas.response.name, TError, typeSchemas.request?.name || 'unknown'].filter(Boolean)\n}\n\nfunction buildClientParams({\n operation,\n path,\n baseURL,\n typeSchemas,\n isFormData,\n headers,\n}: {\n operation: Operation\n path: URLPath\n baseURL: string | undefined\n typeSchemas: OperationSchemas\n isFormData: boolean\n headers: Array<string>\n}) {\n return FunctionParams.factory({\n config: {\n mode: 'object',\n children: {\n method: {\n value: JSON.stringify(operation.method.toUpperCase()),\n },\n url: {\n value: path.template,\n },\n baseURL: baseURL\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: {\n mode: 'inlineSpread',\n },\n headers: headers.length\n ? {\n value: `{ ${headers.join(', ')}, ...requestConfig.headers }`,\n }\n : undefined,\n },\n },\n })\n}\n\nfunction buildRequestDataLine({\n parser,\n zodSchemas,\n typeSchemas,\n}: {\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n zodSchemas: OperationSchemas | undefined\n typeSchemas: OperationSchemas\n}): string {\n if (parser === 'zod' && zodSchemas?.request?.name) {\n return `const requestData = ${zodSchemas.request.name}.parse(data)`\n }\n if (typeSchemas?.request?.name) {\n return 'const requestData = data'\n }\n return ''\n}\n\nfunction buildFormDataLine(isFormData: boolean, hasRequest: boolean): string {\n return isFormData && hasRequest ? 'const formData = buildFormData(requestData)' : ''\n}\n\nfunction buildReturnStatement({\n dataReturnType,\n parser,\n zodSchemas,\n}: {\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n zodSchemas: OperationSchemas | undefined\n}): string {\n if (dataReturnType === 'full' && parser === 'zod' && zodSchemas) {\n return `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`\n }\n if (dataReturnType === 'data' && parser === 'zod' && zodSchemas) {\n return `return ${zodSchemas.response.name}.parse(res.data)`\n }\n if (dataReturnType === 'full' && parser === 'client') {\n return 'return res'\n }\n return 'return res.data'\n}\n\nfunction generateMethod({\n operation,\n name,\n typeSchemas,\n zodSchemas,\n baseURL,\n dataReturnType,\n parser,\n paramsType,\n paramsCasing,\n pathParamsType,\n}: GenerateMethodProps): string {\n const path = new URLPath(operation.path, { casing: paramsCasing })\n const contentType = operation.getContentType()\n const isFormData = contentType === 'multipart/form-data'\n const headers = buildHeaders(contentType, !!typeSchemas.headerParams?.name)\n const generics = buildGenerics(typeSchemas)\n const params = ClassClient.getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable: true })\n const clientParams = buildClientParams({ operation, path, baseURL, typeSchemas, isFormData, headers })\n const jsdoc = buildJSDoc(getComments(operation))\n\n const requestDataLine = buildRequestDataLine({ parser, zodSchemas, typeSchemas })\n const formDataLine = buildFormDataLine(isFormData, !!typeSchemas?.request?.name)\n const returnStatement = buildReturnStatement({ dataReturnType, parser, zodSchemas })\n\n const methodBody = [\n 'const { client: request = this.#client, ...requestConfig } = config',\n '',\n requestDataLine,\n formDataLine,\n `const res = await request<${generics.join(', ')}>(${clientParams.toCall()})`,\n returnStatement,\n ]\n .filter(Boolean)\n .map((line) => ` ${line}`)\n .join('\\n')\n\n return `${jsdoc}async ${name}(${params.toConstructor()}) {\\n${methodBody}\\n }`\n}\n\nexport function ClassClient({\n name,\n isExportable = true,\n isIndexable = true,\n operations,\n baseURL,\n dataReturnType,\n parser,\n paramsType,\n paramsCasing,\n pathParamsType,\n children,\n}: Props): KubbNode {\n const methods = operations.map(({ operation, name: methodName, typeSchemas, zodSchemas }) =>\n generateMethod({\n operation,\n name: methodName,\n typeSchemas,\n zodSchemas,\n baseURL,\n dataReturnType,\n parser,\n paramsType,\n paramsCasing,\n pathParamsType,\n }),\n )\n\n const classCode = `export class ${name} {\n #client: typeof fetch\n\n constructor(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {\n this.#client = config.client || fetch\n }\n\n${methods.join('\\n\\n')}\n}`\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n {classCode}\n {children}\n </File.Source>\n )\n}\nClassClient.getParams = Client.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,yDAACG,yBAAK;EAAa;EAAoB;EAA2B;YAChE,0DAACC;GAAe;GAAM,QAAQ;GAAc,QAAQ,OAAO,eAAe;;IACxE,yDAACC;KAAM,MAAM;eAAQ,cAAc,UAAU,OAAO,aAAa,CAAC,UAAU,KAAK,iBAAiB,EAAE,QAAQ,SAAS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mBAAyE,EAAE;AAEjF,YAAW,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"}
|
package/dist/components.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const require_Operations = require('./Operations-
|
|
1
|
+
const require_Operations = require('./Operations-BVIrtQ0H.cjs');
|
|
2
2
|
|
|
3
|
+
exports.ClassClient = require_Operations.ClassClient;
|
|
3
4
|
exports.Client = require_Operations.Client;
|
|
4
5
|
exports.Operations = require_Operations.Operations;
|
|
5
6
|
exports.Url = require_Operations.Url;
|
package/dist/components.d.cts
CHANGED
|
@@ -1,7 +1,58 @@
|
|
|
1
|
-
import { i as OperationSchemas, n as PluginClient, o as Operation } from "./types-
|
|
1
|
+
import { i as OperationSchemas, n as PluginClient, o as Operation } from "./types-MSth0FPg.cjs";
|
|
2
2
|
import { FunctionParams } from "@kubb/react-fabric";
|
|
3
3
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
4
4
|
|
|
5
|
+
//#region src/components/ClassClient.d.ts
|
|
6
|
+
type Props$2 = {
|
|
7
|
+
/**
|
|
8
|
+
* Name of the class
|
|
9
|
+
*/
|
|
10
|
+
name: string;
|
|
11
|
+
isExportable?: boolean;
|
|
12
|
+
isIndexable?: boolean;
|
|
13
|
+
operations: Array<{
|
|
14
|
+
operation: Operation;
|
|
15
|
+
name: string;
|
|
16
|
+
typeSchemas: OperationSchemas;
|
|
17
|
+
zodSchemas: OperationSchemas | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
baseURL: string | undefined;
|
|
20
|
+
dataReturnType: PluginClient['resolvedOptions']['dataReturnType'];
|
|
21
|
+
paramsCasing: PluginClient['resolvedOptions']['paramsCasing'];
|
|
22
|
+
paramsType: PluginClient['resolvedOptions']['pathParamsType'];
|
|
23
|
+
pathParamsType: PluginClient['resolvedOptions']['pathParamsType'];
|
|
24
|
+
parser: PluginClient['resolvedOptions']['parser'] | undefined;
|
|
25
|
+
children?: KubbNode;
|
|
26
|
+
};
|
|
27
|
+
declare function ClassClient({
|
|
28
|
+
name,
|
|
29
|
+
isExportable,
|
|
30
|
+
isIndexable,
|
|
31
|
+
operations,
|
|
32
|
+
baseURL,
|
|
33
|
+
dataReturnType,
|
|
34
|
+
parser,
|
|
35
|
+
paramsType,
|
|
36
|
+
paramsCasing,
|
|
37
|
+
pathParamsType,
|
|
38
|
+
children
|
|
39
|
+
}: Props$2): KubbNode;
|
|
40
|
+
declare namespace ClassClient {
|
|
41
|
+
var getParams: ({
|
|
42
|
+
paramsType,
|
|
43
|
+
paramsCasing,
|
|
44
|
+
pathParamsType,
|
|
45
|
+
typeSchemas,
|
|
46
|
+
isConfigurable
|
|
47
|
+
}: {
|
|
48
|
+
paramsCasing: PluginClient["resolvedOptions"]["paramsCasing"];
|
|
49
|
+
paramsType: PluginClient["resolvedOptions"]["paramsType"];
|
|
50
|
+
pathParamsType: PluginClient["resolvedOptions"]["pathParamsType"];
|
|
51
|
+
typeSchemas: OperationSchemas;
|
|
52
|
+
isConfigurable: boolean;
|
|
53
|
+
}) => FunctionParams;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
5
56
|
//#region src/components/Client.d.ts
|
|
6
57
|
type Props$1 = {
|
|
7
58
|
/**
|
|
@@ -110,5 +161,5 @@ declare namespace Url {
|
|
|
110
161
|
}: GetParamsProps) => FunctionParams;
|
|
111
162
|
}
|
|
112
163
|
//#endregion
|
|
113
|
-
export { Client, Operations, Url };
|
|
164
|
+
export { ClassClient, Client, Operations, Url };
|
|
114
165
|
//# sourceMappingURL=components.d.cts.map
|
package/dist/components.d.ts
CHANGED
|
@@ -1,7 +1,58 @@
|
|
|
1
|
-
import { i as OperationSchemas, n as PluginClient, o as Operation } from "./types-
|
|
1
|
+
import { i as OperationSchemas, n as PluginClient, o as Operation } from "./types-DDd1VM_Z.js";
|
|
2
2
|
import { FunctionParams } from "@kubb/react-fabric";
|
|
3
3
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
4
4
|
|
|
5
|
+
//#region src/components/ClassClient.d.ts
|
|
6
|
+
type Props$2 = {
|
|
7
|
+
/**
|
|
8
|
+
* Name of the class
|
|
9
|
+
*/
|
|
10
|
+
name: string;
|
|
11
|
+
isExportable?: boolean;
|
|
12
|
+
isIndexable?: boolean;
|
|
13
|
+
operations: Array<{
|
|
14
|
+
operation: Operation;
|
|
15
|
+
name: string;
|
|
16
|
+
typeSchemas: OperationSchemas;
|
|
17
|
+
zodSchemas: OperationSchemas | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
baseURL: string | undefined;
|
|
20
|
+
dataReturnType: PluginClient['resolvedOptions']['dataReturnType'];
|
|
21
|
+
paramsCasing: PluginClient['resolvedOptions']['paramsCasing'];
|
|
22
|
+
paramsType: PluginClient['resolvedOptions']['pathParamsType'];
|
|
23
|
+
pathParamsType: PluginClient['resolvedOptions']['pathParamsType'];
|
|
24
|
+
parser: PluginClient['resolvedOptions']['parser'] | undefined;
|
|
25
|
+
children?: KubbNode;
|
|
26
|
+
};
|
|
27
|
+
declare function ClassClient({
|
|
28
|
+
name,
|
|
29
|
+
isExportable,
|
|
30
|
+
isIndexable,
|
|
31
|
+
operations,
|
|
32
|
+
baseURL,
|
|
33
|
+
dataReturnType,
|
|
34
|
+
parser,
|
|
35
|
+
paramsType,
|
|
36
|
+
paramsCasing,
|
|
37
|
+
pathParamsType,
|
|
38
|
+
children
|
|
39
|
+
}: Props$2): KubbNode;
|
|
40
|
+
declare namespace ClassClient {
|
|
41
|
+
var getParams: ({
|
|
42
|
+
paramsType,
|
|
43
|
+
paramsCasing,
|
|
44
|
+
pathParamsType,
|
|
45
|
+
typeSchemas,
|
|
46
|
+
isConfigurable
|
|
47
|
+
}: {
|
|
48
|
+
paramsCasing: PluginClient["resolvedOptions"]["paramsCasing"];
|
|
49
|
+
paramsType: PluginClient["resolvedOptions"]["paramsType"];
|
|
50
|
+
pathParamsType: PluginClient["resolvedOptions"]["pathParamsType"];
|
|
51
|
+
typeSchemas: OperationSchemas;
|
|
52
|
+
isConfigurable: boolean;
|
|
53
|
+
}) => FunctionParams;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
5
56
|
//#region src/components/Client.d.ts
|
|
6
57
|
type Props$1 = {
|
|
7
58
|
/**
|
|
@@ -110,5 +161,5 @@ declare namespace Url {
|
|
|
110
161
|
}: GetParamsProps) => FunctionParams;
|
|
111
162
|
}
|
|
112
163
|
//#endregion
|
|
113
|
-
export { Client, Operations, Url };
|
|
164
|
+
export { ClassClient, Client, Operations, Url };
|
|
114
165
|
//# sourceMappingURL=components.d.ts.map
|
package/dist/components.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { i as Url, n as ClassClient, r as Client, t as Operations } from "./Operations-B6I1tCOx.js";
|
|
2
2
|
|
|
3
|
-
export { Client, Operations, Url };
|
|
3
|
+
export { ClassClient, Client, Operations, Url };
|