alpha-command-bus
Version:
Very simple command bus implementation
25 lines (24 loc) • 1.09 kB
TypeScript
import { CommandHandlerDescriptor } from "./CommandHandlerDescriptor";
import { Command, CommandRunner } from 'alpha-command-bus-core';
export declare class CommandBus {
private middlewares;
private commandHandlers;
/**
* Registers middleware that wraps process of handling a command
*/
use(middleware: CommandBus.Middleware): this;
registerCommandHandler(filter: CommandHandlerDescriptor.Filter<any>, handler: CommandHandlerDescriptor.Func<any>): this;
registerCommandHandler(descriptor: CommandHandlerDescriptor<any>): this;
registerCommandHandlers(descriptors: Array<CommandHandlerDescriptor<any>>): this;
/**
* Dispatches command to the bus.
*/
handle(command: Command): Promise<any>;
asCommandRunner(): CommandRunner;
hasCommandHandler(command: Command): boolean;
private runCommandHandler;
private getCommandHandlerForCommand;
}
export declare namespace CommandBus {
type Middleware<TCommand extends Command = Command> = (command: TCommand, next: (command: TCommand) => Promise<any>) => Promise<any> | any;
}