From aa75b3173c492116e5f7d840ac66547297a50fd6 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Tue, 13 Dec 2022 08:12:42 +0100 Subject: [PATCH] feat: infamous triplet (#45) --- .npmrc | 1 + package.json | 5 ++++- plugin.d.ts | 24 ++++++++++++++++-------- plugin.js | 6 +++++- 4 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..9cf9495 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false \ No newline at end of file diff --git a/package.json b/package.json index 0e51602..d877a0d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "scripts": { "lint": "standard", "lint:fix": "standard --fix", - "test": "tap test/**.test.* && tsd" + "test": "tap test/**.test.* && tsd", + "test:types": "tsd" }, "repository": { "type": "git", @@ -17,6 +18,8 @@ "raw-body", "body", "request", + "fastify", + "fastify-plugin", "fastify-raw-body" ], "author": "Manuel Spigolon (https://github.com/Eomm)", diff --git a/plugin.d.ts b/plugin.d.ts index 4196e04..9807aa6 100644 --- a/plugin.d.ts +++ b/plugin.d.ts @@ -6,13 +6,21 @@ declare module 'fastify' { } } -export interface RawBodyPluginOptions { - field?: string - global?: boolean - encoding?: string | null | false - runFirst?: boolean - routes?: string[] +type FastifyRawBody = FastifyPluginCallback + +declare namespace fastifyRawBody { + export interface RawBodyPluginOptions { + field?: string + global?: boolean + encoding?: string | null | false + runFirst?: boolean + routes?: string[] + } + + export const fastifyRawBody: FastifyRawBody; + export { fastifyRawBody as default }; } -declare const fastifyRawBody: FastifyPluginCallback -export default fastifyRawBody + +declare function fastifyRawBody(...params: Parameters): ReturnType +export = fastifyRawBody diff --git a/plugin.js b/plugin.js index e7c2c97..5c84d57 100644 --- a/plugin.js +++ b/plugin.js @@ -102,7 +102,11 @@ function rawBody (fastify, opts, next) { } } -module.exports = fp(rawBody, { +const plugin = fp(rawBody, { fastify: '^4.10.x', name: 'fastify-raw-body' }) + +module.exports = plugin +module.exports.default = plugin +module.exports.fastifyRawBody = plugin