ddd-node 34.2.0 → 35.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/meta/model-id.js +1 -1
- package/base/meta/model-props-validator.js +1 -1
- package/base/model/model-descriptor.d.ts +11 -11
- package/base/model/model-descriptor.js +11 -11
- package/base/model/model.d.ts +7 -7
- package/base/model/model.js +9 -13
- package/base/model-registry.d.ts +1 -1
- package/base/model-registry.js +3 -3
- package/core/decorators/enum/is-enum.d.ts +2 -2
- package/core/decorators/enum/is-enum.js +4 -1
- package/core/decorators/es-aggregate/handle.js +1 -1
- package/core/decorators/es-aggregate/when.js +1 -1
- package/core/meta/{command.metadata.js → command.js} +5 -5
- package/core/meta/enum.d.ts +7 -0
- package/core/meta/enum.js +33 -0
- package/core/meta/es-aggregate/{command-handler-map.d.ts → command-handler.d.ts} +2 -3
- package/core/meta/es-aggregate/{command-handler-map.js → command-handler.js} +11 -10
- package/core/meta/es-aggregate/{event-applier-map.d.ts → event-applier.d.ts} +1 -3
- package/core/meta/es-aggregate/{event-applier-map.js → event-applier.js} +11 -11
- package/core/meta/es-aggregate/index.d.ts +2 -2
- package/core/meta/es-aggregate/index.js +2 -2
- package/core/meta/{event.metadata.js → event.js} +4 -4
- package/core/meta/index.d.ts +3 -2
- package/core/meta/index.js +3 -2
- package/core/model/aggregate/aggregate.d.ts +9 -14
- package/core/model/aggregate/aggregate.js +11 -25
- package/core/model/aggregate/es-aggregate.d.ts +13 -9
- package/core/model/aggregate/es-aggregate.js +27 -25
- package/core/model/aggregate/event-releaser.d.ts +4 -0
- package/core/model/aggregate/index.d.ts +1 -0
- package/core/model/aggregate/index.js +1 -0
- package/core/model/aggregate/state-aggregate.d.ts +9 -10
- package/core/model/aggregate/state-aggregate.js +12 -11
- package/core/model/aggregate/types.d.ts +0 -4
- package/core/model/entity/entity.d.ts +4 -6
- package/core/model/entity/entity.js +7 -7
- package/core/model/enum/enum.d.ts +1 -0
- package/core/model/enum/enum.js +12 -10
- package/core/model/identified-model/id.js +2 -0
- package/core/model/identified-model/identified-model.d.ts +16 -0
- package/core/model/identified-model/identified-model.js +21 -0
- package/core/model/identified-model/index.d.ts +2 -0
- package/core/model/{model-with-id → identified-model}/index.js +1 -1
- package/core/model/index.d.ts +1 -1
- package/core/model/index.js +1 -1
- package/core/model/message/command.d.ts +8 -6
- package/core/model/message/command.js +5 -10
- package/core/model/message/event.d.ts +8 -10
- package/core/model/message/event.js +6 -12
- package/core/model/message/message.d.ts +12 -22
- package/core/model/message/message.js +23 -34
- package/package.json +1 -1
- package/core/model/model-with-id/index.d.ts +0 -2
- package/core/model/model-with-id/model-with-id.d.ts +0 -13
- package/core/model/model-with-id/model-with-id.js +0 -23
- /package/core/meta/{command.metadata.d.ts → command.d.ts} +0 -0
- /package/core/meta/{event.metadata.d.ts → event.d.ts} +0 -0
- /package/core/model/{model-with-id/id.js → aggregate/event-releaser.js} +0 -0
- /package/core/model/{model-with-id → identified-model}/id.d.ts +0 -0
|
@@ -2,11 +2,11 @@ import { Id } from "src";
|
|
|
2
2
|
import { Class } from "type-fest";
|
|
3
3
|
import { InferredProps, Props } from "../../../base";
|
|
4
4
|
import { ClassStatic } from "../../../types";
|
|
5
|
-
import { AnyCommand, AnyEvent, EventClassWithTypedConstructor } from "../message";
|
|
6
|
-
import { Aggregate
|
|
7
|
-
import {
|
|
5
|
+
import { AnyCommand, AnyEvent, EventClassWithTypedConstructor, NewEventOptions } from "../message";
|
|
6
|
+
import { Aggregate } from "./aggregate";
|
|
7
|
+
import { IEventReleaser } from "./event-releaser";
|
|
8
8
|
export declare class ESAggregate<P extends Props> extends Aggregate<P> {
|
|
9
|
-
static fromStream<T extends AnyESAggregate>(this: ESAggregateClassWithTypedConstructor<T>,
|
|
9
|
+
static fromStream<T extends AnyESAggregate>(this: ESAggregateClassWithTypedConstructor<T>, id: Id, allPastEvents: AnyEvent[]): T;
|
|
10
10
|
static newStream<T extends AnyESAggregate>(this: ESAggregateClassWithTypedConstructor<T>, id?: Id): T;
|
|
11
11
|
static fromSnapshot<T extends AnyESAggregate>(this: ESAggregateClassWithTypedConstructor<T>, snapshot: Snapshot<T>, pastEvents?: AnyEvent[]): T;
|
|
12
12
|
static ownEventApplierMap<T extends AnyESAggregate>(this: ESAggregateClass<T>): import("src").EventApplierMap;
|
|
@@ -16,9 +16,9 @@ export declare class ESAggregate<P extends Props> extends Aggregate<P> {
|
|
|
16
16
|
private _handledCommands;
|
|
17
17
|
private _pastEvents;
|
|
18
18
|
private _events;
|
|
19
|
-
constructor(
|
|
19
|
+
constructor(id: Id, version: number, props?: P);
|
|
20
20
|
_constructor(): ESAggregateClass<typeof this>;
|
|
21
|
-
version(): number;
|
|
21
|
+
get version(): number;
|
|
22
22
|
pastEvents(): AnyEvent[];
|
|
23
23
|
events(): AnyEvent[];
|
|
24
24
|
handledCommands(): AnyCommand[];
|
|
@@ -30,12 +30,12 @@ export declare class ESAggregate<P extends Props> extends Aggregate<P> {
|
|
|
30
30
|
applyPastEvents(pastEvents: AnyEvent[]): void;
|
|
31
31
|
applyEvent<E extends AnyEvent>(event: E): void;
|
|
32
32
|
applyEvents(events: AnyEvent[]): void;
|
|
33
|
-
applyNewEvent<E extends AnyEvent>(eventClass: EventClassWithTypedConstructor<E>, props: InferredProps<E
|
|
33
|
+
applyNewEvent<E extends AnyEvent>(eventClass: EventClassWithTypedConstructor<E>, props: InferredProps<E>, options?: NewEventOptions): E;
|
|
34
34
|
getCommandHandler<C extends AnyCommand>(command: C): CommandHandler<C>;
|
|
35
35
|
handleCommand<C extends AnyCommand>(command: C): AnyEvent[];
|
|
36
36
|
takeSnapshot(): Snapshot<typeof this>;
|
|
37
37
|
protected commitEvents(): void;
|
|
38
|
-
|
|
38
|
+
releaseEvents<R = any>(releaser: IEventReleaser<R>): R;
|
|
39
39
|
}
|
|
40
40
|
export type AnyESAggregate = ESAggregate<Props>;
|
|
41
41
|
export interface ESAggregateClass<T extends AnyESAggregate = AnyESAggregate, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof ESAggregate<InferredProps<T>>> {
|
|
@@ -44,7 +44,11 @@ export interface ESAggregateClassWithTypedConstructor<T extends AnyESAggregate =
|
|
|
44
44
|
}
|
|
45
45
|
export type EventApplier<T extends AnyEvent = AnyEvent> = (event: T) => void;
|
|
46
46
|
export type CommandHandler<T extends AnyCommand = AnyCommand, U extends AnyEvent | AnyEvent[] = AnyEvent | AnyEvent[]> = (command: T) => U;
|
|
47
|
+
export interface SnapshotMetadata {
|
|
48
|
+
id: Id;
|
|
49
|
+
version: number;
|
|
50
|
+
}
|
|
47
51
|
export interface Snapshot<T extends AnyESAggregate> {
|
|
48
|
-
metadata:
|
|
52
|
+
metadata: SnapshotMetadata;
|
|
49
53
|
props: InferredProps<T>;
|
|
50
54
|
}
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ESAggregate = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
4
5
|
const utils_1 = require("../../../utils");
|
|
5
6
|
const meta_1 = require("../../meta");
|
|
6
7
|
const aggregate_1 = require("./aggregate");
|
|
7
8
|
class ESAggregate extends aggregate_1.Aggregate {
|
|
8
|
-
static fromStream(
|
|
9
|
-
const instance = new this(
|
|
10
|
-
instance.applyPastEvents(
|
|
9
|
+
static fromStream(id, allPastEvents) {
|
|
10
|
+
const instance = new this(id, 0);
|
|
11
|
+
instance.applyPastEvents(allPastEvents);
|
|
11
12
|
return instance;
|
|
12
13
|
}
|
|
13
14
|
static newStream(id) {
|
|
14
|
-
return this.fromStream(
|
|
15
|
+
return this.fromStream(id ?? (0, uuid_1.v4)(), []);
|
|
15
16
|
}
|
|
16
17
|
static fromSnapshot(snapshot, pastEvents = []) {
|
|
17
|
-
const { id, version } = snapshot
|
|
18
|
-
const
|
|
19
|
-
const instance = new this({
|
|
20
|
-
id,
|
|
21
|
-
version,
|
|
22
|
-
}, props);
|
|
18
|
+
const { metadata: { id, version }, props, } = snapshot;
|
|
19
|
+
const instance = new this(id, version, props);
|
|
23
20
|
instance.applyPastEvents(pastEvents);
|
|
24
21
|
return instance;
|
|
25
22
|
}
|
|
@@ -35,8 +32,8 @@ class ESAggregate extends aggregate_1.Aggregate {
|
|
|
35
32
|
static commandHandlerMap() {
|
|
36
33
|
return (0, meta_1.getCommandHandlerMap)(this.prototype);
|
|
37
34
|
}
|
|
38
|
-
constructor(
|
|
39
|
-
super(
|
|
35
|
+
constructor(id, version, props) {
|
|
36
|
+
super(id, version, props);
|
|
40
37
|
this._handledCommands = [];
|
|
41
38
|
this._events = [];
|
|
42
39
|
this._pastEvents = [];
|
|
@@ -44,7 +41,7 @@ class ESAggregate extends aggregate_1.Aggregate {
|
|
|
44
41
|
_constructor() {
|
|
45
42
|
return this.constructor;
|
|
46
43
|
}
|
|
47
|
-
version() {
|
|
44
|
+
get version() {
|
|
48
45
|
return this._version + this._pastEvents.length + this._events.length;
|
|
49
46
|
}
|
|
50
47
|
pastEvents() {
|
|
@@ -64,14 +61,14 @@ class ESAggregate extends aggregate_1.Aggregate {
|
|
|
64
61
|
const eventApplierMap = this._constructor().eventApplierMap();
|
|
65
62
|
const applier = eventApplierMap.get(eventType);
|
|
66
63
|
if (!applier)
|
|
67
|
-
throw new Error("
|
|
64
|
+
throw new Error("Event applier not found");
|
|
68
65
|
return applier;
|
|
69
66
|
}
|
|
70
67
|
validateEventBeforeApply(event) {
|
|
71
68
|
const { aggregateId, aggregateVersion } = event.source();
|
|
72
|
-
if (aggregateId !== this.
|
|
69
|
+
if (aggregateId !== this.id)
|
|
73
70
|
throw new Error("Invalid aggregate id");
|
|
74
|
-
if (aggregateVersion !== this.version
|
|
71
|
+
if (aggregateVersion !== this.version)
|
|
75
72
|
throw new Error("Invalid aggregate version");
|
|
76
73
|
}
|
|
77
74
|
_applyEvent(event) {
|
|
@@ -99,33 +96,38 @@ class ESAggregate extends aggregate_1.Aggregate {
|
|
|
99
96
|
this.applyEvent(event);
|
|
100
97
|
});
|
|
101
98
|
}
|
|
102
|
-
applyNewEvent(eventClass, props) {
|
|
103
|
-
this.
|
|
99
|
+
applyNewEvent(eventClass, props, options) {
|
|
100
|
+
const event = this.newEvent(eventClass, props, options);
|
|
101
|
+
this.applyEvent(event);
|
|
102
|
+
return event;
|
|
104
103
|
}
|
|
105
104
|
getCommandHandler(command) {
|
|
106
105
|
const commandType = command.commandType();
|
|
107
106
|
const commandHandlerMap = this._constructor().commandHandlerMap();
|
|
108
107
|
const handler = commandHandlerMap.get(commandType);
|
|
109
108
|
if (!handler)
|
|
110
|
-
throw new Error("
|
|
109
|
+
throw new Error("Command handler not found");
|
|
111
110
|
return handler;
|
|
112
111
|
}
|
|
113
112
|
handleCommand(command) {
|
|
114
113
|
const handler = this.getCommandHandler(command);
|
|
115
114
|
const events = (0, utils_1.toArray)(handler.call(this, command));
|
|
116
115
|
events.forEach((event) => {
|
|
117
|
-
event.setCausationId(command.id
|
|
118
|
-
event.setCorrelationIds(command.correlationIds
|
|
116
|
+
event.setCausationId(command.id);
|
|
117
|
+
event.setCorrelationIds(command.correlationIds);
|
|
119
118
|
});
|
|
120
119
|
this.applyEvents(events);
|
|
121
120
|
this._handledCommands.push(command);
|
|
122
121
|
return events;
|
|
123
122
|
}
|
|
124
123
|
takeSnapshot() {
|
|
125
|
-
if (this.
|
|
124
|
+
if (!this.isPropsInitialized())
|
|
126
125
|
throw new Error("Cannot create snapshot when the props is not initialized");
|
|
127
126
|
return {
|
|
128
|
-
metadata:
|
|
127
|
+
metadata: {
|
|
128
|
+
id: this.id,
|
|
129
|
+
version: this.version,
|
|
130
|
+
},
|
|
129
131
|
props: this.props(),
|
|
130
132
|
};
|
|
131
133
|
}
|
|
@@ -133,10 +135,10 @@ class ESAggregate extends aggregate_1.Aggregate {
|
|
|
133
135
|
this._pastEvents.push(...this.events());
|
|
134
136
|
this._events = [];
|
|
135
137
|
}
|
|
136
|
-
|
|
138
|
+
releaseEvents(releaser) {
|
|
137
139
|
const events = this.events();
|
|
138
140
|
this.commitEvents();
|
|
139
|
-
return
|
|
141
|
+
return releaser.release(events);
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
exports.ESAggregate = ESAggregate;
|
|
@@ -17,4 +17,5 @@ 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);
|
|
20
21
|
__exportStar(require("./types"), exports);
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { Class } from "type-fest";
|
|
2
2
|
import { InferredProps, Props } from "../../../base";
|
|
3
3
|
import { ClassStatic } from "../../../types";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
}
|
|
4
|
+
import { Id } from "../identified-model";
|
|
5
|
+
import { AnyEvent, EventClassWithTypedConstructor, NewEventOptions } from "../message";
|
|
6
|
+
import { Aggregate } from "./aggregate";
|
|
7
|
+
import { IEventReleaser } from "./event-releaser";
|
|
9
8
|
export declare class StateAggregate<P extends Props> extends Aggregate<P> {
|
|
10
|
-
static
|
|
9
|
+
static new<T extends AnyStateAggregate>(this: StateAggregateClassWithTypedConstructor<T>, props: InferredProps<T>, id?: Id): T;
|
|
11
10
|
private _events;
|
|
12
|
-
constructor(
|
|
11
|
+
constructor(id: Id, version: number, props: P);
|
|
13
12
|
_constructor(): StateAggregateClass<typeof this>;
|
|
14
13
|
props(): P;
|
|
15
|
-
version(): number;
|
|
14
|
+
get version(): number;
|
|
16
15
|
events(): AnyEvent[];
|
|
17
16
|
protected recordEvent<E extends AnyEvent>(event: E): void;
|
|
18
|
-
protected recordEvent<E extends AnyEvent>(eventClass: EventClassWithTypedConstructor<E>, props: InferredProps<E
|
|
17
|
+
protected recordEvent<E extends AnyEvent>(eventClass: EventClassWithTypedConstructor<E>, props: InferredProps<E>, options?: NewEventOptions): void;
|
|
19
18
|
clearEvents(): void;
|
|
20
|
-
|
|
19
|
+
releaseEvents<R = any>(eventReleaser: IEventReleaser<R>): R;
|
|
21
20
|
}
|
|
22
21
|
export type AnyStateAggregate = StateAggregate<Props>;
|
|
23
22
|
export interface StateAggregateClass<T extends AnyStateAggregate = AnyStateAggregate, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof StateAggregate<InferredProps<T>>> {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StateAggregate = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
4
5
|
const aggregate_1 = require("./aggregate");
|
|
5
6
|
class StateAggregate extends aggregate_1.Aggregate {
|
|
6
|
-
static
|
|
7
|
-
return new this(
|
|
7
|
+
static new(props, id) {
|
|
8
|
+
return new this(id ?? (0, uuid_1.v4)(), 0, props);
|
|
8
9
|
}
|
|
9
|
-
constructor(
|
|
10
|
-
super(
|
|
10
|
+
constructor(id, version, props) {
|
|
11
|
+
super(id, version, props);
|
|
11
12
|
this._events = [];
|
|
12
13
|
}
|
|
13
14
|
_constructor() {
|
|
@@ -16,29 +17,29 @@ class StateAggregate extends aggregate_1.Aggregate {
|
|
|
16
17
|
props() {
|
|
17
18
|
return super.props();
|
|
18
19
|
}
|
|
19
|
-
version() {
|
|
20
|
+
get version() {
|
|
20
21
|
return this._version;
|
|
21
22
|
}
|
|
22
23
|
events() {
|
|
23
24
|
return Array.from(this._events);
|
|
24
25
|
}
|
|
25
|
-
recordEvent(
|
|
26
|
+
recordEvent(p1, p2, p3) {
|
|
26
27
|
let event;
|
|
27
|
-
if (typeof
|
|
28
|
-
event = this.newEvent(
|
|
28
|
+
if (typeof p1 === "function" && p2) {
|
|
29
|
+
event = this.newEvent(p1, p2, p3);
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
31
|
-
event =
|
|
32
|
+
event = p1;
|
|
32
33
|
}
|
|
33
34
|
this._events.push(event);
|
|
34
35
|
}
|
|
35
36
|
clearEvents() {
|
|
36
37
|
this._events = [];
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
releaseEvents(eventReleaser) {
|
|
39
40
|
const events = this.events();
|
|
40
41
|
this.clearEvents();
|
|
41
|
-
return
|
|
42
|
+
return eventReleaser.release(events);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
exports.StateAggregate = StateAggregate;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
import { ESAggregateClass } from "./es-aggregate";
|
|
2
2
|
import { StateAggregateClass } from "./state-aggregate";
|
|
3
|
-
import { AnyEvent } from "../message";
|
|
4
3
|
export type AggregateClass = StateAggregateClass | ESAggregateClass;
|
|
5
|
-
export interface IAggregateEventPublisher<R = any> {
|
|
6
|
-
publish(events: AnyEvent | AnyEvent[]): R;
|
|
7
|
-
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Class } from "type-fest";
|
|
2
2
|
import { InferredProps, Props } from "../../../base";
|
|
3
3
|
import { ClassStatic } from "../../../types";
|
|
4
|
-
import { Id,
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
static build<T extends AnyEntity>(this: EntityClassWithTypedConstructor<T>, props: InferredProps<T>, id?: Id): T;
|
|
9
|
-
constructor(metadata: EntityMetadata, props: P);
|
|
4
|
+
import { Id, IdentifiedModel } from "../identified-model";
|
|
5
|
+
export declare class Entity<P extends Props> extends IdentifiedModel<P> {
|
|
6
|
+
static new<T extends AnyEntity>(this: EntityClassWithTypedConstructor<T>, props: InferredProps<T>, id?: Id): T;
|
|
7
|
+
constructor(id: Id, props: P);
|
|
10
8
|
_constructor(): EntityClass<typeof this>;
|
|
11
9
|
}
|
|
12
10
|
export type AnyEntity = Entity<Props>;
|
|
@@ -12,13 +12,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.Entity = void 0;
|
|
13
13
|
const uuid_1 = require("uuid");
|
|
14
14
|
const base_1 = require("../../../base");
|
|
15
|
-
const
|
|
16
|
-
let Entity = class Entity extends
|
|
17
|
-
static
|
|
18
|
-
return new this(
|
|
15
|
+
const identified_model_1 = require("../identified-model");
|
|
16
|
+
let Entity = class Entity extends identified_model_1.IdentifiedModel {
|
|
17
|
+
static new(props, id) {
|
|
18
|
+
return new this(id ?? (0, uuid_1.v4)(), props);
|
|
19
19
|
}
|
|
20
|
-
constructor(
|
|
21
|
-
super(
|
|
20
|
+
constructor(id, props) {
|
|
21
|
+
super(id);
|
|
22
22
|
this.initializeProps(props);
|
|
23
23
|
}
|
|
24
24
|
_constructor() {
|
|
@@ -28,5 +28,5 @@ let Entity = class Entity extends model_with_id_1.ModelWithId {
|
|
|
28
28
|
exports.Entity = Entity;
|
|
29
29
|
exports.Entity = Entity = __decorate([
|
|
30
30
|
(0, base_1.Mutable)(true),
|
|
31
|
-
__metadata("design:paramtypes", [
|
|
31
|
+
__metadata("design:paramtypes", [String, Object])
|
|
32
32
|
], Entity);
|
|
@@ -6,6 +6,7 @@ export interface EnumProps {
|
|
|
6
6
|
value: EnumValue;
|
|
7
7
|
}
|
|
8
8
|
export declare class Enum extends DomainModel<EnumProps> {
|
|
9
|
+
static enumPropertySet<T extends AnyEnum>(this: EnumClass<T>): import("../../meta").EnumPropertySet<EnumClass<T, any[]>>;
|
|
9
10
|
static values(): Enum[];
|
|
10
11
|
static from<T extends AnyEnum>(this: EnumClass<T>, value: EnumValue): T;
|
|
11
12
|
constructor(value: EnumValue);
|
package/core/model/enum/enum.js
CHANGED
|
@@ -11,26 +11,28 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Enum = void 0;
|
|
13
13
|
const base_1 = require("../../../base");
|
|
14
|
+
const meta_1 = require("../../meta");
|
|
14
15
|
let Enum = class Enum extends base_1.DomainModel {
|
|
16
|
+
static enumPropertySet() {
|
|
17
|
+
return (0, meta_1.getEnumPropertySet)(this);
|
|
18
|
+
}
|
|
15
19
|
static values() {
|
|
16
|
-
return Array.from(this.modelDescriptor().ownModelStaticValues
|
|
20
|
+
return Array.from(this.modelDescriptor().ownModelStaticValues.values()).map((staticValue) => staticValue.value);
|
|
17
21
|
}
|
|
18
22
|
static from(value) {
|
|
19
23
|
if (!value)
|
|
20
24
|
throw new Error("Cannot parse enum without value");
|
|
21
25
|
let result;
|
|
22
|
-
this.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
result = staticEnum;
|
|
29
|
-
}
|
|
26
|
+
this.enumPropertySet().forEach((enumProperty) => {
|
|
27
|
+
const enumValue = this?.[enumProperty];
|
|
28
|
+
if (!enumValue)
|
|
29
|
+
return;
|
|
30
|
+
if (enumValue.value === value && !result) {
|
|
31
|
+
result = enumValue;
|
|
30
32
|
}
|
|
31
33
|
});
|
|
32
34
|
if (!result)
|
|
33
|
-
throw new Error(`Invalid provided value for enum ${this.modelDescriptor().modelName
|
|
35
|
+
throw new Error(`Invalid provided value for enum ${this.modelDescriptor().modelName}`);
|
|
34
36
|
return result;
|
|
35
37
|
}
|
|
36
38
|
constructor(value) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Class } from "type-fest";
|
|
2
|
+
import { DomainModel, InferredProps, Props } from "../../../base";
|
|
3
|
+
import { ClassStatic } from "../../../types";
|
|
4
|
+
import { Id } from "./id";
|
|
5
|
+
export declare class IdentifiedModel<P extends Props> extends DomainModel<P> {
|
|
6
|
+
private _id;
|
|
7
|
+
constructor(id: Id);
|
|
8
|
+
get id(): string;
|
|
9
|
+
setId(id: Id): void;
|
|
10
|
+
hasId(id: Id): boolean;
|
|
11
|
+
}
|
|
12
|
+
export type AnyIdentifiedModel = IdentifiedModel<Props>;
|
|
13
|
+
export interface IdentifiedModelClass<T extends AnyIdentifiedModel = AnyIdentifiedModel, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof IdentifiedModel<InferredProps<T>>> {
|
|
14
|
+
}
|
|
15
|
+
export interface IdentifiedModelClassWithTypedConstructor<T extends AnyIdentifiedModel = AnyIdentifiedModel> extends IdentifiedModelClass<T, ConstructorParameters<typeof IdentifiedModel<InferredProps<T>>>> {
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IdentifiedModel = void 0;
|
|
4
|
+
const base_1 = require("../../../base");
|
|
5
|
+
class IdentifiedModel extends base_1.DomainModel {
|
|
6
|
+
constructor(id) {
|
|
7
|
+
super();
|
|
8
|
+
if (id)
|
|
9
|
+
this.setId(id);
|
|
10
|
+
}
|
|
11
|
+
get id() {
|
|
12
|
+
return this._id;
|
|
13
|
+
}
|
|
14
|
+
setId(id) {
|
|
15
|
+
this._id = id;
|
|
16
|
+
}
|
|
17
|
+
hasId(id) {
|
|
18
|
+
return this._id === id;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.IdentifiedModel = IdentifiedModel;
|
|
@@ -15,4 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./id"), exports);
|
|
18
|
-
__exportStar(require("./model
|
|
18
|
+
__exportStar(require("./identified-model"), exports);
|
package/core/model/index.d.ts
CHANGED
package/core/model/index.js
CHANGED
|
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./value-object"), exports);
|
|
18
18
|
__exportStar(require("./enum"), exports);
|
|
19
|
-
__exportStar(require("./model
|
|
19
|
+
__exportStar(require("./identified-model"), exports);
|
|
20
20
|
__exportStar(require("./entity"), exports);
|
|
21
21
|
__exportStar(require("./aggregate"), exports);
|
|
22
22
|
__exportStar(require("./message"), exports);
|
|
@@ -2,17 +2,19 @@ import { Class } from "type-fest";
|
|
|
2
2
|
import { InferredProps, Props } from "../../../base";
|
|
3
3
|
import { ClassStatic } from "../../../types";
|
|
4
4
|
import { CommandType } from "../../meta";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { Id } from "../identified-model";
|
|
6
|
+
import { CausationId, CorrelationIds, Message, MessageClass } from "./message";
|
|
7
|
+
export interface NewCommandOptions {
|
|
8
|
+
id?: Id;
|
|
9
|
+
causationId?: CausationId;
|
|
10
|
+
correlationIds?: CorrelationIds;
|
|
8
11
|
}
|
|
9
12
|
export declare class Command<P extends Props> extends Message<P> {
|
|
10
|
-
static
|
|
13
|
+
static new<T extends AnyCommand>(this: CommandClassWithTypedConstructor<T>, props: InferredProps<T>, options?: NewCommandOptions): T;
|
|
11
14
|
static commandType<T extends AnyCommand>(this: CommandClass<T>): string;
|
|
12
15
|
protected readonly _commandType: CommandType;
|
|
13
|
-
constructor(
|
|
16
|
+
constructor(id: Id, timestamp: number, props: P, causationId?: Id, correlationIds?: CorrelationIds);
|
|
14
17
|
_constructor(): CommandClass<typeof this>;
|
|
15
|
-
metadata(): CommandMetadata;
|
|
16
18
|
commandType(): string;
|
|
17
19
|
}
|
|
18
20
|
export type AnyCommand = Command<Props>;
|
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Command = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
4
5
|
const meta_1 = require("../../meta");
|
|
5
6
|
const message_1 = require("./message");
|
|
6
7
|
class Command extends message_1.Message {
|
|
7
|
-
static
|
|
8
|
-
return new this(
|
|
8
|
+
static new(props, options) {
|
|
9
|
+
return new this(options?.id ?? (0, uuid_1.v4)(), Date.now(), props, options?.causationId, options?.correlationIds);
|
|
9
10
|
}
|
|
10
11
|
static commandType() {
|
|
11
12
|
return (0, meta_1.getCommandType)(this);
|
|
12
13
|
}
|
|
13
|
-
constructor(
|
|
14
|
-
super(
|
|
14
|
+
constructor(id, timestamp, props, causationId, correlationIds) {
|
|
15
|
+
super(id, timestamp, props, causationId, correlationIds);
|
|
15
16
|
this._commandType = this._constructor().commandType();
|
|
16
17
|
}
|
|
17
18
|
_constructor() {
|
|
18
19
|
return this.constructor;
|
|
19
20
|
}
|
|
20
|
-
metadata() {
|
|
21
|
-
return {
|
|
22
|
-
...super.metadata(),
|
|
23
|
-
commandType: this._commandType,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
21
|
commandType() {
|
|
27
22
|
return this._commandType;
|
|
28
23
|
}
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
import { Class } from "type-fest";
|
|
2
2
|
import { InferredProps, Props } from "../../../base";
|
|
3
3
|
import { ClassStatic } from "../../../types";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { Message, MessageClass, MessageMetadata, MessageMetadataInput } from "./message";
|
|
4
|
+
import { Id } from "../identified-model";
|
|
5
|
+
import { CausationId, CorrelationIds, Message, MessageClass } from "./message";
|
|
7
6
|
export type EventSource = Readonly<{
|
|
8
7
|
aggregateId: Id;
|
|
9
8
|
aggregateVersion: number;
|
|
10
9
|
}>;
|
|
11
|
-
export interface
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
export interface NewEventOptions {
|
|
11
|
+
id?: Id;
|
|
12
|
+
causationId?: CausationId;
|
|
13
|
+
correlationIds?: CorrelationIds;
|
|
14
14
|
}
|
|
15
|
-
export type EventMetadataInput = MessageMetadataInput & Pick<EventMetadata, "source">;
|
|
16
15
|
export declare class Event<P extends Props> extends Message<P> {
|
|
17
|
-
static
|
|
16
|
+
static new<T extends AnyEvent>(this: EventClassWithTypedConstructor<T>, eventSource: EventSource, props: InferredProps<T>, options?: NewEventOptions): T;
|
|
18
17
|
static eventType<T extends AnyEvent>(this: EventClass<T>): string;
|
|
19
18
|
private readonly _eventType;
|
|
20
19
|
private readonly _source;
|
|
21
|
-
constructor(
|
|
20
|
+
constructor(id: Id, timestamp: number, eventSource: EventSource, props: P, causationId?: string, correlationIds?: CorrelationIds);
|
|
22
21
|
_constructor(): EventClass<typeof this>;
|
|
23
|
-
metadata(): EventMetadata;
|
|
24
22
|
eventType(): string;
|
|
25
23
|
source(): Readonly<{
|
|
26
24
|
aggregateId: Id;
|
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Event = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
4
5
|
const meta_1 = require("../../meta");
|
|
5
6
|
const message_1 = require("./message");
|
|
6
7
|
class Event extends message_1.Message {
|
|
7
|
-
static
|
|
8
|
-
return new this(
|
|
8
|
+
static new(eventSource, props, options) {
|
|
9
|
+
return new this(options?.id ?? (0, uuid_1.v4)(), Date.now(), eventSource, props, options?.causationId, options?.correlationIds);
|
|
9
10
|
}
|
|
10
11
|
static eventType() {
|
|
11
12
|
return (0, meta_1.getEventType)(this);
|
|
12
13
|
}
|
|
13
|
-
constructor(
|
|
14
|
-
super(
|
|
14
|
+
constructor(id, timestamp, eventSource, props, causationId, correlationIds) {
|
|
15
|
+
super(id, timestamp, props, causationId, correlationIds);
|
|
15
16
|
this._eventType = this._constructor().eventType();
|
|
16
|
-
this._source =
|
|
17
|
+
this._source = eventSource;
|
|
17
18
|
}
|
|
18
19
|
_constructor() {
|
|
19
20
|
return this.constructor;
|
|
20
21
|
}
|
|
21
|
-
metadata() {
|
|
22
|
-
return {
|
|
23
|
-
...super.metadata(),
|
|
24
|
-
eventType: this._eventType,
|
|
25
|
-
source: this._source,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
22
|
eventType() {
|
|
29
23
|
return this._eventType;
|
|
30
24
|
}
|