Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/salty-falcons-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@softnetics/hono-react-query': minor
---

Introduce useQuery with DefinedUseQueryResult type and queryOptions with DefinedInitialDataOptions
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ function useQueryFactory<T extends Record<string, any>>(
): UseHonoQuery<T> {
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<T>
}
Expand All @@ -112,7 +117,7 @@ function queryOptionsFactory<T extends Record<string, any>>(
return responseParser(response)
},
...hookOptions,
})
}) as any
}
}

Expand Down
63 changes: 45 additions & 18 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type {
DefinedInitialDataOptions,
DefinedUseQueryResult,
InvalidateQueryFilters,
UndefinedInitialDataOptions,
UseMutationOptions,
UseMutationResult,
UseQueryOptions,
Expand Down Expand Up @@ -57,21 +60,33 @@ export type HonoPayload<TInput> = undefined extends TInput
export type UseHonoQuery<TApp extends Record<string, any>> = <
TPath extends keyof TApp,
TMethod extends keyof TApp[TPath],
TQueryOptions extends Omit<
UseQueryOptions<
SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>,
ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error
>,
'queryKey' | 'queryFn'
> = Omit<
UseQueryOptions<
SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>,
ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error
>,
'queryKey' | 'queryFn'
>,
>(
path: TPath,
method: TMethod,
honoPayload: HonoPayload<InferFunctionInput<TApp[TPath][TMethod]>>,
queryOptions?: Omit<
UseQueryOptions<
queryOptions?: TQueryOptions
) => 'initialData' extends keyof TQueryOptions
? DefinedUseQueryResult<
SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>,
ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error
>,
'queryKey' | 'queryFn'
>
) => UseQueryResult<
SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>,
ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error
>
>
: UseQueryResult<
SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>,
ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error
>

export type UseHonoMutation<TApp extends Record<string, any>> = <
TPath extends keyof TApp,
Expand Down Expand Up @@ -100,21 +115,33 @@ export type UseHonoMutation<TApp extends Record<string, any>> = <
export type HonoQueryOptions<TApp extends Record<string, any>> = <
TPath extends keyof TApp,
TMethod extends keyof TApp[TPath],
TQueryOptions extends Omit<
UndefinedInitialDataOptions<
SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>,
ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error
>,
'queryKey' | 'queryFn'
> = Omit<
UndefinedInitialDataOptions<
SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>,
ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error
>,
'queryKey' | 'queryFn'
>,
>(
path: TPath,
method: TMethod,
honoPayload: HonoPayload<InferFunctionInput<TApp[TPath][TMethod]>>,
queryOptions?: Omit<
UseQueryOptions<
queryOptions?: TQueryOptions
) => 'initialData' extends keyof TQueryOptions
? DefinedInitialDataOptions<
SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>,
ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error
>,
'queryKey' | 'queryFn'
>
) => UseQueryOptions<
SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>,
ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error
>
>
: UndefinedInitialDataOptions<
SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>,
ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error
>

export type HonoMutationOptions<TApp extends Record<string, any>> = <
TPath extends keyof TApp,
Expand Down
Loading