ddd-node 13.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.js → aggregate/event-sourced-aggregate.js} +28 -77
- 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 +4 -4
- package/dist/core/entity.js +2 -6
- package/dist/core/enum.d.ts +3 -2
- package/dist/core/enum.js +9 -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 +8 -5
- package/dist/core/message/command.js +10 -9
- package/dist/core/message/event.d.ts +9 -7
- package/dist/core/message/event.js +9 -11
- package/dist/core/message/index.js +3 -19
- package/dist/core/message/message.d.ts +6 -2
- 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 +7 -7
- package/dist/core/model/model-with-id.js +8 -12
- package/dist/core/model/model.d.ts +16 -14
- package/dist/core/model/model.js +24 -33
- package/dist/core/repository.d.ts +2 -2
- package/dist/core/repository.js +1 -2
- package/dist/core/value-object.d.ts +4 -3
- package/dist/core/value-object.js +8 -12
- package/dist/decorators/{aggregate → aggregate-es}/handle.d.ts +1 -1
- package/dist/decorators/aggregate-es/handle.js +9 -0
- package/dist/decorators/aggregate-es/index.js +2 -0
- package/dist/decorators/{aggregate → aggregate-es}/when.d.ts +1 -1
- 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 -2
- package/dist/decorators/model/enum.js +3 -7
- package/dist/decorators/model/index.js +5 -21
- package/dist/decorators/model/model-name.d.ts +2 -2
- package/dist/decorators/model/model-name.js +3 -7
- package/dist/decorators/model/prop.d.ts +1 -1
- package/dist/decorators/model/prop.js +3 -7
- package/dist/decorators/model/static.d.ts +3 -3
- package/dist/decorators/model/static.js +4 -8
- package/dist/decorators/model/validator.d.ts +3 -3
- package/dist/decorators/model/validator.js +3 -7
- 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.js +1 -17
- package/dist/meta/helpers/static-value.d.ts +1 -1
- package/dist/meta/helpers/static-value.js +1 -5
- package/dist/meta/id.metadata.d.ts +4 -4
- package/dist/meta/id.metadata.js +10 -10
- package/dist/meta/index.js +4 -20
- package/dist/meta/model.metadata.d.ts +1 -1
- package/dist/meta/model.metadata.js +22 -37
- 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 -71
- 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.js +0 -13
- package/dist/decorators/aggregate/index.js +0 -18
- package/dist/decorators/aggregate/when.js +0 -13
- /package/dist/decorators/{aggregate → aggregate-es}/index.d.ts +0 -0
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { ClassStatic } from "../../types
|
|
1
|
+
import { ClassStatic } from "../../types";
|
|
2
2
|
import { Class } from "type-fest";
|
|
3
3
|
import { Props, PropsOf } from "../model";
|
|
4
4
|
import { MessageBase, MessageContext, MessageMetadata } from "./message";
|
|
5
|
-
export interface CommandMetadata extends MessageMetadata {
|
|
5
|
+
export interface CommandMetadata extends Omit<MessageMetadata, "messageType"> {
|
|
6
6
|
}
|
|
7
|
-
export declare
|
|
7
|
+
export declare class CommandBase<P extends Props> extends MessageBase<P> {
|
|
8
|
+
static readonly COMMAND_MESSAGE_TYPE = "command";
|
|
9
|
+
private _commandType;
|
|
8
10
|
constructor(metadata: CommandMetadata, props: P);
|
|
9
|
-
static newCommand<T extends AnyCommand>(this: CommandClassWithTypedConstructor<T>, props: PropsOf<T>, context?: MessageContext): T;
|
|
11
|
+
static newCommand<T extends AnyCommand>(this: CommandClassWithTypedConstructor<T>, props: PropsOf<T>, context?: MessageContext, timestamp?: number): T;
|
|
12
|
+
getCommandType(): void;
|
|
10
13
|
}
|
|
11
|
-
export type AnyCommand = CommandBase<
|
|
14
|
+
export type AnyCommand = CommandBase<Props>;
|
|
12
15
|
export interface CommandClass<T extends AnyCommand = AnyCommand, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof CommandBase<PropsOf<T>>> {
|
|
13
16
|
}
|
|
14
17
|
export interface CommandClassWithTypedConstructor<T extends AnyCommand = AnyCommand> extends 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,4 +1,4 @@
|
|
|
1
|
-
import { ClassStatic } from "../../types
|
|
1
|
+
import { ClassStatic } from "../../types";
|
|
2
2
|
import { Class } from "type-fest";
|
|
3
3
|
import { Id } from "../id";
|
|
4
4
|
import { Props, PropsOf } from "../model";
|
|
@@ -8,21 +8,23 @@ export type EventSource = Readonly<{
|
|
|
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;
|
|
17
|
+
private readonly _eventType;
|
|
16
18
|
constructor(metadata: EventMetadata, props: P);
|
|
17
|
-
static newEvent<T extends AnyEvent>(this: EventClassWithTypedConstructor<T>, source: EventSource, props: PropsOf<T>, context?: MessageContext): T;
|
|
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;
|
|
24
26
|
}
|
|
25
|
-
export type AnyEvent = EventBase<
|
|
27
|
+
export type AnyEvent = EventBase<Props>;
|
|
26
28
|
export interface EventClass<T extends AnyEvent = AnyEvent, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof EventBase<PropsOf<T>>> {
|
|
27
29
|
}
|
|
28
30
|
export interface EventClassWithTypedConstructor<T extends AnyEvent = AnyEvent> extends 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";
|
|
@@ -6,13 +6,17 @@ export interface MessageContext {
|
|
|
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
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
|
|
1
|
+
import { Id } from "../id";
|
|
2
2
|
import { ModelBase, Props } from "./model";
|
|
3
|
-
export declare
|
|
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
|
-
id(): Id
|
|
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,20 +1,17 @@
|
|
|
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;
|
|
@@ -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,35 +1,37 @@
|
|
|
1
|
-
import { ClassStatic } from "../../types/index";
|
|
2
1
|
import { Class } from "type-fest";
|
|
2
|
+
import { ClassStatic } from "../../types";
|
|
3
3
|
export type PropKey = string | symbol;
|
|
4
4
|
export interface Props {
|
|
5
5
|
[key: PropKey]: any;
|
|
6
6
|
}
|
|
7
|
+
export type EmptyProps = {
|
|
8
|
+
[key: PropKey]: never;
|
|
9
|
+
};
|
|
7
10
|
export declare class ModelBase<P extends Props> {
|
|
8
|
-
static readonly EMPTY_PROPS:
|
|
11
|
+
static readonly EMPTY_PROPS: EmptyProps;
|
|
9
12
|
protected _props: P;
|
|
10
13
|
static isModel(model: any): model is AnyModel;
|
|
11
14
|
static mutable(): boolean;
|
|
12
15
|
static modelName<T extends AnyModel>(this: ModelClass<T>): string;
|
|
13
|
-
static propsValidator<T extends AnyModel>(this: ModelClass<T>): import("../../meta
|
|
14
|
-
static ownStaticValues<T extends AnyModel>(this: ModelClass<T>): Map<string | symbol, import("../../meta
|
|
15
|
-
static ownPropsMap(): import("../../meta
|
|
16
|
-
static propsMap(): import("../../meta
|
|
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>>;
|
|
17
20
|
constructor();
|
|
18
21
|
private redefineModel;
|
|
19
|
-
protected get
|
|
20
|
-
protected get _type(): ModelClass<this>;
|
|
22
|
+
protected get currentModelType(): ModelClass<this>;
|
|
21
23
|
isMutable(): boolean;
|
|
22
24
|
modelName(): string;
|
|
23
|
-
propsValidator(): import("../../meta
|
|
24
|
-
ownPropsMap(): import("../../meta
|
|
25
|
-
propsMap(): import("../../meta
|
|
25
|
+
propsValidator(): import("../../meta").PropsValidator<this> | undefined;
|
|
26
|
+
ownPropsMap(): import("../../meta").PropsMap<ModelBase<any>>;
|
|
27
|
+
propsMap(): import("../../meta").PropsMap<any>;
|
|
26
28
|
validateProps(props: P): void;
|
|
27
29
|
validate(): void;
|
|
28
|
-
|
|
30
|
+
propsIsEmpty(): boolean;
|
|
31
|
+
props(): P | null;
|
|
29
32
|
protected initializeProps(props: P): void;
|
|
30
33
|
}
|
|
31
|
-
export type AnyModel = ModelBase<
|
|
34
|
+
export type AnyModel = ModelBase<Props>;
|
|
32
35
|
export type PropsOf<T extends AnyModel> = T extends ModelBase<infer P extends Props> ? P : never;
|
|
33
36
|
export interface ModelClass<T extends AnyModel = AnyModel> extends Class<T>, ClassStatic<typeof ModelBase<PropsOf<T>>> {
|
|
34
37
|
}
|
|
35
|
-
export type EmptyProps = {};
|
package/dist/core/model/model.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
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 {
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { getModelName, getOwnPropsMap, getOwnStaticValues, getPropsMap, getPropsValidator, } from "../../meta";
|
|
3
|
+
import { PropsInitializedError } from "./errors";
|
|
4
|
+
export class ModelBase {
|
|
10
5
|
static isModel(model) {
|
|
11
6
|
return model instanceof ModelBase;
|
|
12
7
|
}
|
|
@@ -14,19 +9,19 @@ class ModelBase {
|
|
|
14
9
|
return false;
|
|
15
10
|
}
|
|
16
11
|
static modelName() {
|
|
17
|
-
return
|
|
12
|
+
return getModelName(this);
|
|
18
13
|
}
|
|
19
14
|
static propsValidator() {
|
|
20
|
-
return
|
|
15
|
+
return getPropsValidator(this);
|
|
21
16
|
}
|
|
22
17
|
static ownStaticValues() {
|
|
23
|
-
return
|
|
18
|
+
return getOwnStaticValues(this);
|
|
24
19
|
}
|
|
25
20
|
static ownPropsMap() {
|
|
26
|
-
return
|
|
21
|
+
return getOwnPropsMap(this.prototype);
|
|
27
22
|
}
|
|
28
23
|
static propsMap() {
|
|
29
|
-
return
|
|
24
|
+
return getPropsMap(this.prototype);
|
|
30
25
|
}
|
|
31
26
|
constructor() {
|
|
32
27
|
this._props = ModelBase.EMPTY_PROPS;
|
|
@@ -38,35 +33,28 @@ class ModelBase {
|
|
|
38
33
|
configurable: true,
|
|
39
34
|
enumerable: true,
|
|
40
35
|
get() {
|
|
41
|
-
|
|
42
|
-
return (_a = this._props) === null || _a === void 0 ? void 0 : _a[propKeyTarget];
|
|
43
|
-
},
|
|
44
|
-
set() {
|
|
45
|
-
throw new Error(`Cannot set "${key.toString()}"`);
|
|
36
|
+
return this._props?.[propKeyTarget];
|
|
46
37
|
},
|
|
47
38
|
});
|
|
48
39
|
});
|
|
49
40
|
}
|
|
50
|
-
get
|
|
51
|
-
return Reflect.getPrototypeOf(this);
|
|
52
|
-
}
|
|
53
|
-
get _type() {
|
|
41
|
+
get currentModelType() {
|
|
54
42
|
return this.constructor;
|
|
55
43
|
}
|
|
56
44
|
isMutable() {
|
|
57
|
-
return this.
|
|
45
|
+
return this.currentModelType.mutable();
|
|
58
46
|
}
|
|
59
47
|
modelName() {
|
|
60
|
-
return this.
|
|
48
|
+
return this.currentModelType.modelName();
|
|
61
49
|
}
|
|
62
50
|
propsValidator() {
|
|
63
|
-
return this.
|
|
51
|
+
return this.currentModelType.propsValidator();
|
|
64
52
|
}
|
|
65
53
|
ownPropsMap() {
|
|
66
|
-
return this.
|
|
54
|
+
return this.currentModelType.ownPropsMap();
|
|
67
55
|
}
|
|
68
56
|
propsMap() {
|
|
69
|
-
return
|
|
57
|
+
return getPropsMap(Reflect.getPrototypeOf(this));
|
|
70
58
|
}
|
|
71
59
|
validateProps(props) {
|
|
72
60
|
const propsValidator = this.propsValidator();
|
|
@@ -76,18 +64,22 @@ class ModelBase {
|
|
|
76
64
|
validate() {
|
|
77
65
|
this.validateProps(this._props);
|
|
78
66
|
}
|
|
67
|
+
propsIsEmpty() {
|
|
68
|
+
return this._props === ModelBase.EMPTY_PROPS;
|
|
69
|
+
}
|
|
79
70
|
props() {
|
|
80
|
-
|
|
71
|
+
if (this.propsIsEmpty())
|
|
72
|
+
return null;
|
|
73
|
+
return _.cloneDeepWith(this._props, (value) => {
|
|
81
74
|
if (ModelBase.isModel(value)) {
|
|
82
75
|
value.redefineModel();
|
|
83
76
|
return value;
|
|
84
77
|
}
|
|
85
78
|
});
|
|
86
79
|
}
|
|
87
|
-
// initializeProps must be call in leaf class, it cannot be call in a extendable model class
|
|
88
80
|
initializeProps(props) {
|
|
89
|
-
if (this.
|
|
90
|
-
throw new
|
|
81
|
+
if (!this.propsIsEmpty())
|
|
82
|
+
throw new PropsInitializedError();
|
|
91
83
|
if (!this.isMutable()) {
|
|
92
84
|
this._props = props;
|
|
93
85
|
Object.freeze(this._props);
|
|
@@ -104,5 +96,4 @@ class ModelBase {
|
|
|
104
96
|
this.validate();
|
|
105
97
|
}
|
|
106
98
|
}
|
|
107
|
-
exports.ModelBase = ModelBase;
|
|
108
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,12 +1,13 @@
|
|
|
1
1
|
import { Class } from "type-fest";
|
|
2
2
|
import { ModelBase, Props, PropsOf } from "./model";
|
|
3
|
-
import { ClassStatic } from "../types
|
|
4
|
-
export declare
|
|
3
|
+
import { ClassStatic } from "../types";
|
|
4
|
+
export declare class ValueObjectBase<P extends Props> extends ModelBase<P> {
|
|
5
5
|
constructor(props: P);
|
|
6
|
+
props(): P;
|
|
6
7
|
equals<V extends AnyValueObject>(vo: V): boolean;
|
|
7
8
|
with(props: Partial<P>): this;
|
|
8
9
|
}
|
|
9
|
-
export type AnyValueObject = ValueObjectBase<
|
|
10
|
+
export type AnyValueObject = ValueObjectBase<Props>;
|
|
10
11
|
export interface ValueObjectClass<T extends AnyValueObject = AnyValueObject> extends Class<T>, ClassStatic<typeof ValueObjectBase<PropsOf<T>>> {
|
|
11
12
|
}
|
|
12
13
|
export interface ValueObjectClassWithTypedConstructor<T extends AnyValueObject = AnyValueObject> extends 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;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AnyCommand, CommandClass, CommandHandler } from "../../core
|
|
1
|
+
import { AnyCommand, CommandClass, CommandHandler } from "../../core";
|
|
2
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
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AnyEvent, EventApplier, EventClass } from "../../core
|
|
1
|
+
import { AnyEvent, EventApplier, EventClass } from "../../core";
|
|
2
2
|
export declare const When: <T extends AnyEvent>(eventClass: EventClass<T, any[]>) => <U extends EventApplier<T>>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<U>) => void;
|
|
@@ -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;
|
package/dist/decorators/index.js
CHANGED
|
@@ -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("./aggregate"), exports);
|
|
18
|
-
__exportStar(require("./id"), exports);
|
|
19
|
-
__exportStar(require("./model"), exports);
|
|
1
|
+
export * from "./aggregate-es";
|
|
2
|
+
export * from "./id";
|
|
3
|
+
export * from "./model";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EnumClass, EnumValue } from "../../core
|
|
2
|
-
export declare const Enum: (value: EnumValue) => <T extends EnumClass<import("../../core
|
|
1
|
+
import { EnumClass, EnumValue } from "../../core";
|
|
2
|
+
export declare const Enum: (value: EnumValue) => <T extends EnumClass<import("../../core").EnumBase>>(target: T, key: string) => void;
|