Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodenext compatiblity #86

Merged
merged 1 commit into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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