UNPKG

mediatr-ts

Version:

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

47 lines 2.25 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.RequestHandlerMappings = void 0; var orderedMappings_js_1 = require("./orderedMappings.js"); /** * Mapping for request handlers * * @exports */ var RequestHandlerMappings = /** @class */ (function (_super) { __extends(RequestHandlerMappings, _super); function RequestHandlerMappings() { return _super !== null && _super.apply(this, arguments) || this; } /** * Gets all mappings for a specific request if provided, otherwise returns all (sorted) mappings * * @throws Error if no mappings are found for specified argument * @param requestClass The request class to get mappings for * @returns The array of handler classes in the order in which they should be executed. */ RequestHandlerMappings.prototype.getAll = function (requestClass) { var items = this._mappings.filter(function (p) { return p.requestClass === requestClass || !requestClass; }); if (items.length === 0 && requestClass) { throw new Error("No handler found for request ".concat(requestClass.name, ". Remember to decorate your handler with @requestHandler(").concat(requestClass.name, ").")); } return items.sort(orderedMappings_js_1.byOrder); }; return RequestHandlerMappings; }(orderedMappings_js_1.OrderedMappings)); exports.RequestHandlerMappings = RequestHandlerMappings; //# sourceMappingURL=requestHandlerMappings.js.map