@nestjs/core
Version:
The core of NestJS, a TypeScript framework for Node.js backends: modules, dependency injection and the request pipeline, on Express, Fastify or node:http.
55 lines (54 loc) • 3.6 kB
TypeScript
import { type VersioningOptions } from '@nestjs/common';
import { ExcludeRouteMetadata } from '../router/interfaces/exclude-route-metadata.interface.js';
import type { HttpServer, Type } from '@nestjs/common';
import { type RouteInfo, type RouteMatchingOptions } from '@nestjs/common/internal';
/**
* Compiles the given routes into exclusion matchers. Without
* `matchingOptions`, paths match case-insensitively and ignoring a trailing
* slash; pass the router's {@link RouteMatchingOptions} to match requests
* exactly like the router does.
*/
export declare const mapToExcludeRoute: (routes: (string | RouteInfo)[], matchingOptions?: RouteMatchingOptions) => ExcludeRouteMetadata[];
/**
* Removes the trailing slashes of a request path in linear time: the
* `/\/+$/` regex is retried from every slash of the path, which takes
* quadratic time on a long run of slashes that does not end it.
*/
export declare function stripEndSlashes(path: string): string;
/**
* A line terminator (LF, CR, U+2028 or U+2029) in a request path, as it is
* or percent-encoded.
*/
export declare const LINE_TERMINATOR: RegExp;
/**
* Tells whether a route path matches no other path than itself.
*/
export declare function isStaticPath(path: string): boolean;
export declare const filterMiddleware: <T extends Function | Type<any> = any>(middleware: T[], routes: RouteInfo[], httpAdapter: HttpServer, versioningOptions?: VersioningOptions, getServedRoutes?: () => RouteInfo[]) => Type<any>[];
export declare const mapToClass: <T extends Function | Type<any>>(middleware: T, excludedRoutes: ExcludeRouteMetadata[], httpAdapter: HttpServer, matchingOptions?: RouteMatchingOptions | boolean, versioningOptions?: VersioningOptions, getServedRoutes?: () => ExcludeRouteMetadata[]) => Type<any>;
export declare function isMiddlewareClass(middleware: any): middleware is Type<any>;
export declare function assignToken(metatype: Type<any>, token?: string): Type<any>;
/**
* Tells whether the request is served by one of the excluded routes, so that
* the middleware is skipped for it. `matchingOptions` tell how the router
* matches paths (`true` and `false` stand for `ignoreTrailingSlash`), and
* `getServedRoutes` returns the routes of the application that may serve a
* path ending with "/" on a router that serves it with the first route that
* matches it.
*/
export declare function isMiddlewareRouteExcluded(req: Record<string, any>, excludedRoutes: ExcludeRouteMetadata[], httpAdapter: HttpServer, matchingOptions?: RouteMatchingOptions | boolean, versioningOptions?: VersioningOptions, getServedRoutes?: () => ExcludeRouteMetadata[]): boolean;
/**
* Returns a function that tells whether the request asks for the version of
* an excluded route. With header, media type and custom versioning, the
* version is not part of the path, so an excluded route of a version covers
* the requests for that version only. The versions of the request are read
* as the version filters of the HTTP adapters read them, once, and only for
* a route that has a version.
*
* A request that asks for several versions (custom versioning) may be served
* by a route of any of them, so all of them must be versions of the excluded
* route. A request whose versions cannot be read is not excluded, and an
* excluded route that is only version-neutral covers every request, as the
* router serves it for the versions no other route takes.
*/
export declare function createRequestedVersionMatcher(request: Record<string, any>, versioningOptions?: VersioningOptions): (route: ExcludeRouteMetadata) => boolean;