@@ -18,7 +18,7 @@ export class DependenciesScanner {
1818 this . scanModulesForDependencies ( ) ;
1919 }
2020
21- private scanForModules ( module : NestModuleMetatype , scope : NestModuleMetatype [ ] = [ ] ) {
21+ public scanForModules ( module : NestModuleMetatype , scope : NestModuleMetatype [ ] = [ ] ) {
2222 this . storeModule ( module , scope ) ;
2323
2424 const importedModules = this . reflectMetadata ( module , metadata . MODULES ) ;
@@ -27,11 +27,11 @@ export class DependenciesScanner {
2727 } ) ;
2828 }
2929
30- private storeModule ( module : NestModuleMetatype , scope : NestModuleMetatype [ ] ) {
30+ public storeModule ( module : NestModuleMetatype , scope : NestModuleMetatype [ ] ) {
3131 this . container . addModule ( module , scope ) ;
3232 }
3333
34- private scanModulesForDependencies ( ) {
34+ public scanModulesForDependencies ( ) {
3535 const modules = this . container . getModules ( ) ;
3636
3737 modules . forEach ( ( { metatype } , token ) => {
@@ -42,12 +42,12 @@ export class DependenciesScanner {
4242 } ) ;
4343 }
4444
45- private reflectRelatedModules ( module : NestModuleMetatype , token : string ) {
45+ public reflectRelatedModules ( module : NestModuleMetatype , token : string ) {
4646 const modules = this . reflectMetadata ( module , metadata . MODULES ) ;
4747 modules . map ( ( related ) => this . storeRelatedModule ( related , token ) ) ;
4848 }
4949
50- private reflectComponents ( module : NestModuleMetatype , token : string ) {
50+ public reflectComponents ( module : NestModuleMetatype , token : string ) {
5151 const components = this . reflectMetadata ( module , metadata . COMPONENTS ) ;
5252 components . map ( ( component ) => {
5353 this . storeComponent ( component , token ) ;
@@ -56,80 +56,79 @@ export class DependenciesScanner {
5656 } ) ;
5757 }
5858
59- private reflectComponentMetadata ( component : Metatype < Injectable > , token : string ) {
59+ public reflectComponentMetadata ( component : Metatype < Injectable > , token : string ) {
6060 this . reflectGatewaysMiddlewares ( component , token ) ;
6161 }
6262
63- private reflectControllers ( module : NestModuleMetatype , token : string ) {
63+ public reflectControllers ( module : NestModuleMetatype , token : string ) {
6464 const routes = this . reflectMetadata ( module , metadata . CONTROLLERS ) ;
6565 routes . map ( ( route ) => {
6666 this . storeRoute ( route , token ) ;
6767 this . reflectDynamicMetadata ( route , token ) ;
6868 } ) ;
6969 }
7070
71- private reflectDynamicMetadata ( obj : Metatype < Injectable > , token : string ) {
71+ public reflectDynamicMetadata ( obj : Metatype < Injectable > , token : string ) {
7272 if ( ! obj . prototype ) { return ; }
7373
7474 this . reflectGuards ( obj , token ) ;
7575 this . reflectInterceptors ( obj , token ) ;
7676 }
7777
78- private reflectExports ( module : NestModuleMetatype , token : string ) {
78+ public reflectExports ( module : NestModuleMetatype , token : string ) {
7979 const exports = this . reflectMetadata ( module , metadata . EXPORTS ) ;
8080 exports . map ( ( exportedComponent ) => this . storeExportedComponent ( exportedComponent , token ) ) ;
8181 }
8282
83- private reflectGatewaysMiddlewares ( component : Metatype < Injectable > , token : string ) {
83+ public reflectGatewaysMiddlewares ( component : Metatype < Injectable > , token : string ) {
8484 const middlewares = this . reflectMetadata ( component , GATEWAY_MIDDLEWARES ) ;
8585 middlewares . map ( ( middleware ) => this . storeComponent ( middleware , token ) ) ;
8686 }
8787
88- private reflectGuards ( component : Metatype < Injectable > , token : string ) {
88+ public reflectGuards ( component : Metatype < Injectable > , token : string ) {
8989 const controllerGuards = this . reflectMetadata ( component , GUARDS_METADATA ) ;
90- const methodsGuards = this . metadataScanner . scanFromPrototype ( null , component . prototype ,
91- ( method : string ) => {
92- const descriptor = Reflect . getOwnPropertyDescriptor ( component . prototype , method ) ;
93- return descriptor ? Reflect . getMetadata ( GUARDS_METADATA , descriptor . value ) : undefined ;
94- } ,
90+ const methodsGuards = this . metadataScanner . scanFromPrototype (
91+ null , component . prototype , this . reflectKeyMetadata . bind ( this , component , GUARDS_METADATA ) ,
9592 ) ;
96- const flattenMethodsGuards = methodsGuards . reduce ( ( a , b ) => a . concat ( b ) , [ ] ) ;
93+ const flattenMethodsGuards = methodsGuards . reduce < any [ ] > ( ( a : any [ ] , b ) => a . concat ( b ) , [ ] ) ;
9794 [ ...controllerGuards , ...flattenMethodsGuards ] . map ( ( guard ) => this . storeInjectable ( guard , token ) ) ;
9895 }
9996
100- private reflectInterceptors ( component : Metatype < Injectable > , token : string ) {
97+ public reflectInterceptors ( component : Metatype < Injectable > , token : string ) {
10198 const controllerInterceptors = this . reflectMetadata ( component , INTERCEPTORS_METADATA ) ;
102- const methodsInterceptors = this . metadataScanner . scanFromPrototype ( null , component . prototype ,
103- ( method : string ) => {
104- const descriptor = Reflect . getOwnPropertyDescriptor ( component . prototype , method ) ;
105- return descriptor ? Reflect . getMetadata ( INTERCEPTORS_METADATA , descriptor . value ) : undefined ;
106- } ,
99+ const methodsInterceptors = this . metadataScanner . scanFromPrototype (
100+ null , component . prototype , this . reflectKeyMetadata . bind ( this , component , INTERCEPTORS_METADATA ) ,
107101 ) ;
108- const flattenMethodsInterceptors = methodsInterceptors . reduce ( ( a , b ) => a . concat ( b ) , [ ] ) ;
102+ const flattenMethodsInterceptors = methodsInterceptors . reduce < any [ ] > ( ( a : any [ ] , b ) => a . concat ( b ) , [ ] ) ;
109103 [ ...controllerInterceptors , ...flattenMethodsInterceptors ] . map ( ( guard ) => this . storeInjectable ( guard , token ) ) ;
110104 }
111105
112- private storeRelatedModule ( related : NestModuleMetatype , token : string ) {
106+ public reflectKeyMetadata ( component : Metatype < Injectable > , key : string , method : string ) {
107+ const descriptor = Reflect . getOwnPropertyDescriptor ( component . prototype , method ) ;
108+ return descriptor ? Reflect . getMetadata ( key , descriptor . value ) : undefined ;
109+ }
110+
111+ public storeRelatedModule ( related : NestModuleMetatype , token : string ) {
113112 this . container . addRelatedModule ( related , token ) ;
114113 }
115114
116- private storeComponent ( component : Metatype < Injectable > , token : string ) {
115+ public storeComponent ( component : Metatype < Injectable > , token : string ) {
117116 this . container . addComponent ( component , token ) ;
118117 }
119118
120- private storeInjectable ( component : Metatype < Injectable > , token : string ) {
119+ public storeInjectable ( component : Metatype < Injectable > , token : string ) {
121120 this . container . addInjectable ( component , token ) ;
122121 }
123122
124- private storeExportedComponent ( exportedComponent : Metatype < Injectable > , token : string ) {
123+ public storeExportedComponent ( exportedComponent : Metatype < Injectable > , token : string ) {
125124 this . container . addExportedComponent ( exportedComponent , token ) ;
126125 }
127126
128- private storeRoute ( route : Metatype < Controller > , token : string ) {
127+ public storeRoute ( route : Metatype < Controller > , token : string ) {
129128 this . container . addController ( route , token ) ;
130129 }
131130
132- private reflectMetadata ( metatype , metadata : string ) {
131+ public reflectMetadata ( metatype , metadata : string ) {
133132 return Reflect . getMetadata ( metadata , metatype ) || [ ] ;
134133 }
135134
0 commit comments