ddd-node 24.3.0 → 24.5.0
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 +2 -4
- 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 +11 -7
- package/dist/core/message/message-base/message.js +18 -10
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -103,10 +103,8 @@ class EventSourcedAggregateBase extends aggregate_base_1.AggregateBase {
|
|
|
103
103
|
const handler = this.getHandlerForCommand(command);
|
|
104
104
|
const events = (0, utils_1.toArray)(handler.call(this, command));
|
|
105
105
|
events.forEach((event) => {
|
|
106
|
-
event.
|
|
107
|
-
|
|
108
|
-
causationId: command.id(),
|
|
109
|
-
});
|
|
106
|
+
event.setCausationId(command.id());
|
|
107
|
+
event.setCorrelationIds(command.correlationIds());
|
|
110
108
|
});
|
|
111
109
|
this.applyEvents(events);
|
|
112
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
|
}
|
|
@@ -2,23 +2,27 @@ import { Class } from "type-fest";
|
|
|
2
2
|
import { Props, PropsOf } from "../../../base";
|
|
3
3
|
import { ClassStatic } from "../../../types";
|
|
4
4
|
import { IdentifiableModel, IdentifiableModelMetadata } from "../../identifiable-model";
|
|
5
|
-
export interface
|
|
6
|
-
|
|
7
|
-
causationId?: string;
|
|
5
|
+
export interface CorrelationIds {
|
|
6
|
+
[type: string]: string;
|
|
8
7
|
}
|
|
9
8
|
export interface MessageMetadata extends IdentifiableModelMetadata {
|
|
10
9
|
timestamp: number;
|
|
11
|
-
|
|
10
|
+
causationId?: string;
|
|
11
|
+
correlationIds: CorrelationIds;
|
|
12
12
|
}
|
|
13
13
|
export declare class MessageBase<P extends Props> extends IdentifiableModel<P> {
|
|
14
14
|
private readonly _timestamp;
|
|
15
|
-
private
|
|
15
|
+
private _causationId?;
|
|
16
|
+
private _correlationIds;
|
|
16
17
|
constructor(metadata: MessageMetadata, props: P);
|
|
17
18
|
props(): P;
|
|
18
19
|
metadata(): MessageMetadata;
|
|
19
20
|
timestamp(): number;
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
correlationIds(): CorrelationIds;
|
|
22
|
+
causationId(): string | undefined;
|
|
23
|
+
setCausationId(causationId: string): void;
|
|
24
|
+
addCorrelationId(type: string, correlationId: string): void;
|
|
25
|
+
setCorrelationIds(correlationIds: CorrelationIds): void;
|
|
22
26
|
}
|
|
23
27
|
export type AnyMessage = MessageBase<Props>;
|
|
24
28
|
export interface MessageClass<T extends AnyMessage = AnyMessage, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof MessageBase<PropsOf<T>>> {
|
|
@@ -8,19 +8,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.MessageBase = void 0;
|
|
16
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
17
13
|
const base_1 = require("../../../base");
|
|
18
14
|
const identifiable_model_1 = require("../../identifiable-model");
|
|
19
15
|
let MessageBase = class MessageBase extends identifiable_model_1.IdentifiableModel {
|
|
20
16
|
constructor(metadata, props) {
|
|
21
17
|
super(metadata);
|
|
22
|
-
this._context = metadata?.context ?? {};
|
|
23
18
|
this._timestamp = metadata.timestamp;
|
|
19
|
+
this._causationId = metadata.causationId;
|
|
20
|
+
this._correlationIds = metadata.correlationIds;
|
|
24
21
|
this.initializeProps(props);
|
|
25
22
|
}
|
|
26
23
|
props() {
|
|
@@ -30,17 +27,28 @@ let MessageBase = class MessageBase extends identifiable_model_1.IdentifiableMod
|
|
|
30
27
|
return {
|
|
31
28
|
...super.metadata(),
|
|
32
29
|
timestamp: this._timestamp,
|
|
33
|
-
|
|
30
|
+
correlationIds: this._correlationIds,
|
|
31
|
+
causationId: this._causationId,
|
|
34
32
|
};
|
|
35
33
|
}
|
|
36
34
|
timestamp() {
|
|
37
35
|
return this._timestamp;
|
|
38
36
|
}
|
|
39
|
-
|
|
40
|
-
return this.
|
|
37
|
+
correlationIds() {
|
|
38
|
+
return this._correlationIds;
|
|
39
|
+
}
|
|
40
|
+
causationId() {
|
|
41
|
+
return this._causationId;
|
|
42
|
+
}
|
|
43
|
+
setCausationId(causationId) {
|
|
44
|
+
if (!this._causationId)
|
|
45
|
+
this._causationId = causationId;
|
|
46
|
+
}
|
|
47
|
+
addCorrelationId(type, correlationId) {
|
|
48
|
+
this._correlationIds[type] = correlationId;
|
|
41
49
|
}
|
|
42
|
-
|
|
43
|
-
this.
|
|
50
|
+
setCorrelationIds(correlationIds) {
|
|
51
|
+
this._correlationIds = correlationIds;
|
|
44
52
|
}
|
|
45
53
|
};
|
|
46
54
|
exports.MessageBase = MessageBase;
|
package/dist/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"ddd-node","version":"24.
|
|
1
|
+
{"name":"ddd-node","version":"24.5.0","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"}}
|