@archi-code/ddd 3.0.0-alpha.1 → 3.0.0-alpha.2

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 (282) hide show
  1. package/README.md +478 -376
  2. package/SKILL.md +10 -8
  3. package/ddd-skills/archi-code-ddd/imports.md +28 -18
  4. package/ddd-skills/archi-code-ddd/layers.md +68 -53
  5. package/ddd-skills/archi-code-ddd/patterns.md +50 -43
  6. package/ddd-skills/archi-code-ddd/what-not-to-do.md +25 -18
  7. package/ddd-skills/archi-code-ddd/where-each-class-goes.md +11 -10
  8. package/ddd-skills/ddd-agregados/GUIA.md +2 -2
  9. package/ddd-skills/ddd-agregados/references/consistencia-eventual.md +5 -6
  10. package/ddd-skills/ddd-agregados/references/fabricas.md +5 -8
  11. package/ddd-skills/ddd-agregados/references/implementacion-ts.md +22 -27
  12. package/ddd-skills/ddd-arquitectura/GUIA.md +4 -4
  13. package/ddd-skills/ddd-arquitectura/assets/dependency-cruiser.cjs +13 -6
  14. package/ddd-skills/ddd-arquitectura/references/estilos-adicionales.md +2 -2
  15. package/ddd-skills/ddd-arquitectura/references/estructura-hexagonal-ts.md +70 -16
  16. package/ddd-skills/ddd-auditoria-refactorizacion/GUIA.md +1 -1
  17. package/ddd-skills/ddd-auditoria-refactorizacion/references/ejemplo-auditoria.md +9 -11
  18. package/ddd-skills/ddd-auditoria-refactorizacion/references/lista-comprobacion.md +4 -4
  19. package/ddd-skills/ddd-auditoria-refactorizacion/references/plan-migracion.md +2 -2
  20. package/ddd-skills/ddd-context-mapping/GUIA.md +5 -5
  21. package/ddd-skills/ddd-context-mapping/references/anticorrupcion-ts.md +33 -18
  22. package/ddd-skills/ddd-context-mapping/references/estilos-integracion.md +4 -7
  23. package/ddd-skills/ddd-event-sourcing-cqrs/GUIA.md +2 -2
  24. package/ddd-skills/ddd-event-sourcing-cqrs/references/event-sourcing-ts.md +32 -27
  25. package/ddd-skills/ddd-event-sourcing-cqrs/references/proyecciones-cqrs-ts.md +7 -7
  26. package/ddd-skills/ddd-eventos-dominio/GUIA.md +3 -3
  27. package/ddd-skills/ddd-eventos-dominio/references/diseno-eventos.md +15 -16
  28. package/ddd-skills/ddd-eventos-dominio/references/ejemplo-ecommerce.md +11 -11
  29. package/ddd-skills/ddd-eventos-dominio/references/publicacion-ts.md +34 -31
  30. package/ddd-skills/ddd-repositorios-persistencia/GUIA.md +7 -7
  31. package/ddd-skills/ddd-repositorios-persistencia/references/implementacion-ts.md +50 -32
  32. package/ddd-skills/ddd-repositorios-persistencia/references/tests-repositorios.md +31 -17
  33. package/ddd-skills/ddd-repositorios-persistencia/references/transacciones-ts.md +21 -14
  34. package/ddd-skills/ddd-servicios-capa-aplicacion/GUIA.md +2 -2
  35. package/ddd-skills/ddd-servicios-capa-aplicacion/references/capa-aplicacion-ts.md +19 -19
  36. package/ddd-skills/ddd-servicios-capa-aplicacion/references/ejemplo-ecommerce.md +12 -15
  37. package/ddd-skills/ddd-servicios-capa-aplicacion/references/servicios-dominio-ts.md +5 -6
  38. package/ddd-skills/ddd-value-objects-entidades/GUIA.md +3 -3
  39. package/ddd-skills/ddd-value-objects-entidades/references/entidades-ts.md +7 -9
  40. package/ddd-skills/ddd-value-objects-entidades/references/persistencia-valores.md +5 -5
  41. package/ddd-skills/ddd-value-objects-entidades/references/validacion.md +9 -9
  42. package/ddd-skills/ddd-value-objects-entidades/references/value-objects-ts.md +2 -3
  43. package/dist/cjs/application/event/listens-to.js +4 -4
  44. package/dist/cjs/{exceptions/application → application/exceptions}/aggregate-not-found.exception.d.ts +1 -1
  45. package/dist/cjs/{exceptions/application → application/exceptions}/aggregate-not-found.exception.js +4 -4
  46. package/dist/cjs/application/exceptions/application-exception-code.d.ts +7 -0
  47. package/dist/cjs/application/exceptions/application-exception-code.js +11 -0
  48. package/dist/cjs/application/exceptions/application.exception.d.ts +6 -0
  49. package/dist/cjs/application/exceptions/application.exception.js +16 -0
  50. package/dist/cjs/{exceptions/application → application/exceptions}/concurrency.exception.d.ts +1 -1
  51. package/dist/cjs/{exceptions/application → application/exceptions}/concurrency.exception.js +4 -4
  52. package/dist/cjs/{exceptions/application → application/exceptions}/not-allowed.exception.d.ts +1 -1
  53. package/dist/cjs/{exceptions/application → application/exceptions}/not-allowed.exception.js +4 -4
  54. package/dist/cjs/application/exceptions/unexpected-error.exception.d.ts +5 -0
  55. package/dist/cjs/application/exceptions/unexpected-error.exception.js +17 -0
  56. package/dist/cjs/application/index.d.ts +7 -0
  57. package/dist/cjs/application/index.js +15 -1
  58. package/dist/cjs/application/use-case/use-case.js +3 -2
  59. package/dist/{esm/domain/type/value-objects/value-objects.d.ts → cjs/application/value-object-builder/value-object-builder.d.ts} +3 -3
  60. package/dist/cjs/application/value-object-builder/value-object-builder.js +51 -0
  61. package/dist/cjs/domain/aggregate/aggregate-root.d.ts +0 -5
  62. package/dist/cjs/domain/aggregate/aggregate-root.js +4 -20
  63. package/dist/cjs/domain/entity/entity.js +2 -2
  64. package/dist/cjs/domain/event/event-base.d.ts +3 -9
  65. package/dist/cjs/domain/event/event-base.js +8 -38
  66. package/dist/cjs/domain/exceptions/domain-exception-code.d.ts +7 -0
  67. package/dist/cjs/domain/exceptions/domain-exception-code.js +11 -0
  68. package/dist/cjs/domain/exceptions/domain.exception.d.ts +6 -0
  69. package/dist/cjs/domain/exceptions/domain.exception.js +16 -0
  70. package/dist/cjs/domain/exceptions/invalid-event-definition.exception.d.ts +4 -0
  71. package/dist/cjs/domain/exceptions/invalid-event-definition.exception.js +19 -0
  72. package/dist/cjs/{exceptions/domain → domain/exceptions}/required-value.exception.js +5 -6
  73. package/dist/cjs/{exceptions/domain → domain/exceptions}/type-primitive.exception.js +5 -6
  74. package/dist/cjs/{exceptions/domain → domain/exceptions}/validation.exception.js +5 -5
  75. package/dist/cjs/domain/index.d.ts +8 -1
  76. package/dist/cjs/domain/index.js +14 -2
  77. package/dist/cjs/domain/primitive/primitive-types.d.ts +1 -3
  78. package/dist/cjs/domain/type/abstract-type.d.ts +6 -8
  79. package/dist/cjs/domain/type/abstract-type.js +15 -23
  80. package/dist/cjs/domain/type/array-type.d.ts +2 -1
  81. package/dist/cjs/domain/type/array-type.js +17 -18
  82. package/dist/cjs/domain/type/boolean-type.js +2 -2
  83. package/dist/cjs/domain/type/composite/composite-brand.d.ts +4 -0
  84. package/dist/cjs/domain/type/composite/composite-brand.js +15 -0
  85. package/dist/cjs/domain/type/composite/composite-field.d.ts +7 -8
  86. package/dist/cjs/domain/type/composite/composite-field.js +70 -47
  87. package/dist/cjs/domain/type/composite/composite-issues.d.ts +6 -0
  88. package/dist/cjs/domain/type/composite/composite-issues.js +35 -0
  89. package/dist/cjs/domain/type/composite/composite.js +15 -19
  90. package/dist/cjs/domain/type/date-type.d.ts +3 -2
  91. package/dist/cjs/domain/type/date-type.js +42 -7
  92. package/dist/cjs/domain/type/enum-type.js +2 -2
  93. package/dist/cjs/domain/type/id-type.d.ts +1 -1
  94. package/dist/cjs/domain/type/id-type.js +4 -4
  95. package/dist/cjs/domain/type/index.d.ts +2 -4
  96. package/dist/cjs/domain/type/index.js +3 -7
  97. package/dist/cjs/domain/type/json-type.d.ts +4 -0
  98. package/dist/cjs/domain/type/json-type.js +33 -4
  99. package/dist/cjs/domain/type/number-type.js +2 -2
  100. package/dist/cjs/domain/type/required/required-mark.d.ts +0 -1
  101. package/dist/cjs/domain/type/string-type.js +2 -2
  102. package/dist/cjs/domain/type/uuid-type.js +2 -2
  103. package/dist/cjs/infrastructure/event/domain-event-bus.js +9 -9
  104. package/dist/cjs/infrastructure/event/event-registry.js +9 -9
  105. package/dist/cjs/infrastructure/event/in-memory/emitter.js +2 -2
  106. package/dist/cjs/infrastructure/event/in-memory/in-memory-event-channel.d.ts +1 -1
  107. package/dist/cjs/infrastructure/event/in-memory/in-memory-event-channel.js +6 -7
  108. package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/event-delivery.exception.js +4 -4
  109. package/dist/cjs/infrastructure/exceptions/infrastructure-exception-code.d.ts +6 -0
  110. package/dist/cjs/infrastructure/exceptions/infrastructure-exception-code.js +10 -0
  111. package/dist/cjs/infrastructure/exceptions/infrastructure.exception.d.ts +6 -0
  112. package/dist/cjs/infrastructure/exceptions/infrastructure.exception.js +16 -0
  113. package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/internal-error.exception.d.ts +1 -1
  114. package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/internal-error.exception.js +4 -4
  115. package/dist/cjs/infrastructure/exceptions/kind/exception-classifier.d.ts +4 -0
  116. package/dist/cjs/infrastructure/exceptions/kind/exception-classifier.js +34 -0
  117. package/dist/cjs/infrastructure/exceptions/kind/exception-kind.d.ts +9 -0
  118. package/dist/cjs/infrastructure/exceptions/kind/exception-kind.js +13 -0
  119. package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/unknown-event.exception.js +4 -4
  120. package/dist/cjs/infrastructure/index.d.ts +7 -2
  121. package/dist/cjs/infrastructure/index.js +15 -3
  122. package/dist/cjs/infrastructure/logging/console-logger.js +2 -2
  123. package/dist/{esm → cjs/shared}/exceptions/abstract.exception.d.ts +6 -4
  124. package/dist/cjs/{exceptions → shared/exceptions}/abstract.exception.js +9 -16
  125. package/dist/cjs/shared/index.d.ts +8 -0
  126. package/dist/cjs/shared/index.js +13 -0
  127. package/dist/cjs/shared/issue-collection-error.d.ts +9 -0
  128. package/dist/cjs/shared/issue-collection-error.js +11 -0
  129. package/dist/cjs/shared/issue-collector.d.ts +8 -0
  130. package/dist/cjs/shared/issue-collector.js +41 -0
  131. package/dist/esm/application/event/listens-to.js +1 -1
  132. package/dist/esm/{exceptions/application → application/exceptions}/aggregate-not-found.exception.d.ts +1 -1
  133. package/dist/esm/application/exceptions/aggregate-not-found.exception.js +13 -0
  134. package/dist/esm/application/exceptions/application-exception-code.d.ts +7 -0
  135. package/dist/esm/application/exceptions/application-exception-code.js +8 -0
  136. package/dist/esm/application/exceptions/application.exception.d.ts +6 -0
  137. package/dist/esm/application/exceptions/application.exception.js +12 -0
  138. package/dist/esm/{exceptions/application → application/exceptions}/concurrency.exception.d.ts +1 -1
  139. package/dist/esm/{exceptions/application → application/exceptions}/concurrency.exception.js +4 -4
  140. package/dist/esm/{exceptions/application → application/exceptions}/not-allowed.exception.d.ts +1 -1
  141. package/dist/esm/application/exceptions/not-allowed.exception.js +13 -0
  142. package/dist/esm/application/exceptions/unexpected-error.exception.d.ts +5 -0
  143. package/dist/esm/application/exceptions/unexpected-error.exception.js +13 -0
  144. package/dist/esm/application/index.d.ts +7 -0
  145. package/dist/esm/application/index.js +7 -0
  146. package/dist/esm/application/use-case/use-case.js +3 -2
  147. package/dist/{cjs/domain/type/value-objects/value-objects.d.ts → esm/application/value-object-builder/value-object-builder.d.ts} +3 -3
  148. package/dist/esm/application/value-object-builder/value-object-builder.js +47 -0
  149. package/dist/esm/domain/aggregate/aggregate-root.d.ts +0 -5
  150. package/dist/esm/domain/aggregate/aggregate-root.js +4 -20
  151. package/dist/esm/domain/entity/entity.js +1 -1
  152. package/dist/esm/domain/event/event-base.d.ts +3 -9
  153. package/dist/esm/domain/event/event-base.js +8 -38
  154. package/dist/esm/domain/exceptions/domain-exception-code.d.ts +7 -0
  155. package/dist/esm/domain/exceptions/domain-exception-code.js +8 -0
  156. package/dist/esm/domain/exceptions/domain.exception.d.ts +6 -0
  157. package/dist/esm/domain/exceptions/domain.exception.js +12 -0
  158. package/dist/esm/domain/exceptions/invalid-event-definition.exception.d.ts +4 -0
  159. package/dist/esm/domain/exceptions/invalid-event-definition.exception.js +15 -0
  160. package/dist/esm/{exceptions/domain → domain/exceptions}/required-value.exception.js +4 -5
  161. package/dist/esm/{exceptions/domain → domain/exceptions}/type-primitive.exception.js +4 -5
  162. package/dist/esm/{exceptions/domain → domain/exceptions}/validation.exception.js +5 -5
  163. package/dist/esm/domain/index.d.ts +7 -0
  164. package/dist/esm/domain/index.js +6 -0
  165. package/dist/esm/domain/primitive/primitive-types.d.ts +1 -3
  166. package/dist/esm/domain/type/abstract-type.d.ts +6 -8
  167. package/dist/esm/domain/type/abstract-type.js +14 -22
  168. package/dist/esm/domain/type/array-type.d.ts +2 -1
  169. package/dist/esm/domain/type/array-type.js +16 -17
  170. package/dist/esm/domain/type/boolean-type.js +1 -1
  171. package/dist/esm/domain/type/composite/composite-brand.d.ts +4 -0
  172. package/dist/esm/domain/type/composite/composite-brand.js +11 -0
  173. package/dist/esm/domain/type/composite/composite-field.d.ts +7 -8
  174. package/dist/esm/domain/type/composite/composite-field.js +69 -46
  175. package/dist/esm/domain/type/composite/composite-issues.d.ts +6 -0
  176. package/dist/esm/domain/type/composite/composite-issues.js +31 -0
  177. package/dist/esm/domain/type/composite/composite.js +13 -17
  178. package/dist/esm/domain/type/date-type.d.ts +3 -2
  179. package/dist/esm/domain/type/date-type.js +39 -4
  180. package/dist/esm/domain/type/enum-type.js +1 -1
  181. package/dist/esm/domain/type/id-type.d.ts +1 -1
  182. package/dist/esm/domain/type/id-type.js +2 -2
  183. package/dist/esm/domain/type/index.d.ts +2 -4
  184. package/dist/esm/domain/type/index.js +1 -3
  185. package/dist/esm/domain/type/json-type.d.ts +4 -0
  186. package/dist/esm/domain/type/json-type.js +32 -3
  187. package/dist/esm/domain/type/number-type.js +1 -1
  188. package/dist/esm/domain/type/required/required-mark.d.ts +0 -1
  189. package/dist/esm/domain/type/string-type.js +1 -1
  190. package/dist/esm/domain/type/uuid-type.js +1 -1
  191. package/dist/esm/infrastructure/event/domain-event-bus.js +5 -5
  192. package/dist/esm/infrastructure/event/event-registry.js +4 -4
  193. package/dist/esm/infrastructure/event/in-memory/emitter.js +1 -1
  194. package/dist/esm/infrastructure/event/in-memory/in-memory-event-channel.d.ts +1 -1
  195. package/dist/esm/infrastructure/event/in-memory/in-memory-event-channel.js +5 -6
  196. package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/event-delivery.exception.js +4 -4
  197. package/dist/esm/infrastructure/exceptions/infrastructure-exception-code.d.ts +6 -0
  198. package/dist/esm/infrastructure/exceptions/infrastructure-exception-code.js +7 -0
  199. package/dist/esm/infrastructure/exceptions/infrastructure.exception.d.ts +6 -0
  200. package/dist/esm/infrastructure/exceptions/infrastructure.exception.js +12 -0
  201. package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/internal-error.exception.d.ts +1 -1
  202. package/dist/esm/infrastructure/exceptions/internal-error.exception.js +13 -0
  203. package/dist/esm/infrastructure/exceptions/kind/exception-classifier.d.ts +4 -0
  204. package/dist/esm/infrastructure/exceptions/kind/exception-classifier.js +30 -0
  205. package/dist/esm/infrastructure/exceptions/kind/exception-kind.d.ts +9 -0
  206. package/dist/esm/infrastructure/exceptions/kind/exception-kind.js +10 -0
  207. package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/unknown-event.exception.js +4 -4
  208. package/dist/esm/infrastructure/index.d.ts +7 -2
  209. package/dist/esm/infrastructure/index.js +7 -1
  210. package/dist/esm/infrastructure/logging/console-logger.js +1 -1
  211. package/dist/{cjs → esm/shared}/exceptions/abstract.exception.d.ts +6 -4
  212. package/dist/esm/{exceptions → shared/exceptions}/abstract.exception.js +9 -16
  213. package/dist/esm/shared/index.d.ts +8 -0
  214. package/dist/esm/shared/index.js +5 -0
  215. package/dist/esm/shared/issue-collection-error.d.ts +9 -0
  216. package/dist/esm/shared/issue-collection-error.js +7 -0
  217. package/dist/esm/shared/issue-collector.d.ts +8 -0
  218. package/dist/esm/shared/issue-collector.js +37 -0
  219. package/package.json +7 -18
  220. package/dist/cjs/domain/type/equality/value-equality.d.ts +0 -7
  221. package/dist/cjs/domain/type/equality/value-equality.js +0 -41
  222. package/dist/cjs/domain/type/immutable/immutable-date.d.ts +0 -4
  223. package/dist/cjs/domain/type/immutable/immutable-date.js +0 -37
  224. package/dist/cjs/domain/type/immutable/immutable.d.ts +0 -4
  225. package/dist/cjs/domain/type/immutable/immutable.js +0 -19
  226. package/dist/cjs/domain/type/value-objects/value-objects.js +0 -70
  227. package/dist/cjs/exceptions/application/application.exception.d.ts +0 -6
  228. package/dist/cjs/exceptions/application/application.exception.js +0 -17
  229. package/dist/cjs/exceptions/domain/domain.exception.d.ts +0 -6
  230. package/dist/cjs/exceptions/domain/domain.exception.js +0 -17
  231. package/dist/cjs/exceptions/exception-code.d.ts +0 -15
  232. package/dist/cjs/exceptions/exception-code.js +0 -19
  233. package/dist/cjs/exceptions/index.d.ts +0 -14
  234. package/dist/cjs/exceptions/index.js +0 -30
  235. package/dist/cjs/exceptions/infrastructure/infrastructure.exception.d.ts +0 -6
  236. package/dist/cjs/exceptions/infrastructure/infrastructure.exception.js +0 -17
  237. package/dist/cjs/infrastructure/http/http-error-mapper.d.ts +0 -23
  238. package/dist/cjs/infrastructure/http/http-error-mapper.js +0 -63
  239. package/dist/esm/domain/type/equality/value-equality.d.ts +0 -7
  240. package/dist/esm/domain/type/equality/value-equality.js +0 -37
  241. package/dist/esm/domain/type/immutable/immutable-date.d.ts +0 -4
  242. package/dist/esm/domain/type/immutable/immutable-date.js +0 -33
  243. package/dist/esm/domain/type/immutable/immutable.d.ts +0 -4
  244. package/dist/esm/domain/type/immutable/immutable.js +0 -15
  245. package/dist/esm/domain/type/value-objects/value-objects.js +0 -66
  246. package/dist/esm/exceptions/application/aggregate-not-found.exception.js +0 -13
  247. package/dist/esm/exceptions/application/application.exception.d.ts +0 -6
  248. package/dist/esm/exceptions/application/application.exception.js +0 -13
  249. package/dist/esm/exceptions/application/not-allowed.exception.js +0 -13
  250. package/dist/esm/exceptions/domain/domain.exception.d.ts +0 -6
  251. package/dist/esm/exceptions/domain/domain.exception.js +0 -13
  252. package/dist/esm/exceptions/exception-code.d.ts +0 -15
  253. package/dist/esm/exceptions/exception-code.js +0 -16
  254. package/dist/esm/exceptions/index.d.ts +0 -14
  255. package/dist/esm/exceptions/index.js +0 -14
  256. package/dist/esm/exceptions/infrastructure/infrastructure.exception.d.ts +0 -6
  257. package/dist/esm/exceptions/infrastructure/infrastructure.exception.js +0 -13
  258. package/dist/esm/exceptions/infrastructure/internal-error.exception.js +0 -13
  259. package/dist/esm/infrastructure/http/http-error-mapper.d.ts +0 -23
  260. package/dist/esm/infrastructure/http/http-error-mapper.js +0 -59
  261. /package/dist/cjs/{exceptions/domain → domain/exceptions}/required-value.exception.d.ts +0 -0
  262. /package/dist/cjs/{exceptions/domain → domain/exceptions}/type-primitive.exception.d.ts +0 -0
  263. /package/dist/cjs/{exceptions/domain → domain/exceptions}/validation.exception.d.ts +0 -0
  264. /package/dist/cjs/domain/type/required/{required.d.ts → required-type.d.ts} +0 -0
  265. /package/dist/cjs/domain/type/required/{required.js → required-type.js} +0 -0
  266. /package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/event-delivery.exception.d.ts +0 -0
  267. /package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/unknown-event.exception.d.ts +0 -0
  268. /package/dist/cjs/{exceptions → shared/exceptions}/brand/exception-brand.d.ts +0 -0
  269. /package/dist/cjs/{exceptions → shared/exceptions}/brand/exception-brand.js +0 -0
  270. /package/dist/cjs/{exceptions → shared/exceptions}/received/received-value.d.ts +0 -0
  271. /package/dist/cjs/{exceptions → shared/exceptions}/received/received-value.js +0 -0
  272. /package/dist/esm/{exceptions/domain → domain/exceptions}/required-value.exception.d.ts +0 -0
  273. /package/dist/esm/{exceptions/domain → domain/exceptions}/type-primitive.exception.d.ts +0 -0
  274. /package/dist/esm/{exceptions/domain → domain/exceptions}/validation.exception.d.ts +0 -0
  275. /package/dist/esm/domain/type/required/{required.d.ts → required-type.d.ts} +0 -0
  276. /package/dist/esm/domain/type/required/{required.js → required-type.js} +0 -0
  277. /package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/event-delivery.exception.d.ts +0 -0
  278. /package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/unknown-event.exception.d.ts +0 -0
  279. /package/dist/esm/{exceptions → shared/exceptions}/brand/exception-brand.d.ts +0 -0
  280. /package/dist/esm/{exceptions → shared/exceptions}/brand/exception-brand.js +0 -0
  281. /package/dist/esm/{exceptions → shared/exceptions}/received/received-value.d.ts +0 -0
  282. /package/dist/esm/{exceptions → shared/exceptions}/received/received-value.js +0 -0
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ListensTo = ListensTo;
4
- const index_1 = require("../../exceptions/index");
4
+ const application_exception_1 = require("../exceptions/application.exception");
5
5
  const LISTENED_EVENT = Symbol.for('@archi-code/ddd/listens-to.v1');
6
6
  function ListensTo(event, options) {
7
7
  return (listener) => {
8
8
  if (Object.prototype.hasOwnProperty.call(listener, LISTENED_EVENT)) {
9
- throw new index_1.ApplicationException(`${listener.name} already listens to an event`);
9
+ throw new application_exception_1.ApplicationException(`${listener.name} already listens to an event`);
10
10
  }
11
11
  const consumer = options?.consumer;
12
12
  if (typeof consumer !== 'string' || consumer.trim() === '') {
13
- throw new index_1.ApplicationException(`${listener.name} needs a consumer name: @ListensTo(<event class>, { consumer: '<name>' })`);
13
+ throw new application_exception_1.ApplicationException(`${listener.name} needs a consumer name: @ListensTo(<event class>, { consumer: '<name>' })`);
14
14
  }
15
15
  const subscription = Object.freeze({
16
16
  eventName: event.eventName,
@@ -22,7 +22,7 @@ function ListensTo(event, options) {
22
22
  ListensTo.subscriptionOf = (listener) => {
23
23
  const listenerClass = listener.constructor;
24
24
  if (!Object.prototype.hasOwnProperty.call(listenerClass, LISTENED_EVENT)) {
25
- throw new index_1.ApplicationException(`${listenerClass.name} needs @ListensTo(<event class>, { consumer: '<name>' })`);
25
+ throw new application_exception_1.ApplicationException(`${listenerClass.name} needs @ListensTo(<event class>, { consumer: '<name>' })`);
26
26
  }
27
27
  return listenerClass[LISTENED_EVENT];
28
28
  };
@@ -1,5 +1,5 @@
1
+ import type { ExceptionOptions } from '../../shared/index';
1
2
  import { ApplicationException } from './application.exception';
2
- import type { ExceptionOptions } from '../abstract.exception';
3
3
  export declare class AggregateNotFoundException extends ApplicationException {
4
4
  constructor(entity: string, id: string, options?: ExceptionOptions);
5
5
  }
@@ -2,16 +2,16 @@
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.AggregateNotFoundException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const application_exception_code_1 = require("./application-exception-code");
5
7
  const application_exception_1 = require("./application.exception");
6
- const exception_brand_1 = require("../brand/exception-brand");
7
- const exception_code_1 = require("../exception-code");
8
8
  class AggregateNotFoundException extends application_exception_1.ApplicationException {
9
9
  constructor(entity, id, options = {}) {
10
- super(`${entity} with ID ${id} not found.`, [exception_code_1.ExceptionCode.AggregateNotFound], options);
10
+ super(`${entity} with ID ${id} not found.`, [application_exception_code_1.ApplicationExceptionCode.AggregateNotFound], options);
11
11
  }
12
12
  }
13
13
  exports.AggregateNotFoundException = AggregateNotFoundException;
14
14
  _a = AggregateNotFoundException;
15
15
  (() => {
16
- exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.AggregateNotFound);
16
+ index_1.ExceptionBrand.brandClass(_a, application_exception_code_1.ApplicationExceptionCode.AggregateNotFound);
17
17
  })();
@@ -0,0 +1,7 @@
1
+ export declare enum ApplicationExceptionCode {
2
+ ApplicationException = "APP000",
3
+ ConcurrencyConflict = "APP001",
4
+ AggregateNotFound = "APP002",
5
+ NotAllowed = "APP003",
6
+ UnexpectedError = "APP004"
7
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApplicationExceptionCode = void 0;
4
+ var ApplicationExceptionCode;
5
+ (function (ApplicationExceptionCode) {
6
+ ApplicationExceptionCode["ApplicationException"] = "APP000";
7
+ ApplicationExceptionCode["ConcurrencyConflict"] = "APP001";
8
+ ApplicationExceptionCode["AggregateNotFound"] = "APP002";
9
+ ApplicationExceptionCode["NotAllowed"] = "APP003";
10
+ ApplicationExceptionCode["UnexpectedError"] = "APP004";
11
+ })(ApplicationExceptionCode || (exports.ApplicationExceptionCode = ApplicationExceptionCode = {}));
@@ -0,0 +1,6 @@
1
+ import { AbstractException } from '../../shared/index';
2
+ import type { ExceptionOptions } from '../../shared/index';
3
+ import { ApplicationExceptionCode } from './application-exception-code';
4
+ export declare class ApplicationException extends AbstractException {
5
+ constructor(message: string, exceptionCodes?: (ApplicationExceptionCode | string)[], options?: ExceptionOptions);
6
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ApplicationException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const application_exception_code_1 = require("./application-exception-code");
7
+ class ApplicationException extends index_1.AbstractException {
8
+ constructor(message, exceptionCodes = [], options = {}) {
9
+ super(message, [application_exception_code_1.ApplicationExceptionCode.ApplicationException, ...exceptionCodes], options, application_exception_code_1.ApplicationExceptionCode);
10
+ }
11
+ }
12
+ exports.ApplicationException = ApplicationException;
13
+ _a = ApplicationException;
14
+ (() => {
15
+ index_1.ExceptionBrand.brandClass(_a, application_exception_code_1.ApplicationExceptionCode.ApplicationException);
16
+ })();
@@ -1,5 +1,5 @@
1
+ import type { ExceptionOptions } from '../../shared/index';
1
2
  import { ApplicationException } from './application.exception';
2
- import type { ExceptionOptions } from '../abstract.exception';
3
3
  export declare class ConcurrencyException extends ApplicationException {
4
4
  constructor(aggregateName: string, id: string, expectedVersion: number, options?: ExceptionOptions);
5
5
  }
@@ -2,16 +2,16 @@
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ConcurrencyException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const application_exception_code_1 = require("./application-exception-code");
5
7
  const application_exception_1 = require("./application.exception");
6
- const exception_brand_1 = require("../brand/exception-brand");
7
- const exception_code_1 = require("../exception-code");
8
8
  class ConcurrencyException extends application_exception_1.ApplicationException {
9
9
  constructor(aggregateName, id, expectedVersion, options = {}) {
10
- super(`${aggregateName} with ID ${id} was changed by someone else: expected version ${expectedVersion}.`, [exception_code_1.ExceptionCode.ConcurrencyConflict], options);
10
+ super(`${aggregateName} with ID ${id} was changed by someone else: expected version ${expectedVersion}.`, [application_exception_code_1.ApplicationExceptionCode.ConcurrencyConflict], options);
11
11
  }
12
12
  }
13
13
  exports.ConcurrencyException = ConcurrencyException;
14
14
  _a = ConcurrencyException;
15
15
  (() => {
16
- exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.ConcurrencyConflict);
16
+ index_1.ExceptionBrand.brandClass(_a, application_exception_code_1.ApplicationExceptionCode.ConcurrencyConflict);
17
17
  })();
@@ -1,5 +1,5 @@
1
+ import type { ExceptionOptions } from '../../shared/index';
1
2
  import { ApplicationException } from './application.exception';
2
- import type { ExceptionOptions } from '../abstract.exception';
3
3
  export declare class NotAllowedException extends ApplicationException {
4
4
  constructor(message: string, options?: ExceptionOptions);
5
5
  }
@@ -2,16 +2,16 @@
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.NotAllowedException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const application_exception_code_1 = require("./application-exception-code");
5
7
  const application_exception_1 = require("./application.exception");
6
- const exception_brand_1 = require("../brand/exception-brand");
7
- const exception_code_1 = require("../exception-code");
8
8
  class NotAllowedException extends application_exception_1.ApplicationException {
9
9
  constructor(message, options = {}) {
10
- super(message, [exception_code_1.ExceptionCode.NotAllowed], options);
10
+ super(message, [application_exception_code_1.ApplicationExceptionCode.NotAllowed], options);
11
11
  }
12
12
  }
13
13
  exports.NotAllowedException = NotAllowedException;
14
14
  _a = NotAllowedException;
15
15
  (() => {
16
- exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.NotAllowed);
16
+ index_1.ExceptionBrand.brandClass(_a, application_exception_code_1.ApplicationExceptionCode.NotAllowed);
17
17
  })();
@@ -0,0 +1,5 @@
1
+ import type { ExceptionOptions } from '../../shared/index';
2
+ import { ApplicationException } from './application.exception';
3
+ export declare class UnexpectedErrorException extends ApplicationException {
4
+ constructor(message: string, options?: ExceptionOptions);
5
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.UnexpectedErrorException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const application_exception_code_1 = require("./application-exception-code");
7
+ const application_exception_1 = require("./application.exception");
8
+ class UnexpectedErrorException extends application_exception_1.ApplicationException {
9
+ constructor(message, options = {}) {
10
+ super(`Failed, unexpected error: ${message}`, [application_exception_code_1.ApplicationExceptionCode.UnexpectedError], options);
11
+ }
12
+ }
13
+ exports.UnexpectedErrorException = UnexpectedErrorException;
14
+ _a = UnexpectedErrorException;
15
+ (() => {
16
+ index_1.ExceptionBrand.brandClass(_a, application_exception_code_1.ApplicationExceptionCode.UnexpectedError);
17
+ })();
@@ -1,7 +1,14 @@
1
1
  export { UseCase } from './use-case/use-case';
2
+ export { ValueObjectBuilder } from './value-object-builder/value-object-builder';
2
3
  export { EventListener } from './event/event-listener';
3
4
  export { ListensTo } from './event/listens-to';
4
5
  export type { ListenerSubscription, ListensToOptions } from './event/listens-to';
5
6
  export type { EventBus } from './event/event-bus';
6
7
  export type { Clock } from './ports/clock';
7
8
  export type { LogContext, Logger, LogLevel } from './ports/logger';
9
+ export { ApplicationException } from './exceptions/application.exception';
10
+ export { ConcurrencyException } from './exceptions/concurrency.exception';
11
+ export { AggregateNotFoundException } from './exceptions/aggregate-not-found.exception';
12
+ export { NotAllowedException } from './exceptions/not-allowed.exception';
13
+ export { UnexpectedErrorException } from './exceptions/unexpected-error.exception';
14
+ export { ApplicationExceptionCode } from './exceptions/application-exception-code';
@@ -1,9 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ListensTo = exports.EventListener = exports.UseCase = void 0;
3
+ exports.ApplicationExceptionCode = exports.UnexpectedErrorException = exports.NotAllowedException = exports.AggregateNotFoundException = exports.ConcurrencyException = exports.ApplicationException = exports.ListensTo = exports.EventListener = exports.ValueObjectBuilder = exports.UseCase = void 0;
4
4
  var use_case_1 = require("./use-case/use-case");
5
5
  Object.defineProperty(exports, "UseCase", { enumerable: true, get: function () { return use_case_1.UseCase; } });
6
+ var value_object_builder_1 = require("./value-object-builder/value-object-builder");
7
+ Object.defineProperty(exports, "ValueObjectBuilder", { enumerable: true, get: function () { return value_object_builder_1.ValueObjectBuilder; } });
6
8
  var event_listener_1 = require("./event/event-listener");
7
9
  Object.defineProperty(exports, "EventListener", { enumerable: true, get: function () { return event_listener_1.EventListener; } });
8
10
  var listens_to_1 = require("./event/listens-to");
9
11
  Object.defineProperty(exports, "ListensTo", { enumerable: true, get: function () { return listens_to_1.ListensTo; } });
12
+ var application_exception_1 = require("./exceptions/application.exception");
13
+ Object.defineProperty(exports, "ApplicationException", { enumerable: true, get: function () { return application_exception_1.ApplicationException; } });
14
+ var concurrency_exception_1 = require("./exceptions/concurrency.exception");
15
+ Object.defineProperty(exports, "ConcurrencyException", { enumerable: true, get: function () { return concurrency_exception_1.ConcurrencyException; } });
16
+ var aggregate_not_found_exception_1 = require("./exceptions/aggregate-not-found.exception");
17
+ Object.defineProperty(exports, "AggregateNotFoundException", { enumerable: true, get: function () { return aggregate_not_found_exception_1.AggregateNotFoundException; } });
18
+ var not_allowed_exception_1 = require("./exceptions/not-allowed.exception");
19
+ Object.defineProperty(exports, "NotAllowedException", { enumerable: true, get: function () { return not_allowed_exception_1.NotAllowedException; } });
20
+ var unexpected_error_exception_1 = require("./exceptions/unexpected-error.exception");
21
+ Object.defineProperty(exports, "UnexpectedErrorException", { enumerable: true, get: function () { return unexpected_error_exception_1.UnexpectedErrorException; } });
22
+ var application_exception_code_1 = require("./exceptions/application-exception-code");
23
+ Object.defineProperty(exports, "ApplicationExceptionCode", { enumerable: true, get: function () { return application_exception_code_1.ApplicationExceptionCode; } });
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UseCase = void 0;
4
4
  const validation_1 = require("@archi-code/validation");
5
- const index_1 = require("../../exceptions/index");
5
+ const index_1 = require("../../shared/index");
6
+ const unexpected_error_exception_1 = require("../exceptions/unexpected-error.exception");
6
7
  class UseCase {
7
8
  async execute(input) {
8
9
  try {
@@ -12,7 +13,7 @@ class UseCase {
12
13
  if (error instanceof index_1.AbstractException) {
13
14
  throw error;
14
15
  }
15
- throw new index_1.InternalErrorException(`${this.constructor.name}: ${UseCase.describe(error)}`, {
16
+ throw new unexpected_error_exception_1.UnexpectedErrorException(`${this.constructor.name}: ${UseCase.describe(error)}`, {
16
17
  cause: error,
17
18
  });
18
19
  }
@@ -5,12 +5,12 @@ type Built<F extends Factories> = {
5
5
  type Synchronous<F extends Factories> = {
6
6
  [Field in keyof F]: [ReturnType<F[Field]>] extends [never] ? F[Field] : [ReturnType<F[Field]>] extends [PromiseLike<unknown>] ? never : F[Field];
7
7
  };
8
- export declare class ValueObjects {
8
+ export declare class ValueObjectBuilder {
9
9
  static build<F extends Factories>(factories: F & Synchronous<F>): Built<F>;
10
10
  static buildList<Value, Item>(values: readonly Value[], factory: (value: Value, index: number) => Item): Item[];
11
11
  private static synchronous;
12
+ private static validated;
13
+ private static read;
12
14
  private static isThenable;
13
- private static issuesOf;
14
- private static assertNoIssues;
15
15
  }
16
16
  export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValueObjectBuilder = void 0;
4
+ const index_1 = require("../../domain/index");
5
+ const index_2 = require("../../shared/index");
6
+ const unexpected_error_exception_1 = require("../exceptions/unexpected-error.exception");
7
+ class ValueObjectBuilder {
8
+ static build(factories) {
9
+ const builds = Object.fromEntries(Object.entries(factories).map(([field, factory]) => [
10
+ field,
11
+ () => ValueObjectBuilder.synchronous(field, factory()),
12
+ ]));
13
+ return ValueObjectBuilder.validated(() => index_2.IssueCollector.collectFields(builds, ValueObjectBuilder.read));
14
+ }
15
+ static buildList(values, factory) {
16
+ return ValueObjectBuilder.validated(() => index_2.IssueCollector.collectItems(values, (value, index) => ValueObjectBuilder.synchronous(String(index), factory(value, index)), ValueObjectBuilder.read));
17
+ }
18
+ static synchronous(field, result) {
19
+ if (!ValueObjectBuilder.isThenable(result)) {
20
+ return result;
21
+ }
22
+ result.then(undefined, () => undefined);
23
+ throw new unexpected_error_exception_1.UnexpectedErrorException(`ValueObjectBuilder: the factory of "${field}" returned a Promise; build value objects synchronously`);
24
+ }
25
+ static validated(collect) {
26
+ try {
27
+ return collect();
28
+ }
29
+ catch (error) {
30
+ if (error instanceof index_2.IssueCollectionError) {
31
+ throw new index_1.ValidationException(error.issues);
32
+ }
33
+ throw error;
34
+ }
35
+ }
36
+ static read(error) {
37
+ if (error instanceof index_1.ValidationException) {
38
+ return error.errors;
39
+ }
40
+ if (error instanceof index_1.DomainException) {
41
+ return [{ field: null, code: error.code, message: error.message }];
42
+ }
43
+ return null;
44
+ }
45
+ static isThenable(result) {
46
+ return ((typeof result === 'object' || typeof result === 'function') &&
47
+ result !== null &&
48
+ typeof result.then === 'function');
49
+ }
50
+ }
51
+ exports.ValueObjectBuilder = ValueObjectBuilder;
@@ -4,11 +4,6 @@ import type { EventBase } from '../event/event-base';
4
4
  import type { IdType } from '../type/id-type';
5
5
  export declare abstract class AggregateRoot<Id extends EntityId = IdType, Event extends EventBase = EventBase> extends Entity<Id> {
6
6
  private readonly domainEvents;
7
- private persistedVersion;
8
- constructor(id: Id);
9
- get version(): number;
10
7
  protected record(event: Event): void;
11
8
  pullDomainEvents(): Event[];
12
- restoreVersion(version: number): this;
13
- markPersisted(): void;
14
9
  }
@@ -2,32 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AggregateRoot = void 0;
4
4
  const entity_1 = require("../entity/entity");
5
- const immutable_1 = require("../type/immutable/immutable");
6
- const index_1 = require("../../exceptions/index");
7
5
  class AggregateRoot extends entity_1.Entity {
8
- constructor(id) {
9
- super(id);
10
- Object.defineProperty(this, 'domainEvents', { value: [] });
11
- Object.defineProperty(this, 'persistedVersion', { value: 0, writable: true });
12
- }
13
- get version() {
14
- return this.persistedVersion;
6
+ constructor() {
7
+ super(...arguments);
8
+ this.domainEvents = [];
15
9
  }
16
10
  record(event) {
17
- this.domainEvents.push(immutable_1.Immutable.freeze(event));
11
+ this.domainEvents.push(event);
18
12
  }
19
13
  pullDomainEvents() {
20
14
  return this.domainEvents.splice(0);
21
15
  }
22
- restoreVersion(version) {
23
- if (!Number.isSafeInteger(version) || version < 0) {
24
- throw new index_1.InternalErrorException(`${this.constructor.name} cannot be restored with version ${String(version)}`);
25
- }
26
- this.persistedVersion = version;
27
- return this;
28
- }
29
- markPersisted() {
30
- this.persistedVersion += 1;
31
- }
32
16
  }
33
17
  exports.AggregateRoot = AggregateRoot;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Entity = void 0;
4
- const index_1 = require("../../exceptions/index");
4
+ const required_value_exception_1 = require("../exceptions/required-value.exception");
5
5
  class Entity {
6
6
  constructor(id) {
7
7
  this.id = id;
8
8
  if (id?.isNull !== false) {
9
- throw new index_1.RequiredValueException(`${new.target.name}.id`, id?.value);
9
+ throw new required_value_exception_1.RequiredValueException(`${new.target.name}.id`, id?.value);
10
10
  }
11
11
  }
12
12
  equals(other) {
@@ -7,23 +7,17 @@ export interface EventMetadata {
7
7
  }
8
8
  export interface SerializedEvent {
9
9
  eventName: string;
10
- eventVersion: number;
11
10
  eventId: string;
12
- aggregateId: string;
13
11
  occurredOn: string;
14
12
  [payload: string]: unknown;
15
13
  }
16
14
  export interface EventClass<Event extends EventBase = EventBase> {
17
15
  readonly eventName: string;
18
- readonly eventVersion?: number;
19
16
  new (...args: any[]): Event;
20
17
  }
21
18
  export declare abstract class EventBase {
19
+ readonly eventName: string;
22
20
  readonly eventId: string;
23
- readonly aggregateId: string;
24
- readonly occurredOn: Date;
25
- constructor(aggregateId: string, metadata?: EventMetadata);
26
- eventName(): string;
27
- eventVersion(): number;
28
- toJSON(): SerializedEvent;
21
+ readonly occurredOn: string;
22
+ constructor(metadata?: EventMetadata);
29
23
  }
@@ -4,48 +4,18 @@ exports.EventBase = void 0;
4
4
  const date_type_1 = require("../type/date-type");
5
5
  const id_type_1 = require("../type/id-type");
6
6
  const uuid_type_1 = require("../type/uuid-type");
7
- const index_1 = require("../../exceptions/index");
7
+ const invalid_event_definition_exception_1 = require("../exceptions/invalid-event-definition.exception");
8
8
  class EventBase {
9
- constructor(aggregateId, metadata = {}) {
10
- const { eventName, eventVersion = 1 } = this.constructor;
9
+ constructor(metadata = {}) {
10
+ const { eventName } = this.constructor;
11
11
  if (typeof eventName !== 'string' || eventName.trim() === '') {
12
- throw new index_1.InternalErrorException(`${this.constructor.name} must declare a static eventName`);
12
+ throw new invalid_event_definition_exception_1.InvalidEventDefinitionException(this.constructor.name);
13
13
  }
14
- if (!Number.isSafeInteger(eventVersion) || eventVersion < 1) {
15
- throw new index_1.InternalErrorException(`${this.constructor.name}.eventVersion must be a whole number from 1`);
16
- }
17
- if (aggregateId === null ||
18
- aggregateId === undefined ||
19
- (typeof aggregateId === 'string' && aggregateId.trim() === '')) {
20
- throw new index_1.RequiredValueException(`${this.constructor.name}.aggregateId`, aggregateId);
21
- }
22
- this.aggregateId = aggregateId;
14
+ this.eventName = eventName;
23
15
  this.eventId = new id_type_1.IdType(metadata.eventId ?? uuid_type_1.UuidType.random()).value;
24
- this.occurredOn =
25
- metadata.occurredOn === undefined
26
- ? date_type_1.CreatedAt.now(metadata.clock).value
27
- : new date_type_1.CreatedAt(metadata.occurredOn).value;
28
- }
29
- eventName() {
30
- return this.constructor.eventName;
31
- }
32
- eventVersion() {
33
- return this.constructor.eventVersion ?? 1;
34
- }
35
- toJSON() {
36
- const serialized = {
37
- eventName: this.eventName(),
38
- eventVersion: this.eventVersion(),
39
- eventId: this.eventId,
40
- aggregateId: this.aggregateId,
41
- occurredOn: this.occurredOn.toISOString(),
42
- };
43
- for (const [key, value] of Object.entries(this)) {
44
- if (!(key in serialized)) {
45
- serialized[key] = value;
46
- }
47
- }
48
- return serialized;
16
+ this.occurredOn = (metadata.occurredOn === undefined
17
+ ? date_type_1.CreatedAt.now(metadata.clock)
18
+ : new date_type_1.CreatedAt(metadata.occurredOn)).value.toISOString();
49
19
  }
50
20
  }
51
21
  exports.EventBase = EventBase;
@@ -0,0 +1,7 @@
1
+ export declare enum DomainExceptionCode {
2
+ DomainException = "DOM000",
3
+ ValidationFailed = "DOM001",
4
+ TypeFailed = "DOM003",
5
+ RequiredValue = "DOM004",
6
+ InvalidEventDefinition = "DOM005"
7
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DomainExceptionCode = void 0;
4
+ var DomainExceptionCode;
5
+ (function (DomainExceptionCode) {
6
+ DomainExceptionCode["DomainException"] = "DOM000";
7
+ DomainExceptionCode["ValidationFailed"] = "DOM001";
8
+ DomainExceptionCode["TypeFailed"] = "DOM003";
9
+ DomainExceptionCode["RequiredValue"] = "DOM004";
10
+ DomainExceptionCode["InvalidEventDefinition"] = "DOM005";
11
+ })(DomainExceptionCode || (exports.DomainExceptionCode = DomainExceptionCode = {}));
@@ -0,0 +1,6 @@
1
+ import { AbstractException } from '../../shared/index';
2
+ import type { ExceptionOptions } from '../../shared/index';
3
+ import { DomainExceptionCode } from './domain-exception-code';
4
+ export declare class DomainException extends AbstractException {
5
+ constructor(message: string, exceptionCodes?: (DomainExceptionCode | string)[], options?: ExceptionOptions);
6
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.DomainException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const domain_exception_code_1 = require("./domain-exception-code");
7
+ class DomainException extends index_1.AbstractException {
8
+ constructor(message, exceptionCodes = [], options = {}) {
9
+ super(message, [domain_exception_code_1.DomainExceptionCode.DomainException, ...exceptionCodes], options, domain_exception_code_1.DomainExceptionCode);
10
+ }
11
+ }
12
+ exports.DomainException = DomainException;
13
+ _a = DomainException;
14
+ (() => {
15
+ index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.DomainException);
16
+ })();
@@ -0,0 +1,4 @@
1
+ import { DomainException } from './domain.exception';
2
+ export declare class InvalidEventDefinitionException extends DomainException {
3
+ constructor(eventClassName: string);
4
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.InvalidEventDefinitionException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const domain_exception_code_1 = require("./domain-exception-code");
7
+ const domain_exception_1 = require("./domain.exception");
8
+ class InvalidEventDefinitionException extends domain_exception_1.DomainException {
9
+ constructor(eventClassName) {
10
+ super(`${eventClassName} must declare a static eventName`, [
11
+ domain_exception_code_1.DomainExceptionCode.InvalidEventDefinition,
12
+ ]);
13
+ }
14
+ }
15
+ exports.InvalidEventDefinitionException = InvalidEventDefinitionException;
16
+ _a = InvalidEventDefinitionException;
17
+ (() => {
18
+ index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.InvalidEventDefinition);
19
+ })();
@@ -2,20 +2,19 @@
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.RequiredValueException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const domain_exception_code_1 = require("./domain-exception-code");
5
7
  const domain_exception_1 = require("./domain.exception");
6
- const exception_brand_1 = require("../brand/exception-brand");
7
- const exception_code_1 = require("../exception-code");
8
- const received_value_1 = require("../received/received-value");
9
8
  class RequiredValueException extends domain_exception_1.DomainException {
10
9
  constructor(typeName, receivedValue) {
11
- const received = received_value_1.ReceivedValue.describe(receivedValue);
10
+ const received = index_1.ReceivedValue.describe(receivedValue);
12
11
  super(`Validation Error: ${typeName} is required, but received ${received}.`, [
13
- exception_code_1.ExceptionCode.RequiredValue,
12
+ domain_exception_code_1.DomainExceptionCode.RequiredValue,
14
13
  ]);
15
14
  }
16
15
  }
17
16
  exports.RequiredValueException = RequiredValueException;
18
17
  _a = RequiredValueException;
19
18
  (() => {
20
- exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.RequiredValue);
19
+ index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.RequiredValue);
21
20
  })();
@@ -2,20 +2,19 @@
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.TypePrimitiveException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const domain_exception_code_1 = require("./domain-exception-code");
5
7
  const domain_exception_1 = require("./domain.exception");
6
- const exception_brand_1 = require("../brand/exception-brand");
7
- const exception_code_1 = require("../exception-code");
8
- const received_value_1 = require("../received/received-value");
9
8
  class TypePrimitiveException extends domain_exception_1.DomainException {
10
9
  constructor(expectedType, receivedValue, template = 'Expected a valid ') {
11
- const received = received_value_1.ReceivedValue.describe(receivedValue);
10
+ const received = index_1.ReceivedValue.describe(receivedValue);
12
11
  super(`Validation Error: ${template}${expectedType}, but received ${received}.`, [
13
- exception_code_1.ExceptionCode.TypeFailed,
12
+ domain_exception_code_1.DomainExceptionCode.TypeFailed,
14
13
  ]);
15
14
  }
16
15
  }
17
16
  exports.TypePrimitiveException = TypePrimitiveException;
18
17
  _a = TypePrimitiveException;
19
18
  (() => {
20
- exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.TypeFailed);
19
+ index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.TypeFailed);
21
20
  })();
@@ -2,15 +2,15 @@
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ValidationException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const domain_exception_code_1 = require("./domain-exception-code");
5
7
  const domain_exception_1 = require("./domain.exception");
6
- const exception_brand_1 = require("../brand/exception-brand");
7
- const exception_code_1 = require("../exception-code");
8
8
  class ValidationException extends domain_exception_1.DomainException {
9
9
  constructor(errors) {
10
10
  super(`Validation failed, ${errors.map(_a.describe).join(', ')}`, [
11
- exception_code_1.ExceptionCode.ValidationFailed,
11
+ domain_exception_code_1.DomainExceptionCode.ValidationFailed,
12
12
  ]);
13
- this.errors = Object.freeze(errors.map(({ field, code = exception_code_1.ExceptionCode.ValidationFailed, message }) => Object.freeze({ field, code, message })));
13
+ this.errors = Object.freeze(errors.map(({ field, code = domain_exception_code_1.DomainExceptionCode.ValidationFailed, message }) => Object.freeze({ field, code, message })));
14
14
  }
15
15
  static describe(issue) {
16
16
  return issue.field === null ? issue.message : `${issue.field}: ${issue.message}`;
@@ -19,5 +19,5 @@ class ValidationException extends domain_exception_1.DomainException {
19
19
  exports.ValidationException = ValidationException;
20
20
  _a = ValidationException;
21
21
  (() => {
22
- exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.ValidationFailed);
22
+ index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.ValidationFailed);
23
23
  })();