@nestjslatam/ddd-lib 1.0.49 → 1.0.51
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/LICENSE +21 -21
- package/README.md +30 -30
- package/ddd-aggregate-root.d.ts +11 -9
- package/ddd-aggregate-root.js +20 -22
- package/ddd-aggregate-root.js.map +1 -1
- package/{ddd-entity.d.ts → ddd-core/ddd-base-classes.d.ts} +23 -6
- package/ddd-core/ddd-base-classes.js +173 -0
- package/ddd-core/ddd-base-classes.js.map +1 -0
- package/ddd-core/ddd-validators.d.ts +15 -0
- package/ddd-core/ddd-validators.js +70 -0
- package/ddd-core/ddd-validators.js.map +1 -0
- package/ddd-core/impl/of-type.js +1 -2
- package/ddd-core/impl/of-type.js.map +1 -1
- package/ddd-decorators/reflect-command.helper.js +1 -1
- package/ddd-decorators/reflect-command.helper.js.map +1 -1
- package/ddd-events/impl/domain-event-publisher.js.map +1 -1
- package/ddd-exceptions/impl/domain-unhandled-bus.exeption.d.ts +1 -1
- package/ddd-exceptions/impl/domain-unhandled-bus.exeption.js +2 -2
- package/ddd-exceptions/impl/domain-unhandled-bus.exeption.js.map +1 -1
- package/ddd-exceptions/interfaces/exception.base.js +1 -0
- package/ddd-exceptions/interfaces/exception.base.js.map +1 -1
- package/ddd-helpers/domain-object.helper.d.ts +3 -1
- package/ddd-helpers/domain-object.helper.js +8 -6
- package/ddd-helpers/domain-object.helper.js.map +1 -1
- package/ddd-ports/interfaces/domain-repository-read.interface.d.ts +1 -2
- package/ddd-ports/interfaces/domain-repository-write.interface.d.ts +1 -2
- package/ddd-validators/impl/domain-entity.validator.d.ts +1 -1
- package/ddd-validators/impl/domain-entity.validator.js +2 -2
- package/ddd-validators/impl/domain-entity.validator.js.map +1 -1
- package/ddd-validators/impl/domain-value-object.validator.d.ts +1 -1
- package/ddd-validators/impl/domain-value-object.validator.js +2 -2
- package/ddd-validators/impl/domain-value-object.validator.js.map +1 -1
- package/ddd-valueobjects/domain-audit.valueobject.d.ts +1 -1
- package/ddd-valueobjects/domain-audit.valueobject.js +2 -2
- package/ddd-valueobjects/domain-audit.valueobject.js.map +1 -1
- package/ddd-valueobjects/domain-date.valueobject.d.ts +1 -1
- package/ddd-valueobjects/domain-date.valueobject.js +2 -2
- package/ddd-valueobjects/domain-date.valueobject.js.map +1 -1
- package/ddd-valueobjects/domain-number-base.valueobject.d.ts +1 -1
- package/ddd-valueobjects/domain-number-base.valueobject.js +2 -2
- package/ddd-valueobjects/domain-number-base.valueobject.js.map +1 -1
- package/ddd-valueobjects/domain-string-base.valueobject.d.ts +1 -1
- package/ddd-valueobjects/domain-string-base.valueobject.js +2 -2
- package/ddd-valueobjects/domain-string-base.valueobject.js.map +1 -1
- package/ddd-valueobjects/domain-uid.valueobject.d.ts +7 -0
- package/ddd-valueobjects/{domain-uid-string.valueobject.js → domain-uid.valueobject.js} +8 -8
- package/ddd-valueobjects/domain-uid.valueobject.js.map +1 -0
- package/ddd-valueobjects/index.d.ts +1 -1
- package/ddd-valueobjects/index.js +1 -1
- package/ddd-valueobjects/index.js.map +1 -1
- package/ddd.module.js +8 -1
- package/ddd.module.js.map +1 -1
- package/index.d.ts +1 -2
- package/index.js +1 -2
- package/index.js.map +1 -1
- package/package.json +26 -25
- package/tsconfig.lib.tsbuildinfo +1 -1
- package/ddd-entity.js +0 -105
- package/ddd-entity.js.map +0 -1
- package/ddd-valueobject.d.ts +0 -21
- package/ddd-valueobject.js +0 -49
- package/ddd-valueobject.js.map +0 -1
- package/ddd-valueobjects/domain-uid-string.valueobject.d.ts +0 -7
- package/ddd-valueobjects/domain-uid-string.valueobject.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 NESTJS Latam
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 NESTJS Latam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
# Ddd Library
|
|
2
|
-
|
|
3
|
-
Welcome to DDD Library for NESTJS, an innovative open-source library crafted to seamlessly integrate Domain-Driven Design (DDD) principles into your NESTJS applications. This powerful library is meticulously developed with a focus on TypeScript, leveraging the robust capabilities of NESTJS and ensuring seamless compatibility with Node.js.
|
|
4
|
-
|
|
5
|
-
Domain-Driven Design has proven to be a game-changer in building scalable and maintainable applications by placing the domain at the heart of the software design process. With [Library Name], we aim to simplify the application of DDD concepts within the NESTJS framework, empowering developers to create well-architected, domain-centric solutions.
|
|
6
|
-
|
|
7
|
-
## DISCLAIMER: This library is not ready to be used in production environments
|
|
8
|
-
|
|
9
|
-
# Key Features:
|
|
10
|
-
|
|
11
|
-
- NESTJS Integration: DDD Library for NESTJS is designed from the ground up to seamlessly integrate with NESTJS, a leading framework for building efficient and scalable server-side applications with TypeScript.
|
|
12
|
-
- TypeScript Support: Take advantage of the static typing and modern features of TypeScript, enhancing the development experience and catching errors early in the development process.
|
|
13
|
-
- Node.js Compatibility: DDD Library for NESTJS is built to support Node.js, allowing you to harness the full power of JavaScript on the server side.
|
|
14
|
-
- Domain-Driven Design Principles: Embrace the core principles of DDD effortlessly. DDD Library for NESTJS provides abstractions and utilities that align with DDD concepts, allowing you to model your domain in a clear and expressive manner.
|
|
15
|
-
- Modularity and Extensibility: Enjoy a modular and extensible architecture that adapts to the complexity of your application. DDD Library for NESTJS empowers you to build scalable systems by encapsulating domain logic in a modular fashion.
|
|
16
|
-
- Community-Driven: As an open-source project, DDD Library for NESTJS thrives on community collaboration. Contribute, share your insights, and join the growing community of developers dedicated to enhancing DDD practices within NESTJS.
|
|
17
|
-
|
|
18
|
-
# Getting Started:
|
|
19
|
-
|
|
20
|
-
To start incorporating DDD principles into your NESTJS projects, DDD Library for NESTJS offers comprehensive documentation, examples, and tutorials to guide you through the implementation process. Whether you are a seasoned developer or new to DDD, our library provides the tools you need to create robust, maintainable, and scalable applications.
|
|
21
|
-
|
|
22
|
-
Explore the potential of DDD Library for NESTJS today and elevate your NESTJS projects to new heights by seamlessly integrating Domain-Driven Design into your development workflow. Together, let's build software that truly reflects the intricacies of your business domain.
|
|
23
|
-
|
|
24
|
-
### Install
|
|
25
|
-
|
|
26
|
-
`npm install @nestjslatam/ddd-lib`
|
|
27
|
-
|
|
28
|
-
### Use library
|
|
29
|
-
|
|
30
|
-
This source code include a defaultr sample where we can see in detail how use this library.
|
|
1
|
+
# Ddd Library
|
|
2
|
+
|
|
3
|
+
Welcome to DDD Library for NESTJS, an innovative open-source library crafted to seamlessly integrate Domain-Driven Design (DDD) principles into your NESTJS applications. This powerful library is meticulously developed with a focus on TypeScript, leveraging the robust capabilities of NESTJS and ensuring seamless compatibility with Node.js.
|
|
4
|
+
|
|
5
|
+
Domain-Driven Design has proven to be a game-changer in building scalable and maintainable applications by placing the domain at the heart of the software design process. With [Library Name], we aim to simplify the application of DDD concepts within the NESTJS framework, empowering developers to create well-architected, domain-centric solutions.
|
|
6
|
+
|
|
7
|
+
## DISCLAIMER: This library is not ready to be used in production environments
|
|
8
|
+
|
|
9
|
+
# Key Features:
|
|
10
|
+
|
|
11
|
+
- NESTJS Integration: DDD Library for NESTJS is designed from the ground up to seamlessly integrate with NESTJS, a leading framework for building efficient and scalable server-side applications with TypeScript.
|
|
12
|
+
- TypeScript Support: Take advantage of the static typing and modern features of TypeScript, enhancing the development experience and catching errors early in the development process.
|
|
13
|
+
- Node.js Compatibility: DDD Library for NESTJS is built to support Node.js, allowing you to harness the full power of JavaScript on the server side.
|
|
14
|
+
- Domain-Driven Design Principles: Embrace the core principles of DDD effortlessly. DDD Library for NESTJS provides abstractions and utilities that align with DDD concepts, allowing you to model your domain in a clear and expressive manner.
|
|
15
|
+
- Modularity and Extensibility: Enjoy a modular and extensible architecture that adapts to the complexity of your application. DDD Library for NESTJS empowers you to build scalable systems by encapsulating domain logic in a modular fashion.
|
|
16
|
+
- Community-Driven: As an open-source project, DDD Library for NESTJS thrives on community collaboration. Contribute, share your insights, and join the growing community of developers dedicated to enhancing DDD practices within NESTJS.
|
|
17
|
+
|
|
18
|
+
# Getting Started:
|
|
19
|
+
|
|
20
|
+
To start incorporating DDD principles into your NESTJS projects, DDD Library for NESTJS offers comprehensive documentation, examples, and tutorials to guide you through the implementation process. Whether you are a seasoned developer or new to DDD, our library provides the tools you need to create robust, maintainable, and scalable applications.
|
|
21
|
+
|
|
22
|
+
Explore the potential of DDD Library for NESTJS today and elevate your NESTJS projects to new heights by seamlessly integrating Domain-Driven Design into your development workflow. Together, let's build software that truly reflects the intricacies of your business domain.
|
|
23
|
+
|
|
24
|
+
### Install
|
|
25
|
+
|
|
26
|
+
`npm install @nestjslatam/ddd-lib`
|
|
27
|
+
|
|
28
|
+
### Use library
|
|
29
|
+
|
|
30
|
+
This source code include a defaultr sample where we can see in detail how use this library.
|
package/ddd-aggregate-root.d.ts
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
import { ITrackingProps } from './ddd-core';
|
|
2
|
-
import { DomainEntity } from './ddd-
|
|
2
|
+
import { DomainEntity } from './ddd-core/ddd-base-classes';
|
|
3
3
|
import { IDomainEvent, ISerializableEvent } from './ddd-events';
|
|
4
|
-
import {
|
|
4
|
+
import { DomainUid } from './ddd-valueobjects';
|
|
5
5
|
declare const VERSION: unique symbol;
|
|
6
6
|
declare const IS_AUTOCOMMIT_ENABLED: unique symbol;
|
|
7
7
|
export declare abstract class DomainAggregateRoot<TProps, TDomainEventBase extends IDomainEvent = IDomainEvent> extends DomainEntity<TProps> {
|
|
8
8
|
protected _domainEvents: TDomainEventBase[];
|
|
9
9
|
protected [IS_AUTOCOMMIT_ENABLED]: boolean;
|
|
10
10
|
protected [VERSION]: number;
|
|
11
|
-
constructor(id:
|
|
11
|
+
constructor(id: DomainUid, props: TProps, trackingProps: ITrackingProps);
|
|
12
12
|
get version(): number;
|
|
13
13
|
set autoCommit(value: boolean);
|
|
14
14
|
get autoCommit(): boolean;
|
|
15
15
|
protected setVersion(version: number): void;
|
|
16
16
|
loadFromHistory(history: ISerializableEvent[]): void;
|
|
17
|
-
|
|
17
|
+
private applyEvent;
|
|
18
18
|
apply<T extends TDomainEventBase = TDomainEventBase>(event: T, options?: {
|
|
19
|
-
fromHistory?: boolean;
|
|
20
19
|
skipHandler?: boolean;
|
|
21
20
|
}): void;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
protected applyNewEvent<T extends TDomainEventBase = TDomainEventBase>(event: T, options?: {
|
|
22
|
+
skipHandler?: boolean;
|
|
23
|
+
}): void;
|
|
24
|
+
protected applyEventFromHistory<T extends TDomainEventBase = TDomainEventBase>(event: T, options?: {
|
|
25
|
+
skipHandler?: boolean;
|
|
26
|
+
}): void;
|
|
27
|
+
commit(): TDomainEventBase[];
|
|
25
28
|
clearDomainEvents(): void;
|
|
26
29
|
addDomainEvent(domainEvent: TDomainEventBase): void;
|
|
27
30
|
removeDomainEvent(domainEvent: TDomainEventBase): void;
|
|
28
31
|
existsDomainEvent(domainEvent: TDomainEventBase): boolean;
|
|
29
32
|
get DomainEvents(): TDomainEventBase[];
|
|
30
|
-
uncommit(): void;
|
|
31
33
|
}
|
|
32
34
|
export {};
|
package/ddd-aggregate-root.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
var _a, _b;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.DomainAggregateRoot = void 0;
|
|
5
|
-
const
|
|
5
|
+
const ddd_base_classes_1 = require("./ddd-core/ddd-base-classes");
|
|
6
6
|
const ddd_helpers_1 = require("./ddd-helpers");
|
|
7
7
|
const VERSION = Symbol('version');
|
|
8
8
|
const IS_AUTOCOMMIT_ENABLED = Symbol();
|
|
9
|
-
class DomainAggregateRoot extends
|
|
9
|
+
class DomainAggregateRoot extends ddd_base_classes_1.DomainEntity {
|
|
10
10
|
constructor(id, props, trackingProps) {
|
|
11
11
|
super({ id, props, trackingProps });
|
|
12
12
|
this._domainEvents = [];
|
|
@@ -28,38 +28,39 @@ class DomainAggregateRoot extends ddd_entity_1.DomainEntity {
|
|
|
28
28
|
}
|
|
29
29
|
loadFromHistory(history) {
|
|
30
30
|
const domainEvents = history.map((event) => event.data);
|
|
31
|
-
domainEvents.forEach((event) => this.
|
|
31
|
+
domainEvents.forEach((event) => this.applyEventFromHistory(event, { skipHandler: false }));
|
|
32
32
|
const lastEvent = history[history.length - 1];
|
|
33
33
|
this.setVersion(lastEvent.position);
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
const isFromHistory = (typeof optionsOrIsFromHistory === 'boolean'
|
|
37
|
-
? optionsOrIsFromHistory
|
|
38
|
-
: optionsOrIsFromHistory.fromHistory) ?? false;
|
|
39
|
-
const skipHandler = typeof optionsOrIsFromHistory === 'boolean'
|
|
40
|
-
? false
|
|
41
|
-
: optionsOrIsFromHistory.skipHandler;
|
|
42
|
-
if (!isFromHistory && !this.autoCommit) {
|
|
43
|
-
this.addDomainEvent(event);
|
|
44
|
-
}
|
|
45
|
-
this.autoCommit && this.publish(event);
|
|
35
|
+
applyEvent(event, skipHandler) {
|
|
46
36
|
if (!skipHandler) {
|
|
47
37
|
const handler = ddd_helpers_1.DomainObjectHelper.getEventHandler(event);
|
|
48
38
|
handler && handler.call(this, event);
|
|
49
39
|
}
|
|
50
40
|
}
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
apply(event, options) {
|
|
42
|
+
this.applyNewEvent(event, options);
|
|
43
|
+
}
|
|
44
|
+
applyNewEvent(event, options) {
|
|
45
|
+
if (!this.autoCommit) {
|
|
46
|
+
this.addDomainEvent(event);
|
|
47
|
+
}
|
|
48
|
+
this.applyEvent(event, options?.skipHandler);
|
|
49
|
+
}
|
|
50
|
+
applyEventFromHistory(event, options) {
|
|
51
|
+
this.applyEvent(event, options?.skipHandler);
|
|
52
|
+
}
|
|
53
53
|
commit() {
|
|
54
|
-
this.
|
|
54
|
+
const events = [...this._domainEvents];
|
|
55
55
|
this.clearDomainEvents();
|
|
56
|
+
return events;
|
|
56
57
|
}
|
|
57
58
|
clearDomainEvents() {
|
|
58
59
|
this._domainEvents = [];
|
|
59
60
|
}
|
|
60
61
|
addDomainEvent(domainEvent) {
|
|
61
|
-
if (
|
|
62
|
-
|
|
62
|
+
if (this.existsDomainEvent(domainEvent)) {
|
|
63
|
+
return;
|
|
63
64
|
}
|
|
64
65
|
this._domainEvents.push(domainEvent);
|
|
65
66
|
}
|
|
@@ -78,9 +79,6 @@ class DomainAggregateRoot extends ddd_entity_1.DomainEntity {
|
|
|
78
79
|
get DomainEvents() {
|
|
79
80
|
return this._domainEvents;
|
|
80
81
|
}
|
|
81
|
-
uncommit() {
|
|
82
|
-
this._domainEvents.length = 0;
|
|
83
|
-
}
|
|
84
82
|
}
|
|
85
83
|
exports.DomainAggregateRoot = DomainAggregateRoot;
|
|
86
84
|
_a = IS_AUTOCOMMIT_ENABLED, _b = VERSION;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ddd-aggregate-root.js","sourceRoot":"","sources":["../../../libs/ddd/src/ddd-aggregate-root.ts"],"names":[],"mappings":";;;;AAEA,
|
|
1
|
+
{"version":3,"file":"ddd-aggregate-root.js","sourceRoot":"","sources":["../../../libs/ddd/src/ddd-aggregate-root.ts"],"names":[],"mappings":";;;;AAEA,kEAA2D;AAE3D,+CAAmD;AAGnD,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS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G,CAAC,CAAC,EAAE,CAAC;YACf,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAQD,iBAAiB,CAAC,WAA6B;QAC7C,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;IAOD,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;CACF;AA/KD,kDA+KC;KAnKY,qBAAqB,OAKrB,OAAO"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { BrokenRule, BrokenRuleCollection, ITrackingProps, TrackingProps } from './
|
|
2
|
-
import {
|
|
3
|
-
import { AbstractDomainValueObject } from './ddd-valueobject';
|
|
1
|
+
import { BrokenRule, BrokenRuleCollection, ITrackingProps, TrackingProps } from './';
|
|
2
|
+
import { DomainUid } from '../ddd-valueobjects';
|
|
4
3
|
export interface IDomainEntityProps<T> {
|
|
5
|
-
id:
|
|
4
|
+
id: DomainUid;
|
|
6
5
|
props: T;
|
|
7
6
|
trackingProps: TrackingProps;
|
|
8
7
|
}
|
|
@@ -16,9 +15,7 @@ export declare abstract class DomainEntity<TProps> {
|
|
|
16
15
|
private getInternalProps;
|
|
17
16
|
get propsCopy(): TProps & ITrackingProps;
|
|
18
17
|
get props(): TProps & ITrackingProps;
|
|
19
|
-
set id(id: DomainIdAsString);
|
|
20
18
|
get id(): string;
|
|
21
|
-
set trackingProps(trackingProps: ITrackingProps);
|
|
22
19
|
get trackingProps(): ITrackingProps;
|
|
23
20
|
get IsValid(): boolean;
|
|
24
21
|
get BrokenRules(): BrokenRuleCollection;
|
|
@@ -33,3 +30,23 @@ export declare abstract class DomainEntity<TProps> {
|
|
|
33
30
|
removeChild<TParent extends DomainEntity<any>, TChild extends AbstractDomainValueObject<any> | DomainEntity<any>>(parent: TParent, child: TChild, childs: Array<TChild>): Array<TChild>;
|
|
34
31
|
addChild<TParent extends DomainEntity<any>, TChild extends AbstractDomainValueObject<any> | DomainEntity<any>>(parent: TParent, child: TChild, childs: Array<TChild>): Array<TChild>;
|
|
35
32
|
}
|
|
33
|
+
export type Primitives = string | number | boolean;
|
|
34
|
+
export type Props<T> = T extends Primitives | Date ? IDomainPrimitive<T> : T;
|
|
35
|
+
export interface IDomainPrimitive<T extends Primitives | Date> {
|
|
36
|
+
value: T;
|
|
37
|
+
}
|
|
38
|
+
export declare abstract class AbstractDomainValueObject<T> {
|
|
39
|
+
protected readonly _props: Props<T>;
|
|
40
|
+
private _brokenRules;
|
|
41
|
+
private _isValid;
|
|
42
|
+
constructor(props: Props<T>);
|
|
43
|
+
get isValid(): boolean;
|
|
44
|
+
get getBrokenRules(): BrokenRuleCollection;
|
|
45
|
+
addBrokenRule(brokenRule: BrokenRule): void;
|
|
46
|
+
removeBrokenRule(brokenRule: BrokenRule): void;
|
|
47
|
+
equals(object?: AbstractDomainValueObject<T>): boolean;
|
|
48
|
+
isValueObject(obj: unknown): obj is AbstractDomainValueObject<unknown>;
|
|
49
|
+
unpack(): T;
|
|
50
|
+
protected abstract businessRules(props: Props<T>): void;
|
|
51
|
+
private guard;
|
|
52
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractDomainValueObject = exports.DomainEntity = void 0;
|
|
4
|
+
const ddd_helpers_1 = require("../ddd-helpers");
|
|
5
|
+
const ddd_validators_1 = require("./ddd-validators");
|
|
6
|
+
const ddd_exceptions_1 = require("../ddd-exceptions");
|
|
7
|
+
const _1 = require("./");
|
|
8
|
+
class DomainEntity {
|
|
9
|
+
constructor({ id, props, trackingProps }) {
|
|
10
|
+
this._brokenRules = new _1.BrokenRuleCollection();
|
|
11
|
+
this.businessRules(props);
|
|
12
|
+
this._id = id;
|
|
13
|
+
this._props = props;
|
|
14
|
+
this._trackingProps = trackingProps;
|
|
15
|
+
}
|
|
16
|
+
getInternalProps() {
|
|
17
|
+
return {
|
|
18
|
+
id: this._id,
|
|
19
|
+
...this._props,
|
|
20
|
+
...this.trackingProps,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
get propsCopy() {
|
|
24
|
+
const propsCopy = this.getInternalProps();
|
|
25
|
+
return Object.freeze(propsCopy);
|
|
26
|
+
}
|
|
27
|
+
get props() {
|
|
28
|
+
return this.getInternalProps();
|
|
29
|
+
}
|
|
30
|
+
get id() {
|
|
31
|
+
return this._id.unpack();
|
|
32
|
+
}
|
|
33
|
+
get trackingProps() {
|
|
34
|
+
return this._trackingProps;
|
|
35
|
+
}
|
|
36
|
+
get IsValid() {
|
|
37
|
+
return this._brokenRules.getItems().length === 0;
|
|
38
|
+
}
|
|
39
|
+
get BrokenRules() {
|
|
40
|
+
return this._brokenRules;
|
|
41
|
+
}
|
|
42
|
+
equals(object) {
|
|
43
|
+
if (this === object)
|
|
44
|
+
return true;
|
|
45
|
+
if (object === null ||
|
|
46
|
+
object === undefined ||
|
|
47
|
+
!ddd_helpers_1.DomainObjectHelper.isDomainEntity(object))
|
|
48
|
+
return false;
|
|
49
|
+
return this._id ? this._id.equals(object._id) : false;
|
|
50
|
+
}
|
|
51
|
+
toObject() {
|
|
52
|
+
const plainProps = ddd_helpers_1.DomainObjectHelper.convertPropsToObject(this._props);
|
|
53
|
+
const result = {
|
|
54
|
+
id: this._id,
|
|
55
|
+
...this.trackingProps,
|
|
56
|
+
...plainProps,
|
|
57
|
+
};
|
|
58
|
+
return Object.freeze(result);
|
|
59
|
+
}
|
|
60
|
+
markAsNew() {
|
|
61
|
+
this._trackingProps = _1.TrackingProps.setNew();
|
|
62
|
+
}
|
|
63
|
+
markAsDirty() {
|
|
64
|
+
this._trackingProps = _1.TrackingProps.setDirty();
|
|
65
|
+
}
|
|
66
|
+
markAsDeleted() {
|
|
67
|
+
this._trackingProps = _1.TrackingProps.setDeleted();
|
|
68
|
+
}
|
|
69
|
+
addBrokenRule(brokenRule) {
|
|
70
|
+
this._brokenRules.add(brokenRule);
|
|
71
|
+
}
|
|
72
|
+
removeBrokenRule(brokenRule) {
|
|
73
|
+
this._brokenRules.remove(brokenRule);
|
|
74
|
+
}
|
|
75
|
+
validate() {
|
|
76
|
+
this._brokenRules.clear();
|
|
77
|
+
this.businessRules(this._props);
|
|
78
|
+
}
|
|
79
|
+
removeChild(parent, child, childs) {
|
|
80
|
+
if (!childs)
|
|
81
|
+
childs = [];
|
|
82
|
+
const index = ddd_helpers_1.DomainObjectHelper.isDomainEntity(child)
|
|
83
|
+
? childs.findIndex((c) => ddd_helpers_1.DomainObjectHelper.isDomainEntity(c) &&
|
|
84
|
+
c.id === child.id)
|
|
85
|
+
: childs.indexOf(child);
|
|
86
|
+
if (index > -1) {
|
|
87
|
+
childs.splice(index, 1);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
parent._brokenRules.add(new _1.BrokenRule('Child', 'Child not found'));
|
|
91
|
+
}
|
|
92
|
+
return childs;
|
|
93
|
+
}
|
|
94
|
+
addChild(parent, child, childs) {
|
|
95
|
+
if (!childs)
|
|
96
|
+
childs = [];
|
|
97
|
+
const exists = ddd_helpers_1.DomainObjectHelper.isDomainEntity(child)
|
|
98
|
+
? childs.some((c) => ddd_helpers_1.DomainObjectHelper.isDomainEntity(c) &&
|
|
99
|
+
c.id === child.id)
|
|
100
|
+
: childs.includes(child);
|
|
101
|
+
if (exists) {
|
|
102
|
+
parent._brokenRules.add(new _1.BrokenRule('Child', 'Child already exists'));
|
|
103
|
+
return childs;
|
|
104
|
+
}
|
|
105
|
+
childs.push(child);
|
|
106
|
+
return childs;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.DomainEntity = DomainEntity;
|
|
110
|
+
class AbstractDomainValueObject {
|
|
111
|
+
constructor(props) {
|
|
112
|
+
this._brokenRules = new _1.BrokenRuleCollection();
|
|
113
|
+
this._isValid = true;
|
|
114
|
+
this.guard(props);
|
|
115
|
+
if (this._brokenRules.getItems().length === 0 &&
|
|
116
|
+
props !== undefined &&
|
|
117
|
+
props !== null) {
|
|
118
|
+
this.businessRules(props);
|
|
119
|
+
}
|
|
120
|
+
this._isValid = this._brokenRules.getItems().length === 0;
|
|
121
|
+
if (!this._isValid) {
|
|
122
|
+
throw new ddd_exceptions_1.BrokenRulesException(`Invalid value object ${this.constructor.name}: ${this._brokenRules.asString()}`);
|
|
123
|
+
}
|
|
124
|
+
this._props = props;
|
|
125
|
+
}
|
|
126
|
+
get isValid() {
|
|
127
|
+
return this._isValid;
|
|
128
|
+
}
|
|
129
|
+
get getBrokenRules() {
|
|
130
|
+
return this._brokenRules;
|
|
131
|
+
}
|
|
132
|
+
addBrokenRule(brokenRule) {
|
|
133
|
+
this._brokenRules.add(brokenRule);
|
|
134
|
+
}
|
|
135
|
+
removeBrokenRule(brokenRule) {
|
|
136
|
+
this._brokenRules.remove(brokenRule);
|
|
137
|
+
}
|
|
138
|
+
equals(object) {
|
|
139
|
+
if (object === null || object === undefined) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
if (object.constructor.name !== this.constructor.name) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
return JSON.stringify(this._props) === JSON.stringify(object._props);
|
|
146
|
+
}
|
|
147
|
+
isValueObject(obj) {
|
|
148
|
+
return ddd_validators_1.ValueObjectValidator.isValueObject(obj);
|
|
149
|
+
}
|
|
150
|
+
unpack() {
|
|
151
|
+
if (ddd_validators_1.ValueObjectValidator.isDomainPrimitive(this._props)) {
|
|
152
|
+
return this._props
|
|
153
|
+
.value;
|
|
154
|
+
}
|
|
155
|
+
const propsCopy = ddd_helpers_1.DomainObjectHelper.convertPropsToObject(this._props);
|
|
156
|
+
return Object.freeze(propsCopy);
|
|
157
|
+
}
|
|
158
|
+
guard(props) {
|
|
159
|
+
if (props === undefined || props === null) {
|
|
160
|
+
this.addBrokenRule(new _1.BrokenRule(this.constructor.name, 'Props cannot be undefined'));
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (ddd_validators_1.ValueObjectValidator.isNotAndObject(props)) {
|
|
164
|
+
this.addBrokenRule(new _1.BrokenRule(this.constructor.name, 'Props cannot be undefined'));
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (ddd_validators_1.ValueObjectValidator.isEmptyProps(props)) {
|
|
168
|
+
this.addBrokenRule(new _1.BrokenRule(this.constructor.name, 'Props cannot be empty'));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.AbstractDomainValueObject = AbstractDomainValueObject;
|
|
173
|
+
//# sourceMappingURL=ddd-base-classes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ddd-base-classes.js","sourceRoot":"","sources":["../../../../libs/ddd/src/ddd-core/ddd-base-classes.ts"],"names":[],"mappings":";;;AAOA,gDAAoD;AACpD,qDAAwD;AACxD,sDAAyD;AACzD,yBAKY;AAoBZ,MAAsB,YAAY;IAoBhC,YAAY,EAAE,EAAE,EAAE,KAAK,EAAE,aAAa,EAA8B;QAjB5D,iBAAY,GAAyB,IAAI,uBAAoB,EAAE,CAAC;QAkBtE,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1B,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;IAOO,gBAAgB;QACtB,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,GAAG;YACZ,GAAG,IAAI,CAAC,MAAM;YACd,GAAG,IAAI,CAAC,aAAa;SACtB,CAAC;IACJ,CAAC;IAOD,IAAI,SAAS;QACX,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAE1C,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAOD,IAAI,KAAK;QACP,OAA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,EAAE,2BAA2B,CAAC,CACnE,CAAC;YACF,OAAO;QACT,CAAC;QAGD,IAAI,qCAAoB,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/C,IAAI,CAAC,aAAa,CAChB,IAAI,aAAU,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,2BAA2B,CAAC,CACnE,CAAC;YACF,OAAO;QACT,CAAC;QAGD,IAAI,qCAAoB,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7C,IAAI,CAAC,aAAa,CAChB,IAAI,aAAU,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAC/D,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA3JD,8DA2JC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare abstract class AbstractValidator {
|
|
2
|
+
static isNotAndObject(value: unknown): boolean;
|
|
3
|
+
static isUndefinedOrNull(value: unknown): boolean;
|
|
4
|
+
static isEmptyProps(props: unknown): boolean;
|
|
5
|
+
}
|
|
6
|
+
import { BrokenRuleCollection } from './broken-rules';
|
|
7
|
+
import { AbstractDomainValueObject, IDomainPrimitive, Primitives } from './ddd-base-classes';
|
|
8
|
+
export declare const GUARD_ERROR_MESSAGE_LENGTH = "Cannot check length of a value. Provided value is empty";
|
|
9
|
+
export declare class ValueObjectValidator extends AbstractValidator {
|
|
10
|
+
static validate<T>(props: T): BrokenRuleCollection;
|
|
11
|
+
static isInstanceOf(obj: any): boolean;
|
|
12
|
+
static equals<T>(object?: AbstractDomainValueObject<T>): boolean;
|
|
13
|
+
static isValueObject(obj: unknown): obj is AbstractDomainValueObject<unknown>;
|
|
14
|
+
static isDomainPrimitive<T>(obj: unknown): obj is IDomainPrimitive<T & (Primitives | Date)>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValueObjectValidator = exports.GUARD_ERROR_MESSAGE_LENGTH = exports.AbstractValidator = void 0;
|
|
4
|
+
class AbstractValidator {
|
|
5
|
+
static isNotAndObject(value) {
|
|
6
|
+
return typeof value !== 'object';
|
|
7
|
+
}
|
|
8
|
+
static isUndefinedOrNull(value) {
|
|
9
|
+
return typeof value === 'undefined' || value === null;
|
|
10
|
+
}
|
|
11
|
+
static isEmptyProps(props) {
|
|
12
|
+
if (this.isUndefinedOrNull(props))
|
|
13
|
+
return false;
|
|
14
|
+
if (typeof props === 'number' ||
|
|
15
|
+
typeof props === 'boolean' ||
|
|
16
|
+
props instanceof Date)
|
|
17
|
+
return false;
|
|
18
|
+
if (typeof props === 'undefined' ||
|
|
19
|
+
props === null ||
|
|
20
|
+
(props instanceof Object && !Object.keys(props).length) ||
|
|
21
|
+
props === '')
|
|
22
|
+
return true;
|
|
23
|
+
if (Array.isArray(props)) {
|
|
24
|
+
if (props.length === 0)
|
|
25
|
+
return true;
|
|
26
|
+
if (props.every((item) => this.isEmptyProps(item))) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.AbstractValidator = AbstractValidator;
|
|
34
|
+
const broken_rules_1 = require("./broken-rules");
|
|
35
|
+
const ddd_base_classes_1 = require("./ddd-base-classes");
|
|
36
|
+
exports.GUARD_ERROR_MESSAGE_LENGTH = 'Cannot check length of a value. Provided value is empty';
|
|
37
|
+
class ValueObjectValidator extends AbstractValidator {
|
|
38
|
+
static validate(props) {
|
|
39
|
+
const brokenRules = new broken_rules_1.BrokenRuleCollection();
|
|
40
|
+
if (!this.isNotAndObject(props))
|
|
41
|
+
if (this.isUndefinedOrNull(props))
|
|
42
|
+
brokenRules.add(new broken_rules_1.BrokenRule(this.constructor.name, 'Props cannot be undefined'));
|
|
43
|
+
if (!this.isEmptyProps(props))
|
|
44
|
+
brokenRules.add(new broken_rules_1.BrokenRule(this.constructor.name, 'Props cannot be empty'));
|
|
45
|
+
return brokenRules;
|
|
46
|
+
}
|
|
47
|
+
static isInstanceOf(obj) {
|
|
48
|
+
if (obj === null || obj === undefined)
|
|
49
|
+
return false;
|
|
50
|
+
if (typeof obj === 'string' || typeof obj === 'boolean')
|
|
51
|
+
return false;
|
|
52
|
+
const canConvert = obj;
|
|
53
|
+
return !!canConvert;
|
|
54
|
+
}
|
|
55
|
+
static equals(object) {
|
|
56
|
+
if (object === null || object === undefined)
|
|
57
|
+
return false;
|
|
58
|
+
return JSON.stringify(this) === JSON.stringify(object);
|
|
59
|
+
}
|
|
60
|
+
static isValueObject(obj) {
|
|
61
|
+
return obj instanceof ddd_base_classes_1.AbstractDomainValueObject;
|
|
62
|
+
}
|
|
63
|
+
static isDomainPrimitive(obj) {
|
|
64
|
+
if (!obj)
|
|
65
|
+
return false;
|
|
66
|
+
return Object.prototype.hasOwnProperty.call(obj, 'value') ? true : false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.ValueObjectValidator = ValueObjectValidator;
|
|
70
|
+
//# sourceMappingURL=ddd-validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ddd-validators.js","sourceRoot":"","sources":["../../../../libs/ddd/src/ddd-core/ddd-validators.ts"],"names":[],"mappings":";;;AAGA,MAAsB,iBAAiB;IAMrC,MAAM,CAAC,cAAc,CAAC,KAAc;QAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;IACnC,CAAC;IAOD,MAAM,CAAC,iBAAiB,CAAC,KAAc;QACrC,OAAO,OAAO,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,IAAI,CAAC;IACxD,CAAC;IAOD,MAAM,CAAC,YAAY,CAAC,KAAc;QAChC,IAAI,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAEhD,IACE,OAAO,KAAK,KAAK,QAAQ;YACzB,OAAO,KAAK,KAAK,SAAS;YA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,CAAC,YAAY,CAAC,GAAQ;QAC1B,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QAEpD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QAEtE,MAAM,UAAU,GAAG,GAAyC,CAAC;QAE7D,OAAO,CAAC,CAAC,UAAU,CAAC;IACtB,CAAC;IAOD,MAAM,CAAC,MAAM,CAAI,MAAqC;QACpD,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QAE1D,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACzD,CAAC;IAOD,MAAM,CAAC,aAAa,CAClB,GAAY;QAEZ,OAAO,GAAG,YAAY,4CAAyB,CAAC;IAClD,CAAC;IACD,MAAM,CAAC,iBAAiB,CACtB,GAAY;QAEZ,IAAI,CAAC,GAAG;YAAE,OAAO,KAAK,CAAC;QAEvB,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAC3E,CAAC;CACF;AAlED,oDAkEC"}
|
package/ddd-core/impl/of-type.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ofType =
|
|
3
|
+
exports.ofType = ofType;
|
|
4
4
|
const operators_1 = require("rxjs/operators");
|
|
5
5
|
function ofType(...types) {
|
|
6
6
|
const isInstanceOf = (event) => !!types.find((classType) => event instanceof classType);
|
|
7
7
|
return (source) => source.pipe((0, operators_1.filter)(isInstanceOf));
|
|
8
8
|
}
|
|
9
|
-
exports.ofType = ofType;
|
|
10
9
|
//# sourceMappingURL=of-type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"of-type.js","sourceRoot":"","sources":["../../../../../libs/ddd/src/ddd-core/impl/of-type.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"of-type.js","sourceRoot":"","sources":["../../../../../libs/ddd/src/ddd-core/impl/of-type.ts"],"names":[],"mappings":";;AAcA,wBAQC;AApBD,8CAAwC;AAYxC,SAAgB,MAAM,CAGpB,GAAG,KAAsB;IACzB,MAAM,YAAY,GAAG,CAAC,KAAmB,EAAoB,EAAE,CAC7D,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,KAAK,YAAY,SAAS,CAAC,CAAC;IAC1D,OAAO,CAAC,MAA0B,EAAuB,EAAE,CACzD,MAAM,CAAC,IAAI,CAAC,IAAA,kBAAM,EAAC,YAAY,CAAC,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -5,7 +5,7 @@ const _1 = require(".");
|
|
|
5
5
|
const ddd_exceptions_1 = require("../ddd-exceptions");
|
|
6
6
|
class ReflectCommandHelper {
|
|
7
7
|
static getCommandId(command) {
|
|
8
|
-
const
|
|
8
|
+
const commandType = command.constructor;
|
|
9
9
|
const commandMetadata = Reflect.getMetadata(_1.DOMAIN_COMMAND_METADATA, commandType);
|
|
10
10
|
if (!commandMetadata) {
|
|
11
11
|
throw new ddd_exceptions_1.DomainCommandHandlerNotFoundException(commandType.name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reflect-command.helper.js","sourceRoot":"","sources":["../../../../libs/ddd/src/ddd-decorators/reflect-command.helper.ts"],"names":[],"mappings":";;;AACA,wBAA6E;AAC7E,sDAA0E;AAU1E,MAAa,oBAAoB;IAQ/B,MAAM,CAAC,YAAY,CAAC,OAAuB;QACzC,MAAM,
|
|
1
|
+
{"version":3,"file":"reflect-command.helper.js","sourceRoot":"","sources":["../../../../libs/ddd/src/ddd-decorators/reflect-command.helper.ts"],"names":[],"mappings":";;;AACA,wBAA6E;AAC7E,sDAA0E;AAU1E,MAAa,oBAAoB;IAQ/B,MAAM,CAAC,YAAY,CAAC,OAAuB;QACzC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QAExC,MAAM,eAAe,GAA2B,OAAO,CAAC,WAAW,CACjE,0BAAuB,EACvB,WAAW,CACc,CAAC;QAE5B,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,MAAM,IAAI,sDAAqC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACpE,CAAC;QAED,OAAO,eAAe,CAAC,EAAE,CAAC;IAC5B,CAAC;IASD,MAAM,CAAC,gBAAgB,CAAC,OAA2B;QACjD,MAAM,OAAO,GAAyB,OAAO,CAAC,WAAW,CACvD,kCAA+B,EAC/B,OAAO,CACgB,CAAC;QAE1B,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,sDAAqC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChE,CAAC;QAED,MAAM,eAAe,GAA2B,OAAO,CAAC,WAAW,CACjE,0BAAuB,EACvB,OAAO,CACkB,CAAC;QAE5B,OAAO,eAAe,CAAC,EAAE,CAAC;IAC5B,CAAC;CACF;AA/CD,oDA+CC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain-event-publisher.js","sourceRoot":"","sources":["../../../../../libs/ddd/src/ddd-events/impl/domain-event-publisher.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2CAA4C;AAG5C,yDAAoD;AAQ7C,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAG/B,YAA6B,QAAyC;QAAzC,aAAQ,GAAR,QAAQ,CAAiC;IAAG,CAAC;IAO1E,iBAAiB,CAEf,QAAW;QACX,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,OAAO,KAAM,SAAQ,QAAQ;YACjB,aAAa,CAAC,KAAU;YAElC,CAAC;YAC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IAChB,CAAC;CACF,CAAA;AA9CY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;qCAI4B,iCAAc;GAH1C,oBAAoB,CA8ChC"}
|
|
@@ -4,7 +4,7 @@ import { Observable } from 'rxjs';
|
|
|
4
4
|
import { IDomainEvent } from '../../ddd-events';
|
|
5
5
|
import { IUnhandledExceptionPublisher, UnhandledExceptionInfo } from '../interfaces';
|
|
6
6
|
import { IDomainCommand } from '../../ddd-commands';
|
|
7
|
-
import { ObservableBus } from '../../ddd-core';
|
|
7
|
+
import { ObservableBus } from '../../ddd-core/impl/observable-bus';
|
|
8
8
|
export declare class UnhandledExceptionDomainBus<Cause = IDomainEvent | IDomainCommand> extends ObservableBus<UnhandledExceptionInfo<Cause>> {
|
|
9
9
|
private _publisher;
|
|
10
10
|
constructor();
|