ddd-node 15.0.2 → 15.0.4
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 → core}/aggregate/base.js +6 -2
- package/{dist/core → core}/aggregate/event-sourced-aggregate.js +11 -7
- package/core/aggregate/index.js +19 -0
- package/{dist/core → core}/aggregate/state-aggregate.js +6 -2
- package/core/aggregate/types.js +2 -0
- package/{dist/core → core}/entity.js +6 -2
- package/{dist/core → core}/enum.js +6 -2
- package/core/id/common/index.js +18 -0
- package/core/id/common/snowflake.js +14 -0
- package/core/id/common/uuid4.js +18 -0
- package/{dist/core → core}/id/id.js +5 -1
- package/core/id/index.js +19 -0
- package/core/id/interface.js +2 -0
- package/core/index.js +24 -0
- package/{dist/core → core}/message/command.js +6 -2
- package/{dist/core → core}/message/event.js +6 -2
- package/core/message/index.js +19 -0
- package/{dist/core → core}/message/message.js +11 -4
- package/core/model/errors.js +9 -0
- package/core/model/index.js +18 -0
- package/core/model/model-with-id.js +26 -0
- package/{dist/core → core}/model/model.js +19 -12
- package/core/repository.js +2 -0
- package/core/value-object.js +27 -0
- package/decorators/aggregate-es/handle.js +13 -0
- package/decorators/aggregate-es/index.js +18 -0
- package/decorators/aggregate-es/when.js +13 -0
- package/decorators/id.js +10 -0
- package/decorators/index.js +19 -0
- package/decorators/model/enum.js +10 -0
- package/decorators/model/index.js +21 -0
- package/decorators/model/model-name.js +10 -0
- package/decorators/model/prop.js +10 -0
- package/decorators/model/static.js +20 -0
- package/decorators/model/validator.js +11 -0
- package/decorators/type.js +2 -0
- package/index.js +21 -0
- package/meta/aggregate.metadata.js +34 -0
- package/meta/helpers/index.js +17 -0
- package/{dist/meta → meta}/helpers/static-value.js +5 -1
- package/meta/id.metadata.js +17 -0
- package/meta/index.js +20 -0
- package/{dist/meta → meta}/model.metadata.js +34 -20
- package/package.json +6 -5
- package/types/class-static.js +2 -0
- package/types/class.js +2 -0
- package/types/index.js +18 -0
- package/utils/index.js +17 -0
- package/utils/to-array.js +7 -0
- package/.editorconfig +0 -12
- package/.vscode/launch.json +0 -17
- package/dist/core/aggregate/index.js +0 -3
- package/dist/core/aggregate/types.js +0 -1
- package/dist/core/id/common/index.js +0 -2
- package/dist/core/id/common/snowflake.js +0 -10
- package/dist/core/id/common/uuid4.js +0 -14
- package/dist/core/id/index.js +0 -3
- package/dist/core/id/interface.js +0 -1
- package/dist/core/index.js +0 -8
- package/dist/core/message/index.js +0 -3
- package/dist/core/model/errors.js +0 -5
- package/dist/core/model/index.js +0 -2
- package/dist/core/model/model-with-id.js +0 -22
- package/dist/core/repository.js +0 -1
- package/dist/core/value-object.js +0 -20
- package/dist/decorators/aggregate-es/handle.js +0 -9
- package/dist/decorators/aggregate-es/index.js +0 -2
- package/dist/decorators/aggregate-es/when.js +0 -9
- package/dist/decorators/id.js +0 -6
- package/dist/decorators/index.js +0 -3
- package/dist/decorators/model/enum.js +0 -6
- package/dist/decorators/model/index.js +0 -5
- package/dist/decorators/model/model-name.js +0 -6
- package/dist/decorators/model/prop.js +0 -6
- package/dist/decorators/model/static.js +0 -16
- package/dist/decorators/model/validator.js +0 -7
- package/dist/decorators/type.js +0 -1
- package/dist/index.js +0 -5
- package/dist/meta/aggregate.metadata.js +0 -27
- package/dist/meta/helpers/index.js +0 -1
- package/dist/meta/id.metadata.js +0 -12
- package/dist/meta/index.js +0 -4
- package/dist/types/class-static.js +0 -1
- package/dist/types/class.js +0 -1
- package/dist/types/index.js +0 -2
- package/dist/utils/index.js +0 -1
- package/dist/utils/to-array.js +0 -3
- package/ts-loader.js +0 -4
- package/tsconfig.json +0 -122
- package/tsconfig.spec.json +0 -5
- /package/{dist/core → core}/aggregate/base.d.ts +0 -0
- /package/{dist/core → core}/aggregate/event-sourced-aggregate.d.ts +0 -0
- /package/{dist/core → core}/aggregate/index.d.ts +0 -0
- /package/{dist/core → core}/aggregate/state-aggregate.d.ts +0 -0
- /package/{dist/core → core}/aggregate/types.d.ts +0 -0
- /package/{dist/core → core}/entity.d.ts +0 -0
- /package/{dist/core → core}/enum.d.ts +0 -0
- /package/{dist/core → core}/id/common/index.d.ts +0 -0
- /package/{dist/core → core}/id/common/snowflake.d.ts +0 -0
- /package/{dist/core → core}/id/common/uuid4.d.ts +0 -0
- /package/{dist/core → core}/id/id.d.ts +0 -0
- /package/{dist/core → core}/id/index.d.ts +0 -0
- /package/{dist/core → core}/id/interface.d.ts +0 -0
- /package/{dist/core → core}/index.d.ts +0 -0
- /package/{dist/core → core}/message/command.d.ts +0 -0
- /package/{dist/core → core}/message/event.d.ts +0 -0
- /package/{dist/core → core}/message/index.d.ts +0 -0
- /package/{dist/core → core}/message/message.d.ts +0 -0
- /package/{dist/core → core}/model/errors.d.ts +0 -0
- /package/{dist/core → core}/model/index.d.ts +0 -0
- /package/{dist/core → core}/model/model-with-id.d.ts +0 -0
- /package/{dist/core → core}/model/model.d.ts +0 -0
- /package/{dist/core → core}/repository.d.ts +0 -0
- /package/{dist/core → core}/value-object.d.ts +0 -0
- /package/{dist/decorators → decorators}/aggregate-es/handle.d.ts +0 -0
- /package/{dist/decorators → decorators}/aggregate-es/index.d.ts +0 -0
- /package/{dist/decorators → decorators}/aggregate-es/when.d.ts +0 -0
- /package/{dist/decorators → decorators}/id.d.ts +0 -0
- /package/{dist/decorators → decorators}/index.d.ts +0 -0
- /package/{dist/decorators → decorators}/model/enum.d.ts +0 -0
- /package/{dist/decorators → decorators}/model/index.d.ts +0 -0
- /package/{dist/decorators → decorators}/model/model-name.d.ts +0 -0
- /package/{dist/decorators → decorators}/model/prop.d.ts +0 -0
- /package/{dist/decorators → decorators}/model/static.d.ts +0 -0
- /package/{dist/decorators → decorators}/model/validator.d.ts +0 -0
- /package/{dist/decorators → decorators}/type.d.ts +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/meta → meta}/aggregate.metadata.d.ts +0 -0
- /package/{dist/meta → meta}/helpers/index.d.ts +0 -0
- /package/{dist/meta → meta}/helpers/static-value.d.ts +0 -0
- /package/{dist/meta → meta}/id.metadata.d.ts +0 -0
- /package/{dist/meta → meta}/index.d.ts +0 -0
- /package/{dist/meta → meta}/model.metadata.d.ts +0 -0
- /package/{dist/types → types}/class-static.d.ts +0 -0
- /package/{dist/types → types}/class.d.ts +0 -0
- /package/{dist/types → types}/index.d.ts +0 -0
- /package/{dist/utils → utils}/index.d.ts +0 -0
- /package/{dist/utils → utils}/to-array.d.ts +0 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AggregateBase = void 0;
|
|
4
|
+
const entity_1 = require("../entity");
|
|
5
|
+
class AggregateBase extends entity_1.EntityBase {
|
|
3
6
|
constructor(metadata, props) {
|
|
4
7
|
super(metadata, props);
|
|
5
8
|
this._version = metadata.version;
|
|
@@ -13,3 +16,4 @@ export class AggregateBase extends EntityBase {
|
|
|
13
16
|
return eventClass.newEvent(eventSource, props);
|
|
14
17
|
}
|
|
15
18
|
}
|
|
19
|
+
exports.AggregateBase = AggregateBase;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventSourcedAggregateBase = void 0;
|
|
4
|
+
const meta_1 = require("../../meta");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const base_1 = require("./base");
|
|
7
|
+
class EventSourcedAggregateBase extends base_1.AggregateBase {
|
|
5
8
|
constructor(metadata, props) {
|
|
6
9
|
super(metadata, props);
|
|
7
10
|
this._handledCommands = [];
|
|
@@ -26,10 +29,10 @@ export class EventSourcedAggregateBase extends AggregateBase {
|
|
|
26
29
|
return instance;
|
|
27
30
|
}
|
|
28
31
|
static eventApplierMap() {
|
|
29
|
-
return getEventApplierMap(this.prototype);
|
|
32
|
+
return (0, meta_1.getEventApplierMap)(this.prototype);
|
|
30
33
|
}
|
|
31
34
|
static commandHandlerMap() {
|
|
32
|
-
return getCommandHandlerMap(this.prototype);
|
|
35
|
+
return (0, meta_1.getCommandHandlerMap)(this.prototype);
|
|
33
36
|
}
|
|
34
37
|
getVersion() {
|
|
35
38
|
return this._version + this._pastEvents.length + this._events.length;
|
|
@@ -105,7 +108,7 @@ export class EventSourcedAggregateBase extends AggregateBase {
|
|
|
105
108
|
}
|
|
106
109
|
handleCommand(command) {
|
|
107
110
|
const handler = this.getHandlerForCommand(command);
|
|
108
|
-
const events = toArray(handler.call(this, command));
|
|
111
|
+
const events = (0, utils_1.toArray)(handler.call(this, command));
|
|
109
112
|
events.forEach((event) => {
|
|
110
113
|
event.setContext({
|
|
111
114
|
correlationId: command.getContext()?.correlationId,
|
|
@@ -128,3 +131,4 @@ export class EventSourcedAggregateBase extends AggregateBase {
|
|
|
128
131
|
};
|
|
129
132
|
}
|
|
130
133
|
}
|
|
134
|
+
exports.EventSourcedAggregateBase = EventSourcedAggregateBase;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./state-aggregate"), exports);
|
|
18
|
+
__exportStar(require("./event-sourced-aggregate"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StateAggregateBase = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
class StateAggregateBase extends base_1.AggregateBase {
|
|
3
6
|
constructor(metadata, props) {
|
|
4
7
|
super(metadata, props);
|
|
5
8
|
this._events = [];
|
|
@@ -33,3 +36,4 @@ export class StateAggregateBase extends AggregateBase {
|
|
|
33
36
|
this._events = [];
|
|
34
37
|
}
|
|
35
38
|
}
|
|
39
|
+
exports.StateAggregateBase = StateAggregateBase;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityBase = void 0;
|
|
4
|
+
const model_1 = require("./model");
|
|
5
|
+
class EntityBase extends model_1.ModelWithId {
|
|
3
6
|
constructor(metadata, props) {
|
|
4
7
|
super(metadata.id);
|
|
5
8
|
if (props)
|
|
@@ -14,3 +17,4 @@ export class EntityBase extends ModelWithId {
|
|
|
14
17
|
}, props);
|
|
15
18
|
}
|
|
16
19
|
}
|
|
20
|
+
exports.EntityBase = EntityBase;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnumBase = void 0;
|
|
4
|
+
const model_1 = require("./model");
|
|
5
|
+
class EnumBase extends model_1.ModelBase {
|
|
3
6
|
static values() {
|
|
4
7
|
return Array.from(this.ownStaticValues().values()).map((staticValue) => staticValue.value);
|
|
5
8
|
}
|
|
@@ -39,3 +42,4 @@ export class EnumBase extends ModelBase {
|
|
|
39
42
|
return equalType && equalValue;
|
|
40
43
|
}
|
|
41
44
|
}
|
|
45
|
+
exports.EnumBase = EnumBase;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./snowflake"), exports);
|
|
18
|
+
__exportStar(require("./uuid4"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SnowflakeIdService = void 0;
|
|
4
|
+
const nodejs_snowflake_1 = require("nodejs-snowflake");
|
|
5
|
+
class SnowflakeIdService {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this._snowflake = new nodejs_snowflake_1.Snowflake(options);
|
|
8
|
+
}
|
|
9
|
+
validateValue(value) { }
|
|
10
|
+
generateValue() {
|
|
11
|
+
return this._snowflake.getUniqueID().toString(16);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.SnowflakeIdService = SnowflakeIdService;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Uuid4Service = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
class Uuid4Service {
|
|
6
|
+
validateValue(value) {
|
|
7
|
+
const isUuid = (0, uuid_1.validate)(value);
|
|
8
|
+
const isV4 = (0, uuid_1.version)(value) === 4;
|
|
9
|
+
if (!isUuid)
|
|
10
|
+
throw new Error("Id value is invalid for uuid type");
|
|
11
|
+
if (!isV4)
|
|
12
|
+
throw new Error("Version of uuid value must be 4");
|
|
13
|
+
}
|
|
14
|
+
generateValue() {
|
|
15
|
+
return (0, uuid_1.v4)();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.Uuid4Service = Uuid4Service;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Id = void 0;
|
|
4
|
+
class Id {
|
|
2
5
|
constructor(idOrValue) {
|
|
3
6
|
this._value = idOrValue instanceof Id ? idOrValue.value : idOrValue;
|
|
4
7
|
}
|
|
@@ -9,3 +12,4 @@ export class Id {
|
|
|
9
12
|
return id._value === this._value;
|
|
10
13
|
}
|
|
11
14
|
}
|
|
15
|
+
exports.Id = Id;
|
package/core/id/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./interface"), exports);
|
|
18
|
+
__exportStar(require("./id"), exports);
|
|
19
|
+
__exportStar(require("./common"), exports);
|
package/core/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./model"), exports);
|
|
18
|
+
__exportStar(require("./id"), exports);
|
|
19
|
+
__exportStar(require("./aggregate"), exports);
|
|
20
|
+
__exportStar(require("./entity"), exports);
|
|
21
|
+
__exportStar(require("./enum"), exports);
|
|
22
|
+
__exportStar(require("./message"), exports);
|
|
23
|
+
__exportStar(require("./value-object"), exports);
|
|
24
|
+
__exportStar(require("./repository"), exports);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandBase = void 0;
|
|
4
|
+
const message_1 = require("./message");
|
|
5
|
+
class CommandBase extends message_1.MessageBase {
|
|
3
6
|
constructor(metadata, props) {
|
|
4
7
|
super({ ...metadata, messageType: CommandBase.COMMAND_MESSAGE_TYPE }, props);
|
|
5
8
|
this._commandType = this.modelName();
|
|
@@ -15,4 +18,5 @@ export class CommandBase extends MessageBase {
|
|
|
15
18
|
this._commandType;
|
|
16
19
|
}
|
|
17
20
|
}
|
|
21
|
+
exports.CommandBase = CommandBase;
|
|
18
22
|
CommandBase.COMMAND_MESSAGE_TYPE = "command";
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventBase = void 0;
|
|
4
|
+
const message_1 = require("./message");
|
|
5
|
+
class EventBase extends message_1.MessageBase {
|
|
3
6
|
constructor(metadata, props) {
|
|
4
7
|
super({ ...metadata, messageType: EventBase.EVENT_MESSAGE_TYPE }, props);
|
|
5
8
|
this._source = metadata.source;
|
|
@@ -20,4 +23,5 @@ export class EventBase extends MessageBase {
|
|
|
20
23
|
return this._eventType;
|
|
21
24
|
}
|
|
22
25
|
}
|
|
26
|
+
exports.EventBase = EventBase;
|
|
23
27
|
EventBase.EVENT_MESSAGE_TYPE = "event";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./message"), exports);
|
|
18
|
+
__exportStar(require("./command"), exports);
|
|
19
|
+
__exportStar(require("./event"), exports);
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MessageBase = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const model_1 = require("../model");
|
|
9
|
+
class MessageBase extends model_1.ModelWithId {
|
|
4
10
|
constructor(metadata, props) {
|
|
5
11
|
super(metadata.id);
|
|
6
12
|
this._messageType = metadata.messageType;
|
|
@@ -21,6 +27,7 @@ export class MessageBase extends ModelWithId {
|
|
|
21
27
|
return this._context;
|
|
22
28
|
}
|
|
23
29
|
setContext(context) {
|
|
24
|
-
this._context =
|
|
30
|
+
this._context = lodash_1.default.merge(this._context, context);
|
|
25
31
|
}
|
|
26
32
|
}
|
|
33
|
+
exports.MessageBase = MessageBase;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PropsInitializedError = void 0;
|
|
4
|
+
class PropsInitializedError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super("Props is initialized");
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.PropsInitializedError = PropsInitializedError;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./model"), exports);
|
|
18
|
+
__exportStar(require("./model-with-id"), exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelWithId = void 0;
|
|
4
|
+
const meta_1 = require("../../meta");
|
|
5
|
+
const id_1 = require("../id");
|
|
6
|
+
const model_1 = require("./model");
|
|
7
|
+
class ModelWithId extends model_1.ModelBase {
|
|
8
|
+
constructor(id) {
|
|
9
|
+
super();
|
|
10
|
+
this._id = id;
|
|
11
|
+
}
|
|
12
|
+
static idService() {
|
|
13
|
+
return (0, meta_1.getIdService)(this);
|
|
14
|
+
}
|
|
15
|
+
static id(id) {
|
|
16
|
+
const idService = this.idService();
|
|
17
|
+
return new id_1.Id(id ?? idService.generateValue());
|
|
18
|
+
}
|
|
19
|
+
id() {
|
|
20
|
+
return this._id;
|
|
21
|
+
}
|
|
22
|
+
hasId(id) {
|
|
23
|
+
return this._id.equals(id);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.ModelWithId = ModelWithId;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ModelBase = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const meta_1 = require("../../meta");
|
|
9
|
+
const errors_1 = require("./errors");
|
|
10
|
+
class ModelBase {
|
|
5
11
|
static isModel(model) {
|
|
6
12
|
return model instanceof ModelBase;
|
|
7
13
|
}
|
|
@@ -9,19 +15,19 @@ export class ModelBase {
|
|
|
9
15
|
return false;
|
|
10
16
|
}
|
|
11
17
|
static modelName() {
|
|
12
|
-
return getModelName(this);
|
|
18
|
+
return (0, meta_1.getModelName)(this);
|
|
13
19
|
}
|
|
14
20
|
static propsValidator() {
|
|
15
|
-
return getPropsValidator(this);
|
|
21
|
+
return (0, meta_1.getPropsValidator)(this);
|
|
16
22
|
}
|
|
17
23
|
static ownStaticValues() {
|
|
18
|
-
return getOwnStaticValues(this);
|
|
24
|
+
return (0, meta_1.getOwnStaticValues)(this);
|
|
19
25
|
}
|
|
20
26
|
static ownPropsMap() {
|
|
21
|
-
return getOwnPropsMap(this.prototype);
|
|
27
|
+
return (0, meta_1.getOwnPropsMap)(this.prototype);
|
|
22
28
|
}
|
|
23
29
|
static propsMap() {
|
|
24
|
-
return getPropsMap(this.prototype);
|
|
30
|
+
return (0, meta_1.getPropsMap)(this.prototype);
|
|
25
31
|
}
|
|
26
32
|
constructor() {
|
|
27
33
|
this._props = ModelBase.EMPTY_PROPS;
|
|
@@ -54,7 +60,7 @@ export class ModelBase {
|
|
|
54
60
|
return this.currentModelType.ownPropsMap();
|
|
55
61
|
}
|
|
56
62
|
propsMap() {
|
|
57
|
-
return getPropsMap(Reflect.getPrototypeOf(this));
|
|
63
|
+
return (0, meta_1.getPropsMap)(Reflect.getPrototypeOf(this));
|
|
58
64
|
}
|
|
59
65
|
validateProps(props) {
|
|
60
66
|
const propsValidator = this.propsValidator();
|
|
@@ -70,7 +76,7 @@ export class ModelBase {
|
|
|
70
76
|
props() {
|
|
71
77
|
if (this.propsIsEmpty())
|
|
72
78
|
return null;
|
|
73
|
-
return
|
|
79
|
+
return lodash_1.default.cloneDeepWith(this._props, (value) => {
|
|
74
80
|
if (ModelBase.isModel(value)) {
|
|
75
81
|
value.redefineModel();
|
|
76
82
|
return value;
|
|
@@ -79,7 +85,7 @@ export class ModelBase {
|
|
|
79
85
|
}
|
|
80
86
|
initializeProps(props) {
|
|
81
87
|
if (!this.propsIsEmpty())
|
|
82
|
-
throw new PropsInitializedError();
|
|
88
|
+
throw new errors_1.PropsInitializedError();
|
|
83
89
|
if (!this.isMutable()) {
|
|
84
90
|
this._props = props;
|
|
85
91
|
Object.freeze(this._props);
|
|
@@ -96,4 +102,5 @@ export class ModelBase {
|
|
|
96
102
|
this.validate();
|
|
97
103
|
}
|
|
98
104
|
}
|
|
105
|
+
exports.ModelBase = ModelBase;
|
|
99
106
|
ModelBase.EMPTY_PROPS = {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ValueObjectBase = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const model_1 = require("./model");
|
|
9
|
+
class ValueObjectBase extends model_1.ModelBase {
|
|
10
|
+
constructor(props) {
|
|
11
|
+
super();
|
|
12
|
+
this.initializeProps(props);
|
|
13
|
+
}
|
|
14
|
+
props() {
|
|
15
|
+
return super.props();
|
|
16
|
+
}
|
|
17
|
+
equals(vo) {
|
|
18
|
+
const equalsType = vo instanceof this.constructor;
|
|
19
|
+
const equalsValue = JSON.stringify(vo.props()) === JSON.stringify(this.props());
|
|
20
|
+
return equalsType && equalsValue;
|
|
21
|
+
}
|
|
22
|
+
with(props) {
|
|
23
|
+
const newProps = lodash_1.default.merge(this.props(), props);
|
|
24
|
+
return new this.constructor(newProps);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.ValueObjectBase = ValueObjectBase;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Handle = void 0;
|
|
4
|
+
const meta_1 = require("../../meta");
|
|
5
|
+
const Handle = (commandClass) => {
|
|
6
|
+
return (target, propertyKey, descriptor) => {
|
|
7
|
+
if (typeof descriptor.value === "function") {
|
|
8
|
+
const commandName = (0, meta_1.getModelName)(commandClass);
|
|
9
|
+
(0, meta_1.defineCommandHandler)(target, commandName, descriptor.value);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.Handle = Handle;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./handle"), exports);
|
|
18
|
+
__exportStar(require("./when"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.When = void 0;
|
|
4
|
+
const meta_1 = require("../../meta");
|
|
5
|
+
const When = (eventClass) => {
|
|
6
|
+
return (target, propertyKey, descriptor) => {
|
|
7
|
+
if (typeof descriptor.value === "function") {
|
|
8
|
+
const eventName = (0, meta_1.getModelName)(eventClass);
|
|
9
|
+
(0, meta_1.defineEventApplier)(target, eventName, descriptor.value);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.When = When;
|
package/decorators/id.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UseIdService = void 0;
|
|
4
|
+
const meta_1 = require("../meta");
|
|
5
|
+
const UseIdService = (idService) => {
|
|
6
|
+
return (target) => {
|
|
7
|
+
(0, meta_1.defineIdService)(target, idService);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
exports.UseIdService = UseIdService;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./aggregate-es"), exports);
|
|
18
|
+
__exportStar(require("./id"), exports);
|
|
19
|
+
__exportStar(require("./model"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Enum = void 0;
|
|
4
|
+
const static_1 = require("./static");
|
|
5
|
+
const Enum = (value) => {
|
|
6
|
+
return (target, key) => {
|
|
7
|
+
(0, static_1.Static)(() => new target(value))(target, key);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
exports.Enum = Enum;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./prop"), exports);
|
|
18
|
+
__exportStar(require("./model-name"), exports);
|
|
19
|
+
__exportStar(require("./validator"), exports);
|
|
20
|
+
__exportStar(require("./static"), exports);
|
|
21
|
+
__exportStar(require("./enum"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelName = void 0;
|
|
4
|
+
const meta_1 = require("../../meta");
|
|
5
|
+
const ModelName = (name) => {
|
|
6
|
+
return (target) => {
|
|
7
|
+
(0, meta_1.setModelName)(target, name);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
exports.ModelName = ModelName;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Prop = void 0;
|
|
4
|
+
const meta_1 = require("../../meta");
|
|
5
|
+
const Prop = (propKey) => {
|
|
6
|
+
return (target, key) => {
|
|
7
|
+
(0, meta_1.setProp)(target, key, propKey ?? key);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
exports.Prop = Prop;
|