Skip to content

Commit

Permalink
feat(http-client): Refactor debug transformer handling (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
zemd authored Aug 28, 2024
1 parent a51d4b3 commit 4dfc2a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-deers-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zemd/http-client": patch
---

improving debug transformer
13 changes: 8 additions & 5 deletions packages/http-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export const endpoint = <
type TCreateBuildOptions = {
baseUrl: string;
transformers?: Array<TFetchTransformer>;
debug?: boolean;
debug?: boolean | TFetchTransformer;
};

/**
Expand All @@ -342,9 +342,6 @@ export const createBuildEndpointFn = ({
prefix(baseUrl),
json(),
];
if (opts.debug) {
commonTransformers.push(debug());
}

const endpointDecFn = (...params: Parameters<ArgDecFn>) => {
const { url, transformers, ...rest } = fn(...params);
Expand All @@ -354,7 +351,13 @@ export const createBuildEndpointFn = ({
...commonTransformers,
...(opts.transformers ?? []),
...transformers,
],
].concat(
opts.debug === true
? [debug()]
: typeof opts.debug === "function"
? [opts.debug]
: [],
),
...rest,
};
};
Expand Down

0 comments on commit 4dfc2a3

Please sign in to comment.