From 4dfc2a3be541e5e671745b70787eb3eed7aec211 Mon Sep 17 00:00:00 2001 From: Dmytro Zelenetskyi Date: Wed, 28 Aug 2024 12:32:00 +0200 Subject: [PATCH] feat(http-client): Refactor debug transformer handling (#9) --- .changeset/unlucky-deers-wait.md | 5 +++++ packages/http-client/src/index.ts | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changeset/unlucky-deers-wait.md diff --git a/.changeset/unlucky-deers-wait.md b/.changeset/unlucky-deers-wait.md new file mode 100644 index 0000000..8cfb067 --- /dev/null +++ b/.changeset/unlucky-deers-wait.md @@ -0,0 +1,5 @@ +--- +"@zemd/http-client": patch +--- + +improving debug transformer diff --git a/packages/http-client/src/index.ts b/packages/http-client/src/index.ts index 3588a52..3b1cb6f 100644 --- a/packages/http-client/src/index.ts +++ b/packages/http-client/src/index.ts @@ -319,7 +319,7 @@ export const endpoint = < type TCreateBuildOptions = { baseUrl: string; transformers?: Array; - debug?: boolean; + debug?: boolean | TFetchTransformer; }; /** @@ -342,9 +342,6 @@ export const createBuildEndpointFn = ({ prefix(baseUrl), json(), ]; - if (opts.debug) { - commonTransformers.push(debug()); - } const endpointDecFn = (...params: Parameters) => { const { url, transformers, ...rest } = fn(...params); @@ -354,7 +351,13 @@ export const createBuildEndpointFn = ({ ...commonTransformers, ...(opts.transformers ?? []), ...transformers, - ], + ].concat( + opts.debug === true + ? [debug()] + : typeof opts.debug === "function" + ? [opts.debug] + : [], + ), ...rest, }; };