diff --git a/index.js b/index.js index d5556f1..3e0e211 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const SerializerManager = require('./SerializerManager') const FASTIFY_DEFAULT_SERIALIZE_MIME_TYPE = 'application/json' -function acceptsSerializerPlugin (fastify, options, next) { +function fastifyAcceptsSerializer (fastify, options, next) { const serializerCache = {} options.cache = serializerCache @@ -64,7 +64,9 @@ function acceptsSerializerPlugin (fastify, options, next) { next() } -module.exports = fp(acceptsSerializerPlugin, { +module.exports = fp(fastifyAcceptsSerializer, { fastify: '4.x', name: '@fastify/accepts-serializer' }) +module.exports.default = fastifyAcceptsSerializer +module.exports.fastifyAcceptsSerializer = fastifyAcceptsSerializer diff --git a/types/index.d.ts b/types/index.d.ts index 020e11c..cba5be1 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2,20 +2,26 @@ import { FastifyPluginCallback } from 'fastify'; declare module 'fastify' { export interface FastifyContextConfig { - serializers: SerializerConfig[]; + serializers: fastifyAcceptsSerializer.SerializerConfig[]; } } -interface SerializerConfig { - regex: RegExp; - serializer: (body: any) => string; -} +type FastifyAcceptsSerializer = FastifyPluginCallback; -interface FastifyAcceptsSerializerPluginOptions { - serializers: SerializerConfig[]; - default: string; -} +declare namespace fastifyAcceptsSerializer { + export interface SerializerConfig { + regex: RegExp; + serializer: (body: any) => string; + } + + export interface FastifyAcceptsSerializerPluginOptions { + serializers: SerializerConfig[]; + default: string; + } -declare const fastifyAcceptsSerializer: FastifyPluginCallback; + export const fastifyAcceptsSerializer: FastifyAcceptsSerializer + export { fastifyAcceptsSerializer as default } +} -export default fastifyAcceptsSerializer; +declare function fastifyAcceptsSerializer(...params: Parameters): ReturnType +export = fastifyAcceptsSerializer