From 152ee008e2ea44e71cc027c65795c3d1c96bf1ab Mon Sep 17 00:00:00 2001 From: Saenyakorn Siangsanoh Date: Tue, 21 Oct 2025 13:32:56 +0700 Subject: [PATCH 1/3] feat: introduce define query result --- src/index.ts | 9 +++++++-- src/types.ts | 55 +++++++++++++++++++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/index.ts b/src/index.ts index d8df8f0..d41f3eb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -88,7 +88,12 @@ function useQueryFactory>( ): UseHonoQuery { return ((path, method, honoPayload, hookOptions) => { return useQuery( - queryOptionsFactory(client)(path.toString(), method, honoPayload as any, hookOptions as any) + queryOptionsFactory(client)( + path.toString(), + method, + honoPayload as any, + hookOptions as any + ) as any ) }) as UseHonoQuery } @@ -112,7 +117,7 @@ function queryOptionsFactory>( return responseParser(response) }, ...hookOptions, - }) + }) as any } } diff --git a/src/types.ts b/src/types.ts index f7de0ce..c000ed3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,5 @@ import type { + DefinedUseQueryResult, InvalidateQueryFilters, UseMutationOptions, UseMutationResult, @@ -57,21 +58,30 @@ export type HonoPayload = undefined extends TInput export type UseHonoQuery> = < TPath extends keyof TApp, TMethod extends keyof TApp[TPath], + TQueryOptions extends Omit< + UseQueryOptions< + SuccessResponse>, + ErrorResponse> | Error + >, + 'queryKey' | 'queryFn' + > = Omit< + UseQueryOptions< + SuccessResponse>, + ErrorResponse> | Error + >, + 'queryKey' | 'queryFn' + >, >( path: TPath, method: TMethod, honoPayload: HonoPayload>, - queryOptions?: Omit< - UseQueryOptions< + queryOptions?: TQueryOptions +) => 'initialData' extends keyof TQueryOptions + ? DefinedUseQueryResult< SuccessResponse>, ErrorResponse> | Error - >, - 'queryKey' | 'queryFn' - > -) => UseQueryResult< - SuccessResponse>, - ErrorResponse> | Error -> + > + : typeof queryOptions export type UseHonoMutation> = < TPath extends keyof TApp, @@ -100,21 +110,30 @@ export type UseHonoMutation> = < export type HonoQueryOptions> = < TPath extends keyof TApp, TMethod extends keyof TApp[TPath], + TQueryOptions extends Omit< + UseQueryOptions< + SuccessResponse>, + ErrorResponse> | Error + >, + 'queryKey' | 'queryFn' + > = Omit< + UseQueryOptions< + SuccessResponse>, + ErrorResponse> | Error + >, + 'queryKey' | 'queryFn' + >, >( path: TPath, method: TMethod, honoPayload: HonoPayload>, - queryOptions?: Omit< - UseQueryOptions< + queryOptions?: TQueryOptions +) => 'initialData' extends keyof TQueryOptions + ? DefinedUseQueryResult< SuccessResponse>, ErrorResponse> | Error - >, - 'queryKey' | 'queryFn' - > -) => UseQueryOptions< - SuccessResponse>, - ErrorResponse> | Error -> + > + : typeof queryOptions export type HonoMutationOptions> = < TPath extends keyof TApp, From aa3cc28032c75228cbcb9aea4b0e7ab11280ecb7 Mon Sep 17 00:00:00 2001 From: Saenyakorn Siangsanoh Date: Tue, 21 Oct 2025 13:41:25 +0700 Subject: [PATCH 2/3] fix: query options type --- src/types.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/types.ts b/src/types.ts index c000ed3..b18867f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,8 @@ import type { + DefinedInitialDataOptions, DefinedUseQueryResult, InvalidateQueryFilters, + UndefinedInitialDataOptions, UseMutationOptions, UseMutationResult, UseQueryOptions, @@ -81,7 +83,10 @@ export type UseHonoQuery> = < SuccessResponse>, ErrorResponse> | Error > - : typeof queryOptions + : UseQueryResult< + SuccessResponse>, + ErrorResponse> | Error + > export type UseHonoMutation> = < TPath extends keyof TApp, @@ -111,13 +116,13 @@ export type HonoQueryOptions> = < TPath extends keyof TApp, TMethod extends keyof TApp[TPath], TQueryOptions extends Omit< - UseQueryOptions< + UndefinedInitialDataOptions< SuccessResponse>, ErrorResponse> | Error >, 'queryKey' | 'queryFn' > = Omit< - UseQueryOptions< + UndefinedInitialDataOptions< SuccessResponse>, ErrorResponse> | Error >, @@ -129,11 +134,14 @@ export type HonoQueryOptions> = < honoPayload: HonoPayload>, queryOptions?: TQueryOptions ) => 'initialData' extends keyof TQueryOptions - ? DefinedUseQueryResult< + ? DefinedInitialDataOptions< + SuccessResponse>, + ErrorResponse> | Error + > + : UndefinedInitialDataOptions< SuccessResponse>, ErrorResponse> | Error > - : typeof queryOptions export type HonoMutationOptions> = < TPath extends keyof TApp, From e535f40d0debbc4d4348aa1ff57f0776009da2a8 Mon Sep 17 00:00:00 2001 From: Saenyakorn Siangsanoh Date: Tue, 21 Oct 2025 13:45:55 +0700 Subject: [PATCH 3/3] chore: changeset --- .changeset/salty-falcons-march.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/salty-falcons-march.md diff --git a/.changeset/salty-falcons-march.md b/.changeset/salty-falcons-march.md new file mode 100644 index 0000000..a8160b5 --- /dev/null +++ b/.changeset/salty-falcons-march.md @@ -0,0 +1,5 @@ +--- +'@softnetics/hono-react-query': minor +--- + +Introduce useQuery with DefinedUseQueryResult type and queryOptions with DefinedInitialDataOptions