import type { CanActivate, ExceptionFilter, NestInterceptor, PipeTransform, VersioningOptions, WebSocketAdapter, } from '@nestjs/common'; import { InstanceWrapper } from './injector/instance-wrapper.js'; import { ExcludeRouteMetadata } from './router/interfaces/exclude-route-metadata.interface.js'; import type { GlobalPrefixOptions } from '@nestjs/common/internal'; export class ApplicationConfig { private globalPrefix = ''; private globalPrefixOptions: GlobalPrefixOptions = {}; private globalPipes: Array = []; private globalFilters: Array = []; private globalInterceptors: Array = []; private globalGuards: Array = []; private versioningOptions: VersioningOptions; private readonly globalRequestPipes: InstanceWrapper[] = []; private readonly globalRequestFilters: InstanceWrapper[] = []; private readonly globalRequestInterceptors: InstanceWrapper[] = []; private readonly globalRequestGuards: InstanceWrapper[] = []; constructor(private ioAdapter: WebSocketAdapter | null = null) {} public setGlobalPrefix(prefix: string) { this.globalPrefix = prefix; } public getGlobalPrefix() { return this.globalPrefix; } public setGlobalPrefixOptions( options: GlobalPrefixOptions, ) { this.globalPrefixOptions = options; } public getGlobalPrefixOptions(): GlobalPrefixOptions { return this.globalPrefixOptions; } public setIoAdapter(ioAdapter: WebSocketAdapter) { this.ioAdapter = ioAdapter; } public getIoAdapter(): WebSocketAdapter { return this.ioAdapter!; } public addGlobalPipe(pipe: PipeTransform) { this.globalPipes.push(pipe); } public useGlobalPipes(...pipes: PipeTransform[]) { this.globalPipes = this.globalPipes.concat(pipes); } public getGlobalFilters(): ExceptionFilter[] { return this.globalFilters; } public addGlobalFilter(filter: ExceptionFilter) { this.globalFilters.push(filter); } public useGlobalFilters(...filters: ExceptionFilter[]) { this.globalFilters = this.globalFilters.concat(filters); } public getGlobalPipes(): PipeTransform[] { return this.globalPipes; } public getGlobalInterceptors(): NestInterceptor[] { return this.globalInterceptors; } public addGlobalInterceptor(interceptor: NestInterceptor) { this.globalInterceptors.push(interceptor); } public useGlobalInterceptors(...interceptors: NestInterceptor[]) { this.globalInterceptors = this.globalInterceptors.concat(interceptors); } public getGlobalGuards(): CanActivate[] { return this.globalGuards; } public addGlobalGuard(guard: CanActivate) { this.globalGuards.push(guard); } public useGlobalGuards(...guards: CanActivate[]) { this.globalGuards = this.globalGuards.concat(guards); } public addGlobalRequestInterceptor( wrapper: InstanceWrapper, ) { this.globalRequestInterceptors.push(wrapper); } public getGlobalRequestInterceptors(): InstanceWrapper[] { return this.globalRequestInterceptors; } public addGlobalRequestPipe(wrapper: InstanceWrapper) { this.globalRequestPipes.push(wrapper); } public getGlobalRequestPipes(): InstanceWrapper[] { return this.globalRequestPipes; } public addGlobalRequestFilter(wrapper: InstanceWrapper) { this.globalRequestFilters.push(wrapper); } public getGlobalRequestFilters(): InstanceWrapper[] { return this.globalRequestFilters; } public addGlobalRequestGuard(wrapper: InstanceWrapper) { this.globalRequestGuards.push(wrapper); } public getGlobalRequestGuards(): InstanceWrapper[] { return this.globalRequestGuards; } public enableVersioning(options: VersioningOptions): void { if (Array.isArray(options.defaultVersion)) { // Drop duplicated versions options.defaultVersion = Array.from(new Set(options.defaultVersion)); } this.versioningOptions = options; } public getVersioning(): VersioningOptions | undefined { return this.versioningOptions; } }