@kubb/plugin-fetch 5.0.0-beta.81 → 5.0.0-beta.85
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/index.cjs +115 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +80 -18
- package/dist/index.js.map +1 -1
- package/package.json +5 -7
- package/src/generators/clientGenerator.tsx +2 -2
- package/src/plugin.ts +2 -2
- package/src/types.ts +1 -1
- package/templates/fetch.ts +20 -10
- package/templates/serializers.ts +4 -0
package/dist/index.cjs
CHANGED
|
@@ -26,13 +26,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
//#endregion
|
|
27
27
|
let node_path = require("node:path");
|
|
28
28
|
node_path = __toESM(node_path, 1);
|
|
29
|
-
let
|
|
30
|
-
let
|
|
29
|
+
let kubb_kit = require("kubb/kit");
|
|
30
|
+
let kubb_jsx = require("kubb/jsx");
|
|
31
31
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
32
|
-
let
|
|
32
|
+
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
33
33
|
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
34
|
-
let _kubb_ast_utils = require("@kubb/ast/utils");
|
|
35
|
-
let _kubb_ast_macros = require("@kubb/ast/macros");
|
|
36
34
|
let node_url = require("node:url");
|
|
37
35
|
//#region ../../internals/utils/src/casing.ts
|
|
38
36
|
/**
|
|
@@ -369,6 +367,34 @@ function dedupeByCasedName(params) {
|
|
|
369
367
|
return true;
|
|
370
368
|
});
|
|
371
369
|
}
|
|
370
|
+
function buildParamsMapping(originalParams, mappedParams) {
|
|
371
|
+
const mapping = {};
|
|
372
|
+
let hasChanged = false;
|
|
373
|
+
originalParams.forEach((param, i) => {
|
|
374
|
+
const mappedName = mappedParams[i]?.name ?? param.name;
|
|
375
|
+
mapping[param.name] = mappedName;
|
|
376
|
+
if (param.name !== mappedName) hasChanged = true;
|
|
377
|
+
});
|
|
378
|
+
return hasChanged ? mapping : null;
|
|
379
|
+
}
|
|
380
|
+
function toAccess(object, name) {
|
|
381
|
+
return isValidVarName(name) ? `${object}.${name}` : `${object}[${JSON.stringify(name)}]`;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Renders the object-literal expression that renames the camelCased keys of a grouped request
|
|
385
|
+
* option back to the names the OpenAPI document declares, guarded so an omitted optional group
|
|
386
|
+
* stays omitted. Shared by the client and cypress generators, which pass a `buildParamsMapping`
|
|
387
|
+
* result and the source expression to read the keys from.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* buildParamsRemapExpression({ source: 'config.query', mapping: { include_deleted: 'includeDeleted' } })
|
|
392
|
+
* // 'config.query ? { "include_deleted": config.query.includeDeleted } : config.query'
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
function buildParamsRemapExpression({ source, mapping }) {
|
|
396
|
+
return `${source} ? { ${Object.entries(mapping).map(([originalName, casedName]) => `${JSON.stringify(originalName)}: ${toAccess(source, casedName)}`).join(", ")} } : ${source}`;
|
|
397
|
+
}
|
|
372
398
|
//#endregion
|
|
373
399
|
//#region ../../internals/shared/src/operation.ts
|
|
374
400
|
/**
|
|
@@ -690,6 +716,38 @@ function buildSecurityMetadata({ security }) {
|
|
|
690
716
|
return `[${security.map(serializeAuth).join(", ")}]`;
|
|
691
717
|
}
|
|
692
718
|
//#endregion
|
|
719
|
+
//#region ../../internals/client/src/builders/paramsRemap.ts
|
|
720
|
+
/**
|
|
721
|
+
* Builds the call-config entries that rename the camelCased `query` and `headers` keys back to the
|
|
722
|
+
* names the OpenAPI document declares, so the wire format follows the spec while the generated
|
|
723
|
+
* types keep camelCase keys. Returns an empty array when no name changes. Path parameters need no
|
|
724
|
+
* remap because the URL template placeholders are renamed in sync with the `path` keys. Emit the
|
|
725
|
+
* entries after the `...config` spread so they override the camelCased groups the caller passes in.
|
|
726
|
+
*
|
|
727
|
+
* @example
|
|
728
|
+
* ```ts
|
|
729
|
+
* // a query param named include_deleted in the spec
|
|
730
|
+
* buildParamsRemap({ node }) // ['query: config.query ? { "include_deleted": config.query.includeDeleted } : config.query']
|
|
731
|
+
* ```
|
|
732
|
+
*/
|
|
733
|
+
function buildParamsRemap({ node }) {
|
|
734
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return [];
|
|
735
|
+
const original = getOperationParameters(node, { paramsCasing: "original" });
|
|
736
|
+
const cased = getOperationParameters(node);
|
|
737
|
+
const queryMapping = buildParamsMapping(original.query, cased.query);
|
|
738
|
+
const headerMapping = buildParamsMapping(original.header, cased.header);
|
|
739
|
+
const entries = [];
|
|
740
|
+
if (queryMapping) entries.push(`query: ${buildParamsRemapExpression({
|
|
741
|
+
source: "config.query",
|
|
742
|
+
mapping: queryMapping
|
|
743
|
+
})}`);
|
|
744
|
+
if (headerMapping) entries.push(`headers: ${buildParamsRemapExpression({
|
|
745
|
+
source: "config.headers",
|
|
746
|
+
mapping: headerMapping
|
|
747
|
+
})}`);
|
|
748
|
+
return entries;
|
|
749
|
+
}
|
|
750
|
+
//#endregion
|
|
693
751
|
//#region ../../internals/client/src/builders/generics.ts
|
|
694
752
|
/**
|
|
695
753
|
* Builds the `RequestResult` generic arguments for one operation: the plugin-ts per-status responses
|
|
@@ -752,12 +810,13 @@ function buildGroupedOptionsSignature({ node, tsResolver }) {
|
|
|
752
810
|
//#endregion
|
|
753
811
|
//#region ../../internals/client/src/builders/styles.ts
|
|
754
812
|
/**
|
|
755
|
-
* Renders a parameter name as an object-literal key,
|
|
756
|
-
*
|
|
813
|
+
* Renders a parameter name as an object-literal key, quoted when it is not a bare identifier.
|
|
814
|
+
* Path keys are camelCased to match the URL template placeholders. Query, header, and cookie keys
|
|
815
|
+
* keep the spec name, matching the remapped keys the runtime serializes.
|
|
757
816
|
*/
|
|
758
|
-
function toKey(name) {
|
|
759
|
-
const
|
|
760
|
-
return isValidVarName(
|
|
817
|
+
function toKey(name, location) {
|
|
818
|
+
const key = location === "path" ? camelCase(name) : name;
|
|
819
|
+
return isValidVarName(key) ? key : JSON.stringify(key);
|
|
761
820
|
}
|
|
762
821
|
/**
|
|
763
822
|
* Serializes one parameter's metadata into a `{ style, explode }` literal, or `null` when the
|
|
@@ -771,8 +830,9 @@ function serializeParameter(parameter) {
|
|
|
771
830
|
return parts.length > 0 ? `{ ${parts.join(", ")} }` : null;
|
|
772
831
|
}
|
|
773
832
|
/**
|
|
774
|
-
* Builds the per-operation `styles` literal from the operation's parameters, grouped by location
|
|
775
|
-
* keyed by the camelCased
|
|
833
|
+
* Builds the per-operation `styles` literal from the operation's parameters, grouped by location.
|
|
834
|
+
* Path entries are keyed by the camelCased name to match the URL template placeholders; query,
|
|
835
|
+
* header, and cookie entries keep the spec name to match the keys the runtime serializes.
|
|
776
836
|
* Only parameters whose source defines `style` or `explode` are emitted, so calls without
|
|
777
837
|
* serialization metadata keep the runtime defaults and existing output is unchanged. Returns `null`
|
|
778
838
|
* when no parameter carries metadata.
|
|
@@ -784,7 +844,7 @@ function serializeParameter(parameter) {
|
|
|
784
844
|
* ```
|
|
785
845
|
*/
|
|
786
846
|
function buildStyles({ node }) {
|
|
787
|
-
if (!
|
|
847
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
788
848
|
const groups = {
|
|
789
849
|
path: [],
|
|
790
850
|
query: [],
|
|
@@ -794,7 +854,7 @@ function buildStyles({ node }) {
|
|
|
794
854
|
for (const parameter of node.parameters) {
|
|
795
855
|
const literal = serializeParameter(parameter);
|
|
796
856
|
if (!literal) continue;
|
|
797
|
-
groups[parameter.in].push(`${toKey(parameter.name)}: ${literal}`);
|
|
857
|
+
groups[parameter.in].push(`${toKey(parameter.name, parameter.in)}: ${literal}`);
|
|
798
858
|
}
|
|
799
859
|
const locations = Object.keys(groups).filter((location) => groups[location].length > 0);
|
|
800
860
|
if (locations.length === 0) return null;
|
|
@@ -834,7 +894,7 @@ function buildValidatorHooks({ node, validator, zodResolver }) {
|
|
|
834
894
|
* and call config are built with the AST factory, and only the jsx-renderer emits the source.
|
|
835
895
|
*/
|
|
836
896
|
function Operation({ name, node, tsResolver, zodResolver, validator, security, isExportable = true, isIndexable = true }) {
|
|
837
|
-
if (!
|
|
897
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
838
898
|
const signature = buildGroupedOptionsSignature({
|
|
839
899
|
node,
|
|
840
900
|
tsResolver
|
|
@@ -867,7 +927,8 @@ function Operation({ name, node, tsResolver, zodResolver, validator, security, i
|
|
|
867
927
|
validatorLiteral,
|
|
868
928
|
contentTypeLiteral,
|
|
869
929
|
responseTypeLiteral,
|
|
870
|
-
"...config"
|
|
930
|
+
"...config",
|
|
931
|
+
...buildParamsRemap({ node })
|
|
871
932
|
].filter(Boolean).join(", ")} }`;
|
|
872
933
|
const eventType = `SuccessOf<${tsResolver.resolveResponsesName(node)}>`;
|
|
873
934
|
const returnType = eventStream ? `Promise<EventStreamResult<${eventType}>>` : signature.returnType;
|
|
@@ -876,11 +937,11 @@ function Operation({ name, node, tsResolver, zodResolver, validator, security, i
|
|
|
876
937
|
tsResolver,
|
|
877
938
|
callConfig
|
|
878
939
|
});
|
|
879
|
-
return /* @__PURE__ */ (0,
|
|
940
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
880
941
|
name,
|
|
881
942
|
isExportable,
|
|
882
943
|
isIndexable,
|
|
883
|
-
children: /* @__PURE__ */ (0,
|
|
944
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.Function, {
|
|
884
945
|
name,
|
|
885
946
|
export: isExportable,
|
|
886
947
|
generics: signature.generics,
|
|
@@ -893,7 +954,7 @@ function Operation({ name, node, tsResolver, zodResolver, validator, security, i
|
|
|
893
954
|
}) },
|
|
894
955
|
children: [
|
|
895
956
|
mergeContentType ? "const { client: request = client, contentType, ...config } = options" : "const { client: request = client, ...config } = options",
|
|
896
|
-
/* @__PURE__ */ (0,
|
|
957
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)("br", {}),
|
|
897
958
|
returnStatement
|
|
898
959
|
]
|
|
899
960
|
})
|
|
@@ -920,7 +981,8 @@ function buildCallConfig({ node, validator, zodResolver, security }) {
|
|
|
920
981
|
`url: '${Url.toCasedTemplate(node.path, { casing: "camelcase" })}'`,
|
|
921
982
|
securityLiteral ? `security: ${securityLiteral}` : null,
|
|
922
983
|
validatorLiteral,
|
|
923
|
-
"...config"
|
|
984
|
+
"...config",
|
|
985
|
+
...buildParamsRemap({ node })
|
|
924
986
|
].filter(Boolean).join(", ")} }`;
|
|
925
987
|
}
|
|
926
988
|
/**
|
|
@@ -930,7 +992,7 @@ function buildCallConfig({ node, validator, zodResolver, security }) {
|
|
|
930
992
|
* one operation can be routed to a different environment without a new instance.
|
|
931
993
|
*/
|
|
932
994
|
function buildSdkMethod({ node, name, tsResolver, zodResolver, validator, security }) {
|
|
933
|
-
if (!
|
|
995
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return "";
|
|
934
996
|
const signature = buildGroupedOptionsSignature({
|
|
935
997
|
node,
|
|
936
998
|
tsResolver
|
|
@@ -946,7 +1008,7 @@ function buildSdkMethod({ node, name, tsResolver, zodResolver, validator, securi
|
|
|
946
1008
|
})
|
|
947
1009
|
});
|
|
948
1010
|
const generics = signature.generics.length ? `<${signature.generics.join(", ")}>` : "";
|
|
949
|
-
const jsdoc =
|
|
1011
|
+
const jsdoc = kubb_kit.ast.buildJSDoc(buildOperationComments(node, {
|
|
950
1012
|
link: "urlPath",
|
|
951
1013
|
linkPosition: "beforeDeprecated",
|
|
952
1014
|
splitLines: true
|
|
@@ -982,7 +1044,7 @@ function SdkClient({ name, isExportable = true, isIndexable = true, operations,
|
|
|
982
1044
|
" this.client = createClient(config)",
|
|
983
1045
|
" }"
|
|
984
1046
|
].join("\n")}\n\n${methods.join("\n\n")}\n}`;
|
|
985
|
-
return /* @__PURE__ */ (0,
|
|
1047
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File.Source, {
|
|
986
1048
|
name,
|
|
987
1049
|
isExportable,
|
|
988
1050
|
isIndexable,
|
|
@@ -1006,7 +1068,7 @@ function SdkFacade({ name, isExportable = true, isIndexable = true, members, chi
|
|
|
1006
1068
|
...assignments,
|
|
1007
1069
|
" }"
|
|
1008
1070
|
].join("\n")}\n}`;
|
|
1009
|
-
return /* @__PURE__ */ (0,
|
|
1071
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File.Source, {
|
|
1010
1072
|
name,
|
|
1011
1073
|
isExportable,
|
|
1012
1074
|
isIndexable,
|
|
@@ -1051,7 +1113,7 @@ function buildControllers(nodes, ctx) {
|
|
|
1051
1113
|
output: pluginZod.options?.output ?? output,
|
|
1052
1114
|
group: pluginZod.options?.group ?? void 0
|
|
1053
1115
|
}) : null;
|
|
1054
|
-
const security =
|
|
1116
|
+
const security = kubb_kit.ast.isHttpOperationNode(node) ? getOperationSecurity({
|
|
1055
1117
|
document,
|
|
1056
1118
|
method: node.method,
|
|
1057
1119
|
path: node.path
|
|
@@ -1067,7 +1129,7 @@ function buildControllers(nodes, ctx) {
|
|
|
1067
1129
|
};
|
|
1068
1130
|
}
|
|
1069
1131
|
return nodes.reduce((acc, operationNode) => {
|
|
1070
|
-
if (!
|
|
1132
|
+
if (!kubb_kit.ast.isHttpOperationNode(operationNode)) return acc;
|
|
1071
1133
|
const tag = operationNode.tags[0];
|
|
1072
1134
|
const name = tag ? group?.name?.({ group: camelCase(tag) }) ?? resolver.resolveGroupName(tag) : resolver.resolveClassName("ApiClient");
|
|
1073
1135
|
const file = resolver.resolveFile({
|
|
@@ -1119,9 +1181,9 @@ function collectImportsByFile(ops, pick) {
|
|
|
1119
1181
|
* direct method.
|
|
1120
1182
|
*/
|
|
1121
1183
|
function createSdkGenerator() {
|
|
1122
|
-
return (0,
|
|
1184
|
+
return (0, kubb_kit.defineGenerator)({
|
|
1123
1185
|
name: "sdk",
|
|
1124
|
-
renderer:
|
|
1186
|
+
renderer: kubb_jsx.jsxRenderer,
|
|
1125
1187
|
operations(nodes, ctx) {
|
|
1126
1188
|
const { config, resolver, root } = ctx;
|
|
1127
1189
|
const { output, group, validator, sdk } = ctx.options;
|
|
@@ -1156,19 +1218,19 @@ function createSdkGenerator() {
|
|
|
1156
1218
|
namesByPath: /* @__PURE__ */ new Map(),
|
|
1157
1219
|
filesByPath: /* @__PURE__ */ new Map()
|
|
1158
1220
|
};
|
|
1159
|
-
return /* @__PURE__ */ (0,
|
|
1221
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
1160
1222
|
baseName: file.baseName,
|
|
1161
1223
|
path: file.path,
|
|
1162
1224
|
meta: file.meta,
|
|
1163
1225
|
banner: banner(file),
|
|
1164
1226
|
footer: footer(file),
|
|
1165
1227
|
children: [
|
|
1166
|
-
/* @__PURE__ */ (0,
|
|
1228
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1167
1229
|
name: ["createClient"],
|
|
1168
1230
|
root: file.path,
|
|
1169
1231
|
path: clientPath
|
|
1170
1232
|
}),
|
|
1171
|
-
/* @__PURE__ */ (0,
|
|
1233
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1172
1234
|
name: [
|
|
1173
1235
|
"ClientConfig",
|
|
1174
1236
|
"ClientInstance",
|
|
@@ -1179,23 +1241,23 @@ function createSdkGenerator() {
|
|
|
1179
1241
|
path: clientPath,
|
|
1180
1242
|
isTypeOnly: true
|
|
1181
1243
|
}),
|
|
1182
|
-
validator === "zod" && ops.some((op) => op.node.requestBody?.content?.[0]?.schema != null) && /* @__PURE__ */ (0,
|
|
1244
|
+
validator === "zod" && ops.some((op) => op.node.requestBody?.content?.[0]?.schema != null) && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1183
1245
|
name: ["z"],
|
|
1184
1246
|
path: "zod",
|
|
1185
1247
|
isTypeOnly: true
|
|
1186
1248
|
}),
|
|
1187
|
-
Array.from(typeNamesByPath.entries()).map(([filePath, set]) => /* @__PURE__ */ (0,
|
|
1249
|
+
Array.from(typeNamesByPath.entries()).map(([filePath, set]) => /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1188
1250
|
name: Array.from(set),
|
|
1189
1251
|
root: file.path,
|
|
1190
1252
|
path: typeFilesByPath.get(filePath).path,
|
|
1191
1253
|
isTypeOnly: true
|
|
1192
1254
|
}, filePath)),
|
|
1193
|
-
isValidatorEnabled(validator) && Array.from(zodNamesByPath.entries()).map(([filePath, set]) => /* @__PURE__ */ (0,
|
|
1255
|
+
isValidatorEnabled(validator) && Array.from(zodNamesByPath.entries()).map(([filePath, set]) => /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1194
1256
|
name: Array.from(set),
|
|
1195
1257
|
root: file.path,
|
|
1196
1258
|
path: zodFilesByPath.get(filePath).path
|
|
1197
1259
|
}, filePath)),
|
|
1198
|
-
/* @__PURE__ */ (0,
|
|
1260
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(SdkClient, {
|
|
1199
1261
|
name: className,
|
|
1200
1262
|
operations: ops,
|
|
1201
1263
|
validator
|
|
@@ -1212,7 +1274,7 @@ function createSdkGenerator() {
|
|
|
1212
1274
|
group: group ?? void 0
|
|
1213
1275
|
}), controllers.flatMap((controller) => controller.operations));
|
|
1214
1276
|
const classFiles = controllers.map(({ name, file, operations: ops }) => renderClassFile(name, file, ops));
|
|
1215
|
-
if (!sdk.name) return /* @__PURE__ */ (0,
|
|
1277
|
+
if (!sdk.name) return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx_jsx_runtime.Fragment, { children: classFiles });
|
|
1216
1278
|
const sdkFile = resolver.resolveFile({
|
|
1217
1279
|
name: sdk.name,
|
|
1218
1280
|
extname: ".ts"
|
|
@@ -1226,25 +1288,25 @@ function createSdkGenerator() {
|
|
|
1226
1288
|
className: name,
|
|
1227
1289
|
propName: resolver.resolveClientPropertyName(tag ?? name)
|
|
1228
1290
|
}));
|
|
1229
|
-
return /* @__PURE__ */ (0,
|
|
1291
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [classFiles, /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
1230
1292
|
baseName: sdkFile.baseName,
|
|
1231
1293
|
path: sdkFile.path,
|
|
1232
1294
|
meta: sdkFile.meta,
|
|
1233
1295
|
banner: banner(sdkFile),
|
|
1234
1296
|
footer: footer(sdkFile),
|
|
1235
1297
|
children: [
|
|
1236
|
-
/* @__PURE__ */ (0,
|
|
1298
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1237
1299
|
name: ["ClientConfig"],
|
|
1238
1300
|
root: sdkFile.path,
|
|
1239
1301
|
path: clientPath,
|
|
1240
1302
|
isTypeOnly: true
|
|
1241
1303
|
}),
|
|
1242
|
-
controllers.map(({ name, file }) => /* @__PURE__ */ (0,
|
|
1304
|
+
controllers.map(({ name, file }) => /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1243
1305
|
name: [name],
|
|
1244
1306
|
root: sdkFile.path,
|
|
1245
1307
|
path: file.path
|
|
1246
1308
|
}, name)),
|
|
1247
|
-
/* @__PURE__ */ (0,
|
|
1309
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(SdkFacade, {
|
|
1248
1310
|
name: facadeName,
|
|
1249
1311
|
members
|
|
1250
1312
|
})
|
|
@@ -1260,7 +1322,7 @@ function createSdkGenerator() {
|
|
|
1260
1322
|
* drops union members a broader scalar already covers, keeping the generated response and error
|
|
1261
1323
|
* unions tidy. A plugin wires them with `ctx.setMacros([...defaultMacros, ...userMacros])`.
|
|
1262
1324
|
*/
|
|
1263
|
-
const defaultMacros = [
|
|
1325
|
+
const defaultMacros = [kubb_kit.ast.macroSimplifyUnion];
|
|
1264
1326
|
//#endregion
|
|
1265
1327
|
//#region ../../internals/client/src/resolver.ts
|
|
1266
1328
|
/**
|
|
@@ -1273,7 +1335,7 @@ const defaultMacros = [_kubb_ast_macros.macroSimplifyUnion];
|
|
|
1273
1335
|
* resolverClient.resolveGroupName('pet') // 'PetClient'
|
|
1274
1336
|
* ```
|
|
1275
1337
|
*/
|
|
1276
|
-
const resolverClient = (0,
|
|
1338
|
+
const resolverClient = (0, kubb_kit.defineResolver)(() => ({
|
|
1277
1339
|
name: "default",
|
|
1278
1340
|
pluginName: "plugin-contract-client",
|
|
1279
1341
|
default(name, type) {
|
|
@@ -1303,11 +1365,11 @@ const resolverClient = (0, _kubb_core.defineResolver)(() => ({
|
|
|
1303
1365
|
* operation using the shared `Operation` component: a grouped `<Name>Request` type and a function that
|
|
1304
1366
|
* forwards a single `options` object to the bundled `client` and returns the `RequestResult`.
|
|
1305
1367
|
*/
|
|
1306
|
-
const clientGenerator = (0,
|
|
1368
|
+
const clientGenerator = (0, kubb_kit.defineGenerator)({
|
|
1307
1369
|
name: "fetch",
|
|
1308
|
-
renderer:
|
|
1370
|
+
renderer: kubb_jsx.jsxRenderer,
|
|
1309
1371
|
operation(node, ctx) {
|
|
1310
|
-
if (!
|
|
1372
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1311
1373
|
const { config, driver, resolver, root } = ctx;
|
|
1312
1374
|
const { output, validator, group } = ctx.options;
|
|
1313
1375
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
@@ -1347,7 +1409,7 @@ const clientGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1347
1409
|
});
|
|
1348
1410
|
const clientPath = node_path.default.resolve(root, ".kubb/client.ts");
|
|
1349
1411
|
const eventStream = isEventStream(node);
|
|
1350
|
-
return /* @__PURE__ */ (0,
|
|
1412
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
1351
1413
|
baseName: meta.file.baseName,
|
|
1352
1414
|
path: meta.file.path,
|
|
1353
1415
|
meta: meta.file.meta,
|
|
@@ -1368,12 +1430,12 @@ const clientGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1368
1430
|
}
|
|
1369
1431
|
}),
|
|
1370
1432
|
children: [
|
|
1371
|
-
/* @__PURE__ */ (0,
|
|
1433
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1372
1434
|
name: eventStream ? ["client", "toEventStream"] : ["client"],
|
|
1373
1435
|
root: meta.file.path,
|
|
1374
1436
|
path: clientPath
|
|
1375
1437
|
}),
|
|
1376
|
-
/* @__PURE__ */ (0,
|
|
1438
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1377
1439
|
name: eventStream ? [
|
|
1378
1440
|
"Options",
|
|
1379
1441
|
"EventStreamResult",
|
|
@@ -1383,18 +1445,18 @@ const clientGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1383
1445
|
path: clientPath,
|
|
1384
1446
|
isTypeOnly: true
|
|
1385
1447
|
}),
|
|
1386
|
-
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0,
|
|
1448
|
+
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1387
1449
|
name: Array.from(new Set(importedTypeNames)),
|
|
1388
1450
|
root: meta.file.path,
|
|
1389
1451
|
path: meta.fileTs.path,
|
|
1390
1452
|
isTypeOnly: true
|
|
1391
1453
|
}),
|
|
1392
|
-
meta.fileZod && importedZodNames.length > 0 && /* @__PURE__ */ (0,
|
|
1454
|
+
meta.fileZod && importedZodNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1393
1455
|
name: importedZodNames,
|
|
1394
1456
|
root: meta.file.path,
|
|
1395
1457
|
path: meta.fileZod.path
|
|
1396
1458
|
}),
|
|
1397
|
-
/* @__PURE__ */ (0,
|
|
1459
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Operation, {
|
|
1398
1460
|
name: meta.name,
|
|
1399
1461
|
node,
|
|
1400
1462
|
tsResolver,
|
|
@@ -1432,7 +1494,7 @@ const pluginFetchName = "plugin-fetch";
|
|
|
1432
1494
|
*
|
|
1433
1495
|
* @example
|
|
1434
1496
|
* ```ts
|
|
1435
|
-
* import { defineConfig } from 'kubb'
|
|
1497
|
+
* import { defineConfig } from 'kubb/config'
|
|
1436
1498
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
1437
1499
|
* import { pluginFetch } from '@kubb/plugin-fetch'
|
|
1438
1500
|
*
|
|
@@ -1446,7 +1508,7 @@ const pluginFetchName = "plugin-fetch";
|
|
|
1446
1508
|
* })
|
|
1447
1509
|
* ```
|
|
1448
1510
|
*/
|
|
1449
|
-
const pluginFetch = (0,
|
|
1511
|
+
const pluginFetch = (0, kubb_kit.definePlugin)((options) => {
|
|
1450
1512
|
const { output = {
|
|
1451
1513
|
path: "clients",
|
|
1452
1514
|
barrel: { type: "named" }
|