ddd-node 30.1.2 → 32.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/base/decorators/model.d.ts +5 -5
- package/base/decorators/mutable.d.ts +2 -2
- package/base/decorators/prop.d.ts +2 -2
- package/base/decorators/props-validator.d.ts +2 -2
- package/base/decorators/static.d.ts +2 -2
- package/base/domain.d.ts +1 -0
- package/base/domain.js +3 -0
- package/base/meta/model-domain.d.ts +4 -3
- package/base/meta/model-id.d.ts +3 -3
- package/base/meta/model-mutable.d.ts +1 -0
- package/base/meta/model-mutable.js +1 -0
- package/base/meta/model-name.d.ts +3 -3
- package/base/meta/model-props-map.d.ts +5 -5
- package/base/meta/model-props-map.js +1 -1
- package/base/meta/model-props-validator.d.ts +4 -4
- package/base/meta/model-static-values.d.ts +8 -8
- package/base/meta/model-version.d.ts +3 -3
- package/base/model/index.d.ts +0 -1
- package/base/model/index.js +0 -1
- package/base/model/model-descriptor.d.ts +15 -12
- package/base/model/model-descriptor.js +39 -0
- package/base/model/model.d.ts +10 -20
- package/base/model/model.js +23 -52
- package/base/model-registry.d.ts +14 -10
- package/base/model-registry.js +42 -27
- package/core/decorators/enum/index.d.ts +1 -0
- package/core/decorators/enum/index.js +17 -0
- package/core/decorators/enum/is-enum.d.ts +2 -0
- package/{decorators/enum.js → core/decorators/enum/is-enum.js} +4 -4
- package/core/decorators/es-aggregate/handle.d.ts +2 -0
- package/core/decorators/es-aggregate/when.d.ts +2 -0
- package/{decorators → core/decorators}/index.d.ts +1 -1
- package/{decorators → core/decorators}/index.js +1 -1
- package/core/decorators/message/index.d.ts +2 -0
- package/core/decorators/message/index.js +18 -0
- package/core/decorators/message/is-command.d.ts +4 -0
- package/{decorators/message/command.js → core/decorators/message/is-command.js} +4 -4
- package/core/decorators/message/is-event.d.ts +4 -0
- package/{decorators/message/event.js → core/decorators/message/is-event.js} +4 -4
- package/core/index.d.ts +3 -6
- package/core/index.js +3 -6
- package/{meta → core/meta}/command.metadata.js +2 -2
- package/{meta/aggregate-es → core/meta/es-aggregate}/command-handler-map.d.ts +1 -1
- package/{meta/aggregate-es → core/meta/es-aggregate}/event-applier-map.d.ts +1 -1
- package/{meta → core/meta}/event.metadata.js +1 -1
- package/{meta → core/meta}/index.d.ts +1 -1
- package/{meta → core/meta}/index.js +1 -1
- package/core/{aggregate/aggregate-base → model/aggregate}/aggregate.d.ts +7 -6
- package/core/{aggregate/aggregate-base → model/aggregate}/aggregate.js +12 -12
- package/core/model/aggregate/es-aggregate.d.ts +50 -0
- package/core/{aggregate/event-sourced-aggregate/event-sourced-aggregate.js → model/aggregate/es-aggregate.js} +40 -33
- package/core/model/aggregate/index.d.ts +4 -0
- package/core/{aggregate → model/aggregate}/index.js +2 -2
- package/core/{aggregate/state-aggregate → model/aggregate}/state-aggregate.d.ts +10 -9
- package/core/{aggregate/state-aggregate → model/aggregate}/state-aggregate.js +9 -7
- package/core/model/aggregate/types.d.ts +7 -0
- package/core/model/entity/entity.d.ts +18 -0
- package/core/{entity → model/entity}/entity.js +12 -9
- package/core/model/entity/index.d.ts +1 -0
- package/core/{entity → model/entity}/index.js +0 -1
- package/core/{enum → model/enum}/enum.d.ts +7 -10
- package/core/{enum → model/enum}/enum.js +24 -16
- package/core/model/enum/index.d.ts +1 -0
- package/core/{enum → model/enum}/index.js +0 -1
- package/core/model/index.d.ts +6 -0
- package/core/{aggregate/aggregate-base → model}/index.js +5 -2
- package/core/model/message/command.d.ts +20 -0
- package/core/model/message/command.js +27 -0
- package/core/model/message/event.d.ts +32 -0
- package/core/model/message/event.js +31 -0
- package/{decorators → core/model}/message/index.d.ts +2 -1
- package/{decorators → core/model}/message/index.js +2 -1
- package/core/model/message/message.d.ts +37 -0
- package/core/{message/message-base → model/message}/message.js +13 -6
- package/core/{model-with-id → model/model-with-id}/index.d.ts +0 -1
- package/core/{model-with-id → model/model-with-id}/index.js +0 -1
- package/core/{model-with-id → model/model-with-id}/model-with-id.d.ts +2 -2
- package/core/{model-with-id → model/model-with-id}/model-with-id.js +2 -2
- package/core/model/value-object/index.d.ts +1 -0
- package/core/{value-object → model/value-object}/index.js +0 -1
- package/core/model/value-object/value-object.d.ts +18 -0
- package/core/{value-object → model/value-object}/value-object.js +13 -9
- package/core/repository/repository.d.ts +1 -2
- package/event-pubsub/decorators/subscribe-to-events.d.ts +1 -1
- package/event-pubsub/event-dispatcher.d.ts +7 -0
- package/event-pubsub/{event-publisher.js → event-dispatcher.js} +4 -4
- package/event-pubsub/event-subscriber.d.ts +1 -1
- package/event-pubsub/index.d.ts +1 -1
- package/event-pubsub/index.js +1 -1
- package/event-pubsub/interfaces/event-dispatcher.interface.d.ts +4 -0
- package/event-pubsub/interfaces/index.d.ts +1 -1
- package/event-pubsub/interfaces/index.js +1 -1
- package/index.d.ts +1 -3
- package/index.js +1 -3
- package/package.json +1 -1
- package/base/model/model.builder.d.ts +0 -11
- package/base/model/model.builder.js +0 -18
- package/core/aggregate/aggregate-base/aggregate-event-publisher.interface.d.ts +0 -4
- package/core/aggregate/aggregate-base/aggregate.builder.d.ts +0 -6
- package/core/aggregate/aggregate-base/aggregate.builder.js +0 -15
- package/core/aggregate/aggregate-base/index.d.ts +0 -3
- package/core/aggregate/event-sourced-aggregate/event-sourced-aggregate-model-descriptor.d.ts +0 -9
- package/core/aggregate/event-sourced-aggregate/event-sourced-aggregate-model-descriptor.js +0 -2
- package/core/aggregate/event-sourced-aggregate/event-sourced-aggregate.builder.d.ts +0 -13
- package/core/aggregate/event-sourced-aggregate/event-sourced-aggregate.builder.js +0 -33
- package/core/aggregate/event-sourced-aggregate/event-sourced-aggregate.d.ts +0 -49
- package/core/aggregate/event-sourced-aggregate/index.d.ts +0 -2
- package/core/aggregate/event-sourced-aggregate/index.js +0 -18
- package/core/aggregate/event-sourced-aggregate/snapshot.d.ts +0 -8
- package/core/aggregate/event-sourced-aggregate/snapshot.js +0 -2
- package/core/aggregate/index.d.ts +0 -4
- package/core/aggregate/state-aggregate/index.d.ts +0 -2
- package/core/aggregate/state-aggregate/index.js +0 -18
- package/core/aggregate/state-aggregate/state-aggregate.builder.d.ts +0 -7
- package/core/aggregate/state-aggregate/state-aggregate.builder.js +0 -19
- package/core/aggregate/types.d.ts +0 -4
- package/core/entity/entity.builder.d.ts +0 -7
- package/core/entity/entity.builder.js +0 -16
- package/core/entity/entity.d.ts +0 -18
- package/core/entity/index.d.ts +0 -2
- package/core/enum/enum-builder.d.ts +0 -9
- package/core/enum/enum-builder.js +0 -32
- package/core/enum/index.d.ts +0 -2
- package/core/message/command/command-model-descriptor.d.ts +0 -6
- package/core/message/command/command-model-descriptor.js +0 -2
- package/core/message/command/command.builder.d.ts +0 -7
- package/core/message/command/command.builder.js +0 -21
- package/core/message/command/command.d.ts +0 -24
- package/core/message/command/command.js +0 -29
- package/core/message/command/index.d.ts +0 -3
- package/core/message/command/index.js +0 -19
- package/core/message/event/event-model-descriptor.d.ts +0 -6
- package/core/message/event/event-model-descriptor.js +0 -2
- package/core/message/event/event.builder.d.ts +0 -9
- package/core/message/event/event.builder.js +0 -28
- package/core/message/event/event.d.ts +0 -35
- package/core/message/event/event.js +0 -33
- package/core/message/event/index.d.ts +0 -3
- package/core/message/event/index.js +0 -19
- package/core/message/index.d.ts +0 -3
- package/core/message/index.js +0 -19
- package/core/message/message-base/index.d.ts +0 -2
- package/core/message/message-base/index.js +0 -18
- package/core/message/message-base/message.builder.d.ts +0 -16
- package/core/message/message-base/message.builder.js +0 -44
- package/core/message/message-base/message.d.ts +0 -31
- package/core/model-with-id/model-with-id.builder.d.ts +0 -9
- package/core/model-with-id/model-with-id.builder.js +0 -22
- package/core/value-object/index.d.ts +0 -2
- package/core/value-object/value-object.builder.d.ts +0 -7
- package/core/value-object/value-object.builder.js +0 -16
- package/core/value-object/value-object.d.ts +0 -17
- package/decorators/aggregate-es/handle.d.ts +0 -2
- package/decorators/aggregate-es/when.d.ts +0 -2
- package/decorators/enum.d.ts +0 -2
- package/decorators/message/command.d.ts +0 -4
- package/decorators/message/event.d.ts +0 -4
- package/event-pubsub/event-publisher.d.ts +0 -7
- package/event-pubsub/interfaces/event-publisher.interface.d.ts +0 -4
- package/event-pubsub/interfaces/event-publisher.interface.js +0 -2
- /package/{decorators/aggregate-es → core/decorators/es-aggregate}/handle.js +0 -0
- /package/{decorators/aggregate-es → core/decorators/es-aggregate}/index.d.ts +0 -0
- /package/{decorators/aggregate-es → core/decorators/es-aggregate}/index.js +0 -0
- /package/{decorators/aggregate-es → core/decorators/es-aggregate}/when.js +0 -0
- /package/{decorators → core/decorators}/type.d.ts +0 -0
- /package/{decorators → core/decorators}/type.js +0 -0
- /package/{meta → core/meta}/command.metadata.d.ts +0 -0
- /package/{meta/aggregate-es → core/meta/es-aggregate}/command-handler-map.js +0 -0
- /package/{meta/aggregate-es → core/meta/es-aggregate}/event-applier-map.js +0 -0
- /package/{meta/aggregate-es → core/meta/es-aggregate}/index.d.ts +0 -0
- /package/{meta/aggregate-es → core/meta/es-aggregate}/index.js +0 -0
- /package/{meta → core/meta}/event.metadata.d.ts +0 -0
- /package/core/{aggregate → model/aggregate}/types.js +0 -0
- /package/core/{model-with-id → model/model-with-id}/id.d.ts +0 -0
- /package/core/{model-with-id → model/model-with-id}/id.js +0 -0
- /package/{core/aggregate/aggregate-base/aggregate-event-publisher.interface.js → event-pubsub/interfaces/event-dispatcher.interface.js} +0 -0
|
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./aggregate
|
|
17
|
+
__exportStar(require("./es-aggregate"), exports);
|
|
18
18
|
__exportStar(require("./message"), exports);
|
|
19
19
|
__exportStar(require("./enum"), exports);
|
|
@@ -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("./is-command"), exports);
|
|
18
|
+
__exportStar(require("./is-event"), exports);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ModelOptions } from "../../../base";
|
|
2
|
+
import { AnyCommand, CommandClass } from "../../../core";
|
|
3
|
+
import { CommandType } from "../../meta";
|
|
4
|
+
export declare const IsCommand: (commandType: CommandType, modelOptions?: ModelOptions) => <T extends AnyCommand>(target: CommandClass<T>) => void;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const base_1 = require("
|
|
3
|
+
exports.IsCommand = void 0;
|
|
4
|
+
const base_1 = require("../../../base");
|
|
5
5
|
const meta_1 = require("../../meta");
|
|
6
|
-
const
|
|
6
|
+
const IsCommand = (commandType, modelOptions) => {
|
|
7
7
|
return (target) => {
|
|
8
8
|
(0, meta_1.defineCommandType)(target, commandType);
|
|
9
9
|
(0, base_1.Model)(modelOptions)(target);
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
exports.
|
|
12
|
+
exports.IsCommand = IsCommand;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ModelOptions } from "../../../base";
|
|
2
|
+
import { AnyEvent, EventClass } from "../../../core";
|
|
3
|
+
import { EventType } from "../../meta";
|
|
4
|
+
export declare const IsEvent: (eventType: EventType, modelOptions?: ModelOptions) => <T extends AnyEvent>(target: EventClass<T>) => void;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const base_1 = require("
|
|
3
|
+
exports.IsEvent = void 0;
|
|
4
|
+
const base_1 = require("../../../base");
|
|
5
5
|
const meta_1 = require("../../meta");
|
|
6
|
-
const
|
|
6
|
+
const IsEvent = (eventType, modelOptions) => {
|
|
7
7
|
return (target) => {
|
|
8
8
|
(0, meta_1.defineEventType)(target, eventType);
|
|
9
9
|
(0, base_1.Model)(modelOptions)(target);
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
exports.
|
|
12
|
+
exports.IsEvent = IsEvent;
|
package/core/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./enum";
|
|
3
|
-
export * from "./model-with-id";
|
|
4
|
-
export * from "./entity";
|
|
5
|
-
export * from "./aggregate";
|
|
6
|
-
export * from "./message";
|
|
1
|
+
export * from "./model";
|
|
7
2
|
export * from "./repository";
|
|
3
|
+
export * from "./decorators";
|
|
4
|
+
export * from "./meta";
|
package/core/index.js
CHANGED
|
@@ -14,10 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./enum"), exports);
|
|
19
|
-
__exportStar(require("./model-with-id"), exports);
|
|
20
|
-
__exportStar(require("./entity"), exports);
|
|
21
|
-
__exportStar(require("./aggregate"), exports);
|
|
22
|
-
__exportStar(require("./message"), exports);
|
|
17
|
+
__exportStar(require("./model"), exports);
|
|
23
18
|
__exportStar(require("./repository"), exports);
|
|
19
|
+
__exportStar(require("./decorators"), exports);
|
|
20
|
+
__exportStar(require("./meta"), exports);
|
|
@@ -5,7 +5,7 @@ require("reflect-metadata");
|
|
|
5
5
|
class $CommandType extends String {
|
|
6
6
|
static validate(commandType) {
|
|
7
7
|
if (commandType.trim().length === 0)
|
|
8
|
-
throw new Error("
|
|
8
|
+
throw new Error("IsCommand type cannot be an empty string");
|
|
9
9
|
}
|
|
10
10
|
constructor(commandType) {
|
|
11
11
|
$CommandType.validate(commandType);
|
|
@@ -21,7 +21,7 @@ exports.defineCommandType = defineCommandType;
|
|
|
21
21
|
const getCommandType = (target) => {
|
|
22
22
|
const commandType = Reflect.getOwnMetadata(CommandTypeMetaKey, target);
|
|
23
23
|
if (!commandType)
|
|
24
|
-
throw new Error("
|
|
24
|
+
throw new Error("IsCommand's type is not defined");
|
|
25
25
|
return commandType.valueOf();
|
|
26
26
|
};
|
|
27
27
|
exports.getCommandType = getCommandType;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { AnyEvent, EventApplier } from "../../
|
|
2
|
+
import { AnyEvent, EventApplier } from "../../model";
|
|
3
3
|
export declare class EventApplierMap extends Map<string, EventApplier> {
|
|
4
4
|
}
|
|
5
5
|
export declare const OwnEventApplierMapMetaKey: unique symbol;
|
|
@@ -5,7 +5,7 @@ require("reflect-metadata");
|
|
|
5
5
|
class $EventType extends String {
|
|
6
6
|
static validate(eventType) {
|
|
7
7
|
if (eventType.trim().length === 0)
|
|
8
|
-
throw new Error("
|
|
8
|
+
throw new Error("IsEvent type cannot be an empty string");
|
|
9
9
|
}
|
|
10
10
|
constructor(eventType) {
|
|
11
11
|
$EventType.validate(eventType);
|
|
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./aggregate
|
|
17
|
+
__exportStar(require("./es-aggregate"), exports);
|
|
18
18
|
__exportStar(require("./event.metadata"), exports);
|
|
19
19
|
__exportStar(require("./command.metadata"), exports);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ModelWithId, ModelWithIdMetadata } from "
|
|
3
|
-
import {
|
|
4
|
-
import { IAggregateEventPublisher } from "./
|
|
1
|
+
import { AnyEvent, EventClassWithTypedConstructor, EventSource } from "../message";
|
|
2
|
+
import { ModelWithId, ModelWithIdMetadata } from "../model-with-id";
|
|
3
|
+
import { InferredProps, Props } from "./../../../base";
|
|
4
|
+
import { IAggregateEventPublisher } from "./types";
|
|
5
5
|
export interface AggregateMetadata extends ModelWithIdMetadata {
|
|
6
6
|
version: number;
|
|
7
7
|
}
|
|
8
|
-
export declare abstract class
|
|
8
|
+
export declare abstract class Aggregate<P extends Props> extends ModelWithId<P> {
|
|
9
|
+
static createMetadata: (metadata?: Partial<AggregateMetadata>) => AggregateMetadata;
|
|
9
10
|
protected readonly _version: number;
|
|
10
11
|
constructor(metadata: AggregateMetadata, props?: P);
|
|
11
12
|
abstract version(): number;
|
|
@@ -14,4 +15,4 @@ export declare abstract class AggregateBase<P extends Props> extends ModelWithId
|
|
|
14
15
|
protected newEvent<E extends AnyEvent>(eventClass: EventClassWithTypedConstructor<E>, props: InferredProps<E>): E;
|
|
15
16
|
abstract publishEvents(publisher: IAggregateEventPublisher): void;
|
|
16
17
|
}
|
|
17
|
-
export type AnyAggregate =
|
|
18
|
+
export type AnyAggregate = Aggregate<Props>;
|
|
@@ -9,10 +9,11 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
const
|
|
14
|
-
const model_with_id_1 = require("
|
|
15
|
-
|
|
12
|
+
exports.Aggregate = void 0;
|
|
13
|
+
const uuid_1 = require("uuid");
|
|
14
|
+
const model_with_id_1 = require("../model-with-id");
|
|
15
|
+
const base_1 = require("./../../../base");
|
|
16
|
+
let Aggregate = class Aggregate extends model_with_id_1.ModelWithId {
|
|
16
17
|
constructor(metadata, props) {
|
|
17
18
|
super(metadata);
|
|
18
19
|
if (props)
|
|
@@ -29,15 +30,14 @@ let AggregateBase = class AggregateBase extends model_with_id_1.ModelWithId {
|
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
newEvent(eventClass, props) {
|
|
32
|
-
return eventClass
|
|
33
|
-
.builder()
|
|
34
|
-
.withSource(this.createEventSource())
|
|
35
|
-
.withProps(props)
|
|
36
|
-
.build();
|
|
33
|
+
return eventClass.build(props, { source: this.createEventSource() });
|
|
37
34
|
}
|
|
38
35
|
};
|
|
39
|
-
exports.
|
|
40
|
-
|
|
36
|
+
exports.Aggregate = Aggregate;
|
|
37
|
+
Aggregate.createMetadata = (metadata) => {
|
|
38
|
+
return Object.assign({ id: (0, uuid_1.v4)(), version: 0 }, metadata);
|
|
39
|
+
};
|
|
40
|
+
exports.Aggregate = Aggregate = __decorate([
|
|
41
41
|
(0, base_1.Mutable)(true),
|
|
42
42
|
__metadata("design:paramtypes", [Object, Object])
|
|
43
|
-
],
|
|
43
|
+
], Aggregate);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Id } from "src";
|
|
2
|
+
import { Class } from "type-fest";
|
|
3
|
+
import { InferredProps, Props } from "../../../base";
|
|
4
|
+
import { ClassStatic } from "../../../types";
|
|
5
|
+
import { AnyCommand, AnyEvent, EventClassWithTypedConstructor } from "../message";
|
|
6
|
+
import { Aggregate, AggregateMetadata } from "./aggregate";
|
|
7
|
+
import { IAggregateEventPublisher } from "./types";
|
|
8
|
+
export declare class ESAggregate<P extends Props> extends Aggregate<P> {
|
|
9
|
+
static fromStream<T extends AnyESAggregate>(this: ESAggregateClassWithTypedConstructor<T>, pastEvents: AnyEvent[], id?: Id): T;
|
|
10
|
+
static newStream<T extends AnyESAggregate>(this: ESAggregateClassWithTypedConstructor<T>, id?: Id): T;
|
|
11
|
+
static fromSnapshot<T extends AnyESAggregate>(this: ESAggregateClassWithTypedConstructor<T>, snapshot: Snapshot<T>, pastEvents?: AnyEvent[]): T;
|
|
12
|
+
static ownEventApplierMap<T extends AnyESAggregate>(this: ESAggregateClass<T>): import("src").EventApplierMap;
|
|
13
|
+
static eventApplierMap<T extends AnyESAggregate>(this: ESAggregateClass<T>): import("src").EventApplierMap;
|
|
14
|
+
static ownCommandHandlerMap<T extends AnyESAggregate>(this: ESAggregateClass<T>): import("src").CommandHandlerMap;
|
|
15
|
+
static commandHandlerMap<T extends AnyESAggregate>(this: ESAggregateClass<T>): import("src").CommandHandlerMap;
|
|
16
|
+
private _handledCommands;
|
|
17
|
+
private _pastEvents;
|
|
18
|
+
private _events;
|
|
19
|
+
constructor(metadata: AggregateMetadata, props?: P);
|
|
20
|
+
_constructor(): ESAggregateClass<this, any[]>;
|
|
21
|
+
version(): number;
|
|
22
|
+
pastEvents(): AnyEvent[];
|
|
23
|
+
events(): AnyEvent[];
|
|
24
|
+
handledCommands(): AnyCommand[];
|
|
25
|
+
hasNewEvent(): boolean;
|
|
26
|
+
getEventApplier<E extends AnyEvent>(event: E): EventApplier<E>;
|
|
27
|
+
private validateEventBeforeApply;
|
|
28
|
+
private _applyEvent;
|
|
29
|
+
private applyPastEvent;
|
|
30
|
+
applyPastEvents(pastEvents: AnyEvent[]): void;
|
|
31
|
+
applyEvent<E extends AnyEvent>(event: E): void;
|
|
32
|
+
applyEvents(events: AnyEvent[]): void;
|
|
33
|
+
applyNewEvent<E extends AnyEvent>(eventClass: EventClassWithTypedConstructor<E>, props: InferredProps<E>): void;
|
|
34
|
+
getCommandHandler<C extends AnyCommand>(command: C): CommandHandler<C, AnyEvent | AnyEvent[]>;
|
|
35
|
+
handleCommand<C extends AnyCommand>(command: C): AnyEvent[];
|
|
36
|
+
takeSnapshot(): Snapshot<this>;
|
|
37
|
+
protected commitEvents(): void;
|
|
38
|
+
publishEvents(publisher: IAggregateEventPublisher): void;
|
|
39
|
+
}
|
|
40
|
+
export type AnyESAggregate = ESAggregate<Props>;
|
|
41
|
+
export interface ESAggregateClass<T extends AnyESAggregate = AnyESAggregate, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof ESAggregate<InferredProps<T>>> {
|
|
42
|
+
}
|
|
43
|
+
export interface ESAggregateClassWithTypedConstructor<T extends AnyESAggregate = AnyESAggregate> extends ESAggregateClass<T, ConstructorParameters<typeof ESAggregate<InferredProps<T>>>> {
|
|
44
|
+
}
|
|
45
|
+
export type EventApplier<T extends AnyEvent = AnyEvent> = (event: T) => void;
|
|
46
|
+
export type CommandHandler<T extends AnyCommand = AnyCommand, U extends AnyEvent | AnyEvent[] = AnyEvent | AnyEvent[]> = (command: T) => U;
|
|
47
|
+
export interface Snapshot<T extends AnyESAggregate> {
|
|
48
|
+
metadata: AggregateMetadata;
|
|
49
|
+
props: InferredProps<T>;
|
|
50
|
+
}
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const meta_1 = require("../../../meta");
|
|
3
|
+
exports.ESAggregate = void 0;
|
|
5
4
|
const utils_1 = require("../../../utils");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
class
|
|
9
|
-
static
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.
|
|
16
|
-
|
|
5
|
+
const meta_1 = require("../../meta");
|
|
6
|
+
const aggregate_1 = require("./aggregate");
|
|
7
|
+
class ESAggregate extends aggregate_1.Aggregate {
|
|
8
|
+
static fromStream(pastEvents, id) {
|
|
9
|
+
const instance = new this(this.createMetadata({ id }));
|
|
10
|
+
instance.applyPastEvents(pastEvents);
|
|
11
|
+
return instance;
|
|
12
|
+
}
|
|
13
|
+
static newStream(id) {
|
|
14
|
+
return this.fromStream([], id);
|
|
15
|
+
}
|
|
16
|
+
static fromSnapshot(snapshot, pastEvents = []) {
|
|
17
|
+
const { id, version } = snapshot.metadata;
|
|
18
|
+
const { props } = snapshot;
|
|
19
|
+
const instance = new this({
|
|
20
|
+
id,
|
|
21
|
+
version,
|
|
22
|
+
}, props);
|
|
23
|
+
instance.applyPastEvents(pastEvents);
|
|
24
|
+
return instance;
|
|
17
25
|
}
|
|
18
26
|
static ownEventApplierMap() {
|
|
19
27
|
return (0, meta_1.getOwnEventApplierMap)(this.prototype);
|
|
@@ -27,9 +35,14 @@ class EventSourcedAggregateBase extends aggregate_base_1.AggregateBase {
|
|
|
27
35
|
static commandHandlerMap() {
|
|
28
36
|
return (0, meta_1.getCommandHandlerMap)(this.prototype);
|
|
29
37
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
constructor(metadata, props) {
|
|
39
|
+
super(metadata, props);
|
|
40
|
+
this._handledCommands = [];
|
|
41
|
+
this._events = [];
|
|
42
|
+
this._pastEvents = [];
|
|
43
|
+
}
|
|
44
|
+
_constructor() {
|
|
45
|
+
return this.constructor;
|
|
33
46
|
}
|
|
34
47
|
version() {
|
|
35
48
|
return this._version + this._pastEvents.length + this._events.length;
|
|
@@ -47,11 +60,11 @@ class EventSourcedAggregateBase extends aggregate_base_1.AggregateBase {
|
|
|
47
60
|
return Boolean(this._events.length);
|
|
48
61
|
}
|
|
49
62
|
getEventApplier(event) {
|
|
50
|
-
const
|
|
51
|
-
const
|
|
63
|
+
const eventType = event.eventType();
|
|
64
|
+
const eventApplierMap = this._constructor().eventApplierMap();
|
|
52
65
|
const applier = eventApplierMap.get(eventType);
|
|
53
66
|
if (!applier)
|
|
54
|
-
throw new Error("
|
|
67
|
+
throw new Error("IsEvent applier not found");
|
|
55
68
|
return applier;
|
|
56
69
|
}
|
|
57
70
|
validateEventBeforeApply(event) {
|
|
@@ -90,11 +103,11 @@ class EventSourcedAggregateBase extends aggregate_base_1.AggregateBase {
|
|
|
90
103
|
this.applyEvent(this.newEvent(eventClass, props));
|
|
91
104
|
}
|
|
92
105
|
getCommandHandler(command) {
|
|
93
|
-
const
|
|
94
|
-
const
|
|
106
|
+
const commandType = command.commandType();
|
|
107
|
+
const commandHandlerMap = this._constructor().commandHandlerMap();
|
|
95
108
|
const handler = commandHandlerMap.get(commandType);
|
|
96
109
|
if (!handler)
|
|
97
|
-
throw new Error("
|
|
110
|
+
throw new Error("IsCommand handler not found");
|
|
98
111
|
return handler;
|
|
99
112
|
}
|
|
100
113
|
handleCommand(command) {
|
|
@@ -108,28 +121,22 @@ class EventSourcedAggregateBase extends aggregate_base_1.AggregateBase {
|
|
|
108
121
|
this._handledCommands.push(command);
|
|
109
122
|
return events;
|
|
110
123
|
}
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
id: this.id(),
|
|
114
|
-
version: this.version(),
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
snap() {
|
|
124
|
+
takeSnapshot() {
|
|
118
125
|
if (this.propsIsEmpty())
|
|
119
126
|
throw new Error("Cannot create snapshot when the props is not initialized");
|
|
120
127
|
return {
|
|
121
|
-
metadata: this.
|
|
128
|
+
metadata: this.metadata(),
|
|
122
129
|
props: this.props(),
|
|
123
130
|
};
|
|
124
131
|
}
|
|
125
|
-
|
|
132
|
+
commitEvents() {
|
|
126
133
|
const events = this.events();
|
|
127
134
|
this._events = [];
|
|
128
135
|
this._pastEvents.push(...events);
|
|
129
136
|
}
|
|
130
137
|
publishEvents(publisher) {
|
|
131
138
|
publisher.publish(this.events());
|
|
132
|
-
this.
|
|
139
|
+
this.commitEvents();
|
|
133
140
|
}
|
|
134
141
|
}
|
|
135
|
-
exports.
|
|
142
|
+
exports.ESAggregate = ESAggregate;
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./aggregate
|
|
17
|
+
__exportStar(require("./aggregate"), exports);
|
|
18
18
|
__exportStar(require("./state-aggregate"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
19
|
+
__exportStar(require("./es-aggregate"), exports);
|
|
20
20
|
__exportStar(require("./types"), exports);
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Class } from "type-fest";
|
|
2
|
-
import {
|
|
2
|
+
import { InferredProps, Props } from "../../../base";
|
|
3
3
|
import { ClassStatic } from "../../../types";
|
|
4
|
-
import { AnyEvent, EventClassWithTypedConstructor } from "
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { AnyEvent, EventClassWithTypedConstructor } from "../message";
|
|
5
|
+
import { Aggregate, AggregateMetadata } from "./aggregate";
|
|
6
|
+
import { IAggregateEventPublisher } from "./types";
|
|
7
7
|
export interface StateAggregateMetadata extends AggregateMetadata {
|
|
8
8
|
}
|
|
9
|
-
export declare class
|
|
10
|
-
static
|
|
9
|
+
export declare class StateAggregate<P extends Props> extends Aggregate<P> {
|
|
10
|
+
static build<T extends AnyStateAggregate>(this: StateAggregateClassWithTypedConstructor<T>, props: InferredProps<T>, metadata?: Partial<StateAggregateMetadata>): T;
|
|
11
11
|
private _events;
|
|
12
12
|
constructor(metadata: StateAggregateMetadata, props: P);
|
|
13
|
+
_constructor(): StateAggregateClass<this, any[]>;
|
|
13
14
|
props(): P;
|
|
14
15
|
version(): number;
|
|
15
16
|
events(): AnyEvent[];
|
|
@@ -18,8 +19,8 @@ export declare class StateAggregateBase<P extends Props> extends AggregateBase<P
|
|
|
18
19
|
clearEvents(): void;
|
|
19
20
|
publishEvents(publisher: IAggregateEventPublisher): void;
|
|
20
21
|
}
|
|
21
|
-
export type AnyStateAggregate =
|
|
22
|
-
export interface StateAggregateClass<T extends AnyStateAggregate = AnyStateAggregate, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof
|
|
22
|
+
export type AnyStateAggregate = StateAggregate<Props>;
|
|
23
|
+
export interface StateAggregateClass<T extends AnyStateAggregate = AnyStateAggregate, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof StateAggregate<InferredProps<T>>> {
|
|
23
24
|
}
|
|
24
|
-
export interface StateAggregateClassWithTypedConstructor<T extends AnyStateAggregate = AnyStateAggregate> extends StateAggregateClass<T, ConstructorParameters<typeof
|
|
25
|
+
export interface StateAggregateClassWithTypedConstructor<T extends AnyStateAggregate = AnyStateAggregate> extends StateAggregateClass<T, ConstructorParameters<typeof StateAggregate<InferredProps<T>>>> {
|
|
25
26
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return new _1.StateAggregateBuilder(this);
|
|
3
|
+
exports.StateAggregate = void 0;
|
|
4
|
+
const aggregate_1 = require("./aggregate");
|
|
5
|
+
class StateAggregate extends aggregate_1.Aggregate {
|
|
6
|
+
static build(props, metadata) {
|
|
7
|
+
return new this(this.createMetadata(metadata), props);
|
|
9
8
|
}
|
|
10
9
|
constructor(metadata, props) {
|
|
11
10
|
super(metadata, props);
|
|
12
11
|
this._events = [];
|
|
13
12
|
}
|
|
13
|
+
_constructor() {
|
|
14
|
+
return this.constructor;
|
|
15
|
+
}
|
|
14
16
|
props() {
|
|
15
17
|
return super.props();
|
|
16
18
|
}
|
|
@@ -38,4 +40,4 @@ class StateAggregateBase extends aggregate_base_1.AggregateBase {
|
|
|
38
40
|
this.clearEvents();
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
|
-
exports.
|
|
43
|
+
exports.StateAggregate = StateAggregate;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ESAggregateClass } from "./es-aggregate";
|
|
2
|
+
import { StateAggregateClass } from "./state-aggregate";
|
|
3
|
+
import { AnyEvent } from "../message";
|
|
4
|
+
export type AggregateClass = StateAggregateClass | ESAggregateClass;
|
|
5
|
+
export interface IAggregateEventPublisher {
|
|
6
|
+
publish(events: AnyEvent | AnyEvent[]): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Class } from "type-fest";
|
|
2
|
+
import { InferredProps, Props } from "../../../base";
|
|
3
|
+
import { ClassStatic } from "../../../types";
|
|
4
|
+
import { Id, ModelWithId, ModelWithIdMetadata } from "../model-with-id";
|
|
5
|
+
export interface EntityMetadata extends ModelWithIdMetadata {
|
|
6
|
+
}
|
|
7
|
+
export declare class Entity<P extends Props> extends ModelWithId<P> {
|
|
8
|
+
static build<T extends AnyEntity>(this: EntityClassWithTypedConstructor<T>, props: InferredProps<T>, id?: Id): T;
|
|
9
|
+
constructor(metadata: EntityMetadata, props: P);
|
|
10
|
+
_constructor(): EntityClass<this, any[]>;
|
|
11
|
+
}
|
|
12
|
+
export type AnyEntity = Entity<Props>;
|
|
13
|
+
export interface EntityClass<T extends AnyEntity = AnyEntity, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof Entity<InferredProps<T>>> {
|
|
14
|
+
}
|
|
15
|
+
export interface EntityClassWithTypedConstructor<T extends AnyEntity = AnyEntity> extends EntityClass<T, ConstructorParameters<typeof Entity<InferredProps<T>>>> {
|
|
16
|
+
}
|
|
17
|
+
export interface EntityClassWithProps<P extends Props> extends EntityClass<Entity<P>> {
|
|
18
|
+
}
|
|
@@ -9,21 +9,24 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
const
|
|
12
|
+
exports.Entity = void 0;
|
|
13
|
+
const uuid_1 = require("uuid");
|
|
14
|
+
const base_1 = require("../../../base");
|
|
14
15
|
const model_with_id_1 = require("../model-with-id");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return new _1.EntityBuilder(this);
|
|
16
|
+
let Entity = class Entity extends model_with_id_1.ModelWithId {
|
|
17
|
+
static build(props, id) {
|
|
18
|
+
return new this({ id: id !== null && id !== void 0 ? id : (0, uuid_1.v4)() }, props);
|
|
19
19
|
}
|
|
20
20
|
constructor(metadata, props) {
|
|
21
21
|
super(metadata);
|
|
22
22
|
this.initializeProps(props);
|
|
23
23
|
}
|
|
24
|
+
_constructor() {
|
|
25
|
+
return this.constructor;
|
|
26
|
+
}
|
|
24
27
|
};
|
|
25
|
-
exports.
|
|
26
|
-
exports.
|
|
28
|
+
exports.Entity = Entity;
|
|
29
|
+
exports.Entity = Entity = __decorate([
|
|
27
30
|
(0, base_1.Mutable)(true),
|
|
28
31
|
__metadata("design:paramtypes", [Object, Object])
|
|
29
|
-
],
|
|
32
|
+
], Entity);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./entity";
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import { Class } from "type-fest";
|
|
2
|
-
import {
|
|
3
|
-
import { ClassStatic } from "
|
|
4
|
-
import { EnumBuilder } from ".";
|
|
2
|
+
import { DomainModel } from "../../../base";
|
|
3
|
+
import { ClassStatic } from "../../../types";
|
|
5
4
|
export type EnumValue = string | number;
|
|
6
5
|
export interface EnumProps {
|
|
7
6
|
value: EnumValue;
|
|
8
7
|
}
|
|
9
|
-
export declare class
|
|
10
|
-
static
|
|
11
|
-
static values(): EnumBase[];
|
|
8
|
+
export declare class Enum extends DomainModel<EnumProps> {
|
|
9
|
+
static values(): Enum[];
|
|
12
10
|
static from<T extends AnyEnum>(this: EnumClass<T>, value: EnumValue): T;
|
|
13
|
-
static fromSafe<T extends AnyEnum>(this: EnumClass<T>, value: EnumValue): T | null;
|
|
14
11
|
constructor(value: EnumValue);
|
|
15
12
|
value: EnumValue;
|
|
16
13
|
valueOf(): EnumValue;
|
|
17
14
|
}
|
|
18
|
-
export type AnyEnum =
|
|
19
|
-
export interface EnumClass<T extends AnyEnum = AnyEnum, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof
|
|
15
|
+
export type AnyEnum = Enum;
|
|
16
|
+
export interface EnumClass<T extends AnyEnum = AnyEnum, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof Enum> {
|
|
20
17
|
}
|
|
21
|
-
export interface EnumClassWithTypedConstructor<T extends AnyEnum = AnyEnum> extends EnumClass<T, ConstructorParameters<typeof
|
|
18
|
+
export interface EnumClassWithTypedConstructor<T extends AnyEnum = AnyEnum> extends EnumClass<T, ConstructorParameters<typeof Enum>> {
|
|
22
19
|
}
|