Skip to content
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
9 changes: 8 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
IncomingMessage,
RequestOptions,
} from 'node:http'
import { Readable } from 'node:stream'
import {
ClientSessionOptions,
ClientSessionRequestOptions,
Expand Down Expand Up @@ -66,6 +67,12 @@ declare namespace fastifyReplyFrom {
stream: IncomingMessage
}

export interface FastifyReplyFromResponse {
statusCode: number
headers: IncomingHttpHeaders | Http2IncomingHttpHeaders
stream: Readable
}

export interface FastifyReplyFromHooks {
queryString?: { [key: string]: unknown } | QueryStringFunction;
contentType?: string;
Expand All @@ -74,7 +81,7 @@ declare namespace fastifyReplyFrom {
onResponse?: (
request: FastifyRequest<RequestGenericInterface, RawServerBase>,
reply: FastifyReply<RouteGenericInterface, RawServerBase>,
res: RawServerResponse<RawServerBase>
res: FastifyReplyFromResponse
) => void;
onError?: (
reply: FastifyReply<RouteGenericInterface, RawServerBase>,
Expand Down
8 changes: 7 additions & 1 deletion types/index.tst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import * as https from 'node:https'
import { Agent, Client, Dispatcher, Pool } from 'undici'
import replyFrom, {
type FastifyReplyFromOptions,
type FastifyReplyFromResponse,
type RawServerResponse
} from '.'
import { type IncomingHttpHeaders as Http1IncomingHttpHeaders } from 'node:http'
import { type Readable } from 'node:stream'

const fullOptions: FastifyReplyFromOptions = {
base: 'http://example2.com',
Expand Down Expand Up @@ -83,8 +86,11 @@ app.get('/v3', (_request, reply) => {
onResponse (request, reply, res) {
expect(request).type.toBe<FastifyRequest<RequestGenericInterface, RawServerBase>>()
expect(reply).type.toBe<FastifyReply<RouteGenericInterface, RawServerBase>>()
expect(res).type.toBe<RawServerResponse<RawServerBase>>()
expect(res).type.toBe<FastifyReplyFromResponse>()
expect(res.statusCode).type.toBe<number>()
expect(res.headers).type.toBe<Http1IncomingHttpHeaders | IncomingHttpHeaders>()
expect(res.stream).type.toBe<Readable>()
expect<RawServerResponse<RawServerBase>>().type.toBe<RawServerResponse<RawServerBase>>()
}
})
})
Expand Down
Loading