@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,37 @@
1
+ export class ValueEquality {
2
+ static equals(left, right) {
3
+ if (left === right || (Number.isNaN(left) && Number.isNaN(right))) {
4
+ return true;
5
+ }
6
+ if (left instanceof Date || right instanceof Date) {
7
+ return ValueEquality.sameInstant(left, right);
8
+ }
9
+ if (Array.isArray(left) || Array.isArray(right)) {
10
+ return ValueEquality.sameItems(left, right);
11
+ }
12
+ if (ValueEquality.isRecord(left) && ValueEquality.isRecord(right)) {
13
+ return ValueEquality.sameEntries(left, right);
14
+ }
15
+ return false;
16
+ }
17
+ static sameInstant(left, right) {
18
+ return (left instanceof Date &&
19
+ right instanceof Date &&
20
+ ValueEquality.equals(left.getTime(), right.getTime()));
21
+ }
22
+ static sameItems(left, right) {
23
+ return (Array.isArray(left) &&
24
+ Array.isArray(right) &&
25
+ left.length === right.length &&
26
+ left.every((item, index) => ValueEquality.equals(item, right[index])));
27
+ }
28
+ static sameEntries(left, right) {
29
+ const keys = Object.keys(left);
30
+ return (keys.length === Object.keys(right).length &&
31
+ keys.every((key) => Object.prototype.hasOwnProperty.call(right, key) &&
32
+ ValueEquality.equals(left[key], right[key])));
33
+ }
34
+ static isRecord(value) {
35
+ return typeof value === 'object' && value !== null;
36
+ }
37
+ }
@@ -0,0 +1,7 @@
1
+ import { UuidType } from './uuid-type.js';
2
+ declare const IdType_base: import("./required/required.js").RequiredType<typeof UuidType>;
3
+ export declare class IdType<Brand extends string = string> extends IdType_base {
4
+ protected readonly idBrand: Brand;
5
+ protected filter(value: unknown): string;
6
+ }
7
+ export {};
@@ -0,0 +1,13 @@
1
+ import { Required } from './required/required.js';
2
+ import { UuidType } from './uuid-type.js';
3
+ import { TypePrimitiveException } from '../../exceptions/index.js';
4
+ const NIL_OR_MAX_UUID = /^(?:0{8}-0{4}-0{4}-0{4}-0{12}|f{8}-f{4}-f{4}-f{4}-f{12})$/i;
5
+ export class IdType extends Required(UuidType) {
6
+ filter(value) {
7
+ const id = super.filter(value);
8
+ if (NIL_OR_MAX_UUID.test(id)) {
9
+ throw new TypePrimitiveException('Id', value);
10
+ }
11
+ return id;
12
+ }
13
+ }
@@ -0,0 +1,4 @@
1
+ export declare class ImmutableDate extends Date {
2
+ private static readonly setters;
3
+ constructor(date: Date);
4
+ }
@@ -0,0 +1,33 @@
1
+ export class ImmutableDate extends Date {
2
+ constructor(date) {
3
+ super(date.getTime());
4
+ Object.freeze(this);
5
+ }
6
+ }
7
+ ImmutableDate.setters = [
8
+ 'setDate',
9
+ 'setFullYear',
10
+ 'setHours',
11
+ 'setMilliseconds',
12
+ 'setMinutes',
13
+ 'setMonth',
14
+ 'setSeconds',
15
+ 'setTime',
16
+ 'setUTCDate',
17
+ 'setUTCFullYear',
18
+ 'setUTCHours',
19
+ 'setUTCMilliseconds',
20
+ 'setUTCMinutes',
21
+ 'setUTCMonth',
22
+ 'setUTCSeconds',
23
+ 'setYear',
24
+ ];
25
+ (() => {
26
+ for (const setter of ImmutableDate.setters) {
27
+ Object.defineProperty(ImmutableDate.prototype, setter, {
28
+ value() {
29
+ throw new TypeError(`Cannot call ${setter}: the date is immutable`);
30
+ },
31
+ });
32
+ }
33
+ })();
@@ -0,0 +1,4 @@
1
+ export declare class Immutable {
2
+ static freeze<T>(value: T): T;
3
+ static date(date: Date): Date;
4
+ }
@@ -0,0 +1,15 @@
1
+ import { ImmutableDate } from './immutable-date.js';
2
+ export class Immutable {
3
+ static freeze(value) {
4
+ if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
5
+ Object.freeze(value);
6
+ for (const child of Object.values(value)) {
7
+ Immutable.freeze(child);
8
+ }
9
+ }
10
+ return value;
11
+ }
12
+ static date(date) {
13
+ return new ImmutableDate(date);
14
+ }
15
+ }
@@ -0,0 +1,17 @@
1
+ export { AbstractType } from './abstract-type.js';
2
+ export { Required } from './required/required.js';
3
+ export type { RequiredType } from './required/required.js';
4
+ export { ArrayType } from './array-type.js';
5
+ export { BooleanType } from './boolean-type.js';
6
+ export { CreatedAt, DateType, UpdatedAt } from './date-type.js';
7
+ export { EnumType } from './enum-type.js';
8
+ export { JsonType } from './json-type.js';
9
+ export type { JsonTypeValue } from './json-type.js';
10
+ export { NumberType } from './number-type.js';
11
+ export { StringType } from './string-type.js';
12
+ export { IdType } from './id-type.js';
13
+ export { UuidType } from './uuid-type.js';
14
+ export { Immutable } from './immutable/immutable.js';
15
+ export { ValueObjects } from './value-objects/value-objects.js';
16
+ export { Composite } from './composite/composite.js';
17
+ export type { CompositeInput, CompositePrimitives, CompositeProps, CompositeSchema, CompositeType, CompositeValue, } from './composite/composite.js';
@@ -0,0 +1,14 @@
1
+ export { AbstractType } from './abstract-type.js';
2
+ export { Required } from './required/required.js';
3
+ export { ArrayType } from './array-type.js';
4
+ export { BooleanType } from './boolean-type.js';
5
+ export { CreatedAt, DateType, UpdatedAt } from './date-type.js';
6
+ export { EnumType } from './enum-type.js';
7
+ export { JsonType } from './json-type.js';
8
+ export { NumberType } from './number-type.js';
9
+ export { StringType } from './string-type.js';
10
+ export { IdType } from './id-type.js';
11
+ export { UuidType } from './uuid-type.js';
12
+ export { Immutable } from './immutable/immutable.js';
13
+ export { ValueObjects } from './value-objects/value-objects.js';
14
+ export { Composite } from './composite/composite.js';
@@ -0,0 +1,5 @@
1
+ import { AbstractType } from './abstract-type.js';
2
+ export type JsonTypeValue = Record<string, any>;
3
+ export declare class JsonType<T extends JsonTypeValue = JsonTypeValue> extends AbstractType<T> {
4
+ protected filter(value: unknown): T;
5
+ }
@@ -0,0 +1,13 @@
1
+ import { toJson } from '@archi-code/validation';
2
+ import { AbstractType } from './abstract-type.js';
3
+ import { Immutable } from './immutable/immutable.js';
4
+ import { TypePrimitiveException } from '../../exceptions/index.js';
5
+ export class JsonType extends AbstractType {
6
+ filter(value) {
7
+ const converted = toJson(value);
8
+ if (!converted.ok) {
9
+ throw new TypePrimitiveException('Json', value);
10
+ }
11
+ return Immutable.freeze(JSON.parse(JSON.stringify(converted.value)));
12
+ }
13
+ }
@@ -0,0 +1,4 @@
1
+ import { AbstractType } from './abstract-type.js';
2
+ export declare class NumberType extends AbstractType<number> {
3
+ protected filter(value: unknown): number;
4
+ }
@@ -0,0 +1,12 @@
1
+ import { toFloat } from '@archi-code/validation';
2
+ import { AbstractType } from './abstract-type.js';
3
+ import { TypePrimitiveException } from '../../exceptions/index.js';
4
+ export class NumberType extends AbstractType {
5
+ filter(value) {
6
+ const converted = toFloat(value);
7
+ if (!converted.ok) {
8
+ throw new TypePrimitiveException('Number', value);
9
+ }
10
+ return converted.value;
11
+ }
12
+ }
@@ -0,0 +1,9 @@
1
+ export declare class RequiredMark {
2
+ static readonly symbol: unique symbol;
3
+ static isMarked(instance: object): boolean;
4
+ static mark(prototype: object): void;
5
+ }
6
+ export interface RequiredMarked {
7
+ readonly [RequiredMark.symbol]: true;
8
+ }
9
+ export type ValueOf<T, I> = I extends RequiredMarked ? T : T | null;
@@ -0,0 +1,9 @@
1
+ export class RequiredMark {
2
+ static isMarked(instance) {
3
+ return instance[RequiredMark.symbol] === true;
4
+ }
5
+ static mark(prototype) {
6
+ Object.defineProperty(prototype, RequiredMark.symbol, { value: true });
7
+ }
8
+ }
9
+ RequiredMark.symbol = Symbol.for('@archi-code/ddd/required.v1');
@@ -0,0 +1,7 @@
1
+ import type { AbstractType } from '../abstract-type.js';
2
+ import type { RequiredMarked } from './required-mark.js';
3
+ type TypeClass = abstract new (value?: any) => AbstractType<any>;
4
+ type RequiredValueOf<C extends TypeClass> = Exclude<ConstructorParameters<C>[0], null | undefined>;
5
+ export type RequiredType<C extends TypeClass> = Omit<C, 'prototype'> & (abstract new (value: RequiredValueOf<C>) => InstanceType<C> & RequiredMarked);
6
+ export declare function Required<C extends TypeClass>(Base: C): RequiredType<C>;
7
+ export {};
@@ -0,0 +1,18 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Validations } from '@archi-code/validation';
8
+ import { RequiredMark } from './required-mark.js';
9
+ export function Required(Base) {
10
+ let RequiredValue = class RequiredValue extends Base {
11
+ };
12
+ RequiredValue = __decorate([
13
+ Validations([{ validator: 'isRequired' }])
14
+ ], RequiredValue);
15
+ Object.defineProperty(RequiredValue, 'name', { value: `Required(${Base.name})` });
16
+ RequiredMark.mark(RequiredValue.prototype);
17
+ return RequiredValue;
18
+ }
@@ -0,0 +1,4 @@
1
+ import { AbstractType } from './abstract-type.js';
2
+ export declare class StringType extends AbstractType<string> {
3
+ protected filter(value: unknown): string;
4
+ }
@@ -0,0 +1,12 @@
1
+ import { toString as convertToString } from '@archi-code/validation';
2
+ import { AbstractType } from './abstract-type.js';
3
+ import { TypePrimitiveException } from '../../exceptions/index.js';
4
+ export class StringType extends AbstractType {
5
+ filter(value) {
6
+ const converted = convertToString(value);
7
+ if (!converted.ok) {
8
+ throw new TypePrimitiveException('String', value);
9
+ }
10
+ return converted.value;
11
+ }
12
+ }
@@ -0,0 +1,7 @@
1
+ import { AbstractType } from './abstract-type.js';
2
+ export declare class UuidType extends AbstractType<string> {
3
+ static random(): string;
4
+ static generate<T extends AbstractType<string>>(this: new (value: string) => T): T;
5
+ static fromValue(value: string, namespace?: string): string;
6
+ protected filter(value: unknown): string;
7
+ }
@@ -0,0 +1,23 @@
1
+ import { v4 as uuidv4, v5 as uuidv5 } from 'uuid';
2
+ import { isUUID, toString as convertToString } from '@archi-code/validation';
3
+ import { AbstractType } from './abstract-type.js';
4
+ import { TypePrimitiveException } from '../../exceptions/index.js';
5
+ const DNS_NAMESPACE = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
6
+ export class UuidType extends AbstractType {
7
+ static random() {
8
+ return uuidv4();
9
+ }
10
+ static generate() {
11
+ return new this(uuidv4());
12
+ }
13
+ static fromValue(value, namespace = DNS_NAMESPACE) {
14
+ return uuidv5(value, namespace);
15
+ }
16
+ filter(value) {
17
+ const converted = convertToString(value);
18
+ if (!converted.ok || !isUUID(converted.value)) {
19
+ throw new TypePrimitiveException('UUID', value);
20
+ }
21
+ return converted.value.toLowerCase();
22
+ }
23
+ }
@@ -0,0 +1,16 @@
1
+ type Factories = Record<string, () => unknown>;
2
+ type Built<F extends Factories> = {
3
+ [Field in keyof F]: ReturnType<F[Field]>;
4
+ };
5
+ type Synchronous<F extends Factories> = {
6
+ [Field in keyof F]: [ReturnType<F[Field]>] extends [never] ? F[Field] : [ReturnType<F[Field]>] extends [PromiseLike<unknown>] ? never : F[Field];
7
+ };
8
+ export declare class ValueObjects {
9
+ static build<F extends Factories>(factories: F & Synchronous<F>): Built<F>;
10
+ static buildList<Value, Item>(values: readonly Value[], factory: (value: Value, index: number) => Item): Item[];
11
+ private static synchronous;
12
+ private static isThenable;
13
+ private static issuesOf;
14
+ private static assertNoIssues;
15
+ }
16
+ export {};
@@ -0,0 +1,66 @@
1
+ import { DomainException, InternalErrorException, ValidationException, } from '../../../exceptions/index.js';
2
+ export class ValueObjects {
3
+ static build(factories) {
4
+ const built = {};
5
+ const issues = [];
6
+ for (const [field, factory] of Object.entries(factories)) {
7
+ try {
8
+ Object.defineProperty(built, field, {
9
+ value: ValueObjects.synchronous(field, factory()),
10
+ enumerable: true,
11
+ writable: true,
12
+ configurable: true,
13
+ });
14
+ }
15
+ catch (error) {
16
+ issues.push(...ValueObjects.issuesOf(field, error));
17
+ }
18
+ }
19
+ ValueObjects.assertNoIssues(issues);
20
+ return built;
21
+ }
22
+ static buildList(values, factory) {
23
+ const built = [];
24
+ const issues = [];
25
+ values.forEach((value, index) => {
26
+ try {
27
+ built.push(ValueObjects.synchronous(String(index), factory(value, index)));
28
+ }
29
+ catch (error) {
30
+ issues.push(...ValueObjects.issuesOf(String(index), error));
31
+ }
32
+ });
33
+ ValueObjects.assertNoIssues(issues);
34
+ return built;
35
+ }
36
+ static synchronous(field, result) {
37
+ if (!ValueObjects.isThenable(result)) {
38
+ return result;
39
+ }
40
+ result.then(undefined, () => undefined);
41
+ throw new InternalErrorException(`ValueObjects: the factory of "${field}" returned a Promise; build value objects synchronously`);
42
+ }
43
+ static isThenable(result) {
44
+ return ((typeof result === 'object' || typeof result === 'function') &&
45
+ result !== null &&
46
+ typeof result.then === 'function');
47
+ }
48
+ static issuesOf(field, error) {
49
+ if (error instanceof ValidationException) {
50
+ return error.errors.map((issue) => ({
51
+ field: issue.field === null ? field : `${field}.${issue.field}`,
52
+ code: issue.code,
53
+ message: issue.message,
54
+ }));
55
+ }
56
+ if (error instanceof DomainException) {
57
+ return [{ field, code: error.code, message: error.message }];
58
+ }
59
+ throw error;
60
+ }
61
+ static assertNoIssues(issues) {
62
+ if (issues.length > 0) {
63
+ throw new ValidationException(issues);
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,23 @@
1
+ import { ExceptionCode } from './exception-code.js';
2
+ export interface ExceptionOptions {
3
+ cause?: unknown;
4
+ }
5
+ export declare abstract class AbstractException extends Error {
6
+ readonly cause?: unknown;
7
+ private readonly exceptionCodes;
8
+ readonly code: ExceptionCode | string;
9
+ private readonly createdAt;
10
+ static [Symbol.hasInstance](candidate: unknown): boolean;
11
+ constructor(message: string, exceptionCodes: (ExceptionCode | string)[], options?: ExceptionOptions);
12
+ static readonly ExceptionCodeStrings: Record<ExceptionCode, string>;
13
+ get timestamp(): Date;
14
+ get description(): string;
15
+ print(): string;
16
+ toJSON(): {
17
+ name: string;
18
+ message: string;
19
+ code: string;
20
+ description: string;
21
+ timestamp: string;
22
+ };
23
+ }
@@ -0,0 +1,62 @@
1
+ var _a;
2
+ import { ExceptionCode } from './exception-code.js';
3
+ import { ExceptionBrand } from './brand/exception-brand.js';
4
+ export class AbstractException extends Error {
5
+ static [Symbol.hasInstance](candidate) {
6
+ return (Function.prototype[Symbol.hasInstance].call(this, candidate) ||
7
+ ExceptionBrand.matches(this, candidate));
8
+ }
9
+ constructor(message, exceptionCodes, options = {}) {
10
+ super(message);
11
+ this.name = this.constructor.name;
12
+ this.exceptionCodes = exceptionCodes;
13
+ this.code =
14
+ exceptionCodes.length > 0
15
+ ? exceptionCodes[exceptionCodes.length - 1]
16
+ : ExceptionCode.ErrorException;
17
+ this.createdAt = Date.now();
18
+ if ('cause' in options) {
19
+ Object.defineProperty(this, 'cause', {
20
+ value: options.cause,
21
+ writable: true,
22
+ configurable: true,
23
+ });
24
+ }
25
+ ExceptionBrand.brandInstance(this, exceptionCodes);
26
+ Error.captureStackTrace?.(this, this.constructor);
27
+ }
28
+ get timestamp() {
29
+ return new Date(this.createdAt);
30
+ }
31
+ get description() {
32
+ return this.exceptionCodes
33
+ .map((code) => {
34
+ const codeString = _a.ExceptionCodeStrings[code] ?? this.name;
35
+ return `${codeString} (${code})`;
36
+ })
37
+ .join(', ');
38
+ }
39
+ print() {
40
+ return `[${this.description}]: ${this.message}, ${this.timestamp.toISOString()}`;
41
+ }
42
+ toJSON() {
43
+ return {
44
+ name: this.name,
45
+ message: this.message,
46
+ code: this.code,
47
+ description: this.description,
48
+ timestamp: this.timestamp.toISOString(),
49
+ };
50
+ }
51
+ }
52
+ _a = AbstractException;
53
+ (() => {
54
+ ExceptionBrand.brandClass(_a, ExceptionBrand.anyCode);
55
+ })();
56
+ AbstractException.ExceptionCodeStrings = Object.keys(ExceptionCode)
57
+ .filter((key) => isNaN(Number(key)))
58
+ .reduce((acc, key) => {
59
+ const value = ExceptionCode[key];
60
+ acc[value] = key.replace(/([A-Z])/g, ' $1').trim();
61
+ return acc;
62
+ }, {});
@@ -0,0 +1,5 @@
1
+ import { ApplicationException } from './application.exception.js';
2
+ import type { ExceptionOptions } from '../abstract.exception.js';
3
+ export declare class AggregateNotFoundException extends ApplicationException {
4
+ constructor(entity: string, id: string, options?: ExceptionOptions);
5
+ }
@@ -0,0 +1,13 @@
1
+ var _a;
2
+ import { ApplicationException } from './application.exception.js';
3
+ import { ExceptionBrand } from '../brand/exception-brand.js';
4
+ import { ExceptionCode } from '../exception-code.js';
5
+ export class AggregateNotFoundException extends ApplicationException {
6
+ constructor(entity, id, options = {}) {
7
+ super(`${entity} with ID ${id} not found.`, [ExceptionCode.AggregateNotFound], options);
8
+ }
9
+ }
10
+ _a = AggregateNotFoundException;
11
+ (() => {
12
+ ExceptionBrand.brandClass(_a, ExceptionCode.AggregateNotFound);
13
+ })();
@@ -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 ApplicationException 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 ApplicationException extends AbstractException {
6
+ constructor(message, exceptionCodes = [], options = {}) {
7
+ super(message, [ExceptionCode.ApplicationException, ...exceptionCodes], options);
8
+ }
9
+ }
10
+ _a = ApplicationException;
11
+ (() => {
12
+ ExceptionBrand.brandClass(_a, ExceptionCode.ApplicationException);
13
+ })();
@@ -0,0 +1,5 @@
1
+ import { ApplicationException } from './application.exception.js';
2
+ import type { ExceptionOptions } from '../abstract.exception.js';
3
+ export declare class ConcurrencyException extends ApplicationException {
4
+ constructor(aggregateName: string, id: string, expectedVersion: number, options?: ExceptionOptions);
5
+ }
@@ -0,0 +1,13 @@
1
+ var _a;
2
+ import { ApplicationException } from './application.exception.js';
3
+ import { ExceptionBrand } from '../brand/exception-brand.js';
4
+ import { ExceptionCode } from '../exception-code.js';
5
+ export class ConcurrencyException extends ApplicationException {
6
+ constructor(aggregateName, id, expectedVersion, options = {}) {
7
+ super(`${aggregateName} with ID ${id} was changed by someone else: expected version ${expectedVersion}.`, [ExceptionCode.ConcurrencyConflict], options);
8
+ }
9
+ }
10
+ _a = ConcurrencyException;
11
+ (() => {
12
+ ExceptionBrand.brandClass(_a, ExceptionCode.ConcurrencyConflict);
13
+ })();
@@ -0,0 +1,5 @@
1
+ import { ApplicationException } from './application.exception.js';
2
+ import type { ExceptionOptions } from '../abstract.exception.js';
3
+ export declare class NotAllowedException extends ApplicationException {
4
+ constructor(message: string, options?: ExceptionOptions);
5
+ }
@@ -0,0 +1,13 @@
1
+ var _a;
2
+ import { ApplicationException } from './application.exception.js';
3
+ import { ExceptionBrand } from '../brand/exception-brand.js';
4
+ import { ExceptionCode } from '../exception-code.js';
5
+ export class NotAllowedException extends ApplicationException {
6
+ constructor(message, options = {}) {
7
+ super(message, [ExceptionCode.NotAllowed], options);
8
+ }
9
+ }
10
+ _a = NotAllowedException;
11
+ (() => {
12
+ ExceptionBrand.brandClass(_a, ExceptionCode.NotAllowed);
13
+ })();
@@ -0,0 +1,6 @@
1
+ export declare class ExceptionBrand {
2
+ static readonly anyCode = "*";
3
+ static brandClass(exceptionClass: object, code: string): void;
4
+ static brandInstance(exception: object, codes: readonly string[]): void;
5
+ static matches(exceptionClass: object, candidate: unknown): boolean;
6
+ }
@@ -0,0 +1,25 @@
1
+ const INSTANCE_CODES = Symbol.for('@archi-code/ddd/exception-codes.v1');
2
+ const CLASS_CODE = Symbol.for('@archi-code/ddd/exception-class-code.v1');
3
+ export class ExceptionBrand {
4
+ static brandClass(exceptionClass, code) {
5
+ Object.defineProperty(exceptionClass, CLASS_CODE, { value: code });
6
+ }
7
+ static brandInstance(exception, codes) {
8
+ Object.defineProperty(exception, INSTANCE_CODES, { value: Object.freeze([...codes]) });
9
+ }
10
+ static matches(exceptionClass, candidate) {
11
+ if (!Object.prototype.hasOwnProperty.call(exceptionClass, CLASS_CODE)) {
12
+ return false;
13
+ }
14
+ if (typeof candidate !== 'object' || candidate === null) {
15
+ return false;
16
+ }
17
+ const codes = candidate[INSTANCE_CODES];
18
+ if (!Array.isArray(codes)) {
19
+ return false;
20
+ }
21
+ const code = exceptionClass[CLASS_CODE];
22
+ return code === ExceptionBrand.anyCode || codes.includes(code);
23
+ }
24
+ }
25
+ ExceptionBrand.anyCode = '*';
@@ -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 DomainException 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 DomainException extends AbstractException {
6
+ constructor(message, exceptionCodes = [], options = {}) {
7
+ super(message, [ExceptionCode.DomainException, ...exceptionCodes], options);
8
+ }
9
+ }
10
+ _a = DomainException;
11
+ (() => {
12
+ ExceptionBrand.brandClass(_a, ExceptionCode.DomainException);
13
+ })();
@@ -0,0 +1,4 @@
1
+ import { DomainException } from './domain.exception.js';
2
+ export declare class RequiredValueException extends DomainException {
3
+ constructor(typeName: string, receivedValue: unknown);
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 RequiredValueException extends DomainException {
7
+ constructor(typeName, receivedValue) {
8
+ const received = ReceivedValue.describe(receivedValue);
9
+ super(`Validation Error: ${typeName} is required, but received ${received}.`, [
10
+ ExceptionCode.RequiredValue,
11
+ ]);
12
+ }
13
+ }
14
+ _a = RequiredValueException;
15
+ (() => {
16
+ ExceptionBrand.brandClass(_a, ExceptionCode.RequiredValue);
17
+ })();
@@ -0,0 +1,4 @@
1
+ import { DomainException } from './domain.exception.js';
2
+ export declare class TypePrimitiveException extends DomainException {
3
+ constructor(expectedType: string, receivedValue: unknown, template?: string);
4
+ }