|
1 | 1 | import type { |
| 2 | + DefaultError, |
2 | 3 | DefinedInitialDataOptions, |
3 | 4 | DefinedUseQueryResult, |
4 | 5 | InvalidateQueryFilters, |
@@ -53,9 +54,11 @@ type ErrorResponse<T> = |
53 | 54 | > |
54 | 55 | : never |
55 | 56 |
|
56 | | -export type HonoPayload<TInput> = undefined extends TInput |
57 | | - ? { options?: ClientRequestOptions } |
58 | | - : { input: TInput; options?: ClientRequestOptions } |
| 57 | +type HonoPayloadOptions = ClientRequestOptions & { throwOnError?: boolean } |
| 58 | +export type HonoPayload< |
| 59 | + TInput, |
| 60 | + TOptions extends HonoPayloadOptions | undefined = HonoPayloadOptions | undefined, |
| 61 | +> = undefined extends TInput ? { options?: TOptions } : { input: TInput; options?: TOptions } |
59 | 62 |
|
60 | 63 | export type UseHonoQuery<TApp extends Record<string, any>> = < |
61 | 64 | TPath extends keyof TApp, |
@@ -128,20 +131,35 @@ export type HonoQueryOptions<TApp extends Record<string, any>> = < |
128 | 131 | >, |
129 | 132 | 'queryKey' | 'queryFn' |
130 | 133 | >, |
| 134 | + TOptions extends HonoPayloadOptions | undefined = HonoPayloadOptions | undefined, |
131 | 135 | >( |
132 | 136 | path: TPath, |
133 | 137 | method: TMethod, |
134 | | - honoPayload: HonoPayload<InferFunctionInput<TApp[TPath][TMethod]>>, |
| 138 | + honoPayload: HonoPayload<InferFunctionInput<TApp[TPath][TMethod]>, TOptions>, |
135 | 139 | queryOptions?: TQueryOptions |
136 | 140 | ) => 'initialData' extends keyof TQueryOptions |
137 | | - ? DefinedInitialDataOptions< |
138 | | - SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>, |
139 | | - ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error |
140 | | - > |
141 | | - : UndefinedInitialDataOptions< |
142 | | - SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>, |
143 | | - ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error |
144 | | - > |
| 141 | + ? TOptions extends { throwOnError: false } |
| 142 | + ? DefinedInitialDataOptions< |
| 143 | + | SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>> |
| 144 | + | ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> |
| 145 | + | Error, |
| 146 | + DefaultError |
| 147 | + > |
| 148 | + : DefinedInitialDataOptions< |
| 149 | + SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>, |
| 150 | + ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error |
| 151 | + > |
| 152 | + : TOptions extends { throwOnError: false } |
| 153 | + ? UndefinedInitialDataOptions< |
| 154 | + | SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>> |
| 155 | + | ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> |
| 156 | + | Error, |
| 157 | + DefaultError |
| 158 | + > |
| 159 | + : UndefinedInitialDataOptions< |
| 160 | + SuccessResponse<InferFunctionReturn<TApp[TPath][TMethod]>>, |
| 161 | + ErrorResponse<InferFunctionReturn<TApp[TPath][TMethod]>> | Error |
| 162 | + > |
145 | 163 |
|
146 | 164 | export type HonoMutationOptions<TApp extends Record<string, any>> = < |
147 | 165 | TPath extends keyof TApp, |
|
0 commit comments