1
1
/* eslint-disable @typescript-eslint/class-name-casing */
2
2
3
3
import { Readable } from 'stream'
4
+ import { CallbackOrPromise } from './callback-or-promise'
4
5
import { FastifyInstance } from './instance'
5
6
import { RouteOptions , RouteGenericInterface } from './route'
6
7
import { RawServerBase , RawServerDefault , RawRequestDefaultExpression , RawReplyDefaultExpression , ContextConfigDefault } from './utils'
@@ -21,23 +22,20 @@ interface RequestPayload extends Readable {
21
22
* `onRequest` is the first hook to be executed in the request lifecycle. There was no previous hook, the next hook will be `preParsing`.
22
23
* Notice: in the `onRequest` hook, request.body will always be null, because the body parsing happens before the `preHandler` hook.
23
24
*/
24
- export interface onRequestHookHandler <
25
+ export type onRequestHookHandler <
25
26
RawServer extends RawServerBase = RawServerDefault ,
26
27
RawRequest extends RawRequestDefaultExpression < RawServer > = RawRequestDefaultExpression < RawServer > ,
27
28
RawReply extends RawReplyDefaultExpression < RawServer > = RawReplyDefaultExpression < RawServer > ,
28
29
RouteGeneric extends RouteGenericInterface = RouteGenericInterface ,
29
- ContextConfig = ContextConfigDefault
30
- > {
31
- (
32
- request : FastifyRequest < RouteGeneric , RawServer , RawRequest > ,
33
- reply : FastifyReply < RawServer , RawRequest , RawReply , RouteGeneric , ContextConfig > ,
34
- done : HookHandlerDoneFunction
35
- ) : void ;
36
- (
37
- request : FastifyRequest < RouteGeneric , RawServer , RawRequest > ,
38
- reply : FastifyReply < RawServer , RawRequest , RawReply , RouteGeneric , ContextConfig > ,
39
- ) : Promise < unknown > ;
40
- }
30
+ ContextConfig = ContextConfigDefault ,
31
+ T extends ( ...args : any [ ] ) => void = ( ...args : any [ ] ) => void
32
+ > = CallbackOrPromise <
33
+ T ,
34
+ [
35
+ FastifyRequest < RouteGeneric , RawServer , RawRequest > ,
36
+ FastifyReply < RawServer , RawRequest , RawReply , RouteGeneric , ContextConfig >
37
+ ] ,
38
+ HookHandlerDoneFunction >
41
39
42
40
/**
43
41
* `preParsing` is the second hook to be executed in the request lifecycle. The previous hook was `onRequest`, the next hook will be `preValidation`.
0 commit comments