ddd-node 25.0.0 → 27.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/base/decorators/index.d.ts +1 -0
- package/dist/base/decorators/index.js +1 -0
- package/dist/base/decorators/model.d.ts +2 -2
- package/dist/base/decorators/model.js +1 -1
- package/dist/base/decorators/prop.js +1 -1
- package/dist/base/decorators/props-validator.d.ts +2 -0
- package/dist/base/decorators/props-validator.js +8 -0
- package/dist/base/decorators/static.d.ts +2 -2
- package/dist/base/decorators/static.js +2 -2
- package/dist/base/meta/model-props-map.d.ts +4 -4
- package/dist/base/meta/model-props-map.js +24 -24
- package/dist/base/meta/model-props-validator.d.ts +5 -5
- package/dist/base/meta/model-props-validator.js +13 -13
- package/dist/base/meta/model-static-values.d.ts +8 -8
- package/dist/base/meta/model-static-values.js +21 -21
- package/dist/base/model/model-descriptor.d.ts +6 -6
- package/dist/base/model/model.d.ts +6 -6
- package/dist/base/model/model.js +18 -18
- package/dist/core/aggregate/aggregate-base/aggregate.builder.d.ts +2 -2
- package/dist/core/aggregate/aggregate-base/aggregate.builder.js +2 -2
- package/dist/core/aggregate/aggregate-base/aggregate.d.ts +3 -3
- package/dist/core/aggregate/aggregate-base/aggregate.js +2 -2
- package/dist/core/entity/entity.builder.d.ts +2 -2
- package/dist/core/entity/entity.builder.js +2 -2
- package/dist/core/entity/entity.d.ts +3 -3
- package/dist/core/entity/entity.js +2 -2
- package/dist/core/enum/enum-builder.js +1 -1
- package/dist/core/enum/enum.js +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/message/event/event.d.ts +1 -1
- package/dist/core/message/message-base/message.builder.d.ts +2 -2
- package/dist/core/message/message-base/message.builder.js +2 -2
- package/dist/core/message/message-base/message.d.ts +3 -3
- package/dist/core/message/message-base/message.js +2 -2
- package/dist/core/model-with-id/index.d.ts +3 -0
- package/dist/core/{identifiable-model → model-with-id}/index.js +2 -2
- package/dist/core/model-with-id/model-with-id.builder.d.ts +9 -0
- package/dist/core/{identifiable-model/identifiable-model.builder.js → model-with-id/model-with-id.builder.js} +3 -3
- package/dist/core/model-with-id/model-with-id.d.ts +13 -0
- package/dist/core/{identifiable-model/identifiable-model.js → model-with-id/model-with-id.js} +3 -3
- package/dist/core/repository/repository.d.ts +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
- package/dist/core/identifiable-model/identifiable-model.builder.d.ts +0 -9
- package/dist/core/identifiable-model/identifiable-model.d.ts +0 -13
- package/dist/core/identifiable-model/index.d.ts +0 -3
- /package/dist/core/{identifiable-model → model-with-id}/id.d.ts +0 -0
- /package/dist/core/{identifiable-model → model-with-id}/id.js +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AnyModel, ModelClass } from "../model";
|
|
2
|
-
import {
|
|
2
|
+
import { ModelPropsValidator } from "../meta";
|
|
3
3
|
export type ModelOptions<T extends AnyModel = AnyModel> = {
|
|
4
4
|
name?: string;
|
|
5
5
|
version?: number;
|
|
6
6
|
domain?: string;
|
|
7
|
-
propsValidator?:
|
|
7
|
+
propsValidator?: ModelPropsValidator<T>;
|
|
8
8
|
autoRegisterModel?: boolean;
|
|
9
9
|
};
|
|
10
10
|
export declare function Model<T extends ModelClass, I extends InstanceType<T> = InstanceType<T>>(options?: ModelOptions<I>): any;
|
|
@@ -48,7 +48,7 @@ function Model(p1, p2, p3) {
|
|
|
48
48
|
domain.modelRegistry.registerModel(target);
|
|
49
49
|
}
|
|
50
50
|
if (modelOptions?.propsValidator)
|
|
51
|
-
(0, meta_1.
|
|
51
|
+
(0, meta_1.defineModelPropsValidator)(target, modelOptions.propsValidator);
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
exports.Model = Model;
|
|
@@ -4,7 +4,7 @@ exports.Prop = void 0;
|
|
|
4
4
|
const meta_1 = require("../meta");
|
|
5
5
|
const Prop = (propTargetKey) => {
|
|
6
6
|
return (target, key) => {
|
|
7
|
-
(0, meta_1.
|
|
7
|
+
(0, meta_1.defineModelProp)(target, key, propTargetKey ?? key);
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
10
|
exports.Prop = Prop;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PropsValidator = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const PropsValidator = (target, key, propertyDescriptor) => {
|
|
6
|
+
(0, __1.defineModelPropsValidator)(target, propertyDescriptor.value);
|
|
7
|
+
};
|
|
8
|
+
exports.PropsValidator = PropsValidator;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ModelClass } from "../model";
|
|
2
|
-
import {
|
|
3
|
-
export declare const Static: <T extends ModelClass<import("../model").AnyModel>, I extends InstanceType<T> = InstanceType<T>>(builder:
|
|
2
|
+
import { ModelStaticValueBuilder } from "../meta";
|
|
3
|
+
export declare const Static: <T extends ModelClass<import("../model").AnyModel>, I extends InstanceType<T> = InstanceType<T>>(builder: ModelStaticValueBuilder<I>) => (target: T, key: PropertyKey) => void;
|
|
@@ -4,8 +4,8 @@ exports.Static = void 0;
|
|
|
4
4
|
const meta_1 = require("../meta");
|
|
5
5
|
const Static = (builder) => {
|
|
6
6
|
return (target, key) => {
|
|
7
|
-
(0, meta_1.
|
|
8
|
-
(0, meta_1.
|
|
7
|
+
(0, meta_1.setModelStaticValue)(target, key, builder);
|
|
8
|
+
(0, meta_1.defineModelStaticValueProperty)(target, key);
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
exports.Static = Static;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnyModel, PropsOf } from "../model";
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class ModelPropsMap<T extends AnyModel = AnyModel> extends Map<PropertyKey, keyof PropsOf<T>> {
|
|
3
3
|
}
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
4
|
+
export declare const getOwnModelPropsMap: <T extends AnyModel = AnyModel>(target: object) => ModelPropsMap<T>;
|
|
5
|
+
export declare const defineModelProp: <T extends AnyModel = AnyModel>(target: object, key: PropertyKey, propTargetKey?: keyof PropsOf<T> | undefined) => void;
|
|
6
|
+
export declare const getModelPropsMap: <T extends AnyModel = AnyModel>(target: object) => ModelPropsMap<T>;
|
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getModelPropsMap = exports.defineModelProp = exports.getOwnModelPropsMap = exports.ModelPropsMap = void 0;
|
|
4
4
|
const model_1 = require("../model");
|
|
5
|
-
const
|
|
6
|
-
class
|
|
5
|
+
const OwnModelPropsMapMetaKey = Symbol.for("OWN_MODEL_PROPS_MAP");
|
|
6
|
+
class ModelPropsMap extends Map {
|
|
7
7
|
}
|
|
8
|
-
exports.
|
|
8
|
+
exports.ModelPropsMap = ModelPropsMap;
|
|
9
9
|
// target is prototype
|
|
10
|
-
const
|
|
11
|
-
if (!Reflect.hasOwnMetadata(
|
|
12
|
-
Reflect.defineMetadata(
|
|
13
|
-
return Reflect.getOwnMetadata(
|
|
10
|
+
const getOwnModelPropsMap = (target) => {
|
|
11
|
+
if (!Reflect.hasOwnMetadata(OwnModelPropsMapMetaKey, target))
|
|
12
|
+
Reflect.defineMetadata(OwnModelPropsMapMetaKey, new ModelPropsMap(), target);
|
|
13
|
+
return Reflect.getOwnMetadata(OwnModelPropsMapMetaKey, target);
|
|
14
14
|
};
|
|
15
|
-
exports.
|
|
16
|
-
const
|
|
17
|
-
const
|
|
15
|
+
exports.getOwnModelPropsMap = getOwnModelPropsMap;
|
|
16
|
+
const defineModelProp = (target, key, propTargetKey) => {
|
|
17
|
+
const ownModelPropsMap = (0, exports.getOwnModelPropsMap)(target);
|
|
18
18
|
if (propTargetKey)
|
|
19
|
-
|
|
19
|
+
ownModelPropsMap.set(key, propTargetKey);
|
|
20
20
|
};
|
|
21
|
-
exports.
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
if (!Reflect.hasOwnMetadata(
|
|
21
|
+
exports.defineModelProp = defineModelProp;
|
|
22
|
+
const ModelPropsMapMetaKey = Symbol.for("MODEL_PROPS_MAP");
|
|
23
|
+
const getModelPropsMap = (target) => {
|
|
24
|
+
if (!Reflect.hasOwnMetadata(ModelPropsMapMetaKey, target)) {
|
|
25
25
|
const buildPropsMap = (target) => {
|
|
26
26
|
let _target = target;
|
|
27
|
-
const result = new
|
|
27
|
+
const result = new ModelPropsMap();
|
|
28
28
|
const ownPropsMapList = [];
|
|
29
29
|
do {
|
|
30
30
|
if (model_1.ModelBase.isModel(_target)) {
|
|
31
|
-
const
|
|
32
|
-
ownPropsMapList.unshift(
|
|
31
|
+
const ownModelPropsMap = (0, exports.getOwnModelPropsMap)(_target);
|
|
32
|
+
ownPropsMapList.unshift(ownModelPropsMap);
|
|
33
33
|
}
|
|
34
34
|
_target = Reflect.getPrototypeOf(_target);
|
|
35
35
|
} while (_target !== null);
|
|
36
|
-
ownPropsMapList.forEach((
|
|
37
|
-
|
|
36
|
+
ownPropsMapList.forEach((ownModelPropsMap) => {
|
|
37
|
+
ownModelPropsMap.forEach((targetPropKey, key) => result.set(key, targetPropKey));
|
|
38
38
|
});
|
|
39
39
|
return result;
|
|
40
40
|
};
|
|
41
|
-
Reflect.defineMetadata(
|
|
41
|
+
Reflect.defineMetadata(ModelPropsMapMetaKey, buildPropsMap(target), target);
|
|
42
42
|
}
|
|
43
|
-
return Reflect.getOwnMetadata(
|
|
43
|
+
return Reflect.getOwnMetadata(ModelPropsMapMetaKey, target);
|
|
44
44
|
};
|
|
45
|
-
exports.
|
|
45
|
+
exports.getModelPropsMap = getModelPropsMap;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnyModel, PropsOf } from "../model";
|
|
2
|
-
export type
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
2
|
+
export type ModelPropsValidator<T extends AnyModel = AnyModel> = (props: PropsOf<T>) => void;
|
|
3
|
+
export declare const defineModelPropsValidator: <T extends AnyModel>(target: object, validator: ModelPropsValidator<T>) => void;
|
|
4
|
+
export declare const getOwnModelPropsValidator: <T extends AnyModel>(target: object) => ModelPropsValidator<T> | undefined;
|
|
5
|
+
export declare const ModelPropsValidatorsMetaKey: unique symbol;
|
|
6
|
+
export declare const getModelPropsValidators: (target: object) => ModelPropsValidator[];
|
|
@@ -3,31 +3,31 @@ 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.getModelPropsValidators = exports.ModelPropsValidatorsMetaKey = exports.getOwnModelPropsValidator = exports.defineModelPropsValidator = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const OwnPropsValidatorMetaKey = Symbol.for("
|
|
9
|
-
const
|
|
8
|
+
const OwnPropsValidatorMetaKey = Symbol.for("OWN_MODEL_PROPS_VALIDATOR");
|
|
9
|
+
const defineModelPropsValidator = (target, validator) => {
|
|
10
10
|
Reflect.defineMetadata(OwnPropsValidatorMetaKey, validator, target);
|
|
11
11
|
};
|
|
12
|
-
exports.
|
|
13
|
-
const
|
|
12
|
+
exports.defineModelPropsValidator = defineModelPropsValidator;
|
|
13
|
+
const getOwnModelPropsValidator = (target) => {
|
|
14
14
|
return Reflect.getOwnMetadata(OwnPropsValidatorMetaKey, target);
|
|
15
15
|
};
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
18
|
-
const
|
|
19
|
-
if (!Reflect.hasOwnMetadata(exports.
|
|
16
|
+
exports.getOwnModelPropsValidator = getOwnModelPropsValidator;
|
|
17
|
+
exports.ModelPropsValidatorsMetaKey = Symbol.for("MODEL_PROPS_VALIDATORS");
|
|
18
|
+
const getModelPropsValidators = (target) => {
|
|
19
|
+
if (!Reflect.hasOwnMetadata(exports.ModelPropsValidatorsMetaKey, target)) {
|
|
20
20
|
let result = [];
|
|
21
21
|
let _target = target;
|
|
22
22
|
do {
|
|
23
|
-
const ownValidator = (0, exports.
|
|
23
|
+
const ownValidator = (0, exports.getOwnModelPropsValidator)(_target);
|
|
24
24
|
if (ownValidator)
|
|
25
25
|
result.push(ownValidator);
|
|
26
26
|
_target = Reflect.getPrototypeOf(_target);
|
|
27
27
|
} while (_target !== null);
|
|
28
28
|
result = lodash_1.default.uniq(result);
|
|
29
|
-
Reflect.defineMetadata(exports.
|
|
29
|
+
Reflect.defineMetadata(exports.ModelPropsValidatorsMetaKey, result, target);
|
|
30
30
|
}
|
|
31
|
-
return Reflect.getOwnMetadata(exports.
|
|
31
|
+
return Reflect.getOwnMetadata(exports.ModelPropsValidatorsMetaKey, target);
|
|
32
32
|
};
|
|
33
|
-
exports.
|
|
33
|
+
exports.getModelPropsValidators = getModelPropsValidators;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { AnyModel, ModelClass } from "../model";
|
|
2
|
-
export type
|
|
3
|
-
export declare class
|
|
2
|
+
export type ModelStaticValueBuilder<T extends AnyModel = AnyModel> = () => T;
|
|
3
|
+
export declare class ModelStaticValue<T extends AnyModel = AnyModel> {
|
|
4
4
|
private _value;
|
|
5
|
-
constructor(value: T |
|
|
5
|
+
constructor(value: T | ModelStaticValueBuilder<T>);
|
|
6
6
|
get value(): T;
|
|
7
7
|
}
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class ModelStaticValuesMap<T extends AnyModel = AnyModel> extends Map<PropertyKey, ModelStaticValue<T>> {
|
|
9
9
|
}
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
10
|
+
export declare const getOwnModelStaticValues: <T extends AnyModel>(target: object) => ModelStaticValuesMap<T>;
|
|
11
|
+
export declare const setModelStaticValue: <T extends AnyModel>(target: object, key: PropertyKey, value: T | ModelStaticValueBuilder<T>) => void;
|
|
12
|
+
export declare const getModelStaticValue: (target: object, key: PropertyKey) => AnyModel | undefined;
|
|
13
|
+
export declare const defineModelStaticValueProperty: (target: ModelClass, key: PropertyKey) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
3
|
+
exports.defineModelStaticValueProperty = exports.getModelStaticValue = exports.setModelStaticValue = exports.getOwnModelStaticValues = exports.ModelStaticValuesMap = exports.ModelStaticValue = void 0;
|
|
4
|
+
class ModelStaticValue {
|
|
5
5
|
constructor(value) {
|
|
6
6
|
this._value = value;
|
|
7
7
|
}
|
|
@@ -12,43 +12,43 @@ class StaticValue {
|
|
|
12
12
|
return this._value;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
exports.
|
|
16
|
-
const
|
|
17
|
-
class
|
|
15
|
+
exports.ModelStaticValue = ModelStaticValue;
|
|
16
|
+
const OwnModelStaticValuesMetaKey = Symbol.for("OWN_MODEL_STATIC_VALUES");
|
|
17
|
+
class ModelStaticValuesMap extends Map {
|
|
18
18
|
}
|
|
19
|
-
exports.
|
|
20
|
-
const
|
|
21
|
-
if (!Reflect.hasOwnMetadata(
|
|
22
|
-
Reflect.defineMetadata(
|
|
23
|
-
return Reflect.getOwnMetadata(
|
|
19
|
+
exports.ModelStaticValuesMap = ModelStaticValuesMap;
|
|
20
|
+
const getOwnModelStaticValues = (target) => {
|
|
21
|
+
if (!Reflect.hasOwnMetadata(OwnModelStaticValuesMetaKey, target))
|
|
22
|
+
Reflect.defineMetadata(OwnModelStaticValuesMetaKey, new ModelStaticValuesMap(), target);
|
|
23
|
+
return Reflect.getOwnMetadata(OwnModelStaticValuesMetaKey, target);
|
|
24
24
|
};
|
|
25
|
-
exports.
|
|
26
|
-
const
|
|
27
|
-
const staticValues = (0, exports.
|
|
28
|
-
staticValues.set(key, new
|
|
25
|
+
exports.getOwnModelStaticValues = getOwnModelStaticValues;
|
|
26
|
+
const setModelStaticValue = (target, key, value) => {
|
|
27
|
+
const staticValues = (0, exports.getOwnModelStaticValues)(target);
|
|
28
|
+
staticValues.set(key, new ModelStaticValue(value));
|
|
29
29
|
};
|
|
30
|
-
exports.
|
|
31
|
-
const
|
|
30
|
+
exports.setModelStaticValue = setModelStaticValue;
|
|
31
|
+
const getModelStaticValue = (target, key) => {
|
|
32
32
|
let _target = target;
|
|
33
33
|
do {
|
|
34
|
-
const staticValues = (0, exports.
|
|
34
|
+
const staticValues = (0, exports.getOwnModelStaticValues)(_target);
|
|
35
35
|
if (staticValues.has(key))
|
|
36
36
|
return staticValues.get(key)?.value;
|
|
37
37
|
_target = Reflect.getPrototypeOf(_target);
|
|
38
38
|
} while (_target !== null);
|
|
39
39
|
return undefined;
|
|
40
40
|
};
|
|
41
|
-
exports.
|
|
42
|
-
const
|
|
41
|
+
exports.getModelStaticValue = getModelStaticValue;
|
|
42
|
+
const defineModelStaticValueProperty = (target, key) => {
|
|
43
43
|
Object.defineProperty(target, key, {
|
|
44
44
|
configurable: false,
|
|
45
45
|
enumerable: true,
|
|
46
46
|
get() {
|
|
47
|
-
return (0, exports.
|
|
47
|
+
return (0, exports.getModelStaticValue)(target, key);
|
|
48
48
|
},
|
|
49
49
|
set() {
|
|
50
50
|
throw new Error("Static value is readonly");
|
|
51
51
|
},
|
|
52
52
|
});
|
|
53
53
|
};
|
|
54
|
-
exports.
|
|
54
|
+
exports.defineModelStaticValueProperty = defineModelStaticValueProperty;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { AnyModel } from "./model";
|
|
2
|
-
import { ModelId, ModelName, ModelVersion,
|
|
2
|
+
import { ModelId, ModelName, ModelVersion, ModelPropsMap, ModelPropsValidator, ModelStaticValuesMap } from "../meta";
|
|
3
3
|
export interface ModelDescriptor<T extends AnyModel = AnyModel> {
|
|
4
4
|
modelId: ModelId;
|
|
5
5
|
modelName: ModelName;
|
|
6
6
|
modelVersion: ModelVersion;
|
|
7
7
|
modelMutable: boolean;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
ownModelPropsValidator?: ModelPropsValidator<T>;
|
|
9
|
+
modelPropsValidators: ModelPropsValidator[];
|
|
10
|
+
ownModelStaticValues: ModelStaticValuesMap<T>;
|
|
11
|
+
ownModelPropsMap: ModelPropsMap<T>;
|
|
12
|
+
modelPropsMap: ModelPropsMap<T>;
|
|
13
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AbstractClass, Class } from "type-fest";
|
|
2
2
|
import { ClassStatic } from "../../types";
|
|
3
|
-
import { ModelId, ModelName,
|
|
3
|
+
import { ModelId, ModelName, ModelPropsMap, ModelPropsValidator, ModelStaticValuesMap, ModelVersion } from "../meta";
|
|
4
4
|
import { ModelDescriptor } from "./model-descriptor";
|
|
5
5
|
export interface Props {
|
|
6
6
|
[key: PropertyKey]: any;
|
|
@@ -16,11 +16,11 @@ export declare class ModelBase<P extends Props> {
|
|
|
16
16
|
static modelName<T extends AnyModel>(this: ModelClass<T>): ModelName;
|
|
17
17
|
static modelVersion<T extends AnyModel>(this: ModelClass<T>): ModelVersion;
|
|
18
18
|
static modelId<T extends AnyModel>(this: ModelClass<T>): ModelId;
|
|
19
|
-
static
|
|
20
|
-
static
|
|
21
|
-
static
|
|
22
|
-
static
|
|
23
|
-
static
|
|
19
|
+
static ownModelPropsValidator<T extends AnyModel>(this: ModelClass<T>): ModelPropsValidator<T> | undefined;
|
|
20
|
+
static modelPropsValidators<T extends AnyModel>(this: ModelClass<T>): ModelPropsValidator[];
|
|
21
|
+
static ownModelStaticValues<T extends AnyModel>(this: ModelClass<T>): ModelStaticValuesMap<T>;
|
|
22
|
+
static ownModelPropsMap<T extends AnyModel>(this: ModelClass<T>): ModelPropsMap<T>;
|
|
23
|
+
static modelPropsMap<T extends AnyModel>(this: ModelClass<T>): ModelPropsMap<T>;
|
|
24
24
|
constructor();
|
|
25
25
|
redefineModel(): void;
|
|
26
26
|
protected redefineProp<K extends keyof P>(key: keyof this, propTargetKey: K): void;
|
package/dist/base/model/model.js
CHANGED
|
@@ -23,27 +23,27 @@ class ModelBase {
|
|
|
23
23
|
static modelId() {
|
|
24
24
|
return (0, meta_1.getModelId)(this);
|
|
25
25
|
}
|
|
26
|
-
static
|
|
27
|
-
return (0, meta_1.
|
|
26
|
+
static ownModelPropsValidator() {
|
|
27
|
+
return (0, meta_1.getOwnModelPropsValidator)(this);
|
|
28
28
|
}
|
|
29
|
-
static
|
|
30
|
-
return (0, meta_1.
|
|
29
|
+
static modelPropsValidators() {
|
|
30
|
+
return (0, meta_1.getModelPropsValidators)(this);
|
|
31
31
|
}
|
|
32
|
-
static
|
|
33
|
-
return (0, meta_1.
|
|
32
|
+
static ownModelStaticValues() {
|
|
33
|
+
return (0, meta_1.getOwnModelStaticValues)(this);
|
|
34
34
|
}
|
|
35
|
-
static
|
|
36
|
-
return (0, meta_1.
|
|
35
|
+
static ownModelPropsMap() {
|
|
36
|
+
return (0, meta_1.getOwnModelPropsMap)(this.prototype);
|
|
37
37
|
}
|
|
38
|
-
static
|
|
39
|
-
return (0, meta_1.
|
|
38
|
+
static modelPropsMap() {
|
|
39
|
+
return (0, meta_1.getModelPropsMap)(this.prototype);
|
|
40
40
|
}
|
|
41
41
|
constructor() {
|
|
42
42
|
this._props = ModelBase.EMPTY_PROPS;
|
|
43
43
|
this.redefineModel();
|
|
44
44
|
}
|
|
45
45
|
redefineModel() {
|
|
46
|
-
this.modelDescriptor().
|
|
46
|
+
this.modelDescriptor().modelPropsMap.forEach((propTargetKey, key) => {
|
|
47
47
|
this.redefineProp(key, propTargetKey);
|
|
48
48
|
});
|
|
49
49
|
}
|
|
@@ -64,16 +64,16 @@ class ModelBase {
|
|
|
64
64
|
modelId: modelClass.modelId(),
|
|
65
65
|
modelName: modelClass.modelName(),
|
|
66
66
|
modelVersion: modelClass.modelVersion(),
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
ownModelPropsValidator: modelClass.ownModelPropsValidator(),
|
|
68
|
+
modelPropsValidators: modelClass.modelPropsValidators(),
|
|
69
|
+
ownModelStaticValues: modelClass.ownModelStaticValues(),
|
|
70
|
+
ownModelPropsMap: modelClass.ownModelPropsMap(),
|
|
71
|
+
modelPropsMap: modelClass.modelPropsMap(),
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
validateProps(props) {
|
|
75
|
-
const
|
|
76
|
-
|
|
75
|
+
const modelPropsValidators = this.modelDescriptor().modelPropsValidators;
|
|
76
|
+
modelPropsValidators.forEach((propsValidator) => propsValidator.call(this.constructor, props));
|
|
77
77
|
}
|
|
78
78
|
validate() {
|
|
79
79
|
this.validateProps(this._props);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModelWithIdBuilder } from "../../model-with-id";
|
|
2
2
|
import { AnyAggregate } from "./aggregate";
|
|
3
|
-
export declare abstract class AggregateBuilderBase<T extends AnyAggregate> extends
|
|
3
|
+
export declare abstract class AggregateBuilderBase<T extends AnyAggregate> extends ModelWithIdBuilder<T> {
|
|
4
4
|
protected version: number;
|
|
5
5
|
withVersion(version: number): this;
|
|
6
6
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AggregateBuilderBase = void 0;
|
|
4
|
-
const
|
|
5
|
-
class AggregateBuilderBase extends
|
|
4
|
+
const model_with_id_1 = require("../../model-with-id");
|
|
5
|
+
class AggregateBuilderBase extends model_with_id_1.ModelWithIdBuilder {
|
|
6
6
|
constructor() {
|
|
7
7
|
super(...arguments);
|
|
8
8
|
this.version = 0;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Props, PropsOf } from "../../../base";
|
|
2
|
-
import {
|
|
2
|
+
import { ModelWithId, ModelWithIdMetadata } from "../../model-with-id";
|
|
3
3
|
import { AnyEvent, EventClassWithTypedConstructor, EventSource } from "../../message";
|
|
4
4
|
import { IAggregateEventDispatcher } from "./aggregate-event-dispatcher.interface";
|
|
5
|
-
export interface AggregateMetadata extends
|
|
5
|
+
export interface AggregateMetadata extends ModelWithIdMetadata {
|
|
6
6
|
version: number;
|
|
7
7
|
}
|
|
8
|
-
export declare abstract class AggregateBase<P extends Props> extends
|
|
8
|
+
export declare abstract class AggregateBase<P extends Props> extends ModelWithId<P> {
|
|
9
9
|
protected readonly _version: number;
|
|
10
10
|
constructor(metadata: AggregateMetadata, props?: P);
|
|
11
11
|
abstract version(): number;
|
|
@@ -11,8 +11,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.AggregateBase = void 0;
|
|
13
13
|
const base_1 = require("../../../base");
|
|
14
|
-
const
|
|
15
|
-
let AggregateBase = class AggregateBase extends
|
|
14
|
+
const model_with_id_1 = require("../../model-with-id");
|
|
15
|
+
let AggregateBase = class AggregateBase extends model_with_id_1.ModelWithId {
|
|
16
16
|
constructor(metadata, props) {
|
|
17
17
|
super(metadata);
|
|
18
18
|
if (props)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModelWithIdBuilder } from "../model-with-id";
|
|
2
2
|
import { AnyEntity, EntityClassWithTypedConstructor } from "./entity";
|
|
3
|
-
export declare class EntityBuilder<T extends AnyEntity> extends
|
|
3
|
+
export declare class EntityBuilder<T extends AnyEntity> extends ModelWithIdBuilder<T> {
|
|
4
4
|
private entityClass;
|
|
5
5
|
constructor(entityClass: EntityClassWithTypedConstructor<T>);
|
|
6
6
|
build(): T;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EntityBuilder = void 0;
|
|
4
|
-
const
|
|
5
|
-
class EntityBuilder extends
|
|
4
|
+
const model_with_id_1 = require("../model-with-id");
|
|
5
|
+
class EntityBuilder extends model_with_id_1.ModelWithIdBuilder {
|
|
6
6
|
constructor(entityClass) {
|
|
7
7
|
super();
|
|
8
8
|
this.entityClass = entityClass;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Class } from "type-fest";
|
|
2
2
|
import { Props, PropsOf } from "../../base";
|
|
3
3
|
import { ClassStatic } from "../../types";
|
|
4
|
-
import {
|
|
4
|
+
import { ModelWithId, ModelWithIdMetadata } from "../model-with-id";
|
|
5
5
|
import { EntityBuilder } from ".";
|
|
6
|
-
export interface EntityMetadata extends
|
|
6
|
+
export interface EntityMetadata extends ModelWithIdMetadata {
|
|
7
7
|
}
|
|
8
|
-
export declare class EntityBase<P extends Props> extends
|
|
8
|
+
export declare class EntityBase<P extends Props> extends ModelWithId<P> {
|
|
9
9
|
static builder<T extends AnyEntity>(this: EntityClass<T>): EntityBuilder<T>;
|
|
10
10
|
constructor(metadata: EntityMetadata, props: P);
|
|
11
11
|
}
|
|
@@ -11,9 +11,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.EntityBase = void 0;
|
|
13
13
|
const base_1 = require("../../base");
|
|
14
|
-
const
|
|
14
|
+
const model_with_id_1 = require("../model-with-id");
|
|
15
15
|
const _1 = require(".");
|
|
16
|
-
let EntityBase = class EntityBase extends
|
|
16
|
+
let EntityBase = class EntityBase extends model_with_id_1.ModelWithId {
|
|
17
17
|
static builder() {
|
|
18
18
|
return new _1.EntityBuilder(this);
|
|
19
19
|
}
|
|
@@ -16,7 +16,7 @@ class EnumBuilder extends base_1.ModelBuilder {
|
|
|
16
16
|
throw new Error("Cannot parse enum without value");
|
|
17
17
|
const { enumClass } = this;
|
|
18
18
|
let result;
|
|
19
|
-
enumClass.
|
|
19
|
+
enumClass.ownModelStaticValues().forEach((staticValue) => {
|
|
20
20
|
if (staticValue.value instanceof enumClass) {
|
|
21
21
|
const staticEnum = staticValue.value;
|
|
22
22
|
if (staticEnum.value === this._value && !result) {
|
package/dist/core/enum/enum.js
CHANGED
|
@@ -17,7 +17,7 @@ let EnumBase = class EnumBase extends base_1.ModelBase {
|
|
|
17
17
|
return new _1.EnumBuilder(this);
|
|
18
18
|
}
|
|
19
19
|
static values() {
|
|
20
|
-
return Array.from(this.
|
|
20
|
+
return Array.from(this.ownModelStaticValues().values()).map((staticValue) => staticValue.value);
|
|
21
21
|
}
|
|
22
22
|
static from(value) {
|
|
23
23
|
return this.builder().withValue(value).build();
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
|
@@ -16,7 +16,7 @@ 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("./
|
|
19
|
+
__exportStar(require("./model-with-id"), exports);
|
|
20
20
|
__exportStar(require("./entity"), exports);
|
|
21
21
|
__exportStar(require("./aggregate"), exports);
|
|
22
22
|
__exportStar(require("./message"), exports);
|
|
@@ -2,7 +2,7 @@ import { Class } from "type-fest";
|
|
|
2
2
|
import { EventType } from "../../../meta";
|
|
3
3
|
import { Props, PropsOf } from "../../../base";
|
|
4
4
|
import { ClassStatic } from "../../../types";
|
|
5
|
-
import { Id } from "../../
|
|
5
|
+
import { Id } from "../../model-with-id";
|
|
6
6
|
import { MessageBase, MessageMetadata } from "../message-base";
|
|
7
7
|
import { EventModelDescriptor } from "./event-model-descriptor";
|
|
8
8
|
import { EventBuilder } from ".";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModelWithIdBuilder } from "../../model-with-id";
|
|
2
2
|
import { AnyMessage, CorrelationIds, MessageClassWithTypedConstructor } from "./message";
|
|
3
|
-
export declare abstract class MessageBuilderBase<T extends AnyMessage> extends
|
|
3
|
+
export declare abstract class MessageBuilderBase<T extends AnyMessage> extends ModelWithIdBuilder<T> {
|
|
4
4
|
protected timestamp: number;
|
|
5
5
|
protected causationId?: string;
|
|
6
6
|
protected correlationIds: CorrelationIds;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MessageBuilder = exports.MessageBuilderBase = void 0;
|
|
4
|
-
const
|
|
5
|
-
class MessageBuilderBase extends
|
|
4
|
+
const model_with_id_1 = require("../../model-with-id");
|
|
5
|
+
class MessageBuilderBase extends model_with_id_1.ModelWithIdBuilder {
|
|
6
6
|
constructor() {
|
|
7
7
|
super(...arguments);
|
|
8
8
|
this.timestamp = Date.now();
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Class } from "type-fest";
|
|
2
2
|
import { Props, PropsOf } from "../../../base";
|
|
3
3
|
import { ClassStatic } from "../../../types";
|
|
4
|
-
import {
|
|
4
|
+
import { ModelWithId, ModelWithIdMetadata } from "../../model-with-id";
|
|
5
5
|
export interface CorrelationIds {
|
|
6
6
|
[type: string]: string | undefined;
|
|
7
7
|
}
|
|
8
|
-
export interface MessageMetadata extends
|
|
8
|
+
export interface MessageMetadata extends ModelWithIdMetadata {
|
|
9
9
|
timestamp: number;
|
|
10
10
|
causationId?: string;
|
|
11
11
|
correlationIds: CorrelationIds;
|
|
12
12
|
}
|
|
13
|
-
export declare class MessageBase<P extends Props> extends
|
|
13
|
+
export declare class MessageBase<P extends Props> extends ModelWithId<P> {
|
|
14
14
|
private readonly _timestamp;
|
|
15
15
|
private _causationId?;
|
|
16
16
|
private _correlationIds;
|
|
@@ -11,8 +11,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MessageBase = void 0;
|
|
13
13
|
const base_1 = require("../../../base");
|
|
14
|
-
const
|
|
15
|
-
let MessageBase = class MessageBase extends
|
|
14
|
+
const model_with_id_1 = require("../../model-with-id");
|
|
15
|
+
let MessageBase = class MessageBase extends model_with_id_1.ModelWithId {
|
|
16
16
|
constructor(metadata, props) {
|
|
17
17
|
super(metadata);
|
|
18
18
|
this._timestamp = metadata.timestamp;
|
|
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./id"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./model-with-id"), exports);
|
|
19
|
+
__exportStar(require("./model-with-id.builder"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModelBuilder } from "../../base";
|
|
2
|
+
import { AnyModelWithId } from "./model-with-id";
|
|
3
|
+
import { Id } from "./id";
|
|
4
|
+
export declare abstract class ModelWithIdBuilder<T extends AnyModelWithId> extends ModelBuilder<T> {
|
|
5
|
+
protected id: Id;
|
|
6
|
+
newId(): string;
|
|
7
|
+
withId(id: Id): this;
|
|
8
|
+
withNewId(): this;
|
|
9
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ModelWithIdBuilder = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const base_1 = require("../../base");
|
|
6
|
-
class
|
|
6
|
+
class ModelWithIdBuilder extends base_1.ModelBuilder {
|
|
7
7
|
constructor() {
|
|
8
8
|
super(...arguments);
|
|
9
9
|
this.id = this.newId();
|
|
@@ -19,4 +19,4 @@ class IdentifiableModelBuilder extends base_1.ModelBuilder {
|
|
|
19
19
|
return this.withId(this.newId());
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
exports.
|
|
22
|
+
exports.ModelWithIdBuilder = ModelWithIdBuilder;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Id } from "./id";
|
|
2
|
+
import { ModelBase, Props } from "../../base";
|
|
3
|
+
export interface ModelWithIdMetadata {
|
|
4
|
+
id: Id;
|
|
5
|
+
}
|
|
6
|
+
export declare class ModelWithId<P extends Props> extends ModelBase<P> {
|
|
7
|
+
protected readonly _id: Id;
|
|
8
|
+
constructor(metadata: ModelWithIdMetadata);
|
|
9
|
+
metadata(): ModelWithIdMetadata;
|
|
10
|
+
id(): string;
|
|
11
|
+
hasId(id: Id): boolean;
|
|
12
|
+
}
|
|
13
|
+
export type AnyModelWithId = ModelWithId<Props>;
|
package/dist/core/{identifiable-model/identifiable-model.js → model-with-id/model-with-id.js}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ModelWithId = void 0;
|
|
4
4
|
const base_1 = require("../../base");
|
|
5
|
-
class
|
|
5
|
+
class ModelWithId extends base_1.ModelBase {
|
|
6
6
|
constructor(metadata) {
|
|
7
7
|
super();
|
|
8
8
|
this._id = metadata.id;
|
|
@@ -20,4 +20,4 @@ class IdentifiableModel extends base_1.ModelBase {
|
|
|
20
20
|
return this._id === id;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
exports.
|
|
23
|
+
exports.ModelWithId = ModelWithId;
|
package/dist/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"ddd-node","version":"
|
|
1
|
+
{"name":"ddd-node","version":"27.0.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
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ModelBuilder } from "../../base";
|
|
2
|
-
import { AnyIdentifiableModel } from "./identifiable-model";
|
|
3
|
-
import { Id } from "./id";
|
|
4
|
-
export declare abstract class IdentifiableModelBuilder<T extends AnyIdentifiableModel> extends ModelBuilder<T> {
|
|
5
|
-
protected id: Id;
|
|
6
|
-
newId(): string;
|
|
7
|
-
withId(id: Id): this;
|
|
8
|
-
withNewId(): this;
|
|
9
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Id } from "./id";
|
|
2
|
-
import { ModelBase, Props } from "../../base";
|
|
3
|
-
export interface IdentifiableModelMetadata {
|
|
4
|
-
id: Id;
|
|
5
|
-
}
|
|
6
|
-
export declare class IdentifiableModel<P extends Props> extends ModelBase<P> {
|
|
7
|
-
protected readonly _id: Id;
|
|
8
|
-
constructor(metadata: IdentifiableModelMetadata);
|
|
9
|
-
metadata(): IdentifiableModelMetadata;
|
|
10
|
-
id(): string;
|
|
11
|
-
hasId(id: Id): boolean;
|
|
12
|
-
}
|
|
13
|
-
export type AnyIdentifiableModel = IdentifiableModel<Props>;
|
|
File without changes
|
|
File without changes
|