ddd-node 9.1.0 → 12.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +17 -0
- package/dist/core/aggregate.d.ts +14 -15
- package/dist/core/aggregate.js +18 -18
- package/dist/core/entity.d.ts +9 -11
- package/dist/core/entity.js +10 -12
- package/dist/core/error.js +1 -1
- package/dist/core/id/built/index.d.ts +2 -0
- package/dist/core/id/built/index.js +18 -0
- package/dist/core/id/built/snowflake.generator.d.ts +8 -0
- package/dist/core/id/built/snowflake.generator.js +16 -0
- package/dist/core/id/built/uuid4.generator.d.ts +5 -0
- package/dist/core/id/built/uuid4.generator.js +16 -0
- package/dist/core/id/id-generator.d.ts +8 -0
- package/dist/core/id/id-generator.js +17 -0
- package/dist/core/id/id.d.ts +6 -0
- package/dist/core/id/id.js +15 -0
- package/dist/core/id/index.d.ts +3 -0
- package/dist/core/id/index.js +19 -0
- package/dist/core/index.d.ts +0 -5
- package/dist/core/index.js +0 -5
- package/dist/core/{command.d.ts → message/command.d.ts} +8 -8
- package/dist/core/{command.js → message/command.js} +3 -3
- package/dist/core/{event.d.ts → message/event.d.ts} +12 -12
- package/dist/core/{event.js → message/event.js} +6 -3
- package/dist/core/message/index.d.ts +3 -0
- package/dist/core/message/index.js +19 -0
- package/dist/core/{message.d.ts → message/message.d.ts} +3 -5
- package/dist/core/{message.js → message/message.js} +6 -9
- package/dist/core/metadata/aggregate.metadata.d.ts +9 -0
- package/dist/core/metadata/aggregate.metadata.js +29 -0
- package/dist/core/metadata/id.metadata.d.ts +4 -0
- package/dist/core/metadata/id.metadata.js +12 -0
- package/dist/core/metadata/index.d.ts +3 -0
- package/dist/core/metadata/index.js +19 -0
- package/dist/core/metadata/model.metadata.d.ts +13 -0
- package/dist/core/metadata/model.metadata.js +55 -0
- package/dist/core/model/index.d.ts +2 -0
- package/dist/core/model/index.js +18 -0
- package/dist/core/model/model-with-id.d.ts +12 -0
- package/dist/core/model/model-with-id.js +29 -0
- package/dist/core/model/model.d.ts +25 -0
- package/dist/core/model/model.js +89 -0
- package/dist/core/value-object.d.ts +7 -6
- package/dist/core/value-object.js +5 -4
- package/dist/decorators/aggregate.d.ts +3 -6
- package/dist/decorators/aggregate.js +10 -17
- package/dist/decorators/id.d.ts +2 -2
- package/dist/decorators/id.js +5 -6
- package/dist/decorators/index.d.ts +0 -4
- package/dist/decorators/index.js +0 -4
- package/dist/decorators/model.d.ts +12 -3
- package/dist/decorators/model.js +38 -7
- package/dist/decorators/type.d.ts +2 -0
- package/dist/decorators/type.js +2 -0
- package/dist/types/class-static.d.ts +2 -2
- package/dist/types/class.d.ts +2 -4
- package/package.json +3 -1
- package/tsconfig.json +4 -4
- package/dist/core/id.d.ts +0 -17
- package/dist/core/id.js +0 -40
- package/dist/core/metadata.d.ts +0 -18
- package/dist/core/metadata.js +0 -53
- package/dist/core/model-type.d.ts +0 -86
- package/dist/core/model-type.js +0 -55
- package/dist/core/model-with-id.d.ts +0 -6
- package/dist/core/model-with-id.js +0 -16
- package/dist/core/model.d.ts +0 -15
- package/dist/core/model.js +0 -34
- package/dist/core/registry.d.ts +0 -12
- package/dist/core/registry.js +0 -28
- package/dist/decorators/command.d.ts +0 -2
- package/dist/decorators/command.js +0 -10
- package/dist/decorators/entity.d.ts +0 -2
- package/dist/decorators/entity.js +0 -10
- package/dist/decorators/event.d.ts +0 -2
- package/dist/decorators/event.js +0 -10
- package/dist/decorators/value-object.d.ts +0 -2
- package/dist/decorators/value-object.js +0 -10
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"type": "node",
|
|
9
|
+
"request": "launch",
|
|
10
|
+
"name": "Launch Program",
|
|
11
|
+
"skipFiles": ["<node_internals>/**"],
|
|
12
|
+
"program": "${workspaceFolder}/test/example/main.ts",
|
|
13
|
+
"preLaunchTask": "tsc: build - tsconfig.json",
|
|
14
|
+
"outFiles": ["${workspaceFolder}/**/*.js"]
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
package/dist/core/aggregate.d.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Entity, EntityMetadata } from "./entity";
|
|
5
|
-
import { AnyEvent, EventClass, EventClassWithTypedConstructor } from "./event";
|
|
1
|
+
import { ClassStatic } from "../types/index";
|
|
2
|
+
import { Class } from "type-fest";
|
|
3
|
+
import { EntityBase, EntityMetadata } from "./entity";
|
|
6
4
|
import { Id } from "./id";
|
|
7
|
-
import {
|
|
5
|
+
import { AnyCommand, AnyEvent, EventClass, EventClassWithTypedConstructor } from "./message";
|
|
6
|
+
import { PropsOf } from "./model/model";
|
|
8
7
|
export interface AggregateBaseMetadata extends EntityMetadata {
|
|
9
8
|
version: number;
|
|
10
9
|
}
|
|
11
|
-
export declare abstract class
|
|
10
|
+
export declare abstract class AggregateCore<Props extends object> extends EntityBase<Props> {
|
|
12
11
|
protected readonly _version: number;
|
|
13
12
|
constructor(metadata: AggregateBaseMetadata, props?: Props);
|
|
14
13
|
abstract getVersion(): number;
|
|
15
14
|
protected newEvent<E extends AnyEvent>(eventClass: EventClassWithTypedConstructor<E>, props: PropsOf<E>): E;
|
|
16
15
|
}
|
|
17
|
-
export declare class
|
|
16
|
+
export declare abstract class AggregateBase<Props extends object> extends AggregateCore<Props> {
|
|
18
17
|
private _events;
|
|
19
18
|
constructor(metadata: AggregateBaseMetadata, props: Props);
|
|
20
19
|
static newAggregate<T extends AnyAggregate>(this: AggregateClassWithTypedConstructor<T>, props: PropsOf<T>, id?: Id): T;
|
|
@@ -30,7 +29,7 @@ export interface Snapshot<T extends AnyAggregateES> {
|
|
|
30
29
|
metadata: SnapshotMetadata;
|
|
31
30
|
props: PropsOf<T>;
|
|
32
31
|
}
|
|
33
|
-
export declare class
|
|
32
|
+
export declare abstract class AggregateESBase<Props extends object> extends AggregateCore<Props> {
|
|
34
33
|
private _handledCommands;
|
|
35
34
|
private _pastEvents;
|
|
36
35
|
private _events;
|
|
@@ -58,11 +57,11 @@ export declare class AggregateES<Props extends object> extends AggregateBase<Pro
|
|
|
58
57
|
handleCommand<C extends AnyCommand>(command: C): AnyEvent[];
|
|
59
58
|
snap(): Snapshot<this>;
|
|
60
59
|
}
|
|
61
|
-
export type AnyAggregate =
|
|
62
|
-
export type AggregateClass<T extends AnyAggregate = AnyAggregate, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof
|
|
63
|
-
export type AggregateClassWithTypedConstructor<T extends AnyAggregate = AnyAggregate> = AggregateClass<T, ConstructorParameters<typeof
|
|
64
|
-
export type AnyAggregateES =
|
|
65
|
-
export type AggregateESClass<T extends AnyAggregateES = AnyAggregateES, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof
|
|
66
|
-
export type AggregateESClassWithTypedConstructor<T extends AnyAggregateES = AnyAggregateES> = AggregateESClass<T, ConstructorParameters<typeof
|
|
60
|
+
export type AnyAggregate = AggregateBase<any>;
|
|
61
|
+
export type AggregateClass<T extends AnyAggregate = AnyAggregate, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof AggregateBase<PropsOf<T>>>;
|
|
62
|
+
export type AggregateClassWithTypedConstructor<T extends AnyAggregate = AnyAggregate> = AggregateClass<T, ConstructorParameters<typeof AggregateBase<PropsOf<T>>>>;
|
|
63
|
+
export type AnyAggregateES = AggregateESBase<any>;
|
|
64
|
+
export type AggregateESClass<T extends AnyAggregateES = AnyAggregateES, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof AggregateESBase<PropsOf<T>>>;
|
|
65
|
+
export type AggregateESClassWithTypedConstructor<T extends AnyAggregateES = AnyAggregateES> = AggregateESClass<T, ConstructorParameters<typeof AggregateESBase<PropsOf<T>>>>;
|
|
67
66
|
export type EventApplier<T extends AnyEvent = AnyEvent> = (event: T) => void;
|
|
68
67
|
export type CommandHandler<T extends AnyCommand = AnyCommand, U extends AnyEvent | AnyEvent[] = AnyEvent> = (command: T) => U;
|
package/dist/core/aggregate.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.AggregateESBase = exports.AggregateBase = exports.AggregateCore = void 0;
|
|
4
|
+
const _utils_1 = require("../utils/index");
|
|
5
5
|
const entity_1 = require("./entity");
|
|
6
|
-
const
|
|
7
|
-
class
|
|
6
|
+
const aggregate_metadata_1 = require("./metadata/aggregate.metadata");
|
|
7
|
+
class AggregateCore extends entity_1.EntityBase {
|
|
8
8
|
constructor(metadata, props) {
|
|
9
9
|
super(metadata, props);
|
|
10
10
|
this._version = metadata.version;
|
|
11
11
|
}
|
|
12
12
|
newEvent(eventClass, props) {
|
|
13
13
|
const eventSource = {
|
|
14
|
-
|
|
14
|
+
aggregate: this.modelName(),
|
|
15
15
|
id: this.getId(),
|
|
16
16
|
version: this.getVersion(),
|
|
17
17
|
};
|
|
18
18
|
return eventClass.newEvent(eventSource, props);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
exports.
|
|
22
|
-
class
|
|
21
|
+
exports.AggregateCore = AggregateCore;
|
|
22
|
+
class AggregateBase extends AggregateCore {
|
|
23
23
|
constructor(metadata, props) {
|
|
24
24
|
super(metadata, props);
|
|
25
25
|
this._events = [];
|
|
@@ -50,8 +50,8 @@ class Aggregate extends AggregateBase {
|
|
|
50
50
|
this._events = [];
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
exports.
|
|
54
|
-
class
|
|
53
|
+
exports.AggregateBase = AggregateBase;
|
|
54
|
+
class AggregateESBase extends AggregateCore {
|
|
55
55
|
constructor(metadata, props) {
|
|
56
56
|
super(metadata, props);
|
|
57
57
|
this._handledCommands = [];
|
|
@@ -76,10 +76,10 @@ class AggregateES extends AggregateBase {
|
|
|
76
76
|
return instance;
|
|
77
77
|
}
|
|
78
78
|
static eventAppliersMap() {
|
|
79
|
-
return (0,
|
|
79
|
+
return (0, aggregate_metadata_1.getEventAppliersMap)(this.prototype);
|
|
80
80
|
}
|
|
81
81
|
static commandHandlersMap() {
|
|
82
|
-
return (0,
|
|
82
|
+
return (0, aggregate_metadata_1.getCommandHandlersMap)(this.prototype);
|
|
83
83
|
}
|
|
84
84
|
getVersion() {
|
|
85
85
|
return this._version + this._pastEvents.length + this._events.length;
|
|
@@ -100,15 +100,15 @@ class AggregateES extends AggregateBase {
|
|
|
100
100
|
return Boolean(this._events.length);
|
|
101
101
|
}
|
|
102
102
|
getApplierForEvent(event) {
|
|
103
|
-
const
|
|
104
|
-
const applier = this.eventAppliersMap().get(
|
|
103
|
+
const eventName = event.modelName();
|
|
104
|
+
const applier = this.eventAppliersMap().get(eventName);
|
|
105
105
|
if (!applier)
|
|
106
106
|
throw new Error("Event applier not found");
|
|
107
107
|
return applier;
|
|
108
108
|
}
|
|
109
109
|
validateEventBeforeApply(event) {
|
|
110
110
|
const eventSource = event.getSource();
|
|
111
|
-
if (eventSource.
|
|
111
|
+
if (eventSource.aggregate !== this.modelName())
|
|
112
112
|
throw new Error("Invalid source type");
|
|
113
113
|
if (!eventSource.id.equals(this._id))
|
|
114
114
|
throw new Error("Invalid source id");
|
|
@@ -144,15 +144,15 @@ class AggregateES extends AggregateBase {
|
|
|
144
144
|
return this.constructor.commandHandlersMap();
|
|
145
145
|
}
|
|
146
146
|
getHandlerForCommand(command) {
|
|
147
|
-
const
|
|
148
|
-
const handler = this.commandHandlersMap().get(
|
|
147
|
+
const commandName = command.modelName();
|
|
148
|
+
const handler = this.commandHandlersMap().get(commandName);
|
|
149
149
|
if (!handler)
|
|
150
150
|
throw new Error("Command handler not found");
|
|
151
151
|
return handler;
|
|
152
152
|
}
|
|
153
153
|
handleCommand(command) {
|
|
154
154
|
const handler = this.getHandlerForCommand(command);
|
|
155
|
-
const events = (0,
|
|
155
|
+
const events = (0, _utils_1.toArray)(handler.call(this, command));
|
|
156
156
|
events.forEach((event) => {
|
|
157
157
|
var _a;
|
|
158
158
|
event.setContext({
|
|
@@ -176,4 +176,4 @@ class AggregateES extends AggregateBase {
|
|
|
176
176
|
};
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
exports.
|
|
179
|
+
exports.AggregateESBase = AggregateESBase;
|
package/dist/core/entity.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { Class } from "
|
|
2
|
-
import { ClassStatic } from "../types/class-static";
|
|
1
|
+
import { Class } from "type-fest";
|
|
3
2
|
import { Id } from "./id";
|
|
4
|
-
import { PropsOf } from "./model";
|
|
5
|
-
import {
|
|
3
|
+
import { ModelWithId, PropsOf } from "./model";
|
|
4
|
+
import { ClassStatic } from "../types/index";
|
|
6
5
|
export interface EntityMetadata {
|
|
7
6
|
readonly id: Id;
|
|
8
7
|
}
|
|
9
|
-
export declare class
|
|
10
|
-
protected readonly _id: Id;
|
|
8
|
+
export declare abstract class EntityBase<Props extends object> extends ModelWithId<Props> {
|
|
11
9
|
constructor(metadata: EntityMetadata, props?: Props);
|
|
10
|
+
static isMutable(): boolean;
|
|
12
11
|
static newEntity<T extends AnyEntity>(this: EntityClassWithTypedConstructor<T>, props: PropsOf<T>, id?: Id): T;
|
|
13
|
-
getId(): Id;
|
|
14
|
-
hasId(id: Id): boolean;
|
|
15
12
|
}
|
|
16
|
-
export type AnyEntity =
|
|
17
|
-
export type EntityClass<T extends AnyEntity = AnyEntity, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof
|
|
18
|
-
export type EntityClassWithTypedConstructor<T extends AnyEntity = AnyEntity> = EntityClass<T, ConstructorParameters<typeof
|
|
13
|
+
export type AnyEntity = EntityBase<object>;
|
|
14
|
+
export type EntityClass<T extends AnyEntity = AnyEntity, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof EntityBase<PropsOf<T>>>;
|
|
15
|
+
export type EntityClassWithTypedConstructor<T extends AnyEntity = AnyEntity> = EntityClass<T, ConstructorParameters<typeof EntityBase<PropsOf<T>>>>;
|
|
16
|
+
export type EntityClassWithProps<P extends object> = EntityClass<EntityBase<P>>;
|
package/dist/core/entity.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
class
|
|
3
|
+
exports.EntityBase = void 0;
|
|
4
|
+
const model_1 = require("./model");
|
|
5
|
+
class EntityBase extends model_1.ModelWithId {
|
|
6
6
|
constructor(metadata, props) {
|
|
7
|
-
super(
|
|
8
|
-
|
|
7
|
+
super(metadata.id);
|
|
8
|
+
if (props)
|
|
9
|
+
this.initializeProps(props);
|
|
10
|
+
}
|
|
11
|
+
static isMutable() {
|
|
12
|
+
return true;
|
|
9
13
|
}
|
|
10
14
|
static newEntity(props, id) {
|
|
11
15
|
return new this({
|
|
12
16
|
id: this.id(id),
|
|
13
17
|
}, props);
|
|
14
18
|
}
|
|
15
|
-
getId() {
|
|
16
|
-
return this._id;
|
|
17
|
-
}
|
|
18
|
-
hasId(id) {
|
|
19
|
-
return this._id.equals(id);
|
|
20
|
-
}
|
|
21
19
|
}
|
|
22
|
-
exports.
|
|
20
|
+
exports.EntityBase = EntityBase;
|
package/dist/core/error.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ModelError = void 0;
|
|
4
4
|
class ModelError extends Error {
|
|
5
5
|
constructor(model, message) {
|
|
6
|
-
super(`[${model.
|
|
6
|
+
super(`[${model.modelName()}] ${message}`);
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
exports.ModelError = ModelError;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./snowflake.generator"), exports);
|
|
18
|
+
__exportStar(require("./uuid4.generator"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SnowflakeOpts } from "nodejs-snowflake";
|
|
2
|
+
import { IdGeneratorBase } from "../id-generator";
|
|
3
|
+
export declare class SnowflakeGenerator extends IdGeneratorBase {
|
|
4
|
+
private snowflake;
|
|
5
|
+
constructor(options?: SnowflakeOpts);
|
|
6
|
+
generateValue(): string;
|
|
7
|
+
validateValue(value: string): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SnowflakeGenerator = void 0;
|
|
4
|
+
const nodejs_snowflake_1 = require("nodejs-snowflake");
|
|
5
|
+
const id_generator_1 = require("../id-generator");
|
|
6
|
+
class SnowflakeGenerator extends id_generator_1.IdGeneratorBase {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super();
|
|
9
|
+
this.snowflake = new nodejs_snowflake_1.Snowflake(options);
|
|
10
|
+
}
|
|
11
|
+
generateValue() {
|
|
12
|
+
return this.snowflake.getUniqueID().toString(16);
|
|
13
|
+
}
|
|
14
|
+
validateValue(value) { }
|
|
15
|
+
}
|
|
16
|
+
exports.SnowflakeGenerator = SnowflakeGenerator;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Uuid4Generator = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const id_generator_1 = require("../id-generator");
|
|
6
|
+
class Uuid4Generator extends id_generator_1.IdGeneratorBase {
|
|
7
|
+
generateValue() {
|
|
8
|
+
return (0, uuid_1.v4)();
|
|
9
|
+
}
|
|
10
|
+
validateValue(value) {
|
|
11
|
+
const isUuid = (0, uuid_1.validate)(value);
|
|
12
|
+
const isV4 = (0, uuid_1.version)(value) === 4;
|
|
13
|
+
return isUuid && isV4;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.Uuid4Generator = Uuid4Generator;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IdGeneratorBase = void 0;
|
|
4
|
+
const id_1 = require("./id");
|
|
5
|
+
class IdGeneratorBase {
|
|
6
|
+
fromValue(value) {
|
|
7
|
+
this.validateValue(value);
|
|
8
|
+
return new id_1.Id(value);
|
|
9
|
+
}
|
|
10
|
+
fromId(id) {
|
|
11
|
+
return this.fromValue(id.value);
|
|
12
|
+
}
|
|
13
|
+
newId() {
|
|
14
|
+
return this.fromValue(this.generateValue());
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.IdGeneratorBase = IdGeneratorBase;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Id = void 0;
|
|
4
|
+
class Id {
|
|
5
|
+
constructor(value) {
|
|
6
|
+
this._value = value;
|
|
7
|
+
}
|
|
8
|
+
get value() {
|
|
9
|
+
return this._value;
|
|
10
|
+
}
|
|
11
|
+
equals(id) {
|
|
12
|
+
return this._value === id._value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.Id = Id;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./built"), exports);
|
|
18
|
+
__exportStar(require("./id"), exports);
|
|
19
|
+
__exportStar(require("./id-generator"), exports);
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
export * from "./aggregate";
|
|
2
|
-
export * from "./command";
|
|
3
2
|
export * from "./entity";
|
|
4
3
|
export * from "./error";
|
|
5
|
-
export * from "./event";
|
|
6
4
|
export * from "./id";
|
|
7
5
|
export * from "./message";
|
|
8
6
|
export * from "./metadata";
|
|
9
7
|
export * from "./model";
|
|
10
|
-
export * from "./model-type";
|
|
11
|
-
export * from "./model-with-id";
|
|
12
|
-
export * from "./registry";
|
|
13
8
|
export * from "./repository";
|
|
14
9
|
export * from "./value-object";
|
package/dist/core/index.js
CHANGED
|
@@ -15,16 +15,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./aggregate"), exports);
|
|
18
|
-
__exportStar(require("./command"), exports);
|
|
19
18
|
__exportStar(require("./entity"), exports);
|
|
20
19
|
__exportStar(require("./error"), exports);
|
|
21
|
-
__exportStar(require("./event"), exports);
|
|
22
20
|
__exportStar(require("./id"), exports);
|
|
23
21
|
__exportStar(require("./message"), exports);
|
|
24
22
|
__exportStar(require("./metadata"), exports);
|
|
25
23
|
__exportStar(require("./model"), exports);
|
|
26
|
-
__exportStar(require("./model-type"), exports);
|
|
27
|
-
__exportStar(require("./model-with-id"), exports);
|
|
28
|
-
__exportStar(require("./registry"), exports);
|
|
29
24
|
__exportStar(require("./repository"), exports);
|
|
30
25
|
__exportStar(require("./value-object"), exports);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Class } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Class } from "type-fest";
|
|
2
|
+
import { PropsOf } from "../model";
|
|
3
|
+
import { MessageBase, MessageContext, MessageMetadata } from "./message";
|
|
4
|
+
import { ClassStatic } from "../../types/index";
|
|
5
5
|
export interface CommandMetadata extends MessageMetadata {
|
|
6
6
|
}
|
|
7
|
-
export declare class
|
|
7
|
+
export declare abstract class CommandBase<Props extends object> extends MessageBase<Props> {
|
|
8
8
|
constructor(metadata: CommandMetadata, props: Props);
|
|
9
9
|
static newCommand<T extends AnyCommand>(this: CommandClassWithTypedConstructor<T>, props: PropsOf<T>, context?: MessageContext): T;
|
|
10
10
|
}
|
|
11
|
-
export type AnyCommand =
|
|
12
|
-
export type CommandClass<T extends AnyCommand = AnyCommand, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof
|
|
13
|
-
export type CommandClassWithTypedConstructor<T extends AnyCommand = AnyCommand> = CommandClass<T, ConstructorParameters<typeof
|
|
11
|
+
export type AnyCommand = CommandBase<any>;
|
|
12
|
+
export type CommandClass<T extends AnyCommand = AnyCommand, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof CommandBase<PropsOf<T>>>;
|
|
13
|
+
export type CommandClassWithTypedConstructor<T extends AnyCommand = AnyCommand> = CommandClass<T, ConstructorParameters<typeof CommandBase<PropsOf<T>>>>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CommandBase = void 0;
|
|
4
4
|
const message_1 = require("./message");
|
|
5
|
-
class
|
|
5
|
+
class CommandBase extends message_1.MessageBase {
|
|
6
6
|
constructor(metadata, props) {
|
|
7
7
|
super(metadata, props);
|
|
8
8
|
}
|
|
@@ -14,4 +14,4 @@ class Command extends message_1.Message {
|
|
|
14
14
|
}, props);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
exports.
|
|
17
|
+
exports.CommandBase = CommandBase;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { Class } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ModelTypePattern } from "./model-type";
|
|
1
|
+
import { Class } from "type-fest";
|
|
2
|
+
import { Id } from "../id";
|
|
3
|
+
import { PropsOf } from "../model";
|
|
4
|
+
import { MessageBase, MessageContext, MessageMetadata } from "./message";
|
|
5
|
+
import { ClassStatic } from "../../types/index";
|
|
7
6
|
export type EventSource = Readonly<{
|
|
8
|
-
|
|
7
|
+
aggregate: string;
|
|
9
8
|
id: Id;
|
|
10
9
|
version: number;
|
|
11
10
|
}>;
|
|
12
11
|
export interface EventMetadata extends MessageMetadata {
|
|
13
12
|
source: EventSource;
|
|
14
13
|
}
|
|
15
|
-
export declare class
|
|
14
|
+
export declare abstract class EventBase<Props extends object, Raw = any> extends MessageBase<Props> {
|
|
16
15
|
private readonly _source;
|
|
17
16
|
constructor(metadata: EventMetadata, props: Props);
|
|
18
17
|
static newEvent<T extends AnyEvent>(this: EventClassWithTypedConstructor<T>, source: EventSource, props: PropsOf<T>, context?: MessageContext): T;
|
|
19
18
|
getSource(): Readonly<{
|
|
20
|
-
|
|
19
|
+
aggregate: string;
|
|
21
20
|
id: Id;
|
|
22
21
|
version: number;
|
|
23
22
|
}>;
|
|
23
|
+
getRaw(): Raw | null;
|
|
24
24
|
}
|
|
25
|
-
export type AnyEvent =
|
|
26
|
-
export type EventClass<T extends AnyEvent = AnyEvent, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof
|
|
27
|
-
export type EventClassWithTypedConstructor<T extends AnyEvent = AnyEvent> = EventClass<T, ConstructorParameters<typeof
|
|
25
|
+
export type AnyEvent = EventBase<any>;
|
|
26
|
+
export type EventClass<T extends AnyEvent = AnyEvent, Arguments extends unknown[] = any[]> = Class<T, Arguments> & ClassStatic<typeof EventBase<PropsOf<T>>>;
|
|
27
|
+
export type EventClassWithTypedConstructor<T extends AnyEvent = AnyEvent> = EventClass<T, ConstructorParameters<typeof EventBase<PropsOf<T>>>>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.EventBase = void 0;
|
|
4
4
|
const message_1 = require("./message");
|
|
5
|
-
class
|
|
5
|
+
class EventBase extends message_1.MessageBase {
|
|
6
6
|
constructor(metadata, props) {
|
|
7
7
|
super(metadata, props);
|
|
8
8
|
this._source = metadata.source;
|
|
@@ -18,5 +18,8 @@ class Event extends message_1.Message {
|
|
|
18
18
|
getSource() {
|
|
19
19
|
return this._source;
|
|
20
20
|
}
|
|
21
|
+
getRaw() {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
21
24
|
}
|
|
22
|
-
exports.
|
|
25
|
+
exports.EventBase = EventBase;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./command"), exports);
|
|
18
|
+
__exportStar(require("./event"), exports);
|
|
19
|
+
__exportStar(require("./message"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Id } from "
|
|
2
|
-
import { ModelWithId } from "
|
|
1
|
+
import { Id } from "../id";
|
|
2
|
+
import { ModelWithId } from "../model";
|
|
3
3
|
export interface MessageContext {
|
|
4
4
|
correlationId?: string;
|
|
5
5
|
causationId?: string;
|
|
@@ -9,12 +9,10 @@ export interface MessageMetadata {
|
|
|
9
9
|
readonly timestamp: number;
|
|
10
10
|
context?: MessageContext;
|
|
11
11
|
}
|
|
12
|
-
export declare class
|
|
13
|
-
private readonly _id;
|
|
12
|
+
export declare abstract class MessageBase<Props extends object> extends ModelWithId<Props> {
|
|
14
13
|
private readonly _timestamp;
|
|
15
14
|
private _context?;
|
|
16
15
|
protected constructor(metadata: MessageMetadata, props: Props);
|
|
17
|
-
getId(): Id;
|
|
18
16
|
getTimestamp(): number;
|
|
19
17
|
getContext(): MessageContext | undefined;
|
|
20
18
|
setContext(context: Partial<MessageContext>): void;
|
|
@@ -3,19 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.MessageBase = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const
|
|
9
|
-
class
|
|
8
|
+
const model_1 = require("../model");
|
|
9
|
+
class MessageBase extends model_1.ModelWithId {
|
|
10
10
|
constructor(metadata, props) {
|
|
11
11
|
var _a;
|
|
12
|
-
super(
|
|
13
|
-
this._id = metadata.id;
|
|
12
|
+
super(metadata.id);
|
|
14
13
|
this._timestamp = metadata.timestamp;
|
|
15
14
|
this._context = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.context) !== null && _a !== void 0 ? _a : {};
|
|
16
|
-
|
|
17
|
-
getId() {
|
|
18
|
-
return this._id;
|
|
15
|
+
this.initializeProps(props);
|
|
19
16
|
}
|
|
20
17
|
getTimestamp() {
|
|
21
18
|
return this._timestamp;
|
|
@@ -27,4 +24,4 @@ class Message extends model_with_id_1.ModelWithId {
|
|
|
27
24
|
this._context = lodash_1.default.merge(this._context, context);
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
|
-
exports.
|
|
27
|
+
exports.MessageBase = MessageBase;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { CommandHandler, EventApplier } from "../aggregate";
|
|
3
|
+
import { AnyCommand, AnyEvent } from "../message";
|
|
4
|
+
export declare const EventAppliersMetaKey: unique symbol;
|
|
5
|
+
export declare const getEventAppliersMap: (target: object) => Map<string, EventApplier>;
|
|
6
|
+
export declare const defineEventApplier: <T extends AnyEvent>(target: object, eventName: string, applier: EventApplier<T>) => void;
|
|
7
|
+
export declare const CommandHandlersMetaKey: unique symbol;
|
|
8
|
+
export declare const getCommandHandlersMap: (target: object) => Map<string, CommandHandler>;
|
|
9
|
+
export declare const defineCommandHandler: <T extends AnyCommand>(target: object, commandName: string, handler: CommandHandler<T>) => void;
|