UNPKG

@hexadrop/query

Version:

Hexagonal architecture utils library

36 lines (33 loc) 1.51 kB
import Either from '@hexadrop/either'; import DomainError from '@hexadrop/error'; import QueryBus from './bus.js'; import Query from './query.js'; import QueryHandlers from './query-handlers.js'; import '@hexadrop/types/class'; import '@hexadrop/types/primitives'; /** * SyncQueryBus is a class that implements the QueryBus interface. * It is used to handle queries synchronously. * * @property {QueryHandlers} info - An instance of QueryHandlers that contains the query handlers. */ declare class SyncQueryBus implements QueryBus { private readonly info; /** * Constructs a new instance of the SyncQueryBus class. * * @param {QueryHandlers} info - An instance of QueryHandlers that contains the query handlers. */ constructor(info: QueryHandlers); /** * This method is used to ask a query. * It searches for the appropriate handler for the query and executes it. * If an error occurs during the execution of the handler, it returns a DomainError. * * @param {Query<ResponseType>} query - The query to be asked. * @returns {Either<DomainError, ResponseType> | Promise<Either<DomainError, ResponseType>>} - The response from the query handler or a DomainError. * @template ResponseType - The type of the response that the query handler should return. */ ask<const ResponseType>(query: Query<ResponseType>): Either<DomainError, ResponseType> | Promise<Either<DomainError, ResponseType>>; } export { SyncQueryBus as default };