ddd-node 16.4.0 → 17.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/base.js +3 -3
- package/dist/core/aggregate/event-sourced-aggregate.js +3 -3
- package/dist/core/domain.d.ts +3 -5
- package/dist/core/enum.js +1 -1
- package/dist/core/message/command.d.ts +1 -1
- package/dist/core/message/event.d.ts +7 -7
- package/dist/core/model/model.d.ts +4 -2
- package/dist/core/model/model.js +6 -0
- package/dist/decorators/message/command.d.ts +2 -1
- package/dist/decorators/message/event.d.ts +2 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/meta/command.metadata.d.ts +1 -1
- package/dist/meta/event.metadata.d.ts +1 -1
- package/dist/meta/model.metadata.d.ts +23 -7
- package/dist/meta/model.metadata.js +42 -3
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -9,9 +9,9 @@ class AggregateBase extends entity_1.EntityBase {
|
|
|
9
9
|
}
|
|
10
10
|
newEvent(eventClass, props) {
|
|
11
11
|
const eventSource = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
aggregateModel: this.modelName(),
|
|
13
|
+
aggregateId: this.id(),
|
|
14
|
+
aggregateVersion: this.version(),
|
|
15
15
|
};
|
|
16
16
|
return eventClass.newEvent(eventSource, props);
|
|
17
17
|
}
|
|
@@ -61,11 +61,11 @@ class EventSourcedAggregateBase extends base_1.AggregateBase {
|
|
|
61
61
|
}
|
|
62
62
|
validateEventBeforeApply(event) {
|
|
63
63
|
const eventSource = event.source();
|
|
64
|
-
if (eventSource.
|
|
64
|
+
if (eventSource.aggregateModel !== this.modelName())
|
|
65
65
|
throw new Error("Invalid source type");
|
|
66
|
-
if (!eventSource.
|
|
66
|
+
if (!eventSource.aggregateId.equals(this._id))
|
|
67
67
|
throw new Error("Invalid source id");
|
|
68
|
-
if (eventSource.
|
|
68
|
+
if (eventSource.aggregateVersion !== this.version())
|
|
69
69
|
throw new Error("Invalid source version");
|
|
70
70
|
}
|
|
71
71
|
_applyEvent(event) {
|
package/dist/core/domain.d.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
+
import { ModelName, ModelVersion } from "../meta";
|
|
1
2
|
import { AnyModel, ModelClass } from "./model";
|
|
2
|
-
type ModelName = string;
|
|
3
|
-
type ModelVersion = number;
|
|
4
3
|
export declare class ModelVersionRegistry<T extends AnyModel = AnyModel> extends Map<ModelVersion, ModelClass<T>> {
|
|
5
4
|
}
|
|
6
5
|
export declare class ModelRegistry<T extends AnyModel = AnyModel> extends Map<ModelName, ModelVersionRegistry<T>> {
|
|
7
6
|
}
|
|
8
7
|
export type DomainName = string;
|
|
9
8
|
export declare class Domain {
|
|
10
|
-
readonly name
|
|
9
|
+
readonly name: DomainName;
|
|
11
10
|
private readonly modelRegistry;
|
|
12
|
-
constructor(name
|
|
11
|
+
constructor(name: DomainName);
|
|
13
12
|
getModelVersionRegistry(modelName: ModelName): ModelVersionRegistry<AnyModel>;
|
|
14
13
|
getModel(modelName: ModelName, modelVersion?: ModelVersion): ModelClass<AnyModel> | undefined;
|
|
15
14
|
hasRegisteredModel(modelName: ModelName, modelVersion: ModelVersion): boolean;
|
|
16
15
|
hasRegisteredModel(model: ModelClass): boolean;
|
|
17
16
|
registerModel(modelClass: ModelClass): this;
|
|
18
17
|
}
|
|
19
|
-
export {};
|
package/dist/core/enum.js
CHANGED
|
@@ -7,7 +7,7 @@ class EnumBase extends model_1.ModelBase {
|
|
|
7
7
|
return Array.from(this.ownStaticValues().values()).map((staticValue) => staticValue.value);
|
|
8
8
|
}
|
|
9
9
|
static parseSafe(providedValue) {
|
|
10
|
-
let key;
|
|
10
|
+
let key = undefined;
|
|
11
11
|
this.ownStaticValues().forEach((staticValue, staticValueKey) => {
|
|
12
12
|
if (staticValue.value instanceof this) {
|
|
13
13
|
const staticEnum = staticValue.value;
|
|
@@ -2,7 +2,7 @@ import { ClassStatic } from "../../types";
|
|
|
2
2
|
import { Class } from "type-fest";
|
|
3
3
|
import { Props, PropsOf } from "../model";
|
|
4
4
|
import { MessageBase, MessageContext, MessageMetadata } from "./message";
|
|
5
|
-
|
|
5
|
+
import { CommandType } from "../../meta";
|
|
6
6
|
export interface CommandMetadata extends Omit<MessageMetadata, "messageType"> {
|
|
7
7
|
}
|
|
8
8
|
export declare class CommandBase<P extends Props> extends MessageBase<P> {
|
|
@@ -3,11 +3,11 @@ import { Class } from "type-fest";
|
|
|
3
3
|
import { Id } from "../id";
|
|
4
4
|
import { Props, PropsOf } from "../model";
|
|
5
5
|
import { MessageBase, MessageContext, MessageMetadata } from "./message";
|
|
6
|
-
|
|
6
|
+
import { EventType } from "../../meta";
|
|
7
7
|
export type EventSource = Readonly<{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
aggregateModel: string;
|
|
9
|
+
aggregateId: Id;
|
|
10
|
+
aggregateVersion: number;
|
|
11
11
|
}>;
|
|
12
12
|
export interface EventMetadata extends Omit<MessageMetadata, "messageType"> {
|
|
13
13
|
source: EventSource;
|
|
@@ -19,9 +19,9 @@ export declare class EventBase<P extends Props> extends MessageBase<P> {
|
|
|
19
19
|
static eventType(): EventType;
|
|
20
20
|
static newEvent<T extends AnyEvent>(this: EventClassWithTypedConstructor<T>, source: EventSource, props: PropsOf<T>, context?: MessageContext, timestamp?: number): T;
|
|
21
21
|
source(): Readonly<{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
aggregateModel: string;
|
|
23
|
+
aggregateId: Id;
|
|
24
|
+
aggregateVersion: number;
|
|
25
25
|
}>;
|
|
26
26
|
eventType(): string;
|
|
27
27
|
}
|
|
@@ -14,18 +14,20 @@ export declare class ModelBase<P extends Props> {
|
|
|
14
14
|
static mutable(): boolean;
|
|
15
15
|
static modelName<T extends AnyModel>(this: ModelClass<T>): string;
|
|
16
16
|
static modelVersion<T extends AnyModel>(this: ModelClass<T>): number;
|
|
17
|
+
static modelId<T extends AnyModel>(this: ModelClass<T>): import("../../meta").ModelId;
|
|
17
18
|
static ownPropsValidator<T extends AnyModel>(this: ModelClass<T>): import("../../meta").PropsValidator<T> | undefined;
|
|
18
19
|
static propsValidators<T extends AnyModel>(this: ModelClass<T>): import("../../meta").PropsValidator<AnyModel>[];
|
|
19
|
-
static ownStaticValues<T extends AnyModel>(this: ModelClass<T>): Map<
|
|
20
|
+
static ownStaticValues<T extends AnyModel>(this: ModelClass<T>): Map<PropertyKey, import("../../meta").StaticValue<T>>;
|
|
20
21
|
static ownPropsMap(): import("../../meta").PropsMap<ModelBase<any>>;
|
|
21
22
|
static propsMap(): import("../../meta").PropsMap<ModelBase<any>>;
|
|
22
23
|
constructor();
|
|
23
24
|
protected redefineModel(): void;
|
|
24
25
|
protected redefineProp(key: keyof this, propTargetKey: keyof P): void;
|
|
25
|
-
protected get _modelClass(): ModelClass<this>;
|
|
26
|
+
protected get _modelClass(): ModelClass<typeof this>;
|
|
26
27
|
isMutable(): boolean;
|
|
27
28
|
modelName(): string;
|
|
28
29
|
modelVersion(): number;
|
|
30
|
+
modelId(): import("../../meta").ModelId;
|
|
29
31
|
ownPropsValidator(): import("../../meta").PropsValidator<this> | undefined;
|
|
30
32
|
propsValidators(): import("../../meta").PropsValidator<AnyModel>[];
|
|
31
33
|
ownPropsMap(): import("../../meta").PropsMap<ModelBase<any>>;
|
package/dist/core/model/model.js
CHANGED
|
@@ -20,6 +20,9 @@ class ModelBase {
|
|
|
20
20
|
static modelVersion() {
|
|
21
21
|
return (0, meta_1.getModelVersion)(this);
|
|
22
22
|
}
|
|
23
|
+
static modelId() {
|
|
24
|
+
return (0, meta_1.getModelId)(this);
|
|
25
|
+
}
|
|
23
26
|
static ownPropsValidator() {
|
|
24
27
|
return (0, meta_1.getOwnPropsValidator)(this);
|
|
25
28
|
}
|
|
@@ -66,6 +69,9 @@ class ModelBase {
|
|
|
66
69
|
modelVersion() {
|
|
67
70
|
return this._modelClass.modelVersion();
|
|
68
71
|
}
|
|
72
|
+
modelId() {
|
|
73
|
+
return this._modelClass.modelId();
|
|
74
|
+
}
|
|
69
75
|
ownPropsValidator() {
|
|
70
76
|
return this._modelClass.ownPropsValidator();
|
|
71
77
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { AnyCommand, CommandClass
|
|
1
|
+
import { AnyCommand, CommandClass } from "../../core";
|
|
2
|
+
import { CommandType } from "../../meta";
|
|
2
3
|
export declare const Command: (commandType: CommandType) => <T extends AnyCommand>(target: CommandClass<T, any[]>) => void;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./meta"), exports);
|
|
18
|
-
__exportStar(require("./core"), exports);
|
|
19
|
-
__exportStar(require("./decorators"), exports);
|
|
20
18
|
__exportStar(require("./types"), exports);
|
|
21
19
|
__exportStar(require("./utils"), exports);
|
|
20
|
+
__exportStar(require("./core"), exports);
|
|
21
|
+
__exportStar(require("./decorators"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
|
|
2
|
+
export type CommandType = string;
|
|
3
3
|
export declare const setCommandType: (target: object, commandType: CommandType) => void;
|
|
4
4
|
export declare const getCommandType: (target: object) => CommandType | undefined;
|
|
@@ -5,15 +5,31 @@ export declare class PropsMap<T extends AnyModel = AnyModel> extends Map<PropKey
|
|
|
5
5
|
export declare const getOwnPropsMap: <T extends AnyModel = AnyModel>(target: T) => PropsMap<T>;
|
|
6
6
|
export declare const setProp: <T extends AnyModel = AnyModel>(target: T, key: PropKey, propTargetKey?: keyof PropsOf<T> | undefined) => void;
|
|
7
7
|
export declare const getPropsMap: <T extends AnyModel = AnyModel>(target: T) => PropsMap<T>;
|
|
8
|
-
export
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export
|
|
8
|
+
export type ModelName = string;
|
|
9
|
+
export declare const setModelName: <T extends AnyModel>(target: ModelClass<T>, name: ModelName) => void;
|
|
10
|
+
export declare const getModelName: <T extends AnyModel>(target: ModelClass<T>) => ModelName;
|
|
11
|
+
export type ModelVersion = number;
|
|
12
|
+
export declare const setModelVersion: <T extends AnyModel>(target: ModelClass<T>, version: ModelVersion) => void;
|
|
13
|
+
export declare const getModelVersion: <T extends AnyModel>(target: ModelClass<T>) => ModelVersion;
|
|
14
|
+
export type ModelIdValue = `${ModelName}${typeof ModelId.ValueDivider}${ModelVersion}`;
|
|
15
|
+
export declare class ModelId {
|
|
16
|
+
readonly modelName: ModelName;
|
|
17
|
+
readonly modelVersion: ModelVersion;
|
|
18
|
+
static readonly ValueDivider: "|";
|
|
19
|
+
static fromValue(value: ModelIdValue): ModelId;
|
|
20
|
+
static makeValue(modelId: ModelId): ModelIdValue;
|
|
21
|
+
constructor(modelName: ModelName, modelVersion: ModelVersion);
|
|
22
|
+
get value(): ModelIdValue;
|
|
23
|
+
equalsValue(modelIdValue: ModelIdValue): boolean;
|
|
24
|
+
equals(modelId: ModelId): boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare const setModelId: <T extends AnyModel>(target: ModelClass<T>, modelId: ModelId) => void;
|
|
27
|
+
export declare const getModelId: <T extends AnyModel>(target: ModelClass<T>) => ModelId;
|
|
12
28
|
export type PropsValidator<T extends AnyModel = AnyModel> = (props: PropsOf<T>) => void;
|
|
13
29
|
export declare const setPropsValidator: <T extends AnyModel>(target: object, validator: PropsValidator<T>) => void;
|
|
14
30
|
export declare const getOwnPropsValidator: <T extends AnyModel>(target: object) => PropsValidator<T> | undefined;
|
|
15
31
|
export declare const PropsValidatorsMetaKey: unique symbol;
|
|
16
|
-
export declare const getPropsValidators: (target: object) => PropsValidator
|
|
17
|
-
export declare const getOwnStaticValues: <T extends AnyModel>(target: object) => Map<
|
|
18
|
-
export declare const setStaticValue: <T extends AnyModel>(target: object, key:
|
|
32
|
+
export declare const getPropsValidators: (target: object) => PropsValidator[];
|
|
33
|
+
export declare const getOwnStaticValues: <T extends AnyModel>(target: object) => Map<PropertyKey, StaticValue<T>>;
|
|
34
|
+
export declare const setStaticValue: <T extends AnyModel>(target: object, key: PropertyKey, value: T | StaticValueBuilder<T>) => void;
|
|
19
35
|
export declare const getStaticValue: (target: object, key: string | symbol) => AnyModel | undefined;
|
|
@@ -3,10 +3,11 @@ 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.getStaticValue = exports.setStaticValue = exports.getOwnStaticValues = exports.getPropsValidators = exports.PropsValidatorsMetaKey = exports.getOwnPropsValidator = exports.setPropsValidator = exports.getModelVersion = exports.setModelVersion = exports.getModelName = exports.setModelName = exports.getPropsMap = exports.setProp = exports.getOwnPropsMap = exports.PropsMap = void 0;
|
|
6
|
+
exports.getStaticValue = exports.setStaticValue = exports.getOwnStaticValues = exports.getPropsValidators = exports.PropsValidatorsMetaKey = exports.getOwnPropsValidator = exports.setPropsValidator = exports.getModelId = exports.setModelId = exports.ModelId = exports.getModelVersion = exports.setModelVersion = exports.getModelName = exports.setModelName = exports.getPropsMap = exports.setProp = exports.getOwnPropsMap = exports.PropsMap = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const core_1 = require("../core");
|
|
9
9
|
const static_value_1 = require("./helpers/static-value");
|
|
10
|
+
// OWN PROPS MAP
|
|
10
11
|
const OwnPropsMapMetaKey = Symbol.for("OWN_PROPS_MAP");
|
|
11
12
|
class PropsMap extends Map {
|
|
12
13
|
}
|
|
@@ -25,6 +26,7 @@ const setProp = (target, key, propTargetKey) => {
|
|
|
25
26
|
ownPropsMap.set(key, propTargetKey);
|
|
26
27
|
};
|
|
27
28
|
exports.setProp = setProp;
|
|
29
|
+
// PROPS MAP
|
|
28
30
|
const PropsMapMetaKey = Symbol.for("PROPS_MAP");
|
|
29
31
|
const getPropsMap = (target) => {
|
|
30
32
|
const propsMap = () => Reflect.getOwnMetadata(PropsMapMetaKey, target);
|
|
@@ -50,7 +52,6 @@ const getPropsMap = (target) => {
|
|
|
50
52
|
return propsMap();
|
|
51
53
|
};
|
|
52
54
|
exports.getPropsMap = getPropsMap;
|
|
53
|
-
//
|
|
54
55
|
const ModelNameMetaKey = Symbol.for("MODEL_NAME");
|
|
55
56
|
const setModelName = (target, name) => {
|
|
56
57
|
Reflect.defineMetadata(ModelNameMetaKey, name, target);
|
|
@@ -63,7 +64,6 @@ const getModelName = (target) => {
|
|
|
63
64
|
return modelName();
|
|
64
65
|
};
|
|
65
66
|
exports.getModelName = getModelName;
|
|
66
|
-
//
|
|
67
67
|
const ModelVersionMetaKey = Symbol.for("MODEL_VERSION");
|
|
68
68
|
const setModelVersion = (target, version) => {
|
|
69
69
|
Reflect.defineMetadata(ModelVersionMetaKey, version, target);
|
|
@@ -76,6 +76,45 @@ const getModelVersion = (target) => {
|
|
|
76
76
|
return modelVersion();
|
|
77
77
|
};
|
|
78
78
|
exports.getModelVersion = getModelVersion;
|
|
79
|
+
class ModelId {
|
|
80
|
+
static fromValue(value) {
|
|
81
|
+
const [modelName, modelVersion] = value.split(this.ValueDivider);
|
|
82
|
+
return new ModelId(String(modelName), Number(modelVersion));
|
|
83
|
+
}
|
|
84
|
+
static makeValue(modelId) {
|
|
85
|
+
return `${modelId.modelName}${this.ValueDivider}${modelId.modelVersion}`;
|
|
86
|
+
}
|
|
87
|
+
constructor(modelName, modelVersion) {
|
|
88
|
+
this.modelName = modelName;
|
|
89
|
+
this.modelVersion = modelVersion;
|
|
90
|
+
}
|
|
91
|
+
get value() {
|
|
92
|
+
return ModelId.makeValue(this);
|
|
93
|
+
}
|
|
94
|
+
equalsValue(modelIdValue) {
|
|
95
|
+
return this.value === modelIdValue;
|
|
96
|
+
}
|
|
97
|
+
equals(modelId) {
|
|
98
|
+
return this.equalsValue(modelId.value);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.ModelId = ModelId;
|
|
102
|
+
ModelId.ValueDivider = "|";
|
|
103
|
+
const ModelIdMetaKey = Symbol.for("MODEL_ID");
|
|
104
|
+
const setModelId = (target, modelId) => {
|
|
105
|
+
Reflect.defineMetadata(ModelIdMetaKey, modelId, target);
|
|
106
|
+
};
|
|
107
|
+
exports.setModelId = setModelId;
|
|
108
|
+
const getModelId = (target) => {
|
|
109
|
+
const modelId = () => Reflect.getOwnMetadata(ModelIdMetaKey, target);
|
|
110
|
+
if (!modelId()) {
|
|
111
|
+
const modelName = (0, exports.getModelName)(target);
|
|
112
|
+
const modelVersion = (0, exports.getModelVersion)(target);
|
|
113
|
+
(0, exports.setModelId)(target, new ModelId(modelName, modelVersion));
|
|
114
|
+
}
|
|
115
|
+
return modelId();
|
|
116
|
+
};
|
|
117
|
+
exports.getModelId = getModelId;
|
|
79
118
|
const OwnPropsValidatorMetaKey = Symbol.for("OWN_PROPS_VALIDATOR");
|
|
80
119
|
const setPropsValidator = (target, validator) => {
|
|
81
120
|
Reflect.defineMetadata(OwnPropsValidatorMetaKey, validator, target);
|
package/dist/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"ddd-node","version":"
|
|
1
|
+
{"name":"ddd-node","version":"17.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","nodejs-snowflake":"^2.0.1","reflect-metadata":"^0.1.13","tsc-alias":"^1.8.8","type-fest":"^4.15.0","uuid":"^9.0.1"}}
|