ddd-node 23.0.1 → 24.1.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 -2
- package/dist/core/enum/enum-builder.d.ts +9 -0
- package/dist/core/enum/enum-builder.js +32 -0
- package/dist/core/enum/enum.d.ts +2 -4
- package/dist/core/enum/enum.js +3 -25
- package/dist/core/enum/index.d.ts +1 -0
- package/dist/core/enum/index.js +1 -0
- package/dist/core/identifiable-model/id.d.ts +1 -0
- package/dist/core/identifiable-model/id.js +2 -0
- package/dist/core/identifiable-model/identifiable-model.builder.d.ts +2 -2
- package/dist/core/identifiable-model/identifiable-model.builder.js +1 -2
- package/dist/core/identifiable-model/identifiable-model.d.ts +2 -2
- package/dist/core/identifiable-model/identifiable-model.js +1 -1
- package/dist/core/identifiable-model/index.d.ts +1 -0
- package/dist/core/identifiable-model/index.js +1 -0
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -1
- package/dist/core/message/event/event-model-descriptor.d.ts +2 -1
- package/dist/core/message/event/event.d.ts +2 -2
- package/dist/core/repository/repository.d.ts +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
- package/dist/core/id/id.d.ts +0 -8
- package/dist/core/id/id.js +0 -24
- package/dist/core/id/index.d.ts +0 -1
- package/dist/core/id/index.js +0 -17
|
@@ -58,7 +58,7 @@ class EventSourcedAggregateBase extends aggregate_base_1.AggregateBase {
|
|
|
58
58
|
}
|
|
59
59
|
validateEventBeforeApply(event) {
|
|
60
60
|
const { aggregateId, aggregateVersion } = event.source();
|
|
61
|
-
if (
|
|
61
|
+
if (aggregateId !== this._id)
|
|
62
62
|
throw new Error("Invalid aggregate id");
|
|
63
63
|
if (aggregateVersion !== this.version())
|
|
64
64
|
throw new Error("Invalid aggregate version");
|
|
@@ -105,7 +105,7 @@ class EventSourcedAggregateBase extends aggregate_base_1.AggregateBase {
|
|
|
105
105
|
events.forEach((event) => {
|
|
106
106
|
event.setContext({
|
|
107
107
|
correlationId: command.context()?.correlationId,
|
|
108
|
-
causationId: command.id()
|
|
108
|
+
causationId: command.id(),
|
|
109
109
|
});
|
|
110
110
|
});
|
|
111
111
|
this.applyEvents(events);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModelBuilder } from "../../model";
|
|
2
|
+
import { AnyEnum, EnumClass, EnumValue } from "./enum";
|
|
3
|
+
export declare class EnumBuilder<T extends AnyEnum> extends ModelBuilder<T> {
|
|
4
|
+
private enumClass;
|
|
5
|
+
protected _value?: EnumValue;
|
|
6
|
+
constructor(enumClass: EnumClass<T>);
|
|
7
|
+
withValue(value: EnumValue): this;
|
|
8
|
+
build(): T;
|
|
9
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnumBuilder = void 0;
|
|
4
|
+
const model_1 = require("../../model");
|
|
5
|
+
class EnumBuilder extends model_1.ModelBuilder {
|
|
6
|
+
constructor(enumClass) {
|
|
7
|
+
super();
|
|
8
|
+
this.enumClass = enumClass;
|
|
9
|
+
}
|
|
10
|
+
withValue(value) {
|
|
11
|
+
this._value = value;
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
build() {
|
|
15
|
+
if (!this._value)
|
|
16
|
+
throw new Error("Cannot parse enum without value");
|
|
17
|
+
const { enumClass } = this;
|
|
18
|
+
let result;
|
|
19
|
+
enumClass.ownStaticValues().forEach((staticValue) => {
|
|
20
|
+
if (staticValue.value instanceof enumClass) {
|
|
21
|
+
const staticEnum = staticValue.value;
|
|
22
|
+
if (staticEnum.value === this._value && !result) {
|
|
23
|
+
result = staticEnum;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
if (!result)
|
|
28
|
+
throw new Error(`Invalid provided value for enum ${enumClass.modelName()}`);
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.EnumBuilder = EnumBuilder;
|
package/dist/core/enum/enum.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { Class } from "type-fest";
|
|
2
|
-
import {
|
|
2
|
+
import { ModelBase } from "../../model";
|
|
3
3
|
import { ClassStatic } from "../../types";
|
|
4
4
|
export type EnumValue = string | number;
|
|
5
5
|
export interface EnumProps {
|
|
6
6
|
value: EnumValue;
|
|
7
7
|
}
|
|
8
|
-
export declare class EnumBase extends
|
|
8
|
+
export declare class EnumBase extends ModelBase<EnumProps> {
|
|
9
9
|
static values(): EnumBase[];
|
|
10
|
-
static parse<T extends AnyEnum>(this: EnumClass<T>, providedValue: EnumValue): T;
|
|
11
|
-
static parseSafe<T extends AnyEnum>(this: EnumClass<T>, providedValue: EnumValue): T | null;
|
|
12
10
|
constructor(value: EnumValue);
|
|
13
11
|
value: EnumValue;
|
|
14
12
|
}
|
package/dist/core/enum/enum.js
CHANGED
|
@@ -10,36 +10,14 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.EnumBase = void 0;
|
|
13
|
-
const __1 = require("..");
|
|
14
13
|
const model_1 = require("../../model");
|
|
15
|
-
let EnumBase = class EnumBase extends
|
|
14
|
+
let EnumBase = class EnumBase extends model_1.ModelBase {
|
|
16
15
|
static values() {
|
|
17
16
|
return Array.from(this.ownStaticValues().values()).map((staticValue) => staticValue.value);
|
|
18
17
|
}
|
|
19
|
-
static parse(providedValue) {
|
|
20
|
-
let result = undefined;
|
|
21
|
-
this.ownStaticValues().forEach((staticValue) => {
|
|
22
|
-
if (staticValue.value instanceof this) {
|
|
23
|
-
const staticEnum = staticValue.value;
|
|
24
|
-
if (staticEnum.value === providedValue && !result) {
|
|
25
|
-
result = staticEnum;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
if (!result)
|
|
30
|
-
throw new Error(`Invalid provided value for enum ${this.modelName()}`);
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
static parseSafe(providedValue) {
|
|
34
|
-
try {
|
|
35
|
-
return this.parse(providedValue);
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
18
|
constructor(value) {
|
|
42
|
-
super(
|
|
19
|
+
super();
|
|
20
|
+
this.initializeProps({ value });
|
|
43
21
|
}
|
|
44
22
|
};
|
|
45
23
|
exports.EnumBase = EnumBase;
|
package/dist/core/enum/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Id = string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ModelBuilder } from "../../model";
|
|
2
|
-
import { Id } from "../id";
|
|
3
2
|
import { AnyIdentifiableModel } from "./identifiable-model";
|
|
3
|
+
import { Id } from "./id";
|
|
4
4
|
export declare abstract class IdentifiableModelBuilder<T extends AnyIdentifiableModel> extends ModelBuilder<T> {
|
|
5
5
|
protected id: Id;
|
|
6
|
-
newId():
|
|
6
|
+
newId(): string;
|
|
7
7
|
withId(id: Id): this;
|
|
8
8
|
withNewId(): this;
|
|
9
9
|
}
|
|
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.IdentifiableModelBuilder = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const model_1 = require("../../model");
|
|
6
|
-
const id_1 = require("../id");
|
|
7
6
|
class IdentifiableModelBuilder extends model_1.ModelBuilder {
|
|
8
7
|
constructor() {
|
|
9
8
|
super(...arguments);
|
|
10
9
|
this.id = this.newId();
|
|
11
10
|
}
|
|
12
11
|
newId() {
|
|
13
|
-
return
|
|
12
|
+
return (0, uuid_1.v4)();
|
|
14
13
|
}
|
|
15
14
|
withId(id) {
|
|
16
15
|
this.id = id;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Id } from "./id";
|
|
1
2
|
import { ModelBase, Props } from "../../model";
|
|
2
|
-
import { Id } from "../id";
|
|
3
3
|
export interface IdentifiableModelMetadata {
|
|
4
4
|
id: Id;
|
|
5
5
|
}
|
|
@@ -7,7 +7,7 @@ export declare class IdentifiableModel<P extends Props> extends ModelBase<P> {
|
|
|
7
7
|
protected readonly _id: Id;
|
|
8
8
|
constructor(metadata: IdentifiableModelMetadata);
|
|
9
9
|
metadata(): IdentifiableModelMetadata;
|
|
10
|
-
id():
|
|
10
|
+
id(): string;
|
|
11
11
|
hasId(id: Id): boolean;
|
|
12
12
|
}
|
|
13
13
|
export type AnyIdentifiableModel = IdentifiableModel<Props>;
|
|
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./id"), exports);
|
|
17
18
|
__exportStar(require("./identifiable-model"), exports);
|
|
18
19
|
__exportStar(require("./identifiable-model.builder"), exports);
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
|
@@ -16,7 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./value-object"), exports);
|
|
18
18
|
__exportStar(require("./enum"), exports);
|
|
19
|
-
__exportStar(require("./id"), exports);
|
|
20
19
|
__exportStar(require("./identifiable-model"), exports);
|
|
21
20
|
__exportStar(require("./entity"), exports);
|
|
22
21
|
__exportStar(require("./aggregate"), exports);
|
|
@@ -2,7 +2,7 @@ import { Class } from "type-fest";
|
|
|
2
2
|
import { EventType } from "../../../meta";
|
|
3
3
|
import { Props, PropsOf } from "../../../model";
|
|
4
4
|
import { ClassStatic } from "../../../types";
|
|
5
|
-
import { Id } from "../../
|
|
5
|
+
import { Id } from "../../identifiable-model";
|
|
6
6
|
import { MessageBase, MessageMetadata } from "../message-base";
|
|
7
7
|
import { EventModelDescriptor } from "./event-model-descriptor";
|
|
8
8
|
export type EventSource = Readonly<{
|
|
@@ -22,7 +22,7 @@ export declare abstract class EventBase<P extends Props> extends MessageBase<P>
|
|
|
22
22
|
metadata(): EventMetadata;
|
|
23
23
|
eventType(): string;
|
|
24
24
|
source(): Readonly<{
|
|
25
|
-
aggregateId:
|
|
25
|
+
aggregateId: string;
|
|
26
26
|
aggregateVersion: number;
|
|
27
27
|
}>;
|
|
28
28
|
}
|
package/dist/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"ddd-node","version":"
|
|
1
|
+
{"name":"ddd-node","version":"24.1.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"}}
|
package/package.json
CHANGED
package/dist/core/id/id.d.ts
DELETED
package/dist/core/id/id.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Id = void 0;
|
|
13
|
-
const model_1 = require("../../model");
|
|
14
|
-
const value_object_1 = require("../value-object");
|
|
15
|
-
class Id extends value_object_1.ValueObjectBase {
|
|
16
|
-
constructor(idOrValue) {
|
|
17
|
-
super({ value: idOrValue instanceof Id ? idOrValue.value : idOrValue });
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.Id = Id;
|
|
21
|
-
__decorate([
|
|
22
|
-
(0, model_1.Prop)(),
|
|
23
|
-
__metadata("design:type", String)
|
|
24
|
-
], Id.prototype, "value", void 0);
|
package/dist/core/id/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./id";
|
package/dist/core/id/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./id"), exports);
|