From bab4d151e28b1d97e943342cbbd65f33c5436a90 Mon Sep 17 00:00:00 2001 From: Saenyakorn Siangsanoh Date: Fri, 14 Nov 2025 11:37:52 +0700 Subject: [PATCH 1/2] feat: add raw response --- src/index.spec.tsx | 14 +++++++++++++- src/index.ts | 3 +++ src/types.ts | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/index.spec.tsx b/src/index.spec.tsx index f8978b6..5210c21 100644 --- a/src/index.spec.tsx +++ b/src/index.spec.tsx @@ -71,6 +71,7 @@ describe('createReactQueryClient', () => { } status: 200 format: 'json' + raw: Response } | { data: { @@ -78,6 +79,7 @@ describe('createReactQueryClient', () => { } status: 400 format: 'json' + raw: Response }, Error > @@ -100,6 +102,7 @@ describe('createReactQueryClient', () => { } status: 200 format: 'json' + raw: Response } | { data: { @@ -107,6 +110,7 @@ describe('createReactQueryClient', () => { } status: 400 format: 'json' + raw: Response }, Error > @@ -135,6 +139,7 @@ describe('createReactQueryClient', () => { } status: 200 format: 'json' + raw: Response }, Error | HonoResponseError<{ error: string }, 400, 'json'> > @@ -157,6 +162,7 @@ describe('createReactQueryClient', () => { } status: 200 format: 'json' + raw: Response }, | Error | HonoResponseError< @@ -196,10 +202,16 @@ describe('createReactQueryClient', () => { >() expectTypeOf>>().toMatchTypeOf< - (data: { data: { user: { id: string; name: string } }; status: 201; format: 'json' }) => { + (data: { data: { user: { id: string; name: string } } status: 201 format: 'json' + raw: Response + }) => { + data: { user: { id: string; name: string } } + status: 201 + format: 'json' + raw: Response } >() diff --git a/src/index.ts b/src/index.ts index 667aa4c..8465f9f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,6 +56,8 @@ function getter(obj: object, paths: string[]): any { } async function responseParser(response: Response, throwOnError?: boolean): Promise { + const raw = response.clone() + let data: any const contentType = response.headers.get('content-type') if (contentType?.includes('application/json')) { @@ -74,6 +76,7 @@ async function responseParser(response: Response, throwOnError?: boolean): Promi : contentType?.includes('text/plain') ? 'text' : 'body', + raw, } if (response.ok || throwOnError === false) { diff --git a/src/types.ts b/src/types.ts index 2a8bafc..1e208a7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -37,7 +37,7 @@ type InferFunctionReturn = T extends (...rest: any[]) => infer TReturn ? Awai type ClientResponseParser = T extends ClientResponse - ? { data: TData; status: TStatus; format: TFormat } + ? { data: TData; status: TStatus; format: TFormat; raw: Response } : never type SuccessResponse = From a89fdcb9d3392cda2ffa1f84a8fc17d28ce1b67a Mon Sep 17 00:00:00 2001 From: Saenyakorn Siangsanoh <33742791+saenyakorn@users.noreply.github.com> Date: Fri, 14 Nov 2025 11:43:50 +0700 Subject: [PATCH 2/2] Create purple-kids-juggle.md --- .changeset/purple-kids-juggle.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/purple-kids-juggle.md diff --git a/.changeset/purple-kids-juggle.md b/.changeset/purple-kids-juggle.md new file mode 100644 index 0000000..97d03d6 --- /dev/null +++ b/.changeset/purple-kids-juggle.md @@ -0,0 +1,5 @@ +--- +"@softnetics/hono-react-query": minor +--- + +Add Raw Response to the response from the lib.