@kubb/plugin-fetch 5.5.2 → 5.5.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/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  [![Node][node-src]][node-href]
11
11
 
12
12
  <h4>
13
- <a href="https://kubb.dev/plugins/fetch" target="_blank">Documentation</a>
13
+ <a href="https://kubb.dev/plugins/plugin-fetch" target="_blank">Documentation</a>
14
14
  <span> · </span>
15
15
  <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
16
16
  <span> · </span>
@@ -38,7 +38,7 @@ npm install @kubb/plugin-fetch
38
38
 
39
39
  ## Documentation
40
40
 
41
- See the [full documentation](https://kubb.dev/plugins/fetch) for configuration options and examples.
41
+ See the [full documentation](https://kubb.dev/plugins/plugin-fetch) for configuration options and examples.
42
42
 
43
43
  ## Supporting Kubb
44
44
 
package/dist/index.cjs CHANGED
@@ -478,7 +478,8 @@ function buildRequestResultGenerics({ node, types }) {
478
478
  }
479
479
  /**
480
480
  * Builds the full return type an operation's function signature uses: `Unwrappable<RequestResult>`
481
- * for the default `returnType: 'full'`, already a promise so no further wrapping is needed, or a
481
+ * for the default `returnType: 'full'`, already a promise so no further wrapping is needed, a plain
482
+ * `Promise<RequestResult>` for the internal `'plain'` shape, or a
482
483
  * `Promise` of the runtime's `UnwrappedResult` when `returnType: 'data'` narrows a resolved call
483
484
  * down to the bare success body.
484
485
  *
@@ -490,7 +491,9 @@ function buildResultType({ node, types, returnType }) {
490
491
  node,
491
492
  types
492
493
  });
493
- return returnType === "data" ? `Promise<UnwrappedResult<${generics}>>` : `Unwrappable<RequestResult<${generics}>>`;
494
+ if (returnType === "data") return `Promise<UnwrappedResult<${generics}>>`;
495
+ if (returnType === "plain") return `Promise<RequestResult<${generics}>>`;
496
+ return `Unwrappable<RequestResult<${generics}>>`;
494
497
  }
495
498
  //#endregion
496
499
  //#region ../../internals/client/src/builders/returnStatement.ts
@@ -502,6 +505,7 @@ function buildResultType({ node, types, returnType }) {
502
505
  * body. With `returnType: 'data'` it instead routes the call through the runtime's `unwrapResult`,
503
506
  * which narrows the resolved value down to the bare success body the same way `RequestResult`
504
507
  * already does, using the plugin default when the call leaves `throwOnError` unset.
508
+ * With `returnType: 'plain'` it returns the runtime call as is, cast to `RequestResult`, with no helper.
505
509
  *
506
510
  * Cast first, wrap second, for the `'full'` path. That order keeps `withUnwrap`'s generic inferred
507
511
  * as `RequestResult` instead of the runtime's own internal result type. Casting an `Unwrappable<A>`
@@ -512,6 +516,8 @@ function buildResultType({ node, types, returnType }) {
512
516
  * `return withUnwrap(request({ method: 'POST', url: '/pet', ...config }) as Promise<RequestResult<AddPetResponses, ThrowOnError>>)`
513
517
  * @example
514
518
  * `return unwrapResult(request({ method: 'POST', url: '/pet', ...config }), config.throwOnError ?? false) as Promise<UnwrappedResult<AddPetResponses, ThrowOnError>>`
519
+ * @example
520
+ * `return request({ method: 'POST', url: '/pet', ...config }) as Promise<RequestResult<AddPetResponses, ThrowOnError>>`
515
521
  */
516
522
  function buildReturnStatement({ node, types, callConfig, returnType, throwOnErrorDefault }) {
517
523
  if (returnType === "data") return `return unwrapResult(request(${callConfig}), config.throwOnError ?? ${throwOnErrorDefault}) as ${buildResultType({
@@ -519,6 +525,10 @@ function buildReturnStatement({ node, types, callConfig, returnType, throwOnErro
519
525
  types,
520
526
  returnType
521
527
  })}`;
528
+ if (returnType === "plain") return `return request(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
529
+ node,
530
+ types
531
+ })}>>`;
522
532
  return `return withUnwrap(request(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
523
533
  node,
524
534
  types
@@ -996,7 +1006,7 @@ function resolveOperationTypes(driver) {
996
1006
  * generator `name` differs between plugins. Every other resolution, import, and rendering step is
997
1007
  * identical.
998
1008
  */
999
- function createClientGenerator(name) {
1009
+ function createClientGenerator(name, resolveClientPath) {
1000
1010
  return (0, kubb_kit.defineGenerator)({
1001
1011
  name,
1002
1012
  renderer: kubb_jsx.jsxRenderer,
@@ -1046,8 +1056,30 @@ function createClientGenerator(name) {
1046
1056
  method: node.method,
1047
1057
  path: node.path
1048
1058
  });
1049
- const clientPath = node_path.default.resolve(root, ".kubb/client.ts");
1059
+ const customClientPath = resolveClientPath?.(ctx.options, root);
1060
+ const clientPath = customClientPath ?? node_path.default.resolve(root, ".kubb/client.ts");
1061
+ const clientRoot = customClientPath === void 0 ? meta.file.path : void 0;
1050
1062
  const eventStream = isEventStream(node);
1063
+ const clientValueImports = (() => {
1064
+ if (eventStream) return ["client", "toEventStream"];
1065
+ if (returnType === "plain") return ["client"];
1066
+ if (returnType === "data") return ["client", "unwrapResult"];
1067
+ return ["client", "withUnwrap"];
1068
+ })();
1069
+ const clientTypeImports = (() => {
1070
+ if (eventStream) return [
1071
+ "Options",
1072
+ "EventStreamResult",
1073
+ "SuccessOf"
1074
+ ];
1075
+ if (returnType === "plain") return ["Options", "RequestResult"];
1076
+ if (returnType === "data") return ["Options", "UnwrappedResult"];
1077
+ return [
1078
+ "Options",
1079
+ "Unwrappable",
1080
+ "RequestResult"
1081
+ ];
1082
+ })();
1051
1083
  return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
1052
1084
  baseName: meta.file.baseName,
1053
1085
  path: meta.file.path,
@@ -1070,21 +1102,13 @@ function createClientGenerator(name) {
1070
1102
  }),
1071
1103
  children: [
1072
1104
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1073
- name: eventStream ? ["client", "toEventStream"] : ["client", returnType === "data" ? "unwrapResult" : "withUnwrap"],
1074
- root: meta.file.path,
1105
+ name: clientValueImports,
1106
+ root: clientRoot,
1075
1107
  path: clientPath
1076
1108
  }),
1077
1109
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1078
- name: eventStream ? [
1079
- "Options",
1080
- "EventStreamResult",
1081
- "SuccessOf"
1082
- ] : returnType === "data" ? ["Options", "UnwrappedResult"] : [
1083
- "Options",
1084
- "Unwrappable",
1085
- "RequestResult"
1086
- ],
1087
- root: meta.file.path,
1110
+ name: clientTypeImports,
1111
+ root: clientRoot,
1088
1112
  path: clientPath,
1089
1113
  isTypeOnly: true
1090
1114
  }),