ddd-node 13.0.0-0 → 14.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/.editorconfig +12 -0
- package/dist/core/aggregate/base.d.ts +12 -0
- package/dist/core/aggregate/base.js +15 -0
- package/dist/core/aggregate/event-sourced-aggregate.d.ts +48 -0
- package/dist/core/aggregate/event-sourced-aggregate.js +130 -0
- package/dist/core/aggregate/index.d.ts +3 -0
- package/dist/core/aggregate/index.js +3 -0
- package/dist/core/aggregate/state-aggregate.d.ts +22 -0
- package/dist/core/aggregate/state-aggregate.js +35 -0
- package/dist/core/aggregate/types.d.ts +4 -0
- package/dist/core/aggregate/types.js +1 -0
- package/dist/core/entity.d.ts +12 -9
- package/dist/core/entity.js +3 -7
- package/dist/core/enum.d.ts +12 -10
- package/dist/core/enum.js +30 -22
- package/dist/core/id/common/index.d.ts +2 -0
- package/dist/core/id/common/index.js +2 -0
- package/dist/core/id/common/snowflake.d.ts +9 -0
- package/dist/core/id/common/snowflake.js +13 -0
- package/dist/core/id/common/uuid4.d.ts +6 -0
- package/dist/core/id/common/uuid4.js +17 -0
- package/dist/core/id/id.d.ts +7 -5
- package/dist/core/id/id.js +13 -8
- package/dist/core/id/index.d.ts +2 -2
- package/dist/core/id/index.js +3 -19
- package/dist/core/id/interface.d.ts +10 -0
- package/dist/core/id/interface.js +1 -0
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +8 -25
- package/dist/core/message/command.d.ts +14 -9
- package/dist/core/message/command.js +10 -9
- package/dist/core/message/event.d.ts +15 -11
- package/dist/core/message/event.js +9 -11
- package/dist/core/message/index.js +3 -19
- package/dist/core/message/message.d.ts +8 -4
- package/dist/core/message/message.js +13 -14
- package/dist/core/model/errors.d.ts +3 -0
- package/dist/core/model/errors.js +5 -0
- package/dist/core/model/index.js +2 -18
- package/dist/core/model/model-with-id.d.ts +8 -8
- package/dist/core/model/model-with-id.js +9 -13
- package/dist/core/model/model.d.ts +30 -19
- package/dist/core/model/model.js +50 -41
- package/dist/core/repository.d.ts +2 -2
- package/dist/core/repository.js +1 -2
- package/dist/core/value-object.d.ts +11 -8
- package/dist/core/value-object.js +8 -12
- package/dist/decorators/aggregate-es/handle.d.ts +2 -0
- package/dist/decorators/aggregate-es/handle.js +9 -0
- package/dist/decorators/aggregate-es/index.js +2 -0
- package/dist/decorators/aggregate-es/when.d.ts +2 -0
- package/dist/decorators/aggregate-es/when.js +9 -0
- package/dist/decorators/id.d.ts +2 -2
- package/dist/decorators/id.js +3 -7
- package/dist/decorators/index.d.ts +1 -1
- package/dist/decorators/index.js +3 -19
- package/dist/decorators/model/enum.d.ts +2 -0
- package/dist/decorators/model/enum.js +6 -0
- package/dist/decorators/model/index.d.ts +3 -3
- package/dist/decorators/model/index.js +5 -21
- package/dist/decorators/model/model-name.d.ts +2 -0
- package/dist/decorators/model/model-name.js +6 -0
- package/dist/decorators/model/prop.d.ts +2 -1
- package/dist/decorators/model/prop.js +5 -7
- package/dist/decorators/model/static.d.ts +3 -3
- package/dist/decorators/model/static.js +7 -30
- package/dist/decorators/model/validator.d.ts +3 -0
- package/dist/decorators/model/validator.js +7 -0
- package/dist/decorators/type.js +1 -2
- package/dist/index.js +5 -21
- package/dist/meta/aggregate.metadata.d.ts +5 -5
- package/dist/meta/aggregate.metadata.js +19 -22
- package/dist/meta/helpers/index.d.ts +1 -0
- package/dist/meta/helpers/index.js +1 -0
- package/dist/meta/helpers/static-value.d.ts +7 -0
- package/dist/meta/helpers/static-value.js +11 -0
- package/dist/meta/id.metadata.d.ts +4 -4
- package/dist/meta/id.metadata.js +10 -10
- package/dist/meta/index.d.ts +1 -0
- package/dist/meta/index.js +4 -19
- package/dist/meta/model.metadata.d.ts +14 -12
- package/dist/meta/model.metadata.js +79 -43
- package/dist/types/class-static.js +1 -2
- package/dist/types/class.js +1 -2
- package/dist/types/index.js +2 -18
- package/dist/utils/index.js +1 -17
- package/dist/utils/to-array.js +2 -8
- package/package.json +27 -3
- package/ts-loader.js +4 -0
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +29 -22
- package/tsconfig.spec.json +5 -0
- package/dist/core/aggregate.d.ts +0 -67
- package/dist/core/aggregate.js +0 -179
- package/dist/core/error.d.ts +0 -4
- package/dist/core/error.js +0 -9
- package/dist/core/id/built/index.d.ts +0 -2
- package/dist/core/id/built/index.js +0 -18
- package/dist/core/id/built/snowflake.generator.d.ts +0 -8
- package/dist/core/id/built/snowflake.generator.js +0 -16
- package/dist/core/id/built/uuid4.generator.d.ts +0 -5
- package/dist/core/id/built/uuid4.generator.js +0 -16
- package/dist/core/id/id-generator.d.ts +0 -8
- package/dist/core/id/id-generator.js +0 -17
- package/dist/decorators/aggregate/handle.d.ts +0 -2
- package/dist/decorators/aggregate/handle.js +0 -13
- package/dist/decorators/aggregate/index.js +0 -18
- package/dist/decorators/aggregate/when.d.ts +0 -2
- package/dist/decorators/aggregate/when.js +0 -13
- package/dist/decorators/model/helpers/static-values.d.ts +0 -12
- package/dist/decorators/model/helpers/static-values.js +0 -30
- package/dist/decorators/model/model.d.ts +0 -10
- package/dist/decorators/model/model.js +0 -26
- package/dist/decorators/model/name.d.ts +0 -2
- package/dist/decorators/model/name.js +0 -10
- package/dist/decorators/model/types/static-typed-target.d.ts +0 -5
- package/dist/decorators/model/types/static-typed-target.js +0 -3
- package/dist/decorators/model/types/static-value-builder.d.ts +0 -2
- package/dist/decorators/model/types/static-value-builder.js +0 -2
- package/dist/decorators/model/validate.d.ts +0 -3
- package/dist/decorators/model/validate.js +0 -11
- /package/dist/decorators/{aggregate → aggregate-es}/index.d.ts +0 -0
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
import { ClassStatic } from "../../types";
|
|
1
2
|
import { Class } from "type-fest";
|
|
2
|
-
import { PropsOf } from "../model";
|
|
3
|
+
import { Props, PropsOf } from "../model";
|
|
3
4
|
import { MessageBase, MessageContext, MessageMetadata } from "./message";
|
|
4
|
-
|
|
5
|
-
export interface CommandMetadata extends MessageMetadata {
|
|
5
|
+
export interface CommandMetadata extends Omit<MessageMetadata, "messageType"> {
|
|
6
6
|
}
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
export declare class CommandBase<P extends Props> extends MessageBase<P> {
|
|
8
|
+
static readonly COMMAND_MESSAGE_TYPE = "command";
|
|
9
|
+
private _commandType;
|
|
10
|
+
constructor(metadata: CommandMetadata, props: P);
|
|
11
|
+
static newCommand<T extends AnyCommand>(this: CommandClassWithTypedConstructor<T>, props: PropsOf<T>, context?: MessageContext, timestamp?: number): T;
|
|
12
|
+
getCommandType(): void;
|
|
13
|
+
}
|
|
14
|
+
export type AnyCommand = CommandBase<Props>;
|
|
15
|
+
export interface CommandClass<T extends AnyCommand = AnyCommand, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof CommandBase<PropsOf<T>>> {
|
|
16
|
+
}
|
|
17
|
+
export interface CommandClassWithTypedConstructor<T extends AnyCommand = AnyCommand> extends CommandClass<T, ConstructorParameters<typeof CommandBase<PropsOf<T>>>> {
|
|
10
18
|
}
|
|
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,17 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.CommandBase = void 0;
|
|
4
|
-
const message_1 = require("./message");
|
|
5
|
-
class CommandBase extends message_1.MessageBase {
|
|
1
|
+
import { MessageBase } from "./message";
|
|
2
|
+
export class CommandBase extends MessageBase {
|
|
6
3
|
constructor(metadata, props) {
|
|
7
|
-
super(metadata, props);
|
|
4
|
+
super({ ...metadata, messageType: CommandBase.COMMAND_MESSAGE_TYPE }, props);
|
|
5
|
+
this._commandType = this.modelName();
|
|
8
6
|
}
|
|
9
|
-
static newCommand(props, context) {
|
|
7
|
+
static newCommand(props, context, timestamp) {
|
|
10
8
|
return new this({
|
|
11
9
|
id: this.id(),
|
|
12
|
-
timestamp: Date.now(),
|
|
13
10
|
context,
|
|
11
|
+
timestamp,
|
|
14
12
|
}, props);
|
|
15
13
|
}
|
|
14
|
+
getCommandType() {
|
|
15
|
+
this._commandType;
|
|
16
|
+
}
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
CommandBase.COMMAND_MESSAGE_TYPE = "command";
|
|
@@ -1,27 +1,31 @@
|
|
|
1
|
+
import { ClassStatic } from "../../types";
|
|
1
2
|
import { Class } from "type-fest";
|
|
2
3
|
import { Id } from "../id";
|
|
3
|
-
import { PropsOf } from "../model";
|
|
4
|
+
import { Props, PropsOf } from "../model";
|
|
4
5
|
import { MessageBase, MessageContext, MessageMetadata } from "./message";
|
|
5
|
-
import { ClassStatic } from "../../types/index";
|
|
6
6
|
export type EventSource = Readonly<{
|
|
7
7
|
aggregate: string;
|
|
8
8
|
id: Id;
|
|
9
9
|
version: number;
|
|
10
10
|
}>;
|
|
11
|
-
export interface EventMetadata extends MessageMetadata {
|
|
11
|
+
export interface EventMetadata extends Omit<MessageMetadata, "messageType"> {
|
|
12
12
|
source: EventSource;
|
|
13
13
|
}
|
|
14
|
-
export declare
|
|
14
|
+
export declare class EventBase<P extends Props> extends MessageBase<P> {
|
|
15
|
+
static readonly EVENT_MESSAGE_TYPE = "event";
|
|
15
16
|
private readonly _source;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
private readonly _eventType;
|
|
18
|
+
constructor(metadata: EventMetadata, props: P);
|
|
19
|
+
static newEvent<T extends AnyEvent>(this: EventClassWithTypedConstructor<T>, source: EventSource, props: PropsOf<T>, context?: MessageContext, timestamp?: number): T;
|
|
18
20
|
getSource(): Readonly<{
|
|
19
21
|
aggregate: string;
|
|
20
|
-
id: Id
|
|
22
|
+
id: Id<any>;
|
|
21
23
|
version: number;
|
|
22
24
|
}>;
|
|
23
|
-
|
|
25
|
+
getEventType(): string;
|
|
26
|
+
}
|
|
27
|
+
export type AnyEvent = EventBase<Props>;
|
|
28
|
+
export interface EventClass<T extends AnyEvent = AnyEvent, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof EventBase<PropsOf<T>>> {
|
|
29
|
+
}
|
|
30
|
+
export interface EventClassWithTypedConstructor<T extends AnyEvent = AnyEvent> extends EventClass<T, ConstructorParameters<typeof EventBase<PropsOf<T>>>> {
|
|
24
31
|
}
|
|
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,25 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.EventBase = void 0;
|
|
4
|
-
const message_1 = require("./message");
|
|
5
|
-
class EventBase extends message_1.MessageBase {
|
|
1
|
+
import { MessageBase } from "./message";
|
|
2
|
+
export class EventBase extends MessageBase {
|
|
6
3
|
constructor(metadata, props) {
|
|
7
|
-
super(metadata, props);
|
|
4
|
+
super({ ...metadata, messageType: EventBase.EVENT_MESSAGE_TYPE }, props);
|
|
8
5
|
this._source = metadata.source;
|
|
6
|
+
this._eventType = this.modelName();
|
|
9
7
|
}
|
|
10
|
-
static newEvent(source, props, context) {
|
|
8
|
+
static newEvent(source, props, context, timestamp) {
|
|
11
9
|
return new this({
|
|
12
10
|
id: this.id(),
|
|
13
|
-
timestamp: Date.now(),
|
|
14
11
|
source,
|
|
15
12
|
context,
|
|
13
|
+
timestamp,
|
|
16
14
|
}, props);
|
|
17
15
|
}
|
|
18
16
|
getSource() {
|
|
19
17
|
return this._source;
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
return
|
|
19
|
+
getEventType() {
|
|
20
|
+
return this._eventType;
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
|
-
|
|
23
|
+
EventBase.EVENT_MESSAGE_TYPE = "event";
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./message"), exports);
|
|
18
|
-
__exportStar(require("./command"), exports);
|
|
19
|
-
__exportStar(require("./event"), exports);
|
|
1
|
+
export * from "./message";
|
|
2
|
+
export * from "./command";
|
|
3
|
+
export * from "./event";
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { Id } from "../id";
|
|
2
|
-
import { ModelWithId } from "../model";
|
|
2
|
+
import { ModelWithId, Props } from "../model";
|
|
3
3
|
export interface MessageContext {
|
|
4
4
|
correlationId?: string;
|
|
5
5
|
causationId?: string;
|
|
6
6
|
}
|
|
7
7
|
export interface MessageMetadata {
|
|
8
8
|
readonly id: Id;
|
|
9
|
-
readonly
|
|
9
|
+
readonly messageType: string;
|
|
10
|
+
readonly timestamp?: number;
|
|
10
11
|
context?: MessageContext;
|
|
11
12
|
}
|
|
12
|
-
export declare
|
|
13
|
+
export declare class MessageBase<P extends Props> extends ModelWithId<P> {
|
|
14
|
+
private readonly _messageType;
|
|
13
15
|
private readonly _timestamp;
|
|
14
16
|
private _context?;
|
|
15
|
-
protected constructor(metadata: MessageMetadata, props:
|
|
17
|
+
protected constructor(metadata: MessageMetadata, props: P);
|
|
18
|
+
props(): P;
|
|
19
|
+
getMessageType(): string;
|
|
16
20
|
getTimestamp(): number;
|
|
17
21
|
getContext(): MessageContext | undefined;
|
|
18
22
|
setContext(context: Partial<MessageContext>): void;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MessageBase = void 0;
|
|
7
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const model_1 = require("../model");
|
|
9
|
-
class MessageBase extends model_1.ModelWithId {
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { ModelWithId } from "../model";
|
|
3
|
+
export class MessageBase extends ModelWithId {
|
|
10
4
|
constructor(metadata, props) {
|
|
11
|
-
var _a;
|
|
12
5
|
super(metadata.id);
|
|
13
|
-
this.
|
|
14
|
-
this._context =
|
|
6
|
+
this._messageType = metadata.messageType;
|
|
7
|
+
this._context = metadata?.context ?? {};
|
|
8
|
+
this._timestamp = metadata.timestamp ?? Date.now();
|
|
15
9
|
this.initializeProps(props);
|
|
16
10
|
}
|
|
11
|
+
props() {
|
|
12
|
+
return super.props();
|
|
13
|
+
}
|
|
14
|
+
getMessageType() {
|
|
15
|
+
return this._messageType;
|
|
16
|
+
}
|
|
17
17
|
getTimestamp() {
|
|
18
18
|
return this._timestamp;
|
|
19
19
|
}
|
|
@@ -21,7 +21,6 @@ class MessageBase extends model_1.ModelWithId {
|
|
|
21
21
|
return this._context;
|
|
22
22
|
}
|
|
23
23
|
setContext(context) {
|
|
24
|
-
this._context =
|
|
24
|
+
this._context = _.merge(this._context, context);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
exports.MessageBase = MessageBase;
|
package/dist/core/model/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./model"), exports);
|
|
18
|
-
__exportStar(require("./model-with-id"), exports);
|
|
1
|
+
export * from "./model";
|
|
2
|
+
export * from "./model-with-id";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Id
|
|
2
|
-
import { ModelBase } from "./model";
|
|
3
|
-
export declare
|
|
1
|
+
import { Id } from "../id";
|
|
2
|
+
import { ModelBase, Props } from "./model";
|
|
3
|
+
export declare class ModelWithId<P extends Props> extends ModelBase<P> {
|
|
4
4
|
protected readonly _id: Id;
|
|
5
5
|
constructor(id: Id);
|
|
6
|
-
static
|
|
7
|
-
static id(id?: Id): Id
|
|
8
|
-
|
|
6
|
+
static idService(): import("../id").IIdService<any>;
|
|
7
|
+
static id(id?: Id): Id<any>;
|
|
8
|
+
id(): Id<any>;
|
|
9
9
|
hasId(id: Id): boolean;
|
|
10
|
-
rawId():
|
|
10
|
+
rawId(): any;
|
|
11
11
|
}
|
|
12
|
-
export type AnyModelWithId = ModelWithId<
|
|
12
|
+
export type AnyModelWithId = ModelWithId<Props>;
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const id_1 = require("../id");
|
|
6
|
-
const model_1 = require("./model");
|
|
7
|
-
class ModelWithId extends model_1.ModelBase {
|
|
1
|
+
import { getIdService } from "../../meta";
|
|
2
|
+
import { Id } from "../id";
|
|
3
|
+
import { ModelBase } from "./model";
|
|
4
|
+
export class ModelWithId extends ModelBase {
|
|
8
5
|
constructor(id) {
|
|
9
6
|
super();
|
|
10
7
|
this._id = id;
|
|
11
8
|
}
|
|
12
|
-
static
|
|
13
|
-
return (
|
|
9
|
+
static idService() {
|
|
10
|
+
return getIdService(this);
|
|
14
11
|
}
|
|
15
12
|
static id(id) {
|
|
16
|
-
const
|
|
17
|
-
return
|
|
13
|
+
const idService = this.idService();
|
|
14
|
+
return new Id(idService, id);
|
|
18
15
|
}
|
|
19
|
-
|
|
16
|
+
id() {
|
|
20
17
|
return this._id;
|
|
21
18
|
}
|
|
22
19
|
hasId(id) {
|
|
@@ -26,4 +23,3 @@ class ModelWithId extends model_1.ModelBase {
|
|
|
26
23
|
return this._id.value;
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
|
-
exports.ModelWithId = ModelWithId;
|
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
import { ModelMetadata } from "../../meta/index";
|
|
2
|
-
import { ClassStatic } from "../../types/index";
|
|
3
1
|
import { Class } from "type-fest";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { ClassStatic } from "../../types";
|
|
3
|
+
export type PropKey = string | symbol;
|
|
4
|
+
export interface Props {
|
|
5
|
+
[key: PropKey]: any;
|
|
6
|
+
}
|
|
7
|
+
export type EmptyProps = {
|
|
8
|
+
[key: PropKey]: never;
|
|
9
|
+
};
|
|
10
|
+
export declare class ModelBase<P extends Props> {
|
|
11
|
+
static readonly EMPTY_PROPS: EmptyProps;
|
|
12
|
+
protected _props: P;
|
|
11
13
|
static isModel(model: any): model is AnyModel;
|
|
14
|
+
static mutable(): boolean;
|
|
15
|
+
static modelName<T extends AnyModel>(this: ModelClass<T>): string;
|
|
16
|
+
static propsValidator<T extends AnyModel>(this: ModelClass<T>): import("../../meta").PropsValidator<T> | undefined;
|
|
17
|
+
static ownStaticValues<T extends AnyModel>(this: ModelClass<T>): Map<string | symbol, import("../../meta").StaticValue<T>>;
|
|
18
|
+
static ownPropsMap(): import("../../meta").PropsMap<ModelBase<any>>;
|
|
19
|
+
static propsMap(): import("../../meta").PropsMap<ModelBase<any>>;
|
|
12
20
|
constructor();
|
|
13
21
|
private redefineModel;
|
|
22
|
+
protected get currentModelType(): ModelClass<this>;
|
|
14
23
|
isMutable(): boolean;
|
|
15
|
-
getPropKeys(): Set<string | symbol>;
|
|
16
|
-
validateProps(props: Props): void;
|
|
17
|
-
validate(): void;
|
|
18
|
-
getModelMetadata(): ModelMetadata<this>;
|
|
19
24
|
modelName(): string;
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
propsValidator(): import("../../meta").PropsValidator<this> | undefined;
|
|
26
|
+
ownPropsMap(): import("../../meta").PropsMap<ModelBase<any>>;
|
|
27
|
+
propsMap(): import("../../meta").PropsMap<any>;
|
|
28
|
+
validateProps(props: P): void;
|
|
29
|
+
validate(): void;
|
|
30
|
+
propsIsEmpty(): boolean;
|
|
31
|
+
props(): P | null;
|
|
32
|
+
protected initializeProps(props: P): void;
|
|
33
|
+
}
|
|
34
|
+
export type AnyModel = ModelBase<Props>;
|
|
35
|
+
export type PropsOf<T extends AnyModel> = T extends ModelBase<infer P extends Props> ? P : never;
|
|
36
|
+
export interface ModelClass<T extends AnyModel = AnyModel> extends Class<T>, ClassStatic<typeof ModelBase<PropsOf<T>>> {
|
|
22
37
|
}
|
|
23
|
-
export type AnyModel = ModelBase<object>;
|
|
24
|
-
export type PropsOf<T extends AnyModel> = T extends ModelBase<infer P extends object> ? P : never;
|
|
25
|
-
export type ModelClass<T extends AnyModel = AnyModel> = Class<T> & ClassStatic<typeof ModelBase<PropsOf<T>>>;
|
|
26
|
-
export type EmptyProps = {};
|
package/dist/core/model/model.js
CHANGED
|
@@ -1,65 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ModelBase = void 0;
|
|
7
|
-
const _meta_1 = require("../../meta/index");
|
|
8
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
-
class ModelBase {
|
|
10
|
-
static isMutable() {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { getModelName, getOwnPropsMap, getOwnStaticValues, getPropsMap, getPropsValidator, } from "../../meta";
|
|
3
|
+
import { PropsInitializedError } from "./errors";
|
|
4
|
+
export class ModelBase {
|
|
13
5
|
static isModel(model) {
|
|
14
6
|
return model instanceof ModelBase;
|
|
15
7
|
}
|
|
8
|
+
static mutable() {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
static modelName() {
|
|
12
|
+
return getModelName(this);
|
|
13
|
+
}
|
|
14
|
+
static propsValidator() {
|
|
15
|
+
return getPropsValidator(this);
|
|
16
|
+
}
|
|
17
|
+
static ownStaticValues() {
|
|
18
|
+
return getOwnStaticValues(this);
|
|
19
|
+
}
|
|
20
|
+
static ownPropsMap() {
|
|
21
|
+
return getOwnPropsMap(this.prototype);
|
|
22
|
+
}
|
|
23
|
+
static propsMap() {
|
|
24
|
+
return getPropsMap(this.prototype);
|
|
25
|
+
}
|
|
16
26
|
constructor() {
|
|
17
27
|
this._props = ModelBase.EMPTY_PROPS;
|
|
18
28
|
this.redefineModel();
|
|
19
29
|
}
|
|
20
30
|
redefineModel() {
|
|
21
|
-
this.
|
|
22
|
-
Object.defineProperty(this,
|
|
31
|
+
this.propsMap().forEach((propKeyTarget, key) => {
|
|
32
|
+
Object.defineProperty(this, key, {
|
|
23
33
|
configurable: true,
|
|
24
34
|
enumerable: true,
|
|
25
35
|
get() {
|
|
26
|
-
|
|
27
|
-
return (_a = this._props) === null || _a === void 0 ? void 0 : _a[propKey];
|
|
28
|
-
},
|
|
29
|
-
set() {
|
|
30
|
-
throw new Error(`Prop "${propKey.toString()}" cannot be set directly`);
|
|
36
|
+
return this._props?.[propKeyTarget];
|
|
31
37
|
},
|
|
32
38
|
});
|
|
33
39
|
});
|
|
34
40
|
}
|
|
41
|
+
get currentModelType() {
|
|
42
|
+
return this.constructor;
|
|
43
|
+
}
|
|
35
44
|
isMutable() {
|
|
36
|
-
return this.
|
|
45
|
+
return this.currentModelType.mutable();
|
|
37
46
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return this.
|
|
47
|
+
modelName() {
|
|
48
|
+
return this.currentModelType.modelName();
|
|
49
|
+
}
|
|
50
|
+
propsValidator() {
|
|
51
|
+
return this.currentModelType.propsValidator();
|
|
52
|
+
}
|
|
53
|
+
ownPropsMap() {
|
|
54
|
+
return this.currentModelType.ownPropsMap();
|
|
55
|
+
}
|
|
56
|
+
propsMap() {
|
|
57
|
+
return getPropsMap(Reflect.getPrototypeOf(this));
|
|
43
58
|
}
|
|
44
59
|
validateProps(props) {
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
|
|
60
|
+
const propsValidator = this.propsValidator();
|
|
61
|
+
if (propsValidator)
|
|
62
|
+
propsValidator(props);
|
|
48
63
|
}
|
|
49
64
|
validate() {
|
|
50
65
|
this.validateProps(this._props);
|
|
51
66
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this._metadata = (0, _meta_1.getModelMetadata)(this.constructor);
|
|
55
|
-
}
|
|
56
|
-
return this._metadata;
|
|
57
|
-
}
|
|
58
|
-
modelName() {
|
|
59
|
-
return this.getModelMetadata().name;
|
|
67
|
+
propsIsEmpty() {
|
|
68
|
+
return this._props === ModelBase.EMPTY_PROPS;
|
|
60
69
|
}
|
|
61
70
|
props() {
|
|
62
|
-
|
|
71
|
+
if (this.propsIsEmpty())
|
|
72
|
+
return null;
|
|
73
|
+
return _.cloneDeepWith(this._props, (value) => {
|
|
63
74
|
if (ModelBase.isModel(value)) {
|
|
64
75
|
value.redefineModel();
|
|
65
76
|
return value;
|
|
@@ -67,8 +78,8 @@ class ModelBase {
|
|
|
67
78
|
});
|
|
68
79
|
}
|
|
69
80
|
initializeProps(props) {
|
|
70
|
-
if (this.
|
|
71
|
-
throw new
|
|
81
|
+
if (!this.propsIsEmpty())
|
|
82
|
+
throw new PropsInitializedError();
|
|
72
83
|
if (!this.isMutable()) {
|
|
73
84
|
this._props = props;
|
|
74
85
|
Object.freeze(this._props);
|
|
@@ -85,6 +96,4 @@ class ModelBase {
|
|
|
85
96
|
this.validate();
|
|
86
97
|
}
|
|
87
98
|
}
|
|
88
|
-
exports.ModelBase = ModelBase;
|
|
89
|
-
ModelBase.STATIC_VALUES_KEY = "__STATIC_VALUES__";
|
|
90
99
|
ModelBase.EMPTY_PROPS = {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AnyAggregate
|
|
1
|
+
import { AnyAggregate } from "./aggregate";
|
|
2
2
|
import { Id } from "./id";
|
|
3
|
-
export interface IRepository<T extends AnyAggregate
|
|
3
|
+
export interface IRepository<T extends AnyAggregate> {
|
|
4
4
|
findById(id: Id): Promise<T | null>;
|
|
5
5
|
save(instance: T): Promise<any>;
|
|
6
6
|
}
|
package/dist/core/repository.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Class } from "type-fest";
|
|
2
|
-
import { ModelBase, PropsOf } from "./model";
|
|
3
|
-
import { ClassStatic } from "../types
|
|
4
|
-
export declare
|
|
5
|
-
constructor(props:
|
|
2
|
+
import { ModelBase, Props, PropsOf } from "./model";
|
|
3
|
+
import { ClassStatic } from "../types";
|
|
4
|
+
export declare class ValueObjectBase<P extends Props> extends ModelBase<P> {
|
|
5
|
+
constructor(props: P);
|
|
6
|
+
props(): P;
|
|
6
7
|
equals<V extends AnyValueObject>(vo: V): boolean;
|
|
7
|
-
with(props: Partial<
|
|
8
|
+
with(props: Partial<P>): this;
|
|
9
|
+
}
|
|
10
|
+
export type AnyValueObject = ValueObjectBase<Props>;
|
|
11
|
+
export interface ValueObjectClass<T extends AnyValueObject = AnyValueObject> extends Class<T>, ClassStatic<typeof ValueObjectBase<PropsOf<T>>> {
|
|
12
|
+
}
|
|
13
|
+
export interface ValueObjectClassWithTypedConstructor<T extends AnyValueObject = AnyValueObject> extends Class<T, ConstructorParameters<typeof ValueObjectBase<PropsOf<T>>>> {
|
|
8
14
|
}
|
|
9
|
-
export type AnyValueObject = ValueObjectBase<any>;
|
|
10
|
-
export type ValueObjectClass<T extends AnyValueObject = AnyValueObject> = Class<T> & ClassStatic<typeof ValueObjectBase<PropsOf<T>>>;
|
|
11
|
-
export type ValueObjectClassWithTypedConstructor<T extends AnyValueObject = AnyValueObject> = Class<T, ConstructorParameters<typeof ValueObjectBase<PropsOf<T>>>>;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ValueObjectBase = void 0;
|
|
7
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const model_1 = require("./model");
|
|
9
|
-
class ValueObjectBase extends model_1.ModelBase {
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { ModelBase } from "./model";
|
|
3
|
+
export class ValueObjectBase extends ModelBase {
|
|
10
4
|
constructor(props) {
|
|
11
5
|
super();
|
|
12
6
|
this.initializeProps(props);
|
|
13
7
|
}
|
|
8
|
+
props() {
|
|
9
|
+
return super.props();
|
|
10
|
+
}
|
|
14
11
|
equals(vo) {
|
|
15
12
|
const equalsType = vo instanceof this.constructor;
|
|
16
|
-
const equalsValue = JSON.stringify(vo) === JSON.stringify(this);
|
|
13
|
+
const equalsValue = JSON.stringify(vo.props()) === JSON.stringify(this.props());
|
|
17
14
|
return equalsType && equalsValue;
|
|
18
15
|
}
|
|
19
16
|
with(props) {
|
|
20
|
-
const newProps =
|
|
17
|
+
const newProps = _.merge(this.props(), props);
|
|
21
18
|
return new this.constructor(newProps);
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
exports.ValueObjectBase = ValueObjectBase;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AnyCommand, CommandClass, CommandHandler } from "../../core";
|
|
2
|
+
export declare const Handle: <T extends AnyCommand>(commandClass: CommandClass<T, any[]>) => <U extends CommandHandler<T>>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<U>) => void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineCommandHandler, getModelName } from "../../meta";
|
|
2
|
+
export const Handle = (commandClass) => {
|
|
3
|
+
return (target, propertyKey, descriptor) => {
|
|
4
|
+
if (typeof descriptor.value === "function") {
|
|
5
|
+
const commandName = getModelName(commandClass);
|
|
6
|
+
defineCommandHandler(target, commandName, descriptor.value);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineEventApplier, getModelName } from "../../meta";
|
|
2
|
+
export const When = (eventClass) => {
|
|
3
|
+
return (target, propertyKey, descriptor) => {
|
|
4
|
+
if (typeof descriptor.value === "function") {
|
|
5
|
+
const eventName = getModelName(eventClass);
|
|
6
|
+
defineEventApplier(target, eventName, descriptor.value);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
};
|
package/dist/decorators/id.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AnyModelWithId,
|
|
2
|
-
export declare const
|
|
1
|
+
import { AnyModelWithId, IIdService, ModelClass } from "../core";
|
|
2
|
+
export declare const UseIdService: (idService: IIdService) => <T extends AnyModelWithId>(target: ModelClass<T>) => void;
|
package/dist/decorators/id.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.UseId = void 0;
|
|
4
|
-
const _meta_1 = require("../meta/index");
|
|
5
|
-
const UseId = (generator) => {
|
|
1
|
+
import { defineIdService } from "../meta";
|
|
2
|
+
export const UseIdService = (idService) => {
|
|
6
3
|
return (target) => {
|
|
7
|
-
(
|
|
4
|
+
defineIdService(target, idService);
|
|
8
5
|
};
|
|
9
6
|
};
|
|
10
|
-
exports.UseId = UseId;
|