@kubb/plugin-fetch 5.5.2 → 5.5.3
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 +40 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +40 -16
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -27,8 +27,10 @@ type Mode = 'tag' | 'flat';
|
|
|
27
27
|
* - `'full'`: the complete `{ status, data, error, contentType, request, response }` result.
|
|
28
28
|
* - `'data'`: the bare success body when `throwOnError` is true, or the full result when it is false
|
|
29
29
|
* so callers can inspect `error`.
|
|
30
|
+
* - `'plain'`: the client's own promise typed as `RequestResult`, with no `withUnwrap` / `unwrapResult`
|
|
31
|
+
* helper. Backs `@kubb/plugin-client`.
|
|
30
32
|
*/
|
|
31
|
-
type ReturnTypeOption = 'full' | 'data';
|
|
33
|
+
type ReturnTypeOption = 'full' | 'data' | 'plain';
|
|
32
34
|
/**
|
|
33
35
|
* The resolver shared by the client plugins. Inherits the built-in camelCase `name` and `file`;
|
|
34
36
|
* classes and tag groups use PascalCase (with a `Client` suffix for groups).
|
package/dist/index.js
CHANGED
|
@@ -452,7 +452,8 @@ function buildRequestResultGenerics({ node, types }) {
|
|
|
452
452
|
}
|
|
453
453
|
/**
|
|
454
454
|
* Builds the full return type an operation's function signature uses: `Unwrappable<RequestResult>`
|
|
455
|
-
* for the default `returnType: 'full'`, already a promise so no further wrapping is needed,
|
|
455
|
+
* for the default `returnType: 'full'`, already a promise so no further wrapping is needed, a plain
|
|
456
|
+
* `Promise<RequestResult>` for the internal `'plain'` shape, or a
|
|
456
457
|
* `Promise` of the runtime's `UnwrappedResult` when `returnType: 'data'` narrows a resolved call
|
|
457
458
|
* down to the bare success body.
|
|
458
459
|
*
|
|
@@ -464,7 +465,9 @@ function buildResultType({ node, types, returnType }) {
|
|
|
464
465
|
node,
|
|
465
466
|
types
|
|
466
467
|
});
|
|
467
|
-
|
|
468
|
+
if (returnType === "data") return `Promise<UnwrappedResult<${generics}>>`;
|
|
469
|
+
if (returnType === "plain") return `Promise<RequestResult<${generics}>>`;
|
|
470
|
+
return `Unwrappable<RequestResult<${generics}>>`;
|
|
468
471
|
}
|
|
469
472
|
//#endregion
|
|
470
473
|
//#region ../../internals/client/src/builders/returnStatement.ts
|
|
@@ -476,6 +479,7 @@ function buildResultType({ node, types, returnType }) {
|
|
|
476
479
|
* body. With `returnType: 'data'` it instead routes the call through the runtime's `unwrapResult`,
|
|
477
480
|
* which narrows the resolved value down to the bare success body the same way `RequestResult`
|
|
478
481
|
* already does, using the plugin default when the call leaves `throwOnError` unset.
|
|
482
|
+
* With `returnType: 'plain'` it returns the runtime call as is, cast to `RequestResult`, with no helper.
|
|
479
483
|
*
|
|
480
484
|
* Cast first, wrap second, for the `'full'` path. That order keeps `withUnwrap`'s generic inferred
|
|
481
485
|
* as `RequestResult` instead of the runtime's own internal result type. Casting an `Unwrappable<A>`
|
|
@@ -486,6 +490,8 @@ function buildResultType({ node, types, returnType }) {
|
|
|
486
490
|
* `return withUnwrap(request({ method: 'POST', url: '/pet', ...config }) as Promise<RequestResult<AddPetResponses, ThrowOnError>>)`
|
|
487
491
|
* @example
|
|
488
492
|
* `return unwrapResult(request({ method: 'POST', url: '/pet', ...config }), config.throwOnError ?? false) as Promise<UnwrappedResult<AddPetResponses, ThrowOnError>>`
|
|
493
|
+
* @example
|
|
494
|
+
* `return request({ method: 'POST', url: '/pet', ...config }) as Promise<RequestResult<AddPetResponses, ThrowOnError>>`
|
|
489
495
|
*/
|
|
490
496
|
function buildReturnStatement({ node, types, callConfig, returnType, throwOnErrorDefault }) {
|
|
491
497
|
if (returnType === "data") return `return unwrapResult(request(${callConfig}), config.throwOnError ?? ${throwOnErrorDefault}) as ${buildResultType({
|
|
@@ -493,6 +499,10 @@ function buildReturnStatement({ node, types, callConfig, returnType, throwOnErro
|
|
|
493
499
|
types,
|
|
494
500
|
returnType
|
|
495
501
|
})}`;
|
|
502
|
+
if (returnType === "plain") return `return request(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
|
|
503
|
+
node,
|
|
504
|
+
types
|
|
505
|
+
})}>>`;
|
|
496
506
|
return `return withUnwrap(request(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
|
|
497
507
|
node,
|
|
498
508
|
types
|
|
@@ -970,7 +980,7 @@ function resolveOperationTypes(driver) {
|
|
|
970
980
|
* generator `name` differs between plugins. Every other resolution, import, and rendering step is
|
|
971
981
|
* identical.
|
|
972
982
|
*/
|
|
973
|
-
function createClientGenerator(name) {
|
|
983
|
+
function createClientGenerator(name, resolveClientPath) {
|
|
974
984
|
return defineGenerator({
|
|
975
985
|
name,
|
|
976
986
|
renderer: jsxRenderer,
|
|
@@ -1020,8 +1030,30 @@ function createClientGenerator(name) {
|
|
|
1020
1030
|
method: node.method,
|
|
1021
1031
|
path: node.path
|
|
1022
1032
|
});
|
|
1023
|
-
const
|
|
1033
|
+
const customClientPath = resolveClientPath?.(ctx.options, root);
|
|
1034
|
+
const clientPath = customClientPath ?? path.resolve(root, ".kubb/client.ts");
|
|
1035
|
+
const clientRoot = customClientPath === void 0 ? meta.file.path : void 0;
|
|
1024
1036
|
const eventStream = isEventStream(node);
|
|
1037
|
+
const clientValueImports = (() => {
|
|
1038
|
+
if (eventStream) return ["client", "toEventStream"];
|
|
1039
|
+
if (returnType === "plain") return ["client"];
|
|
1040
|
+
if (returnType === "data") return ["client", "unwrapResult"];
|
|
1041
|
+
return ["client", "withUnwrap"];
|
|
1042
|
+
})();
|
|
1043
|
+
const clientTypeImports = (() => {
|
|
1044
|
+
if (eventStream) return [
|
|
1045
|
+
"Options",
|
|
1046
|
+
"EventStreamResult",
|
|
1047
|
+
"SuccessOf"
|
|
1048
|
+
];
|
|
1049
|
+
if (returnType === "plain") return ["Options", "RequestResult"];
|
|
1050
|
+
if (returnType === "data") return ["Options", "UnwrappedResult"];
|
|
1051
|
+
return [
|
|
1052
|
+
"Options",
|
|
1053
|
+
"Unwrappable",
|
|
1054
|
+
"RequestResult"
|
|
1055
|
+
];
|
|
1056
|
+
})();
|
|
1025
1057
|
return /* @__PURE__ */ jsxs(File, {
|
|
1026
1058
|
baseName: meta.file.baseName,
|
|
1027
1059
|
path: meta.file.path,
|
|
@@ -1044,21 +1076,13 @@ function createClientGenerator(name) {
|
|
|
1044
1076
|
}),
|
|
1045
1077
|
children: [
|
|
1046
1078
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1047
|
-
name:
|
|
1048
|
-
root:
|
|
1079
|
+
name: clientValueImports,
|
|
1080
|
+
root: clientRoot,
|
|
1049
1081
|
path: clientPath
|
|
1050
1082
|
}),
|
|
1051
1083
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1052
|
-
name:
|
|
1053
|
-
|
|
1054
|
-
"EventStreamResult",
|
|
1055
|
-
"SuccessOf"
|
|
1056
|
-
] : returnType === "data" ? ["Options", "UnwrappedResult"] : [
|
|
1057
|
-
"Options",
|
|
1058
|
-
"Unwrappable",
|
|
1059
|
-
"RequestResult"
|
|
1060
|
-
],
|
|
1061
|
-
root: meta.file.path,
|
|
1084
|
+
name: clientTypeImports,
|
|
1085
|
+
root: clientRoot,
|
|
1062
1086
|
path: clientPath,
|
|
1063
1087
|
isTypeOnly: true
|
|
1064
1088
|
}),
|