ddd-node 24.4.0 → 24.5.1
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/dist/core/aggregate/event-sourced-aggregate/event-sourced-aggregate.js +1 -1
- package/dist/core/message/command/command.builder.js +2 -1
- package/dist/core/message/event/event.builder.js +2 -1
- package/dist/core/message/message-base/message.builder.d.ts +5 -3
- package/dist/core/message/message-base/message.builder.js +9 -3
- package/dist/core/message/message-base/message.d.ts +7 -8
- package/dist/core/message/message-base/message.js +13 -12
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -104,7 +104,7 @@ class EventSourcedAggregateBase extends aggregate_base_1.AggregateBase {
|
|
|
104
104
|
const events = (0, utils_1.toArray)(handler.call(this, command));
|
|
105
105
|
events.forEach((event) => {
|
|
106
106
|
event.setCausationId(command.id());
|
|
107
|
-
event.setCorrelationIds(command.
|
|
107
|
+
event.setCorrelationIds(command.correlationIds());
|
|
108
108
|
});
|
|
109
109
|
this.applyEvents(events);
|
|
110
110
|
this._handledCommands.push(command);
|
|
@@ -13,7 +13,8 @@ class CommandBuilder extends message_base_1.MessageBuilderBase {
|
|
|
13
13
|
return new this.commandClass({
|
|
14
14
|
id: this.id,
|
|
15
15
|
timestamp: this.timestamp,
|
|
16
|
-
|
|
16
|
+
causationId: this.causationId,
|
|
17
|
+
correlationIds: this.correlationIds,
|
|
17
18
|
}, this.props);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -20,7 +20,8 @@ class EventBuilder extends message_base_1.MessageBuilderBase {
|
|
|
20
20
|
id: this.id,
|
|
21
21
|
timestamp: this.timestamp,
|
|
22
22
|
source: this.source,
|
|
23
|
-
|
|
23
|
+
causationId: this.causationId,
|
|
24
|
+
correlationIds: this.correlationIds,
|
|
24
25
|
}, this.props);
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { IdentifiableModelBuilder } from "../../identifiable-model";
|
|
2
|
-
import { AnyMessage,
|
|
2
|
+
import { AnyMessage, CorrelationIds, MessageClassWithTypedConstructor } from "./message";
|
|
3
3
|
export declare abstract class MessageBuilderBase<T extends AnyMessage> extends IdentifiableModelBuilder<T> {
|
|
4
4
|
protected timestamp: number;
|
|
5
|
-
protected
|
|
6
|
-
|
|
5
|
+
protected causationId?: string;
|
|
6
|
+
protected correlationIds: CorrelationIds;
|
|
7
|
+
withCausationId(causationId: string): this;
|
|
8
|
+
withCorrelationIds(correlationIds: CorrelationIds): this;
|
|
7
9
|
withTimestamp(timestamp: number): this;
|
|
8
10
|
withTimestampNow(): this;
|
|
9
11
|
}
|
|
@@ -6,9 +6,14 @@ class MessageBuilderBase extends identifiable_model_1.IdentifiableModelBuilder {
|
|
|
6
6
|
constructor() {
|
|
7
7
|
super(...arguments);
|
|
8
8
|
this.timestamp = Date.now();
|
|
9
|
+
this.correlationIds = {};
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
this.
|
|
11
|
+
withCausationId(causationId) {
|
|
12
|
+
this.causationId = causationId;
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
withCorrelationIds(correlationIds) {
|
|
16
|
+
this.correlationIds = correlationIds;
|
|
12
17
|
return this;
|
|
13
18
|
}
|
|
14
19
|
withTimestamp(timestamp) {
|
|
@@ -30,8 +35,9 @@ class MessageBuilder extends MessageBuilderBase {
|
|
|
30
35
|
throw new Error("The props must be set before build");
|
|
31
36
|
return new this.messageClass({
|
|
32
37
|
id: this.id,
|
|
33
|
-
context: this.context,
|
|
34
38
|
timestamp: this.timestamp,
|
|
39
|
+
correlationIds: this.correlationIds,
|
|
40
|
+
causationId: this.causationId,
|
|
35
41
|
}, this.props);
|
|
36
42
|
}
|
|
37
43
|
}
|
|
@@ -3,24 +3,23 @@ import { Props, PropsOf } from "../../../base";
|
|
|
3
3
|
import { ClassStatic } from "../../../types";
|
|
4
4
|
import { IdentifiableModel, IdentifiableModelMetadata } from "../../identifiable-model";
|
|
5
5
|
export interface CorrelationIds {
|
|
6
|
-
[type: string]: string;
|
|
7
|
-
}
|
|
8
|
-
export interface MessageContext {
|
|
9
|
-
correlationIds?: CorrelationIds;
|
|
10
|
-
causationId?: string;
|
|
6
|
+
[type: string]: string | undefined;
|
|
11
7
|
}
|
|
12
8
|
export interface MessageMetadata extends IdentifiableModelMetadata {
|
|
13
9
|
timestamp: number;
|
|
14
|
-
|
|
10
|
+
causationId?: string;
|
|
11
|
+
correlationIds: CorrelationIds;
|
|
15
12
|
}
|
|
16
13
|
export declare class MessageBase<P extends Props> extends IdentifiableModel<P> {
|
|
17
14
|
private readonly _timestamp;
|
|
18
|
-
private
|
|
15
|
+
private _causationId?;
|
|
16
|
+
private _correlationIds;
|
|
19
17
|
constructor(metadata: MessageMetadata, props: P);
|
|
20
18
|
props(): P;
|
|
21
19
|
metadata(): MessageMetadata;
|
|
22
20
|
timestamp(): number;
|
|
23
|
-
|
|
21
|
+
correlationIds(): CorrelationIds;
|
|
22
|
+
causationId(): string | undefined;
|
|
24
23
|
setCausationId(causationId: string): void;
|
|
25
24
|
addCorrelationId(type: string, correlationId: string): void;
|
|
26
25
|
setCorrelationIds(correlationIds: CorrelationIds): void;
|
|
@@ -15,8 +15,9 @@ const identifiable_model_1 = require("../../identifiable-model");
|
|
|
15
15
|
let MessageBase = class MessageBase extends identifiable_model_1.IdentifiableModel {
|
|
16
16
|
constructor(metadata, props) {
|
|
17
17
|
super(metadata);
|
|
18
|
-
this._context = metadata?.context ?? {};
|
|
19
18
|
this._timestamp = metadata.timestamp;
|
|
19
|
+
this._causationId = metadata.causationId;
|
|
20
|
+
this._correlationIds = metadata.correlationIds;
|
|
20
21
|
this.initializeProps(props);
|
|
21
22
|
}
|
|
22
23
|
props() {
|
|
@@ -26,28 +27,28 @@ let MessageBase = class MessageBase extends identifiable_model_1.IdentifiableMod
|
|
|
26
27
|
return {
|
|
27
28
|
...super.metadata(),
|
|
28
29
|
timestamp: this._timestamp,
|
|
29
|
-
|
|
30
|
+
correlationIds: this._correlationIds,
|
|
31
|
+
causationId: this._causationId,
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
timestamp() {
|
|
33
35
|
return this._timestamp;
|
|
34
36
|
}
|
|
35
|
-
|
|
36
|
-
return this.
|
|
37
|
+
correlationIds() {
|
|
38
|
+
return this._correlationIds;
|
|
39
|
+
}
|
|
40
|
+
causationId() {
|
|
41
|
+
return this._causationId;
|
|
37
42
|
}
|
|
38
43
|
setCausationId(causationId) {
|
|
39
|
-
if (!this.
|
|
40
|
-
this.
|
|
44
|
+
if (!this._causationId)
|
|
45
|
+
this._causationId = causationId;
|
|
41
46
|
}
|
|
42
47
|
addCorrelationId(type, correlationId) {
|
|
43
|
-
|
|
44
|
-
this._context.correlationIds = {};
|
|
45
|
-
if (!this._context.correlationIds[type])
|
|
46
|
-
this._context.correlationIds[type] = correlationId;
|
|
48
|
+
this._correlationIds[type] = correlationId;
|
|
47
49
|
}
|
|
48
50
|
setCorrelationIds(correlationIds) {
|
|
49
|
-
|
|
50
|
-
this._context.correlationIds = correlationIds;
|
|
51
|
+
this._correlationIds = correlationIds;
|
|
51
52
|
}
|
|
52
53
|
};
|
|
53
54
|
exports.MessageBase = MessageBase;
|
package/dist/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"ddd-node","version":"24.
|
|
1
|
+
{"name":"ddd-node","version":"24.5.1","description":"Domain Driven Design base for NodeJs","type":"commonjs","main":"index.js","types":"index.d.ts","files":["dist"],"repository":{"type":"git","url":"https://github.com/nqd881/ddd-node"},"keywords":["ddd","ddd-node","ddd-base","ddd-ts","ddd-js"],"author":"Quoc Dai","license":"ISC","devDependencies":{"@types/chai":"^4.3.16","@types/lodash":"^4.14.200","@types/mocha":"^10.0.6","@types/uuid":"^9.0.6","chai":"^5.1.1","chai-deep-match":"^1.2.1","ddd-node":"file:dist","mocha":"^10.4.0","ts-node":"^10.9.1","tsconfig-paths":"^4.2.0","typescript":"^5.2.2"},"dependencies":{"lodash":"^4.17.21","reflect-metadata":"^0.1.13","tsc-alias":"^1.8.8","type-fest":"^4.20.1","uuid":"^9.0.1"}}
|