Initial commit - Event Planner application

This commit is contained in:
mberlin
2026-03-18 14:55:56 -03:00
commit 86d779eb4d
7548 changed files with 1006324 additions and 0 deletions

15
node_modules/@nestjs/core/middleware/builder.d.ts generated vendored Normal file
View File

@@ -0,0 +1,15 @@
import { HttpServer, MiddlewareConsumer, Type } from '@nestjs/common/interfaces';
import { MiddlewareConfigProxy, MiddlewareConfiguration } from '@nestjs/common/interfaces/middleware';
import { RouteInfoPathExtractor } from './route-info-path-extractor';
import { RoutesMapper } from './routes-mapper';
export declare class MiddlewareBuilder implements MiddlewareConsumer {
private readonly routesMapper;
private readonly httpAdapter;
private readonly routeInfoPathExtractor;
private readonly middlewareCollection;
constructor(routesMapper: RoutesMapper, httpAdapter: HttpServer, routeInfoPathExtractor: RouteInfoPathExtractor);
apply(...middleware: Array<Type<any> | Function | Array<Type<any> | Function>>): MiddlewareConfigProxy;
build(): MiddlewareConfiguration[];
getHttpAdapter(): HttpServer;
private static readonly ConfigProxy;
}

91
node_modules/@nestjs/core/middleware/builder.js generated vendored Normal file
View File

@@ -0,0 +1,91 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MiddlewareBuilder = void 0;
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
const iterare_1 = require("iterare");
const utils_1 = require("./utils");
class MiddlewareBuilder {
constructor(routesMapper, httpAdapter, routeInfoPathExtractor) {
this.routesMapper = routesMapper;
this.httpAdapter = httpAdapter;
this.routeInfoPathExtractor = routeInfoPathExtractor;
this.middlewareCollection = new Set();
}
apply(...middleware) {
return new MiddlewareBuilder.ConfigProxy(this, middleware.flat(), this.routeInfoPathExtractor);
}
build() {
return [...this.middlewareCollection];
}
getHttpAdapter() {
return this.httpAdapter;
}
}
exports.MiddlewareBuilder = MiddlewareBuilder;
MiddlewareBuilder.ConfigProxy = class {
constructor(builder, middleware, routeInfoPathExtractor) {
this.builder = builder;
this.middleware = middleware;
this.routeInfoPathExtractor = routeInfoPathExtractor;
this.excludedRoutes = [];
}
getExcludedRoutes() {
return this.excludedRoutes;
}
exclude(...routes) {
this.excludedRoutes = [
...this.excludedRoutes,
...this.getRoutesFlatList(routes).reduce((excludedRoutes, route) => {
for (const routePath of this.routeInfoPathExtractor.extractPathFrom(route)) {
excludedRoutes.push({
...route,
path: routePath,
});
}
return excludedRoutes;
}, []),
];
return this;
}
forRoutes(...routes) {
const { middlewareCollection } = this.builder;
const flattedRoutes = this.getRoutesFlatList(routes);
const forRoutes = this.removeOverlappedRoutes(flattedRoutes);
const configuration = {
middleware: (0, utils_1.filterMiddleware)(this.middleware, this.excludedRoutes, this.builder.getHttpAdapter()),
forRoutes,
};
middlewareCollection.add(configuration);
return this.builder;
}
getRoutesFlatList(routes) {
const { routesMapper } = this.builder;
return (0, iterare_1.iterate)(routes)
.map(route => routesMapper.mapRouteToRouteInfo(route))
.flatten()
.toArray();
}
removeOverlappedRoutes(routes) {
const regexMatchParams = /(:[^/]*)/g;
const wildcard = '([^/]*)';
const routesWithRegex = routes
.filter(route => route.path.includes(':'))
.map(route => ({
method: route.method,
path: route.path,
regex: new RegExp('^(' + route.path.replace(regexMatchParams, wildcard) + ')$', 'g'),
}));
return routes.filter(route => {
const isOverlapped = (item) => {
if (route.method !== item.method) {
return false;
}
const normalizedRoutePath = (0, shared_utils_1.stripEndSlash)(route.path);
return (normalizedRoutePath !== item.path &&
item.regex.test(normalizedRoutePath));
};
const routeMatch = routesWithRegex.find(isOverlapped);
return routeMatch === undefined;
});
}
};

14
node_modules/@nestjs/core/middleware/container.d.ts generated vendored Normal file
View File

@@ -0,0 +1,14 @@
import { InjectionToken } from '@nestjs/common';
import { MiddlewareConfiguration } from '@nestjs/common/interfaces/middleware/middleware-configuration.interface';
import { NestContainer } from '../injector/container';
import { InstanceWrapper } from '../injector/instance-wrapper';
export declare class MiddlewareContainer {
private readonly container;
private readonly middleware;
private readonly configurationSets;
constructor(container: NestContainer);
getMiddlewareCollection(moduleKey: string): Map<InjectionToken, InstanceWrapper>;
getConfigurations(): Map<string, Set<MiddlewareConfiguration>>;
insertConfig(configList: MiddlewareConfiguration[], moduleKey: string): void;
private getTargetConfig;
}

49
node_modules/@nestjs/core/middleware/container.js generated vendored Normal file
View File

@@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MiddlewareContainer = void 0;
const get_class_scope_1 = require("../helpers/get-class-scope");
const is_durable_1 = require("../helpers/is-durable");
const instance_wrapper_1 = require("../injector/instance-wrapper");
class MiddlewareContainer {
constructor(container) {
this.container = container;
this.middleware = new Map();
this.configurationSets = new Map();
}
getMiddlewareCollection(moduleKey) {
if (!this.middleware.has(moduleKey)) {
const moduleRef = this.container.getModuleByKey(moduleKey);
this.middleware.set(moduleKey, moduleRef.middlewares);
}
return this.middleware.get(moduleKey);
}
getConfigurations() {
return this.configurationSets;
}
insertConfig(configList, moduleKey) {
const middleware = this.getMiddlewareCollection(moduleKey);
const targetConfig = this.getTargetConfig(moduleKey);
const configurations = configList || [];
const insertMiddleware = (metatype) => {
const token = metatype;
middleware.set(token, new instance_wrapper_1.InstanceWrapper({
scope: (0, get_class_scope_1.getClassScope)(metatype),
durable: (0, is_durable_1.isDurable)(metatype),
name: token?.name ?? token,
metatype,
token,
}));
};
configurations.forEach(config => {
[].concat(config.middleware).map(insertMiddleware);
targetConfig.add(config);
});
}
getTargetConfig(moduleName) {
if (!this.configurationSets.has(moduleName)) {
this.configurationSets.set(moduleName, new Set());
}
return this.configurationSets.get(moduleName);
}
}
exports.MiddlewareContainer = MiddlewareContainer;

1
node_modules/@nestjs/core/middleware/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export * from './builder';

4
node_modules/@nestjs/core/middleware/index.js generated vendored Normal file
View File

@@ -0,0 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./builder"), exports);

View File

@@ -0,0 +1,33 @@
import { HttpServer } from '@nestjs/common';
import { MiddlewareConfiguration, RouteInfo } from '@nestjs/common/interfaces/middleware';
import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
import { ApplicationConfig } from '../application-config';
import { NestContainer } from '../injector/container';
import { Injector } from '../injector/injector';
import { Module } from '../injector/module';
import { GraphInspector } from '../inspector/graph-inspector';
import { MiddlewareContainer } from './container';
export declare class MiddlewareModule<TAppOptions extends NestApplicationContextOptions = NestApplicationContextOptions> {
private readonly routerProxy;
private readonly exceptionFiltersCache;
private readonly logger;
private injector;
private routerExceptionFilter;
private routesMapper;
private resolver;
private container;
private httpAdapter;
private graphInspector;
private appOptions;
private routeInfoPathExtractor;
register(middlewareContainer: MiddlewareContainer, container: NestContainer, config: ApplicationConfig, injector: Injector, httpAdapter: HttpServer, graphInspector: GraphInspector, options: TAppOptions): Promise<void>;
resolveMiddleware(middlewareContainer: MiddlewareContainer, modules: Map<string, Module>): Promise<void>;
loadConfiguration(middlewareContainer: MiddlewareContainer, moduleRef: Module, moduleKey: string): Promise<void>;
registerMiddleware(middlewareContainer: MiddlewareContainer, applicationRef: any): Promise<void>;
registerMiddlewareConfig(middlewareContainer: MiddlewareContainer, config: MiddlewareConfiguration, moduleKey: string, applicationRef: any): Promise<void>;
registerRouteMiddleware(middlewareContainer: MiddlewareContainer, routeInfo: RouteInfo, config: MiddlewareConfiguration, moduleKey: string, applicationRef: any): Promise<void>;
private bindHandler;
private createProxy;
private registerHandler;
private getContextId;
}

View File

@@ -0,0 +1,208 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MiddlewareModule = void 0;
const common_1 = require("@nestjs/common");
const request_method_enum_1 = require("@nestjs/common/enums/request-method.enum");
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
const invalid_middleware_exception_1 = require("../errors/exceptions/invalid-middleware.exception");
const runtime_exception_1 = require("../errors/exceptions/runtime.exception");
const context_id_factory_1 = require("../helpers/context-id-factory");
const execution_context_host_1 = require("../helpers/execution-context-host");
const constants_1 = require("../injector/constants");
const request_constants_1 = require("../router/request/request-constants");
const router_exception_filters_1 = require("../router/router-exception-filters");
const router_proxy_1 = require("../router/router-proxy");
const utils_1 = require("../router/utils");
const builder_1 = require("./builder");
const resolver_1 = require("./resolver");
const route_info_path_extractor_1 = require("./route-info-path-extractor");
const routes_mapper_1 = require("./routes-mapper");
class MiddlewareModule {
constructor() {
this.routerProxy = new router_proxy_1.RouterProxy();
this.exceptionFiltersCache = new WeakMap();
this.logger = new common_1.Logger(MiddlewareModule.name);
}
async register(middlewareContainer, container, config, injector, httpAdapter, graphInspector, options) {
this.appOptions = options;
const appRef = container.getHttpAdapterRef();
this.routerExceptionFilter = new router_exception_filters_1.RouterExceptionFilters(container, config, appRef);
this.routesMapper = new routes_mapper_1.RoutesMapper(container, config);
this.resolver = new resolver_1.MiddlewareResolver(middlewareContainer, injector);
this.routeInfoPathExtractor = new route_info_path_extractor_1.RouteInfoPathExtractor(config);
this.injector = injector;
this.container = container;
this.httpAdapter = httpAdapter;
this.graphInspector = graphInspector;
const modules = container.getModules();
await this.resolveMiddleware(middlewareContainer, modules);
}
async resolveMiddleware(middlewareContainer, modules) {
const moduleEntries = [...modules.entries()];
const loadMiddlewareConfiguration = async ([moduleName, moduleRef]) => {
await this.loadConfiguration(middlewareContainer, moduleRef, moduleName);
await this.resolver.resolveInstances(moduleRef, moduleName);
};
await Promise.all(moduleEntries.map(loadMiddlewareConfiguration));
}
async loadConfiguration(middlewareContainer, moduleRef, moduleKey) {
const { instance } = moduleRef;
if (!instance.configure) {
return;
}
const middlewareBuilder = new builder_1.MiddlewareBuilder(this.routesMapper, this.httpAdapter, this.routeInfoPathExtractor);
try {
await instance.configure(middlewareBuilder);
}
catch (err) {
if (!this.appOptions.preview) {
throw err;
}
const warningMessage = `Warning! "${moduleRef.name}" module exposes a "configure" method that throws an exception in the preview mode` +
` (possibly due to missing dependencies). Note: you can ignore this message, just be aware that some of those conditional middlewares will not be reflected in your graph.`;
this.logger.warn(warningMessage);
}
if (!(middlewareBuilder instanceof builder_1.MiddlewareBuilder)) {
return;
}
const config = middlewareBuilder.build();
middlewareContainer.insertConfig(config, moduleKey);
}
async registerMiddleware(middlewareContainer, applicationRef) {
const configs = middlewareContainer.getConfigurations();
const registerAllConfigs = async (moduleKey, middlewareConfig) => {
for (const config of middlewareConfig) {
await this.registerMiddlewareConfig(middlewareContainer, config, moduleKey, applicationRef);
}
};
const entriesSortedByDistance = [...configs.entries()].sort(([moduleA], [moduleB]) => {
const moduleARef = this.container.getModuleByKey(moduleA);
const moduleBRef = this.container.getModuleByKey(moduleB);
const isModuleAGlobal = moduleARef.distance === Number.MAX_VALUE;
const isModuleBGlobal = moduleBRef.distance === Number.MAX_VALUE;
if (isModuleAGlobal && isModuleBGlobal) {
return 0;
}
if (isModuleAGlobal) {
return -1;
}
if (isModuleBGlobal) {
return 1;
}
return moduleARef.distance - moduleBRef.distance;
});
for (const [moduleRef, moduleConfigurations] of entriesSortedByDistance) {
await registerAllConfigs(moduleRef, [...moduleConfigurations]);
}
}
async registerMiddlewareConfig(middlewareContainer, config, moduleKey, applicationRef) {
const { forRoutes } = config;
for (const routeInfo of forRoutes) {
await this.registerRouteMiddleware(middlewareContainer, routeInfo, config, moduleKey, applicationRef);
}
}
async registerRouteMiddleware(middlewareContainer, routeInfo, config, moduleKey, applicationRef) {
const middlewareCollection = [].concat(config.middleware);
const moduleRef = this.container.getModuleByKey(moduleKey);
for (const metatype of middlewareCollection) {
const collection = middlewareContainer.getMiddlewareCollection(moduleKey);
const instanceWrapper = collection.get(metatype);
if ((0, shared_utils_1.isUndefined)(instanceWrapper)) {
throw new runtime_exception_1.RuntimeException();
}
if (instanceWrapper.isTransient) {
return;
}
this.graphInspector.insertClassNode(moduleRef, instanceWrapper, 'middleware');
const middlewareDefinition = {
type: 'middleware',
methodName: 'use',
className: instanceWrapper.name,
classNodeId: instanceWrapper.id,
metadata: {
key: routeInfo.path,
path: routeInfo.path,
requestMethod: request_method_enum_1.RequestMethod[routeInfo.method] ??
'ALL',
version: routeInfo.version,
},
};
this.graphInspector.insertEntrypointDefinition(middlewareDefinition, instanceWrapper.id);
await this.bindHandler(instanceWrapper, applicationRef, routeInfo, moduleRef, collection);
}
}
async bindHandler(wrapper, applicationRef, routeInfo, moduleRef, collection) {
const { instance, metatype } = wrapper;
if ((0, shared_utils_1.isUndefined)(instance?.use)) {
throw new invalid_middleware_exception_1.InvalidMiddlewareException(metatype.name);
}
const isStatic = wrapper.isDependencyTreeStatic();
if (isStatic) {
const proxy = await this.createProxy(instance);
return this.registerHandler(applicationRef, routeInfo, proxy);
}
const isTreeDurable = wrapper.isDependencyTreeDurable();
await this.registerHandler(applicationRef, routeInfo, async (req, res, next) => {
try {
const contextId = this.getContextId(req, isTreeDurable);
const contextInstance = await this.injector.loadPerContext(instance, moduleRef, collection, contextId);
const proxy = await this.createProxy(contextInstance, contextId);
return proxy(req, res, next);
}
catch (err) {
let exceptionsHandler = this.exceptionFiltersCache.get(instance.use);
if (!exceptionsHandler) {
exceptionsHandler = this.routerExceptionFilter.create(instance, instance.use, undefined);
this.exceptionFiltersCache.set(instance.use, exceptionsHandler);
}
const host = new execution_context_host_1.ExecutionContextHost([req, res, next]);
exceptionsHandler.next(err, host);
}
});
}
async createProxy(instance, contextId = constants_1.STATIC_CONTEXT) {
const exceptionsHandler = this.routerExceptionFilter.create(instance, instance.use, undefined, contextId);
const middleware = instance.use.bind(instance);
return this.routerProxy.createProxy(middleware, exceptionsHandler);
}
async registerHandler(applicationRef, routeInfo, proxy) {
const { method } = routeInfo;
const paths = this.routeInfoPathExtractor.extractPathsFrom(routeInfo);
const isMethodAll = (0, utils_1.isRequestMethodAll)(method);
const requestMethod = request_method_enum_1.RequestMethod[method];
const router = await applicationRef.createMiddlewareFactory(method);
const middlewareFunction = isMethodAll
? proxy
: (req, res, next) => {
const actualRequestMethod = applicationRef.getRequestMethod?.(req);
if (actualRequestMethod === requestMethod ||
(actualRequestMethod === request_method_enum_1.RequestMethod[request_method_enum_1.RequestMethod.HEAD] &&
requestMethod === request_method_enum_1.RequestMethod[request_method_enum_1.RequestMethod.GET])) {
return proxy(req, res, next);
}
return next();
};
const pathsToApplyMiddleware = [];
paths.some(path => path.match(/^\/?$/))
? pathsToApplyMiddleware.push('/')
: pathsToApplyMiddleware.push(...paths);
pathsToApplyMiddleware.forEach(path => router(path, middlewareFunction));
}
getContextId(request, isTreeDurable) {
const contextId = context_id_factory_1.ContextIdFactory.getByRequest(request);
if (!request[request_constants_1.REQUEST_CONTEXT_ID]) {
Object.defineProperty(request, request_constants_1.REQUEST_CONTEXT_ID, {
value: contextId,
enumerable: false,
writable: false,
configurable: false,
});
const requestProviderValue = isTreeDurable
? contextId.payload
: Object.assign(request, contextId.payload);
this.container.registerRequestProvider(requestProviderValue, contextId);
}
return contextId;
}
}
exports.MiddlewareModule = MiddlewareModule;

10
node_modules/@nestjs/core/middleware/resolver.d.ts generated vendored Normal file
View File

@@ -0,0 +1,10 @@
import { Injector } from '../injector/injector';
import { Module } from '../injector/module';
import { MiddlewareContainer } from './container';
export declare class MiddlewareResolver {
private readonly middlewareContainer;
private readonly injector;
constructor(middlewareContainer: MiddlewareContainer, injector: Injector);
resolveInstances(moduleRef: Module, moduleName: string): Promise<void>;
private resolveMiddlewareInstance;
}

18
node_modules/@nestjs/core/middleware/resolver.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MiddlewareResolver = void 0;
class MiddlewareResolver {
constructor(middlewareContainer, injector) {
this.middlewareContainer = middlewareContainer;
this.injector = injector;
}
async resolveInstances(moduleRef, moduleName) {
const middlewareMap = this.middlewareContainer.getMiddlewareCollection(moduleName);
const resolveInstance = async (wrapper) => this.resolveMiddlewareInstance(wrapper, middlewareMap, moduleRef);
await Promise.all([...middlewareMap.values()].map(resolveInstance));
}
async resolveMiddlewareInstance(wrapper, middlewareMap, moduleRef) {
await this.injector.loadMiddleware(wrapper, middlewareMap, moduleRef);
}
}
exports.MiddlewareResolver = MiddlewareResolver;

View File

@@ -0,0 +1,15 @@
import { RouteInfo } from '@nestjs/common/interfaces';
import { ApplicationConfig } from '../application-config';
export declare class RouteInfoPathExtractor {
private readonly applicationConfig;
private readonly routePathFactory;
private readonly prefixPath;
private readonly excludedGlobalPrefixRoutes;
private readonly versioningConfig?;
constructor(applicationConfig: ApplicationConfig);
extractPathsFrom({ path, method, version }: RouteInfo): string[];
extractPathFrom(route: RouteInfo): string[];
private isAWildcard;
private extractNonWildcardPathsFrom;
private extractVersionPathFrom;
}

View File

@@ -0,0 +1,81 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RouteInfoPathExtractor = void 0;
const common_1 = require("@nestjs/common");
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
const utils_1 = require("../router/utils");
const route_path_factory_1 = require("./../router/route-path-factory");
class RouteInfoPathExtractor {
constructor(applicationConfig) {
this.applicationConfig = applicationConfig;
this.routePathFactory = new route_path_factory_1.RoutePathFactory(applicationConfig);
this.prefixPath = (0, shared_utils_1.stripEndSlash)((0, shared_utils_1.addLeadingSlash)(this.applicationConfig.getGlobalPrefix()));
this.excludedGlobalPrefixRoutes =
this.applicationConfig.getGlobalPrefixOptions().exclude;
this.versioningConfig = this.applicationConfig.getVersioning();
}
extractPathsFrom({ path, method, version }) {
const versionPaths = this.extractVersionPathFrom(version);
if (this.isAWildcard(path)) {
const entries = versionPaths.length > 0
? versionPaths
.map(versionPath => [
this.prefixPath + versionPath + '$',
this.prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path),
])
.flat()
: this.prefixPath
? [this.prefixPath + '$', this.prefixPath + (0, shared_utils_1.addLeadingSlash)(path)]
: [(0, shared_utils_1.addLeadingSlash)(path)];
return Array.isArray(this.excludedGlobalPrefixRoutes)
? [
...entries,
...this.excludedGlobalPrefixRoutes
.map(route => Array.isArray(versionPaths) && versionPaths.length > 0
? versionPaths.map(v => v + (0, shared_utils_1.addLeadingSlash)(route.path))
: (0, shared_utils_1.addLeadingSlash)(route.path))
.flat(),
]
: entries;
}
return this.extractNonWildcardPathsFrom({ path, method, version });
}
extractPathFrom(route) {
if (this.isAWildcard(route.path) && !route.version) {
return [(0, shared_utils_1.addLeadingSlash)(route.path)];
}
return this.extractNonWildcardPathsFrom(route);
}
isAWildcard(path) {
const isSimpleWildcard = ['*', '/*', '/*/', '(.*)', '/(.*)'];
if (isSimpleWildcard.includes(path)) {
return true;
}
const wildcardRegexp = /^\/\{.*\}.*|^\/\*.*$/;
return wildcardRegexp.test(path);
}
extractNonWildcardPathsFrom({ path, method, version, }) {
const versionPaths = this.extractVersionPathFrom(version);
if (Array.isArray(this.excludedGlobalPrefixRoutes) &&
(0, utils_1.isRouteExcluded)(this.excludedGlobalPrefixRoutes, path, method)) {
if (!versionPaths.length) {
return [(0, shared_utils_1.addLeadingSlash)(path)];
}
return versionPaths.map(versionPath => versionPath + (0, shared_utils_1.addLeadingSlash)(path));
}
if (!versionPaths.length) {
return [this.prefixPath + (0, shared_utils_1.addLeadingSlash)(path)];
}
return versionPaths.map(versionPath => this.prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path));
}
extractVersionPathFrom(versionValue) {
if (!versionValue || this.versioningConfig?.type !== common_1.VersioningType.URI)
return [];
const versionPrefix = this.routePathFactory.getVersionPrefix(this.versioningConfig);
if (Array.isArray(versionValue)) {
return versionValue.map(version => (0, shared_utils_1.addLeadingSlash)(versionPrefix + version.toString()));
}
return [(0, shared_utils_1.addLeadingSlash)(versionPrefix + versionValue.toString())];
}
}
exports.RouteInfoPathExtractor = RouteInfoPathExtractor;

View File

@@ -0,0 +1,19 @@
import { RouteInfo, Type } from '@nestjs/common/interfaces';
import { ApplicationConfig } from '../application-config';
import { NestContainer } from '../injector/container';
export declare class RoutesMapper {
private readonly container;
private readonly applicationConfig;
private readonly pathsExplorer;
constructor(container: NestContainer, applicationConfig: ApplicationConfig);
mapRouteToRouteInfo(controllerOrRoute: Type<any> | RouteInfo | string): RouteInfo[];
private getRouteInfoFromPath;
private getRouteInfoFromObject;
private getRouteInfoFromController;
private isRouteInfo;
private normalizeGlobalPath;
private getRoutePath;
private getHostModuleOfController;
private getModulePath;
private getVersionMetadata;
}

117
node_modules/@nestjs/core/middleware/routes-mapper.js generated vendored Normal file
View File

@@ -0,0 +1,117 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RoutesMapper = void 0;
const constants_1 = require("@nestjs/common/constants");
const interfaces_1 = require("@nestjs/common/interfaces");
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
const metadata_scanner_1 = require("../metadata-scanner");
const paths_explorer_1 = require("../router/paths-explorer");
const router_module_1 = require("../router/router-module");
class RoutesMapper {
constructor(container, applicationConfig) {
this.container = container;
this.applicationConfig = applicationConfig;
this.pathsExplorer = new paths_explorer_1.PathsExplorer(new metadata_scanner_1.MetadataScanner());
}
mapRouteToRouteInfo(controllerOrRoute) {
if ((0, shared_utils_1.isString)(controllerOrRoute)) {
return this.getRouteInfoFromPath(controllerOrRoute);
}
const routePathOrPaths = this.getRoutePath(controllerOrRoute);
if (this.isRouteInfo(routePathOrPaths, controllerOrRoute)) {
return this.getRouteInfoFromObject(controllerOrRoute);
}
return this.getRouteInfoFromController(controllerOrRoute, routePathOrPaths);
}
getRouteInfoFromPath(routePath) {
const defaultRequestMethod = -1;
return [
{
path: (0, shared_utils_1.addLeadingSlash)(routePath),
method: defaultRequestMethod,
},
];
}
getRouteInfoFromObject(routeInfoObject) {
const routeInfo = {
path: (0, shared_utils_1.addLeadingSlash)(routeInfoObject.path),
method: routeInfoObject.method,
};
if (routeInfoObject.version) {
routeInfo.version = routeInfoObject.version;
}
return [routeInfo];
}
getRouteInfoFromController(controller, routePath) {
const controllerPaths = this.pathsExplorer.scanForPaths(Object.create(controller), controller.prototype);
const controllerVersion = this.getVersionMetadata(controller);
const versioningConfig = this.applicationConfig.getVersioning();
const moduleRef = this.getHostModuleOfController(controller);
const modulePath = this.getModulePath(moduleRef?.metatype);
const concatPaths = (acc, currentValue) => acc.concat(currentValue);
const toUndefinedIfNeural = (version) => version === interfaces_1.VERSION_NEUTRAL ? undefined : version;
const toRouteInfo = (item, prefix) => item.path?.flatMap(p => {
let endpointPath = modulePath ?? '';
endpointPath += this.normalizeGlobalPath(prefix) + (0, shared_utils_1.addLeadingSlash)(p);
const routeInfo = {
path: endpointPath,
method: item.requestMethod,
};
const version = item.version ?? controllerVersion;
if (version && versioningConfig) {
if (typeof version !== 'string' && Array.isArray(version)) {
return version.map(v => ({
...routeInfo,
version: toUndefinedIfNeural(v),
}));
}
routeInfo.version = toUndefinedIfNeural(version);
}
return routeInfo;
});
return []
.concat(routePath)
.map(routePath => controllerPaths
.map(item => toRouteInfo(item, routePath))
.reduce(concatPaths, []))
.reduce(concatPaths, []);
}
isRouteInfo(path, objectOrClass) {
return (0, shared_utils_1.isUndefined)(path);
}
normalizeGlobalPath(path) {
const prefix = (0, shared_utils_1.addLeadingSlash)(path);
return prefix === '/' ? '' : prefix;
}
getRoutePath(route) {
return Reflect.getMetadata(constants_1.PATH_METADATA, route);
}
getHostModuleOfController(metatype) {
if (!metatype) {
return;
}
const modulesContainer = this.container.getModules();
const moduleRefsSet = router_module_1.targetModulesByContainer.get(modulesContainer);
if (!moduleRefsSet) {
return;
}
const modules = Array.from(modulesContainer.values()).filter(moduleRef => moduleRefsSet.has(moduleRef));
return modules.find(({ controllers }) => controllers.has(metatype));
}
getModulePath(metatype) {
if (!metatype) {
return;
}
const modulesContainer = this.container.getModules();
const modulePath = Reflect.getMetadata(constants_1.MODULE_PATH + modulesContainer.applicationId, metatype);
return modulePath ?? Reflect.getMetadata(constants_1.MODULE_PATH, metatype);
}
getVersionMetadata(metatype) {
const versioningConfig = this.applicationConfig.getVersioning();
if (versioningConfig) {
return (Reflect.getMetadata(constants_1.VERSION_METADATA, metatype) ??
versioningConfig.defaultVersion);
}
}
}
exports.RoutesMapper = RoutesMapper;

8
node_modules/@nestjs/core/middleware/utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
import { HttpServer, RouteInfo, Type } from '@nestjs/common/interfaces';
import { ExcludeRouteMetadata } from '../router/interfaces/exclude-route-metadata.interface';
export declare const mapToExcludeRoute: (routes: (string | RouteInfo)[]) => ExcludeRouteMetadata[];
export declare const filterMiddleware: <T extends Function | Type<any> = any>(middleware: T[], routes: RouteInfo[], httpAdapter: HttpServer) => Type<any>[];
export declare const mapToClass: <T extends Function | Type<any>>(middleware: T, excludedRoutes: ExcludeRouteMetadata[], httpAdapter: HttpServer) => Type<any>;
export declare function isMiddlewareClass(middleware: any): middleware is Type<any>;
export declare function assignToken(metatype: Type<any>, token?: string): Type<any>;
export declare function isMiddlewareRouteExcluded(req: Record<string, any>, excludedRoutes: ExcludeRouteMetadata[], httpAdapter: HttpServer): boolean;

106
node_modules/@nestjs/core/middleware/utils.js generated vendored Normal file
View File

@@ -0,0 +1,106 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mapToClass = exports.filterMiddleware = exports.mapToExcludeRoute = void 0;
exports.isMiddlewareClass = isMiddlewareClass;
exports.assignToken = assignToken;
exports.isMiddlewareRouteExcluded = isMiddlewareRouteExcluded;
const common_1 = require("@nestjs/common");
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
const iterare_1 = require("iterare");
const path_to_regexp_1 = require("path-to-regexp");
const uid_1 = require("uid");
const legacy_route_converter_1 = require("../router/legacy-route-converter");
const utils_1 = require("../router/utils");
const mapToExcludeRoute = (routes) => {
return routes.map(route => {
const originalPath = (0, shared_utils_1.isString)(route) ? route : route.path;
const path = legacy_route_converter_1.LegacyRouteConverter.tryConvert(originalPath);
try {
if ((0, shared_utils_1.isString)(route)) {
return {
path,
requestMethod: common_1.RequestMethod.ALL,
pathRegex: (0, path_to_regexp_1.pathToRegexp)((0, shared_utils_1.addLeadingSlash)(path)).regexp,
};
}
return {
path,
requestMethod: route.method,
pathRegex: (0, path_to_regexp_1.pathToRegexp)((0, shared_utils_1.addLeadingSlash)(path)).regexp,
};
}
catch (e) {
if (e instanceof TypeError) {
legacy_route_converter_1.LegacyRouteConverter.printError(originalPath);
}
throw e;
}
});
};
exports.mapToExcludeRoute = mapToExcludeRoute;
const filterMiddleware = (middleware, routes, httpAdapter) => {
const excludedRoutes = (0, exports.mapToExcludeRoute)(routes);
return (0, iterare_1.iterate)([])
.concat(middleware)
.filter(shared_utils_1.isFunction)
.map((item) => (0, exports.mapToClass)(item, excludedRoutes, httpAdapter))
.toArray();
};
exports.filterMiddleware = filterMiddleware;
const mapToClass = (middleware, excludedRoutes, httpAdapter) => {
if (isMiddlewareClass(middleware)) {
if (excludedRoutes.length <= 0) {
return middleware;
}
const MiddlewareHost = class extends middleware {
use(...params) {
const [req, _, next] = params;
const isExcluded = isMiddlewareRouteExcluded(req, excludedRoutes, httpAdapter);
if (isExcluded) {
return next();
}
return super.use(...params);
}
};
return assignToken(MiddlewareHost, middleware.name);
}
return assignToken(class {
constructor() {
this.use = (...params) => {
const [req, _, next] = params;
const isExcluded = isMiddlewareRouteExcluded(req, excludedRoutes, httpAdapter);
if (isExcluded) {
return next();
}
return middleware(...params);
};
}
});
};
exports.mapToClass = mapToClass;
function isMiddlewareClass(middleware) {
const middlewareStr = middleware.toString();
if (middlewareStr.substring(0, 5) === 'class') {
return true;
}
const middlewareArr = middlewareStr.split(' ');
return (middlewareArr[0] === 'function' &&
/[A-Z]/.test(middlewareArr[1]?.[0]) &&
(0, shared_utils_1.isFunction)(middleware.prototype?.use));
}
function assignToken(metatype, token = (0, uid_1.uid)(21)) {
Object.defineProperty(metatype, 'name', { value: token });
return metatype;
}
function isMiddlewareRouteExcluded(req, excludedRoutes, httpAdapter) {
if (excludedRoutes.length <= 0) {
return false;
}
const reqMethod = httpAdapter.getRequestMethod(req);
const originalUrl = httpAdapter.getRequestUrl(req);
const queryParamsIndex = originalUrl ? originalUrl.indexOf('?') : -1;
const pathname = queryParamsIndex >= 0
? originalUrl.slice(0, queryParamsIndex)
: originalUrl;
return (0, utils_1.isRouteExcluded)(excludedRoutes, pathname, common_1.RequestMethod[reqMethod]);
}