@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,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConsoleLogger = void 0;
4
- const index_1 = require("../../exceptions/index");
4
+ const internal_error_exception_1 = require("../exceptions/internal-error.exception");
5
5
  const system_clock_1 = require("../clock/system-clock");
6
6
  const log_serializer_1 = require("./log-serializer");
7
7
  class ConsoleLogger {
@@ -9,7 +9,7 @@ class ConsoleLogger {
9
9
  this.output = console;
10
10
  this.minimum = ConsoleLogger.levels.indexOf(level);
11
11
  if (this.minimum === -1) {
12
- throw new index_1.InternalErrorException(`unknown log level "${String(level)}": use ${ConsoleLogger.levels.join(', ')}`);
12
+ throw new internal_error_exception_1.InternalErrorException(`unknown log level "${String(level)}": use ${ConsoleLogger.levels.join(', ')}`);
13
13
  }
14
14
  this.clock = clock;
15
15
  }
@@ -1,17 +1,19 @@
1
- import { ExceptionCode } from './exception-code.js';
2
1
  export interface ExceptionOptions {
3
2
  cause?: unknown;
4
3
  }
4
+ export type ExceptionCodeNames = Readonly<Record<string, string>>;
5
5
  export declare abstract class AbstractException extends Error {
6
+ private static readonly fallbackCode;
6
7
  readonly cause?: unknown;
7
8
  private readonly exceptionCodes;
8
- readonly code: ExceptionCode | string;
9
+ private readonly codeNames;
10
+ readonly code: string;
9
11
  private readonly createdAt;
10
12
  static [Symbol.hasInstance](candidate: unknown): boolean;
11
- constructor(message: string, exceptionCodes: (ExceptionCode | string)[], options?: ExceptionOptions);
12
- static readonly ExceptionCodeStrings: Record<ExceptionCode, string>;
13
+ constructor(message: string, exceptionCodes: string[], options?: ExceptionOptions, codeNames?: ExceptionCodeNames);
13
14
  get timestamp(): Date;
14
15
  get description(): string;
16
+ private labelOf;
15
17
  print(): string;
16
18
  toJSON(): {
17
19
  name: string;
@@ -2,21 +2,21 @@
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.AbstractException = void 0;
5
- const exception_code_1 = require("./exception-code");
6
5
  const exception_brand_1 = require("./brand/exception-brand");
7
6
  class AbstractException extends Error {
8
7
  static [Symbol.hasInstance](candidate) {
9
8
  return (Function.prototype[Symbol.hasInstance].call(this, candidate) ||
10
9
  exception_brand_1.ExceptionBrand.matches(this, candidate));
11
10
  }
12
- constructor(message, exceptionCodes, options = {}) {
11
+ constructor(message, exceptionCodes, options = {}, codeNames = {}) {
13
12
  super(message);
14
13
  this.name = this.constructor.name;
15
14
  this.exceptionCodes = exceptionCodes;
15
+ this.codeNames = codeNames;
16
16
  this.code =
17
17
  exceptionCodes.length > 0
18
18
  ? exceptionCodes[exceptionCodes.length - 1]
19
- : exception_code_1.ExceptionCode.ErrorException;
19
+ : _a.fallbackCode;
20
20
  this.createdAt = Date.now();
21
21
  if ('cause' in options) {
22
22
  Object.defineProperty(this, 'cause', {
@@ -32,12 +32,11 @@ class AbstractException extends Error {
32
32
  return new Date(this.createdAt);
33
33
  }
34
34
  get description() {
35
- return this.exceptionCodes
36
- .map((code) => {
37
- const codeString = _a.ExceptionCodeStrings[code] ?? this.name;
38
- return `${codeString} (${code})`;
39
- })
40
- .join(', ');
35
+ return this.exceptionCodes.map((code) => `${this.labelOf(code)} (${code})`).join(', ');
36
+ }
37
+ labelOf(code) {
38
+ const name = Object.keys(this.codeNames).find((key) => this.codeNames[key] === code);
39
+ return name === undefined ? this.name : name.replace(/([A-Z])/g, ' $1').trim();
41
40
  }
42
41
  print() {
43
42
  return `[${this.description}]: ${this.message}, ${this.timestamp.toISOString()}`;
@@ -54,13 +53,7 @@ class AbstractException extends Error {
54
53
  }
55
54
  exports.AbstractException = AbstractException;
56
55
  _a = AbstractException;
56
+ AbstractException.fallbackCode = 'E000';
57
57
  (() => {
58
58
  exception_brand_1.ExceptionBrand.brandClass(_a, exception_brand_1.ExceptionBrand.anyCode);
59
59
  })();
60
- AbstractException.ExceptionCodeStrings = Object.keys(exception_code_1.ExceptionCode)
61
- .filter((key) => isNaN(Number(key)))
62
- .reduce((acc, key) => {
63
- const value = exception_code_1.ExceptionCode[key];
64
- acc[value] = key.replace(/([A-Z])/g, ' $1').trim();
65
- return acc;
66
- }, {});
@@ -0,0 +1,8 @@
1
+ export { AbstractException } from './exceptions/abstract.exception';
2
+ export type { ExceptionCodeNames, ExceptionOptions } from './exceptions/abstract.exception';
3
+ export { ExceptionBrand } from './exceptions/brand/exception-brand';
4
+ export { ReceivedValue } from './exceptions/received/received-value';
5
+ export { IssueCollector } from './issue-collector';
6
+ export type { IssueReader } from './issue-collector';
7
+ export { IssueCollectionError } from './issue-collection-error';
8
+ export type { CollectedIssue } from './issue-collection-error';
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IssueCollectionError = exports.IssueCollector = exports.ReceivedValue = exports.ExceptionBrand = exports.AbstractException = void 0;
4
+ var abstract_exception_1 = require("./exceptions/abstract.exception");
5
+ Object.defineProperty(exports, "AbstractException", { enumerable: true, get: function () { return abstract_exception_1.AbstractException; } });
6
+ var exception_brand_1 = require("./exceptions/brand/exception-brand");
7
+ Object.defineProperty(exports, "ExceptionBrand", { enumerable: true, get: function () { return exception_brand_1.ExceptionBrand; } });
8
+ var received_value_1 = require("./exceptions/received/received-value");
9
+ Object.defineProperty(exports, "ReceivedValue", { enumerable: true, get: function () { return received_value_1.ReceivedValue; } });
10
+ var issue_collector_1 = require("./issue-collector");
11
+ Object.defineProperty(exports, "IssueCollector", { enumerable: true, get: function () { return issue_collector_1.IssueCollector; } });
12
+ var issue_collection_error_1 = require("./issue-collection-error");
13
+ Object.defineProperty(exports, "IssueCollectionError", { enumerable: true, get: function () { return issue_collection_error_1.IssueCollectionError; } });
@@ -0,0 +1,9 @@
1
+ export interface CollectedIssue {
2
+ readonly field: string | null;
3
+ readonly code: string;
4
+ readonly message: string;
5
+ }
6
+ export declare class IssueCollectionError extends Error {
7
+ readonly issues: readonly CollectedIssue[];
8
+ constructor(issues: readonly CollectedIssue[]);
9
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IssueCollectionError = void 0;
4
+ class IssueCollectionError extends Error {
5
+ constructor(issues) {
6
+ super(`${issues.length} issues collected`);
7
+ this.name = 'IssueCollectionError';
8
+ this.issues = Object.freeze([...issues]);
9
+ }
10
+ }
11
+ exports.IssueCollectionError = IssueCollectionError;
@@ -0,0 +1,8 @@
1
+ import type { CollectedIssue } from './issue-collection-error';
2
+ export type IssueReader = (error: unknown) => readonly CollectedIssue[] | null;
3
+ export declare class IssueCollector {
4
+ static collectFields(builds: Readonly<Record<string, () => unknown>>, readIssues: IssueReader): Record<string, unknown>;
5
+ static collectItems<Item, Built>(items: readonly Item[], build: (item: Item, index: number) => Built, readIssues: IssueReader): Built[];
6
+ private static collect;
7
+ private static issuesAt;
8
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IssueCollector = void 0;
4
+ const issue_collection_error_1 = require("./issue-collection-error");
5
+ class IssueCollector {
6
+ static collectFields(builds, readIssues) {
7
+ return Object.fromEntries(IssueCollector.collect(Object.entries(builds), readIssues));
8
+ }
9
+ static collectItems(items, build, readIssues) {
10
+ const builds = items.map((item, index) => [String(index), () => build(item, index)]);
11
+ return IssueCollector.collect(builds, readIssues).map(([, built]) => built);
12
+ }
13
+ static collect(builds, readIssues) {
14
+ const built = [];
15
+ const issues = [];
16
+ for (const [path, build] of builds) {
17
+ try {
18
+ built.push([path, build()]);
19
+ }
20
+ catch (error) {
21
+ issues.push(...IssueCollector.issuesAt(path, error, readIssues));
22
+ }
23
+ }
24
+ if (issues.length > 0) {
25
+ throw new issue_collection_error_1.IssueCollectionError(issues);
26
+ }
27
+ return built;
28
+ }
29
+ static issuesAt(path, error, readIssues) {
30
+ const issues = readIssues(error);
31
+ if (issues === null) {
32
+ throw error;
33
+ }
34
+ return issues.map((issue) => ({
35
+ field: issue.field === null ? path : `${path}.${issue.field}`,
36
+ code: issue.code,
37
+ message: issue.message,
38
+ }));
39
+ }
40
+ }
41
+ exports.IssueCollector = IssueCollector;
@@ -1,4 +1,4 @@
1
- import { ApplicationException } from '../../exceptions/index.js';
1
+ import { ApplicationException } from '../exceptions/application.exception.js';
2
2
  const LISTENED_EVENT = Symbol.for('@archi-code/ddd/listens-to.v1');
3
3
  export function ListensTo(event, options) {
4
4
  return (listener) => {
@@ -1,5 +1,5 @@
1
+ import type { ExceptionOptions } from '../../shared/index.js';
1
2
  import { ApplicationException } from './application.exception.js';
2
- import type { ExceptionOptions } from '../abstract.exception.js';
3
3
  export declare class AggregateNotFoundException extends ApplicationException {
4
4
  constructor(entity: string, id: string, options?: ExceptionOptions);
5
5
  }
@@ -0,0 +1,13 @@
1
+ var _a;
2
+ import { ExceptionBrand } from '../../shared/index.js';
3
+ import { ApplicationExceptionCode } from './application-exception-code.js';
4
+ import { ApplicationException } from './application.exception.js';
5
+ export class AggregateNotFoundException extends ApplicationException {
6
+ constructor(entity, id, options = {}) {
7
+ super(`${entity} with ID ${id} not found.`, [ApplicationExceptionCode.AggregateNotFound], options);
8
+ }
9
+ }
10
+ _a = AggregateNotFoundException;
11
+ (() => {
12
+ ExceptionBrand.brandClass(_a, ApplicationExceptionCode.AggregateNotFound);
13
+ })();
@@ -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,8 @@
1
+ export var ApplicationExceptionCode;
2
+ (function (ApplicationExceptionCode) {
3
+ ApplicationExceptionCode["ApplicationException"] = "APP000";
4
+ ApplicationExceptionCode["ConcurrencyConflict"] = "APP001";
5
+ ApplicationExceptionCode["AggregateNotFound"] = "APP002";
6
+ ApplicationExceptionCode["NotAllowed"] = "APP003";
7
+ ApplicationExceptionCode["UnexpectedError"] = "APP004";
8
+ })(ApplicationExceptionCode || (ApplicationExceptionCode = {}));
@@ -0,0 +1,6 @@
1
+ import { AbstractException } from '../../shared/index.js';
2
+ import type { ExceptionOptions } from '../../shared/index.js';
3
+ import { ApplicationExceptionCode } from './application-exception-code.js';
4
+ export declare class ApplicationException extends AbstractException {
5
+ constructor(message: string, exceptionCodes?: (ApplicationExceptionCode | string)[], options?: ExceptionOptions);
6
+ }
@@ -0,0 +1,12 @@
1
+ var _a;
2
+ import { AbstractException, ExceptionBrand } from '../../shared/index.js';
3
+ import { ApplicationExceptionCode } from './application-exception-code.js';
4
+ export class ApplicationException extends AbstractException {
5
+ constructor(message, exceptionCodes = [], options = {}) {
6
+ super(message, [ApplicationExceptionCode.ApplicationException, ...exceptionCodes], options, ApplicationExceptionCode);
7
+ }
8
+ }
9
+ _a = ApplicationException;
10
+ (() => {
11
+ ExceptionBrand.brandClass(_a, ApplicationExceptionCode.ApplicationException);
12
+ })();
@@ -1,5 +1,5 @@
1
+ import type { ExceptionOptions } from '../../shared/index.js';
1
2
  import { ApplicationException } from './application.exception.js';
2
- import type { ExceptionOptions } from '../abstract.exception.js';
3
3
  export declare class ConcurrencyException extends ApplicationException {
4
4
  constructor(aggregateName: string, id: string, expectedVersion: number, options?: ExceptionOptions);
5
5
  }
@@ -1,13 +1,13 @@
1
1
  var _a;
2
+ import { ExceptionBrand } from '../../shared/index.js';
3
+ import { ApplicationExceptionCode } from './application-exception-code.js';
2
4
  import { ApplicationException } from './application.exception.js';
3
- import { ExceptionBrand } from '../brand/exception-brand.js';
4
- import { ExceptionCode } from '../exception-code.js';
5
5
  export class ConcurrencyException extends ApplicationException {
6
6
  constructor(aggregateName, id, expectedVersion, options = {}) {
7
- super(`${aggregateName} with ID ${id} was changed by someone else: expected version ${expectedVersion}.`, [ExceptionCode.ConcurrencyConflict], options);
7
+ super(`${aggregateName} with ID ${id} was changed by someone else: expected version ${expectedVersion}.`, [ApplicationExceptionCode.ConcurrencyConflict], options);
8
8
  }
9
9
  }
10
10
  _a = ConcurrencyException;
11
11
  (() => {
12
- ExceptionBrand.brandClass(_a, ExceptionCode.ConcurrencyConflict);
12
+ ExceptionBrand.brandClass(_a, ApplicationExceptionCode.ConcurrencyConflict);
13
13
  })();
@@ -1,5 +1,5 @@
1
+ import type { ExceptionOptions } from '../../shared/index.js';
1
2
  import { ApplicationException } from './application.exception.js';
2
- import type { ExceptionOptions } from '../abstract.exception.js';
3
3
  export declare class NotAllowedException extends ApplicationException {
4
4
  constructor(message: string, options?: ExceptionOptions);
5
5
  }
@@ -0,0 +1,13 @@
1
+ var _a;
2
+ import { ExceptionBrand } from '../../shared/index.js';
3
+ import { ApplicationExceptionCode } from './application-exception-code.js';
4
+ import { ApplicationException } from './application.exception.js';
5
+ export class NotAllowedException extends ApplicationException {
6
+ constructor(message, options = {}) {
7
+ super(message, [ApplicationExceptionCode.NotAllowed], options);
8
+ }
9
+ }
10
+ _a = NotAllowedException;
11
+ (() => {
12
+ ExceptionBrand.brandClass(_a, ApplicationExceptionCode.NotAllowed);
13
+ })();
@@ -0,0 +1,5 @@
1
+ import type { ExceptionOptions } from '../../shared/index.js';
2
+ import { ApplicationException } from './application.exception.js';
3
+ export declare class UnexpectedErrorException extends ApplicationException {
4
+ constructor(message: string, options?: ExceptionOptions);
5
+ }
@@ -0,0 +1,13 @@
1
+ var _a;
2
+ import { ExceptionBrand } from '../../shared/index.js';
3
+ import { ApplicationExceptionCode } from './application-exception-code.js';
4
+ import { ApplicationException } from './application.exception.js';
5
+ export class UnexpectedErrorException extends ApplicationException {
6
+ constructor(message, options = {}) {
7
+ super(`Failed, unexpected error: ${message}`, [ApplicationExceptionCode.UnexpectedError], options);
8
+ }
9
+ }
10
+ _a = UnexpectedErrorException;
11
+ (() => {
12
+ ExceptionBrand.brandClass(_a, ApplicationExceptionCode.UnexpectedError);
13
+ })();
@@ -1,7 +1,14 @@
1
1
  export { UseCase } from './use-case/use-case.js';
2
+ export { ValueObjectBuilder } from './value-object-builder/value-object-builder.js';
2
3
  export { EventListener } from './event/event-listener.js';
3
4
  export { ListensTo } from './event/listens-to.js';
4
5
  export type { ListenerSubscription, ListensToOptions } from './event/listens-to.js';
5
6
  export type { EventBus } from './event/event-bus.js';
6
7
  export type { Clock } from './ports/clock.js';
7
8
  export type { LogContext, Logger, LogLevel } from './ports/logger.js';
9
+ export { ApplicationException } from './exceptions/application.exception.js';
10
+ export { ConcurrencyException } from './exceptions/concurrency.exception.js';
11
+ export { AggregateNotFoundException } from './exceptions/aggregate-not-found.exception.js';
12
+ export { NotAllowedException } from './exceptions/not-allowed.exception.js';
13
+ export { UnexpectedErrorException } from './exceptions/unexpected-error.exception.js';
14
+ export { ApplicationExceptionCode } from './exceptions/application-exception-code.js';
@@ -1,3 +1,10 @@
1
1
  export { UseCase } from './use-case/use-case.js';
2
+ export { ValueObjectBuilder } from './value-object-builder/value-object-builder.js';
2
3
  export { EventListener } from './event/event-listener.js';
3
4
  export { ListensTo } from './event/listens-to.js';
5
+ export { ApplicationException } from './exceptions/application.exception.js';
6
+ export { ConcurrencyException } from './exceptions/concurrency.exception.js';
7
+ export { AggregateNotFoundException } from './exceptions/aggregate-not-found.exception.js';
8
+ export { NotAllowedException } from './exceptions/not-allowed.exception.js';
9
+ export { UnexpectedErrorException } from './exceptions/unexpected-error.exception.js';
10
+ export { ApplicationExceptionCode } from './exceptions/application-exception-code.js';
@@ -1,5 +1,6 @@
1
1
  import { anyToString } from '@archi-code/validation';
2
- import { AbstractException, InternalErrorException } from '../../exceptions/index.js';
2
+ import { AbstractException } from '../../shared/index.js';
3
+ import { UnexpectedErrorException } from '../exceptions/unexpected-error.exception.js';
3
4
  export class UseCase {
4
5
  async execute(input) {
5
6
  try {
@@ -9,7 +10,7 @@ export class UseCase {
9
10
  if (error instanceof AbstractException) {
10
11
  throw error;
11
12
  }
12
- throw new InternalErrorException(`${this.constructor.name}: ${UseCase.describe(error)}`, {
13
+ throw new UnexpectedErrorException(`${this.constructor.name}: ${UseCase.describe(error)}`, {
13
14
  cause: error,
14
15
  });
15
16
  }
@@ -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,47 @@
1
+ import { DomainException, ValidationException } from '../../domain/index.js';
2
+ import { IssueCollectionError, IssueCollector } from '../../shared/index.js';
3
+ import { UnexpectedErrorException } from '../exceptions/unexpected-error.exception.js';
4
+ export class ValueObjectBuilder {
5
+ static build(factories) {
6
+ const builds = Object.fromEntries(Object.entries(factories).map(([field, factory]) => [
7
+ field,
8
+ () => ValueObjectBuilder.synchronous(field, factory()),
9
+ ]));
10
+ return ValueObjectBuilder.validated(() => IssueCollector.collectFields(builds, ValueObjectBuilder.read));
11
+ }
12
+ static buildList(values, factory) {
13
+ return ValueObjectBuilder.validated(() => IssueCollector.collectItems(values, (value, index) => ValueObjectBuilder.synchronous(String(index), factory(value, index)), ValueObjectBuilder.read));
14
+ }
15
+ static synchronous(field, result) {
16
+ if (!ValueObjectBuilder.isThenable(result)) {
17
+ return result;
18
+ }
19
+ result.then(undefined, () => undefined);
20
+ throw new UnexpectedErrorException(`ValueObjectBuilder: the factory of "${field}" returned a Promise; build value objects synchronously`);
21
+ }
22
+ static validated(collect) {
23
+ try {
24
+ return collect();
25
+ }
26
+ catch (error) {
27
+ if (error instanceof IssueCollectionError) {
28
+ throw new ValidationException(error.issues);
29
+ }
30
+ throw error;
31
+ }
32
+ }
33
+ static read(error) {
34
+ if (error instanceof ValidationException) {
35
+ return error.errors;
36
+ }
37
+ if (error instanceof DomainException) {
38
+ return [{ field: null, code: error.code, message: error.message }];
39
+ }
40
+ return null;
41
+ }
42
+ static isThenable(result) {
43
+ return ((typeof result === 'object' || typeof result === 'function') &&
44
+ result !== null &&
45
+ typeof result.then === 'function');
46
+ }
47
+ }
@@ -4,11 +4,6 @@ import type { EventBase } from '../event/event-base.js';
4
4
  import type { IdType } from '../type/id-type.js';
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
  }
@@ -1,29 +1,13 @@
1
1
  import { Entity } from '../entity/entity.js';
2
- import { Immutable } from '../type/immutable/immutable.js';
3
- import { InternalErrorException } from '../../exceptions/index.js';
4
2
  export class AggregateRoot extends Entity {
5
- constructor(id) {
6
- super(id);
7
- Object.defineProperty(this, 'domainEvents', { value: [] });
8
- Object.defineProperty(this, 'persistedVersion', { value: 0, writable: true });
9
- }
10
- get version() {
11
- return this.persistedVersion;
3
+ constructor() {
4
+ super(...arguments);
5
+ this.domainEvents = [];
12
6
  }
13
7
  record(event) {
14
- this.domainEvents.push(Immutable.freeze(event));
8
+ this.domainEvents.push(event);
15
9
  }
16
10
  pullDomainEvents() {
17
11
  return this.domainEvents.splice(0);
18
12
  }
19
- restoreVersion(version) {
20
- if (!Number.isSafeInteger(version) || version < 0) {
21
- throw new InternalErrorException(`${this.constructor.name} cannot be restored with version ${String(version)}`);
22
- }
23
- this.persistedVersion = version;
24
- return this;
25
- }
26
- markPersisted() {
27
- this.persistedVersion += 1;
28
- }
29
13
  }
@@ -1,4 +1,4 @@
1
- import { RequiredValueException } from '../../exceptions/index.js';
1
+ import { RequiredValueException } from '../exceptions/required-value.exception.js';
2
2
  export class Entity {
3
3
  constructor(id) {
4
4
  this.id = id;
@@ -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
  }
@@ -1,47 +1,17 @@
1
1
  import { CreatedAt } from '../type/date-type.js';
2
2
  import { IdType } from '../type/id-type.js';
3
3
  import { UuidType } from '../type/uuid-type.js';
4
- import { InternalErrorException, RequiredValueException } from '../../exceptions/index.js';
4
+ import { InvalidEventDefinitionException } from '../exceptions/invalid-event-definition.exception.js';
5
5
  export class EventBase {
6
- constructor(aggregateId, metadata = {}) {
7
- const { eventName, eventVersion = 1 } = this.constructor;
6
+ constructor(metadata = {}) {
7
+ const { eventName } = this.constructor;
8
8
  if (typeof eventName !== 'string' || eventName.trim() === '') {
9
- throw new InternalErrorException(`${this.constructor.name} must declare a static eventName`);
9
+ throw new InvalidEventDefinitionException(this.constructor.name);
10
10
  }
11
- if (!Number.isSafeInteger(eventVersion) || eventVersion < 1) {
12
- throw new InternalErrorException(`${this.constructor.name}.eventVersion must be a whole number from 1`);
13
- }
14
- if (aggregateId === null ||
15
- aggregateId === undefined ||
16
- (typeof aggregateId === 'string' && aggregateId.trim() === '')) {
17
- throw new RequiredValueException(`${this.constructor.name}.aggregateId`, aggregateId);
18
- }
19
- this.aggregateId = aggregateId;
11
+ this.eventName = eventName;
20
12
  this.eventId = new IdType(metadata.eventId ?? UuidType.random()).value;
21
- this.occurredOn =
22
- metadata.occurredOn === undefined
23
- ? CreatedAt.now(metadata.clock).value
24
- : new CreatedAt(metadata.occurredOn).value;
25
- }
26
- eventName() {
27
- return this.constructor.eventName;
28
- }
29
- eventVersion() {
30
- return this.constructor.eventVersion ?? 1;
31
- }
32
- toJSON() {
33
- const serialized = {
34
- eventName: this.eventName(),
35
- eventVersion: this.eventVersion(),
36
- eventId: this.eventId,
37
- aggregateId: this.aggregateId,
38
- occurredOn: this.occurredOn.toISOString(),
39
- };
40
- for (const [key, value] of Object.entries(this)) {
41
- if (!(key in serialized)) {
42
- serialized[key] = value;
43
- }
44
- }
45
- return serialized;
13
+ this.occurredOn = (metadata.occurredOn === undefined
14
+ ? CreatedAt.now(metadata.clock)
15
+ : new CreatedAt(metadata.occurredOn)).value.toISOString();
46
16
  }
47
17
  }
@@ -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,8 @@
1
+ export var DomainExceptionCode;
2
+ (function (DomainExceptionCode) {
3
+ DomainExceptionCode["DomainException"] = "DOM000";
4
+ DomainExceptionCode["ValidationFailed"] = "DOM001";
5
+ DomainExceptionCode["TypeFailed"] = "DOM003";
6
+ DomainExceptionCode["RequiredValue"] = "DOM004";
7
+ DomainExceptionCode["InvalidEventDefinition"] = "DOM005";
8
+ })(DomainExceptionCode || (DomainExceptionCode = {}));
@@ -0,0 +1,6 @@
1
+ import { AbstractException } from '../../shared/index.js';
2
+ import type { ExceptionOptions } from '../../shared/index.js';
3
+ import { DomainExceptionCode } from './domain-exception-code.js';
4
+ export declare class DomainException extends AbstractException {
5
+ constructor(message: string, exceptionCodes?: (DomainExceptionCode | string)[], options?: ExceptionOptions);
6
+ }
@@ -0,0 +1,12 @@
1
+ var _a;
2
+ import { AbstractException, ExceptionBrand } from '../../shared/index.js';
3
+ import { DomainExceptionCode } from './domain-exception-code.js';
4
+ export class DomainException extends AbstractException {
5
+ constructor(message, exceptionCodes = [], options = {}) {
6
+ super(message, [DomainExceptionCode.DomainException, ...exceptionCodes], options, DomainExceptionCode);
7
+ }
8
+ }
9
+ _a = DomainException;
10
+ (() => {
11
+ ExceptionBrand.brandClass(_a, DomainExceptionCode.DomainException);
12
+ })();