import { Injectable , OnModuleInit } from '@nestjs/common' ; import { DiscoveryService } from '@nestjs/core' ; import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper' ; import { MetadataScanner } from '@nestjs/core/metadata-scanner' ; import { ProxyMetadataAccessor } from './proxy-metadata.accessor' ; import { Scanner } from '@nestcloud/common' ; import { ProxyFilterRegistry } from './proxy-filter.registry' ; import { Filter } from './interfaces/filter.interface' ; @ Injectable ( ) export class ProxyExplorer implements OnModuleInit { constructor ( private readonly discoveryService , private readonly metadataAccessor , private readonly metadataScanner , private readonly scanner , private readonly filterRegistry ) { } onModuleInit ( ) { this . explore ( ) ; } explore ( ) { const providers = [ ... this . discoveryService . getControllers ( ) , ... this . discoveryService . getProviders ( ) , ] ; providers . forEach ( ( wrapper ) => { const { instance } = wrapper ; if ( ! instance || typeof instance === 'string' ) { return ; } this . lookupFilters ( instance ) ; } ) ; } lookupFilters ( instance ) { const Filters = this . metadataAccessor . getFilters ( instance . constructor ) ; if ( Filters ) { Filters . forEach ( ref => { const filter = this . scanner . findInjectable < Filter > ( ref as Function ) ; if ( filter ) { this . filterRegistry . addFilter ( ( ref as Function ) . name , filter ) ; } } ) ; } } }