Skip to content

Commit

Permalink
Companion change to fastify PR
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli committed Sep 2, 2024
1 parent 39e89ea commit 468a769
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 10 additions & 8 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
// Leo <https://github.com/leomelzer>
/// <reference types="node" />

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<T extends FastifyReply>(this: T, filename: string, rootPath?: string): T,
sendFile<T extends FastifyReply>(this: T, filename: string, options?: fastifyStatic.SendOptions): T,
sendFile<T extends FastifyReply>(this: T, filename: string, rootPath?: string, options?: fastifyStatic.SendOptions): T,
download<T extends FastifyReply>(this: T, filepath: string, options?: fastifyStatic.SendOptions): T,
download<T extends FastifyReply>(this: T, filepath: string, filename?: string): T,
download<T extends FastifyReply>(this: T, filepath: string, filename?: string, options?: fastifyStatic.SendOptions): T,
}>
}
}

Expand Down
4 changes: 3 additions & 1 deletion types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
})
})

Expand Down

0 comments on commit 468a769

Please sign in to comment.