UNPKG

mediatr-ts

Version:

Mimic the famous MediatR csharp library see: (https://github.com/jbogard/MediatR)

39 lines (38 loc) 1.93 kB
import { NotificationHandlerClass } from "../../interfaces/notificationHandler.js"; import { NotificationClass } from "../notificationData.js"; import { OrderedMapping, OrderedMappings } from "./orderedMappings.js"; type NotificationHandlerMappingData = { handlerClass: NotificationHandlerClass<unknown>; notificationClass: NotificationClass; }; /** * NotificationHandlerMappings class extends OrderedMappings and is used to * manage notification handlers for specific notification classes. * * @exports */ export declare class NotificationHandlerMappings extends OrderedMappings<NotificationHandlerMappingData> { /** * It allows you to specify the order in which notification handlers should be executed for a particular * notification class. * * It takes a notification class and an array of handler classes as input and updates the order of each handler in * the array based on its index. If not found it place the order as -1. * * @param notificationClass The notification class for which to set the order. * @param handlerClasses The array of handler classes in the order in which they should be executed. */ setOrder<TNotification extends NotificationClass>(notificationClass: NotificationClass, handlerClasses: NotificationHandlerClass<TNotification>[]): void; /** * Retrieves all notification handlers for a specific notification class. * If no class is provided, it returns all handlers. * If no handlers are found for the specified class, it throws an error. * * The returned handlers are sorted by their order. * * @param notificationClass The notification class for which to retrieve the handlers. * @returns The array of handler classes in the order in which they should be executed. */ getAll(notificationClass?: NotificationClass): OrderedMapping<NotificationHandlerMappingData>[]; } export {};