UNPKG

@dolittle/sdk.events.handling

Version:

Dolittle is a decentralized, distributed, event-driven microservice platform built to harness the power of events.

45 lines 3.33 kB
"use strict"; // Copyright (c) Dolittle. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.EventHandler = void 0; const IEventHandler_1 = require("./IEventHandler"); const MissingEventHandlerForType_1 = require("./MissingEventHandlerForType"); /** * Represents an implementation of {@link IEventHandler}. */ class EventHandler extends IEventHandler_1.IEventHandler { /** * Initializes a new instance of {@link EventHandler}. * @param {EventHandlerId} eventHandlerId - The unique identifier of the event handler. * @param {ScopeId} scopeId - The identifier of the scope the event handler is in. * @param {boolean} partitioned - Whether or not the event handler is partitioned. * @param {EventTypeMap<EventHandlerSignature<any>>} handleMethodsByEventType - Handle methods per event type. * @param {EventHandlerAlias | undefined} alias - The optional event handler alias. */ constructor(eventHandlerId, scopeId, partitioned, handleMethodsByEventType, alias = undefined) { super(); this.eventHandlerId = eventHandlerId; this.scopeId = scopeId; this.partitioned = partitioned; this.handleMethodsByEventType = handleMethodsByEventType; this.alias = alias; this.hasAlias = alias !== undefined; } /** @inheritdoc */ get handledEvents() { return this.handleMethodsByEventType.keys(); } /** @inheritdoc */ async handle(event, eventType, context, services, logger) { if (this.handleMethodsByEventType.has(eventType)) { const method = this.handleMethodsByEventType.get(eventType); await method(event, context, services, logger); } else { throw new MissingEventHandlerForType_1.MissingEventHandlerForType(eventType); } } } exports.EventHandler = EventHandler; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRXZlbnRIYW5kbGVyLmpzIiwic291cmNlUm9vdCI6Ii4uLyIsInNvdXJjZXMiOlsiRXZlbnRIYW5kbGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwrQ0FBK0M7QUFDL0MscUdBQXFHOzs7QUFVckcsbURBQWdEO0FBQ2hELDZFQUEwRTtBQUUxRTs7R0FFRztBQUNILE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