ddd-node 35.0.0 → 36.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.js +1 -1
- package/base/decorators/static.d.ts +2 -2
- package/base/decorators/static.js +2 -2
- package/base/meta/index.d.ts +4 -4
- package/base/meta/index.js +4 -4
- package/base/meta/model-domain.d.ts +1 -1
- package/base/meta/model-domain.js +4 -4
- package/base/meta/model-id.d.ts +2 -2
- package/base/meta/model-id.js +9 -9
- package/base/meta/model-mutable.d.ts +1 -1
- package/base/meta/model-mutable.js +4 -4
- package/base/meta/model-name.d.ts +1 -1
- package/base/meta/model-name.js +4 -4
- package/base/meta/model-property-accessor.d.ts +2 -2
- package/base/meta/model-property-accessor.js +8 -8
- package/base/meta/model-props-type.d.ts +1 -1
- package/base/meta/model-props-type.js +4 -4
- package/base/meta/model-props-validator.d.ts +2 -2
- package/base/meta/model-props-validator.js +7 -7
- package/base/meta/model-version.d.ts +1 -1
- package/base/meta/model-version.js +4 -4
- package/base/meta/static-entry.d.ts +13 -0
- package/base/meta/static-entry.js +54 -0
- package/base/model/model-descriptor.d.ts +4 -4
- package/base/model/model-descriptor.js +14 -14
- package/base/model/model.js +1 -1
- package/base/model-registry.d.ts +1 -1
- package/base/model-registry.js +4 -4
- package/common/props-validator/use-class-validator.js +1 -1
- package/core/decorators/index.d.ts +3 -3
- package/core/decorators/index.js +3 -3
- package/core/decorators/{enum/is-enum.d.ts → is-enum.d.ts} +1 -1
- package/core/decorators/{enum/is-enum.js → is-enum.js} +3 -3
- package/core/decorators/is-event.d.ts +4 -0
- package/core/decorators/{message/is-event.js → is-event.js} +2 -2
- package/core/decorators/{es-aggregate/when.js → when.js} +1 -1
- package/core/meta/enum.d.ts +2 -2
- package/core/meta/enum.js +8 -8
- package/core/meta/{es-aggregate/event-applier.d.ts → event-applier.d.ts} +3 -3
- package/core/meta/{es-aggregate/event-applier.js → event-applier.js} +9 -9
- package/core/meta/event.d.ts +1 -1
- package/core/meta/event.js +4 -4
- package/core/meta/index.d.ts +1 -2
- package/core/meta/index.js +1 -2
- package/core/model/aggregate/aggregate.d.ts +3 -8
- package/core/model/aggregate/aggregate.js +2 -11
- package/core/model/aggregate/es-aggregate.d.ts +20 -31
- package/core/model/aggregate/es-aggregate.js +36 -68
- package/core/model/aggregate/index.d.ts +0 -1
- package/core/model/aggregate/index.js +0 -1
- package/core/model/aggregate/state-aggregate.d.ts +6 -12
- package/core/model/aggregate/state-aggregate.js +11 -20
- package/core/model/entity/entity.d.ts +4 -7
- package/core/model/entity/entity.js +1 -1
- package/core/model/enum/enum.d.ts +3 -5
- package/core/model/enum/enum.js +4 -4
- package/core/model/event/event.d.ts +25 -0
- package/core/model/event/event.js +47 -0
- package/core/model/event/index.d.ts +1 -0
- package/core/{decorators/enum → model/event}/index.js +1 -1
- package/core/model/identified-model/identified-model.d.ts +3 -7
- package/core/model/identified-model/identified-model.js +2 -9
- package/core/model/index.d.ts +1 -1
- package/core/model/index.js +1 -1
- package/core/model/value-object/value-object.d.ts +5 -6
- package/core/model/value-object/value-object.js +7 -4
- package/{handling-event → event-handling}/decorators/subscribe-to-events.js +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/base/meta/model-static-values.d.ts +0 -13
- package/base/meta/model-static-values.js +0 -54
- package/core/decorators/enum/index.d.ts +0 -1
- package/core/decorators/es-aggregate/handle.d.ts +0 -2
- package/core/decorators/es-aggregate/handle.js +0 -13
- package/core/decorators/es-aggregate/index.d.ts +0 -2
- package/core/decorators/es-aggregate/index.js +0 -18
- package/core/decorators/message/index.d.ts +0 -2
- package/core/decorators/message/index.js +0 -18
- package/core/decorators/message/is-command.d.ts +0 -4
- package/core/decorators/message/is-command.js +0 -12
- package/core/decorators/message/is-event.d.ts +0 -4
- package/core/meta/command.d.ts +0 -8
- package/core/meta/command.js +0 -27
- package/core/meta/es-aggregate/command-handler.d.ts +0 -7
- package/core/meta/es-aggregate/command-handler.js +0 -44
- package/core/meta/es-aggregate/index.d.ts +0 -2
- package/core/meta/es-aggregate/index.js +0 -18
- package/core/model/aggregate/event-releaser.d.ts +0 -4
- package/core/model/aggregate/event-releaser.js +0 -2
- package/core/model/message/command.d.ts +0 -22
- package/core/model/message/command.js +0 -25
- package/core/model/message/event.d.ts +0 -30
- package/core/model/message/event.js +0 -29
- package/core/model/message/index.d.ts +0 -3
- package/core/model/message/index.js +0 -19
- package/core/model/message/message.d.ts +0 -27
- package/core/model/message/message.js +0 -59
- /package/core/decorators/{es-aggregate/when.d.ts → when.d.ts} +0 -0
- /package/{handling-event → event-handling}/decorators/index.d.ts +0 -0
- /package/{handling-event → event-handling}/decorators/index.js +0 -0
- /package/{handling-event → event-handling}/decorators/subscribe-to-events.d.ts +0 -0
- /package/{handling-event → event-handling}/event-dispatcher.d.ts +0 -0
- /package/{handling-event → event-handling}/event-dispatcher.js +0 -0
- /package/{handling-event → event-handling}/event-subscriber-registry.d.ts +0 -0
- /package/{handling-event → event-handling}/event-subscriber-registry.js +0 -0
- /package/{handling-event → event-handling}/event-subscriber.d.ts +0 -0
- /package/{handling-event → event-handling}/event-subscriber.js +0 -0
- /package/{handling-event → event-handling}/index.d.ts +0 -0
- /package/{handling-event → event-handling}/index.js +0 -0
- /package/{handling-event → event-handling}/interfaces/event-dispatcher.interface.d.ts +0 -0
- /package/{handling-event → event-handling}/interfaces/event-dispatcher.interface.js +0 -0
- /package/{handling-event → event-handling}/interfaces/event-subscriber-registry.interface.d.ts +0 -0
- /package/{handling-event → event-handling}/interfaces/event-subscriber-registry.interface.js +0 -0
- /package/{handling-event → event-handling}/interfaces/event-subscriber.interface.d.ts +0 -0
- /package/{handling-event → event-handling}/interfaces/event-subscriber.interface.js +0 -0
- /package/{handling-event → event-handling}/interfaces/index.d.ts +0 -0
- /package/{handling-event → event-handling}/interfaces/index.js +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.When = void 0;
|
|
4
|
-
const meta_1 = require("
|
|
4
|
+
const meta_1 = require("../meta");
|
|
5
5
|
const When = (eventClass) => {
|
|
6
6
|
return (target, propertyKey, descriptor) => {
|
|
7
7
|
if (typeof descriptor.value === "function") {
|
package/core/meta/enum.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export type EnumProperty<T extends Object = Object> = Extract<keyof T, string>;
|
|
|
3
3
|
export declare class EnumPropertySet<T extends Object = Object> extends Set<EnumProperty<T>> {
|
|
4
4
|
}
|
|
5
5
|
export declare const markEnumProperty: <T extends Object>(target: T, key: EnumProperty<T>) => void;
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
6
|
+
export declare const resolveOwnEnumPropertySet: <T extends Object>(target: T) => EnumPropertySet<T>;
|
|
7
|
+
export declare const resolveEnumPropertySet: <T extends Object>(target: T) => EnumPropertySet<T>;
|
package/core/meta/enum.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolveEnumPropertySet = exports.resolveOwnEnumPropertySet = exports.markEnumProperty = exports.EnumPropertySet = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
|
-
const ENUM_PROP_SET = Symbol
|
|
5
|
+
const ENUM_PROP_SET = Symbol("ENUM_PROP_SET");
|
|
6
6
|
class EnumPropertySet extends Set {
|
|
7
7
|
}
|
|
8
8
|
exports.EnumPropertySet = EnumPropertySet;
|
|
9
9
|
const markEnumProperty = (target, key) => {
|
|
10
|
-
const enumSet = (0, exports.
|
|
10
|
+
const enumSet = (0, exports.resolveOwnEnumPropertySet)(target);
|
|
11
11
|
enumSet.add(key);
|
|
12
12
|
};
|
|
13
13
|
exports.markEnumProperty = markEnumProperty;
|
|
14
|
-
const
|
|
14
|
+
const resolveOwnEnumPropertySet = (target) => {
|
|
15
15
|
if (!Reflect.getOwnMetadata(ENUM_PROP_SET, target)) {
|
|
16
16
|
Reflect.defineMetadata(ENUM_PROP_SET, new EnumPropertySet(), target);
|
|
17
17
|
}
|
|
18
18
|
return Reflect.getOwnMetadata(ENUM_PROP_SET, target);
|
|
19
19
|
};
|
|
20
|
-
exports.
|
|
21
|
-
const
|
|
20
|
+
exports.resolveOwnEnumPropertySet = resolveOwnEnumPropertySet;
|
|
21
|
+
const resolveEnumPropertySet = (target) => {
|
|
22
22
|
let _target = target;
|
|
23
23
|
const result = new EnumPropertySet();
|
|
24
24
|
do {
|
|
25
|
-
const ownMarkedEnumValues = (0, exports.
|
|
25
|
+
const ownMarkedEnumValues = (0, exports.resolveOwnEnumPropertySet)(_target);
|
|
26
26
|
ownMarkedEnumValues.forEach((markedEnumValue) => {
|
|
27
27
|
result.add(markedEnumValue);
|
|
28
28
|
});
|
|
@@ -30,4 +30,4 @@ const getEnumPropertySet = (target) => {
|
|
|
30
30
|
} while (_target !== null);
|
|
31
31
|
return result;
|
|
32
32
|
};
|
|
33
|
-
exports.
|
|
33
|
+
exports.resolveEnumPropertySet = resolveEnumPropertySet;
|
|
@@ -1,7 +1,7 @@
|
|
|
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
|
-
export declare const
|
|
5
|
+
export declare const resolveOwnEventApplierMap: (target: object) => EventApplierMap;
|
|
6
6
|
export declare const defineOwnEventApplier: <T extends AnyEvent>(target: object, eventType: string, applier: EventApplier<T>) => void;
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const resolveEventApplierMap: (target: object) => EventApplierMap;
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolveEventApplierMap = exports.defineOwnEventApplier = exports.resolveOwnEventApplierMap = exports.EventApplierMap = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
|
-
const OWN_EVENT_APPLIER_MAP = Symbol
|
|
6
|
-
const EVENT_APPLIER_MAP = Symbol
|
|
5
|
+
const OWN_EVENT_APPLIER_MAP = Symbol("OWN_EVENT_APPLIER_MAP");
|
|
6
|
+
const EVENT_APPLIER_MAP = Symbol("EVENT_HANDLER_MAP");
|
|
7
7
|
class EventApplierMap extends Map {
|
|
8
8
|
}
|
|
9
9
|
exports.EventApplierMap = EventApplierMap;
|
|
10
|
-
const
|
|
10
|
+
const resolveOwnEventApplierMap = (target) => {
|
|
11
11
|
if (!Reflect.hasOwnMetadata(OWN_EVENT_APPLIER_MAP, target))
|
|
12
12
|
Reflect.defineMetadata(OWN_EVENT_APPLIER_MAP, new EventApplierMap(), target);
|
|
13
13
|
return Reflect.getMetadata(OWN_EVENT_APPLIER_MAP, target);
|
|
14
14
|
};
|
|
15
|
-
exports.
|
|
15
|
+
exports.resolveOwnEventApplierMap = resolveOwnEventApplierMap;
|
|
16
16
|
const defineOwnEventApplier = (target, eventType, applier) => {
|
|
17
|
-
const eventAppliersMap = (0, exports.
|
|
17
|
+
const eventAppliersMap = (0, exports.resolveOwnEventApplierMap)(target);
|
|
18
18
|
eventAppliersMap.set(eventType, applier);
|
|
19
19
|
};
|
|
20
20
|
exports.defineOwnEventApplier = defineOwnEventApplier;
|
|
21
|
-
const
|
|
21
|
+
const resolveEventApplierMap = (target) => {
|
|
22
22
|
if (!Reflect.hasOwnMetadata(EVENT_APPLIER_MAP, target)) {
|
|
23
23
|
const buildEventApplierMap = (target) => {
|
|
24
24
|
let _target = target;
|
|
25
25
|
const result = new EventApplierMap();
|
|
26
26
|
const ownEventApplierMaps = [];
|
|
27
27
|
do {
|
|
28
|
-
const ownEventApplierMap = (0, exports.
|
|
28
|
+
const ownEventApplierMap = (0, exports.resolveOwnEventApplierMap)(_target);
|
|
29
29
|
ownEventApplierMaps.unshift(ownEventApplierMap);
|
|
30
30
|
_target = Reflect.getPrototypeOf(_target);
|
|
31
31
|
} while (_target !== null);
|
|
@@ -40,4 +40,4 @@ const getEventApplierMap = (target) => {
|
|
|
40
40
|
}
|
|
41
41
|
return Reflect.getOwnMetadata(EVENT_APPLIER_MAP, target);
|
|
42
42
|
};
|
|
43
|
-
exports.
|
|
43
|
+
exports.resolveEventApplierMap = resolveEventApplierMap;
|
package/core/meta/event.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export declare class $EventType extends String {
|
|
|
5
5
|
constructor(eventType: EventType);
|
|
6
6
|
}
|
|
7
7
|
export declare const defineEventType: (target: object, eventType: EventType) => void;
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const resolveEventType: (target: object) => EventType;
|
package/core/meta/event.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolveEventType = exports.defineEventType = exports.$EventType = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
|
-
const EVENT_TYPE = Symbol
|
|
5
|
+
const EVENT_TYPE = Symbol("EVENT_TYPE");
|
|
6
6
|
class $EventType extends String {
|
|
7
7
|
static validate(eventType) {
|
|
8
8
|
if (eventType.trim().length === 0)
|
|
@@ -18,10 +18,10 @@ const defineEventType = (target, eventType) => {
|
|
|
18
18
|
Reflect.defineMetadata(EVENT_TYPE, new $EventType(eventType), target);
|
|
19
19
|
};
|
|
20
20
|
exports.defineEventType = defineEventType;
|
|
21
|
-
const
|
|
21
|
+
const resolveEventType = (target) => {
|
|
22
22
|
const eventType = Reflect.getOwnMetadata(EVENT_TYPE, target);
|
|
23
23
|
if (!eventType)
|
|
24
24
|
throw new Error("Event's type is not defined");
|
|
25
25
|
return eventType.valueOf();
|
|
26
26
|
};
|
|
27
|
-
exports.
|
|
27
|
+
exports.resolveEventType = resolveEventType;
|
package/core/meta/index.d.ts
CHANGED
package/core/meta/index.js
CHANGED
|
@@ -14,7 +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("./es-aggregate"), exports);
|
|
18
17
|
__exportStar(require("./event"), exports);
|
|
19
|
-
__exportStar(require("./command"), exports);
|
|
20
18
|
__exportStar(require("./enum"), exports);
|
|
19
|
+
__exportStar(require("./event-applier"), exports);
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { Id, IdentifiedModel } from "../identified-model";
|
|
2
|
-
import {
|
|
3
|
-
import { InferredProps, Props } from "./../../../base";
|
|
4
|
-
import { IEventReleaser } from "./event-releaser";
|
|
2
|
+
import { Props } from "./../../../base";
|
|
5
3
|
export declare abstract class Aggregate<P extends Props> extends IdentifiedModel<P> {
|
|
6
|
-
|
|
7
|
-
constructor(id: Id,
|
|
4
|
+
readonly initialVersion: number;
|
|
5
|
+
constructor(id: Id, initialVersion: number, props?: P);
|
|
8
6
|
abstract get version(): number;
|
|
9
|
-
protected asEventSource(): EventSource;
|
|
10
|
-
protected newEvent<E extends AnyEvent>(eventClass: EventClassWithTypedConstructor<E>, props: InferredProps<E>, options?: NewEventOptions): E;
|
|
11
|
-
abstract releaseEvents<R = any>(eventReleaser: IEventReleaser<R>): R;
|
|
12
7
|
}
|
|
13
8
|
export type AnyAggregate = Aggregate<Props>;
|
|
@@ -13,21 +13,12 @@ exports.Aggregate = void 0;
|
|
|
13
13
|
const identified_model_1 = require("../identified-model");
|
|
14
14
|
const base_1 = require("./../../../base");
|
|
15
15
|
let Aggregate = class Aggregate extends identified_model_1.IdentifiedModel {
|
|
16
|
-
constructor(id,
|
|
16
|
+
constructor(id, initialVersion, props) {
|
|
17
17
|
super(id);
|
|
18
|
-
this.
|
|
18
|
+
this.initialVersion = initialVersion;
|
|
19
19
|
if (props)
|
|
20
20
|
this.initializeProps(props);
|
|
21
21
|
}
|
|
22
|
-
asEventSource() {
|
|
23
|
-
return {
|
|
24
|
-
aggregateId: this.id,
|
|
25
|
-
aggregateVersion: this.version,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
newEvent(eventClass, props, options) {
|
|
29
|
-
return eventClass.new(this.asEventSource(), props, options);
|
|
30
|
-
}
|
|
31
22
|
};
|
|
32
23
|
exports.Aggregate = Aggregate;
|
|
33
24
|
exports.Aggregate = Aggregate = __decorate([
|
|
@@ -1,54 +1,43 @@
|
|
|
1
|
-
import { Id } from "src";
|
|
2
1
|
import { Class } from "type-fest";
|
|
3
2
|
import { InferredProps, Props } from "../../../base";
|
|
4
3
|
import { ClassStatic } from "../../../types";
|
|
5
|
-
import {
|
|
4
|
+
import { AnyEvent, EventClassWithTypedConstructor } from "../event";
|
|
6
5
|
import { Aggregate } from "./aggregate";
|
|
7
|
-
import {
|
|
6
|
+
import { Id } from "../identified-model";
|
|
8
7
|
export declare class ESAggregate<P extends Props> extends Aggregate<P> {
|
|
9
|
-
static fromStream<T extends AnyESAggregate>(this: ESAggregateClassWithTypedConstructor<T>, id: Id,
|
|
8
|
+
static fromStream<T extends AnyESAggregate>(this: ESAggregateClassWithTypedConstructor<T>, id: Id, pastEvents: AnyEvent[]): T;
|
|
10
9
|
static newStream<T extends AnyESAggregate>(this: ESAggregateClassWithTypedConstructor<T>, id?: Id): T;
|
|
11
10
|
static fromSnapshot<T extends AnyESAggregate>(this: ESAggregateClassWithTypedConstructor<T>, snapshot: Snapshot<T>, pastEvents?: AnyEvent[]): T;
|
|
12
|
-
static
|
|
13
|
-
static
|
|
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;
|
|
11
|
+
static ownEventAppliers<T extends AnyESAggregate>(this: ESAggregateClass<T>): import("../../meta").EventApplierMap;
|
|
12
|
+
static eventAppliers<T extends AnyESAggregate>(this: ESAggregateClass<T>): import("../../meta").EventApplierMap;
|
|
17
13
|
private _pastEvents;
|
|
18
14
|
private _events;
|
|
19
|
-
|
|
20
|
-
_constructor(): ESAggregateClass<typeof this>;
|
|
15
|
+
typedConstructor(): ESAggregateClass<typeof this>;
|
|
21
16
|
get version(): number;
|
|
22
17
|
pastEvents(): AnyEvent[];
|
|
23
18
|
events(): AnyEvent[];
|
|
24
|
-
handledCommands(): AnyCommand[];
|
|
25
19
|
hasNewEvent(): boolean;
|
|
26
|
-
|
|
20
|
+
resolveEventApplier<E extends AnyEvent>(event: E): EventApplier<E>;
|
|
27
21
|
private validateEventBeforeApply;
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
getCommandHandler<C extends AnyCommand>(command: C): CommandHandler<C>;
|
|
35
|
-
handleCommand<C extends AnyCommand>(command: C): AnyEvent[];
|
|
22
|
+
private applyEvent;
|
|
23
|
+
replayPastEvent<E extends AnyEvent>(event: E): void;
|
|
24
|
+
replayPastEvents(pastEvents: AnyEvent[]): void;
|
|
25
|
+
recordEvent<E extends AnyEvent>(event: E): void;
|
|
26
|
+
recordEvent<E extends AnyEvent>(eventClass: EventClassWithTypedConstructor<E>, props: InferredProps<E>): void;
|
|
27
|
+
recordEvents(events: AnyEvent[]): void;
|
|
36
28
|
takeSnapshot(): Snapshot<typeof this>;
|
|
37
29
|
protected commitEvents(): void;
|
|
38
|
-
releaseEvents
|
|
30
|
+
releaseEvents(): AnyEvent[];
|
|
39
31
|
}
|
|
40
32
|
export type AnyESAggregate = ESAggregate<Props>;
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
export interface ESAggregateClassWithTypedConstructor<T extends AnyESAggregate = AnyESAggregate> extends ESAggregateClass<T, ConstructorParameters<typeof ESAggregate<InferredProps<T>>>> {
|
|
44
|
-
}
|
|
33
|
+
export type ESAggregateClass<T extends AnyESAggregate = AnyESAggregate, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof ESAggregate<InferredProps<T>>>;
|
|
34
|
+
export type ESAggregateClassWithTypedConstructor<T extends AnyESAggregate = AnyESAggregate> = ESAggregateClass<T, ConstructorParameters<typeof ESAggregate<InferredProps<T>>>>;
|
|
45
35
|
export type EventApplier<T extends AnyEvent = AnyEvent> = (event: T) => void;
|
|
46
|
-
export type
|
|
47
|
-
export interface SnapshotMetadata {
|
|
36
|
+
export type SnapshotMetadata = {
|
|
48
37
|
id: Id;
|
|
49
38
|
version: number;
|
|
50
|
-
}
|
|
51
|
-
export
|
|
39
|
+
};
|
|
40
|
+
export type Snapshot<T extends AnyESAggregate> = {
|
|
52
41
|
metadata: SnapshotMetadata;
|
|
53
42
|
props: InferredProps<T>;
|
|
54
|
-
}
|
|
43
|
+
};
|
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ESAggregate = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
|
-
const utils_1 = require("../../../utils");
|
|
6
5
|
const meta_1 = require("../../meta");
|
|
7
6
|
const aggregate_1 = require("./aggregate");
|
|
8
7
|
class ESAggregate extends aggregate_1.Aggregate {
|
|
9
|
-
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this._pastEvents = [];
|
|
11
|
+
this._events = [];
|
|
12
|
+
}
|
|
13
|
+
static fromStream(id, pastEvents) {
|
|
10
14
|
const instance = new this(id, 0);
|
|
11
|
-
instance.
|
|
15
|
+
instance.replayPastEvents(pastEvents);
|
|
12
16
|
return instance;
|
|
13
17
|
}
|
|
14
18
|
static newStream(id) {
|
|
@@ -17,32 +21,20 @@ class ESAggregate extends aggregate_1.Aggregate {
|
|
|
17
21
|
static fromSnapshot(snapshot, pastEvents = []) {
|
|
18
22
|
const { metadata: { id, version }, props, } = snapshot;
|
|
19
23
|
const instance = new this(id, version, props);
|
|
20
|
-
instance.
|
|
24
|
+
instance.replayPastEvents(pastEvents);
|
|
21
25
|
return instance;
|
|
22
26
|
}
|
|
23
|
-
static
|
|
24
|
-
return (0, meta_1.
|
|
25
|
-
}
|
|
26
|
-
static eventApplierMap() {
|
|
27
|
-
return (0, meta_1.getEventApplierMap)(this.prototype);
|
|
28
|
-
}
|
|
29
|
-
static ownCommandHandlerMap() {
|
|
30
|
-
return (0, meta_1.getOwnCommandHandlerMap)(this.prototype);
|
|
27
|
+
static ownEventAppliers() {
|
|
28
|
+
return (0, meta_1.resolveOwnEventApplierMap)(this.prototype);
|
|
31
29
|
}
|
|
32
|
-
static
|
|
33
|
-
return (0, meta_1.
|
|
30
|
+
static eventAppliers() {
|
|
31
|
+
return (0, meta_1.resolveEventApplierMap)(this.prototype);
|
|
34
32
|
}
|
|
35
|
-
|
|
36
|
-
super(id, version, props);
|
|
37
|
-
this._handledCommands = [];
|
|
38
|
-
this._events = [];
|
|
39
|
-
this._pastEvents = [];
|
|
40
|
-
}
|
|
41
|
-
_constructor() {
|
|
33
|
+
typedConstructor() {
|
|
42
34
|
return this.constructor;
|
|
43
35
|
}
|
|
44
36
|
get version() {
|
|
45
|
-
return this.
|
|
37
|
+
return this.initialVersion + this._pastEvents.length + this._events.length;
|
|
46
38
|
}
|
|
47
39
|
pastEvents() {
|
|
48
40
|
return Array.from(this._pastEvents);
|
|
@@ -50,76 +42,52 @@ class ESAggregate extends aggregate_1.Aggregate {
|
|
|
50
42
|
events() {
|
|
51
43
|
return Array.from(this._events);
|
|
52
44
|
}
|
|
53
|
-
handledCommands() {
|
|
54
|
-
return Array.from(this._handledCommands);
|
|
55
|
-
}
|
|
56
45
|
hasNewEvent() {
|
|
57
46
|
return Boolean(this._events.length);
|
|
58
47
|
}
|
|
59
|
-
|
|
60
|
-
const eventType = event.eventType
|
|
61
|
-
const
|
|
62
|
-
const applier =
|
|
48
|
+
resolveEventApplier(event) {
|
|
49
|
+
const eventType = event.eventType;
|
|
50
|
+
const eventAppliers = this.typedConstructor().eventAppliers();
|
|
51
|
+
const applier = eventAppliers.get(eventType);
|
|
63
52
|
if (!applier)
|
|
64
53
|
throw new Error("Event applier not found");
|
|
65
54
|
return applier;
|
|
66
55
|
}
|
|
67
56
|
validateEventBeforeApply(event) {
|
|
68
|
-
const { aggregateId,
|
|
57
|
+
const { aggregateId, streamPosition } = event;
|
|
69
58
|
if (aggregateId !== this.id)
|
|
70
59
|
throw new Error("Invalid aggregate id");
|
|
71
|
-
if (
|
|
72
|
-
throw new Error("Invalid
|
|
60
|
+
if (streamPosition !== this.version + 1)
|
|
61
|
+
throw new Error("Invalid stream position");
|
|
73
62
|
}
|
|
74
|
-
|
|
75
|
-
const applier = this.
|
|
63
|
+
applyEvent(event) {
|
|
64
|
+
const applier = this.resolveEventApplier(event);
|
|
76
65
|
this.validateEventBeforeApply(event);
|
|
77
66
|
applier.call(this, event);
|
|
78
67
|
}
|
|
79
|
-
|
|
68
|
+
replayPastEvent(event) {
|
|
80
69
|
if (this.hasNewEvent())
|
|
81
70
|
throw new Error("Cannot apply a past event when new event is recorded");
|
|
82
|
-
this.
|
|
71
|
+
this.applyEvent(event);
|
|
83
72
|
this._pastEvents.push(event);
|
|
84
73
|
}
|
|
85
|
-
|
|
74
|
+
replayPastEvents(pastEvents) {
|
|
86
75
|
pastEvents.forEach((pastEvent) => {
|
|
87
|
-
this.
|
|
76
|
+
this.replayPastEvent(pastEvent);
|
|
88
77
|
});
|
|
89
78
|
}
|
|
90
|
-
|
|
91
|
-
|
|
79
|
+
recordEvent(eventOrClass, props) {
|
|
80
|
+
const event = typeof eventOrClass === "function"
|
|
81
|
+
? eventOrClass.new(this.id, this.version + 1, props)
|
|
82
|
+
: eventOrClass;
|
|
83
|
+
this.applyEvent(event);
|
|
92
84
|
this._events.push(event);
|
|
93
85
|
}
|
|
94
|
-
|
|
86
|
+
recordEvents(events) {
|
|
95
87
|
events.forEach((event) => {
|
|
96
|
-
this.
|
|
88
|
+
this.recordEvent(event);
|
|
97
89
|
});
|
|
98
90
|
}
|
|
99
|
-
applyNewEvent(eventClass, props, options) {
|
|
100
|
-
const event = this.newEvent(eventClass, props, options);
|
|
101
|
-
this.applyEvent(event);
|
|
102
|
-
return event;
|
|
103
|
-
}
|
|
104
|
-
getCommandHandler(command) {
|
|
105
|
-
const commandType = command.commandType();
|
|
106
|
-
const commandHandlerMap = this._constructor().commandHandlerMap();
|
|
107
|
-
const handler = commandHandlerMap.get(commandType);
|
|
108
|
-
if (!handler)
|
|
109
|
-
throw new Error("Command handler not found");
|
|
110
|
-
return handler;
|
|
111
|
-
}
|
|
112
|
-
handleCommand(command) {
|
|
113
|
-
const handler = this.getCommandHandler(command);
|
|
114
|
-
const events = (0, utils_1.toArray)(handler.call(this, command));
|
|
115
|
-
events.forEach((event) => {
|
|
116
|
-
event.setCausationId(command.id);
|
|
117
|
-
event.setCorrelationIds(command.correlationIds);
|
|
118
|
-
});
|
|
119
|
-
this.applyEvents(events);
|
|
120
|
-
this._handledCommands.push(command);
|
|
121
|
-
return events;
|
|
122
|
-
}
|
|
123
91
|
takeSnapshot() {
|
|
124
92
|
if (!this.isPropsInitialized())
|
|
125
93
|
throw new Error("Cannot create snapshot when the props is not initialized");
|
|
@@ -135,10 +103,10 @@ class ESAggregate extends aggregate_1.Aggregate {
|
|
|
135
103
|
this._pastEvents.push(...this.events());
|
|
136
104
|
this._events = [];
|
|
137
105
|
}
|
|
138
|
-
releaseEvents(
|
|
106
|
+
releaseEvents() {
|
|
139
107
|
const events = this.events();
|
|
140
108
|
this.commitEvents();
|
|
141
|
-
return
|
|
109
|
+
return events;
|
|
142
110
|
}
|
|
143
111
|
}
|
|
144
112
|
exports.ESAggregate = ESAggregate;
|
|
@@ -17,5 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./aggregate"), exports);
|
|
18
18
|
__exportStar(require("./state-aggregate"), exports);
|
|
19
19
|
__exportStar(require("./es-aggregate"), exports);
|
|
20
|
-
__exportStar(require("./event-releaser"), exports);
|
|
21
20
|
__exportStar(require("./types"), exports);
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import { Class } from "type-fest";
|
|
2
2
|
import { InferredProps, Props } from "../../../base";
|
|
3
3
|
import { ClassStatic } from "../../../types";
|
|
4
|
+
import { AnyEvent, EventClass } from "../event";
|
|
4
5
|
import { Id } from "../identified-model";
|
|
5
|
-
import { AnyEvent, EventClassWithTypedConstructor, NewEventOptions } from "../message";
|
|
6
6
|
import { Aggregate } from "./aggregate";
|
|
7
|
-
import { IEventReleaser } from "./event-releaser";
|
|
8
7
|
export declare class StateAggregate<P extends Props> extends Aggregate<P> {
|
|
9
8
|
static new<T extends AnyStateAggregate>(this: StateAggregateClassWithTypedConstructor<T>, props: InferredProps<T>, id?: Id): T;
|
|
10
9
|
private _events;
|
|
11
|
-
|
|
12
|
-
_constructor(): StateAggregateClass<typeof this>;
|
|
10
|
+
typedConstructor(): StateAggregateClass<typeof this>;
|
|
13
11
|
props(): P;
|
|
14
12
|
get version(): number;
|
|
15
13
|
events(): AnyEvent[];
|
|
16
|
-
protected recordEvent<E extends AnyEvent>(
|
|
17
|
-
|
|
18
|
-
clearEvents(): void;
|
|
19
|
-
releaseEvents<R = any>(eventReleaser: IEventReleaser<R>): R;
|
|
14
|
+
protected recordEvent<E extends AnyEvent>(eventClass: EventClass<E>, props: InferredProps<E>): void;
|
|
15
|
+
clearEvents(): AnyEvent[];
|
|
20
16
|
}
|
|
21
17
|
export type AnyStateAggregate = StateAggregate<Props>;
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
export interface StateAggregateClassWithTypedConstructor<T extends AnyStateAggregate = AnyStateAggregate> extends StateAggregateClass<T, ConstructorParameters<typeof StateAggregate<InferredProps<T>>>> {
|
|
25
|
-
}
|
|
18
|
+
export type StateAggregateClass<T extends AnyStateAggregate = AnyStateAggregate, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof StateAggregate<InferredProps<T>>>;
|
|
19
|
+
export type StateAggregateClassWithTypedConstructor<T extends AnyStateAggregate = AnyStateAggregate> = StateAggregateClass<T, ConstructorParameters<typeof StateAggregate<InferredProps<T>>>>;
|
|
@@ -4,42 +4,33 @@ exports.StateAggregate = void 0;
|
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const aggregate_1 = require("./aggregate");
|
|
6
6
|
class StateAggregate extends aggregate_1.Aggregate {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this._events = [];
|
|
10
|
+
}
|
|
7
11
|
static new(props, id) {
|
|
8
12
|
return new this(id ?? (0, uuid_1.v4)(), 0, props);
|
|
9
13
|
}
|
|
10
|
-
|
|
11
|
-
super(id, version, props);
|
|
12
|
-
this._events = [];
|
|
13
|
-
}
|
|
14
|
-
_constructor() {
|
|
14
|
+
typedConstructor() {
|
|
15
15
|
return this.constructor;
|
|
16
16
|
}
|
|
17
17
|
props() {
|
|
18
18
|
return super.props();
|
|
19
19
|
}
|
|
20
20
|
get version() {
|
|
21
|
-
return this.
|
|
21
|
+
return this.initialVersion + this._events.length;
|
|
22
22
|
}
|
|
23
23
|
events() {
|
|
24
24
|
return Array.from(this._events);
|
|
25
25
|
}
|
|
26
|
-
recordEvent(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
event = this.newEvent(p1, p2, p3);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
event = p1;
|
|
33
|
-
}
|
|
34
|
-
this._events.push(event);
|
|
26
|
+
recordEvent(eventClass, props) {
|
|
27
|
+
const newEvent = eventClass.new(this.id, this.version + 1, props);
|
|
28
|
+
this._events.push(newEvent);
|
|
35
29
|
}
|
|
36
30
|
clearEvents() {
|
|
37
|
-
this._events = [];
|
|
38
|
-
}
|
|
39
|
-
releaseEvents(eventReleaser) {
|
|
40
31
|
const events = this.events();
|
|
41
|
-
this.
|
|
42
|
-
return
|
|
32
|
+
this._events = [];
|
|
33
|
+
return events;
|
|
43
34
|
}
|
|
44
35
|
}
|
|
45
36
|
exports.StateAggregate = StateAggregate;
|
|
@@ -5,12 +5,9 @@ import { Id, IdentifiedModel } from "../identified-model";
|
|
|
5
5
|
export declare class Entity<P extends Props> extends IdentifiedModel<P> {
|
|
6
6
|
static new<T extends AnyEntity>(this: EntityClassWithTypedConstructor<T>, props: InferredProps<T>, id?: Id): T;
|
|
7
7
|
constructor(id: Id, props: P);
|
|
8
|
-
|
|
8
|
+
typedConstructor(): EntityClass<typeof this>;
|
|
9
9
|
}
|
|
10
10
|
export type AnyEntity = Entity<Props>;
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
}
|
|
15
|
-
export interface EntityClassWithProps<P extends Props> extends EntityClass<Entity<P>> {
|
|
16
|
-
}
|
|
11
|
+
export type EntityClass<T extends AnyEntity = AnyEntity, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof Entity<InferredProps<T>>>;
|
|
12
|
+
export type EntityClassWithTypedConstructor<T extends AnyEntity = AnyEntity> = EntityClass<T, ConstructorParameters<typeof Entity<InferredProps<T>>>>;
|
|
13
|
+
export type EntityClassWithProps<P extends Props> = EntityClass<Entity<P>>;
|
|
@@ -6,7 +6,7 @@ export interface EnumProps {
|
|
|
6
6
|
value: EnumValue;
|
|
7
7
|
}
|
|
8
8
|
export declare class Enum extends DomainModel<EnumProps> {
|
|
9
|
-
static
|
|
9
|
+
static enumProperties<T extends AnyEnum>(this: EnumClass<T>): import("../../meta").EnumPropertySet<EnumClass<T, any[]>>;
|
|
10
10
|
static values(): Enum[];
|
|
11
11
|
static from<T extends AnyEnum>(this: EnumClass<T>, value: EnumValue): T;
|
|
12
12
|
constructor(value: EnumValue);
|
|
@@ -14,7 +14,5 @@ export declare class Enum extends DomainModel<EnumProps> {
|
|
|
14
14
|
valueOf(): EnumValue;
|
|
15
15
|
}
|
|
16
16
|
export type AnyEnum = Enum;
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
export interface EnumClassWithTypedConstructor<T extends AnyEnum = AnyEnum> extends EnumClass<T, ConstructorParameters<typeof Enum>> {
|
|
20
|
-
}
|
|
17
|
+
export type EnumClass<T extends AnyEnum = AnyEnum, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof Enum>;
|
|
18
|
+
export type EnumClassWithTypedConstructor<T extends AnyEnum = AnyEnum> = EnumClass<T, ConstructorParameters<typeof Enum>>;
|
package/core/model/enum/enum.js
CHANGED
|
@@ -13,17 +13,17 @@ exports.Enum = void 0;
|
|
|
13
13
|
const base_1 = require("../../../base");
|
|
14
14
|
const meta_1 = require("../../meta");
|
|
15
15
|
let Enum = class Enum extends base_1.DomainModel {
|
|
16
|
-
static
|
|
17
|
-
return (0, meta_1.
|
|
16
|
+
static enumProperties() {
|
|
17
|
+
return (0, meta_1.resolveEnumPropertySet)(this);
|
|
18
18
|
}
|
|
19
19
|
static values() {
|
|
20
|
-
return Array.from(this.modelDescriptor().
|
|
20
|
+
return Array.from(this.modelDescriptor().ownStaticEntries.values()).map((staticEntry) => staticEntry.value);
|
|
21
21
|
}
|
|
22
22
|
static from(value) {
|
|
23
23
|
if (!value)
|
|
24
24
|
throw new Error("Cannot parse enum without value");
|
|
25
25
|
let result;
|
|
26
|
-
this.
|
|
26
|
+
this.enumProperties().forEach((enumProperty) => {
|
|
27
27
|
const enumValue = this?.[enumProperty];
|
|
28
28
|
if (!enumValue)
|
|
29
29
|
return;
|