@kubb/plugin-client 3.16.2 → 3.16.4
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-Cxn7C-GC.cjs +228 -0
- package/dist/Operations-Cxn7C-GC.cjs.map +1 -0
- package/dist/Operations-tGJwS9Oj.js +210 -0
- package/dist/Operations-tGJwS9Oj.js.map +1 -0
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/clients/axios.cjs +24 -30
- package/dist/clients/axios.cjs.map +1 -1
- package/dist/clients/axios.d.cts +23 -21
- package/dist/clients/axios.d.ts +23 -21
- package/dist/clients/axios.js +23 -23
- package/dist/clients/axios.js.map +1 -1
- package/dist/clients/fetch.cjs +37 -36
- package/dist/clients/fetch.cjs.map +1 -1
- package/dist/clients/fetch.d.cts +20 -18
- package/dist/clients/fetch.d.ts +20 -18
- package/dist/clients/fetch.js +37 -34
- package/dist/clients/fetch.js.map +1 -1
- package/dist/components.cjs +4 -19
- package/dist/components.d.cts +97 -56
- package/dist/components.d.ts +97 -56
- package/dist/components.js +3 -3
- package/dist/generators-BQnLTqYl.js +216 -0
- package/dist/generators-BQnLTqYl.js.map +1 -0
- package/dist/generators-XXsaqEtA.cjs +234 -0
- package/dist/generators-XXsaqEtA.cjs.map +1 -0
- package/dist/generators.cjs +5 -20
- package/dist/generators.d.cts +12 -11
- package/dist/generators.d.ts +12 -11
- package/dist/generators.js +4 -4
- package/dist/index.cjs +89 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -7
- package/dist/index.d.ts +6 -7
- package/dist/index.js +88 -112
- package/dist/index.js.map +1 -1
- package/dist/types-CdM4kNiz.d.ts +1274 -0
- package/dist/types-Cpfa5PKO.d.cts +1274 -0
- package/package.json +27 -34
- package/dist/chunk-H5KNP3DD.cjs +0 -205
- package/dist/chunk-H5KNP3DD.cjs.map +0 -1
- package/dist/chunk-LNJCFB5O.js +0 -201
- package/dist/chunk-LNJCFB5O.js.map +0 -1
- package/dist/chunk-QNFXNUH5.js +0 -187
- package/dist/chunk-QNFXNUH5.js.map +0 -1
- package/dist/chunk-SDEXSATF.cjs +0 -191
- package/dist/chunk-SDEXSATF.cjs.map +0 -1
- package/dist/components.cjs.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/generators.cjs.map +0 -1
- package/dist/generators.js.map +0 -1
- package/dist/types-DFo3xInC.d.cts +0 -119
- package/dist/types-DFo3xInC.d.ts +0 -119
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const __kubb_plugin_oas_utils = require_chunk.__toESM(require("@kubb/plugin-oas/utils"));
|
|
3
|
+
const __kubb_react = require_chunk.__toESM(require("@kubb/react"));
|
|
4
|
+
const __kubb_core_utils = require_chunk.__toESM(require("@kubb/core/utils"));
|
|
5
|
+
const __kubb_oas = require_chunk.__toESM(require("@kubb/oas"));
|
|
6
|
+
const __kubb_react_jsx_runtime = require_chunk.__toESM(require("@kubb/react/jsx-runtime"));
|
|
7
|
+
|
|
8
|
+
//#region src/components/Url.tsx
|
|
9
|
+
function getParams$1({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
|
|
10
|
+
if (paramsType === "object") return __kubb_react.FunctionParams.factory({ data: {
|
|
11
|
+
mode: "object",
|
|
12
|
+
children: { ...(0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
13
|
+
typed: true,
|
|
14
|
+
casing: paramsCasing
|
|
15
|
+
}) }
|
|
16
|
+
} });
|
|
17
|
+
return __kubb_react.FunctionParams.factory({ pathParams: typeSchemas.pathParams?.name ? {
|
|
18
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
19
|
+
children: (0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
20
|
+
typed: true,
|
|
21
|
+
casing: paramsCasing
|
|
22
|
+
}),
|
|
23
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.pathParams?.schema)
|
|
24
|
+
} : void 0 });
|
|
25
|
+
}
|
|
26
|
+
function Url({ name, isExportable = true, isIndexable = true, typeSchemas, baseURL, paramsType, paramsCasing, pathParamsType, operation }) {
|
|
27
|
+
const path = new __kubb_core_utils.URLPath(operation.path, { casing: paramsCasing });
|
|
28
|
+
const params = getParams$1({
|
|
29
|
+
paramsType,
|
|
30
|
+
paramsCasing,
|
|
31
|
+
pathParamsType,
|
|
32
|
+
typeSchemas
|
|
33
|
+
});
|
|
34
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
35
|
+
name,
|
|
36
|
+
isExportable,
|
|
37
|
+
isIndexable,
|
|
38
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function, {
|
|
39
|
+
name,
|
|
40
|
+
export: isExportable,
|
|
41
|
+
params: params.toConstructor(),
|
|
42
|
+
children: `return ${path.toTemplateString({ prefix: baseURL })} as const`
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
Url.getParams = getParams$1;
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/components/Client.tsx
|
|
50
|
+
function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable }) {
|
|
51
|
+
if (paramsType === "object") return __kubb_react.FunctionParams.factory({
|
|
52
|
+
data: {
|
|
53
|
+
mode: "object",
|
|
54
|
+
children: {
|
|
55
|
+
...(0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
56
|
+
typed: true,
|
|
57
|
+
casing: paramsCasing
|
|
58
|
+
}),
|
|
59
|
+
data: typeSchemas.request?.name ? {
|
|
60
|
+
type: typeSchemas.request?.name,
|
|
61
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
62
|
+
} : void 0,
|
|
63
|
+
params: typeSchemas.queryParams?.name ? {
|
|
64
|
+
type: typeSchemas.queryParams?.name,
|
|
65
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
66
|
+
} : void 0,
|
|
67
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
68
|
+
type: typeSchemas.headerParams?.name,
|
|
69
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
70
|
+
} : void 0
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
config: isConfigurable ? {
|
|
74
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
|
|
75
|
+
default: "{}"
|
|
76
|
+
} : void 0
|
|
77
|
+
});
|
|
78
|
+
return __kubb_react.FunctionParams.factory({
|
|
79
|
+
pathParams: typeSchemas.pathParams?.name ? {
|
|
80
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
81
|
+
children: (0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
82
|
+
typed: true,
|
|
83
|
+
casing: paramsCasing
|
|
84
|
+
}),
|
|
85
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.pathParams?.schema)
|
|
86
|
+
} : void 0,
|
|
87
|
+
data: typeSchemas.request?.name ? {
|
|
88
|
+
type: typeSchemas.request?.name,
|
|
89
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
90
|
+
} : void 0,
|
|
91
|
+
params: typeSchemas.queryParams?.name ? {
|
|
92
|
+
type: typeSchemas.queryParams?.name,
|
|
93
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
94
|
+
} : void 0,
|
|
95
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
96
|
+
type: typeSchemas.headerParams?.name,
|
|
97
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
98
|
+
} : void 0,
|
|
99
|
+
config: isConfigurable ? {
|
|
100
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
|
|
101
|
+
default: "{}"
|
|
102
|
+
} : void 0
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function Client({ name, isExportable = true, isIndexable = true, returnType, typeSchemas, baseURL, dataReturnType, parser, zodSchemas, paramsType, paramsCasing, pathParamsType, operation, urlName, children, isConfigurable = true }) {
|
|
106
|
+
const path = new __kubb_core_utils.URLPath(operation.path, { casing: paramsCasing });
|
|
107
|
+
const contentType = operation.getContentType();
|
|
108
|
+
const isFormData = contentType === "multipart/form-data";
|
|
109
|
+
const headers = [contentType !== "application/json" ? `'Content-Type': '${contentType}'` : void 0, typeSchemas.headerParams?.name ? "...headers" : void 0].filter(Boolean);
|
|
110
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
111
|
+
const generics = [
|
|
112
|
+
typeSchemas.response.name,
|
|
113
|
+
TError,
|
|
114
|
+
typeSchemas.request?.name || "unknown"
|
|
115
|
+
].filter(Boolean);
|
|
116
|
+
const params = getParams({
|
|
117
|
+
paramsType,
|
|
118
|
+
paramsCasing,
|
|
119
|
+
pathParamsType,
|
|
120
|
+
typeSchemas,
|
|
121
|
+
isConfigurable
|
|
122
|
+
});
|
|
123
|
+
const urlParams = Url.getParams({
|
|
124
|
+
paramsType,
|
|
125
|
+
paramsCasing,
|
|
126
|
+
pathParamsType,
|
|
127
|
+
typeSchemas
|
|
128
|
+
});
|
|
129
|
+
const clientParams = __kubb_react.FunctionParams.factory({ config: {
|
|
130
|
+
mode: "object",
|
|
131
|
+
children: {
|
|
132
|
+
method: { value: JSON.stringify(operation.method.toUpperCase()) },
|
|
133
|
+
url: { value: urlName ? `${urlName}(${urlParams.toCall()}).toString()` : path.template },
|
|
134
|
+
baseURL: baseURL && !urlName ? { value: JSON.stringify(baseURL) } : void 0,
|
|
135
|
+
params: typeSchemas.queryParams?.name ? {} : void 0,
|
|
136
|
+
data: typeSchemas.request?.name ? { value: isFormData ? "formData" : "requestData" } : void 0,
|
|
137
|
+
requestConfig: isConfigurable ? { mode: "inlineSpread" } : void 0,
|
|
138
|
+
headers: headers.length ? { value: isConfigurable ? `{ ${headers.join(", ")}, ...requestConfig.headers }` : `{ ${headers.join(", ")} }` } : void 0
|
|
139
|
+
}
|
|
140
|
+
} });
|
|
141
|
+
const formData = isFormData ? `
|
|
142
|
+
const formData = new FormData()
|
|
143
|
+
if(requestData) {
|
|
144
|
+
Object.keys(requestData).forEach((key) => {
|
|
145
|
+
const value = requestData[key as keyof typeof requestData];
|
|
146
|
+
if (typeof value === 'string' || (value as unknown) instanceof Blob) {
|
|
147
|
+
formData.append(key, value as unknown as string | Blob);
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
` : "";
|
|
152
|
+
const childrenElement = children ? children : /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [
|
|
153
|
+
dataReturnType === "full" && parser === "zod" && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`,
|
|
154
|
+
dataReturnType === "data" && parser === "zod" && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`,
|
|
155
|
+
dataReturnType === "full" && parser === "client" && "return res",
|
|
156
|
+
dataReturnType === "data" && parser === "client" && "return res.data"
|
|
157
|
+
] });
|
|
158
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
159
|
+
name,
|
|
160
|
+
isExportable,
|
|
161
|
+
isIndexable,
|
|
162
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react.Function, {
|
|
163
|
+
name,
|
|
164
|
+
async: true,
|
|
165
|
+
export: isExportable,
|
|
166
|
+
params: params.toConstructor(),
|
|
167
|
+
JSDoc: { comments: (0, __kubb_plugin_oas_utils.getComments)(operation) },
|
|
168
|
+
returnType,
|
|
169
|
+
children: [
|
|
170
|
+
isConfigurable ? "const { client:request = fetch, ...requestConfig } = config" : "",
|
|
171
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)("br", {}),
|
|
172
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)("br", {}),
|
|
173
|
+
parser === "zod" && zodSchemas?.request?.name && `const requestData = ${zodSchemas.request.name}.parse(data)`,
|
|
174
|
+
parser === "client" && typeSchemas?.request?.name && "const requestData = data",
|
|
175
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)("br", {}),
|
|
176
|
+
formData,
|
|
177
|
+
isConfigurable ? `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})` : `const res = await fetch<${generics.join(", ")}>(${clientParams.toCall()})`,
|
|
178
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)("br", {}),
|
|
179
|
+
childrenElement
|
|
180
|
+
]
|
|
181
|
+
})
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
Client.getParams = getParams;
|
|
185
|
+
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/components/Operations.tsx
|
|
188
|
+
function Operations({ name, operations }) {
|
|
189
|
+
const operationsObject = {};
|
|
190
|
+
operations.forEach((operation) => {
|
|
191
|
+
operationsObject[operation.getOperationId()] = {
|
|
192
|
+
path: new __kubb_core_utils.URLPath(operation.path).URL,
|
|
193
|
+
method: operation.method
|
|
194
|
+
};
|
|
195
|
+
});
|
|
196
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
197
|
+
name,
|
|
198
|
+
isExportable: true,
|
|
199
|
+
isIndexable: true,
|
|
200
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Const, {
|
|
201
|
+
name,
|
|
202
|
+
export: true,
|
|
203
|
+
asConst: true,
|
|
204
|
+
children: JSON.stringify(operationsObject, void 0, 2)
|
|
205
|
+
})
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
//#endregion
|
|
210
|
+
Object.defineProperty(exports, 'Client', {
|
|
211
|
+
enumerable: true,
|
|
212
|
+
get: function () {
|
|
213
|
+
return Client;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
Object.defineProperty(exports, 'Operations', {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
get: function () {
|
|
219
|
+
return Operations;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
Object.defineProperty(exports, 'Url', {
|
|
223
|
+
enumerable: true,
|
|
224
|
+
get: function () {
|
|
225
|
+
return Url;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
//# sourceMappingURL=Operations-Cxn7C-GC.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Operations-Cxn7C-GC.cjs","names":["getParams","FunctionParams","URLPath","File","Function","FunctionParams","URLPath","File","Function","operationsObject: Record<string, { path: string; method: HttpMethod }>","URLPath","File","Const"],"sources":["../src/components/Url.tsx","../src/components/Client.tsx","../src/components/Operations.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\n\nimport { type Operation, isOptional } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams } from '@kubb/react'\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({ name, isExportable = true, isIndexable = true, typeSchemas, baseURL, paramsType, paramsCasing, pathParamsType, operation }: Props) {\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 {`return ${path.toTemplateString({ prefix: baseURL })} as const`}\n </Function>\n </File.Source>\n )\n}\n\nUrl.getParams = getParams\n","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, FunctionParams } from '@kubb/react'\nimport type { PluginClient } from '../types.ts'\nimport { Url } from './Url.tsx'\nimport type { KubbNode } from '@kubb/react/types'\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) {\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' ? `'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()}).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' : '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 formData = isFormData\n ? `\n const formData = new FormData()\n if(requestData) {\n Object.keys(requestData).forEach((key) => {\n const value = requestData[key as keyof typeof requestData];\n if (typeof value === 'string' || (value as unknown) instanceof Blob) {\n formData.append(key, value as unknown as string | Blob);\n }\n })\n }\n `\n : ''\n\n const childrenElement = children ? (\n children\n ) : (\n <>\n {dataReturnType === 'full' && parser === 'zod' && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`}\n {dataReturnType === 'data' && parser === 'zod' && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`}\n {dataReturnType === 'full' && parser === 'client' && 'return res'}\n {dataReturnType === 'data' && parser === 'client' && 'return res.data'}\n </>\n )\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n <Function\n name={name}\n async\n export={isExportable}\n params={params.toConstructor()}\n JSDoc={{\n comments: getComments(operation),\n }}\n returnType={returnType}\n >\n {isConfigurable ? 'const { client:request = fetch, ...requestConfig } = config' : ''}\n <br />\n <br />\n {parser === 'zod' && zodSchemas?.request?.name && `const requestData = ${zodSchemas.request.name}.parse(data)`}\n {parser === 'client' && typeSchemas?.request?.name && 'const requestData = data'}\n <br />\n {formData}\n {isConfigurable\n ? `const res = await request<${generics.join(', ')}>(${clientParams.toCall()})`\n : `const res = await fetch<${generics.join(', ')}>(${clientParams.toCall()})`}\n <br />\n {childrenElement}\n </Function>\n </File.Source>\n )\n}\n\nClient.getParams = getParams\n","import { URLPath } from '@kubb/core/utils'\nimport { 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"],"mappings":";;;;;;;;AA+BA,SAASA,YAAU,EAAE,YAAY,cAAc,gBAAgB,aAA6B,EAAE;AAC5F,KAAI,eAAe,SACjB,QAAOC,4BAAe,QAAQ,EAC5B,MAAM;EACJ,MAAM;EACN,UAAU,EACR,8CAAiB,YAAY,YAAY;GAAE,OAAO;GAAM,QAAQ;EAAc,EAAC,CAChF;CACF,EACF,EAAC;AAGJ,QAAOA,4BAAe,QAAQ,EAC5B,YAAY,YAAY,YAAY,OAChC;EACE,MAAM,mBAAmB,WAAW,WAAW;EAC/C,qDAAwB,YAAY,YAAY;GAAE,OAAO;GAAM,QAAQ;EAAc,EAAC;EACtF,qCAAqB,YAAY,YAAY,OAAO;CACrD,IACD,OACL,EAAC;AACH;AAED,SAAgB,IAAI,EAAE,MAAM,eAAe,MAAM,cAAc,MAAM,aAAa,SAAS,YAAY,cAAc,gBAAgB,WAAkB,EAAE;CACvJ,MAAM,OAAO,IAAIC,0BAAQ,UAAU,MAAM,EAAE,QAAQ,aAAc;CACjE,MAAM,SAASF,YAAU;EAAE;EAAY;EAAc;EAAgB;CAAa,EAAC;AAEnF,0DACGG,kBAAK;EAAa;EAAoB;EAA2B;8DAC/DC;GAAe;GAAM,QAAQ;GAAc,QAAQ,OAAO,eAAe;aACvE,CAAC,OAAO,EAAE,KAAK,iBAAiB,EAAE,QAAQ,QAAS,EAAC,CAAC,SAAS,CAAC;IACvD;GACC;AAEjB;AAED,IAAI,YAAYJ;;;;AC1BhB,SAAS,UAAU,EAAE,YAAY,cAAc,gBAAgB,aAAa,gBAAgC,EAAE;AAC5G,KAAI,eAAe,SACjB,QAAOK,4BAAe,QAAQ;EAC5B,MAAM;GACJ,MAAM;GACN,UAAU;IACR,8CAAiB,YAAY,YAAY;KAAE,OAAO;KAAM,QAAQ;IAAc,EAAC;IAC/E,MA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AkB,QAAW,EAAE;IACzC;GACI;AAEjB"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { getComments, getPathParams } from "@kubb/plugin-oas/utils";
|
|
2
|
+
import { Const, File, Function, FunctionParams } from "@kubb/react";
|
|
3
|
+
import { URLPath } from "@kubb/core/utils";
|
|
4
|
+
import { isOptional } from "@kubb/oas";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/components/Url.tsx
|
|
8
|
+
function getParams$1({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
|
|
9
|
+
if (paramsType === "object") return FunctionParams.factory({ data: {
|
|
10
|
+
mode: "object",
|
|
11
|
+
children: { ...getPathParams(typeSchemas.pathParams, {
|
|
12
|
+
typed: true,
|
|
13
|
+
casing: paramsCasing
|
|
14
|
+
}) }
|
|
15
|
+
} });
|
|
16
|
+
return FunctionParams.factory({ pathParams: typeSchemas.pathParams?.name ? {
|
|
17
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
18
|
+
children: getPathParams(typeSchemas.pathParams, {
|
|
19
|
+
typed: true,
|
|
20
|
+
casing: paramsCasing
|
|
21
|
+
}),
|
|
22
|
+
optional: isOptional(typeSchemas.pathParams?.schema)
|
|
23
|
+
} : void 0 });
|
|
24
|
+
}
|
|
25
|
+
function Url({ name, isExportable = true, isIndexable = true, typeSchemas, baseURL, paramsType, paramsCasing, pathParamsType, operation }) {
|
|
26
|
+
const path = new URLPath(operation.path, { casing: paramsCasing });
|
|
27
|
+
const params = getParams$1({
|
|
28
|
+
paramsType,
|
|
29
|
+
paramsCasing,
|
|
30
|
+
pathParamsType,
|
|
31
|
+
typeSchemas
|
|
32
|
+
});
|
|
33
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
34
|
+
name,
|
|
35
|
+
isExportable,
|
|
36
|
+
isIndexable,
|
|
37
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
38
|
+
name,
|
|
39
|
+
export: isExportable,
|
|
40
|
+
params: params.toConstructor(),
|
|
41
|
+
children: `return ${path.toTemplateString({ prefix: baseURL })} as const`
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
Url.getParams = getParams$1;
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/components/Client.tsx
|
|
49
|
+
function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable }) {
|
|
50
|
+
if (paramsType === "object") return FunctionParams.factory({
|
|
51
|
+
data: {
|
|
52
|
+
mode: "object",
|
|
53
|
+
children: {
|
|
54
|
+
...getPathParams(typeSchemas.pathParams, {
|
|
55
|
+
typed: true,
|
|
56
|
+
casing: paramsCasing
|
|
57
|
+
}),
|
|
58
|
+
data: typeSchemas.request?.name ? {
|
|
59
|
+
type: typeSchemas.request?.name,
|
|
60
|
+
optional: isOptional(typeSchemas.request?.schema)
|
|
61
|
+
} : void 0,
|
|
62
|
+
params: typeSchemas.queryParams?.name ? {
|
|
63
|
+
type: typeSchemas.queryParams?.name,
|
|
64
|
+
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
65
|
+
} : void 0,
|
|
66
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
67
|
+
type: typeSchemas.headerParams?.name,
|
|
68
|
+
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
69
|
+
} : void 0
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
config: isConfigurable ? {
|
|
73
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
|
|
74
|
+
default: "{}"
|
|
75
|
+
} : void 0
|
|
76
|
+
});
|
|
77
|
+
return FunctionParams.factory({
|
|
78
|
+
pathParams: typeSchemas.pathParams?.name ? {
|
|
79
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
80
|
+
children: getPathParams(typeSchemas.pathParams, {
|
|
81
|
+
typed: true,
|
|
82
|
+
casing: paramsCasing
|
|
83
|
+
}),
|
|
84
|
+
optional: isOptional(typeSchemas.pathParams?.schema)
|
|
85
|
+
} : void 0,
|
|
86
|
+
data: typeSchemas.request?.name ? {
|
|
87
|
+
type: typeSchemas.request?.name,
|
|
88
|
+
optional: isOptional(typeSchemas.request?.schema)
|
|
89
|
+
} : void 0,
|
|
90
|
+
params: typeSchemas.queryParams?.name ? {
|
|
91
|
+
type: typeSchemas.queryParams?.name,
|
|
92
|
+
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
93
|
+
} : void 0,
|
|
94
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
95
|
+
type: typeSchemas.headerParams?.name,
|
|
96
|
+
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
97
|
+
} : void 0,
|
|
98
|
+
config: isConfigurable ? {
|
|
99
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
|
|
100
|
+
default: "{}"
|
|
101
|
+
} : void 0
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function Client({ name, isExportable = true, isIndexable = true, returnType, typeSchemas, baseURL, dataReturnType, parser, zodSchemas, paramsType, paramsCasing, pathParamsType, operation, urlName, children, isConfigurable = true }) {
|
|
105
|
+
const path = new URLPath(operation.path, { casing: paramsCasing });
|
|
106
|
+
const contentType = operation.getContentType();
|
|
107
|
+
const isFormData = contentType === "multipart/form-data";
|
|
108
|
+
const headers = [contentType !== "application/json" ? `'Content-Type': '${contentType}'` : void 0, typeSchemas.headerParams?.name ? "...headers" : void 0].filter(Boolean);
|
|
109
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
110
|
+
const generics = [
|
|
111
|
+
typeSchemas.response.name,
|
|
112
|
+
TError,
|
|
113
|
+
typeSchemas.request?.name || "unknown"
|
|
114
|
+
].filter(Boolean);
|
|
115
|
+
const params = getParams({
|
|
116
|
+
paramsType,
|
|
117
|
+
paramsCasing,
|
|
118
|
+
pathParamsType,
|
|
119
|
+
typeSchemas,
|
|
120
|
+
isConfigurable
|
|
121
|
+
});
|
|
122
|
+
const urlParams = Url.getParams({
|
|
123
|
+
paramsType,
|
|
124
|
+
paramsCasing,
|
|
125
|
+
pathParamsType,
|
|
126
|
+
typeSchemas
|
|
127
|
+
});
|
|
128
|
+
const clientParams = FunctionParams.factory({ config: {
|
|
129
|
+
mode: "object",
|
|
130
|
+
children: {
|
|
131
|
+
method: { value: JSON.stringify(operation.method.toUpperCase()) },
|
|
132
|
+
url: { value: urlName ? `${urlName}(${urlParams.toCall()}).toString()` : path.template },
|
|
133
|
+
baseURL: baseURL && !urlName ? { value: JSON.stringify(baseURL) } : void 0,
|
|
134
|
+
params: typeSchemas.queryParams?.name ? {} : void 0,
|
|
135
|
+
data: typeSchemas.request?.name ? { value: isFormData ? "formData" : "requestData" } : void 0,
|
|
136
|
+
requestConfig: isConfigurable ? { mode: "inlineSpread" } : void 0,
|
|
137
|
+
headers: headers.length ? { value: isConfigurable ? `{ ${headers.join(", ")}, ...requestConfig.headers }` : `{ ${headers.join(", ")} }` } : void 0
|
|
138
|
+
}
|
|
139
|
+
} });
|
|
140
|
+
const formData = isFormData ? `
|
|
141
|
+
const formData = new FormData()
|
|
142
|
+
if(requestData) {
|
|
143
|
+
Object.keys(requestData).forEach((key) => {
|
|
144
|
+
const value = requestData[key as keyof typeof requestData];
|
|
145
|
+
if (typeof value === 'string' || (value as unknown) instanceof Blob) {
|
|
146
|
+
formData.append(key, value as unknown as string | Blob);
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
` : "";
|
|
151
|
+
const childrenElement = children ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
152
|
+
dataReturnType === "full" && parser === "zod" && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`,
|
|
153
|
+
dataReturnType === "data" && parser === "zod" && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`,
|
|
154
|
+
dataReturnType === "full" && parser === "client" && "return res",
|
|
155
|
+
dataReturnType === "data" && parser === "client" && "return res.data"
|
|
156
|
+
] });
|
|
157
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
158
|
+
name,
|
|
159
|
+
isExportable,
|
|
160
|
+
isIndexable,
|
|
161
|
+
children: /* @__PURE__ */ jsxs(Function, {
|
|
162
|
+
name,
|
|
163
|
+
async: true,
|
|
164
|
+
export: isExportable,
|
|
165
|
+
params: params.toConstructor(),
|
|
166
|
+
JSDoc: { comments: getComments(operation) },
|
|
167
|
+
returnType,
|
|
168
|
+
children: [
|
|
169
|
+
isConfigurable ? "const { client:request = fetch, ...requestConfig } = config" : "",
|
|
170
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
171
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
172
|
+
parser === "zod" && zodSchemas?.request?.name && `const requestData = ${zodSchemas.request.name}.parse(data)`,
|
|
173
|
+
parser === "client" && typeSchemas?.request?.name && "const requestData = data",
|
|
174
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
175
|
+
formData,
|
|
176
|
+
isConfigurable ? `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})` : `const res = await fetch<${generics.join(", ")}>(${clientParams.toCall()})`,
|
|
177
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
178
|
+
childrenElement
|
|
179
|
+
]
|
|
180
|
+
})
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
Client.getParams = getParams;
|
|
184
|
+
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/components/Operations.tsx
|
|
187
|
+
function Operations({ name, operations }) {
|
|
188
|
+
const operationsObject = {};
|
|
189
|
+
operations.forEach((operation) => {
|
|
190
|
+
operationsObject[operation.getOperationId()] = {
|
|
191
|
+
path: new URLPath(operation.path).URL,
|
|
192
|
+
method: operation.method
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
196
|
+
name,
|
|
197
|
+
isExportable: true,
|
|
198
|
+
isIndexable: true,
|
|
199
|
+
children: /* @__PURE__ */ jsx(Const, {
|
|
200
|
+
name,
|
|
201
|
+
export: true,
|
|
202
|
+
asConst: true,
|
|
203
|
+
children: JSON.stringify(operationsObject, void 0, 2)
|
|
204
|
+
})
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
//#endregion
|
|
209
|
+
export { Client, Operations, Url };
|
|
210
|
+
//# sourceMappingURL=Operations-tGJwS9Oj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Operations-tGJwS9Oj.js","names":["getParams","operationsObject: Record<string, { path: string; method: HttpMethod }>"],"sources":["../src/components/Url.tsx","../src/components/Client.tsx","../src/components/Operations.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\n\nimport { type Operation, isOptional } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams } from '@kubb/react'\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({ name, isExportable = true, isIndexable = true, typeSchemas, baseURL, paramsType, paramsCasing, pathParamsType, operation }: Props) {\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 {`return ${path.toTemplateString({ prefix: baseURL })} as const`}\n </Function>\n </File.Source>\n )\n}\n\nUrl.getParams = getParams\n","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, FunctionParams } from '@kubb/react'\nimport type { PluginClient } from '../types.ts'\nimport { Url } from './Url.tsx'\nimport type { KubbNode } from '@kubb/react/types'\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) {\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' ? `'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()}).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' : '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 formData = isFormData\n ? `\n const formData = new FormData()\n if(requestData) {\n Object.keys(requestData).forEach((key) => {\n const value = requestData[key as keyof typeof requestData];\n if (typeof value === 'string' || (value as unknown) instanceof Blob) {\n formData.append(key, value as unknown as string | Blob);\n }\n })\n }\n `\n : ''\n\n const childrenElement = children ? (\n children\n ) : (\n <>\n {dataReturnType === 'full' && parser === 'zod' && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`}\n {dataReturnType === 'data' && parser === 'zod' && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`}\n {dataReturnType === 'full' && parser === 'client' && 'return res'}\n {dataReturnType === 'data' && parser === 'client' && 'return res.data'}\n </>\n )\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n <Function\n name={name}\n async\n export={isExportable}\n params={params.toConstructor()}\n JSDoc={{\n comments: getComments(operation),\n }}\n returnType={returnType}\n >\n {isConfigurable ? 'const { client:request = fetch, ...requestConfig } = config' : ''}\n <br />\n <br />\n {parser === 'zod' && zodSchemas?.request?.name && `const requestData = ${zodSchemas.request.name}.parse(data)`}\n {parser === 'client' && typeSchemas?.request?.name && 'const requestData = data'}\n <br />\n {formData}\n {isConfigurable\n ? `const res = await request<${generics.join(', ')}>(${clientParams.toCall()})`\n : `const res = await fetch<${generics.join(', ')}>(${clientParams.toCall()})`}\n <br />\n {childrenElement}\n </Function>\n </File.Source>\n )\n}\n\nClient.getParams = getParams\n","import { URLPath } from '@kubb/core/utils'\nimport { 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"],"mappings":";;;;;;;AA+BA,SAASA,YAAU,EAAE,YAAY,cAAc,gBAAgB,aA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
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(exports, '__toESM', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return __toESM;
|
|
29
|
+
}
|
|
30
|
+
});
|
package/dist/clients/axios.cjs
CHANGED
|
@@ -1,45 +1,39 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
3
|
+
const axios = require_chunk.__toESM(require("axios"));
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
10
|
-
|
|
11
|
-
// src/clients/axios.ts
|
|
12
|
-
var _config = {
|
|
13
|
-
baseURL: typeof AXIOS_BASE !== "undefined" ? AXIOS_BASE : void 0,
|
|
14
|
-
headers: typeof AXIOS_HEADERS !== "undefined" ? JSON.parse(AXIOS_HEADERS) : void 0
|
|
5
|
+
//#region src/clients/axios.ts
|
|
6
|
+
let _config = {
|
|
7
|
+
baseURL: typeof AXIOS_BASE !== "undefined" ? AXIOS_BASE : void 0,
|
|
8
|
+
headers: typeof AXIOS_HEADERS !== "undefined" ? JSON.parse(AXIOS_HEADERS) : void 0
|
|
15
9
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
const getConfig = () => _config;
|
|
11
|
+
const setConfig = (config) => {
|
|
12
|
+
_config = config;
|
|
13
|
+
return getConfig();
|
|
20
14
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
const axiosInstance = axios.default.create(getConfig());
|
|
16
|
+
const client = async (config) => {
|
|
17
|
+
const globalConfig = getConfig();
|
|
18
|
+
return axiosInstance.request({
|
|
19
|
+
...globalConfig,
|
|
20
|
+
...config,
|
|
21
|
+
headers: {
|
|
22
|
+
...globalConfig.headers,
|
|
23
|
+
...config.headers
|
|
24
|
+
}
|
|
25
|
+
}).catch((e) => {
|
|
26
|
+
throw e;
|
|
27
|
+
});
|
|
34
28
|
};
|
|
35
29
|
client.getConfig = getConfig;
|
|
36
30
|
client.setConfig = setConfig;
|
|
37
31
|
var axios_default = client;
|
|
38
32
|
|
|
33
|
+
//#endregion
|
|
39
34
|
exports.axiosInstance = axiosInstance;
|
|
40
35
|
exports.client = client;
|
|
41
36
|
exports.default = axios_default;
|
|
42
37
|
exports.getConfig = getConfig;
|
|
43
38
|
exports.setConfig = setConfig;
|
|
44
|
-
//# sourceMappingURL=axios.cjs.map
|
|
45
39
|
//# sourceMappingURL=axios.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"axios.cjs","names":["_config: Partial<RequestConfig>","config: RequestConfig","config: RequestConfig<TVariables>","e: AxiosError<TError>"],"sources":["../../src/clients/axios.ts"],"sourcesContent":["import axios from 'axios'\n\nimport type { AxiosError, AxiosHeaders, AxiosRequestConfig, AxiosResponse } from 'axios'\n\ndeclare const AXIOS_BASE: string\ndeclare const AXIOS_HEADERS: string\n\n/**\n * Subset of AxiosRequestConfig\n */\nexport type RequestConfig<TData = unknown> = {\n baseURL?: string\n url?: string\n method?: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD'\n params?: unknown\n data?: TData | FormData\n responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'\n signal?: AbortSignal\n validateStatus?: (status: number) => boolean\n headers?: AxiosRequestConfig['headers']\n}\n\n/**\n * Subset of AxiosResponse\n */\nexport type ResponseConfig<TData = unknown> = {\n data: TData\n status: number\n statusText: string\n headers: AxiosResponse['headers']\n}\n\nexport type ResponseErrorConfig<TError = unknown> = AxiosError<TError>\n\nlet _config: Partial<RequestConfig> = {\n baseURL: typeof AXIOS_BASE !== 'undefined' ? AXIOS_BASE : undefined,\n headers: typeof AXIOS_HEADERS !== 'undefined' ? (JSON.parse(AXIOS_HEADERS) as AxiosHeaders) : undefined,\n}\n\nexport const getConfig = () => _config\n\nexport const setConfig = (config: RequestConfig) => {\n _config = config\n return getConfig()\n}\n\nexport const axiosInstance = axios.create(getConfig())\n\nexport const client = async <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>> => {\n const globalConfig = getConfig()\n\n return axiosInstance\n .request<TData, ResponseConfig<TData>>({\n ...globalConfig,\n ...config,\n headers: {\n ...globalConfig.headers,\n ...config.headers,\n },\n })\n .catch((e: AxiosError<TError>) => {\n throw e\n })\n}\n\nclient.getConfig = getConfig\nclient.setConfig = setConfig\n\nexport default client\n"],"mappings":";;;;;AAkCA,IAAIA,UAAkC;CACpC,SAAS,OAAO,eAAe,cAAc,aAAa;CAC1D,SAAS,OAAO,kBAAkB,cAAe,KAAK,MAAM,cAAc,GAAoB;AAC/F;AAED,MAAa,YAAY,MAAM;AAE/B,MAAa,YAAY,CAACC,WAA0B;CAClD,UAAU;AACV,QAAO,WAAW;AACnB;AAED,MAAa,gBAAgB,cAAM,OAAO,WAAW,CAAC;AAEtD,MAAa,SAAS,OAAsDC,WAAsE;CAChJ,MAAM,eAAe,WAAW;AAEhC,QAAO,cACJ,QAAsC;EACrC,GAAG;EACH,GAAG;EACH,SAAS;GACP,GAAG,aAAa;GAChB,GAAG,OAAO;EACX;CACF,EAAC,CACD,MAAM,CAACC,MAA0B;AAChC,QAAM;CACP,EAAC;AACL;AAED,OAAO,YAAY;AACnB,OAAO,YAAY;AAEnB,oBAAe"}
|