import { Query } from '../../domain/Query' ; import { QueryHandler } from '../../domain/QueryHandler' ; import { Response } from '../../domain/Response' ; import { QueryNotRegisteredError } from '../../domain/QueryNotRegisteredError' ; export class QueryHandlersInformation { private queryHandlersMap : Map < Query , QueryHandler < Query , Response > > ; constructor ( queryHandlers ) { this . queryHandlersMap = this . formatHandlers ( queryHandlers ) ; } private formatHandlers ( queryHandlers ) { const handlersMap = new Map ( ) ; queryHandlers . forEach ( queryHandler => { handlersMap . set ( queryHandler . subscribedTo ( ) , queryHandler ) ; } ) ; return handlersMap ; } public search ( query ) { const queryHandler = this . queryHandlersMap . get ( query . constructor ) ; if ( ! queryHandler ) { throw new QueryNotRegisteredError ( query ) ; } return queryHandler ; } }