ddd-node 9.0.0 → 9.2.1
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/dist/core/aggregate.d.ts +3 -5
- package/dist/core/aggregate.js +4 -5
- package/dist/core/entity.d.ts +4 -5
- package/dist/core/entity.js +3 -4
- 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 -3
- package/dist/core/index.js +0 -3
- package/dist/core/{command.d.ts → message/command.d.ts} +2 -3
- package/dist/core/{command.js → message/command.js} +1 -2
- package/dist/core/{event.d.ts → message/event.d.ts} +3 -5
- package/dist/core/{event.js → message/event.js} +1 -2
- 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 -3
- package/dist/core/{message.js → message/message.js} +2 -2
- package/dist/core/metadata.d.ts +6 -3
- package/dist/core/metadata.js +11 -1
- package/dist/core/model/index.d.ts +3 -0
- package/dist/core/model/index.js +19 -0
- package/dist/core/{model-type.d.ts → model/model-type.d.ts} +1 -2
- package/dist/core/model/model-with-id.d.ts +6 -0
- package/dist/core/model/model-with-id.js +16 -0
- package/dist/core/{model.d.ts → model/model.d.ts} +1 -1
- package/dist/core/{model.js → model/model.js} +1 -1
- package/dist/core/registry.d.ts +1 -2
- package/dist/core/value-object.d.ts +1 -1
- package/dist/decorators/aggregate.d.ts +1 -3
- package/dist/decorators/aggregate.js +6 -7
- package/dist/decorators/command.d.ts +1 -1
- package/dist/decorators/command.js +2 -2
- package/dist/decorators/entity.d.ts +1 -1
- package/dist/decorators/entity.js +2 -2
- package/dist/decorators/event.d.ts +1 -1
- package/dist/decorators/event.js +2 -2
- package/dist/decorators/id.d.ts +2 -0
- package/dist/decorators/id.js +11 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/dist/decorators/model.d.ts +1 -2
- package/dist/decorators/model.js +3 -4
- package/dist/decorators/value-object.d.ts +1 -1
- package/dist/decorators/value-object.js +2 -2
- package/package.json +2 -1
- package/tsconfig.json +4 -4
- package/dist/core/id.d.ts +0 -12
- package/dist/core/id.js +0 -35
- /package/dist/core/{model-type.js → model/model-type.js} +0 -0
package/dist/core/aggregate.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { Class } from "../types/
|
|
2
|
-
import { ClassStatic } from "../types/class-static";
|
|
3
|
-
import { AnyCommand } from "./command";
|
|
1
|
+
import { Class, ClassStatic } from "../types/index";
|
|
4
2
|
import { Entity, EntityMetadata } from "./entity";
|
|
5
|
-
import { AnyEvent, EventClass, EventClassWithTypedConstructor } from "./event";
|
|
6
3
|
import { Id } from "./id";
|
|
7
|
-
import {
|
|
4
|
+
import { AnyCommand, AnyEvent, EventClass, EventClassWithTypedConstructor } from "./message";
|
|
5
|
+
import { PropsOf } from "./model/model";
|
|
8
6
|
export interface AggregateBaseMetadata extends EntityMetadata {
|
|
9
7
|
version: number;
|
|
10
8
|
}
|
package/dist/core/aggregate.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AggregateES = exports.Aggregate = exports.AggregateBase = void 0;
|
|
4
|
-
const
|
|
4
|
+
const _utils_1 = require("../utils/index");
|
|
5
5
|
const entity_1 = require("./entity");
|
|
6
|
-
const id_1 = require("./id");
|
|
7
6
|
const metadata_1 = require("./metadata");
|
|
8
7
|
class AggregateBase extends entity_1.Entity {
|
|
9
8
|
constructor(metadata, props) {
|
|
@@ -27,7 +26,7 @@ class Aggregate extends AggregateBase {
|
|
|
27
26
|
}
|
|
28
27
|
static newAggregate(props, id) {
|
|
29
28
|
return new this({
|
|
30
|
-
id: id
|
|
29
|
+
id: this.id(id),
|
|
31
30
|
version: 0,
|
|
32
31
|
}, props);
|
|
33
32
|
}
|
|
@@ -61,7 +60,7 @@ class AggregateES extends AggregateBase {
|
|
|
61
60
|
}
|
|
62
61
|
static newStream(id) {
|
|
63
62
|
return new this({
|
|
64
|
-
id: id
|
|
63
|
+
id: this.id(id),
|
|
65
64
|
version: 0,
|
|
66
65
|
});
|
|
67
66
|
}
|
|
@@ -153,7 +152,7 @@ class AggregateES extends AggregateBase {
|
|
|
153
152
|
}
|
|
154
153
|
handleCommand(command) {
|
|
155
154
|
const handler = this.getHandlerForCommand(command);
|
|
156
|
-
const events = (0,
|
|
155
|
+
const events = (0, _utils_1.toArray)(handler.call(this, command));
|
|
157
156
|
events.forEach((event) => {
|
|
158
157
|
var _a;
|
|
159
158
|
event.setContext({
|
package/dist/core/entity.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { Class } from "../types/
|
|
2
|
-
import { ClassStatic } from "../types/class-static";
|
|
1
|
+
import { Class, ClassStatic } from "../types/index";
|
|
3
2
|
import { Id } from "./id";
|
|
4
|
-
import {
|
|
3
|
+
import { ModelWithId, PropsOf } from "./model";
|
|
5
4
|
export interface EntityMetadata {
|
|
6
5
|
readonly id: Id;
|
|
7
6
|
}
|
|
8
|
-
export declare class Entity<Props extends object> extends
|
|
7
|
+
export declare class Entity<Props extends object> extends ModelWithId<Props> {
|
|
9
8
|
protected readonly _id: Id;
|
|
10
9
|
constructor(metadata: EntityMetadata, props?: Props);
|
|
11
|
-
static newEntity<T extends AnyEntity>(this: EntityClassWithTypedConstructor<T>, props: PropsOf<T
|
|
10
|
+
static newEntity<T extends AnyEntity>(this: EntityClassWithTypedConstructor<T>, props: PropsOf<T>, id?: Id): T;
|
|
12
11
|
getId(): Id;
|
|
13
12
|
hasId(id: Id): boolean;
|
|
14
13
|
}
|
package/dist/core/entity.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Entity = void 0;
|
|
4
|
-
const id_1 = require("./id");
|
|
5
4
|
const model_1 = require("./model");
|
|
6
|
-
class Entity extends model_1.
|
|
5
|
+
class Entity extends model_1.ModelWithId {
|
|
7
6
|
constructor(metadata, props) {
|
|
8
7
|
super(props);
|
|
9
8
|
this._id = metadata.id;
|
|
10
9
|
}
|
|
11
|
-
static newEntity(props) {
|
|
10
|
+
static newEntity(props, id) {
|
|
12
11
|
return new this({
|
|
13
|
-
id:
|
|
12
|
+
id: this.id(id),
|
|
14
13
|
}, props);
|
|
15
14
|
}
|
|
16
15
|
getId() {
|
|
@@ -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 { IdGenerator } from "../id-generator";
|
|
3
|
+
export declare class SnowflakeGenerator extends IdGenerator {
|
|
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.IdGenerator {
|
|
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.IdGenerator {
|
|
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.IdGenerator = void 0;
|
|
4
|
+
const id_1 = require("./id");
|
|
5
|
+
class IdGenerator {
|
|
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.IdGenerator = IdGenerator;
|
|
@@ -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,13 +1,10 @@
|
|
|
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
8
|
export * from "./registry";
|
|
12
9
|
export * from "./repository";
|
|
13
10
|
export * from "./value-object";
|
package/dist/core/index.js
CHANGED
|
@@ -15,15 +15,12 @@ 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
24
|
__exportStar(require("./registry"), exports);
|
|
28
25
|
__exportStar(require("./repository"), exports);
|
|
29
26
|
__exportStar(require("./value-object"), exports);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Class } from "
|
|
2
|
-
import {
|
|
1
|
+
import { Class, ClassStatic } from "../../types/index";
|
|
2
|
+
import { PropsOf } from "../model";
|
|
3
3
|
import { Message, MessageContext, MessageMetadata } from "./message";
|
|
4
|
-
import { PropsOf } from "./model";
|
|
5
4
|
export interface CommandMetadata extends MessageMetadata {
|
|
6
5
|
}
|
|
7
6
|
export declare class Command<Props extends object> extends Message<Props> {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Command = void 0;
|
|
4
|
-
const id_1 = require("./id");
|
|
5
4
|
const message_1 = require("./message");
|
|
6
5
|
class Command extends message_1.Message {
|
|
7
6
|
constructor(metadata, props) {
|
|
@@ -9,7 +8,7 @@ class Command extends message_1.Message {
|
|
|
9
8
|
}
|
|
10
9
|
static newCommand(props, context) {
|
|
11
10
|
return new this({
|
|
12
|
-
id:
|
|
11
|
+
id: this.id(),
|
|
13
12
|
timestamp: Date.now(),
|
|
14
13
|
context,
|
|
15
14
|
}, props);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { Class } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Class, ClassStatic } from "../../types/index";
|
|
2
|
+
import { Id } from "../id";
|
|
3
|
+
import { ModelTypePattern, PropsOf } from "../model";
|
|
4
4
|
import { Message, MessageContext, MessageMetadata } from "./message";
|
|
5
|
-
import { PropsOf } from "./model";
|
|
6
|
-
import { ModelTypePattern } from "./model-type";
|
|
7
5
|
export type EventSource = Readonly<{
|
|
8
6
|
type: ModelTypePattern;
|
|
9
7
|
id: Id;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Event = void 0;
|
|
4
|
-
const id_1 = require("./id");
|
|
5
4
|
const message_1 = require("./message");
|
|
6
5
|
class Event extends message_1.Message {
|
|
7
6
|
constructor(metadata, props) {
|
|
@@ -10,7 +9,7 @@ class Event extends message_1.Message {
|
|
|
10
9
|
}
|
|
11
10
|
static newEvent(source, props, context) {
|
|
12
11
|
return new this({
|
|
13
|
-
id:
|
|
12
|
+
id: this.id(),
|
|
14
13
|
timestamp: Date.now(),
|
|
15
14
|
source,
|
|
16
15
|
context,
|
|
@@ -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 {
|
|
1
|
+
import { Id } from "../id";
|
|
2
|
+
import { ModelWithId } from "../model";
|
|
3
3
|
export interface MessageContext {
|
|
4
4
|
correlationId?: string;
|
|
5
5
|
causationId?: string;
|
|
@@ -9,7 +9,7 @@ export interface MessageMetadata {
|
|
|
9
9
|
readonly timestamp: number;
|
|
10
10
|
context?: MessageContext;
|
|
11
11
|
}
|
|
12
|
-
export declare class Message<Props extends object> extends
|
|
12
|
+
export declare class Message<Props extends object> extends ModelWithId<Props> {
|
|
13
13
|
private readonly _id;
|
|
14
14
|
private readonly _timestamp;
|
|
15
15
|
private _context?;
|
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Message = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const model_1 = require("
|
|
9
|
-
class Message extends model_1.
|
|
8
|
+
const model_1 = require("../model");
|
|
9
|
+
class Message extends model_1.ModelWithId {
|
|
10
10
|
constructor(metadata, props) {
|
|
11
11
|
var _a;
|
|
12
12
|
super(props);
|
package/dist/core/metadata.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { CommandHandler, EventApplier } from "./aggregate";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { IdGenerator } from "./id";
|
|
4
|
+
import { ModelTypePattern } from "./model";
|
|
5
|
+
import { AnyCommand, AnyEvent } from "./message";
|
|
6
6
|
export declare const MODEL_TYPE = "MODEL_TYPE";
|
|
7
7
|
export declare const defineModelType: (target: object, type: ModelTypePattern) => void;
|
|
8
8
|
export declare const getModelType: (target: object) => ModelTypePattern;
|
|
9
|
+
export declare const ID_GENERATOR = "ID_GENERATOR";
|
|
10
|
+
export declare const defineIdGenerator: (target: object, idGenerator: IdGenerator) => void;
|
|
11
|
+
export declare const getIdGenerator: (target: object) => any;
|
|
9
12
|
export declare const EVENT_APPLIERS = "EVENT_APPLIERS";
|
|
10
13
|
export declare const getEventAppliersMap: (target: object) => Map<string, EventApplier>;
|
|
11
14
|
export declare const defineEventApplier: <T extends AnyEvent>(target: object, eventType: string, applier: EventApplier<T>) => void;
|
package/dist/core/metadata.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineCommandHandler = exports.getCommandHandlersMap = exports.COMMAND_HANDLERS = exports.defineEventApplier = exports.getEventAppliersMap = exports.EVENT_APPLIERS = exports.getModelType = exports.defineModelType = exports.MODEL_TYPE = void 0;
|
|
3
|
+
exports.defineCommandHandler = exports.getCommandHandlersMap = exports.COMMAND_HANDLERS = exports.defineEventApplier = exports.getEventAppliersMap = exports.EVENT_APPLIERS = exports.getIdGenerator = exports.defineIdGenerator = exports.ID_GENERATOR = exports.getModelType = exports.defineModelType = exports.MODEL_TYPE = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
// Model type
|
|
6
6
|
exports.MODEL_TYPE = "MODEL_TYPE";
|
|
@@ -15,6 +15,16 @@ const getModelType = (target) => {
|
|
|
15
15
|
return type;
|
|
16
16
|
};
|
|
17
17
|
exports.getModelType = getModelType;
|
|
18
|
+
// Id generator
|
|
19
|
+
exports.ID_GENERATOR = "ID_GENERATOR";
|
|
20
|
+
const defineIdGenerator = (target, idGenerator) => {
|
|
21
|
+
Reflect.defineMetadata(exports.ID_GENERATOR, idGenerator, target);
|
|
22
|
+
};
|
|
23
|
+
exports.defineIdGenerator = defineIdGenerator;
|
|
24
|
+
const getIdGenerator = (target) => {
|
|
25
|
+
return Reflect.getMetadata(exports.ID_GENERATOR, target);
|
|
26
|
+
};
|
|
27
|
+
exports.getIdGenerator = getIdGenerator;
|
|
18
28
|
// Event applier map
|
|
19
29
|
exports.EVENT_APPLIERS = "EVENT_APPLIERS";
|
|
20
30
|
const getEventAppliersMap = (target) => {
|
|
@@ -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("./model"), exports);
|
|
18
|
+
__exportStar(require("./model-type"), exports);
|
|
19
|
+
__exportStar(require("./model-with-id"), exports);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Class } from "
|
|
2
|
-
import { ClassStatic } from "../types/class-static";
|
|
1
|
+
import { Class, ClassStatic } from "../../types/index";
|
|
3
2
|
export declare const seperator: "#";
|
|
4
3
|
export type ModelTypePattern<Prefix extends string = string> = `${Prefix}${typeof seperator}${string}`;
|
|
5
4
|
export declare const ModelTypePatternRegex: RegExp;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelWithId = void 0;
|
|
4
|
+
const id_1 = require("../id");
|
|
5
|
+
const metadata_1 = require("../metadata");
|
|
6
|
+
const model_1 = require("./model");
|
|
7
|
+
class ModelWithId extends model_1.Model {
|
|
8
|
+
static getIdGenerator() {
|
|
9
|
+
return (0, metadata_1.getIdGenerator)(this) || new id_1.Uuid4Generator();
|
|
10
|
+
}
|
|
11
|
+
static id(id) {
|
|
12
|
+
const generator = this.getIdGenerator();
|
|
13
|
+
return id ? generator.fromId(id) : generator.newId();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ModelWithId = ModelWithId;
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Model = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const metadata_1 = require("
|
|
8
|
+
const metadata_1 = require("../metadata");
|
|
9
9
|
class Model {
|
|
10
10
|
constructor(props) {
|
|
11
11
|
if (props)
|
package/dist/core/registry.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { AggregateClass, AggregateESClass, CommandHandler, EventApplier } from "../core/
|
|
2
|
-
import { AnyCommand, CommandClass } from "../core/command";
|
|
3
|
-
import { AnyEvent, EventClass } from "../core/event";
|
|
1
|
+
import { AggregateClass, AggregateESClass, AnyCommand, AnyEvent, CommandClass, CommandHandler, EventApplier, EventClass } from "../core/index";
|
|
4
2
|
export declare const aggregate: (name?: string) => <T extends AggregateClass | AggregateESClass>(target: T) => void;
|
|
5
3
|
export declare const applyEvent: <T extends AnyEvent>(eventClass: EventClass<T>) => <U extends EventApplier<T>>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<U>) => void;
|
|
6
4
|
export declare const handleCommand: <T extends AnyCommand>(commandClass: CommandClass<T>) => <U extends CommandHandler<T>>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<U>) => void;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handleCommand = exports.applyEvent = exports.aggregate = void 0;
|
|
4
|
-
const
|
|
5
|
-
const model_type_1 = require("../core/model-type");
|
|
4
|
+
const _core_1 = require("../core/index");
|
|
6
5
|
const model_1 = require("./model");
|
|
7
6
|
const aggregate = (name) => (target) => {
|
|
8
|
-
const aggregateType = new
|
|
7
|
+
const aggregateType = new _core_1.AggregateType(name !== null && name !== void 0 ? name : target.name);
|
|
9
8
|
(0, model_1.model)(aggregateType.value)(target);
|
|
10
9
|
};
|
|
11
10
|
exports.aggregate = aggregate;
|
|
12
11
|
const applyEvent = (eventClass) => {
|
|
13
12
|
return (target, propertyKey, descriptor) => {
|
|
14
13
|
if (typeof descriptor.value === "function") {
|
|
15
|
-
const type = (0,
|
|
16
|
-
(0,
|
|
14
|
+
const type = (0, _core_1.getModelType)(eventClass.prototype);
|
|
15
|
+
(0, _core_1.defineEventApplier)(target, type, descriptor.value);
|
|
17
16
|
}
|
|
18
17
|
};
|
|
19
18
|
};
|
|
@@ -21,8 +20,8 @@ exports.applyEvent = applyEvent;
|
|
|
21
20
|
const handleCommand = (commandClass) => {
|
|
22
21
|
return (target, propertyKey, descriptor) => {
|
|
23
22
|
if (typeof descriptor.value === "function") {
|
|
24
|
-
const type = (0,
|
|
25
|
-
(0,
|
|
23
|
+
const type = (0, _core_1.getModelType)(commandClass.prototype);
|
|
24
|
+
(0, _core_1.defineCommandHandler)(target, type, descriptor.value);
|
|
26
25
|
}
|
|
27
26
|
};
|
|
28
27
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CommandClass } from "../core/
|
|
1
|
+
import { CommandClass } from "../core/index";
|
|
2
2
|
export declare const command: (name?: string) => <T extends CommandClass>(target: T) => void;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.command = void 0;
|
|
4
|
-
const
|
|
4
|
+
const _core_1 = require("../core/index");
|
|
5
5
|
const model_1 = require("./model");
|
|
6
6
|
const command = (name) => (target) => {
|
|
7
|
-
const commandType = new
|
|
7
|
+
const commandType = new _core_1.CommandType(name !== null && name !== void 0 ? name : target.name);
|
|
8
8
|
(0, model_1.model)(commandType.value)(target);
|
|
9
9
|
};
|
|
10
10
|
exports.command = command;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EntityClass } from "../core/
|
|
1
|
+
import { EntityClass } from "../core/index";
|
|
2
2
|
export declare const entity: (name?: string) => <T extends EntityClass>(target: T) => void;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.entity = void 0;
|
|
4
|
-
const
|
|
4
|
+
const _core_1 = require("../core/index");
|
|
5
5
|
const model_1 = require("./model");
|
|
6
6
|
const entity = (name) => (target) => {
|
|
7
|
-
const entityType = new
|
|
7
|
+
const entityType = new _core_1.EntityType(name !== null && name !== void 0 ? name : target.name);
|
|
8
8
|
(0, model_1.model)(entityType.value)(target);
|
|
9
9
|
};
|
|
10
10
|
exports.entity = entity;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EventClass } from "../core/
|
|
1
|
+
import { EventClass } from "../core/index";
|
|
2
2
|
export declare const event: (name?: string) => <T extends EventClass>(target: T) => void;
|
package/dist/decorators/event.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.event = void 0;
|
|
4
|
-
const
|
|
4
|
+
const _core_1 = require("../core/index");
|
|
5
5
|
const model_1 = require("./model");
|
|
6
6
|
const event = (name) => (target) => {
|
|
7
|
-
const eventType = new
|
|
7
|
+
const eventType = new _core_1.EventType(name !== null && name !== void 0 ? name : target.name);
|
|
8
8
|
(0, model_1.model)(eventType.value)(target);
|
|
9
9
|
};
|
|
10
10
|
exports.event = event;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.id = void 0;
|
|
4
|
+
const _core_1 = require("../core/index");
|
|
5
|
+
const id = (idGenerator) => {
|
|
6
|
+
return (target) => {
|
|
7
|
+
console.log("Target", target);
|
|
8
|
+
(0, _core_1.defineIdGenerator)(target, idGenerator);
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
exports.id = id;
|
package/dist/decorators/index.js
CHANGED
|
@@ -18,5 +18,6 @@ __exportStar(require("./aggregate"), exports);
|
|
|
18
18
|
__exportStar(require("./command"), exports);
|
|
19
19
|
__exportStar(require("./entity"), exports);
|
|
20
20
|
__exportStar(require("./event"), exports);
|
|
21
|
+
__exportStar(require("./id"), exports);
|
|
21
22
|
__exportStar(require("./model"), exports);
|
|
22
23
|
__exportStar(require("./value-object"), exports);
|
package/dist/decorators/model.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.model = void 0;
|
|
4
|
-
const
|
|
5
|
-
const registry_1 = require("../core/registry");
|
|
4
|
+
const _core_1 = require("../core/index");
|
|
6
5
|
const model = (type) => {
|
|
7
6
|
return (target) => {
|
|
8
|
-
|
|
9
|
-
(0,
|
|
7
|
+
_core_1.ModelRegistry.instance().registerModel(type, target);
|
|
8
|
+
(0, _core_1.defineModelType)(target.prototype, type);
|
|
10
9
|
};
|
|
11
10
|
};
|
|
12
11
|
exports.model = model;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ValueObjectClass } from "../core/
|
|
1
|
+
import { ValueObjectClass } from "../core/index";
|
|
2
2
|
export declare const valueObject: (name?: string) => <T extends ValueObjectClass>(target: T) => void;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.valueObject = void 0;
|
|
4
|
-
const
|
|
4
|
+
const _core_1 = require("../core/index");
|
|
5
5
|
const model_1 = require("./model");
|
|
6
6
|
const valueObject = (name) => (target) => {
|
|
7
|
-
const valueObjectType = new
|
|
7
|
+
const valueObjectType = new _core_1.ValueObjectType(name !== null && name !== void 0 ? name : target.name);
|
|
8
8
|
(0, model_1.model)(valueObjectType.value)(target);
|
|
9
9
|
};
|
|
10
10
|
exports.valueObject = valueObject;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ddd-node",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.1",
|
|
4
4
|
"description": "Domain Driven Design base for NodeJs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"lodash": "^4.17.21",
|
|
32
|
+
"nodejs-snowflake": "^2.0.1",
|
|
32
33
|
"reflect-metadata": "^0.1.13",
|
|
33
34
|
"tsc-alias": "^1.8.8",
|
|
34
35
|
"uuid": "^9.0.1"
|
package/tsconfig.json
CHANGED
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
31
|
"baseUrl": "./" /* Specify the base directory to resolve non-relative module names. */,
|
|
32
32
|
"paths": {
|
|
33
|
-
"#core
|
|
34
|
-
"#decorators
|
|
35
|
-
"#utils
|
|
36
|
-
"#types
|
|
33
|
+
"#core": ["src/core/index"],
|
|
34
|
+
"#decorators": ["src/dedcorators/index"],
|
|
35
|
+
"#utils": ["src/utils/index"],
|
|
36
|
+
"#types": ["src/types/index"]
|
|
37
37
|
} /* Specify a set of entries that re-map imports to additional lookup locations. */,
|
|
38
38
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
39
39
|
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
package/dist/core/id.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare class Id {
|
|
2
|
-
private _value;
|
|
3
|
-
constructor(value: string);
|
|
4
|
-
get value(): string;
|
|
5
|
-
equals(id: Id): boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare class Uuid4 extends Id {
|
|
8
|
-
private constructor();
|
|
9
|
-
static new(): Uuid4;
|
|
10
|
-
static from(value: string): Uuid4;
|
|
11
|
-
static validate(value: string): boolean;
|
|
12
|
-
}
|
package/dist/core/id.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Uuid4 = exports.Id = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
|
-
class Id {
|
|
6
|
-
constructor(value) {
|
|
7
|
-
this._value = value;
|
|
8
|
-
}
|
|
9
|
-
get value() {
|
|
10
|
-
return this._value;
|
|
11
|
-
}
|
|
12
|
-
equals(id) {
|
|
13
|
-
return this._value === id._value;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.Id = Id;
|
|
17
|
-
class Uuid4 extends Id {
|
|
18
|
-
constructor(value) {
|
|
19
|
-
super(value);
|
|
20
|
-
}
|
|
21
|
-
static new() {
|
|
22
|
-
const newValue = (0, uuid_1.v4)();
|
|
23
|
-
return this.from(newValue);
|
|
24
|
-
}
|
|
25
|
-
static from(value) {
|
|
26
|
-
this.validate(value);
|
|
27
|
-
return new Uuid4(value);
|
|
28
|
-
}
|
|
29
|
-
static validate(value) {
|
|
30
|
-
const isUuid = (0, uuid_1.validate)(value);
|
|
31
|
-
const isV4 = (0, uuid_1.version)(value) === 4;
|
|
32
|
-
return isUuid && isV4;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.Uuid4 = Uuid4;
|
|
File without changes
|