@event-nest/core 1.0.3 → 1.0.5
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 +1 -1
- package/src/lib/aggregate-root-aware-event.d.ts +11 -0
- package/src/lib/aggregate-root-name.d.ts +9 -0
- package/src/lib/aggregate-root-name.js +9 -0
- package/src/lib/aggregate-root-name.js.map +1 -1
- package/src/lib/aggregate-root.d.ts +4 -0
- package/src/lib/aggregate-root.js +6 -1
- package/src/lib/aggregate-root.js.map +1 -1
- package/src/lib/event-processor.d.ts +8 -0
- package/src/lib/event-processor.js +8 -0
- package/src/lib/event-processor.js.map +1 -1
- package/src/lib/on-domain-event.d.ts +9 -0
- package/src/lib/storage/abstract-event-store.d.ts +6 -0
- package/src/lib/storage/abstract-event-store.js +7 -2
- package/src/lib/storage/abstract-event-store.js.map +1 -1
- package/src/lib/storage/event-store.d.ts +6 -0
- package/src/lib/storage/stored-event.d.ts +2 -1
- package/src/lib/storage/stored-event.js +3 -2
- package/src/lib/storage/stored-event.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@event-nest/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Nick Tsitlakidis",
|
|
6
6
|
"description": "Event sourcing module for NestJS. It provides a set of decorators and classes to build an application based on event sourcing.",
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
export interface AggregateRootAwareEvent<T> {
|
|
2
|
+
/**
|
|
3
|
+
* The unique id of the aggregate root that published the event
|
|
4
|
+
*/
|
|
2
5
|
aggregateRootId: string;
|
|
6
|
+
/**
|
|
7
|
+
* The payload of the event. The type of this object depends on the events
|
|
8
|
+
* you register using the {@link RegisteredEvent} decorator.
|
|
9
|
+
*/
|
|
3
10
|
payload: T;
|
|
11
|
+
/**
|
|
12
|
+
* A UTC timestamp that defines when the event occurred.
|
|
13
|
+
*/
|
|
14
|
+
occurredAt: Date;
|
|
4
15
|
}
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A decorator to mark an aggregate root class with a unique name. The name will
|
|
3
|
+
* be saved with each event in the database.
|
|
4
|
+
*
|
|
5
|
+
* It will also be used during the retrieval process of the events to make sure that
|
|
6
|
+
* the correct events are retrieved.
|
|
7
|
+
* @param name The name of the aggregate root
|
|
8
|
+
* @constructor
|
|
9
|
+
*/
|
|
1
10
|
export declare const AggregateRootName: (name: string) => ClassDecorator;
|
|
2
11
|
export declare function getAggregateRootName(targetClass: Function): string | undefined;
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAggregateRootName = exports.AggregateRootName = void 0;
|
|
4
4
|
const metadata_keys_1 = require("./metadata-keys");
|
|
5
|
+
/**
|
|
6
|
+
* A decorator to mark an aggregate root class with a unique name. The name will
|
|
7
|
+
* be saved with each event in the database.
|
|
8
|
+
*
|
|
9
|
+
* It will also be used during the retrieval process of the events to make sure that
|
|
10
|
+
* the correct events are retrieved.
|
|
11
|
+
* @param name The name of the aggregate root
|
|
12
|
+
* @constructor
|
|
13
|
+
*/
|
|
5
14
|
const AggregateRootName = (name) => {
|
|
6
15
|
return (target) => {
|
|
7
16
|
Reflect.defineMetadata(metadata_keys_1.AGGREGATE_ROOT_NAME_KEY, { aggregateRootName: name }, target);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate-root-name.js","sourceRoot":"","sources":["../../../../../libs/core/src/lib/aggregate-root-name.ts"],"names":[],"mappings":";;;AAAA,mDAA0D;
|
|
1
|
+
{"version":3,"file":"aggregate-root-name.js","sourceRoot":"","sources":["../../../../../libs/core/src/lib/aggregate-root-name.ts"],"names":[],"mappings":";;;AAAA,mDAA0D;AAE1D;;;;;;;;GAQG;AACI,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAkB,EAAE;IAC9D,OAAO,CAAC,MAAc,EAAE,EAAE;QACtB,OAAO,CAAC,cAAc,CAAC,uCAAuB,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,EAAE,MAAM,CAAC,CAAC;IACzF,CAAC,CAAC;AACN,CAAC,CAAC;AAJW,QAAA,iBAAiB,qBAI5B;AAEF,wDAAwD;AACxD,SAAgB,oBAAoB,CAAC,WAAqB;IACtD,OAAO,OAAO,CAAC,WAAW,CAAC,uCAAuB,EAAE,WAAW,CAAC,EAAE,iBAAiB,CAAC;AACxF,CAAC;AAFD,oDAEC"}
|
|
@@ -8,6 +8,10 @@ export declare abstract class AggregateRoot {
|
|
|
8
8
|
private readonly _logger;
|
|
9
9
|
protected constructor(_id: string, logger?: Logger);
|
|
10
10
|
get id(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Defines the current version of the aggregate root. The version is increased
|
|
13
|
+
* each time an event is persisted.
|
|
14
|
+
*/
|
|
11
15
|
get version(): number;
|
|
12
16
|
get logger(): Logger;
|
|
13
17
|
/**
|
|
@@ -17,6 +17,10 @@ class AggregateRoot {
|
|
|
17
17
|
get id() {
|
|
18
18
|
return this._id;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Defines the current version of the aggregate root. The version is increased
|
|
22
|
+
* each time an event is persisted.
|
|
23
|
+
*/
|
|
20
24
|
get version() {
|
|
21
25
|
return this._version;
|
|
22
26
|
}
|
|
@@ -63,7 +67,8 @@ class AggregateRoot {
|
|
|
63
67
|
}
|
|
64
68
|
this._appendedEvents.push({
|
|
65
69
|
aggregateRootId: this.id,
|
|
66
|
-
payload: event
|
|
70
|
+
payload: event,
|
|
71
|
+
occurredAt: new Date(Date.now())
|
|
67
72
|
});
|
|
68
73
|
}
|
|
69
74
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate-root.js","sourceRoot":"","sources":["../../../../../libs/core/src/lib/aggregate-root.ts"],"names":[],"mappings":";;;AA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kB,EAAE,CAAC;QACvC,MAAM,gBAAgB,GAAkB,EAAE,CAAC;QAE3C,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;YAClB,MAAM,UAAU,GAAG,IAAA,gCAAa,EAAC,EAAE,CAAC,SAAS,CAAC,CAAC;YAC/C,IAAI,IAAA,kBAAK,EAAC,UAAU,CAAC,EAAE;gBACnB,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;aACnC;iBAAM;gBACH,MAAM,YAAY,GAAG,IAAA,yCAAuB,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;gBAC/D,IAAI,IAAA,kBAAK,EAAC,YAAY,CAAC,EAAE;oBACrB,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;iBACvC;qBAAM;oBACH,KAAK,CAAC,IAAI,CAAC;wBACP,YAAY;wBACZ,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC;qBACvC,CAAC,CAAC;iBACN;aACJ;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,YAAY,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;IACnD,CAAC;CACJ;AA/ID,sCA+IC"}
|
|
@@ -2,4 +2,12 @@ import "reflect-metadata";
|
|
|
2
2
|
import { AggregateRoot } from "./aggregate-root";
|
|
3
3
|
import { ClassConstructor } from "class-transformer";
|
|
4
4
|
export declare function getDecoratedPropertyKey(entity: AggregateRoot, eventClass: ClassConstructor<unknown>): string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* A decorator to mark a method as an event processor.
|
|
7
|
+
* When an aggregate root has to be recreated based on database events, these methods
|
|
8
|
+
* are called to process the events.
|
|
9
|
+
*
|
|
10
|
+
* @param eventClass The event class that this method processes.
|
|
11
|
+
* @constructor
|
|
12
|
+
*/
|
|
5
13
|
export declare function EventProcessor(eventClass: ClassConstructor<unknown>): PropertyDecorator;
|
|
@@ -18,6 +18,14 @@ function getDecoratedPropertyKey(entity, eventClass) {
|
|
|
18
18
|
return Reflect.getMetadata(matchingKey, entity).key;
|
|
19
19
|
}
|
|
20
20
|
exports.getDecoratedPropertyKey = getDecoratedPropertyKey;
|
|
21
|
+
/**
|
|
22
|
+
* A decorator to mark a method as an event processor.
|
|
23
|
+
* When an aggregate root has to be recreated based on database events, these methods
|
|
24
|
+
* are called to process the events.
|
|
25
|
+
*
|
|
26
|
+
* @param eventClass The event class that this method processes.
|
|
27
|
+
* @constructor
|
|
28
|
+
*/
|
|
21
29
|
function EventProcessor(eventClass) {
|
|
22
30
|
return (propertyParent, propertyKey) => {
|
|
23
31
|
Reflect.defineMetadata(metadata_keys_1.EVENT_PROCESSOR_KEY + "-" + propertyKey.toString(), { eventClass: eventClass, key: propertyKey }, propertyParent);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-processor.js","sourceRoot":"","sources":["../../../../../libs/core/src/lib/event-processor.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAG1B,mDAAsD;AAEtD,SAAgB,uBAAuB,CACnC,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,0DAmBC;AAED,SAAgB,cAAc,CAAC,UAAqC;IAChE,OAAO,CAAC,cAAc,EAAE,WAAW,EAAE,EAAE;QACnC,OAAO,CAAC,cAAc,CAClB,mCAAmB,GAAG,GAAG,GAAG,WAAW,CAAC,QAAQ,EAAE,EAClD,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,EAC5C,cAAc,CACjB,CAAC;IACN,CAAC,CAAC;AACN,CAAC;AARD,wCAQC"}
|
|
1
|
+
{"version":3,"file":"event-processor.js","sourceRoot":"","sources":["../../../../../libs/core/src/lib/event-processor.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAG1B,mDAAsD;AAEtD,SAAgB,uBAAuB,CACnC,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,0DAmBC;AAED;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,UAAqC;IAChE,OAAO,CAAC,cAAc,EAAE,WAAW,EAAE,EAAE;QACnC,OAAO,CAAC,cAAc,CAClB,mCAAmB,GAAG,GAAG,GAAG,WAAW,CAAC,QAAQ,EAAE,EAClD,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,EAC5C,cAAc,CACjB,CAAC;IACN,CAAC,CAAC;AACN,CAAC;AARD,wCAQC"}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { AggregateRootAwareEvent } from "./aggregate-root-aware-event";
|
|
2
|
+
/**
|
|
3
|
+
* A basic interface that can be implemented by nest.js services to make sure
|
|
4
|
+
* that they can be called by the {@link DomainEventEmitter} when a domain event is emitted.
|
|
5
|
+
* The service also has to be decorated with the {@link DomainEventSubscription} decorator.
|
|
6
|
+
*/
|
|
2
7
|
export interface OnDomainEvent<T> {
|
|
8
|
+
/**
|
|
9
|
+
* Called by the {@link DomainEventEmitter} when a domain event is emitted.
|
|
10
|
+
* @param event The domain event that was emitted along with the id of the aggregate root that emitted it.
|
|
11
|
+
*/
|
|
3
12
|
onDomainEvent(event: AggregateRootAwareEvent<T>): Promise<unknown>;
|
|
4
13
|
}
|
|
@@ -3,10 +3,16 @@ import { StoredEvent } from "./stored-event";
|
|
|
3
3
|
import { AggregateRoot } from "../aggregate-root";
|
|
4
4
|
import { StoredAggregateRoot } from "./stored-aggregate-root";
|
|
5
5
|
import { DomainEventEmitter } from "../domain-event-emitter";
|
|
6
|
+
/**
|
|
7
|
+
* An abstract implementation of the {@link EventStore} interface.
|
|
8
|
+
* Regardless of the database technology, all subclasses should have a common implementation
|
|
9
|
+
* of the {@link EventStore:addPublisher} method and this is why this class exists.
|
|
10
|
+
*/
|
|
6
11
|
export declare abstract class AbstractEventStore implements EventStore {
|
|
7
12
|
private _eventBus;
|
|
8
13
|
protected constructor(_eventBus: DomainEventEmitter);
|
|
9
14
|
abstract findByAggregateRootId<T extends AggregateRoot>(aggregateRootClass: AggregateRootClass<T>, id: string): Promise<Array<StoredEvent>>;
|
|
15
|
+
abstract findAggregateRootVersion(id: string): Promise<number>;
|
|
10
16
|
abstract save(events: Array<StoredEvent>, aggregate: StoredAggregateRoot): Promise<Array<StoredEvent>>;
|
|
11
17
|
abstract generateEntityId(): Promise<string>;
|
|
12
18
|
addPublisher<T extends AggregateRoot>(aggregateRoot: T): T;
|
|
@@ -7,6 +7,11 @@ const id_generation_exception_1 = require("../exceptions/id-generation-exception
|
|
|
7
7
|
const type_utils_1 = require("../utils/type-utils");
|
|
8
8
|
const aggregate_root_name_1 = require("../aggregate-root-name");
|
|
9
9
|
const missing_aggregate_root_name_exception_1 = require("../exceptions/missing-aggregate-root-name-exception");
|
|
10
|
+
/**
|
|
11
|
+
* An abstract implementation of the {@link EventStore} interface.
|
|
12
|
+
* Regardless of the database technology, all subclasses should have a common implementation
|
|
13
|
+
* of the {@link EventStore:addPublisher} method and this is why this class exists.
|
|
14
|
+
*/
|
|
10
15
|
class AbstractEventStore {
|
|
11
16
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
12
17
|
constructor(_eventBus) {
|
|
@@ -25,9 +30,9 @@ class AbstractEventStore {
|
|
|
25
30
|
if (ids.length !== events.length || !(0, type_utils_1.hasAllValues)(ids)) {
|
|
26
31
|
throw new id_generation_exception_1.IdGenerationException(ids.length, events.length);
|
|
27
32
|
}
|
|
28
|
-
const storedEvents = events.map((
|
|
33
|
+
const storedEvents = events.map((arAwareEvent) => {
|
|
29
34
|
const id = ids.pop();
|
|
30
|
-
return stored_event_1.StoredEvent.fromPublishedEvent(id, aggregateRoot.id, aggregateRootName,
|
|
35
|
+
return stored_event_1.StoredEvent.fromPublishedEvent(id, aggregateRoot.id, aggregateRootName, arAwareEvent.payload, arAwareEvent.occurredAt);
|
|
31
36
|
});
|
|
32
37
|
const toStore = new stored_aggregate_root_1.StoredAggregateRoot(aggregateRoot.id, aggregateRoot.version);
|
|
33
38
|
return this.save(storedEvents, toStore).then((savedEvents) => {
|
|
@@ -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;AAE7C,mEAA8D;AAC9D,mFAA8E;AAE9E,oDAA0D;AAE1D,gEAA8D;AAC9D,+GAAwG;AAExG,MAAsB,kBAAkB;IACpC,gEAAgE;IAChE,YAA8B,SAA6B;QAA7B,cAAS,GAAT,SAAS,CAAoB;IAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"abstract-event-store.js","sourceRoot":"","sources":["../../../../../../libs/core/src/lib/storage/abstract-event-store.ts"],"names":[],"mappings":";;;AACA,iDAA6C;AAE7C,mEAA8D;AAC9D,mFAA8E;AAE9E,oDAA0D;AAE1D,gEAA8D;AAC9D,+GAAwG;AAExG;;;;GAIG;AACH,MAAsB,kBAAkB;IACpC,gEAAgE;IAChE,YAA8B,SAA6B;QAA7B,cAAS,GAAT,SAAS,CAAoB;IAAG,CAAC;IAa/D,YAAY,CAA0B,aAAgB;QAClD,aAAa,CAAC,OAAO,GAAG,KAAK,EAAE,MAA8C,EAAE,EAAE;YAC7E,MAAM,iBAAiB,GAAG,IAAA,0CAAoB,EAAC,aAAa,CAAC,WAAW,CAAC,CAAC;YAC1E,IAAI,IAAA,kBAAK,EAAC,iBAAiB,CAAC,EAAE;gBAC1B,MAAM,IAAI,yEAAiC,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;aAC/E;YAED,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE;gBACpB,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;aAC9B;YAED,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC;YACzE,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,IAAI,CAAC,IAAA,yBAAY,EAAC,GAAG,CAAC,EAAE;gBACpD,MAAM,IAAI,+CAAqB,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;aAC9D;YACD,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE;gBAC7C,MAAM,EAAE,GAAG,GAAG,CAAC,GAAG,EAAG,CAAC;gBACtB,OAAO,0BAAW,CAAC,kBAAkB,CACjC,EAAE,EACF,aAAa,CAAC,EAAE,EAChB,iBAAiB,EACjB,YAAY,CAAC,OAAO,EACpB,YAAY,CAAC,UAAU,CAC1B,CAAC;YACN,CAAC,CAAC,CAAC;YAEH,MAAM,OAAO,GAAG,IAAI,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;AAjDD,gDAiDC"}
|
|
@@ -26,6 +26,12 @@ export interface EventStore {
|
|
|
26
26
|
* @param id The unique id of the aggregate root object
|
|
27
27
|
*/
|
|
28
28
|
findByAggregateRootId<T extends AggregateRoot>(aggregateRootClass: AggregateRootClass<T>, id: string): Promise<Array<StoredEvent>>;
|
|
29
|
+
/**
|
|
30
|
+
* Finds the version of the aggregate root object that is associated with the provided id. If the aggregate root is not found
|
|
31
|
+
* or there's no version information, the method will return -1
|
|
32
|
+
* @param id The id of the aggregate root object
|
|
33
|
+
*/
|
|
34
|
+
findAggregateRootVersion(id: string): Promise<number>;
|
|
29
35
|
/**
|
|
30
36
|
* Saves the provided event and aggregate root object. Before saving the aggregate root object, the method will check
|
|
31
37
|
* if the version of the aggregate root object is the same as the version of the aggregate root object in the database.
|
|
@@ -26,8 +26,9 @@ export declare class StoredEvent {
|
|
|
26
26
|
* @param aggregateRootId The aggregate root id
|
|
27
27
|
* @param aggregateRootName The name of the aggregate root
|
|
28
28
|
* @param payload The event payload as an object.
|
|
29
|
+
* @param occurredAt The event creation date
|
|
29
30
|
*/
|
|
30
|
-
static fromPublishedEvent(id: string, aggregateRootId: string, aggregateRootName: string, payload: object): StoredEvent;
|
|
31
|
+
static fromPublishedEvent(id: string, aggregateRootId: string, aggregateRootName: string, payload: object, occurredAt: Date): StoredEvent;
|
|
31
32
|
/**
|
|
32
33
|
* Factory method that will create a new event based on the provided info. Typically, it should be used when creating
|
|
33
34
|
* an event that is already persisted, and we want to create a new instance of it to pass it to an aggregate root.
|
|
@@ -27,10 +27,11 @@ class StoredEvent {
|
|
|
27
27
|
* @param aggregateRootId The aggregate root id
|
|
28
28
|
* @param aggregateRootName The name of the aggregate root
|
|
29
29
|
* @param payload The event payload as an object.
|
|
30
|
+
* @param occurredAt The event creation date
|
|
30
31
|
*/
|
|
31
|
-
static fromPublishedEvent(id, aggregateRootId, aggregateRootName, payload) {
|
|
32
|
+
static fromPublishedEvent(id, aggregateRootId, aggregateRootName, payload, occurredAt) {
|
|
32
33
|
const newEvent = new StoredEvent(id, aggregateRootId);
|
|
33
|
-
newEvent._createdAt =
|
|
34
|
+
newEvent._createdAt = occurredAt;
|
|
34
35
|
newEvent._aggregateRootName = aggregateRootName;
|
|
35
36
|
const eventName = (0, registered_event_1.getEventName)(payload);
|
|
36
37
|
if (!(0, type_utils_1.isNil)(eventName)) {
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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;;;;;;;;;OASG;IACH,MAAM,CAAC,kBAAkB,CACrB,EAAU,EACV,eAAuB,EACvB,iBAAyB,EACzB,OAAe,EACf,UAAgB;QAEhB,MAAM,QAAQ,GAAG,IAAI,WAAW,CAAC,EAAE,EAAE,eAAe,CAAC,CAAC;QACtD,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;QACjC,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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