UNPKG

@cashfarm/plow

Version:

Library for validating input data and parameters

43 lines 1.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const inversify_1 = require("inversify"); const esAggregateFactory_1 = require("./esAggregateFactory"); const iEventStore_1 = require("./iEventStore"); const iEventBus_1 = require("./iEventBus"); const debug = require('debug')('plow:events:repository'); let ESRepository = class ESRepository { constructor(storage, aggtClass, eventBus) { this.storage = storage; this.aggtClass = aggtClass; this.eventBus = eventBus; } save(aggregate) { return this.storage.save(aggregate) .then(nextVersion => { const events = aggregate.uncommittedChanges.slice(); if (this.eventBus) events.map(e => this.eventBus.publish(e)); aggregate.markChangesAsCommitted(); return events; }); } getById(id) { return tslib_1.__awaiter(this, void 0, void 0, function* () { debug(`Getting aggregate of ${this.aggtClass.name} with id ${id}`); const evts = yield this.storage.getEventsByAggregate(this.aggtClass, id); if (evts.length === 0) return null; return esAggregateFactory_1.ESAggregateFactory.create(this.aggtClass, evts); }); } }; ESRepository = tslib_1.__decorate([ inversify_1.injectable(), tslib_1.__param(0, inversify_1.unmanaged()), tslib_1.__param(1, inversify_1.unmanaged()), tslib_1.__param(2, inversify_1.unmanaged()), tslib_1.__metadata("design:paramtypes", [Object, Object, Object]) ], ESRepository); exports.ESRepository = ESRepository; //# sourceMappingURL=esRepository.js.map