Skip to content

Commit

Permalink
nodenext compatibilty (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Dec 5, 2022
1 parent 9745095 commit f34f767
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fp = require('fastify-plugin')
const Ajv = require('ajv')

function validateResponse (fastify, opts, next) {
function fastifyResponseValidation (fastify, opts, next) {
const { plugins: ajvPlugins, ...ajvOptions } = Object.assign({
coerceTypes: false,
useDefaults: true,
Expand Down Expand Up @@ -93,7 +93,9 @@ function schemaErrorsText (errors) {
return text.slice(0, -separator.length)
}

module.exports = fp(validateResponse, {
module.exports = fp(fastifyResponseValidation, {
fastify: '4.x',
name: '@fastify/response-validation'
})
module.exports.default = fastifyResponseValidation
module.exports.fastifyResponseValidation = fastifyResponseValidation
21 changes: 11 additions & 10 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { FastifyPluginCallback, RawServerBase, RawServerDefault } from "fastify";
import {
Options as AjvOptions
} from "ajv";
import { Options as AjvOptions } from "ajv";

declare module 'fastify' {
interface RouteShorthandOptions<
RawServer extends RawServerBase = RawServerDefault
> {
interface RouteShorthandOptions<RawServer extends RawServerBase = RawServerDefault> {
responseValidation?: boolean;
}
}

declare namespace FastifyResponseValidationPlugin {
interface Options {
type FastifyResponseValidation = FastifyPluginCallback<fastifyResponseValidation.Options>;

declare namespace fastifyResponseValidation {
export interface Options {
ajv?: AjvOptions & {
plugins?: (Function | [Function, unknown])[];
};
responseValidation?: boolean;
}

export const fastifyReponseValidation: FastifyResponseValidation
export { fastifyReponseValidation as default }
}

declare const FastifyResponseValidationPlugin: FastifyPluginCallback<FastifyResponseValidationPlugin.Options>;
export default FastifyResponseValidationPlugin;
declare function fastifyResponseValidation(...params: Parameters<FastifyResponseValidation>): ReturnType<FastifyResponseValidation>
export = fastifyResponseValidation

0 comments on commit f34f767

Please sign in to comment.