From 468a769a8121e8b1e525618e701457b2db0fbf56 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Mon, 2 Sep 2024 15:17:00 +0200 Subject: [PATCH] Companion change to fastify PR See https://github.com/fastify/fastify/pull/5648 --- package.json | 2 +- types/index.d.ts | 18 ++++++++++-------- types/index.test-d.ts | 4 +++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 8b98a99..8e360e1 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@types/node": "^22.0.0", "concat-stream": "^2.0.0", "eslint": "^9.9.0", - "fastify": "^5.0.0-alpha.3", + "fastify": "voxpelli/fastify#prototype-improved-register", "neostandard": "^0.11.3", "pino": "^9.1.0", "proxyquire": "^2.1.3", diff --git a/types/index.d.ts b/types/index.d.ts index 1af2a6b..00cf453 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2,17 +2,19 @@ // Leo /// -import { FastifyPluginAsync, FastifyReply, FastifyRequest, RouteOptions } from 'fastify' +import { FastifyPluginAsync, FastifyReply, FastifyReplyMixin, FastifyRequest, RouteOptions } from 'fastify' import { Stats } from 'fs' declare module 'fastify' { - interface FastifyReply { - sendFile(filename: string, rootPath?: string): FastifyReply; - sendFile(filename: string, options?: fastifyStatic.SendOptions): FastifyReply; - sendFile(filename: string, rootPath?: string, options?: fastifyStatic.SendOptions): FastifyReply; - download(filepath: string, options?: fastifyStatic.SendOptions): FastifyReply; - download(filepath: string, filename?: string): FastifyReply; - download(filepath: string, filename?: string, options?: fastifyStatic.SendOptions): FastifyReply; + interface FastifyReplyMixins { + fastifyStatic: FastifyReplyMixin<'fastifyStatic', { + sendFile(this: T, filename: string, rootPath?: string): T, + sendFile(this: T, filename: string, options?: fastifyStatic.SendOptions): T, + sendFile(this: T, filename: string, rootPath?: string, options?: fastifyStatic.SendOptions): T, + download(this: T, filepath: string, options?: fastifyStatic.SendOptions): T, + download(this: T, filepath: string, filename?: string): T, + download(this: T, filepath: string, filename?: string, options?: fastifyStatic.SendOptions): T, + }> } } diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 75f21be..d8496cb 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -121,7 +121,9 @@ appWithImplicitHttp .register(fastifyStatic, options) .after(() => { appWithImplicitHttp.get('/', (request, reply) => { - reply.sendFile('some-file-name') + if (reply.hasMixin('fastifyStatic')) { + reply.sendFile('some-file-name').sendFile('some-file-name') + } }) })