@kubb/plugin-fetch 5.2.0-canary.20260902T141305 → 5.2.1

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 CHANGED
@@ -480,17 +480,23 @@ function buildRequestResultGenerics({ node, types }) {
480
480
  //#region ../../internals/client/src/builders/returnStatement.ts
481
481
  /**
482
482
  * Builds the return statement of a generated operation function. The runtime call already resolves
483
- * to `{ data, error, request, response }`; the generated code forwards that result and casts it to
484
- * the operation's `RequestResult`, which carries the `throwOnError` discrimination.
483
+ * to `{ data, error, request, response }`. The generated code casts that result to the operation's
484
+ * `RequestResult`, then wraps it with `withUnwrap`, so the caller can `await` it directly or call
485
+ * `.unwrap()` for the bare success body.
486
+ *
487
+ * Cast first, wrap second. That order keeps `withUnwrap`'s generic inferred as `RequestResult`
488
+ * instead of the runtime's own internal result type. Casting an `Unwrappable<A>` straight to
489
+ * `Unwrappable<B>` does not work: the `.then` overload stays pinned to `A`, and `as` rejects that
490
+ * two-generic swap even where `A` and `B` on their own would satisfy it.
485
491
  *
486
492
  * @example
487
- * `return request({ method: 'POST', url: '/pet', ...config }) as Promise<RequestResult<AddPetResponses, ThrowOnError>>`
493
+ * `return withUnwrap(request({ method: 'POST', url: '/pet', ...config }) as Promise<RequestResult<AddPetResponses, ThrowOnError>>)`
488
494
  */
489
495
  function buildReturnStatement({ node, types, callConfig }) {
490
- return `return request(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
496
+ return `return withUnwrap(request(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
491
497
  node,
492
498
  types
493
- })}>>`;
499
+ })}>>)`;
494
500
  }
495
501
  //#endregion
496
502
  //#region ../../internals/client/src/builders/security.ts
@@ -574,10 +580,6 @@ const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declara
574
580
  */
575
581
  function buildGroupedOptionsSignature({ node, types }) {
576
582
  const optionsName = types.response.options(node);
577
- const resultGenerics = buildRequestResultGenerics({
578
- node,
579
- types
580
- });
581
583
  const { isOptional } = getRequestGroupOptionality(node);
582
584
  return {
583
585
  paramsSignature: declarationPrinter.print((0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
@@ -585,7 +587,10 @@ function buildGroupedOptionsSignature({ node, types }) {
585
587
  type: `Options<${optionsName}, ThrowOnError>`,
586
588
  ...isOptional ? { default: "{}" } : {}
587
589
  })] })) ?? "",
588
- returnType: `Promise<RequestResult<${resultGenerics}>>`,
590
+ returnType: `Unwrappable<RequestResult<${buildRequestResultGenerics({
591
+ node,
592
+ types
593
+ })}>>`,
589
594
  generics: ["ThrowOnError extends boolean = true"]
590
595
  };
591
596
  }
@@ -702,8 +707,9 @@ function buildCallConfig({ node, validator, zodResolver, security }) {
702
707
  /**
703
708
  * Builds a single instance method for a generated SDK class. The body forwards the single grouped
704
709
  * `options` object to the instance's own client (`this.client`, built once in the constructor) and
705
- * returns the `RequestResult`. A per-call `options.client` still overrides the instance client, so
706
- * one operation can be routed to a different environment without a new instance.
710
+ * returns the `Unwrappable<RequestResult>`. A per-call `options.client` still overrides the
711
+ * instance client, so one operation can be routed to a different environment without a new
712
+ * instance.
707
713
  */
708
714
  function buildSdkMethod({ node, name, types, zodResolver, validator, security }) {
709
715
  if (!kubb_kit.ast.isHttpOperationNode(node)) return "";
@@ -791,8 +797,9 @@ function buildStyles({ node }) {
791
797
  //#region ../../internals/client/src/components/Operation.tsx
792
798
  /**
793
799
  * Renders one client operation: the grouped `<Name>Request` type and the function that forwards a
794
- * single `options` object to the resolved client and returns the `RequestResult`. The type, signature,
795
- * and call config are built with the AST factory, and only the jsx-renderer emits the source.
800
+ * single `options` object to the resolved client and returns the `Unwrappable<RequestResult>`. The
801
+ * type, signature, and call config are built with the AST factory, and only the jsx-renderer emits
802
+ * the source.
796
803
  */
797
804
  function Operation({ name, node, types, zodResolver, validator, security, isExportable = true, isIndexable = true }) {
798
805
  if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
@@ -944,8 +951,9 @@ function resolveOperationTypes(driver) {
944
951
  * Builds the built-in per-operation generator shared by the client plugins (`@kubb/plugin-fetch`,
945
952
  * `@kubb/plugin-axios`). Emits one async function per OpenAPI operation using the shared
946
953
  * `Operation` component: a grouped `<Name>Request` type and a function that forwards a single
947
- * `options` object to the bundled `client` and returns the `RequestResult`. Only the generator
948
- * `name` differs between plugins; every other resolution, import, and rendering step is identical.
954
+ * `options` object to the bundled `client` and returns the `Unwrappable<RequestResult>`. Only the
955
+ * generator `name` differs between plugins. Every other resolution, import, and rendering step is
956
+ * identical.
949
957
  */
950
958
  function createClientGenerator(name) {
951
959
  return (0, kubb_kit.defineGenerator)({
@@ -1021,7 +1029,7 @@ function createClientGenerator(name) {
1021
1029
  }),
1022
1030
  children: [
1023
1031
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1024
- name: eventStream ? ["client", "toEventStream"] : ["client"],
1032
+ name: eventStream ? ["client", "toEventStream"] : ["client", "withUnwrap"],
1025
1033
  root: meta.file.path,
1026
1034
  path: clientPath
1027
1035
  }),
@@ -1030,7 +1038,11 @@ function createClientGenerator(name) {
1030
1038
  "Options",
1031
1039
  "EventStreamResult",
1032
1040
  "SuccessOf"
1033
- ] : ["Options", "RequestResult"],
1041
+ ] : [
1042
+ "Options",
1043
+ "Unwrappable",
1044
+ "RequestResult"
1045
+ ],
1034
1046
  root: meta.file.path,
1035
1047
  path: clientPath,
1036
1048
  isTypeOnly: true
@@ -1237,7 +1249,7 @@ function createSdkGenerator() {
1237
1249
  footer: footer(file),
1238
1250
  children: [
1239
1251
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1240
- name: ["createClient"],
1252
+ name: ["createClient", "withUnwrap"],
1241
1253
  root: file.path,
1242
1254
  path: clientPath
1243
1255
  }),
@@ -1246,6 +1258,7 @@ function createSdkGenerator() {
1246
1258
  "ClientConfig",
1247
1259
  "ClientInstance",
1248
1260
  "Options",
1261
+ "Unwrappable",
1249
1262
  "RequestResult"
1250
1263
  ],
1251
1264
  root: file.path,