@@ -14,32 +14,16 @@ import { PipesConsumer } from '../pipes/pipes-consumer';
1414import { PipesContextCreator } from '../pipes/pipes-context-creator' ;
1515import { ExternalExceptionFilterContext } from './../exceptions/external-exception-filter-context' ;
1616import { STATIC_CONTEXT } from './../injector/constants' ;
17- import { ContextId } from './../injector/instance-wrapper' ;
1817import { ContextUtils , ParamProperties } from './context-utils' ;
1918import { ExternalErrorProxy } from './external-proxy' ;
2019import { HandlerMetadataStorage } from './handler-metadata-storage' ;
21-
22- export interface ParamsMetadata {
23- [ prop : number ] : {
24- index : number ;
25- data ?: ParamData ;
26- } ;
27- }
20+ import { ExternalHandlerMetadata } from './interfaces/external-handler-metadata.interface' ;
21+ import { ParamsMetadata } from './interfaces/params-metadata.interface' ;
2822
2923export interface ParamsFactory {
3024 exchangeKeyForValue ( type : number , data : ParamData , args : any ) : any ;
3125}
3226
33- export interface ExternalHandlerMetadata {
34- argsLength : number ;
35- paramtypes : any [ ] ;
36- getParamsMetadata : (
37- moduleKey : string ,
38- contextId ?: ContextId ,
39- inquirerId ?: string ,
40- ) => ( ParamProperties & { metatype ?: any } ) [ ] ;
41- }
42-
4327export interface ExternalContextOptions {
4428 guards ?: boolean ;
4529 interceptors ?: boolean ;
@@ -110,7 +94,7 @@ export class ExternalContextCreator {
11094 filters : true ,
11195 } ,
11296 ) {
113- const module = this . findContextModuleName ( instance . constructor ) ;
97+ const module = this . getContextModuleName ( instance . constructor ) ;
11498 const { argsLength, paramtypes, getParamsMetadata } = this . getMetadata < T > (
11599 instance ,
116100 methodName ,
@@ -230,20 +214,21 @@ export class ExternalContextCreator {
230214 return handlerMetadata ;
231215 }
232216
233- public findContextModuleName ( constructor : Function ) : string {
217+ public getContextModuleName ( constructor : Function ) : string {
218+ const defaultModuleName = '' ;
234219 const className = constructor . name ;
235220 if ( ! className ) {
236- return '' ;
221+ return defaultModuleName ;
237222 }
238223 for ( const [ key , module ] of [ ...this . modulesContainer . entries ( ) ] ) {
239- if ( this . findProviderByClassName ( module , className ) ) {
224+ if ( this . getProviderByClassName ( module , className ) ) {
240225 return key ;
241226 }
242227 }
243- return '' ;
228+ return defaultModuleName ;
244229 }
245230
246- public findProviderByClassName ( module : Module , className : string ) : boolean {
231+ public getProviderByClassName ( module : Module , className : string ) : boolean {
247232 const { providers } = module ;
248233 const hasProvider = [ ...providers . keys ( ) ] . some (
249234 provider => provider === className ,
@@ -271,50 +256,45 @@ export class ExternalContextCreator {
271256
272257 if ( key . includes ( CUSTOM_ROUTE_AGRS_METADATA ) ) {
273258 const { factory } = metadata [ key ] ;
274- const customExtractValue = this . getCustomFactory ( factory , data ) ;
259+ const customExtractValue = this . contextUtils . getCustomFactory (
260+ factory ,
261+ data ,
262+ ) ;
275263 return { index, extractValue : customExtractValue , type, data, pipes } ;
276264 }
277265 const numericType = Number ( type ) ;
278- const extractValue = ( ...args : any [ ] ) =>
266+ const extractValue = ( ...args : unknown [ ] ) =>
279267 paramsFactory . exchangeKeyForValue ( numericType , data , args ) ;
280268
281269 return { index, extractValue, type : numericType , data, pipes } ;
282270 } ) ;
283271 }
284272
285- public getCustomFactory (
286- factory : ( ...args : any [ ] ) => void ,
287- data : any ,
288- ) : ( ...args : any [ ] ) => any {
289- return isFunction ( factory )
290- ? ( ...args : any [ ] ) => factory ( data , args )
291- : ( ) => null ;
292- }
293-
294273 public createPipesFn (
295274 pipes : PipeTransform [ ] ,
296- paramsOptions : ( ParamProperties & { metatype ?: any } ) [ ] ,
275+ paramsOptions : ( ParamProperties & { metatype ?: unknown } ) [ ] ,
297276 ) {
298- const pipesFn = async ( args : any [ ] , ...params : any [ ] ) => {
299- await Promise . all (
300- paramsOptions . map ( async param => {
301- const {
302- index,
303- extractValue,
304- type,
305- data,
306- metatype,
307- pipes : paramPipes ,
308- } = param ;
309- const value = extractValue ( ...params ) ;
277+ const pipesFn = async ( args : unknown [ ] , ...params : unknown [ ] ) => {
278+ const resolveParamValue = async (
279+ param : ParamProperties & { metatype ?: unknown } ,
280+ ) => {
281+ const {
282+ index,
283+ extractValue,
284+ type,
285+ data,
286+ metatype,
287+ pipes : paramPipes ,
288+ } = param ;
289+ const value = extractValue ( ...params ) ;
310290
311- args [ index ] = await this . getParamValue (
312- value ,
313- { metatype, type, data } ,
314- pipes . concat ( paramPipes ) ,
315- ) ;
316- } ) ,
317- ) ;
291+ args [ index ] = await this . getParamValue (
292+ value ,
293+ { metatype, type, data } ,
294+ pipes . concat ( paramPipes ) ,
295+ ) ;
296+ } ;
297+ await Promise . all ( paramsOptions . map ( resolveParamValue ) ) ;
318298 } ;
319299 return paramsOptions . length ? pipesFn : null ;
320300 }
0 commit comments