@event-nest/core 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/index.d.ts +14 -9
- package/src/index.js +14 -9
- package/src/index.js.map +1 -1
- package/src/lib/aggregate-root-aware-event.d.ts +4 -0
- package/src/lib/aggregate-root-aware-event.js +3 -0
- package/src/lib/aggregate-root-aware-event.js.map +1 -0
- package/src/lib/aggregate-root-name.d.ts +2 -0
- package/src/lib/aggregate-root-name.js +16 -0
- package/src/lib/aggregate-root-name.js.map +1 -0
- package/src/lib/aggregate-root.d.ts +50 -0
- package/src/lib/aggregate-root.js +133 -0
- package/src/lib/aggregate-root.js.map +1 -0
- package/src/lib/core-module-options.d.ts +11 -0
- package/src/lib/core-module-options.js +3 -0
- package/src/lib/core-module-options.js.map +1 -0
- package/src/lib/domain-event-emitter.d.ts +13 -0
- package/src/lib/domain-event-emitter.js +59 -0
- package/src/lib/domain-event-emitter.js.map +1 -0
- package/src/lib/domain-event-subscription.d.ts +5 -0
- package/src/lib/domain-event-subscription.js +33 -0
- package/src/lib/domain-event-subscription.js.map +1 -0
- package/src/lib/event-processor.d.ts +5 -0
- package/src/lib/{decorators/event-processor.js → event-processor.js} +5 -5
- package/src/lib/event-processor.js.map +1 -0
- package/src/lib/{decorators → exceptions}/event-name-conflict-exception.js.map +1 -1
- package/src/lib/exceptions/id-generation-exception.js.map +1 -0
- package/src/lib/exceptions/missing-aggregate-root-name-exception.d.ts +3 -0
- package/src/lib/exceptions/missing-aggregate-root-name-exception.js +10 -0
- package/src/lib/exceptions/missing-aggregate-root-name-exception.js.map +1 -0
- package/src/lib/exceptions/unknown-event-exception.d.ts +3 -0
- package/src/lib/exceptions/unknown-event-exception.js +10 -0
- package/src/lib/exceptions/unknown-event-exception.js.map +1 -0
- package/src/lib/exceptions/unregistered-event-exception.d.ts +3 -0
- package/src/lib/exceptions/unregistered-event-exception.js +10 -0
- package/src/lib/exceptions/unregistered-event-exception.js.map +1 -0
- package/src/lib/metadata-keys.d.ts +4 -0
- package/src/lib/metadata-keys.js +8 -0
- package/src/lib/metadata-keys.js.map +1 -0
- package/src/lib/on-domain-event.d.ts +4 -0
- package/src/lib/{storage/event-payload.js → on-domain-event.js} +1 -1
- package/src/lib/on-domain-event.js.map +1 -0
- package/src/lib/{decorators/registered-event.d.ts → registered-event.d.ts} +2 -2
- package/src/lib/{decorators/registered-event.js → registered-event.js} +7 -3
- package/src/lib/registered-event.js.map +1 -0
- package/src/lib/storage/abstract-event-store.d.ts +6 -4
- package/src/lib/storage/abstract-event-store.js +14 -5
- package/src/lib/storage/abstract-event-store.js.map +1 -1
- package/src/lib/storage/event-store.d.ts +36 -2
- package/src/lib/storage/event-store.js.map +1 -1
- package/src/lib/storage/stored-aggregate-root.d.ts +4 -0
- package/src/lib/storage/stored-aggregate-root.js +4 -0
- package/src/lib/storage/stored-aggregate-root.js.map +1 -1
- package/src/lib/storage/stored-event.d.ts +37 -3
- package/src/lib/storage/stored-event.js +43 -5
- package/src/lib/storage/stored-event.js.map +1 -1
- package/src/lib/decorators/event-processor.d.ts +0 -5
- package/src/lib/decorators/event-processor.js.map +0 -1
- package/src/lib/decorators/registered-event.js.map +0 -1
- package/src/lib/domain/aggregate-root.d.ts +0 -48
- package/src/lib/domain/aggregate-root.js +0 -109
- package/src/lib/domain/aggregate-root.js.map +0 -1
- package/src/lib/domain/missing-event-processor-exception.d.ts +0 -3
- package/src/lib/domain/missing-event-processor-exception.js +0 -10
- package/src/lib/domain/missing-event-processor-exception.js.map +0 -1
- package/src/lib/storage/event-payload.d.ts +0 -3
- package/src/lib/storage/event-payload.js.map +0 -1
- package/src/lib/storage/id-generation-exception.js.map +0 -1
- /package/src/lib/{decorators → exceptions}/event-name-conflict-exception.d.ts +0 -0
- /package/src/lib/{decorators → exceptions}/event-name-conflict-exception.js +0 -0
- /package/src/lib/{storage → exceptions}/id-generation-exception.d.ts +0 -0
- /package/src/lib/{storage → exceptions}/id-generation-exception.js +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ClassConstructor } from "class-transformer";
|
|
2
|
-
import { EventPayload } from "../storage/event-payload";
|
|
3
2
|
export declare function RegisteredEvent(eventName: string): ClassDecorator;
|
|
4
3
|
/**
|
|
5
4
|
* Returns the event name that matches the class of the provided object.
|
|
6
5
|
* @param target
|
|
7
6
|
*/
|
|
8
|
-
export declare function getEventName(target:
|
|
7
|
+
export declare function getEventName(target: object): string | undefined;
|
|
9
8
|
/**
|
|
10
9
|
* Returns the class that matches the provided name. Or undefined.
|
|
11
10
|
* @param name The event name to be checked.
|
|
12
11
|
*/
|
|
13
12
|
export declare function getEventClass<T>(name: string): ClassConstructor<T> | undefined;
|
|
13
|
+
export declare function isRegistered(event: object): boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEventClass = exports.getEventName = exports.RegisteredEvent = void 0;
|
|
4
|
-
const event_name_conflict_exception_1 = require("./event-name-conflict-exception");
|
|
5
|
-
const type_utils_1 = require("
|
|
3
|
+
exports.isRegistered = exports.getEventClass = exports.getEventName = exports.RegisteredEvent = void 0;
|
|
4
|
+
const event_name_conflict_exception_1 = require("./exceptions/event-name-conflict-exception");
|
|
5
|
+
const type_utils_1 = require("./utils/type-utils");
|
|
6
6
|
const REGISTRATIONS = [];
|
|
7
7
|
function RegisteredEvent(eventName) {
|
|
8
8
|
return (target) => {
|
|
@@ -34,4 +34,8 @@ function getEventClass(name) {
|
|
|
34
34
|
return (0, type_utils_1.isNil)(found) ? undefined : found.eventClass;
|
|
35
35
|
}
|
|
36
36
|
exports.getEventClass = getEventClass;
|
|
37
|
+
function isRegistered(event) {
|
|
38
|
+
return !(0, type_utils_1.isNil)(getEventName(event));
|
|
39
|
+
}
|
|
40
|
+
exports.isRegistered = isRegistered;
|
|
37
41
|
//# sourceMappingURL=registered-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registered-event.js","sourceRoot":"","sources":["../../../../../libs/core/src/lib/registered-event.ts"],"names":[],"mappings":";;;AACA,8FAAwF;AACxF,mDAA2C;AAO3C,MAAM,aAAa,GAA6B,EAAE,CAAC;AAEnD,SAAgB,eAAe,CAAC,SAAiB;IAC7C,OAAO,CAAC,MAAM,EAAE,EAAE;QACd,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,SAAS,KAAK,SAAS,CAAC,EAAE;YAC5E,MAAM,IAAI,0DAA0B,CAAC,SAAS,CAAC,CAAC;SACnD;QACD,aAAa,CAAC,IAAI,CAAC;YACf,SAAS,EAAE,SAAS;YACpB,UAAU,EAAE,MAAM;SACrB,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC;AAVD,0CAUC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,MAAc;IACvC,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,UAAU,KAAK,MAAM,CAAC,WAAW,CAAC,CAAC;IACnG,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/C,CAAC;AAHD,oCAGC;AAED;;;GAGG;AACH,SAAgB,aAAa,CAAI,IAAY;IACzC,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC;IACpF,OAAO,IAAA,kBAAK,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAE,KAAK,CAAC,UAAkC,CAAC;AAChF,CAAC;AAHD,sCAGC;AAED,SAAgB,YAAY,CAAC,KAAa;IACtC,OAAO,CAAC,IAAA,kBAAK,EAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;AACvC,CAAC;AAFD,oCAEC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { EventStore } from "./event-store";
|
|
1
|
+
import { AggregateRootClass, EventStore } from "./event-store";
|
|
2
2
|
import { StoredEvent } from "./stored-event";
|
|
3
|
-
import { AggregateRoot } from "../
|
|
3
|
+
import { AggregateRoot } from "../aggregate-root";
|
|
4
4
|
import { StoredAggregateRoot } from "./stored-aggregate-root";
|
|
5
|
+
import { DomainEventEmitter } from "../domain-event-emitter";
|
|
5
6
|
export declare abstract class AbstractEventStore implements EventStore {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
private _eventBus;
|
|
8
|
+
protected constructor(_eventBus: DomainEventEmitter);
|
|
9
|
+
abstract findByAggregateRootId<T extends AggregateRoot>(aggregateRootClass: AggregateRootClass<T>, id: string): Promise<Array<StoredEvent>>;
|
|
8
10
|
abstract save(events: Array<StoredEvent>, aggregate: StoredAggregateRoot): Promise<Array<StoredEvent>>;
|
|
9
11
|
abstract generateEntityId(): Promise<string>;
|
|
10
12
|
addPublisher<T extends AggregateRoot>(aggregateRoot: T): T;
|
|
@@ -3,26 +3,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AbstractEventStore = void 0;
|
|
4
4
|
const stored_event_1 = require("./stored-event");
|
|
5
5
|
const stored_aggregate_root_1 = require("./stored-aggregate-root");
|
|
6
|
-
const id_generation_exception_1 = require("
|
|
6
|
+
const id_generation_exception_1 = require("../exceptions/id-generation-exception");
|
|
7
|
+
const type_utils_1 = require("../utils/type-utils");
|
|
8
|
+
const aggregate_root_name_1 = require("../aggregate-root-name");
|
|
9
|
+
const missing_aggregate_root_name_exception_1 = require("../exceptions/missing-aggregate-root-name-exception");
|
|
7
10
|
class AbstractEventStore {
|
|
8
11
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
9
|
-
constructor() {
|
|
12
|
+
constructor(_eventBus) {
|
|
13
|
+
this._eventBus = _eventBus;
|
|
14
|
+
}
|
|
10
15
|
addPublisher(aggregateRoot) {
|
|
11
16
|
aggregateRoot.publish = async (events) => {
|
|
17
|
+
const aggregateRootName = (0, aggregate_root_name_1.getAggregateRootName)(aggregateRoot.constructor);
|
|
18
|
+
if ((0, type_utils_1.isNil)(aggregateRootName)) {
|
|
19
|
+
throw new missing_aggregate_root_name_exception_1.MissingAggregateRootNameException(aggregateRoot.constructor.name);
|
|
20
|
+
}
|
|
12
21
|
if (events.length == 0) {
|
|
13
22
|
return Promise.resolve([]);
|
|
14
23
|
}
|
|
15
24
|
const ids = await Promise.all(events.map(() => this.generateEntityId()));
|
|
16
|
-
if (ids.length !== events.length) {
|
|
25
|
+
if (ids.length !== events.length || !(0, type_utils_1.hasAllValues)(ids)) {
|
|
17
26
|
throw new id_generation_exception_1.IdGenerationException(ids.length, events.length);
|
|
18
27
|
}
|
|
19
28
|
const storedEvents = events.map((serializable) => {
|
|
20
29
|
const id = ids.pop();
|
|
21
|
-
return stored_event_1.StoredEvent.fromPublishedEvent(id, aggregateRoot.id, serializable);
|
|
30
|
+
return stored_event_1.StoredEvent.fromPublishedEvent(id, aggregateRoot.id, aggregateRootName, serializable.payload);
|
|
22
31
|
});
|
|
23
32
|
const toStore = new stored_aggregate_root_1.StoredAggregateRoot(aggregateRoot.id, aggregateRoot.version);
|
|
24
33
|
return this.save(storedEvents, toStore).then((savedEvents) => {
|
|
25
|
-
|
|
34
|
+
this._eventBus.emitMultiple(events);
|
|
26
35
|
return Promise.resolve(savedEvents);
|
|
27
36
|
});
|
|
28
37
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-event-store.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/storage/abstract-event-store.ts"],"names":[],"mappings":";;;AACA,iDAA6C;
|
|
1
|
+
{"version":3,"file":"abstract-event-store.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/storage/abstract-event-store.ts"],"names":[],"mappings":";;;AACA,iDAA6C;AA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2CAAmB,CAAC,aAAa,CAAC,EAAE,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;YACjF,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE;gBACzD,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;gBACpC,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YACxC,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;QACF,OAAO,aAAa,CAAC;IACzB,CAAC;CACJ;AAzCD,gDAyCC"}
|
|
@@ -1,10 +1,44 @@
|
|
|
1
1
|
import { StoredEvent } from "./stored-event";
|
|
2
2
|
import { StoredAggregateRoot } from "./stored-aggregate-root";
|
|
3
|
-
import { AggregateRoot } from "../
|
|
3
|
+
import { AggregateRoot } from "../aggregate-root";
|
|
4
|
+
export type AggregateRootClass<T> = Function & {
|
|
5
|
+
prototype: T;
|
|
6
|
+
};
|
|
4
7
|
export declare const EVENT_STORE: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* Defines the main EventStore interface that can be used to retrieve and save events. Each implementation of this interface
|
|
10
|
+
* is unique based on the storage solution that is used.
|
|
11
|
+
*
|
|
12
|
+
* To inject it in your NestJS classes, you can use the {@link EVENT_STORE} symbol.
|
|
13
|
+
*/
|
|
5
14
|
export interface EventStore {
|
|
15
|
+
/**
|
|
16
|
+
* Each aggregate root object needs some way of connecting to the event store in order to be able to store its events.
|
|
17
|
+
* Since these objects are not handled by NestJS dependency injection, we need to provide a way for them to get a reference to the event store and this is
|
|
18
|
+
* the method that does that. It takes an aggregate root object and returns the same object but with a publish method attached to it.
|
|
19
|
+
* @param aggregateRoot The aggregate root object to which we want to add a publish method.
|
|
20
|
+
*/
|
|
6
21
|
addPublisher<T extends AggregateRoot>(aggregateRoot: T): T;
|
|
7
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Finds all events that are associated with the provided aggregate root id and match the aggregate root name which
|
|
24
|
+
* is resolved from the aggregate root class. These events can later be used to recreate an aggregate root object.
|
|
25
|
+
* @param aggregateRootClass The class of the aggregate root for which the store will search for events
|
|
26
|
+
* @param id The unique id of the aggregate root object
|
|
27
|
+
*/
|
|
28
|
+
findByAggregateRootId<T extends AggregateRoot>(aggregateRootClass: AggregateRootClass<T>, id: string): Promise<Array<StoredEvent>>;
|
|
29
|
+
/**
|
|
30
|
+
* Saves the provided event and aggregate root object. Before saving the aggregate root object, the method will check
|
|
31
|
+
* if the version of the aggregate root object is the same as the version of the aggregate root object in the database.
|
|
32
|
+
* If there's a version mismatch, the method will throw an exception. Otherwise, the method will increase the version
|
|
33
|
+
* of the aggregate root and then proceed to save the aggregate root and the event objects.
|
|
34
|
+
* @param events The events to save
|
|
35
|
+
* @param aggregate The aggregate root object that matches the events
|
|
36
|
+
*/
|
|
8
37
|
save(events: Array<StoredEvent>, aggregate: StoredAggregateRoot): Promise<Array<StoredEvent>>;
|
|
38
|
+
/**
|
|
39
|
+
* Each storage solution has its own way of dealing with unique ids. This method's implementation should reflect
|
|
40
|
+
* the way the storage solution generates unique ids. For example, in a MongoDB database this would usually return
|
|
41
|
+
* a String representation of a MongoDB ObjectId.
|
|
42
|
+
*/
|
|
9
43
|
generateEntityId(): Promise<string>;
|
|
10
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-store.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/storage/event-store.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"event-store.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/storage/event-store.ts"],"names":[],"mappings":";;;AAUM,QAAA,WAAW,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines a simple representation of an aggregate root that is persisted. This information needs to be persisted so
|
|
3
|
+
* that we can always have a way of knowing what is the current version of the aggregate root object.
|
|
4
|
+
*/
|
|
1
5
|
export declare class StoredAggregateRoot {
|
|
2
6
|
id: string;
|
|
3
7
|
version: number;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StoredAggregateRoot = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Defines a simple representation of an aggregate root that is persisted. This information needs to be persisted so
|
|
6
|
+
* that we can always have a way of knowing what is the current version of the aggregate root object.
|
|
7
|
+
*/
|
|
4
8
|
class StoredAggregateRoot {
|
|
5
9
|
constructor(id, version) {
|
|
6
10
|
this.id = id;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stored-aggregate-root.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/storage/stored-aggregate-root.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAmB;IAC5B,YAAmB,EAAU,EAAS,OAAe;QAAlC,OAAE,GAAF,EAAE,CAAQ;QAAS,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;CAC5D;AAFD,kDAEC"}
|
|
1
|
+
{"version":3,"file":"stored-aggregate-root.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/storage/stored-aggregate-root.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,mBAAmB;IAC5B,YAAmB,EAAU,EAAS,OAAe;QAAlC,OAAE,GAAF,EAAE,CAAQ;QAAS,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;CAC5D;AAFD,kDAEC"}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { ClassConstructor } from "class-transformer";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Represents an event that will be persisted according to the storage solution that is used.
|
|
4
|
+
* The event is defined by metadata like aggregate root id, version and creation date, and it also includes its payload
|
|
5
|
+
* which can be any object based on the use case. Payload serialization is done using class-transformer
|
|
6
|
+
* (https://github.com/typestack/class-transformer) so the payload needs to follow the rules defined by that library.
|
|
7
|
+
*
|
|
8
|
+
* The class constructor is marked as private to force the use of the static factory methods which are implemented based
|
|
9
|
+
* on the use case to create the event.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
3
12
|
export declare class StoredEvent {
|
|
4
13
|
aggregateRootVersion: number;
|
|
5
14
|
private readonly _id;
|
|
@@ -7,13 +16,38 @@ export declare class StoredEvent {
|
|
|
7
16
|
private _createdAt;
|
|
8
17
|
private _payload;
|
|
9
18
|
private _eventName;
|
|
19
|
+
private _aggregateRootName;
|
|
10
20
|
private constructor();
|
|
11
|
-
|
|
12
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Factory method that will create a new event based on the provided info. Typically, it should be used when
|
|
23
|
+
* creating a new event that will be persisted. In this case, the payload is serialized to a plain object using the
|
|
24
|
+
* class-transformer library.
|
|
25
|
+
* @param id The event id
|
|
26
|
+
* @param aggregateRootId The aggregate root id
|
|
27
|
+
* @param aggregateRootName The name of the aggregate root
|
|
28
|
+
* @param payload The event payload as an object.
|
|
29
|
+
*/
|
|
30
|
+
static fromPublishedEvent(id: string, aggregateRootId: string, aggregateRootName: string, payload: object): StoredEvent;
|
|
31
|
+
/**
|
|
32
|
+
* Factory method that will create a new event based on the provided info. Typically, it should be used when creating
|
|
33
|
+
* an event that is already persisted, and we want to create a new instance of it to pass it to an aggregate root.
|
|
34
|
+
* In this case the payload is not mapped to a class instance. {@link getPayloadAs} should be later used for this
|
|
35
|
+
* kind of mapping.
|
|
36
|
+
*
|
|
37
|
+
* @param id The event id
|
|
38
|
+
* @param aggregateRootId The aggregate root id
|
|
39
|
+
* @param eventName The event name
|
|
40
|
+
* @param createdAt The event creation date
|
|
41
|
+
* @param aggregateRootVersion The aggregate root version
|
|
42
|
+
* @param aggregateRootName The aggregate root name
|
|
43
|
+
* @param payload The event payload as an object.
|
|
44
|
+
*/
|
|
45
|
+
static fromStorage(id: string, aggregateRootId: string, eventName: string, createdAt: Date, aggregateRootVersion: number, aggregateRootName: string, payload: unknown): StoredEvent;
|
|
13
46
|
getPayloadAs<T>(payloadClass: ClassConstructor<T>): T;
|
|
14
47
|
get payload(): unknown;
|
|
15
48
|
get id(): string;
|
|
16
49
|
get aggregateRootId(): string;
|
|
17
50
|
get createdAt(): Date;
|
|
18
51
|
get eventName(): string;
|
|
52
|
+
get aggregateRootName(): string;
|
|
19
53
|
}
|
|
@@ -2,28 +2,63 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StoredEvent = void 0;
|
|
4
4
|
const class_transformer_1 = require("class-transformer");
|
|
5
|
-
const registered_event_1 = require("../
|
|
5
|
+
const registered_event_1 = require("../registered-event");
|
|
6
6
|
const type_utils_1 = require("../utils/type-utils");
|
|
7
|
+
/**
|
|
8
|
+
* Represents an event that will be persisted according to the storage solution that is used.
|
|
9
|
+
* The event is defined by metadata like aggregate root id, version and creation date, and it also includes its payload
|
|
10
|
+
* which can be any object based on the use case. Payload serialization is done using class-transformer
|
|
11
|
+
* (https://github.com/typestack/class-transformer) so the payload needs to follow the rules defined by that library.
|
|
12
|
+
*
|
|
13
|
+
* The class constructor is marked as private to force the use of the static factory methods which are implemented based
|
|
14
|
+
* on the use case to create the event.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
7
17
|
class StoredEvent {
|
|
8
18
|
constructor(id, aggregateRootId) {
|
|
9
19
|
this._aggregateRootId = aggregateRootId;
|
|
10
20
|
this._id = id;
|
|
11
21
|
}
|
|
12
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Factory method that will create a new event based on the provided info. Typically, it should be used when
|
|
24
|
+
* creating a new event that will be persisted. In this case, the payload is serialized to a plain object using the
|
|
25
|
+
* class-transformer library.
|
|
26
|
+
* @param id The event id
|
|
27
|
+
* @param aggregateRootId The aggregate root id
|
|
28
|
+
* @param aggregateRootName The name of the aggregate root
|
|
29
|
+
* @param payload The event payload as an object.
|
|
30
|
+
*/
|
|
31
|
+
static fromPublishedEvent(id, aggregateRootId, aggregateRootName, payload) {
|
|
13
32
|
const newEvent = new StoredEvent(id, aggregateRootId);
|
|
14
33
|
newEvent._createdAt = new Date(new Date().toUTCString());
|
|
15
|
-
|
|
34
|
+
newEvent._aggregateRootName = aggregateRootName;
|
|
35
|
+
const eventName = (0, registered_event_1.getEventName)(payload);
|
|
16
36
|
if (!(0, type_utils_1.isNil)(eventName)) {
|
|
17
|
-
newEvent._payload = (0, class_transformer_1.instanceToPlain)(
|
|
37
|
+
newEvent._payload = (0, class_transformer_1.instanceToPlain)(payload);
|
|
18
38
|
newEvent._eventName = eventName;
|
|
19
39
|
}
|
|
20
40
|
return newEvent;
|
|
21
41
|
}
|
|
22
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Factory method that will create a new event based on the provided info. Typically, it should be used when creating
|
|
44
|
+
* an event that is already persisted, and we want to create a new instance of it to pass it to an aggregate root.
|
|
45
|
+
* In this case the payload is not mapped to a class instance. {@link getPayloadAs} should be later used for this
|
|
46
|
+
* kind of mapping.
|
|
47
|
+
*
|
|
48
|
+
* @param id The event id
|
|
49
|
+
* @param aggregateRootId The aggregate root id
|
|
50
|
+
* @param eventName The event name
|
|
51
|
+
* @param createdAt The event creation date
|
|
52
|
+
* @param aggregateRootVersion The aggregate root version
|
|
53
|
+
* @param aggregateRootName The aggregate root name
|
|
54
|
+
* @param payload The event payload as an object.
|
|
55
|
+
*/
|
|
56
|
+
static fromStorage(id, aggregateRootId, eventName, createdAt, aggregateRootVersion, aggregateRootName, payload) {
|
|
23
57
|
const newEvent = new StoredEvent(id, aggregateRootId);
|
|
24
58
|
newEvent._eventName = eventName;
|
|
25
59
|
newEvent._createdAt = createdAt;
|
|
26
60
|
newEvent.aggregateRootVersion = aggregateRootVersion;
|
|
61
|
+
newEvent._aggregateRootName = aggregateRootName;
|
|
27
62
|
newEvent._payload = payload;
|
|
28
63
|
return newEvent;
|
|
29
64
|
}
|
|
@@ -45,6 +80,9 @@ class StoredEvent {
|
|
|
45
80
|
get eventName() {
|
|
46
81
|
return this._eventName;
|
|
47
82
|
}
|
|
83
|
+
get aggregateRootName() {
|
|
84
|
+
return this._aggregateRootName;
|
|
85
|
+
}
|
|
48
86
|
}
|
|
49
87
|
exports.StoredEvent = StoredEvent;
|
|
50
88
|
//# sourceMappingURL=stored-event.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stored-event.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/storage/stored-event.ts"],"names":[],"mappings":";;;AAAA,yDAAoF;
|
|
1
|
+
{"version":3,"file":"stored-event.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/storage/stored-event.ts"],"names":[],"mappings":";;;AAAA,yDAAoF;AACpF,0DAAmD;AACnD,oDAA4C;AAE5C;;;;;;;;;GASG;AACH,MAAa,WAAW;IAUpB,YAAoB,EAAU,EAAE,eAAuB;QACnD,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QACxC,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;IAClB,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,kBAAkB,CACrB,EAAU,EACV,eAAuB,EACvB,iBAAyB,EACzB,OAAe;QAEf,MAAM,QAAQ,GAAG,IAAI,WAAW,CAAC,EAAE,EAAE,eAAe,CAAC,CAAC;QACtD,QAAQ,CAAC,UAAU,GAAG,IAAI,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;QACzD,QAAQ,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;QAEhD,MAAM,SAAS,GAAG,IAAA,+BAAY,EAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,IAAA,kBAAK,EAAC,SAAS,CAAC,EAAE;YACnB,QAAQ,CAAC,QAAQ,GAAG,IAAA,mCAAe,EAAC,OAAO,CAAC,CAAC;YAC7C,QAAQ,CAAC,UAAU,GAAG,SAAS,CAAC;SACnC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,WAAW,CACd,EAAU,EACV,eAAuB,EACvB,SAAiB,EACjB,SAAe,EACf,oBAA4B,EAC5B,iBAAyB,EACzB,OAAgB;QAEhB,MAAM,QAAQ,GAAG,IAAI,WAAW,CAAC,EAAE,EAAE,eAAe,CAAC,CAAC;QACtD,QAAQ,CAAC,UAAU,GAAG,SAAS,CAAC;QAChC,QAAQ,CAAC,UAAU,GAAG,SAAS,CAAC;QAChC,QAAQ,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;QACrD,QAAQ,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;QAChD,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC;QAC5B,OAAO,QAAQ,CAAC;IACpB,CAAC;IAEM,YAAY,CAAI,YAAiC;QACpD,OAAO,IAAA,gCAAY,EAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrD,CAAC;IAED,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IAED,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,gBAAgB,CAAC;IACjC,CAAC;IAED,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED,IAAI,iBAAiB;QACjB,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACnC,CAAC;CACJ;AArGD,kCAqGC"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { AggregateRoot } from "../domain/aggregate-root";
|
|
3
|
-
import { ClassConstructor } from "class-transformer";
|
|
4
|
-
export declare function getProcessFunctionKey(entity: AggregateRoot, eventClass: ClassConstructor<unknown>): string | undefined;
|
|
5
|
-
export declare function EventProcessor(eventClass: ClassConstructor<unknown>): PropertyDecorator;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-processor.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/decorators/event-processor.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAI1B,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAE1C,SAAgB,qBAAqB,CACjC,MAAqB,EACrB,UAAqC;IAErC,MAAM,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IACrD,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,IAAI,CAAC,EAAE;QAC3C,OAAO,SAAS,CAAC;KACpB;IAED,MAAM,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE;QAClD,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QAC1D,OAAO,QAAQ,CAAC,UAAU,KAAK,UAAU,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,WAAW,EAAE;QACd,OAAO,SAAS,CAAC;KACpB;IAED,OAAO,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC;AACxD,CAAC;AAnBD,sDAmBC;AAED,SAAgB,cAAc,CAAC,UAAqC;IAChE,OAAO,CAAC,cAAc,EAAE,WAAW,EAAE,EAAE;QACnC,OAAO,CAAC,cAAc,CAClB,YAAY,GAAG,GAAG,GAAG,WAAW,CAAC,QAAQ,EAAE,EAC3C,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,EAC5C,cAAc,CACjB,CAAC;IACN,CAAC,CAAC;AACN,CAAC;AARD,wCAQC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registered-event.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/decorators/registered-event.ts"],"names":[],"mappings":";;;AACA,mFAA6E;AAE7E,oDAA4C;AAO5C,MAAM,aAAa,GAA6B,EAAE,CAAC;AAEnD,SAAgB,eAAe,CAAC,SAAiB;IAC7C,OAAO,CAAC,MAAM,EAAE,EAAE;QACd,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,SAAS,KAAK,SAAS,CAAC,EAAE;YAC5E,MAAM,IAAI,0DAA0B,CAAC,SAAS,CAAC,CAAC;SACnD;QACD,aAAa,CAAC,IAAI,CAAC;YACf,SAAS,EAAE,SAAS;YACpB,UAAU,EAAE,MAAM;SACrB,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC;AAVD,0CAUC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,MAAoB;IAC7C,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,UAAU,KAAK,MAAM,CAAC,WAAW,CAAC,CAAC;IACnG,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/C,CAAC;AAHD,oCAGC;AAED;;;GAGG;AACH,SAAgB,aAAa,CAAI,IAAY;IACzC,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC;IACpF,OAAO,IAAA,kBAAK,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAE,KAAK,CAAC,UAAkC,CAAC;AAChF,CAAC;AAHD,sCAGC"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { EventPayload } from "../storage/event-payload";
|
|
2
|
-
import { Logger } from "@nestjs/common";
|
|
3
|
-
import { StoredEvent } from "../storage/stored-event";
|
|
4
|
-
export declare abstract class AggregateRoot {
|
|
5
|
-
private readonly _id;
|
|
6
|
-
private _appliedEvents;
|
|
7
|
-
private _version;
|
|
8
|
-
private readonly _logger;
|
|
9
|
-
protected constructor(_id: string, events?: Array<StoredEvent>, logger?: Logger);
|
|
10
|
-
get id(): string;
|
|
11
|
-
get version(): number;
|
|
12
|
-
get logger(): Logger;
|
|
13
|
-
/**
|
|
14
|
-
* Publishes all the provided events using a connected event publisher. To connect a publisher, use the
|
|
15
|
-
* EventStoreConnector. Normally this should never be called by application logic once the connector is used.
|
|
16
|
-
* If a publisher is not connected, the method will return a rejected promise.
|
|
17
|
-
* @param events The events to be published
|
|
18
|
-
*/
|
|
19
|
-
publish(events: Array<EventPayload>): Promise<Array<StoredEvent>>;
|
|
20
|
-
/**
|
|
21
|
-
* All the events that have been previously applied will be committed once this method runs. The commit phase has the
|
|
22
|
-
* effect of publishing all the events. After publishing, the applied events will be deleted so that the next commit
|
|
23
|
-
* publishes newer events.
|
|
24
|
-
* During publishing, the events will be saved to Mongo and after the successful save, all the application event
|
|
25
|
-
* handlers will be called to take care of async updates.
|
|
26
|
-
* Call this once all the events you want, have been applied.
|
|
27
|
-
*/
|
|
28
|
-
commit(): Promise<AggregateRoot>;
|
|
29
|
-
/**
|
|
30
|
-
* Adds an event to the currently applied events of the entity. This will not publish the event. Use the commit
|
|
31
|
-
* method once all the events you want are appliec.
|
|
32
|
-
* @param event The event to be applied
|
|
33
|
-
*/
|
|
34
|
-
apply(event: EventPayload): void;
|
|
35
|
-
/**
|
|
36
|
-
* Returns a clone array of all the currently applied events of the entity.
|
|
37
|
-
*/
|
|
38
|
-
get appliedEvents(): Array<EventPayload>;
|
|
39
|
-
/**
|
|
40
|
-
* Used when a set of events have been retrieved from the database. These events can be passed to the method and the
|
|
41
|
-
* method will trigger all the matching EventProcessor functions of the entity to populate the object based on
|
|
42
|
-
* application logic.
|
|
43
|
-
* @param events The events that will be sent to EventProcessors
|
|
44
|
-
*/
|
|
45
|
-
processEvents(events: Array<StoredEvent>): void;
|
|
46
|
-
protected resolveVersion(events: Array<StoredEvent>): void;
|
|
47
|
-
protected sortEvents(events: Array<StoredEvent>): Array<StoredEvent>;
|
|
48
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AggregateRoot = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
const registered_event_1 = require("../decorators/registered-event");
|
|
6
|
-
const event_processor_1 = require("../decorators/event-processor");
|
|
7
|
-
const missing_event_processor_exception_1 = require("./missing-event-processor-exception");
|
|
8
|
-
const type_utils_1 = require("../utils/type-utils");
|
|
9
|
-
class AggregateRoot {
|
|
10
|
-
constructor(_id, events = [], logger) {
|
|
11
|
-
this._id = _id;
|
|
12
|
-
this._appliedEvents = [];
|
|
13
|
-
this._version = 0;
|
|
14
|
-
if (events && events.length > 0) {
|
|
15
|
-
this.processEvents(events);
|
|
16
|
-
}
|
|
17
|
-
this._logger = (0, type_utils_1.isNil)(logger) ? new common_1.Logger(AggregateRoot.name) : logger;
|
|
18
|
-
}
|
|
19
|
-
get id() {
|
|
20
|
-
return this._id;
|
|
21
|
-
}
|
|
22
|
-
get version() {
|
|
23
|
-
return this._version;
|
|
24
|
-
}
|
|
25
|
-
get logger() {
|
|
26
|
-
return this._logger;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Publishes all the provided events using a connected event publisher. To connect a publisher, use the
|
|
30
|
-
* EventStoreConnector. Normally this should never be called by application logic once the connector is used.
|
|
31
|
-
* If a publisher is not connected, the method will return a rejected promise.
|
|
32
|
-
* @param events The events to be published
|
|
33
|
-
*/
|
|
34
|
-
publish(events) {
|
|
35
|
-
this.logger.error("There is no event publisher assigned");
|
|
36
|
-
return Promise.reject("There is no event publisher assigned");
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* All the events that have been previously applied will be committed once this method runs. The commit phase has the
|
|
40
|
-
* effect of publishing all the events. After publishing, the applied events will be deleted so that the next commit
|
|
41
|
-
* publishes newer events.
|
|
42
|
-
* During publishing, the events will be saved to Mongo and after the successful save, all the application event
|
|
43
|
-
* handlers will be called to take care of async updates.
|
|
44
|
-
* Call this once all the events you want, have been applied.
|
|
45
|
-
*/
|
|
46
|
-
commit() {
|
|
47
|
-
const toPublish = this._appliedEvents.slice(0);
|
|
48
|
-
this._appliedEvents = [];
|
|
49
|
-
if (toPublish.length > 0) {
|
|
50
|
-
return this.publish(toPublish).then(() => Promise.resolve(this));
|
|
51
|
-
}
|
|
52
|
-
return Promise.resolve(this);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Adds an event to the currently applied events of the entity. This will not publish the event. Use the commit
|
|
56
|
-
* method once all the events you want are appliec.
|
|
57
|
-
* @param event The event to be applied
|
|
58
|
-
*/
|
|
59
|
-
apply(event) {
|
|
60
|
-
event.aggregateRootId = this.id;
|
|
61
|
-
this._appliedEvents.push(event);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Returns a clone array of all the currently applied events of the entity.
|
|
65
|
-
*/
|
|
66
|
-
get appliedEvents() {
|
|
67
|
-
return this._appliedEvents.slice(0);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Used when a set of events have been retrieved from the database. These events can be passed to the method and the
|
|
71
|
-
* method will trigger all the matching EventProcessor functions of the entity to populate the object based on
|
|
72
|
-
* application logic.
|
|
73
|
-
* @param events The events that will be sent to EventProcessors
|
|
74
|
-
*/
|
|
75
|
-
processEvents(events) {
|
|
76
|
-
if (events.length > 0) {
|
|
77
|
-
this.sortEvents(events).forEach((ev) => {
|
|
78
|
-
try {
|
|
79
|
-
const eventClass = (0, registered_event_1.getEventClass)(ev.eventName);
|
|
80
|
-
if (!eventClass) {
|
|
81
|
-
this.logger.error(`Found event name with no handler : ${ev.eventName}.`);
|
|
82
|
-
throw new missing_event_processor_exception_1.MissingEventProcessor(ev.eventName, this._id);
|
|
83
|
-
}
|
|
84
|
-
const processorKey = (0, event_processor_1.getProcessFunctionKey)(this, eventClass);
|
|
85
|
-
if (!processorKey) {
|
|
86
|
-
this.logger.error(`Found event name with no handler : ${ev.eventName}.`);
|
|
87
|
-
throw new missing_event_processor_exception_1.MissingEventProcessor(ev.eventName, this._id);
|
|
88
|
-
}
|
|
89
|
-
const mappedEvent = ev.getPayloadAs(eventClass);
|
|
90
|
-
this[processorKey](mappedEvent);
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
this.logger.error(`Unable to process domain event : ${ev.eventName}.`);
|
|
94
|
-
throw error;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
this.resolveVersion(events);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
resolveVersion(events) {
|
|
101
|
-
const sorted = events.sort((e1, e2) => e1.aggregateRootVersion - e2.aggregateRootVersion);
|
|
102
|
-
this._version = sorted.slice(-1)[0].aggregateRootVersion;
|
|
103
|
-
}
|
|
104
|
-
sortEvents(events) {
|
|
105
|
-
return events.sort((e1, e2) => e1.aggregateRootVersion - e2.aggregateRootVersion);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exports.AggregateRoot = AggregateRoot;
|
|
109
|
-
//# sourceMappingURL=aggregate-root.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate-root.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/domain/aggregate-root.ts"],"names":[],"mappings":";;;AACA,2CAAwC;AAExC,qEAA+D;AAC/D,mEAAsE;AACtE,2FAA4E;AAC5E,oDAA4C;AAE5C,MAAsB,aAAa;IAK/B,YAAuC,GAAW,EAAE,SAA6B,EAAE,EAAE,MAAe;QAA7D,QAAG,GAAH,GAAG,CAAQ;QAC9C,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAElB,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC7B,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC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C,oBAAoB,GAAG,EAAE,CAAC,oBAAoB,CAAC,CAAC;QAC9G,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC;IAC7D,CAAC;IAES,UAAU,CAAC,MAA0B;QAC3C,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,oBAAoB,GAAG,EAAE,CAAC,oBAAoB,CAAC,CAAC;IACtF,CAAC;CACJ;AAjHD,sCAiHC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MissingEventProcessor = void 0;
|
|
4
|
-
class MissingEventProcessor extends Error {
|
|
5
|
-
constructor(eventName, aggregateRootId) {
|
|
6
|
-
super(`Missing event processor for event : ${eventName} of aggregate root : ${aggregateRootId}`);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
exports.MissingEventProcessor = MissingEventProcessor;
|
|
10
|
-
//# sourceMappingURL=missing-event-processor-exception.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"missing-event-processor-exception.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/domain/missing-event-processor-exception.ts"],"names":[],"mappings":";;;AAAA,MAAa,qBAAsB,SAAQ,KAAK;IAC5C,YAAY,SAAiB,EAAE,eAAuB;QAClD,KAAK,CAAC,uCAAuC,SAAS,wBAAwB,eAAe,EAAE,CAAC,CAAC;IACrG,CAAC;CACJ;AAJD,sDAIC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-payload.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/storage/event-payload.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"id-generation-exception.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/storage/id-generation-exception.ts"],"names":[],"mappings":";;;AAAA,MAAa,qBAAsB,SAAQ,KAAK;IAC5C,YAAY,SAAiB,EAAE,cAAsB;QACjD,KAAK,CAAC,mDAAmD,SAAS,eAAe,cAAc,EAAE,CAAC,CAAC;IACvG,CAAC;CACJ;AAJD,sDAIC"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|