@nestjslatam/ddd-lib 1.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.
Files changed (190) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -0
  3. package/command.base.d.ts +7 -0
  4. package/command.base.js +21 -0
  5. package/command.base.js.map +1 -0
  6. package/core/broken-rules/broken-rule-collection.d.ts +11 -0
  7. package/core/broken-rules/broken-rule-collection.js +44 -0
  8. package/core/broken-rules/broken-rule-collection.js.map +1 -0
  9. package/core/broken-rules/broken-rule.d.ts +6 -0
  10. package/core/broken-rules/broken-rule.js +21 -0
  11. package/core/broken-rules/broken-rule.js.map +1 -0
  12. package/core/broken-rules/index.d.ts +2 -0
  13. package/core/broken-rules/index.js +19 -0
  14. package/core/broken-rules/index.js.map +1 -0
  15. package/core/index.d.ts +3 -0
  16. package/core/index.js +20 -0
  17. package/core/index.js.map +1 -0
  18. package/core/interfaces/command-bus.interface.d.ts +4 -0
  19. package/core/interfaces/command-bus.interface.js +3 -0
  20. package/core/interfaces/command-bus.interface.js.map +1 -0
  21. package/core/interfaces/command-handler.interface.d.ts +4 -0
  22. package/core/interfaces/command-handler.interface.js +3 -0
  23. package/core/interfaces/command-handler.interface.js.map +1 -0
  24. package/core/interfaces/command-metadata.interface.d.ts +5 -0
  25. package/core/interfaces/command-metadata.interface.js +3 -0
  26. package/core/interfaces/command-metadata.interface.js.map +1 -0
  27. package/core/interfaces/command-publisher.interface.d.ts +4 -0
  28. package/core/interfaces/command-publisher.interface.js +3 -0
  29. package/core/interfaces/command-publisher.interface.js.map +1 -0
  30. package/core/interfaces/command.interface.d.ts +5 -0
  31. package/core/interfaces/command.interface.js +3 -0
  32. package/core/interfaces/command.interface.js.map +1 -0
  33. package/core/interfaces/domain-event-bus.interface.d.ts +5 -0
  34. package/core/interfaces/domain-event-bus.interface.js +3 -0
  35. package/core/interfaces/domain-event-bus.interface.js.map +1 -0
  36. package/core/interfaces/domain-event-handler.interface.d.ts +4 -0
  37. package/core/interfaces/domain-event-handler.interface.js +3 -0
  38. package/core/interfaces/domain-event-handler.interface.js.map +1 -0
  39. package/core/interfaces/domain-event-metadata.interface.d.ts +6 -0
  40. package/core/interfaces/domain-event-metadata.interface.js +3 -0
  41. package/core/interfaces/domain-event-metadata.interface.js.map +1 -0
  42. package/core/interfaces/domain-event-publisher.interface.d.ts +5 -0
  43. package/core/interfaces/domain-event-publisher.interface.js +3 -0
  44. package/core/interfaces/domain-event-publisher.interface.js.map +1 -0
  45. package/core/interfaces/domain-event.interface.d.ts +2 -0
  46. package/core/interfaces/domain-event.interface.js +3 -0
  47. package/core/interfaces/domain-event.interface.js.map +1 -0
  48. package/core/interfaces/domain-repository-read.interface.d.ts +4 -0
  49. package/core/interfaces/domain-repository-read.interface.js +3 -0
  50. package/core/interfaces/domain-repository-read.interface.js.map +1 -0
  51. package/core/interfaces/domain-repository-transaction.interface.d.ts +4 -0
  52. package/core/interfaces/domain-repository-transaction.interface.js +3 -0
  53. package/core/interfaces/domain-repository-transaction.interface.js.map +1 -0
  54. package/core/interfaces/domain-repository-write.interface.d.ts +4 -0
  55. package/core/interfaces/domain-repository-write.interface.js +3 -0
  56. package/core/interfaces/domain-repository-write.interface.js.map +1 -0
  57. package/core/interfaces/index.d.ts +19 -0
  58. package/core/interfaces/index.js +36 -0
  59. package/core/interfaces/index.js.map +1 -0
  60. package/core/interfaces/message-source.interface.d.ts +5 -0
  61. package/core/interfaces/message-source.interface.js +3 -0
  62. package/core/interfaces/message-source.interface.js.map +1 -0
  63. package/core/interfaces/observable-bus.d.ts +6 -0
  64. package/core/interfaces/observable-bus.js +16 -0
  65. package/core/interfaces/observable-bus.js.map +1 -0
  66. package/core/interfaces/saga.interface.d.ts +4 -0
  67. package/core/interfaces/saga.interface.js +3 -0
  68. package/core/interfaces/saga.interface.js.map +1 -0
  69. package/core/interfaces/tracking.interface.d.ts +5 -0
  70. package/core/interfaces/tracking.interface.js +3 -0
  71. package/core/interfaces/tracking.interface.js.map +1 -0
  72. package/core/interfaces/unhandled-exception-info.interface.d.ts +5 -0
  73. package/core/interfaces/unhandled-exception-info.interface.js +3 -0
  74. package/core/interfaces/unhandled-exception-info.interface.js.map +1 -0
  75. package/core/interfaces/unhandled-exception-publisher.interface.d.ts +5 -0
  76. package/core/interfaces/unhandled-exception-publisher.interface.js +3 -0
  77. package/core/interfaces/unhandled-exception-publisher.interface.js.map +1 -0
  78. package/core/pagination.base.d.ts +25 -0
  79. package/core/pagination.base.js +22 -0
  80. package/core/pagination.base.js.map +1 -0
  81. package/ddd.module.d.ts +12 -0
  82. package/ddd.module.js +48 -0
  83. package/ddd.module.js.map +1 -0
  84. package/ddd.options.d.ts +7 -0
  85. package/ddd.options.js +3 -0
  86. package/ddd.options.js.map +1 -0
  87. package/ddd.service.d.ts +14 -0
  88. package/ddd.service.js +53 -0
  89. package/ddd.service.js.map +1 -0
  90. package/decorators/command-handler.decorator.d.ts +3 -0
  91. package/decorators/command-handler.decorator.js +16 -0
  92. package/decorators/command-handler.decorator.js.map +1 -0
  93. package/decorators/constants.d.ts +5 -0
  94. package/decorators/constants.js +9 -0
  95. package/decorators/constants.js.map +1 -0
  96. package/decorators/events-handler.decorator.d.ts +3 -0
  97. package/decorators/events-handler.decorator.js +18 -0
  98. package/decorators/events-handler.decorator.js.map +1 -0
  99. package/decorators/index.d.ts +4 -0
  100. package/decorators/index.js +21 -0
  101. package/decorators/index.js.map +1 -0
  102. package/decorators/saga.decorator.d.ts +2 -0
  103. package/decorators/saga.decorator.js +13 -0
  104. package/decorators/saga.decorator.js.map +1 -0
  105. package/domain-aggregate-root.d.ts +13 -0
  106. package/domain-aggregate-root.js +39 -0
  107. package/domain-aggregate-root.js.map +1 -0
  108. package/domain-command-bus.d.ts +21 -0
  109. package/domain-command-bus.js +81 -0
  110. package/domain-command-bus.js.map +1 -0
  111. package/domain-entity.d.ts +33 -0
  112. package/domain-entity.js +104 -0
  113. package/domain-entity.js.map +1 -0
  114. package/domain-event-bus.d.ts +34 -0
  115. package/domain-event-bus.js +141 -0
  116. package/domain-event-bus.js.map +1 -0
  117. package/domain-event-collection.d.ts +11 -0
  118. package/domain-event-collection.js +33 -0
  119. package/domain-event-collection.js.map +1 -0
  120. package/domain-event-publisher.d.ts +12 -0
  121. package/domain-event-publisher.js +48 -0
  122. package/domain-event-publisher.js.map +1 -0
  123. package/domain-event.d.ts +15 -0
  124. package/domain-event.js +28 -0
  125. package/domain-event.js.map +1 -0
  126. package/exceptions/constants.d.ts +6 -0
  127. package/exceptions/constants.js +10 -0
  128. package/exceptions/constants.js.map +1 -0
  129. package/exceptions/exception.base.d.ts +17 -0
  130. package/exceptions/exception.base.js +23 -0
  131. package/exceptions/exception.base.js.map +1 -0
  132. package/exceptions/exceptions.d.ts +32 -0
  133. package/exceptions/exceptions.js +71 -0
  134. package/exceptions/exceptions.js.map +1 -0
  135. package/exceptions/index.d.ts +3 -0
  136. package/exceptions/index.js +20 -0
  137. package/exceptions/index.js.map +1 -0
  138. package/helpers/datetime.helper.d.ts +3 -0
  139. package/helpers/datetime.helper.js +13 -0
  140. package/helpers/datetime.helper.js.map +1 -0
  141. package/helpers/default-command-pubsub.helper.d.ts +7 -0
  142. package/helpers/default-command-pubsub.helper.js +13 -0
  143. package/helpers/default-command-pubsub.helper.js.map +1 -0
  144. package/helpers/default-get-event-id.helper.d.ts +4 -0
  145. package/helpers/default-get-event-id.helper.js +14 -0
  146. package/helpers/default-get-event-id.helper.js.map +1 -0
  147. package/helpers/default-pubsub.helper.d.ts +8 -0
  148. package/helpers/default-pubsub.helper.js +16 -0
  149. package/helpers/default-pubsub.helper.js.map +1 -0
  150. package/helpers/default-unhandled-exception-pubsub.helper.d.ts +8 -0
  151. package/helpers/default-unhandled-exception-pubsub.helper.js +13 -0
  152. package/helpers/default-unhandled-exception-pubsub.helper.js.map +1 -0
  153. package/helpers/domain-guard.helper.d.ts +13 -0
  154. package/helpers/domain-guard.helper.js +60 -0
  155. package/helpers/domain-guard.helper.js.map +1 -0
  156. package/helpers/domain-object.helper.d.ts +1 -0
  157. package/helpers/domain-object.helper.js +37 -0
  158. package/helpers/domain-object.helper.js.map +1 -0
  159. package/helpers/index.d.ts +7 -0
  160. package/helpers/index.js +24 -0
  161. package/helpers/index.js.map +1 -0
  162. package/index.d.ts +15 -0
  163. package/index.js +32 -0
  164. package/index.js.map +1 -0
  165. package/package.json +23 -0
  166. package/tsconfig.lib.tsbuildinfo +1 -0
  167. package/unhandled-exeption-bus.d.ts +15 -0
  168. package/unhandled-exeption-bus.js +45 -0
  169. package/unhandled-exeption-bus.js.map +1 -0
  170. package/valueobjects/domain-audit.valueobject.d.ts +23 -0
  171. package/valueobjects/domain-audit.valueobject.js +59 -0
  172. package/valueobjects/domain-audit.valueobject.js.map +1 -0
  173. package/valueobjects/domain-date.valueobject.d.ts +6 -0
  174. package/valueobjects/domain-date.valueobject.js +20 -0
  175. package/valueobjects/domain-date.valueobject.js.map +1 -0
  176. package/valueobjects/domain-number.valueobject.d.ts +6 -0
  177. package/valueobjects/domain-number.valueobject.js +21 -0
  178. package/valueobjects/domain-number.valueobject.js.map +1 -0
  179. package/valueobjects/domain-string.valueobject.d.ts +6 -0
  180. package/valueobjects/domain-string.valueobject.js +21 -0
  181. package/valueobjects/domain-string.valueobject.js.map +1 -0
  182. package/valueobjects/domain-uid.valueobject.d.ts +6 -0
  183. package/valueobjects/domain-uid.valueobject.js +20 -0
  184. package/valueobjects/domain-uid.valueobject.js.map +1 -0
  185. package/valueobjects/domain-valueobject.d.ts +23 -0
  186. package/valueobjects/domain-valueobject.js +55 -0
  187. package/valueobjects/domain-valueobject.js.map +1 -0
  188. package/valueobjects/index.d.ts +6 -0
  189. package/valueobjects/index.js +23 -0
  190. package/valueobjects/index.js.map +1 -0
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DomainDateValueObject = void 0;
4
+ const helpers_1 = require("../helpers");
5
+ const domain_valueobject_1 = require("./domain-valueobject");
6
+ const core_1 = require("../core");
7
+ class DomainDateValueObject extends domain_valueobject_1.DomainValueObject {
8
+ constructor(value) {
9
+ super({ value });
10
+ this.basicBusinessRules({ value });
11
+ this.businessRules({ value });
12
+ }
13
+ basicBusinessRules(props) {
14
+ const { value } = props;
15
+ if (helpers_1.DomainGuard.isEmpty(value) || !helpers_1.DomainGuard.isDate(value))
16
+ this.addBrokenRule(new core_1.BrokenRule(this.constructor.name, 'Value must be a date'));
17
+ }
18
+ }
19
+ exports.DomainDateValueObject = DomainDateValueObject;
20
+ //# sourceMappingURL=domain-date.valueobject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-date.valueobject.js","sourceRoot":"","sources":["../../../../libs/ddd/src/valueobjects/domain-date.valueobject.ts"],"names":[],"mappings":";;;AAAA,wCAAyC;AACzC,6DAA2E;AAC3E,kCAAqC;AAErC,MAAsB,qBAAsB,SAAQ,sCAAuB;IAGzE,YAAsB,KAAW;QAC/B,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAEjB,IAAI,CAAC,kBAAkB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAEnC,IAAI,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAChC,CAAC;IAES,kBAAkB,CAAC,KAA6B;QACxD,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QAExB,IAAI,qBAAW,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,qBAAW,CAAC,MAAM,CAAC,KAAK,CAAC;YAC1D,IAAI,CAAC,aAAa,CAChB,IAAI,iBAAU,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAC9D,CAAC;IACN,CAAC;CACF;AAnBD,sDAmBC"}
@@ -0,0 +1,6 @@
1
+ import { DomainValueObject, IDomainPrimitive } from './domain-valueobject';
2
+ export declare abstract class DomainNumberValueObject extends DomainValueObject<number> {
3
+ protected abstract businessRules(props: IDomainPrimitive<number>): void;
4
+ protected constructor(value: number);
5
+ protected basicBusinessRules(props: IDomainPrimitive<number>): void;
6
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DomainNumberValueObject = void 0;
4
+ const core_1 = require("../core");
5
+ const helpers_1 = require("../helpers");
6
+ const domain_valueobject_1 = require("./domain-valueobject");
7
+ class DomainNumberValueObject extends domain_valueobject_1.DomainValueObject {
8
+ constructor(value) {
9
+ super({ value });
10
+ this.basicBusinessRules({ value });
11
+ this.businessRules({ value });
12
+ }
13
+ basicBusinessRules(props) {
14
+ const { value } = props;
15
+ if (helpers_1.DomainGuard.isEmpty(value) || !helpers_1.DomainGuard.isNumber(value)) {
16
+ this.addBrokenRule(new core_1.BrokenRule(this.constructor.name, 'Value must be a number'));
17
+ }
18
+ }
19
+ }
20
+ exports.DomainNumberValueObject = DomainNumberValueObject;
21
+ //# sourceMappingURL=domain-number.valueobject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-number.valueobject.js","sourceRoot":"","sources":["../../../../libs/ddd/src/valueobjects/domain-number.valueobject.ts"],"names":[],"mappings":";;;AAAA,kCAAqC;AACrC,wCAAyC;AACzC,6DAA2E;AAE3E,MAAsB,uBAAwB,SAAQ,sCAAyB;IAG7E,YAAsB,KAAa;QACjC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACjB,IAAI,CAAC,kBAAkB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACnC,IAAI,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAChC,CAAC;IAES,kBAAkB,CAAC,KAA+B;QAC1D,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QAExB,IAAI,qBAAW,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,qBAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YAC9D,IAAI,CAAC,aAAa,CAChB,IAAI,iBAAU,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,wBAAwB,CAAC,CAChE,CAAC;SACH;IACH,CAAC;CACF;AAlBD,0DAkBC"}
@@ -0,0 +1,6 @@
1
+ import { DomainValueObject, IDomainPrimitive } from './domain-valueobject';
2
+ export declare abstract class DomainStringValueObject extends DomainValueObject<string> {
3
+ protected abstract businessRules(props: IDomainPrimitive<string>): void;
4
+ protected constructor(value: string);
5
+ protected basicBusinessRules(props: IDomainPrimitive<string>): void;
6
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DomainStringValueObject = void 0;
4
+ const core_1 = require("../core");
5
+ const helpers_1 = require("../helpers");
6
+ const domain_valueobject_1 = require("./domain-valueobject");
7
+ class DomainStringValueObject extends domain_valueobject_1.DomainValueObject {
8
+ constructor(value) {
9
+ super({ value });
10
+ this.basicBusinessRules({ value });
11
+ this.businessRules({ value });
12
+ }
13
+ basicBusinessRules(props) {
14
+ const { value } = props;
15
+ if (helpers_1.DomainGuard.isEmpty(value) || !helpers_1.DomainGuard.isString(value)) {
16
+ this.addBrokenRule(new core_1.BrokenRule(this.constructor.name, 'Value must be a string'));
17
+ }
18
+ }
19
+ }
20
+ exports.DomainStringValueObject = DomainStringValueObject;
21
+ //# sourceMappingURL=domain-string.valueobject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-string.valueobject.js","sourceRoot":"","sources":["../../../../libs/ddd/src/valueobjects/domain-string.valueobject.ts"],"names":[],"mappings":";;;AAAA,kCAAqC;AACrC,wCAAyC;AACzC,6DAA2E;AAE3E,MAAsB,uBAAwB,SAAQ,sCAAyB;IAG7E,YAAsB,KAAa;QACjC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAEjB,IAAI,CAAC,kBAAkB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAEnC,IAAI,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAChC,CAAC;IAES,kBAAkB,CAAC,KAA+B;QAC1D,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QAExB,IAAI,qBAAW,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,qBAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YAC9D,IAAI,CAAC,aAAa,CAChB,IAAI,iBAAU,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,wBAAwB,CAAC,CAChE,CAAC;SACH;IACH,CAAC;CACF;AApBD,0DAoBC"}
@@ -0,0 +1,6 @@
1
+ import { DomainValueObject, IDomainPrimitive } from './domain-valueobject';
2
+ export declare abstract class DomainUIdValueObject extends DomainValueObject<string> {
3
+ protected abstract businessRules(props: IDomainPrimitive<string>): void;
4
+ protected constructor(value: string);
5
+ private basicBusinessRules;
6
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DomainUIdValueObject = void 0;
4
+ const core_1 = require("../core");
5
+ const helpers_1 = require("../helpers");
6
+ const domain_valueobject_1 = require("./domain-valueobject");
7
+ class DomainUIdValueObject extends domain_valueobject_1.DomainValueObject {
8
+ constructor(value) {
9
+ super({ value });
10
+ this.basicBusinessRules({ value });
11
+ this.businessRules({ value });
12
+ }
13
+ basicBusinessRules(props) {
14
+ const { value } = props;
15
+ if (!helpers_1.DomainGuard.lenghtIsEqual(value, 36))
16
+ this.addBrokenRule(new core_1.BrokenRule(this.constructor.name, 'Invalid Id lenght. The value should be a string Guid with 36 characters'));
17
+ }
18
+ }
19
+ exports.DomainUIdValueObject = DomainUIdValueObject;
20
+ //# sourceMappingURL=domain-uid.valueobject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-uid.valueobject.js","sourceRoot":"","sources":["../../../../libs/ddd/src/valueobjects/domain-uid.valueobject.ts"],"names":[],"mappings":";;;AAAA,kCAAqC;AACrC,wCAAyC;AACzC,6DAA2E;AAE3E,MAAsB,oBAAqB,SAAQ,sCAAyB;IAG1E,YAAsB,KAAa;QACjC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAEjB,IAAI,CAAC,kBAAkB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAEnC,IAAI,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAChC,CAAC;IAEO,kBAAkB,CAAC,KAA+B;QACxD,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QAExB,IAAI,CAAC,qBAAW,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,CAAC;YACvC,IAAI,CAAC,aAAa,CAChB,IAAI,iBAAU,CACZ,IAAI,CAAC,WAAW,CAAC,IAAI,EACrB,yEAAyE,CAC1E,CACF,CAAC;IACN,CAAC;CACF;AAtBD,oDAsBC"}
@@ -0,0 +1,23 @@
1
+ import { BrokenRule } from '../core';
2
+ type Primitives = string | number | boolean;
3
+ type Props<T> = T extends Primitives | Date ? IDomainPrimitive<T> : T;
4
+ export interface IDomainPrimitive<T extends Primitives | Date> {
5
+ value: T;
6
+ }
7
+ export declare abstract class DomainValueObject<T> {
8
+ protected readonly props: Props<T>;
9
+ private _brokenRules;
10
+ private _isValid;
11
+ protected abstract businessRules(props: Props<T>): void;
12
+ constructor(props: Props<T>);
13
+ isValid(): boolean;
14
+ getBrokenRules(): Array<BrokenRule>;
15
+ addBrokenRule(brokenRule: BrokenRule): void;
16
+ removeBrokenRule(brokenRule: BrokenRule): void;
17
+ static isValueObject(obj: unknown): obj is DomainValueObject<unknown>;
18
+ equals(object?: DomainValueObject<T>): boolean;
19
+ unpack(): T;
20
+ private guard;
21
+ private isDomainPrimitive;
22
+ }
23
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DomainValueObject = void 0;
4
+ const helpers_1 = require("../helpers");
5
+ const core_1 = require("../core");
6
+ class DomainValueObject {
7
+ constructor(props) {
8
+ this._brokenRules = new core_1.BrokenRuleCollection();
9
+ this._isValid = true;
10
+ this.guard(props);
11
+ this.businessRules(props);
12
+ this._isValid = this._brokenRules.getItems().length ? true : false;
13
+ this.props = props;
14
+ }
15
+ isValid() {
16
+ return this._isValid;
17
+ }
18
+ getBrokenRules() {
19
+ return this._brokenRules.getItems();
20
+ }
21
+ addBrokenRule(brokenRule) {
22
+ this._brokenRules.add(brokenRule);
23
+ }
24
+ removeBrokenRule(brokenRule) {
25
+ this._brokenRules.remove(brokenRule);
26
+ }
27
+ static isValueObject(obj) {
28
+ return obj instanceof DomainValueObject;
29
+ }
30
+ equals(object) {
31
+ if (object === null || object === undefined)
32
+ return false;
33
+ return JSON.stringify(this) === JSON.stringify(object);
34
+ }
35
+ unpack() {
36
+ if (this.isDomainPrimitive(this.props)) {
37
+ return this.props.value;
38
+ }
39
+ const propsCopy = (0, helpers_1.convertPropsToObject)(this.props);
40
+ return Object.freeze(propsCopy);
41
+ }
42
+ guard(props) {
43
+ if (helpers_1.DomainGuard.isEmpty(props) ||
44
+ (this.isDomainPrimitive(props) && helpers_1.DomainGuard.isEmpty(props.value))) {
45
+ this._brokenRules.add(new core_1.BrokenRule(this.constructor.name, 'Properties cannot be empty'));
46
+ }
47
+ }
48
+ isDomainPrimitive(obj) {
49
+ if (!obj)
50
+ this._brokenRules.add(new core_1.BrokenRule(this.constructor.name, 'Object cannot be null'));
51
+ return Object.prototype.hasOwnProperty.call(obj, 'value') ? true : false;
52
+ }
53
+ }
54
+ exports.DomainValueObject = DomainValueObject;
55
+ //# sourceMappingURL=domain-valueobject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-valueobject.js","sourceRoot":"","sources":["../../../../libs/ddd/src/valueobjects/domain-valueobject.ts"],"names":[],"mappings":";;;AAAA,wCAA+D;AAC/D,kCAA2D;AAU3D,MAAsB,iBAAiB;IAOrC,YAAY,KAAe;QALnB,iBAAY,GAAyB,IAAI,2BAAoB,EAAE,CAAC;QAMtE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QAErB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClB,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAE1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;QAEnE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;IACtC,CAAC;IAED,aAAa,CAAC,UAAsB;QAClC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;IAED,gBAAgB,CAAC,UAAsB;QACrC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,GAAY;QAC/B,OAAO,GAAG,YAAY,iBAAiB,CAAC;IAC1C,CAAC;IAEM,MAAM,CAAC,MAA6B;QACzC,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;IAEM,MAAM;QACX,IAAI,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACtC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;SACzB;QAED,MAAM,SAAS,GAAG,IAAA,8BAAoB,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEnD,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAEO,KAAK,CAAC,KAAe;QAC3B,IACE,qBAAW,CAAC,OAAO,CAAC,KAAK,CAAC;YAC1B,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,qBAAW,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EACnE;YACA,IAAI,CAAC,YAAY,CAAC,GAAG,CACnB,IAAI,iBAAU,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,4BAA4B,CAAC,CACpE,CAAC;SACH;IACH,CAAC;IAEO,iBAAiB,CACvB,GAAY;QAEZ,IAAI,CAAC,GAAG;YACN,IAAI,CAAC,YAAY,CAAC,GAAG,CACnB,IAAI,iBAAU,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAC/D,CAAC;QAEJ,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;AA3ED,8CA2EC"}
@@ -0,0 +1,6 @@
1
+ export * from './domain-audit.valueobject';
2
+ export * from './domain-date.valueobject';
3
+ export * from './domain-number.valueobject';
4
+ export * from './domain-string.valueobject';
5
+ export * from './domain-uid.valueobject';
6
+ export * from './domain-valueobject';
@@ -0,0 +1,23 @@
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("./domain-audit.valueobject"), exports);
18
+ __exportStar(require("./domain-date.valueobject"), exports);
19
+ __exportStar(require("./domain-number.valueobject"), exports);
20
+ __exportStar(require("./domain-string.valueobject"), exports);
21
+ __exportStar(require("./domain-uid.valueobject"), exports);
22
+ __exportStar(require("./domain-valueobject"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/ddd/src/valueobjects/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,4DAA0C;AAC1C,8DAA4C;AAC5C,8DAA4C;AAC5C,2DAAyC;AACzC,uDAAqC"}