ddd-node 9.0.0 → 9.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.js +2 -3
- package/dist/core/command.js +1 -2
- package/dist/core/entity.d.ts +4 -3
- package/dist/core/entity.js +4 -5
- package/dist/core/event.js +1 -2
- package/dist/core/id.d.ts +10 -5
- package/dist/core/id.js +17 -12
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/message.d.ts +2 -2
- package/dist/core/message.js +2 -2
- package/dist/core/metadata.d.ts +4 -0
- package/dist/core/metadata.js +11 -1
- package/dist/core/model-with-id.d.ts +6 -0
- package/dist/core/model-with-id.js +16 -0
- package/dist/decorators/id.d.ts +2 -0
- package/dist/decorators/id.js +11 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/package.json +1 -1
package/dist/core/aggregate.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AggregateES = exports.Aggregate = exports.AggregateBase = void 0;
|
|
4
4
|
const to_array_1 = require("../utils/to-array");
|
|
5
5
|
const entity_1 = require("./entity");
|
|
6
|
-
const id_1 = require("./id");
|
|
7
6
|
const metadata_1 = require("./metadata");
|
|
8
7
|
class AggregateBase extends entity_1.Entity {
|
|
9
8
|
constructor(metadata, props) {
|
|
@@ -27,7 +26,7 @@ class Aggregate extends AggregateBase {
|
|
|
27
26
|
}
|
|
28
27
|
static newAggregate(props, id) {
|
|
29
28
|
return new this({
|
|
30
|
-
id: id
|
|
29
|
+
id: this.id(id),
|
|
31
30
|
version: 0,
|
|
32
31
|
}, props);
|
|
33
32
|
}
|
|
@@ -61,7 +60,7 @@ class AggregateES extends AggregateBase {
|
|
|
61
60
|
}
|
|
62
61
|
static newStream(id) {
|
|
63
62
|
return new this({
|
|
64
|
-
id: id
|
|
63
|
+
id: this.id(id),
|
|
65
64
|
version: 0,
|
|
66
65
|
});
|
|
67
66
|
}
|
package/dist/core/command.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Command = void 0;
|
|
4
|
-
const id_1 = require("./id");
|
|
5
4
|
const message_1 = require("./message");
|
|
6
5
|
class Command extends message_1.Message {
|
|
7
6
|
constructor(metadata, props) {
|
|
@@ -9,7 +8,7 @@ class Command extends message_1.Message {
|
|
|
9
8
|
}
|
|
10
9
|
static newCommand(props, context) {
|
|
11
10
|
return new this({
|
|
12
|
-
id:
|
|
11
|
+
id: this.id(),
|
|
13
12
|
timestamp: Date.now(),
|
|
14
13
|
context,
|
|
15
14
|
}, props);
|
package/dist/core/entity.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Class } from "../types/class";
|
|
2
2
|
import { ClassStatic } from "../types/class-static";
|
|
3
3
|
import { Id } from "./id";
|
|
4
|
-
import {
|
|
4
|
+
import { PropsOf } from "./model";
|
|
5
|
+
import { ModelWithId } from "./model-with-id";
|
|
5
6
|
export interface EntityMetadata {
|
|
6
7
|
readonly id: Id;
|
|
7
8
|
}
|
|
8
|
-
export declare class Entity<Props extends object> extends
|
|
9
|
+
export declare class Entity<Props extends object> extends ModelWithId<Props> {
|
|
9
10
|
protected readonly _id: Id;
|
|
10
11
|
constructor(metadata: EntityMetadata, props?: Props);
|
|
11
|
-
static newEntity<T extends AnyEntity>(this: EntityClassWithTypedConstructor<T>, props: PropsOf<T
|
|
12
|
+
static newEntity<T extends AnyEntity>(this: EntityClassWithTypedConstructor<T>, props: PropsOf<T>, id?: Id): T;
|
|
12
13
|
getId(): Id;
|
|
13
14
|
hasId(id: Id): boolean;
|
|
14
15
|
}
|
package/dist/core/entity.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Entity = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
class Entity extends model_1.Model {
|
|
4
|
+
const model_with_id_1 = require("./model-with-id");
|
|
5
|
+
class Entity extends model_with_id_1.ModelWithId {
|
|
7
6
|
constructor(metadata, props) {
|
|
8
7
|
super(props);
|
|
9
8
|
this._id = metadata.id;
|
|
10
9
|
}
|
|
11
|
-
static newEntity(props) {
|
|
10
|
+
static newEntity(props, id) {
|
|
12
11
|
return new this({
|
|
13
|
-
id:
|
|
12
|
+
id: this.id(id),
|
|
14
13
|
}, props);
|
|
15
14
|
}
|
|
16
15
|
getId() {
|
package/dist/core/event.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Event = void 0;
|
|
4
|
-
const id_1 = require("./id");
|
|
5
4
|
const message_1 = require("./message");
|
|
6
5
|
class Event extends message_1.Message {
|
|
7
6
|
constructor(metadata, props) {
|
|
@@ -10,7 +9,7 @@ class Event extends message_1.Message {
|
|
|
10
9
|
}
|
|
11
10
|
static newEvent(source, props, context) {
|
|
12
11
|
return new this({
|
|
13
|
-
id:
|
|
12
|
+
id: this.id(),
|
|
14
13
|
timestamp: Date.now(),
|
|
15
14
|
source,
|
|
16
15
|
context,
|
package/dist/core/id.d.ts
CHANGED
|
@@ -4,9 +4,14 @@ export declare class Id {
|
|
|
4
4
|
get value(): string;
|
|
5
5
|
equals(id: Id): boolean;
|
|
6
6
|
}
|
|
7
|
-
export declare class
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export declare abstract class IdGenerator {
|
|
8
|
+
abstract generateValue(): string;
|
|
9
|
+
abstract validateValue(value: string): void;
|
|
10
|
+
fromValue(value: string): Id;
|
|
11
|
+
fromId(id: Id): Id;
|
|
12
|
+
newId(): Id;
|
|
13
|
+
}
|
|
14
|
+
export declare class Uuid4Generator extends IdGenerator {
|
|
15
|
+
generateValue(): string;
|
|
16
|
+
validateValue(value: string): boolean;
|
|
12
17
|
}
|
package/dist/core/id.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Uuid4Generator = exports.IdGenerator = exports.Id = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
class Id {
|
|
6
6
|
constructor(value) {
|
|
@@ -14,22 +14,27 @@ class Id {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
exports.Id = Id;
|
|
17
|
-
class
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
class IdGenerator {
|
|
18
|
+
fromValue(value) {
|
|
19
|
+
this.validateValue(value);
|
|
20
|
+
return new Id(value);
|
|
21
|
+
}
|
|
22
|
+
fromId(id) {
|
|
23
|
+
return this.fromValue(id.value);
|
|
20
24
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return this.from(newValue);
|
|
25
|
+
newId() {
|
|
26
|
+
return this.fromValue(this.generateValue());
|
|
24
27
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
}
|
|
29
|
+
exports.IdGenerator = IdGenerator;
|
|
30
|
+
class Uuid4Generator extends IdGenerator {
|
|
31
|
+
generateValue() {
|
|
32
|
+
return (0, uuid_1.v4)();
|
|
28
33
|
}
|
|
29
|
-
|
|
34
|
+
validateValue(value) {
|
|
30
35
|
const isUuid = (0, uuid_1.validate)(value);
|
|
31
36
|
const isV4 = (0, uuid_1.version)(value) === 4;
|
|
32
37
|
return isUuid && isV4;
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
|
-
exports.
|
|
40
|
+
exports.Uuid4Generator = Uuid4Generator;
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __exportStar(require("./message"), exports);
|
|
|
24
24
|
__exportStar(require("./metadata"), exports);
|
|
25
25
|
__exportStar(require("./model"), exports);
|
|
26
26
|
__exportStar(require("./model-type"), exports);
|
|
27
|
+
__exportStar(require("./model-with-id"), exports);
|
|
27
28
|
__exportStar(require("./registry"), exports);
|
|
28
29
|
__exportStar(require("./repository"), exports);
|
|
29
30
|
__exportStar(require("./value-object"), exports);
|
package/dist/core/message.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Id } from "./id";
|
|
2
|
-
import {
|
|
2
|
+
import { ModelWithId } from "./model-with-id";
|
|
3
3
|
export interface MessageContext {
|
|
4
4
|
correlationId?: string;
|
|
5
5
|
causationId?: string;
|
|
@@ -9,7 +9,7 @@ export interface MessageMetadata {
|
|
|
9
9
|
readonly timestamp: number;
|
|
10
10
|
context?: MessageContext;
|
|
11
11
|
}
|
|
12
|
-
export declare class Message<Props extends object> extends
|
|
12
|
+
export declare class Message<Props extends object> extends ModelWithId<Props> {
|
|
13
13
|
private readonly _id;
|
|
14
14
|
private readonly _timestamp;
|
|
15
15
|
private _context?;
|
package/dist/core/message.js
CHANGED
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Message = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const
|
|
9
|
-
class Message extends
|
|
8
|
+
const model_with_id_1 = require("./model-with-id");
|
|
9
|
+
class Message extends model_with_id_1.ModelWithId {
|
|
10
10
|
constructor(metadata, props) {
|
|
11
11
|
var _a;
|
|
12
12
|
super(props);
|
package/dist/core/metadata.d.ts
CHANGED
|
@@ -3,9 +3,13 @@ import { CommandHandler, EventApplier } from "./aggregate";
|
|
|
3
3
|
import { AnyCommand } from "./command";
|
|
4
4
|
import { AnyEvent } from "./event";
|
|
5
5
|
import { ModelTypePattern } from "./model-type";
|
|
6
|
+
import { IdGenerator } from "./id";
|
|
6
7
|
export declare const MODEL_TYPE = "MODEL_TYPE";
|
|
7
8
|
export declare const defineModelType: (target: object, type: ModelTypePattern) => void;
|
|
8
9
|
export declare const getModelType: (target: object) => ModelTypePattern;
|
|
10
|
+
export declare const ID_GENERATOR = "ID_GENERATOR";
|
|
11
|
+
export declare const defineIdGenerator: (target: object, idGenerator: IdGenerator) => void;
|
|
12
|
+
export declare const getIdGenerator: (target: object) => any;
|
|
9
13
|
export declare const EVENT_APPLIERS = "EVENT_APPLIERS";
|
|
10
14
|
export declare const getEventAppliersMap: (target: object) => Map<string, EventApplier>;
|
|
11
15
|
export declare const defineEventApplier: <T extends AnyEvent>(target: object, eventType: string, applier: EventApplier<T>) => void;
|
package/dist/core/metadata.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineCommandHandler = exports.getCommandHandlersMap = exports.COMMAND_HANDLERS = exports.defineEventApplier = exports.getEventAppliersMap = exports.EVENT_APPLIERS = exports.getModelType = exports.defineModelType = exports.MODEL_TYPE = void 0;
|
|
3
|
+
exports.defineCommandHandler = exports.getCommandHandlersMap = exports.COMMAND_HANDLERS = exports.defineEventApplier = exports.getEventAppliersMap = exports.EVENT_APPLIERS = exports.getIdGenerator = exports.defineIdGenerator = exports.ID_GENERATOR = exports.getModelType = exports.defineModelType = exports.MODEL_TYPE = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
// Model type
|
|
6
6
|
exports.MODEL_TYPE = "MODEL_TYPE";
|
|
@@ -15,6 +15,16 @@ const getModelType = (target) => {
|
|
|
15
15
|
return type;
|
|
16
16
|
};
|
|
17
17
|
exports.getModelType = getModelType;
|
|
18
|
+
// Id generator
|
|
19
|
+
exports.ID_GENERATOR = "ID_GENERATOR";
|
|
20
|
+
const defineIdGenerator = (target, idGenerator) => {
|
|
21
|
+
Reflect.defineMetadata(exports.ID_GENERATOR, idGenerator, target);
|
|
22
|
+
};
|
|
23
|
+
exports.defineIdGenerator = defineIdGenerator;
|
|
24
|
+
const getIdGenerator = (target) => {
|
|
25
|
+
return Reflect.getMetadata(exports.ID_GENERATOR, target);
|
|
26
|
+
};
|
|
27
|
+
exports.getIdGenerator = getIdGenerator;
|
|
18
28
|
// Event applier map
|
|
19
29
|
exports.EVENT_APPLIERS = "EVENT_APPLIERS";
|
|
20
30
|
const getEventAppliersMap = (target) => {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelWithId = void 0;
|
|
4
|
+
const id_1 = require("./id");
|
|
5
|
+
const metadata_1 = require("./metadata");
|
|
6
|
+
const model_1 = require("./model");
|
|
7
|
+
class ModelWithId extends model_1.Model {
|
|
8
|
+
static getIdGenerator() {
|
|
9
|
+
return (0, metadata_1.getIdGenerator)(this) || new id_1.Uuid4Generator();
|
|
10
|
+
}
|
|
11
|
+
static id(id) {
|
|
12
|
+
const generator = this.getIdGenerator();
|
|
13
|
+
return id ? generator.fromId(id) : generator.newId();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ModelWithId = ModelWithId;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.id = void 0;
|
|
4
|
+
const metadata_1 = require("../core/metadata");
|
|
5
|
+
const id = (idGenerator) => {
|
|
6
|
+
return (target) => {
|
|
7
|
+
console.log("Target", target);
|
|
8
|
+
(0, metadata_1.defineIdGenerator)(target, idGenerator);
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
exports.id = id;
|
package/dist/decorators/index.js
CHANGED
|
@@ -18,5 +18,6 @@ __exportStar(require("./aggregate"), exports);
|
|
|
18
18
|
__exportStar(require("./command"), exports);
|
|
19
19
|
__exportStar(require("./entity"), exports);
|
|
20
20
|
__exportStar(require("./event"), exports);
|
|
21
|
+
__exportStar(require("./id"), exports);
|
|
21
22
|
__exportStar(require("./model"), exports);
|
|
22
23
|
__exportStar(require("./value-object"), exports);
|