UNPKG

@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.

131 lines (130 loc) • 6.91 kB
import { ApplicationConfig } from '../application-config.js'; import type { VersioningOptions } from '@nestjs/common'; import { type RouteInfo } from '@nestjs/common/internal'; export declare class RouteInfoPathExtractor { private readonly applicationConfig; private readonly getControllerRoutes?; private readonly routePathFactory; private readonly prefixPath; private readonly excludedGlobalPrefixRoutes; private readonly versioningConfig?; private servedControllerRoutes?; /** * @param getControllerRoutes Returns the routes of the controllers of the * application, so that a route passed to `forRoutes()` is also mounted on * the routes it covers that the router serves on the other side of the * global prefix (see `getPathsOfCoveredControllerRoutes()`). */ constructor(applicationConfig: ApplicationConfig, getControllerRoutes?: (() => RouteInfo[]) | undefined); extractPathsFrom(route: RouteInfo): string[]; private extractMountPathsFrom; /** * Returns the routes of the controllers that the route passed to * `forRoutes()` covers, but that the router serves on the other side of * the global prefix than the paths the route is mounted on, with the method * of the route they are served for. The router decides for each route * whether the prefix applies, by testing the exclusions against the path * the route is declared with, while the route of `forRoutes()` is mounted * on one side only: "files/*path" excluded by "files/:name" (which matches * its text) is mounted without the prefix, where "files/:name/versions" is * served under it. * * A route covers a controller route whose declared path it matches (as a * plain string mounted on the sub-paths too), of a method it is mounted * for, under one of its versions. See `getPathsOfCoveredControllerRoutes()` * for a wildcard. */ extractControllerRoutesCoveredBy({ path, method, version, }: RouteInfo): RouteInfo[]; /** * Returns the paths the router serves the routes of the controllers that it * takes out of the global prefix at, for a wildcard of `forRoutes()`: it * is mounted under the prefix and on the exclusions themselves, which do * not cover every route they take out ("files/:id" also takes out * "files/*path", read as a value of ":id", which serves "/files/a/b"; a * mis-cased exclusion takes out the route as it is spelled). The routes of * other versions than the wildcard's own are left out. */ private getPathsOfCoveredControllerRoutes; /** * A route without a version is mounted without a version path. */ private toMountedVersionPaths; private getServedControllerRoutes; /** * Returns the routes excluded from the global prefix that the route covers * without being excluded itself: the router serves them without the * prefix, out of the reach of the paths the route is mounted on. These are * the excluded routes without parameters or wildcards that the route * matches, such as "users/me" for "users/:id" (or a `GET` exclusion for a * route of every method), and the root route of a controller at the * route's own path, which an exclusion ending in an optional segment such * as "reports/{*path}" takes out of the prefix (see * `isExcludedWithTrailingSlash()`). * * The route matches case-insensitively unless `caseSensitive` is set: a * caller that skips something for the covered routes (an exclusion) must * match them as strictly as the router does. Such a caller also sets * `asServed`, to compare the paths as the router serves them, without a * trailing slash: an excluded route written "webhooks/" is served at * "/webhooks", which "webhooks/{*path}" does not match. */ extractExcludedRoutesCoveredBy({ path, method, version }: RouteInfo, { caseSensitive, asServed, }?: { caseSensitive?: boolean; asServed?: boolean; }): RouteInfo[]; /** * Returns the routes that an exclusion (`MiddlewareConsumer.exclude()`, or * the `exclude` option of the CSRF protection) skips, with the paths they * are served at: the route itself and the routes excluded from the global * prefix that it covers, which the router serves without the prefix (see * `extractExcludedRoutesCoveredBy()`). Exclusions match case-sensitively * unless told otherwise, as matching too much skips the middleware. */ extractExclusionsFrom(route: RouteInfo, { caseSensitive }?: { caseSensitive?: boolean; }): RouteInfo[]; /** * Returns the version paths to mount the routes excluded from the global * prefix under for a wildcard. A wildcard limited to some versions covers * those, while any other one covers the routes of every version under the * prefix, so it has to cover them out of it too. The versions controllers * declare are not known when middleware is registered, hence the parameter. */ private getVersionPathsOfExcludedRoutes; /** * Returns the paths the router serves a route excluded from the global * prefix at: those of its pattern and, for a pattern ending in an optional * segment such as "reports/{*path}", the parent path ("/reports") (see * `isExcludedWithTrailingSlash()`). */ private getPathsOfExcludedRoute; /** * Tells whether the exclusion takes a route at the path out of the global * prefix only through a trailing slash: the router tests the root route of * a controller with one ("/reports/"), which an exclusion ending in an * optional segment matches ("reports/{*path}"), and serves it at * "/reports", which the exclusion does not match. */ private isExcludedWithTrailingSlash; getVersioningOptions(): VersioningOptions | undefined; /** * Returns the paths the router serves an excluded route at: under the * global prefix, unless the route is excluded from it, and under the * version segments of its version. A route without a version covers the * versions an unversioned route is served under (see * `getVersionOfUnversionedRoutes()`), as in `forRoutes()`. A path that * starts with a wildcard and has no version is returned as it is, without * the prefix or a version segment. */ extractPathFrom(route: RouteInfo): string[]; private isAWildcard; private extractNonWildcardPathsFrom; /** * Returns the versions a route given without a version (e.g. * `forRoutes('cats')` or `exclude('cats')`) may be served under: no * version, as for a version-neutral controller, and the default version, * under which controllers without a version are served. */ private getVersionOfUnversionedRoutes; private extractVersionPathFrom; }