UNPKG

@dugongjs/nestjs

Version:

77 lines (76 loc) 4.23 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; import { AggregateContext, IExternalOriginMap, IOutboundMessageMapper } from "@dugongjs/core"; import { Injectable, Optional } from "@nestjs/common"; import { InjectCurrentOrigin } from "../decorators/inject-current-origin.decorator.js"; import { InjectDomainEventRepository } from "../decorators/inject-domain-event-repository.decorator.js"; import { InjectExternalOriginMap } from "../decorators/inject-external-origin-map.decorator.js"; import { InjectLoggerFactory } from "../decorators/inject-logger-factory.decorator.js"; import { InjectMessageProducer } from "../decorators/inject-message-producer.decorator.js"; import { InjectOutboundMessageMapper } from "../decorators/inject-outbound-message-mapper.decorator.js"; import { InjectSnapshotRepository } from "../decorators/inject-snapshot-repository.decorator.js"; import { InjectTransactionManager } from "../decorators/inject-transaction-manager.decorator.js"; let EventSourcingService = class EventSourcingService { constructor(currentOrigin, transactionManager, domainEventRepository, snapshotRepository, externalOriginMap, messageProducer, outboundMessageMapper, loggerFactory) { this.currentOrigin = currentOrigin; this.transactionManager = transactionManager; this.domainEventRepository = domainEventRepository; this.snapshotRepository = snapshotRepository; this.externalOriginMap = externalOriginMap; this.messageProducer = messageProducer; this.outboundMessageMapper = outboundMessageMapper; this.logger = loggerFactory?.createLogger(AggregateContext.name); } createAggregateContext(transactionContext, aggregateClass) { const aggregateContextOptions = { aggregateClass: aggregateClass, transactionManager: this.transactionManager, domainEventRepository: this.domainEventRepository, snapshotRepository: this.snapshotRepository, messageProducer: this.messageProducer, outboundMessageMapper: this.outboundMessageMapper, externalOriginMap: this.externalOriginMap, currentOrigin: this.currentOrigin, logger: this.logger }; const context = new AggregateContext(aggregateContextOptions); const factory = context.getFactory(); factory.setTransactionContext(transactionContext); try { const manager = context.getManager(); manager.setTransactionContext(transactionContext); } catch { } return context; } transaction(runInTransaction) { return this.transactionManager.transaction(runInTransaction); } }; EventSourcingService = __decorate([ Injectable(), __param(0, InjectCurrentOrigin()), __param(1, InjectTransactionManager()), __param(2, InjectDomainEventRepository()), __param(3, InjectSnapshotRepository()), __param(4, Optional()), __param(4, InjectExternalOriginMap()), __param(5, Optional()), __param(5, InjectMessageProducer()), __param(6, Optional()), __param(6, InjectOutboundMessageMapper()), __param(7, Optional()), __param(7, InjectLoggerFactory()), __metadata("design:paramtypes", [String, Object, Object, Object, Object, Object, Object, Object]) ], EventSourcingService); export { EventSourcingService };