UNPKG

@hexadrop/query

Version:

Hexagonal architecture utils library

42 lines (39 loc) 2.05 kB
import { Container } from '@hexadrop/ioc'; import { QueryBusCallback } from './bus.js'; import Query, { QueryClass } from './query.js'; import QueryHandlers from './query-handlers.js'; import '@hexadrop/either'; import '@hexadrop/error'; import '@hexadrop/types/class'; import '@hexadrop/types/primitives'; /** * This is a class named IoCQueryHandlers that extends the abstract class QueryHandlers. * It provides an implementation for handling queries using an IoC (Inversion of Control) container. */ declare class IoCQueryHandlers extends QueryHandlers { private readonly container; /** * This is the constructor method for the class. * It takes a container of type 'Container' as an argument. * The container is used to get instances of query handlers. * * @param {Container} container - The IoC container. */ constructor(container: Container); /** * This is a public method named 'search'. * It takes a query of type 'QueryType' or 'QueryClass<ResponseType, QueryType>' as an argument. * 'ResponseType' and 'QueryType' are generic parameters where 'QueryType' extends 'Query<ResponseType>'. * The method searches for a query handler registered with the query name using the IoC container. * If the query does not have a name, it throws an 'InvalidQueryError'. * If the query handler is not registered, it throws a 'QueryNotRegisteredError'. * The method returns a 'QueryBusCallback<ResponseType, QueryType>'. * * @param {QueryType | QueryClass<ResponseType, QueryType>} query - The query to be searched. * @returns {QueryBusCallback<ResponseType, QueryType>} - The query handler callback. * @template ResponseType - The type of the response. * @template QueryType - The type of the Query that extends Query<ResponseType>. */ search<ResponseType, QueryType extends Query<ResponseType>>(query: QueryClass<ResponseType, QueryType> | QueryType): QueryBusCallback<ResponseType, QueryType>; } export { IoCQueryHandlers as default };