import { defaultMetadataArgsStorage } from '../index' ; import { ControllerMetadata } from '../metadata/ControllerMetadata' ; import { ActionMetadata } from '../metadata/ActionMetadata' ; import { ParamMetadata } from '../metadata/ParamMetadata' ; import { MiddlewareMetadata } from '../metadata/MiddlewareMetadata' ; import { ResultMetadata } from '../metadata/ResultMetadata' ; /**
 * Builds metadata from the given metadata arguments.
 */ export class MetadataBuilder { buildControllerMetadata ( classes ? ) { return this . createControllers ( classes ) ; } buildMiddlewareMetadata ( classes ? ) { return this . createMiddlewares ( classes ) ; } private createMiddlewares ( classes ? ) { const storage = defaultMetadataArgsStorage ( ) ; const middlewares = ! classes ? storage . middlewares : storage . findMiddlewareMetadatasForClasses ( classes ) ; return middlewares . map ( middlewareArgs => { return new MiddlewareMetadata ( middlewareArgs ) ; } ) ; } private createControllers ( classes ? ) { const storage = defaultMetadataArgsStorage ( ) ; const controllers = ! classes ? storage . controllers : storage . findControllerMetadatasForClasses ( classes ) ; return controllers . map ( controllerArgs => { const controller = new ControllerMetadata ( controllerArgs ) ; controller . actions = this . createActions ( controller ) ; return controller ; } ) ; } private createActions ( controller ) { return defaultMetadataArgsStorage ( ) . findActionsWithTarget ( controller . target ) . map ( actionArgs => { const action = new ActionMetadata ( controller , actionArgs ) ; action . params = this . createParams ( action ) ; action . results = this . createResults ( action ) ; return action ; } ) ; } private createParams ( action ) { return defaultMetadataArgsStorage ( ) . findParamsWithTargetAndMethod ( action . target , action . method ) . map ( paramArgs => new ParamMetadata ( action , paramArgs ) ) ; } private createResults ( action ) { return defaultMetadataArgsStorage ( ) . findResutlsWithTargetAndMethod ( action . target , action . method ) . map ( resultArgs => new ResultMetadata ( action , resultArgs ) ) ; } }