Skip to content

Commit

Permalink
nodenext compatiblity (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Nov 24, 2022
1 parent 0289baf commit 33ee90d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
28 changes: 17 additions & 11 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<fastifyAcceptsSerializer.FastifyAcceptsSerializerPluginOptions>;

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<FastifyAcceptsSerializerPluginOptions>;
export const fastifyAcceptsSerializer: FastifyAcceptsSerializer
export { fastifyAcceptsSerializer as default }
}

export default fastifyAcceptsSerializer;
declare function fastifyAcceptsSerializer(...params: Parameters<FastifyAcceptsSerializer>): ReturnType<FastifyAcceptsSerializer>
export = fastifyAcceptsSerializer

0 comments on commit 33ee90d

Please sign in to comment.