@archi-code/ddd 0.0.0-stage → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/LICENSE +46 -0
  2. package/README.md +2693 -2
  3. package/SKILL.md +104 -0
  4. package/ddd-skills/archi-code-ddd/imports.md +84 -0
  5. package/ddd-skills/archi-code-ddd/layers.md +299 -0
  6. package/ddd-skills/archi-code-ddd/patterns.md +676 -0
  7. package/ddd-skills/archi-code-ddd/what-not-to-do.md +189 -0
  8. package/ddd-skills/archi-code-ddd/where-each-class-goes.md +63 -0
  9. package/ddd-skills/ddd-agregados/GUIA.md +114 -0
  10. package/ddd-skills/ddd-agregados/references/consistencia-eventual.md +159 -0
  11. package/ddd-skills/ddd-agregados/references/ejemplo-ecommerce.md +52 -0
  12. package/ddd-skills/ddd-agregados/references/fabricas.md +196 -0
  13. package/ddd-skills/ddd-agregados/references/implementacion-ts.md +711 -0
  14. package/ddd-skills/ddd-arquitectura/GUIA.md +80 -0
  15. package/ddd-skills/ddd-arquitectura/assets/dependency-cruiser.cjs +92 -0
  16. package/ddd-skills/ddd-arquitectura/references/estilos-adicionales.md +51 -0
  17. package/ddd-skills/ddd-arquitectura/references/estructura-hexagonal-ts.md +352 -0
  18. package/ddd-skills/ddd-arquitectura/references/modulos.md +48 -0
  19. package/ddd-skills/ddd-auditoria-refactorizacion/GUIA.md +85 -0
  20. package/ddd-skills/ddd-auditoria-refactorizacion/references/ejemplo-auditoria.md +316 -0
  21. package/ddd-skills/ddd-auditoria-refactorizacion/references/lista-comprobacion.md +54 -0
  22. package/ddd-skills/ddd-auditoria-refactorizacion/references/plan-migracion.md +73 -0
  23. package/ddd-skills/ddd-auditoria-refactorizacion/scripts/scan_ddd_smells.py +264 -0
  24. package/ddd-skills/ddd-context-mapping/GUIA.md +83 -0
  25. package/ddd-skills/ddd-context-mapping/references/anticorrupcion-ts.md +404 -0
  26. package/ddd-skills/ddd-context-mapping/references/estilos-integracion.md +155 -0
  27. package/ddd-skills/ddd-event-sourcing-cqrs/GUIA.md +92 -0
  28. package/ddd-skills/ddd-event-sourcing-cqrs/references/event-sourcing-ts.md +471 -0
  29. package/ddd-skills/ddd-event-sourcing-cqrs/references/proyecciones-cqrs-ts.md +285 -0
  30. package/ddd-skills/ddd-eventos-dominio/GUIA.md +106 -0
  31. package/ddd-skills/ddd-eventos-dominio/references/diseno-eventos.md +131 -0
  32. package/ddd-skills/ddd-eventos-dominio/references/ejemplo-ecommerce.md +240 -0
  33. package/ddd-skills/ddd-eventos-dominio/references/publicacion-ts.md +526 -0
  34. package/ddd-skills/ddd-orquestador/GUIA.md +40 -0
  35. package/ddd-skills/ddd-orquestador/references/chuleta-reglas.md +35 -0
  36. package/ddd-skills/ddd-repositorios-persistencia/GUIA.md +121 -0
  37. package/ddd-skills/ddd-repositorios-persistencia/references/implementacion-ts.md +296 -0
  38. package/ddd-skills/ddd-repositorios-persistencia/references/tests-repositorios.md +177 -0
  39. package/ddd-skills/ddd-repositorios-persistencia/references/transacciones-ts.md +294 -0
  40. package/ddd-skills/ddd-servicios-capa-aplicacion/GUIA.md +99 -0
  41. package/ddd-skills/ddd-servicios-capa-aplicacion/references/capa-aplicacion-ts.md +264 -0
  42. package/ddd-skills/ddd-servicios-capa-aplicacion/references/ejemplo-ecommerce.md +324 -0
  43. package/ddd-skills/ddd-servicios-capa-aplicacion/references/servicios-dominio-ts.md +191 -0
  44. package/ddd-skills/ddd-value-objects-entidades/GUIA.md +118 -0
  45. package/ddd-skills/ddd-value-objects-entidades/references/ejemplo-ecommerce.md +87 -0
  46. package/ddd-skills/ddd-value-objects-entidades/references/entidades-ts.md +220 -0
  47. package/ddd-skills/ddd-value-objects-entidades/references/persistencia-valores.md +88 -0
  48. package/ddd-skills/ddd-value-objects-entidades/references/specification-y-diseno-flexible.md +119 -0
  49. package/ddd-skills/ddd-value-objects-entidades/references/validacion.md +96 -0
  50. package/ddd-skills/ddd-value-objects-entidades/references/value-objects-ts.md +377 -0
  51. package/dist/cjs/application/event/event-bus.d.ts +4 -0
  52. package/dist/cjs/application/event/event-bus.js +2 -0
  53. package/dist/cjs/application/event/event-listener.d.ts +4 -0
  54. package/dist/cjs/application/event/event-listener.js +6 -0
  55. package/dist/cjs/application/event/listens-to.d.ts +15 -0
  56. package/dist/cjs/application/event/listens-to.js +28 -0
  57. package/dist/cjs/application/index.d.ts +7 -0
  58. package/dist/cjs/application/index.js +9 -0
  59. package/dist/cjs/application/ports/clock.d.ts +3 -0
  60. package/dist/cjs/application/ports/clock.js +2 -0
  61. package/dist/cjs/application/ports/logger.d.ts +8 -0
  62. package/dist/cjs/application/ports/logger.js +2 -0
  63. package/dist/cjs/application/use-case/use-case.d.ts +6 -0
  64. package/dist/cjs/application/use-case/use-case.js +24 -0
  65. package/dist/cjs/domain/aggregate/aggregate-root.d.ts +14 -0
  66. package/dist/cjs/domain/aggregate/aggregate-root.js +33 -0
  67. package/dist/cjs/domain/entity/entity.d.ts +9 -0
  68. package/dist/cjs/domain/entity/entity.js +19 -0
  69. package/dist/cjs/domain/event/event-base.d.ts +29 -0
  70. package/dist/cjs/domain/event/event-base.js +51 -0
  71. package/dist/cjs/domain/index.d.ts +10 -0
  72. package/dist/cjs/domain/index.js +24 -0
  73. package/dist/cjs/domain/primitive/primitive-types.d.ts +22 -0
  74. package/dist/cjs/domain/primitive/primitive-types.js +2 -0
  75. package/dist/cjs/domain/repository/aggregate-finder.d.ts +4 -0
  76. package/dist/cjs/domain/repository/aggregate-finder.js +2 -0
  77. package/dist/cjs/domain/repository/aggregate-remover.d.ts +4 -0
  78. package/dist/cjs/domain/repository/aggregate-remover.js +2 -0
  79. package/dist/cjs/domain/repository/aggregate-saver.d.ts +4 -0
  80. package/dist/cjs/domain/repository/aggregate-saver.js +2 -0
  81. package/dist/cjs/domain/specification/specification.d.ts +9 -0
  82. package/dist/cjs/domain/specification/specification.js +44 -0
  83. package/dist/cjs/domain/type/abstract-type.d.ts +20 -0
  84. package/dist/cjs/domain/type/abstract-type.js +69 -0
  85. package/dist/cjs/domain/type/array-type.d.ts +16 -0
  86. package/dist/cjs/domain/type/array-type.js +65 -0
  87. package/dist/cjs/domain/type/boolean-type.d.ts +4 -0
  88. package/dist/cjs/domain/type/boolean-type.js +16 -0
  89. package/dist/cjs/domain/type/composite/composite-field.d.ts +19 -0
  90. package/dist/cjs/domain/type/composite/composite-field.js +63 -0
  91. package/dist/cjs/domain/type/composite/composite.d.ts +26 -0
  92. package/dist/cjs/domain/type/composite/composite.js +55 -0
  93. package/dist/cjs/domain/type/date-type.d.ts +18 -0
  94. package/dist/cjs/domain/type/date-type.js +35 -0
  95. package/dist/cjs/domain/type/enum-type.d.ts +7 -0
  96. package/dist/cjs/domain/type/enum-type.js +30 -0
  97. package/dist/cjs/domain/type/equality/value-equality.d.ts +7 -0
  98. package/dist/cjs/domain/type/equality/value-equality.js +41 -0
  99. package/dist/cjs/domain/type/id-type.d.ts +7 -0
  100. package/dist/cjs/domain/type/id-type.js +17 -0
  101. package/dist/cjs/domain/type/immutable/immutable-date.d.ts +4 -0
  102. package/dist/cjs/domain/type/immutable/immutable-date.js +37 -0
  103. package/dist/cjs/domain/type/immutable/immutable.d.ts +4 -0
  104. package/dist/cjs/domain/type/immutable/immutable.js +19 -0
  105. package/dist/cjs/domain/type/index.d.ts +17 -0
  106. package/dist/cjs/domain/type/index.js +33 -0
  107. package/dist/cjs/domain/type/json-type.d.ts +5 -0
  108. package/dist/cjs/domain/type/json-type.js +17 -0
  109. package/dist/cjs/domain/type/number-type.d.ts +4 -0
  110. package/dist/cjs/domain/type/number-type.js +16 -0
  111. package/dist/cjs/domain/type/required/required-mark.d.ts +9 -0
  112. package/dist/cjs/domain/type/required/required-mark.js +13 -0
  113. package/dist/cjs/domain/type/required/required.d.ts +7 -0
  114. package/dist/cjs/domain/type/required/required.js +21 -0
  115. package/dist/cjs/domain/type/string-type.d.ts +4 -0
  116. package/dist/cjs/domain/type/string-type.js +16 -0
  117. package/dist/cjs/domain/type/uuid-type.d.ts +7 -0
  118. package/dist/cjs/domain/type/uuid-type.js +27 -0
  119. package/dist/cjs/domain/type/value-objects/value-objects.d.ts +16 -0
  120. package/dist/cjs/domain/type/value-objects/value-objects.js +70 -0
  121. package/dist/cjs/exceptions/abstract.exception.d.ts +23 -0
  122. package/dist/cjs/exceptions/abstract.exception.js +66 -0
  123. package/dist/cjs/exceptions/application/aggregate-not-found.exception.d.ts +5 -0
  124. package/dist/cjs/exceptions/application/aggregate-not-found.exception.js +17 -0
  125. package/dist/cjs/exceptions/application/application.exception.d.ts +6 -0
  126. package/dist/cjs/exceptions/application/application.exception.js +17 -0
  127. package/dist/cjs/exceptions/application/concurrency.exception.d.ts +5 -0
  128. package/dist/cjs/exceptions/application/concurrency.exception.js +17 -0
  129. package/dist/cjs/exceptions/application/not-allowed.exception.d.ts +5 -0
  130. package/dist/cjs/exceptions/application/not-allowed.exception.js +17 -0
  131. package/dist/cjs/exceptions/brand/exception-brand.d.ts +6 -0
  132. package/dist/cjs/exceptions/brand/exception-brand.js +29 -0
  133. package/dist/cjs/exceptions/domain/domain.exception.d.ts +6 -0
  134. package/dist/cjs/exceptions/domain/domain.exception.js +17 -0
  135. package/dist/cjs/exceptions/domain/required-value.exception.d.ts +4 -0
  136. package/dist/cjs/exceptions/domain/required-value.exception.js +21 -0
  137. package/dist/cjs/exceptions/domain/type-primitive.exception.d.ts +4 -0
  138. package/dist/cjs/exceptions/domain/type-primitive.exception.js +21 -0
  139. package/dist/cjs/exceptions/domain/validation.exception.d.ts +14 -0
  140. package/dist/cjs/exceptions/domain/validation.exception.js +23 -0
  141. package/dist/cjs/exceptions/exception-code.d.ts +15 -0
  142. package/dist/cjs/exceptions/exception-code.js +19 -0
  143. package/dist/cjs/exceptions/index.d.ts +14 -0
  144. package/dist/cjs/exceptions/index.js +30 -0
  145. package/dist/cjs/exceptions/infrastructure/event-delivery.exception.d.ts +5 -0
  146. package/dist/cjs/exceptions/infrastructure/event-delivery.exception.js +20 -0
  147. package/dist/cjs/exceptions/infrastructure/infrastructure.exception.d.ts +6 -0
  148. package/dist/cjs/exceptions/infrastructure/infrastructure.exception.js +17 -0
  149. package/dist/cjs/exceptions/infrastructure/internal-error.exception.d.ts +5 -0
  150. package/dist/cjs/exceptions/infrastructure/internal-error.exception.js +17 -0
  151. package/dist/cjs/exceptions/infrastructure/unknown-event.exception.d.ts +4 -0
  152. package/dist/cjs/exceptions/infrastructure/unknown-event.exception.js +19 -0
  153. package/dist/cjs/exceptions/received/received-value.d.ts +4 -0
  154. package/dist/cjs/exceptions/received/received-value.js +13 -0
  155. package/dist/cjs/infrastructure/clock/fixed-clock.d.ts +8 -0
  156. package/dist/cjs/infrastructure/clock/fixed-clock.js +19 -0
  157. package/dist/cjs/infrastructure/clock/system-clock.d.ts +4 -0
  158. package/dist/cjs/infrastructure/clock/system-clock.js +9 -0
  159. package/dist/cjs/infrastructure/event/domain-event-bus.d.ts +16 -0
  160. package/dist/cjs/infrastructure/event/domain-event-bus.js +60 -0
  161. package/dist/cjs/infrastructure/event/event-channel.d.ts +9 -0
  162. package/dist/cjs/infrastructure/event/event-channel.js +2 -0
  163. package/dist/cjs/infrastructure/event/event-registry.d.ts +9 -0
  164. package/dist/cjs/infrastructure/event/event-registry.js +43 -0
  165. package/dist/cjs/infrastructure/event/in-memory/emitter.d.ts +11 -0
  166. package/dist/cjs/infrastructure/event/in-memory/emitter.js +54 -0
  167. package/dist/cjs/infrastructure/event/in-memory/in-memory-event-channel.d.ts +16 -0
  168. package/dist/cjs/infrastructure/event/in-memory/in-memory-event-channel.js +51 -0
  169. package/dist/cjs/infrastructure/http/http-error-mapper.d.ts +23 -0
  170. package/dist/cjs/infrastructure/http/http-error-mapper.js +63 -0
  171. package/dist/cjs/infrastructure/index.d.ts +16 -0
  172. package/dist/cjs/infrastructure/index.js +21 -0
  173. package/dist/cjs/infrastructure/logging/console-logger.d.ts +17 -0
  174. package/dist/cjs/infrastructure/logging/console-logger.js +37 -0
  175. package/dist/cjs/infrastructure/logging/in-memory-logger.d.ts +15 -0
  176. package/dist/cjs/infrastructure/logging/in-memory-logger.js +27 -0
  177. package/dist/cjs/infrastructure/logging/log-serializer.d.ts +7 -0
  178. package/dist/cjs/infrastructure/logging/log-serializer.js +59 -0
  179. package/dist/cjs/infrastructure/logging/silent-logger.d.ts +7 -0
  180. package/dist/cjs/infrastructure/logging/silent-logger.js +18 -0
  181. package/dist/esm/application/event/event-bus.d.ts +4 -0
  182. package/dist/esm/application/event/event-bus.js +1 -0
  183. package/dist/esm/application/event/event-listener.d.ts +4 -0
  184. package/dist/esm/application/event/event-listener.js +2 -0
  185. package/dist/esm/application/event/listens-to.d.ts +15 -0
  186. package/dist/esm/application/event/listens-to.js +25 -0
  187. package/dist/esm/application/index.d.ts +7 -0
  188. package/dist/esm/application/index.js +3 -0
  189. package/dist/esm/application/ports/clock.d.ts +3 -0
  190. package/dist/esm/application/ports/clock.js +1 -0
  191. package/dist/esm/application/ports/logger.d.ts +8 -0
  192. package/dist/esm/application/ports/logger.js +1 -0
  193. package/dist/esm/application/use-case/use-case.d.ts +6 -0
  194. package/dist/esm/application/use-case/use-case.js +20 -0
  195. package/dist/esm/domain/aggregate/aggregate-root.d.ts +14 -0
  196. package/dist/esm/domain/aggregate/aggregate-root.js +29 -0
  197. package/dist/esm/domain/entity/entity.d.ts +9 -0
  198. package/dist/esm/domain/entity/entity.js +15 -0
  199. package/dist/esm/domain/event/event-base.d.ts +29 -0
  200. package/dist/esm/domain/event/event-base.js +47 -0
  201. package/dist/esm/domain/index.d.ts +10 -0
  202. package/dist/esm/domain/index.js +6 -0
  203. package/dist/esm/domain/primitive/primitive-types.d.ts +22 -0
  204. package/dist/esm/domain/primitive/primitive-types.js +1 -0
  205. package/dist/esm/domain/repository/aggregate-finder.d.ts +4 -0
  206. package/dist/esm/domain/repository/aggregate-finder.js +1 -0
  207. package/dist/esm/domain/repository/aggregate-remover.d.ts +4 -0
  208. package/dist/esm/domain/repository/aggregate-remover.js +1 -0
  209. package/dist/esm/domain/repository/aggregate-saver.d.ts +4 -0
  210. package/dist/esm/domain/repository/aggregate-saver.js +1 -0
  211. package/dist/esm/domain/specification/specification.d.ts +9 -0
  212. package/dist/esm/domain/specification/specification.js +40 -0
  213. package/dist/esm/domain/type/abstract-type.d.ts +20 -0
  214. package/dist/esm/domain/type/abstract-type.js +65 -0
  215. package/dist/esm/domain/type/array-type.d.ts +16 -0
  216. package/dist/esm/domain/type/array-type.js +61 -0
  217. package/dist/esm/domain/type/boolean-type.d.ts +4 -0
  218. package/dist/esm/domain/type/boolean-type.js +12 -0
  219. package/dist/esm/domain/type/composite/composite-field.d.ts +19 -0
  220. package/dist/esm/domain/type/composite/composite-field.js +59 -0
  221. package/dist/esm/domain/type/composite/composite.d.ts +26 -0
  222. package/dist/esm/domain/type/composite/composite.js +52 -0
  223. package/dist/esm/domain/type/date-type.d.ts +18 -0
  224. package/dist/esm/domain/type/date-type.js +29 -0
  225. package/dist/esm/domain/type/enum-type.d.ts +7 -0
  226. package/dist/esm/domain/type/enum-type.js +26 -0
  227. package/dist/esm/domain/type/equality/value-equality.d.ts +7 -0
  228. package/dist/esm/domain/type/equality/value-equality.js +37 -0
  229. package/dist/esm/domain/type/id-type.d.ts +7 -0
  230. package/dist/esm/domain/type/id-type.js +13 -0
  231. package/dist/esm/domain/type/immutable/immutable-date.d.ts +4 -0
  232. package/dist/esm/domain/type/immutable/immutable-date.js +33 -0
  233. package/dist/esm/domain/type/immutable/immutable.d.ts +4 -0
  234. package/dist/esm/domain/type/immutable/immutable.js +15 -0
  235. package/dist/esm/domain/type/index.d.ts +17 -0
  236. package/dist/esm/domain/type/index.js +14 -0
  237. package/dist/esm/domain/type/json-type.d.ts +5 -0
  238. package/dist/esm/domain/type/json-type.js +13 -0
  239. package/dist/esm/domain/type/number-type.d.ts +4 -0
  240. package/dist/esm/domain/type/number-type.js +12 -0
  241. package/dist/esm/domain/type/required/required-mark.d.ts +9 -0
  242. package/dist/esm/domain/type/required/required-mark.js +9 -0
  243. package/dist/esm/domain/type/required/required.d.ts +7 -0
  244. package/dist/esm/domain/type/required/required.js +18 -0
  245. package/dist/esm/domain/type/string-type.d.ts +4 -0
  246. package/dist/esm/domain/type/string-type.js +12 -0
  247. package/dist/esm/domain/type/uuid-type.d.ts +7 -0
  248. package/dist/esm/domain/type/uuid-type.js +23 -0
  249. package/dist/esm/domain/type/value-objects/value-objects.d.ts +16 -0
  250. package/dist/esm/domain/type/value-objects/value-objects.js +66 -0
  251. package/dist/esm/exceptions/abstract.exception.d.ts +23 -0
  252. package/dist/esm/exceptions/abstract.exception.js +62 -0
  253. package/dist/esm/exceptions/application/aggregate-not-found.exception.d.ts +5 -0
  254. package/dist/esm/exceptions/application/aggregate-not-found.exception.js +13 -0
  255. package/dist/esm/exceptions/application/application.exception.d.ts +6 -0
  256. package/dist/esm/exceptions/application/application.exception.js +13 -0
  257. package/dist/esm/exceptions/application/concurrency.exception.d.ts +5 -0
  258. package/dist/esm/exceptions/application/concurrency.exception.js +13 -0
  259. package/dist/esm/exceptions/application/not-allowed.exception.d.ts +5 -0
  260. package/dist/esm/exceptions/application/not-allowed.exception.js +13 -0
  261. package/dist/esm/exceptions/brand/exception-brand.d.ts +6 -0
  262. package/dist/esm/exceptions/brand/exception-brand.js +25 -0
  263. package/dist/esm/exceptions/domain/domain.exception.d.ts +6 -0
  264. package/dist/esm/exceptions/domain/domain.exception.js +13 -0
  265. package/dist/esm/exceptions/domain/required-value.exception.d.ts +4 -0
  266. package/dist/esm/exceptions/domain/required-value.exception.js +17 -0
  267. package/dist/esm/exceptions/domain/type-primitive.exception.d.ts +4 -0
  268. package/dist/esm/exceptions/domain/type-primitive.exception.js +17 -0
  269. package/dist/esm/exceptions/domain/validation.exception.d.ts +14 -0
  270. package/dist/esm/exceptions/domain/validation.exception.js +19 -0
  271. package/dist/esm/exceptions/exception-code.d.ts +15 -0
  272. package/dist/esm/exceptions/exception-code.js +16 -0
  273. package/dist/esm/exceptions/index.d.ts +14 -0
  274. package/dist/esm/exceptions/index.js +14 -0
  275. package/dist/esm/exceptions/infrastructure/event-delivery.exception.d.ts +5 -0
  276. package/dist/esm/exceptions/infrastructure/event-delivery.exception.js +16 -0
  277. package/dist/esm/exceptions/infrastructure/infrastructure.exception.d.ts +6 -0
  278. package/dist/esm/exceptions/infrastructure/infrastructure.exception.js +13 -0
  279. package/dist/esm/exceptions/infrastructure/internal-error.exception.d.ts +5 -0
  280. package/dist/esm/exceptions/infrastructure/internal-error.exception.js +13 -0
  281. package/dist/esm/exceptions/infrastructure/unknown-event.exception.d.ts +4 -0
  282. package/dist/esm/exceptions/infrastructure/unknown-event.exception.js +15 -0
  283. package/dist/esm/exceptions/received/received-value.d.ts +4 -0
  284. package/dist/esm/exceptions/received/received-value.js +9 -0
  285. package/dist/esm/infrastructure/clock/fixed-clock.d.ts +8 -0
  286. package/dist/esm/infrastructure/clock/fixed-clock.js +15 -0
  287. package/dist/esm/infrastructure/clock/system-clock.d.ts +4 -0
  288. package/dist/esm/infrastructure/clock/system-clock.js +5 -0
  289. package/dist/esm/infrastructure/event/domain-event-bus.d.ts +16 -0
  290. package/dist/esm/infrastructure/event/domain-event-bus.js +56 -0
  291. package/dist/esm/infrastructure/event/event-channel.d.ts +9 -0
  292. package/dist/esm/infrastructure/event/event-channel.js +1 -0
  293. package/dist/esm/infrastructure/event/event-registry.d.ts +9 -0
  294. package/dist/esm/infrastructure/event/event-registry.js +39 -0
  295. package/dist/esm/infrastructure/event/in-memory/emitter.d.ts +11 -0
  296. package/dist/esm/infrastructure/event/in-memory/emitter.js +50 -0
  297. package/dist/esm/infrastructure/event/in-memory/in-memory-event-channel.d.ts +16 -0
  298. package/dist/esm/infrastructure/event/in-memory/in-memory-event-channel.js +47 -0
  299. package/dist/esm/infrastructure/http/http-error-mapper.d.ts +23 -0
  300. package/dist/esm/infrastructure/http/http-error-mapper.js +59 -0
  301. package/dist/esm/infrastructure/index.d.ts +16 -0
  302. package/dist/esm/infrastructure/index.js +9 -0
  303. package/dist/esm/infrastructure/logging/console-logger.d.ts +17 -0
  304. package/dist/esm/infrastructure/logging/console-logger.js +33 -0
  305. package/dist/esm/infrastructure/logging/in-memory-logger.d.ts +15 -0
  306. package/dist/esm/infrastructure/logging/in-memory-logger.js +23 -0
  307. package/dist/esm/infrastructure/logging/log-serializer.d.ts +7 -0
  308. package/dist/esm/infrastructure/logging/log-serializer.js +55 -0
  309. package/dist/esm/infrastructure/logging/silent-logger.d.ts +7 -0
  310. package/dist/esm/infrastructure/logging/silent-logger.js +14 -0
  311. package/dist/esm/package.json +3 -0
  312. package/package.json +106 -4
@@ -0,0 +1,17 @@
1
+ var _a;
2
+ import { DomainException } from './domain.exception.js';
3
+ import { ExceptionBrand } from '../brand/exception-brand.js';
4
+ import { ExceptionCode } from '../exception-code.js';
5
+ import { ReceivedValue } from '../received/received-value.js';
6
+ export class TypePrimitiveException extends DomainException {
7
+ constructor(expectedType, receivedValue, template = 'Expected a valid ') {
8
+ const received = ReceivedValue.describe(receivedValue);
9
+ super(`Validation Error: ${template}${expectedType}, but received ${received}.`, [
10
+ ExceptionCode.TypeFailed,
11
+ ]);
12
+ }
13
+ }
14
+ _a = TypePrimitiveException;
15
+ (() => {
16
+ ExceptionBrand.brandClass(_a, ExceptionCode.TypeFailed);
17
+ })();
@@ -0,0 +1,14 @@
1
+ import { DomainException } from './domain.exception.js';
2
+ export interface ValidationIssue {
3
+ readonly field: string | null;
4
+ readonly code: string;
5
+ readonly message: string;
6
+ }
7
+ export type ValidationIssueInput = Omit<ValidationIssue, 'code'> & {
8
+ readonly code?: string;
9
+ };
10
+ export declare class ValidationException extends DomainException {
11
+ readonly errors: readonly ValidationIssue[];
12
+ constructor(errors: readonly ValidationIssueInput[]);
13
+ private static describe;
14
+ }
@@ -0,0 +1,19 @@
1
+ var _a;
2
+ import { DomainException } from './domain.exception.js';
3
+ import { ExceptionBrand } from '../brand/exception-brand.js';
4
+ import { ExceptionCode } from '../exception-code.js';
5
+ export class ValidationException extends DomainException {
6
+ constructor(errors) {
7
+ super(`Validation failed, ${errors.map(_a.describe).join(', ')}`, [
8
+ ExceptionCode.ValidationFailed,
9
+ ]);
10
+ this.errors = Object.freeze(errors.map(({ field, code = ExceptionCode.ValidationFailed, message }) => Object.freeze({ field, code, message })));
11
+ }
12
+ static describe(issue) {
13
+ return issue.field === null ? issue.message : `${issue.field}: ${issue.message}`;
14
+ }
15
+ }
16
+ _a = ValidationException;
17
+ (() => {
18
+ ExceptionBrand.brandClass(_a, ExceptionCode.ValidationFailed);
19
+ })();
@@ -0,0 +1,15 @@
1
+ export declare enum ExceptionCode {
2
+ DomainException = "DOM000",
3
+ ValidationFailed = "DOM001",
4
+ TypeFailed = "DOM003",
5
+ RequiredValue = "DOM004",
6
+ ApplicationException = "APP000",
7
+ ConcurrencyConflict = "APP001",
8
+ AggregateNotFound = "APP002",
9
+ NotAllowed = "APP003",
10
+ InfrastructureException = "INF000",
11
+ InternalError = "INF001",
12
+ UnknownEvent = "INF002",
13
+ EventDelivery = "INF003",
14
+ ErrorException = "E000"
15
+ }
@@ -0,0 +1,16 @@
1
+ export var ExceptionCode;
2
+ (function (ExceptionCode) {
3
+ ExceptionCode["DomainException"] = "DOM000";
4
+ ExceptionCode["ValidationFailed"] = "DOM001";
5
+ ExceptionCode["TypeFailed"] = "DOM003";
6
+ ExceptionCode["RequiredValue"] = "DOM004";
7
+ ExceptionCode["ApplicationException"] = "APP000";
8
+ ExceptionCode["ConcurrencyConflict"] = "APP001";
9
+ ExceptionCode["AggregateNotFound"] = "APP002";
10
+ ExceptionCode["NotAllowed"] = "APP003";
11
+ ExceptionCode["InfrastructureException"] = "INF000";
12
+ ExceptionCode["InternalError"] = "INF001";
13
+ ExceptionCode["UnknownEvent"] = "INF002";
14
+ ExceptionCode["EventDelivery"] = "INF003";
15
+ ExceptionCode["ErrorException"] = "E000";
16
+ })(ExceptionCode || (ExceptionCode = {}));
@@ -0,0 +1,14 @@
1
+ export * from './abstract.exception.js';
2
+ export * from './exception-code.js';
3
+ export * from './application/application.exception.js';
4
+ export * from './application/concurrency.exception.js';
5
+ export * from './application/aggregate-not-found.exception.js';
6
+ export * from './application/not-allowed.exception.js';
7
+ export * from './infrastructure/infrastructure.exception.js';
8
+ export * from './infrastructure/internal-error.exception.js';
9
+ export * from './infrastructure/unknown-event.exception.js';
10
+ export * from './infrastructure/event-delivery.exception.js';
11
+ export * from './domain/validation.exception.js';
12
+ export * from './domain/domain.exception.js';
13
+ export * from './domain/required-value.exception.js';
14
+ export * from './domain/type-primitive.exception.js';
@@ -0,0 +1,14 @@
1
+ export * from './abstract.exception.js';
2
+ export * from './exception-code.js';
3
+ export * from './application/application.exception.js';
4
+ export * from './application/concurrency.exception.js';
5
+ export * from './application/aggregate-not-found.exception.js';
6
+ export * from './application/not-allowed.exception.js';
7
+ export * from './infrastructure/infrastructure.exception.js';
8
+ export * from './infrastructure/internal-error.exception.js';
9
+ export * from './infrastructure/unknown-event.exception.js';
10
+ export * from './infrastructure/event-delivery.exception.js';
11
+ export * from './domain/validation.exception.js';
12
+ export * from './domain/domain.exception.js';
13
+ export * from './domain/required-value.exception.js';
14
+ export * from './domain/type-primitive.exception.js';
@@ -0,0 +1,5 @@
1
+ import { InfrastructureException } from './infrastructure.exception.js';
2
+ export declare class EventDeliveryException extends InfrastructureException {
3
+ readonly errors: readonly unknown[];
4
+ constructor(eventName: string, errors: readonly unknown[], consumers: number);
5
+ }
@@ -0,0 +1,16 @@
1
+ var _a;
2
+ import { InfrastructureException } from './infrastructure.exception.js';
3
+ import { ExceptionBrand } from '../brand/exception-brand.js';
4
+ import { ExceptionCode } from '../exception-code.js';
5
+ export class EventDeliveryException extends InfrastructureException {
6
+ constructor(eventName, errors, consumers) {
7
+ super(`${errors.length} of ${consumers} consumers of "${eventName}" failed.`, [
8
+ ExceptionCode.EventDelivery,
9
+ ]);
10
+ this.errors = Object.freeze([...errors]);
11
+ }
12
+ }
13
+ _a = EventDeliveryException;
14
+ (() => {
15
+ ExceptionBrand.brandClass(_a, ExceptionCode.EventDelivery);
16
+ })();
@@ -0,0 +1,6 @@
1
+ import { AbstractException } from '../abstract.exception.js';
2
+ import type { ExceptionOptions } from '../abstract.exception.js';
3
+ import { ExceptionCode } from '../exception-code.js';
4
+ export declare class InfrastructureException extends AbstractException {
5
+ constructor(message: string, exceptionCodes?: (ExceptionCode | string)[], options?: ExceptionOptions);
6
+ }
@@ -0,0 +1,13 @@
1
+ var _a;
2
+ import { AbstractException } from '../abstract.exception.js';
3
+ import { ExceptionBrand } from '../brand/exception-brand.js';
4
+ import { ExceptionCode } from '../exception-code.js';
5
+ export class InfrastructureException extends AbstractException {
6
+ constructor(message, exceptionCodes = [], options = {}) {
7
+ super(message, [ExceptionCode.InfrastructureException, ...exceptionCodes], options);
8
+ }
9
+ }
10
+ _a = InfrastructureException;
11
+ (() => {
12
+ ExceptionBrand.brandClass(_a, ExceptionCode.InfrastructureException);
13
+ })();
@@ -0,0 +1,5 @@
1
+ import { InfrastructureException } from './infrastructure.exception.js';
2
+ import type { ExceptionOptions } from '../abstract.exception.js';
3
+ export declare class InternalErrorException extends InfrastructureException {
4
+ constructor(message: string, options?: ExceptionOptions);
5
+ }
@@ -0,0 +1,13 @@
1
+ var _a;
2
+ import { InfrastructureException } from './infrastructure.exception.js';
3
+ import { ExceptionBrand } from '../brand/exception-brand.js';
4
+ import { ExceptionCode } from '../exception-code.js';
5
+ export class InternalErrorException extends InfrastructureException {
6
+ constructor(message, options = {}) {
7
+ super(`Failed, internal error: ${message}`, [ExceptionCode.InternalError], options);
8
+ }
9
+ }
10
+ _a = InternalErrorException;
11
+ (() => {
12
+ ExceptionBrand.brandClass(_a, ExceptionCode.InternalError);
13
+ })();
@@ -0,0 +1,4 @@
1
+ import { InfrastructureException } from './infrastructure.exception.js';
2
+ export declare class UnknownEventException extends InfrastructureException {
3
+ constructor(eventName: string);
4
+ }
@@ -0,0 +1,15 @@
1
+ var _a;
2
+ import { InfrastructureException } from './infrastructure.exception.js';
3
+ import { ExceptionBrand } from '../brand/exception-brand.js';
4
+ import { ExceptionCode } from '../exception-code.js';
5
+ export class UnknownEventException extends InfrastructureException {
6
+ constructor(eventName) {
7
+ super(`Unknown event "${eventName}": register it before reading it.`, [
8
+ ExceptionCode.UnknownEvent,
9
+ ]);
10
+ }
11
+ }
12
+ _a = UnknownEventException;
13
+ (() => {
14
+ ExceptionBrand.brandClass(_a, ExceptionCode.UnknownEvent);
15
+ })();
@@ -0,0 +1,4 @@
1
+ export declare class ReceivedValue {
2
+ static readonly maxLength = 64;
3
+ static describe(value: unknown): string;
4
+ }
@@ -0,0 +1,9 @@
1
+ import { anyToString } from '@archi-code/validation';
2
+ export class ReceivedValue {
3
+ static describe(value) {
4
+ const text = typeof value === 'string' ? value : anyToString(value);
5
+ const shown = text.length > ReceivedValue.maxLength ? `${text.slice(0, ReceivedValue.maxLength)}…` : text;
6
+ return typeof value === 'string' ? `"${shown}"` : shown;
7
+ }
8
+ }
9
+ ReceivedValue.maxLength = 64;
@@ -0,0 +1,8 @@
1
+ import type { Clock } from '../../application/index.js';
2
+ export declare class FixedClock implements Clock {
3
+ private current;
4
+ constructor(at: Date | string);
5
+ now(): Date;
6
+ set(at: Date | string): void;
7
+ advance(milliseconds: number): void;
8
+ }
@@ -0,0 +1,15 @@
1
+ import { CreatedAt } from '../../domain/index.js';
2
+ export class FixedClock {
3
+ constructor(at) {
4
+ this.current = new CreatedAt(at).value;
5
+ }
6
+ now() {
7
+ return new Date(this.current.getTime());
8
+ }
9
+ set(at) {
10
+ this.current = new CreatedAt(at).value;
11
+ }
12
+ advance(milliseconds) {
13
+ this.current = new CreatedAt(new Date(this.current.getTime() + milliseconds)).value;
14
+ }
15
+ }
@@ -0,0 +1,4 @@
1
+ import type { Clock } from '../../application/index.js';
2
+ export declare class SystemClock implements Clock {
3
+ now(): Date;
4
+ }
@@ -0,0 +1,5 @@
1
+ export class SystemClock {
2
+ now() {
3
+ return new Date();
4
+ }
5
+ }
@@ -0,0 +1,16 @@
1
+ import type { EventBase } from '../../domain/index.js';
2
+ import type { EventBus, EventListener, Logger } from '../../application/index.js';
3
+ import type { EventChannel } from './event-channel.js';
4
+ import type { EventRegistry } from './event-registry.js';
5
+ export interface Subscription {
6
+ unsubscribe(): Promise<void>;
7
+ }
8
+ export declare class DomainEventBus<Event extends EventBase = EventBase> implements EventBus<Event> {
9
+ private readonly channel;
10
+ private readonly registry;
11
+ private readonly logger;
12
+ constructor(channel: EventChannel, registry: EventRegistry<Event>, logger?: Logger);
13
+ publish(events: readonly Event[]): Promise<void>;
14
+ subscribe(listener: EventListener<Event>): Promise<Subscription>;
15
+ private deliver;
16
+ }
@@ -0,0 +1,56 @@
1
+ import { ApplicationException, DomainException, UnknownEventException, } from '../../exceptions/index.js';
2
+ import { ListensTo } from '../../application/index.js';
3
+ import { SilentLogger } from '../logging/silent-logger.js';
4
+ export class DomainEventBus {
5
+ constructor(channel, registry, logger = new SilentLogger()) {
6
+ this.channel = channel;
7
+ this.registry = registry;
8
+ this.logger = logger;
9
+ }
10
+ async publish(events) {
11
+ await this.channel.send(events.map((event) => event.toJSON()));
12
+ this.logger.debug('domain_events_published', {
13
+ events: events.map((event) => ({
14
+ eventName: event.eventName(),
15
+ eventId: event.eventId,
16
+ aggregateId: event.aggregateId,
17
+ })),
18
+ });
19
+ }
20
+ async subscribe(listener) {
21
+ const subscription = ListensTo.subscriptionOf(listener);
22
+ const { eventName, consumer } = subscription;
23
+ if (!this.registry.has(eventName)) {
24
+ throw new UnknownEventException(eventName);
25
+ }
26
+ const channelSubscription = await this.channel.receive(eventName, consumer, (serialized) => this.deliver(listener, subscription, serialized));
27
+ this.logger.info('event_listener_subscribed', { eventName, consumer });
28
+ return {
29
+ unsubscribe: async () => {
30
+ await channelSubscription.close();
31
+ this.logger.info('event_listener_unsubscribed', { eventName, consumer });
32
+ },
33
+ };
34
+ }
35
+ async deliver(listener, { eventName, consumer }, serialized) {
36
+ try {
37
+ await listener.handle(this.registry.fromJSON(serialized));
38
+ }
39
+ catch (error) {
40
+ const context = {
41
+ eventName,
42
+ consumer,
43
+ eventId: serialized.eventId,
44
+ aggregateId: serialized.aggregateId,
45
+ error,
46
+ };
47
+ if (error instanceof DomainException || error instanceof ApplicationException) {
48
+ this.logger.warn('event_listener_rejected', context);
49
+ }
50
+ else {
51
+ this.logger.error('event_listener_failed', context);
52
+ }
53
+ throw error;
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,9 @@
1
+ import type { SerializedEvent } from '../../domain/index.js';
2
+ export type ChannelHandler = (event: SerializedEvent) => Promise<void>;
3
+ export interface ChannelSubscription {
4
+ close(): Promise<void>;
5
+ }
6
+ export interface EventChannel {
7
+ send(events: readonly SerializedEvent[]): Promise<void>;
8
+ receive(eventName: string, consumer: string, handler: ChannelHandler): Promise<ChannelSubscription>;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { EventBase, EventClass, SerializedEvent } from '../../domain/index.js';
2
+ export type EventFactory<Event extends EventBase> = (serialized: SerializedEvent) => Event;
3
+ export declare class EventRegistry<Event extends EventBase = EventBase> {
4
+ private readonly factories;
5
+ register<Registered extends Event>(event: EventClass<Registered>, factory: EventFactory<Registered>): this;
6
+ has(eventName: string): boolean;
7
+ fromJSON(event: SerializedEvent): Event;
8
+ private static assertSameIdentity;
9
+ }
@@ -0,0 +1,39 @@
1
+ import { InternalErrorException, UnknownEventException } from '../../exceptions/index.js';
2
+ import { Immutable } from '../../domain/index.js';
3
+ export class EventRegistry {
4
+ constructor() {
5
+ this.factories = new Map();
6
+ }
7
+ register(event, factory) {
8
+ const { eventName } = event;
9
+ if (this.factories.has(eventName)) {
10
+ throw new InternalErrorException(`event "${eventName}" is already registered`);
11
+ }
12
+ this.factories.set(eventName, factory);
13
+ return this;
14
+ }
15
+ has(eventName) {
16
+ return this.factories.has(eventName);
17
+ }
18
+ fromJSON(event) {
19
+ if (typeof event !== 'object' || event === null) {
20
+ throw new InternalErrorException('a serialized event must be a JSON object');
21
+ }
22
+ if (typeof event.eventName !== 'string') {
23
+ throw new InternalErrorException('a serialized event needs its eventName');
24
+ }
25
+ const factory = this.factories.get(event.eventName);
26
+ if (factory === undefined) {
27
+ throw new UnknownEventException(event.eventName);
28
+ }
29
+ const rebuilt = factory(event);
30
+ EventRegistry.assertSameIdentity(event, rebuilt);
31
+ return Immutable.freeze(rebuilt);
32
+ }
33
+ static assertSameIdentity(serialized, rebuilt) {
34
+ if (rebuilt.eventId !== String(serialized.eventId).toLowerCase() ||
35
+ rebuilt.occurredOn.getTime() !== new Date(serialized.occurredOn).getTime()) {
36
+ throw new InternalErrorException(`the factory of "${serialized.eventName}" must pass the serialized event as metadata, so it keeps its eventId and occurredOn`);
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,11 @@
1
+ type EmitterListener<Data> = (data: Data) => Promise<void> | void;
2
+ export declare class Emitter<Data> {
3
+ private static readonly resolved;
4
+ private readonly events;
5
+ on(eventName: string, listener: EmitterListener<Data>): () => void;
6
+ private off;
7
+ emit(eventName: string, data: Data): Promise<void>;
8
+ emitSerial(eventName: string, data: Data): Promise<void>;
9
+ private listenersOf;
10
+ }
11
+ export {};
@@ -0,0 +1,50 @@
1
+ import { EventDeliveryException } from '../../../exceptions/index.js';
2
+ export class Emitter {
3
+ constructor() {
4
+ this.events = new Map();
5
+ }
6
+ on(eventName, listener) {
7
+ const listeners = this.events.get(eventName) ?? new Set();
8
+ listeners.add(listener);
9
+ this.events.set(eventName, listeners);
10
+ return () => this.off(eventName, listener);
11
+ }
12
+ off(eventName, listener) {
13
+ const listeners = this.events.get(eventName);
14
+ if (listeners === undefined) {
15
+ return;
16
+ }
17
+ listeners.delete(listener);
18
+ if (listeners.size === 0) {
19
+ this.events.delete(eventName);
20
+ }
21
+ }
22
+ async emit(eventName, data) {
23
+ const listeners = this.listenersOf(eventName);
24
+ const snapshot = Array.from(listeners);
25
+ await Emitter.resolved;
26
+ const results = await Promise.allSettled(snapshot.map(async (listener) => {
27
+ if (listeners.has(listener)) {
28
+ await listener(data);
29
+ }
30
+ }));
31
+ const errors = results.flatMap((result) => result.status === 'rejected' ? [result.reason] : []);
32
+ if (errors.length > 0) {
33
+ throw new EventDeliveryException(eventName, errors, snapshot.length);
34
+ }
35
+ }
36
+ async emitSerial(eventName, data) {
37
+ const listeners = this.listenersOf(eventName);
38
+ const snapshot = Array.from(listeners);
39
+ await Emitter.resolved;
40
+ for (const listener of snapshot) {
41
+ if (listeners.has(listener)) {
42
+ await listener(data);
43
+ }
44
+ }
45
+ }
46
+ listenersOf(eventName) {
47
+ return this.events.get(eventName) ?? new Set();
48
+ }
49
+ }
50
+ Emitter.resolved = Promise.resolve();
@@ -0,0 +1,16 @@
1
+ import type { ChannelHandler, ChannelSubscription, EventChannel } from '../event-channel.js';
2
+ import type { SerializedEvent } from '../../../domain/index.js';
3
+ export interface InMemoryEventChannelOptions {
4
+ readonly delivery?: 'serial' | 'parallel';
5
+ }
6
+ export declare class InMemoryEventChannel implements EventChannel {
7
+ private readonly emitter;
8
+ private readonly receivers;
9
+ private readonly sentEvents;
10
+ private readonly delivery;
11
+ constructor({ delivery }?: InMemoryEventChannelOptions);
12
+ get sent(): readonly SerializedEvent[];
13
+ send(events: readonly SerializedEvent[]): Promise<void>;
14
+ receive(eventName: string, consumer: string, handler: ChannelHandler): Promise<ChannelSubscription>;
15
+ private static frozenCopy;
16
+ }
@@ -0,0 +1,47 @@
1
+ import { Immutable } from '../../../domain/index.js';
2
+ import { InfrastructureException } from '../../../exceptions/index.js';
3
+ import { Emitter } from './emitter.js';
4
+ export class InMemoryEventChannel {
5
+ constructor({ delivery = 'serial' } = {}) {
6
+ this.emitter = new Emitter();
7
+ this.receivers = new Set();
8
+ this.sentEvents = [];
9
+ this.delivery = delivery;
10
+ }
11
+ get sent() {
12
+ return [...this.sentEvents];
13
+ }
14
+ async send(events) {
15
+ for (const event of events) {
16
+ const copy = InMemoryEventChannel.frozenCopy(event);
17
+ this.sentEvents.push(copy);
18
+ if (this.delivery === 'parallel') {
19
+ await this.emitter.emit(copy.eventName, copy);
20
+ }
21
+ else {
22
+ await this.emitter.emitSerial(copy.eventName, copy);
23
+ }
24
+ }
25
+ }
26
+ async receive(eventName, consumer, handler) {
27
+ const receiver = JSON.stringify([eventName, consumer]);
28
+ if (this.receivers.has(receiver)) {
29
+ throw new InfrastructureException(`${consumer} already receives "${eventName}": close its subscription first.`);
30
+ }
31
+ this.receivers.add(receiver);
32
+ const off = this.emitter.on(eventName, (event) => handler(event));
33
+ let open = true;
34
+ return {
35
+ close: async () => {
36
+ if (open) {
37
+ open = false;
38
+ off();
39
+ this.receivers.delete(receiver);
40
+ }
41
+ },
42
+ };
43
+ }
44
+ static frozenCopy(event) {
45
+ return Immutable.freeze(JSON.parse(JSON.stringify(event)));
46
+ }
47
+ }
@@ -0,0 +1,23 @@
1
+ import type { ValidationIssue } from '../../exceptions/index.js';
2
+ import type { Logger } from '../../application/index.js';
3
+ export interface HttpErrorBody {
4
+ code: string;
5
+ message: string;
6
+ errors?: readonly ValidationIssue[];
7
+ }
8
+ export interface HttpError {
9
+ status: number;
10
+ body: HttpErrorBody;
11
+ }
12
+ export interface HttpErrorMapperOptions {
13
+ readonly statusByCode?: Readonly<Record<string, number>>;
14
+ readonly logger?: Logger;
15
+ }
16
+ export declare class HttpErrorMapper {
17
+ private readonly statusByCode;
18
+ private readonly logger;
19
+ constructor({ statusByCode, logger }?: HttpErrorMapperOptions);
20
+ map(error: unknown): HttpError;
21
+ private toHttpError;
22
+ private static defaultStatus;
23
+ }
@@ -0,0 +1,59 @@
1
+ import { AbstractException, AggregateNotFoundException, ApplicationException, ConcurrencyException, DomainException, ExceptionCode, NotAllowedException, RequiredValueException, TypePrimitiveException, ValidationException, } from '../../exceptions/index.js';
2
+ import { SilentLogger } from '../logging/silent-logger.js';
3
+ const INTERNAL_MESSAGE = 'Internal server error';
4
+ export class HttpErrorMapper {
5
+ constructor({ statusByCode = {}, logger = new SilentLogger() } = {}) {
6
+ this.statusByCode = statusByCode;
7
+ this.logger = logger;
8
+ }
9
+ map(error) {
10
+ const mapped = this.toHttpError(error);
11
+ const { status, body } = mapped;
12
+ if (status >= 500) {
13
+ this.logger.error('http_request_failed', { status, code: body.code, error });
14
+ }
15
+ else {
16
+ this.logger.debug('http_request_rejected', { status, code: body.code });
17
+ }
18
+ return mapped;
19
+ }
20
+ toHttpError(error) {
21
+ if (!(error instanceof AbstractException)) {
22
+ return {
23
+ status: 500,
24
+ body: { code: ExceptionCode.ErrorException, message: INTERNAL_MESSAGE },
25
+ };
26
+ }
27
+ const status = Object.prototype.hasOwnProperty.call(this.statusByCode, error.code)
28
+ ? this.statusByCode[error.code]
29
+ : HttpErrorMapper.defaultStatus(error);
30
+ if (status >= 500) {
31
+ return { status, body: { code: error.code, message: INTERNAL_MESSAGE } };
32
+ }
33
+ if (error instanceof ValidationException) {
34
+ return { status, body: { code: error.code, message: error.message, errors: error.errors } };
35
+ }
36
+ return { status, body: { code: error.code, message: error.message } };
37
+ }
38
+ static defaultStatus(error) {
39
+ if (error instanceof AggregateNotFoundException) {
40
+ return 404;
41
+ }
42
+ if (error instanceof NotAllowedException) {
43
+ return 403;
44
+ }
45
+ if (error instanceof ConcurrencyException) {
46
+ return 409;
47
+ }
48
+ if (error instanceof TypePrimitiveException || error instanceof RequiredValueException) {
49
+ return 400;
50
+ }
51
+ if (error instanceof DomainException) {
52
+ return 422;
53
+ }
54
+ if (error instanceof ApplicationException) {
55
+ return 400;
56
+ }
57
+ return 500;
58
+ }
59
+ }
@@ -0,0 +1,16 @@
1
+ export { SystemClock } from './clock/system-clock.js';
2
+ export { FixedClock } from './clock/fixed-clock.js';
3
+ export { DomainEventBus } from './event/domain-event-bus.js';
4
+ export type { Subscription } from './event/domain-event-bus.js';
5
+ export { EventRegistry } from './event/event-registry.js';
6
+ export type { EventFactory } from './event/event-registry.js';
7
+ export type { ChannelHandler, ChannelSubscription, EventChannel } from './event/event-channel.js';
8
+ export { InMemoryEventChannel } from './event/in-memory/in-memory-event-channel.js';
9
+ export type { InMemoryEventChannelOptions } from './event/in-memory/in-memory-event-channel.js';
10
+ export { HttpErrorMapper } from './http/http-error-mapper.js';
11
+ export type { HttpError, HttpErrorBody, HttpErrorMapperOptions } from './http/http-error-mapper.js';
12
+ export { ConsoleLogger } from './logging/console-logger.js';
13
+ export type { ConsoleLoggerOptions } from './logging/console-logger.js';
14
+ export { InMemoryLogger } from './logging/in-memory-logger.js';
15
+ export type { LogEntry } from './logging/in-memory-logger.js';
16
+ export { SilentLogger } from './logging/silent-logger.js';
@@ -0,0 +1,9 @@
1
+ export { SystemClock } from './clock/system-clock.js';
2
+ export { FixedClock } from './clock/fixed-clock.js';
3
+ export { DomainEventBus } from './event/domain-event-bus.js';
4
+ export { EventRegistry } from './event/event-registry.js';
5
+ export { InMemoryEventChannel } from './event/in-memory/in-memory-event-channel.js';
6
+ export { HttpErrorMapper } from './http/http-error-mapper.js';
7
+ export { ConsoleLogger } from './logging/console-logger.js';
8
+ export { InMemoryLogger } from './logging/in-memory-logger.js';
9
+ export { SilentLogger } from './logging/silent-logger.js';