UNPKG

@hexadrop/query

Version:

Hexagonal architecture utils library

23 lines (20 loc) 1.13 kB
import { QueryClass } from './query.js'; import '@hexadrop/types/class'; import '@hexadrop/types/primitives'; /** * @constant * @description The metadata key used to define query handlers. */ declare const QUERY_HANDLER_METADATA_KEY = "query-handler"; /** * QueryHandler is a function that acts as a class decorator. It is used to define query handlers. * It checks if the target class has a 'run' method in its prototype. If it does, it defines metadata for each query in the queries array. * If the 'run' method is not found in the target's prototype, it throws a QueryHandlerError. * * @param {...QueryClass<ResponseType>[]} queries - An array of QueryClass instances. * @returns {ClassDecorator} - Returns a class decorator that can be used to decorate a class. * @throws {QueryHandlerError} - Throws an error if the target class does not implement a 'run' method. * @template ResponseType - The type of the response that the queries handle. */ declare function QueryHandler<ResponseType>(...queries: QueryClass<ResponseType>[]): ClassDecorator; export { QUERY_HANDLER_METADATA_KEY, QueryHandler as default };