11import Ajv from 'ajv'
22import { FastifyInstance , RegisterOptions } from 'fastify'
33import fastifyPlugin from 'fastify-plugin'
4- import { IncomingMessage , Server , ServerResponse } from 'http'
4+ import { IncomingMessage , Server as HttpServer , ServerResponse } from 'http'
5+ import { Http2Server , Http2ServerRequest , Http2ServerResponse } from 'http2'
6+ import { Server as HttpsServer } from 'https'
57import { handleErrors , handleNotFoundError } from './handlers'
68import { addResponseValidation } from './validation'
79
@@ -10,10 +12,26 @@ export * from './interfaces'
1012export { addAdditionalProperties , serializeError } from './properties'
1113export { convertValidationErrors , niceJoin , validationMessagesFormatters } from './validation'
1214
15+ export interface Options <
16+ S extends HttpServer | HttpsServer | Http2Server = HttpServer ,
17+ I extends IncomingMessage | Http2ServerRequest = IncomingMessage ,
18+ R extends ServerResponse | Http2ServerResponse = ServerResponse
19+ > extends RegisterOptions < S , I , R > {
20+ hideUnhandledErrors ?: boolean
21+ convertValidationErrors ?: boolean
22+ convertResponsesValidationErrors ?: boolean
23+ }
24+
25+ export type Plugin <
26+ S extends HttpServer | HttpsServer | Http2Server = HttpServer ,
27+ I extends IncomingMessage | Http2ServerRequest = IncomingMessage ,
28+ R extends ServerResponse | Http2ServerResponse = ServerResponse
29+ > = ( fastify : FastifyInstance < S , I , R > , options : Options < S , I , R > ) => void
30+
1331export const plugin = fastifyPlugin (
14- function < S = Server , I = IncomingMessage , R = ServerResponse > (
15- instance : FastifyInstance ,
16- options : RegisterOptions < S , I , R > ,
32+ function (
33+ instance : FastifyInstance < HttpServer , IncomingMessage , ServerResponse > ,
34+ options : Options < HttpServer , IncomingMessage , ServerResponse > ,
1735 done : ( ) => void
1836 ) : void {
1937 const isProduction = process . env . NODE_ENV === 'production'
@@ -46,5 +64,6 @@ export const plugin = fastifyPlugin(
4664 { name : 'fastify-errors-properties' }
4765)
4866
67+ export default plugin as Plugin
4968module . exports = plugin
5069Object . assign ( module . exports , exports )
0 commit comments