Skip to content

Commit

Permalink
Add routeOptions.config to types (#5034)
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Sep 13, 2023
1 parent 6b9b093 commit 30c2dff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 4 additions & 1 deletion test/types/request.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expectAssignable, expectType } from 'tsd'
import fastify, {
ContextConfigDefault,
FastifyContext,
FastifyContextConfig,
FastifyLogFn,
FastifySchema,
FastifyTypeProviderDefault,
Expand All @@ -18,7 +19,7 @@ import { FastifyInstance } from '../../types/instance'
import { FastifyLoggerInstance } from '../../types/logger'
import { FastifyReply } from '../../types/reply'
import { FastifyRequest, RequestRouteOptions } from '../../types/request'
import { RouteGenericInterface } from '../../types/route'
import { FastifyRouteConfig, RouteGenericInterface } from '../../types/route'
import { RequestHeadersDefault, RequestParamsDefault, RequestQuerystringDefault } from '../../types/utils'

interface RequestBody {
Expand Down Expand Up @@ -77,6 +78,8 @@ const getHandler: RouteHandler = function (request, _reply) {
expectType<FastifyContext<ContextConfigDefault>>(request.context)
expectType<FastifyContext<ContextConfigDefault>['config']>(request.context.config)
expectType<FastifyContext<ContextConfigDefault>['config']>(request.routeConfig)
expectType<FastifyContext<ContextConfigDefault>['config']>(request.routeOptions.config)
expectType<ContextConfigDefault & FastifyRouteConfig & FastifyContextConfig>(request.routeOptions.config)
expectType<FastifySchema>(request.routeSchema)

expectType<RequestHeadersDefault & RawRequestDefaultExpression['headers']>(request.headers)
Expand Down
11 changes: 6 additions & 5 deletions types/request.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ErrorObject } from '@fastify/ajv-compiler'
import { FastifyContext } from './context'
import { FastifyContext, FastifyContextConfig } from './context'
import { FastifyInstance } from './instance'
import { FastifyBaseLogger } from './logger'
import { RouteGenericInterface } from './route'
import { RouteGenericInterface, FastifyRouteConfig } from './route'
import { FastifySchema } from './schema'
import { FastifyRequestType, FastifyTypeProvider, FastifyTypeProviderDefault, ResolveFastifyRequestType } from './type-provider'
import { ContextConfigDefault, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestBodyDefault, RequestHeadersDefault, RequestParamsDefault, RequestQuerystringDefault } from './utils'
Expand All @@ -20,15 +20,16 @@ export interface ValidationFunction {
errors?: null | ErrorObject[];
}

export interface RequestRouteOptions {
export interface RequestRouteOptions<ContextConfig = ContextConfigDefault> {
method: string,
url: string,
bodyLimit:number,
attachValidation:boolean,
logLevel:string,
version: string | undefined,
exposeHeadRoute: boolean,
prefixTrailingSlash: string
prefixTrailingSlash: string,
config: FastifyContextConfig & FastifyRouteConfig & ContextConfig
}

/**
Expand Down Expand Up @@ -78,7 +79,7 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
readonly method: string;
readonly routerPath: string;
readonly routerMethod: string;
readonly routeOptions: Readonly<RequestRouteOptions>
readonly routeOptions: Readonly<RequestRouteOptions<ContextConfig>>
readonly is404: boolean;
readonly socket: RawRequest['socket'];

Expand Down

0 comments on commit 30c2dff

Please sign in to comment.