ddd-node 9.2.1 → 12.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/.vscode/launch.json +17 -0
- package/dist/core/aggregate.d.ts +12 -11
- package/dist/core/aggregate.js +16 -16
- package/dist/core/entity.d.ts +8 -8
- package/dist/core/entity.js +9 -11
- package/dist/core/error.js +1 -1
- package/dist/core/id/built/snowflake.generator.d.ts +2 -2
- package/dist/core/id/built/snowflake.generator.js +1 -1
- package/dist/core/id/built/uuid4.generator.d.ts +2 -2
- package/dist/core/id/built/uuid4.generator.js +1 -1
- package/dist/core/id/id-generator.d.ts +1 -1
- package/dist/core/id/id-generator.js +3 -3
- package/dist/core/id/id.d.ts +1 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -1
- package/dist/core/message/command.d.ts +7 -6
- package/dist/core/message/command.js +3 -3
- package/dist/core/message/event.d.ts +11 -9
- package/dist/core/message/event.js +6 -3
- package/dist/core/message/message.d.ts +1 -3
- package/dist/core/message/message.js +5 -8
- package/dist/core/metadata/aggregate.metadata.d.ts +9 -0
- package/dist/core/metadata/aggregate.metadata.js +29 -0
- package/dist/core/metadata/id.metadata.d.ts +4 -0
- package/dist/core/metadata/id.metadata.js +12 -0
- package/dist/core/metadata/index.d.ts +3 -0
- package/dist/core/metadata/index.js +19 -0
- package/dist/core/metadata/model.metadata.d.ts +13 -0
- package/dist/core/metadata/model.metadata.js +55 -0
- package/dist/core/model/index.d.ts +0 -1
- package/dist/core/model/index.js +0 -1
- package/dist/core/model/model-with-id.d.ts +10 -4
- package/dist/core/model/model-with-id.js +16 -3
- package/dist/core/model/model.d.ts +21 -11
- package/dist/core/model/model.js +74 -19
- package/dist/core/value-object.d.ts +7 -6
- package/dist/core/value-object.js +5 -4
- package/dist/decorators/aggregate.d.ts +3 -4
- package/dist/decorators/aggregate.js +9 -15
- package/dist/decorators/id.d.ts +2 -2
- package/dist/decorators/id.js +3 -4
- package/dist/decorators/index.d.ts +0 -4
- package/dist/decorators/index.js +0 -4
- package/dist/decorators/model.d.ts +12 -2
- package/dist/decorators/model.js +37 -5
- package/dist/decorators/type.d.ts +2 -0
- package/dist/decorators/type.js +2 -0
- package/dist/types/class-static.d.ts +2 -2
- package/dist/types/class.d.ts +2 -4
- package/package.json +2 -1
- package/tsconfig.json +1 -1
- package/dist/core/metadata.d.ts +0 -17
- package/dist/core/metadata.js +0 -53
- package/dist/core/model/model-type.d.ts +0 -85
- package/dist/core/model/model-type.js +0 -55
- package/dist/core/registry.d.ts +0 -11
- package/dist/core/registry.js +0 -28
- package/dist/decorators/command.d.ts +0 -2
- package/dist/decorators/command.js +0 -10
- package/dist/decorators/entity.d.ts +0 -2
- package/dist/decorators/entity.js +0 -10
- package/dist/decorators/event.d.ts +0 -2
- package/dist/decorators/event.js +0 -10
- package/dist/decorators/value-object.d.ts +0 -2
- package/dist/decorators/value-object.js +0 -10
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import { Id,
|
|
2
|
-
import {
|
|
3
|
-
export declare class ModelWithId<Props extends object> extends
|
|
4
|
-
|
|
1
|
+
import { Id, IdGeneratorBase } from "../id";
|
|
2
|
+
import { ModelBase } from "./model";
|
|
3
|
+
export declare abstract class ModelWithId<Props extends object> extends ModelBase<Props> {
|
|
4
|
+
protected readonly _id: Id;
|
|
5
|
+
constructor(id: Id);
|
|
6
|
+
static getIdGenerator(this: any): IdGeneratorBase;
|
|
5
7
|
static id(id?: Id): Id;
|
|
8
|
+
getId(): Id;
|
|
9
|
+
hasId(id: Id): boolean;
|
|
10
|
+
rawId(): string;
|
|
6
11
|
}
|
|
12
|
+
export type AnyModelWithId = ModelWithId<any>;
|
|
@@ -2,15 +2,28 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ModelWithId = void 0;
|
|
4
4
|
const id_1 = require("../id");
|
|
5
|
-
const
|
|
5
|
+
const id_metadata_1 = require("../metadata/id.metadata");
|
|
6
6
|
const model_1 = require("./model");
|
|
7
|
-
class ModelWithId extends model_1.
|
|
7
|
+
class ModelWithId extends model_1.ModelBase {
|
|
8
|
+
constructor(id) {
|
|
9
|
+
super();
|
|
10
|
+
this._id = id;
|
|
11
|
+
}
|
|
8
12
|
static getIdGenerator() {
|
|
9
|
-
return (0,
|
|
13
|
+
return (0, id_metadata_1.getIdGenerator)(this) || new id_1.Uuid4Generator();
|
|
10
14
|
}
|
|
11
15
|
static id(id) {
|
|
12
16
|
const generator = this.getIdGenerator();
|
|
13
17
|
return id ? generator.fromId(id) : generator.newId();
|
|
14
18
|
}
|
|
19
|
+
getId() {
|
|
20
|
+
return this._id;
|
|
21
|
+
}
|
|
22
|
+
hasId(id) {
|
|
23
|
+
return this._id.equals(id);
|
|
24
|
+
}
|
|
25
|
+
rawId() {
|
|
26
|
+
return this._id.value;
|
|
27
|
+
}
|
|
15
28
|
}
|
|
16
29
|
exports.ModelWithId = ModelWithId;
|
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ClassStatic } from "../../types/index";
|
|
2
|
+
import { Class } from "type-fest";
|
|
3
|
+
import { ModelMetadata } from "../metadata/model.metadata";
|
|
4
|
+
export declare class ModelBase<Props extends object> {
|
|
5
|
+
static readonly EMPTY_PROPS: {};
|
|
6
|
+
private _metadata;
|
|
7
|
+
private _propKeys;
|
|
3
8
|
protected _props: Props;
|
|
4
|
-
|
|
5
|
-
static isModel(
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
static isMutable(): boolean;
|
|
10
|
+
static isModel(model: any): model is AnyModel;
|
|
11
|
+
constructor();
|
|
12
|
+
private redefineModel;
|
|
13
|
+
isMutable(): boolean;
|
|
14
|
+
getPropKeys(): Set<string | symbol>;
|
|
15
|
+
validateProps(props: Props): void;
|
|
8
16
|
validate(): void;
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
getModelMetadata(): ModelMetadata<this>;
|
|
18
|
+
modelName(): string;
|
|
19
|
+
props(): any;
|
|
20
|
+
protected initializeProps(props: Props): void;
|
|
11
21
|
}
|
|
12
|
-
export type AnyModel =
|
|
13
|
-
export type PropsOf<T> = T extends
|
|
14
|
-
export type ModelClass<T extends AnyModel = AnyModel> = Class<T
|
|
22
|
+
export type AnyModel = ModelBase<object>;
|
|
23
|
+
export type PropsOf<T extends AnyModel> = T extends ModelBase<infer P extends object> ? P : never;
|
|
24
|
+
export type ModelClass<T extends AnyModel = AnyModel> = Class<T> & ClassStatic<typeof ModelBase<PropsOf<T>>>;
|
|
15
25
|
export type EmptyProps = {};
|
package/dist/core/model/model.js
CHANGED
|
@@ -3,32 +3,87 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.ModelBase = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const
|
|
9
|
-
class
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.initializeProps(props);
|
|
8
|
+
const model_metadata_1 = require("../metadata/model.metadata");
|
|
9
|
+
class ModelBase {
|
|
10
|
+
static isMutable() {
|
|
11
|
+
return false;
|
|
13
12
|
}
|
|
14
|
-
static isModel(
|
|
15
|
-
return
|
|
13
|
+
static isModel(model) {
|
|
14
|
+
return model instanceof ModelBase;
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
constructor() {
|
|
17
|
+
this._props = ModelBase.EMPTY_PROPS;
|
|
18
|
+
this.redefineModel();
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this
|
|
23
|
-
|
|
20
|
+
redefineModel() {
|
|
21
|
+
this.getPropKeys().forEach((propKey) => {
|
|
22
|
+
Object.defineProperty(this, propKey, {
|
|
23
|
+
configurable: true,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get() {
|
|
26
|
+
var _a;
|
|
27
|
+
return (_a = this._props) === null || _a === void 0 ? void 0 : _a[propKey];
|
|
28
|
+
},
|
|
29
|
+
set() {
|
|
30
|
+
throw new Error(`Prop "${propKey.toString()}" cannot be set directly`);
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
isMutable() {
|
|
36
|
+
return this.constructor.isMutable();
|
|
37
|
+
}
|
|
38
|
+
getPropKeys() {
|
|
39
|
+
if (!this._propKeys) {
|
|
40
|
+
this._propKeys = (0, model_metadata_1.getPropKeySet)(Reflect.getPrototypeOf(this));
|
|
24
41
|
}
|
|
42
|
+
return this._propKeys;
|
|
25
43
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
44
|
+
validateProps(props) {
|
|
45
|
+
const { validator } = this.getModelMetadata();
|
|
46
|
+
if (validator)
|
|
47
|
+
validator(props);
|
|
48
|
+
}
|
|
49
|
+
validate() {
|
|
50
|
+
this.validateProps(this._props);
|
|
51
|
+
}
|
|
52
|
+
getModelMetadata() {
|
|
53
|
+
if (!this._metadata) {
|
|
54
|
+
this._metadata = (0, model_metadata_1.getModelMetadata)(this.constructor);
|
|
55
|
+
}
|
|
56
|
+
return this._metadata;
|
|
57
|
+
}
|
|
58
|
+
modelName() {
|
|
59
|
+
return this.getModelMetadata().name;
|
|
29
60
|
}
|
|
30
61
|
props() {
|
|
31
|
-
return lodash_1.default.
|
|
62
|
+
return lodash_1.default.cloneDeepWith(this._props, (value) => {
|
|
63
|
+
if (ModelBase.isModel(value)) {
|
|
64
|
+
value.redefineModel();
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
initializeProps(props) {
|
|
70
|
+
if (this._props !== ModelBase.EMPTY_PROPS)
|
|
71
|
+
throw new Error("Props is initialized");
|
|
72
|
+
if (!this.isMutable()) {
|
|
73
|
+
this._props = props;
|
|
74
|
+
Object.freeze(this._props);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this._props = new Proxy(props, {
|
|
78
|
+
set: (target, propKey, value) => {
|
|
79
|
+
let result = Reflect.set(target, propKey, value);
|
|
80
|
+
this.validate();
|
|
81
|
+
return result;
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
this.validate();
|
|
32
86
|
}
|
|
33
87
|
}
|
|
34
|
-
exports.
|
|
88
|
+
exports.ModelBase = ModelBase;
|
|
89
|
+
ModelBase.EMPTY_PROPS = {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Class } from "
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { Class } from "type-fest";
|
|
2
|
+
import { ModelBase, PropsOf } from "./model";
|
|
3
|
+
import { ClassStatic } from "../types/index";
|
|
4
|
+
export declare abstract class ValueObjectBase<Props extends object> extends ModelBase<Props> {
|
|
4
5
|
constructor(props: Props);
|
|
5
6
|
equals<V extends AnyValueObject>(vo: V): boolean;
|
|
6
7
|
with(props: Partial<Props>): this;
|
|
7
8
|
}
|
|
8
|
-
export type AnyValueObject =
|
|
9
|
-
export type ValueObjectClass<T extends AnyValueObject = AnyValueObject> = Class<T
|
|
10
|
-
export type ValueObjectClassWithTypedConstructor<T extends AnyValueObject = AnyValueObject> = Class<T, ConstructorParameters<typeof
|
|
9
|
+
export type AnyValueObject = ValueObjectBase<any>;
|
|
10
|
+
export type ValueObjectClass<T extends AnyValueObject = AnyValueObject> = Class<T> & ClassStatic<typeof ValueObjectBase<PropsOf<T>>>;
|
|
11
|
+
export type ValueObjectClassWithTypedConstructor<T extends AnyValueObject = AnyValueObject> = Class<T, ConstructorParameters<typeof ValueObjectBase<PropsOf<T>>>>;
|
|
@@ -3,12 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.ValueObjectBase = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const model_1 = require("./model");
|
|
9
|
-
class
|
|
9
|
+
class ValueObjectBase extends model_1.ModelBase {
|
|
10
10
|
constructor(props) {
|
|
11
|
-
super(
|
|
11
|
+
super();
|
|
12
|
+
this.initializeProps(props);
|
|
12
13
|
}
|
|
13
14
|
equals(vo) {
|
|
14
15
|
const equalsType = vo instanceof this.constructor;
|
|
@@ -20,4 +21,4 @@ class ValueObject extends model_1.Model {
|
|
|
20
21
|
return new this.constructor(newProps);
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
|
-
exports.
|
|
24
|
+
exports.ValueObjectBase = ValueObjectBase;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const handleCommand: <T extends AnyCommand>(commandClass: CommandClass<T>) => <U extends CommandHandler<T>>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<U>) => void;
|
|
1
|
+
import { AnyCommand, AnyEvent, CommandClass, CommandHandler, EventApplier, EventClass } from "../core/index";
|
|
2
|
+
export declare const ApplyEvent: <T extends AnyEvent>(eventClass: EventClass<T>) => <U extends EventApplier<T>>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<U>) => void;
|
|
3
|
+
export declare const HandleCommand: <T extends AnyCommand>(commandClass: CommandClass<T>) => <U extends CommandHandler<T>>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<U>) => void;
|
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.HandleCommand = exports.ApplyEvent = void 0;
|
|
4
4
|
const _core_1 = require("../core/index");
|
|
5
|
-
const
|
|
6
|
-
const aggregate = (name) => (target) => {
|
|
7
|
-
const aggregateType = new _core_1.AggregateType(name !== null && name !== void 0 ? name : target.name);
|
|
8
|
-
(0, model_1.model)(aggregateType.value)(target);
|
|
9
|
-
};
|
|
10
|
-
exports.aggregate = aggregate;
|
|
11
|
-
const applyEvent = (eventClass) => {
|
|
5
|
+
const ApplyEvent = (eventClass) => {
|
|
12
6
|
return (target, propertyKey, descriptor) => {
|
|
13
7
|
if (typeof descriptor.value === "function") {
|
|
14
|
-
const
|
|
15
|
-
(0, _core_1.defineEventApplier)(target,
|
|
8
|
+
const eventName = (0, _core_1.getModelName)(eventClass);
|
|
9
|
+
(0, _core_1.defineEventApplier)(target, eventName, descriptor.value);
|
|
16
10
|
}
|
|
17
11
|
};
|
|
18
12
|
};
|
|
19
|
-
exports.
|
|
20
|
-
const
|
|
13
|
+
exports.ApplyEvent = ApplyEvent;
|
|
14
|
+
const HandleCommand = (commandClass) => {
|
|
21
15
|
return (target, propertyKey, descriptor) => {
|
|
22
16
|
if (typeof descriptor.value === "function") {
|
|
23
|
-
const
|
|
24
|
-
(0, _core_1.defineCommandHandler)(target,
|
|
17
|
+
const commandName = (0, _core_1.getModelName)(commandClass);
|
|
18
|
+
(0, _core_1.defineCommandHandler)(target, commandName, descriptor.value);
|
|
25
19
|
}
|
|
26
20
|
};
|
|
27
21
|
};
|
|
28
|
-
exports.
|
|
22
|
+
exports.HandleCommand = HandleCommand;
|
package/dist/decorators/id.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
1
|
+
import { AnyModelWithId, IdGeneratorBase, ModelClass } from "../core/index";
|
|
2
|
+
export declare const UseId: (idGenerator: IdGeneratorBase) => <T extends AnyModelWithId>(target: ModelClass<T>) => void;
|
package/dist/decorators/id.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.UseId = void 0;
|
|
4
4
|
const _core_1 = require("../core/index");
|
|
5
|
-
const
|
|
5
|
+
const UseId = (idGenerator) => {
|
|
6
6
|
return (target) => {
|
|
7
|
-
console.log("Target", target);
|
|
8
7
|
(0, _core_1.defineIdGenerator)(target, idGenerator);
|
|
9
8
|
};
|
|
10
9
|
};
|
|
11
|
-
exports.
|
|
10
|
+
exports.UseId = UseId;
|
package/dist/decorators/index.js
CHANGED
|
@@ -15,9 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./aggregate"), exports);
|
|
18
|
-
__exportStar(require("./command"), exports);
|
|
19
|
-
__exportStar(require("./entity"), exports);
|
|
20
|
-
__exportStar(require("./event"), exports);
|
|
21
18
|
__exportStar(require("./id"), exports);
|
|
22
19
|
__exportStar(require("./model"), exports);
|
|
23
|
-
__exportStar(require("./value-object"), exports);
|
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
import { ModelClass,
|
|
2
|
-
|
|
1
|
+
import { AnyModel, ModelClass, PropsValidator } from "../core/index";
|
|
2
|
+
import { TypedClassDecorator } from "./type";
|
|
3
|
+
export declare const Prop: (target: object, propKey: string) => void;
|
|
4
|
+
export declare const Name: (name?: string) => <T extends AnyModel>(target: ModelClass<T>) => void;
|
|
5
|
+
export declare const Validate: <T extends AnyModel>(validator?: PropsValidator<T> | undefined) => (target: ModelClass<T>) => void;
|
|
6
|
+
export type ModelOptions<T extends AnyModel> = {
|
|
7
|
+
name?: string;
|
|
8
|
+
validator?: PropsValidator<T>;
|
|
9
|
+
};
|
|
10
|
+
export declare function Model<T extends ModelClass, I extends InstanceType<T> = InstanceType<T>>(options?: ModelOptions<I>): TypedClassDecorator<T>;
|
|
11
|
+
export declare function Model<T extends ModelClass, I extends InstanceType<T> = InstanceType<T>>(name?: string, validator?: PropsValidator<I>): TypedClassDecorator<T>;
|
|
12
|
+
export declare function Model<T extends ModelClass, I extends InstanceType<T> = InstanceType<T>>(name?: string, options?: Omit<ModelOptions<I>, "name">): TypedClassDecorator<T>;
|
package/dist/decorators/model.js
CHANGED
|
@@ -1,11 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Model = exports.Validate = exports.Name = exports.Prop = void 0;
|
|
4
4
|
const _core_1 = require("../core/index");
|
|
5
|
-
const
|
|
5
|
+
const Prop = (target, propKey) => {
|
|
6
|
+
(0, _core_1.setPropKey)(target, propKey);
|
|
7
|
+
};
|
|
8
|
+
exports.Prop = Prop;
|
|
9
|
+
const Name = (name) => {
|
|
10
|
+
return (target) => {
|
|
11
|
+
(0, _core_1.setModelName)(target, name !== null && name !== void 0 ? name : target.name);
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
exports.Name = Name;
|
|
15
|
+
const Validate = (validator) => {
|
|
6
16
|
return (target) => {
|
|
7
|
-
|
|
8
|
-
|
|
17
|
+
if (validator)
|
|
18
|
+
(0, _core_1.setValidateProps)(target, validator);
|
|
9
19
|
};
|
|
10
20
|
};
|
|
11
|
-
exports.
|
|
21
|
+
exports.Validate = Validate;
|
|
22
|
+
function Model(p1, p2) {
|
|
23
|
+
return (target) => {
|
|
24
|
+
let options = {};
|
|
25
|
+
if (p1 && !p2) {
|
|
26
|
+
if (typeof p1 === "string")
|
|
27
|
+
options = { name: p1 };
|
|
28
|
+
else
|
|
29
|
+
options = p1;
|
|
30
|
+
}
|
|
31
|
+
else if (p1 && p2) {
|
|
32
|
+
p1 = p1;
|
|
33
|
+
if (typeof p2 === "function")
|
|
34
|
+
options = { name: p1, validator: p2 };
|
|
35
|
+
else
|
|
36
|
+
options = Object.assign({ name: p1 }, p2);
|
|
37
|
+
}
|
|
38
|
+
const { name, validator } = options;
|
|
39
|
+
(0, exports.Name)(name)(target);
|
|
40
|
+
(0, exports.Validate)(validator)(target);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.Model = Model;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type ClassStatic<T extends
|
|
1
|
+
import { AnyClass } from "./class";
|
|
2
|
+
export type ClassStatic<T extends AnyClass<any>> = Omit<T, "constructor" | "prototype">;
|
package/dist/types/class.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export type
|
|
3
|
-
prototype: T;
|
|
4
|
-
};
|
|
1
|
+
import { AbstractClass, Class } from "type-fest";
|
|
2
|
+
export type AnyClass<T = any> = Class<T> | AbstractClass<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ddd-node",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.1.0",
|
|
4
4
|
"description": "Domain Driven Design base for NodeJs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"nodejs-snowflake": "^2.0.1",
|
|
33
33
|
"reflect-metadata": "^0.1.13",
|
|
34
34
|
"tsc-alias": "^1.8.8",
|
|
35
|
+
"type-fest": "^4.15.0",
|
|
35
36
|
"uuid": "^9.0.1"
|
|
36
37
|
}
|
|
37
38
|
}
|
package/tsconfig.json
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"baseUrl": "./" /* Specify the base directory to resolve non-relative module names. */,
|
|
32
32
|
"paths": {
|
|
33
33
|
"#core": ["src/core/index"],
|
|
34
|
-
"#decorators": ["src/
|
|
34
|
+
"#decorators": ["src/decorators/index"],
|
|
35
35
|
"#utils": ["src/utils/index"],
|
|
36
36
|
"#types": ["src/types/index"]
|
|
37
37
|
} /* Specify a set of entries that re-map imports to additional lookup locations. */,
|
package/dist/core/metadata.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { CommandHandler, EventApplier } from "./aggregate";
|
|
3
|
-
import { IdGenerator } from "./id";
|
|
4
|
-
import { ModelTypePattern } from "./model";
|
|
5
|
-
import { AnyCommand, AnyEvent } from "./message";
|
|
6
|
-
export declare const MODEL_TYPE = "MODEL_TYPE";
|
|
7
|
-
export declare const defineModelType: (target: object, type: ModelTypePattern) => void;
|
|
8
|
-
export declare const getModelType: (target: object) => ModelTypePattern;
|
|
9
|
-
export declare const ID_GENERATOR = "ID_GENERATOR";
|
|
10
|
-
export declare const defineIdGenerator: (target: object, idGenerator: IdGenerator) => void;
|
|
11
|
-
export declare const getIdGenerator: (target: object) => any;
|
|
12
|
-
export declare const EVENT_APPLIERS = "EVENT_APPLIERS";
|
|
13
|
-
export declare const getEventAppliersMap: (target: object) => Map<string, EventApplier>;
|
|
14
|
-
export declare const defineEventApplier: <T extends AnyEvent>(target: object, eventType: string, applier: EventApplier<T>) => void;
|
|
15
|
-
export declare const COMMAND_HANDLERS = "COMMAND_HANDLERS";
|
|
16
|
-
export declare const getCommandHandlersMap: (target: object) => Map<string, CommandHandler>;
|
|
17
|
-
export declare const defineCommandHandler: <T extends AnyCommand>(target: object, commandType: string, handler: CommandHandler<T>) => void;
|
package/dist/core/metadata.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
-
require("reflect-metadata");
|
|
5
|
-
// Model type
|
|
6
|
-
exports.MODEL_TYPE = "MODEL_TYPE";
|
|
7
|
-
const defineModelType = (target, type) => {
|
|
8
|
-
Reflect.defineMetadata(exports.MODEL_TYPE, type, target);
|
|
9
|
-
};
|
|
10
|
-
exports.defineModelType = defineModelType;
|
|
11
|
-
const getModelType = (target) => {
|
|
12
|
-
const type = Reflect.getMetadata(exports.MODEL_TYPE, target);
|
|
13
|
-
if (!type)
|
|
14
|
-
throw new Error("The type has not been defined");
|
|
15
|
-
return type;
|
|
16
|
-
};
|
|
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;
|
|
28
|
-
// Event applier map
|
|
29
|
-
exports.EVENT_APPLIERS = "EVENT_APPLIERS";
|
|
30
|
-
const getEventAppliersMap = (target) => {
|
|
31
|
-
return (Reflect.getMetadata(exports.EVENT_APPLIERS, target) ||
|
|
32
|
-
new Map());
|
|
33
|
-
};
|
|
34
|
-
exports.getEventAppliersMap = getEventAppliersMap;
|
|
35
|
-
const defineEventApplier = (target, eventType, applier) => {
|
|
36
|
-
const eventAppliersMap = (0, exports.getEventAppliersMap)(target);
|
|
37
|
-
eventAppliersMap.set(eventType, applier);
|
|
38
|
-
Reflect.defineMetadata(exports.EVENT_APPLIERS, eventAppliersMap, target);
|
|
39
|
-
};
|
|
40
|
-
exports.defineEventApplier = defineEventApplier;
|
|
41
|
-
// Command handler map
|
|
42
|
-
exports.COMMAND_HANDLERS = "COMMAND_HANDLERS";
|
|
43
|
-
const getCommandHandlersMap = (target) => {
|
|
44
|
-
return (Reflect.getMetadata(exports.COMMAND_HANDLERS, target) ||
|
|
45
|
-
new Map());
|
|
46
|
-
};
|
|
47
|
-
exports.getCommandHandlersMap = getCommandHandlersMap;
|
|
48
|
-
const defineCommandHandler = (target, commandType, handler) => {
|
|
49
|
-
const commandHandlersMap = (0, exports.getCommandHandlersMap)(target);
|
|
50
|
-
commandHandlersMap.set(commandType, handler);
|
|
51
|
-
Reflect.defineMetadata(exports.COMMAND_HANDLERS, commandHandlersMap, target);
|
|
52
|
-
};
|
|
53
|
-
exports.defineCommandHandler = defineCommandHandler;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Class, ClassStatic } from "../../types/index";
|
|
2
|
-
export declare const seperator: "#";
|
|
3
|
-
export type ModelTypePattern<Prefix extends string = string> = `${Prefix}${typeof seperator}${string}`;
|
|
4
|
-
export declare const ModelTypePatternRegex: RegExp;
|
|
5
|
-
export declare class ModelType<Prefix extends string = string> {
|
|
6
|
-
readonly prefix: Prefix;
|
|
7
|
-
readonly name: string;
|
|
8
|
-
constructor(prefix: Prefix, name: string);
|
|
9
|
-
static from<Prefix extends string = string>(value: ModelTypePattern<Prefix>): ModelType<Prefix>;
|
|
10
|
-
static isPattern(type: string): type is ModelTypePattern;
|
|
11
|
-
get value(): ModelTypePattern<Prefix>;
|
|
12
|
-
}
|
|
13
|
-
export type PrefixOf<T extends ModelType> = T extends ModelType<infer Prefix> ? Prefix : never;
|
|
14
|
-
export type ModelTypeClass<T extends ModelType> = Class<T> & ClassStatic<typeof ModelType<PrefixOf<T>>>;
|
|
15
|
-
export type ModelTypePatternOf<T extends ModelType> = ModelTypePattern<PrefixOf<T>>;
|
|
16
|
-
export declare const createPrefixedModelTypeClass: <Prefix extends string = string>(prefix: Prefix) => {
|
|
17
|
-
new (name: string): {
|
|
18
|
-
readonly prefix: Prefix;
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly value: `${Prefix}#${string}`;
|
|
21
|
-
};
|
|
22
|
-
from<Prefix_1 extends string = string>(value: `${Prefix_1}#${string}`): ModelType<Prefix_1>;
|
|
23
|
-
isPattern(type: string): type is `${string}#${string}`;
|
|
24
|
-
};
|
|
25
|
-
export declare const EntityTypePrefix: "Entity";
|
|
26
|
-
declare const EntityType_base: {
|
|
27
|
-
new (name: string): {
|
|
28
|
-
readonly prefix: "Entity";
|
|
29
|
-
readonly name: string;
|
|
30
|
-
readonly value: `Entity#${string}`;
|
|
31
|
-
};
|
|
32
|
-
from<Prefix extends string = string>(value: `${Prefix}#${string}`): ModelType<Prefix>;
|
|
33
|
-
isPattern(type: string): type is `${string}#${string}`;
|
|
34
|
-
};
|
|
35
|
-
export declare class EntityType extends EntityType_base {
|
|
36
|
-
}
|
|
37
|
-
export declare const AggregateTypePrefix: "Aggregate";
|
|
38
|
-
declare const AggregateType_base: {
|
|
39
|
-
new (name: string): {
|
|
40
|
-
readonly prefix: "Aggregate";
|
|
41
|
-
readonly name: string;
|
|
42
|
-
readonly value: `Aggregate#${string}`;
|
|
43
|
-
};
|
|
44
|
-
from<Prefix extends string = string>(value: `${Prefix}#${string}`): ModelType<Prefix>;
|
|
45
|
-
isPattern(type: string): type is `${string}#${string}`;
|
|
46
|
-
};
|
|
47
|
-
export declare class AggregateType extends AggregateType_base {
|
|
48
|
-
}
|
|
49
|
-
export declare const EventTypePrefix: "Event";
|
|
50
|
-
declare const EventType_base: {
|
|
51
|
-
new (name: string): {
|
|
52
|
-
readonly prefix: "Event";
|
|
53
|
-
readonly name: string;
|
|
54
|
-
readonly value: `Event#${string}`;
|
|
55
|
-
};
|
|
56
|
-
from<Prefix extends string = string>(value: `${Prefix}#${string}`): ModelType<Prefix>;
|
|
57
|
-
isPattern(type: string): type is `${string}#${string}`;
|
|
58
|
-
};
|
|
59
|
-
export declare class EventType extends EventType_base {
|
|
60
|
-
}
|
|
61
|
-
export declare const CommandTypePrefix: "Command";
|
|
62
|
-
declare const CommandType_base: {
|
|
63
|
-
new (name: string): {
|
|
64
|
-
readonly prefix: "Command";
|
|
65
|
-
readonly name: string;
|
|
66
|
-
readonly value: `Command#${string}`;
|
|
67
|
-
};
|
|
68
|
-
from<Prefix extends string = string>(value: `${Prefix}#${string}`): ModelType<Prefix>;
|
|
69
|
-
isPattern(type: string): type is `${string}#${string}`;
|
|
70
|
-
};
|
|
71
|
-
export declare class CommandType extends CommandType_base {
|
|
72
|
-
}
|
|
73
|
-
export declare const ValueObjectTypePrefix: "ValueObject";
|
|
74
|
-
declare const ValueObjectType_base: {
|
|
75
|
-
new (name: string): {
|
|
76
|
-
readonly prefix: "ValueObject";
|
|
77
|
-
readonly name: string;
|
|
78
|
-
readonly value: `ValueObject#${string}`;
|
|
79
|
-
};
|
|
80
|
-
from<Prefix extends string = string>(value: `${Prefix}#${string}`): ModelType<Prefix>;
|
|
81
|
-
isPattern(type: string): type is `${string}#${string}`;
|
|
82
|
-
};
|
|
83
|
-
export declare class ValueObjectType extends ValueObjectType_base {
|
|
84
|
-
}
|
|
85
|
-
export {};
|