ddd-node 8.1.0 → 9.0.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.d.ts +7 -6
- package/dist/core/aggregate.js +24 -22
- package/dist/core/entity.d.ts +2 -2
- package/dist/core/entity.js +2 -2
- package/dist/core/error.js +1 -1
- package/dist/core/event.d.ts +1 -1
- package/dist/core/event.js +1 -1
- package/dist/core/message.d.ts +3 -3
- package/dist/core/message.js +4 -4
- package/dist/core/model.d.ts +1 -1
- package/dist/core/model.js +1 -1
- package/package.json +1 -1
package/dist/core/aggregate.d.ts
CHANGED
|
@@ -11,15 +11,15 @@ export interface AggregateBaseMetadata extends EntityMetadata {
|
|
|
11
11
|
export declare abstract class AggregateBase<Props extends object> extends Entity<Props> {
|
|
12
12
|
protected readonly _version: number;
|
|
13
13
|
constructor(metadata: AggregateBaseMetadata, props?: Props);
|
|
14
|
-
abstract
|
|
14
|
+
abstract getVersion(): number;
|
|
15
15
|
protected newEvent<E extends AnyEvent>(eventClass: EventClassWithTypedConstructor<E>, props: PropsOf<E>): E;
|
|
16
16
|
}
|
|
17
17
|
export declare class Aggregate<Props extends object> extends AggregateBase<Props> {
|
|
18
18
|
private _events;
|
|
19
19
|
constructor(metadata: AggregateBaseMetadata, props: Props);
|
|
20
20
|
static newAggregate<T extends AnyAggregate>(this: AggregateClassWithTypedConstructor<T>, props: PropsOf<T>, id?: Id): T;
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
getVersion(): number;
|
|
22
|
+
getEvents(): AnyEvent[];
|
|
23
23
|
protected recordEvent<E extends AnyEvent>(event: E): void;
|
|
24
24
|
protected recordEvent<E extends AnyEvent>(eventClass: EventClass<E>, props: PropsOf<E>): void;
|
|
25
25
|
clearEvents(): void;
|
|
@@ -40,9 +40,10 @@ export declare class AggregateES<Props extends object> extends AggregateBase<Pro
|
|
|
40
40
|
static fromSnapshot<T extends AnyAggregateES>(this: AggregateESClassWithTypedConstructor<T>, snapshot: Snapshot<T>, events?: AnyEvent[]): T;
|
|
41
41
|
static eventAppliersMap<T extends AnyAggregateES>(this: AggregateESClass<T>): Map<string, EventApplier>;
|
|
42
42
|
static commandHandlersMap<T extends AnyAggregateES>(this: AggregateESClass<T>): Map<string, CommandHandler>;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
getVersion(): number;
|
|
44
|
+
getPastEvents(): AnyEvent[];
|
|
45
|
+
getEvents(): AnyEvent[];
|
|
46
|
+
getHandledCommands(): AnyCommand[];
|
|
46
47
|
eventAppliersMap(): Map<string, EventApplier>;
|
|
47
48
|
hasEvent(): boolean;
|
|
48
49
|
getApplierForEvent<E extends AnyEvent>(event: E): EventApplier<E>;
|
package/dist/core/aggregate.js
CHANGED
|
@@ -12,9 +12,9 @@ class AggregateBase extends entity_1.Entity {
|
|
|
12
12
|
}
|
|
13
13
|
newEvent(eventClass, props) {
|
|
14
14
|
const eventSource = {
|
|
15
|
-
type: this.
|
|
16
|
-
id: this.
|
|
17
|
-
version: this.
|
|
15
|
+
type: this.getType(),
|
|
16
|
+
id: this.getId(),
|
|
17
|
+
version: this.getVersion(),
|
|
18
18
|
};
|
|
19
19
|
return eventClass.newEvent(eventSource, props);
|
|
20
20
|
}
|
|
@@ -31,10 +31,10 @@ class Aggregate extends AggregateBase {
|
|
|
31
31
|
version: 0,
|
|
32
32
|
}, props);
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
getVersion() {
|
|
35
35
|
return this._version;
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
getEvents() {
|
|
38
38
|
return this._events;
|
|
39
39
|
}
|
|
40
40
|
recordEvent(param1, param2) {
|
|
@@ -82,14 +82,16 @@ class AggregateES extends AggregateBase {
|
|
|
82
82
|
static commandHandlersMap() {
|
|
83
83
|
return (0, metadata_1.getCommandHandlersMap)(this.prototype);
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
return
|
|
87
|
-
(this.hasEvent() ? this._events.length : this._pastEvents.length));
|
|
85
|
+
getVersion() {
|
|
86
|
+
return this._version + this._pastEvents.length + this._events.length;
|
|
88
87
|
}
|
|
89
|
-
|
|
88
|
+
getPastEvents() {
|
|
89
|
+
return this._pastEvents;
|
|
90
|
+
}
|
|
91
|
+
getEvents() {
|
|
90
92
|
return this._events;
|
|
91
93
|
}
|
|
92
|
-
|
|
94
|
+
getHandledCommands() {
|
|
93
95
|
return this._handledCommands;
|
|
94
96
|
}
|
|
95
97
|
eventAppliersMap() {
|
|
@@ -99,19 +101,19 @@ class AggregateES extends AggregateBase {
|
|
|
99
101
|
return Boolean(this._events.length);
|
|
100
102
|
}
|
|
101
103
|
getApplierForEvent(event) {
|
|
102
|
-
const
|
|
103
|
-
const applier = this.eventAppliersMap().get(
|
|
104
|
+
const eventType = event.getType();
|
|
105
|
+
const applier = this.eventAppliersMap().get(eventType);
|
|
104
106
|
if (!applier)
|
|
105
107
|
throw new Error("Event applier not found");
|
|
106
108
|
return applier;
|
|
107
109
|
}
|
|
108
110
|
validateEventBeforeApply(event) {
|
|
109
|
-
const
|
|
110
|
-
if (
|
|
111
|
+
const eventSource = event.getSource();
|
|
112
|
+
if (eventSource.type !== this.getType())
|
|
111
113
|
throw new Error("Invalid source type");
|
|
112
|
-
if (!
|
|
114
|
+
if (!eventSource.id.equals(this._id))
|
|
113
115
|
throw new Error("Invalid source id");
|
|
114
|
-
if (
|
|
116
|
+
if (eventSource.version !== this.getVersion())
|
|
115
117
|
throw new Error("Invalid source version");
|
|
116
118
|
}
|
|
117
119
|
_applyEvent(event) {
|
|
@@ -143,8 +145,8 @@ class AggregateES extends AggregateBase {
|
|
|
143
145
|
return this.constructor.commandHandlersMap();
|
|
144
146
|
}
|
|
145
147
|
getHandlerForCommand(command) {
|
|
146
|
-
const
|
|
147
|
-
const handler = this.commandHandlersMap().get(
|
|
148
|
+
const commandType = command.getType();
|
|
149
|
+
const handler = this.commandHandlersMap().get(commandType);
|
|
148
150
|
if (!handler)
|
|
149
151
|
throw new Error("Command handler not found");
|
|
150
152
|
return handler;
|
|
@@ -155,8 +157,8 @@ class AggregateES extends AggregateBase {
|
|
|
155
157
|
events.forEach((event) => {
|
|
156
158
|
var _a;
|
|
157
159
|
event.setContext({
|
|
158
|
-
correlationId: (_a = command.
|
|
159
|
-
causationId: command.
|
|
160
|
+
correlationId: (_a = command.getContext()) === null || _a === void 0 ? void 0 : _a.correlationId,
|
|
161
|
+
causationId: command.getId().value,
|
|
160
162
|
});
|
|
161
163
|
});
|
|
162
164
|
this.applyEvents(events);
|
|
@@ -168,8 +170,8 @@ class AggregateES extends AggregateBase {
|
|
|
168
170
|
throw new Error();
|
|
169
171
|
return {
|
|
170
172
|
metadata: {
|
|
171
|
-
id: this.
|
|
172
|
-
version: this.
|
|
173
|
+
id: this.getId(),
|
|
174
|
+
version: this.getVersion(),
|
|
173
175
|
},
|
|
174
176
|
props: this.props(),
|
|
175
177
|
};
|
package/dist/core/entity.d.ts
CHANGED
|
@@ -6,10 +6,10 @@ export interface EntityMetadata {
|
|
|
6
6
|
readonly id: Id;
|
|
7
7
|
}
|
|
8
8
|
export declare class Entity<Props extends object> extends Model<Props> {
|
|
9
|
-
|
|
9
|
+
protected readonly _id: Id;
|
|
10
10
|
constructor(metadata: EntityMetadata, props?: Props);
|
|
11
11
|
static newEntity<T extends AnyEntity>(this: EntityClassWithTypedConstructor<T>, props: PropsOf<T>): T;
|
|
12
|
-
|
|
12
|
+
getId(): Id;
|
|
13
13
|
hasId(id: Id): boolean;
|
|
14
14
|
}
|
|
15
15
|
export type AnyEntity = Entity<object>;
|
package/dist/core/entity.js
CHANGED
|
@@ -13,11 +13,11 @@ class Entity extends model_1.Model {
|
|
|
13
13
|
id: id_1.Uuid4.new(),
|
|
14
14
|
}, props);
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
getId() {
|
|
17
17
|
return this._id;
|
|
18
18
|
}
|
|
19
19
|
hasId(id) {
|
|
20
|
-
return this.
|
|
20
|
+
return this._id.equals(id);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
exports.Entity = Entity;
|
package/dist/core/error.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ModelError = void 0;
|
|
4
4
|
class ModelError extends Error {
|
|
5
5
|
constructor(model, message) {
|
|
6
|
-
super(`[${model.
|
|
6
|
+
super(`[${model.getType()}] ${message}`);
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
exports.ModelError = ModelError;
|
package/dist/core/event.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare class Event<Props extends object> extends Message<Props> {
|
|
|
16
16
|
private readonly _source;
|
|
17
17
|
constructor(metadata: EventMetadata, props: Props);
|
|
18
18
|
static newEvent<T extends AnyEvent>(this: EventClassWithTypedConstructor<T>, source: EventSource, props: PropsOf<T>, context?: MessageContext): T;
|
|
19
|
-
|
|
19
|
+
getSource(): Readonly<{
|
|
20
20
|
type: `${string}#${string}`;
|
|
21
21
|
id: Id;
|
|
22
22
|
version: number;
|
package/dist/core/event.js
CHANGED
package/dist/core/message.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export declare class Message<Props extends object> extends Model<Props> {
|
|
|
14
14
|
private readonly _timestamp;
|
|
15
15
|
private _context?;
|
|
16
16
|
protected constructor(metadata: MessageMetadata, props: Props);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
getId(): Id;
|
|
18
|
+
getTimestamp(): number;
|
|
19
|
+
getContext(): MessageContext | undefined;
|
|
20
20
|
setContext(context: Partial<MessageContext>): void;
|
|
21
21
|
}
|
package/dist/core/message.js
CHANGED
|
@@ -14,17 +14,17 @@ class Message extends model_1.Model {
|
|
|
14
14
|
this._timestamp = metadata.timestamp;
|
|
15
15
|
this._context = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.context) !== null && _a !== void 0 ? _a : {};
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
getId() {
|
|
18
18
|
return this._id;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
getTimestamp() {
|
|
21
21
|
return this._timestamp;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
getContext() {
|
|
24
24
|
return this._context;
|
|
25
25
|
}
|
|
26
26
|
setContext(context) {
|
|
27
|
-
this._context = lodash_1.default.merge(this.
|
|
27
|
+
this._context = lodash_1.default.merge(this._context, context);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
exports.Message = Message;
|
package/dist/core/model.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare class Model<Props extends object> {
|
|
|
6
6
|
static type(): `${string}#${string}`;
|
|
7
7
|
protected initializeProps(props: Props): void;
|
|
8
8
|
validate(): void;
|
|
9
|
-
|
|
9
|
+
getType(): `${string}#${string}`;
|
|
10
10
|
props(): Props;
|
|
11
11
|
}
|
|
12
12
|
export type AnyModel = Model<object>;
|
package/dist/core/model.js
CHANGED