@appvise/domain
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -23,3 +23,4 @@ "use strict"; | ||
static prepareForPublish(aggregate) { | ||
const aggregateFound = !!this.findAggregateByID(aggregate.id); | ||
const aggregateType = aggregate.constructor.name; | ||
const aggregateFound = !!this.findAggregateByID(aggregate.id, aggregateType); | ||
if (!aggregateFound) { | ||
@@ -29,5 +30,5 @@ this.aggregates.push(aggregate); | ||
} | ||
static publishEvents(id, logger, correlationId) { | ||
static publishEvents(id, aggregateType, logger, correlationId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const aggregate = this.findAggregateByID(id); | ||
const aggregate = this.findAggregateByID(id, aggregateType); | ||
if (aggregate) { | ||
@@ -39,3 +40,3 @@ logger.debug(`[${aggregate.domainEvents.map((event) => event.constructor.name)}] published ${aggregate.id.value}`); | ||
} | ||
return this.publish(id, event, logger); | ||
return this.publish(id, aggregateType, event, logger); | ||
})); | ||
@@ -47,5 +48,6 @@ aggregate.clearEvents(); | ||
} | ||
static findAggregateByID(id) { | ||
static findAggregateByID(id, aggregateType) { | ||
for (const aggregate of this.aggregates) { | ||
if (aggregate.id.equals(id)) { | ||
if (aggregate.id.equals(id) && | ||
aggregate.constructor.name === aggregateType) { | ||
return aggregate; | ||
@@ -56,6 +58,7 @@ } | ||
static removeAggregateFromPublishList(aggregate) { | ||
const index = this.aggregates.findIndex((a) => a.equals(aggregate)); | ||
const aggregateType = aggregate.constructor.name; | ||
const index = this.aggregates.findIndex((a) => a.equals(aggregate) && a.constructor.name === aggregateType); | ||
this.aggregates.splice(index, 1); | ||
} | ||
static publish(id, event, logger) { | ||
static publish(id, aggregateType, event, logger) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -69,3 +72,3 @@ const eventName = event.constructor.name; | ||
// Prevents infinite loop when updating after a save on same aggregate | ||
(_a = this.findAggregateByID(id)) === null || _a === void 0 ? void 0 : _a.markEventAsSent(eventName); | ||
(_a = this.findAggregateByID(id, aggregateType)) === null || _a === void 0 ? void 0 : _a.markEventAsSent(eventName); | ||
return handler.handle(event); | ||
@@ -72,0 +75,0 @@ })); |
@@ -20,3 +20,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
static prepareForPublish(aggregate) { | ||
const aggregateFound = !!this.findAggregateByID(aggregate.id); | ||
const aggregateType = aggregate.constructor.name; | ||
const aggregateFound = !!this.findAggregateByID(aggregate.id, aggregateType); | ||
if (!aggregateFound) { | ||
@@ -26,5 +27,5 @@ this.aggregates.push(aggregate); | ||
} | ||
static publishEvents(id, logger, correlationId) { | ||
static publishEvents(id, aggregateType, logger, correlationId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const aggregate = this.findAggregateByID(id); | ||
const aggregate = this.findAggregateByID(id, aggregateType); | ||
if (aggregate) { | ||
@@ -36,3 +37,3 @@ logger.debug(`[${aggregate.domainEvents.map((event) => event.constructor.name)}] published ${aggregate.id.value}`); | ||
} | ||
return this.publish(id, event, logger); | ||
return this.publish(id, aggregateType, event, logger); | ||
})); | ||
@@ -44,5 +45,6 @@ aggregate.clearEvents(); | ||
} | ||
static findAggregateByID(id) { | ||
static findAggregateByID(id, aggregateType) { | ||
for (const aggregate of this.aggregates) { | ||
if (aggregate.id.equals(id)) { | ||
if (aggregate.id.equals(id) && | ||
aggregate.constructor.name === aggregateType) { | ||
return aggregate; | ||
@@ -53,6 +55,7 @@ } | ||
static removeAggregateFromPublishList(aggregate) { | ||
const index = this.aggregates.findIndex((a) => a.equals(aggregate)); | ||
const aggregateType = aggregate.constructor.name; | ||
const index = this.aggregates.findIndex((a) => a.equals(aggregate) && a.constructor.name === aggregateType); | ||
this.aggregates.splice(index, 1); | ||
} | ||
static publish(id, event, logger) { | ||
static publish(id, aggregateType, event, logger) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -66,3 +69,3 @@ const eventName = event.constructor.name; | ||
// Prevents infinite loop when updating after a save on same aggregate | ||
(_a = this.findAggregateByID(id)) === null || _a === void 0 ? void 0 : _a.markEventAsSent(eventName); | ||
(_a = this.findAggregateByID(id, aggregateType)) === null || _a === void 0 ? void 0 : _a.markEventAsSent(eventName); | ||
return handler.handle(event); | ||
@@ -69,0 +72,0 @@ })); |
@@ -11,3 +11,3 @@ import { AggregateRoot } from '../base-classes/aggregate-root'; | ||
static prepareForPublish(aggregate: AggregateRoot<unknown>): void; | ||
static publishEvents(id: ID, logger: Logger, correlationId?: string): Promise<void>; | ||
static publishEvents(id: ID, aggregateType: string, logger: Logger, correlationId?: string): Promise<void>; | ||
private static findAggregateByID; | ||
@@ -14,0 +14,0 @@ private static removeAggregateFromPublishList; |
@@ -7,4 +7,5 @@ import { SelectionSet } from './selection-set'; | ||
abstract save(entity: TEntity): Promise<TEntity>; | ||
abstract save(entity: TEntity, reload?: boolean): Promise<TEntity>; | ||
abstract delete(entity: TEntity): Promise<void>; | ||
abstract setCorrelationId(correlationId: string): this; | ||
} |
{ | ||
"name": "@appvise/domain", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Base package for building Domain-Driven Hexagon applications in TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114336
3004