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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (336) hide show
  1. package/LICENSE +46 -0
  2. package/README.md +2795 -2
  3. package/SKILL.md +106 -0
  4. package/ddd-skills/archi-code-ddd/imports.md +94 -0
  5. package/ddd-skills/archi-code-ddd/layers.md +314 -0
  6. package/ddd-skills/archi-code-ddd/patterns.md +683 -0
  7. package/ddd-skills/archi-code-ddd/what-not-to-do.md +196 -0
  8. package/ddd-skills/archi-code-ddd/where-each-class-goes.md +64 -0
  9. package/ddd-skills/ddd-agregados/GUIA.md +114 -0
  10. package/ddd-skills/ddd-agregados/references/consistencia-eventual.md +158 -0
  11. package/ddd-skills/ddd-agregados/references/ejemplo-ecommerce.md +52 -0
  12. package/ddd-skills/ddd-agregados/references/fabricas.md +193 -0
  13. package/ddd-skills/ddd-agregados/references/implementacion-ts.md +706 -0
  14. package/ddd-skills/ddd-arquitectura/GUIA.md +80 -0
  15. package/ddd-skills/ddd-arquitectura/assets/dependency-cruiser.cjs +99 -0
  16. package/ddd-skills/ddd-arquitectura/references/estilos-adicionales.md +51 -0
  17. package/ddd-skills/ddd-arquitectura/references/estructura-hexagonal-ts.md +406 -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 +314 -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 +419 -0
  26. package/ddd-skills/ddd-context-mapping/references/estilos-integracion.md +152 -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 +476 -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 +130 -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 +529 -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 +314 -0
  38. package/ddd-skills/ddd-repositorios-persistencia/references/tests-repositorios.md +191 -0
  39. package/ddd-skills/ddd-repositorios-persistencia/references/transacciones-ts.md +301 -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 +321 -0
  43. package/ddd-skills/ddd-servicios-capa-aplicacion/references/servicios-dominio-ts.md +190 -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 +218 -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 +376 -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/exceptions/aggregate-not-found.exception.d.ts +5 -0
  58. package/dist/cjs/application/exceptions/aggregate-not-found.exception.js +17 -0
  59. package/dist/cjs/application/exceptions/application-exception-code.d.ts +7 -0
  60. package/dist/cjs/application/exceptions/application-exception-code.js +11 -0
  61. package/dist/cjs/application/exceptions/application.exception.d.ts +6 -0
  62. package/dist/cjs/application/exceptions/application.exception.js +16 -0
  63. package/dist/cjs/application/exceptions/concurrency.exception.d.ts +5 -0
  64. package/dist/cjs/application/exceptions/concurrency.exception.js +17 -0
  65. package/dist/cjs/application/exceptions/not-allowed.exception.d.ts +5 -0
  66. package/dist/cjs/application/exceptions/not-allowed.exception.js +17 -0
  67. package/dist/cjs/application/exceptions/unexpected-error.exception.d.ts +5 -0
  68. package/dist/cjs/application/exceptions/unexpected-error.exception.js +17 -0
  69. package/dist/cjs/application/index.d.ts +14 -0
  70. package/dist/cjs/application/index.js +23 -0
  71. package/dist/cjs/application/ports/clock.d.ts +3 -0
  72. package/dist/cjs/application/ports/clock.js +2 -0
  73. package/dist/cjs/application/ports/logger.d.ts +8 -0
  74. package/dist/cjs/application/ports/logger.js +2 -0
  75. package/dist/cjs/application/use-case/use-case.d.ts +6 -0
  76. package/dist/cjs/application/use-case/use-case.js +25 -0
  77. package/dist/cjs/application/value-object-builder/value-object-builder.d.ts +16 -0
  78. package/dist/cjs/application/value-object-builder/value-object-builder.js +51 -0
  79. package/dist/cjs/domain/aggregate/aggregate-root.d.ts +9 -0
  80. package/dist/cjs/domain/aggregate/aggregate-root.js +17 -0
  81. package/dist/cjs/domain/entity/entity.d.ts +9 -0
  82. package/dist/cjs/domain/entity/entity.js +19 -0
  83. package/dist/cjs/domain/event/event-base.d.ts +23 -0
  84. package/dist/cjs/domain/event/event-base.js +21 -0
  85. package/dist/cjs/domain/exceptions/domain-exception-code.d.ts +7 -0
  86. package/dist/cjs/domain/exceptions/domain-exception-code.js +11 -0
  87. package/dist/cjs/domain/exceptions/domain.exception.d.ts +6 -0
  88. package/dist/cjs/domain/exceptions/domain.exception.js +16 -0
  89. package/dist/cjs/domain/exceptions/invalid-event-definition.exception.d.ts +4 -0
  90. package/dist/cjs/domain/exceptions/invalid-event-definition.exception.js +19 -0
  91. package/dist/cjs/domain/exceptions/required-value.exception.d.ts +4 -0
  92. package/dist/cjs/domain/exceptions/required-value.exception.js +20 -0
  93. package/dist/cjs/domain/exceptions/type-primitive.exception.d.ts +4 -0
  94. package/dist/cjs/domain/exceptions/type-primitive.exception.js +20 -0
  95. package/dist/cjs/domain/exceptions/validation.exception.d.ts +14 -0
  96. package/dist/cjs/domain/exceptions/validation.exception.js +23 -0
  97. package/dist/cjs/domain/index.d.ts +17 -0
  98. package/dist/cjs/domain/index.js +36 -0
  99. package/dist/cjs/domain/primitive/primitive-types.d.ts +20 -0
  100. package/dist/cjs/domain/primitive/primitive-types.js +2 -0
  101. package/dist/cjs/domain/repository/aggregate-finder.d.ts +4 -0
  102. package/dist/cjs/domain/repository/aggregate-finder.js +2 -0
  103. package/dist/cjs/domain/repository/aggregate-remover.d.ts +4 -0
  104. package/dist/cjs/domain/repository/aggregate-remover.js +2 -0
  105. package/dist/cjs/domain/repository/aggregate-saver.d.ts +4 -0
  106. package/dist/cjs/domain/repository/aggregate-saver.js +2 -0
  107. package/dist/cjs/domain/specification/specification.d.ts +9 -0
  108. package/dist/cjs/domain/specification/specification.js +44 -0
  109. package/dist/cjs/domain/type/abstract-type.d.ts +18 -0
  110. package/dist/cjs/domain/type/abstract-type.js +61 -0
  111. package/dist/cjs/domain/type/array-type.d.ts +17 -0
  112. package/dist/cjs/domain/type/array-type.js +64 -0
  113. package/dist/cjs/domain/type/boolean-type.d.ts +4 -0
  114. package/dist/cjs/domain/type/boolean-type.js +16 -0
  115. package/dist/cjs/domain/type/composite/composite-brand.d.ts +4 -0
  116. package/dist/cjs/domain/type/composite/composite-brand.js +15 -0
  117. package/dist/cjs/domain/type/composite/composite-field.d.ts +18 -0
  118. package/dist/cjs/domain/type/composite/composite-field.js +86 -0
  119. package/dist/cjs/domain/type/composite/composite-issues.d.ts +6 -0
  120. package/dist/cjs/domain/type/composite/composite-issues.js +35 -0
  121. package/dist/cjs/domain/type/composite/composite.d.ts +26 -0
  122. package/dist/cjs/domain/type/composite/composite.js +51 -0
  123. package/dist/cjs/domain/type/date-type.d.ts +19 -0
  124. package/dist/cjs/domain/type/date-type.js +70 -0
  125. package/dist/cjs/domain/type/enum-type.d.ts +7 -0
  126. package/dist/cjs/domain/type/enum-type.js +30 -0
  127. package/dist/cjs/domain/type/id-type.d.ts +7 -0
  128. package/dist/cjs/domain/type/id-type.js +17 -0
  129. package/dist/cjs/domain/type/index.d.ts +15 -0
  130. package/dist/cjs/domain/type/index.js +29 -0
  131. package/dist/cjs/domain/type/json-type.d.ts +9 -0
  132. package/dist/cjs/domain/type/json-type.js +46 -0
  133. package/dist/cjs/domain/type/number-type.d.ts +4 -0
  134. package/dist/cjs/domain/type/number-type.js +16 -0
  135. package/dist/cjs/domain/type/required/required-mark.d.ts +8 -0
  136. package/dist/cjs/domain/type/required/required-mark.js +13 -0
  137. package/dist/cjs/domain/type/required/required-type.d.ts +7 -0
  138. package/dist/cjs/domain/type/required/required-type.js +21 -0
  139. package/dist/cjs/domain/type/string-type.d.ts +4 -0
  140. package/dist/cjs/domain/type/string-type.js +16 -0
  141. package/dist/cjs/domain/type/uuid-type.d.ts +7 -0
  142. package/dist/cjs/domain/type/uuid-type.js +27 -0
  143. package/dist/cjs/infrastructure/clock/fixed-clock.d.ts +8 -0
  144. package/dist/cjs/infrastructure/clock/fixed-clock.js +19 -0
  145. package/dist/cjs/infrastructure/clock/system-clock.d.ts +4 -0
  146. package/dist/cjs/infrastructure/clock/system-clock.js +9 -0
  147. package/dist/cjs/infrastructure/event/domain-event-bus.d.ts +16 -0
  148. package/dist/cjs/infrastructure/event/domain-event-bus.js +60 -0
  149. package/dist/cjs/infrastructure/event/event-channel.d.ts +9 -0
  150. package/dist/cjs/infrastructure/event/event-channel.js +2 -0
  151. package/dist/cjs/infrastructure/event/event-registry.d.ts +9 -0
  152. package/dist/cjs/infrastructure/event/event-registry.js +43 -0
  153. package/dist/cjs/infrastructure/event/in-memory/emitter.d.ts +11 -0
  154. package/dist/cjs/infrastructure/event/in-memory/emitter.js +54 -0
  155. package/dist/cjs/infrastructure/event/in-memory/in-memory-event-channel.d.ts +16 -0
  156. package/dist/cjs/infrastructure/event/in-memory/in-memory-event-channel.js +50 -0
  157. package/dist/cjs/infrastructure/exceptions/event-delivery.exception.d.ts +5 -0
  158. package/dist/cjs/infrastructure/exceptions/event-delivery.exception.js +20 -0
  159. package/dist/cjs/infrastructure/exceptions/infrastructure-exception-code.d.ts +6 -0
  160. package/dist/cjs/infrastructure/exceptions/infrastructure-exception-code.js +10 -0
  161. package/dist/cjs/infrastructure/exceptions/infrastructure.exception.d.ts +6 -0
  162. package/dist/cjs/infrastructure/exceptions/infrastructure.exception.js +16 -0
  163. package/dist/cjs/infrastructure/exceptions/internal-error.exception.d.ts +5 -0
  164. package/dist/cjs/infrastructure/exceptions/internal-error.exception.js +17 -0
  165. package/dist/cjs/infrastructure/exceptions/kind/exception-classifier.d.ts +4 -0
  166. package/dist/cjs/infrastructure/exceptions/kind/exception-classifier.js +34 -0
  167. package/dist/cjs/infrastructure/exceptions/kind/exception-kind.d.ts +9 -0
  168. package/dist/cjs/infrastructure/exceptions/kind/exception-kind.js +13 -0
  169. package/dist/cjs/infrastructure/exceptions/unknown-event.exception.d.ts +4 -0
  170. package/dist/cjs/infrastructure/exceptions/unknown-event.exception.js +19 -0
  171. package/dist/cjs/infrastructure/index.d.ts +21 -0
  172. package/dist/cjs/infrastructure/index.js +33 -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/cjs/shared/exceptions/abstract.exception.d.ts +25 -0
  182. package/dist/cjs/shared/exceptions/abstract.exception.js +59 -0
  183. package/dist/cjs/shared/exceptions/brand/exception-brand.d.ts +6 -0
  184. package/dist/cjs/shared/exceptions/brand/exception-brand.js +29 -0
  185. package/dist/cjs/shared/exceptions/received/received-value.d.ts +4 -0
  186. package/dist/cjs/shared/exceptions/received/received-value.js +13 -0
  187. package/dist/cjs/shared/index.d.ts +8 -0
  188. package/dist/cjs/shared/index.js +13 -0
  189. package/dist/cjs/shared/issue-collection-error.d.ts +9 -0
  190. package/dist/cjs/shared/issue-collection-error.js +11 -0
  191. package/dist/cjs/shared/issue-collector.d.ts +8 -0
  192. package/dist/cjs/shared/issue-collector.js +41 -0
  193. package/dist/esm/application/event/event-bus.d.ts +4 -0
  194. package/dist/esm/application/event/event-bus.js +1 -0
  195. package/dist/esm/application/event/event-listener.d.ts +4 -0
  196. package/dist/esm/application/event/event-listener.js +2 -0
  197. package/dist/esm/application/event/listens-to.d.ts +15 -0
  198. package/dist/esm/application/event/listens-to.js +25 -0
  199. package/dist/esm/application/exceptions/aggregate-not-found.exception.d.ts +5 -0
  200. package/dist/esm/application/exceptions/aggregate-not-found.exception.js +13 -0
  201. package/dist/esm/application/exceptions/application-exception-code.d.ts +7 -0
  202. package/dist/esm/application/exceptions/application-exception-code.js +8 -0
  203. package/dist/esm/application/exceptions/application.exception.d.ts +6 -0
  204. package/dist/esm/application/exceptions/application.exception.js +12 -0
  205. package/dist/esm/application/exceptions/concurrency.exception.d.ts +5 -0
  206. package/dist/esm/application/exceptions/concurrency.exception.js +13 -0
  207. package/dist/esm/application/exceptions/not-allowed.exception.d.ts +5 -0
  208. package/dist/esm/application/exceptions/not-allowed.exception.js +13 -0
  209. package/dist/esm/application/exceptions/unexpected-error.exception.d.ts +5 -0
  210. package/dist/esm/application/exceptions/unexpected-error.exception.js +13 -0
  211. package/dist/esm/application/index.d.ts +14 -0
  212. package/dist/esm/application/index.js +10 -0
  213. package/dist/esm/application/ports/clock.d.ts +3 -0
  214. package/dist/esm/application/ports/clock.js +1 -0
  215. package/dist/esm/application/ports/logger.d.ts +8 -0
  216. package/dist/esm/application/ports/logger.js +1 -0
  217. package/dist/esm/application/use-case/use-case.d.ts +6 -0
  218. package/dist/esm/application/use-case/use-case.js +21 -0
  219. package/dist/esm/application/value-object-builder/value-object-builder.d.ts +16 -0
  220. package/dist/esm/application/value-object-builder/value-object-builder.js +47 -0
  221. package/dist/esm/domain/aggregate/aggregate-root.d.ts +9 -0
  222. package/dist/esm/domain/aggregate/aggregate-root.js +13 -0
  223. package/dist/esm/domain/entity/entity.d.ts +9 -0
  224. package/dist/esm/domain/entity/entity.js +15 -0
  225. package/dist/esm/domain/event/event-base.d.ts +23 -0
  226. package/dist/esm/domain/event/event-base.js +17 -0
  227. package/dist/esm/domain/exceptions/domain-exception-code.d.ts +7 -0
  228. package/dist/esm/domain/exceptions/domain-exception-code.js +8 -0
  229. package/dist/esm/domain/exceptions/domain.exception.d.ts +6 -0
  230. package/dist/esm/domain/exceptions/domain.exception.js +12 -0
  231. package/dist/esm/domain/exceptions/invalid-event-definition.exception.d.ts +4 -0
  232. package/dist/esm/domain/exceptions/invalid-event-definition.exception.js +15 -0
  233. package/dist/esm/domain/exceptions/required-value.exception.d.ts +4 -0
  234. package/dist/esm/domain/exceptions/required-value.exception.js +16 -0
  235. package/dist/esm/domain/exceptions/type-primitive.exception.d.ts +4 -0
  236. package/dist/esm/domain/exceptions/type-primitive.exception.js +16 -0
  237. package/dist/esm/domain/exceptions/validation.exception.d.ts +14 -0
  238. package/dist/esm/domain/exceptions/validation.exception.js +19 -0
  239. package/dist/esm/domain/index.d.ts +17 -0
  240. package/dist/esm/domain/index.js +12 -0
  241. package/dist/esm/domain/primitive/primitive-types.d.ts +20 -0
  242. package/dist/esm/domain/primitive/primitive-types.js +1 -0
  243. package/dist/esm/domain/repository/aggregate-finder.d.ts +4 -0
  244. package/dist/esm/domain/repository/aggregate-finder.js +1 -0
  245. package/dist/esm/domain/repository/aggregate-remover.d.ts +4 -0
  246. package/dist/esm/domain/repository/aggregate-remover.js +1 -0
  247. package/dist/esm/domain/repository/aggregate-saver.d.ts +4 -0
  248. package/dist/esm/domain/repository/aggregate-saver.js +1 -0
  249. package/dist/esm/domain/specification/specification.d.ts +9 -0
  250. package/dist/esm/domain/specification/specification.js +40 -0
  251. package/dist/esm/domain/type/abstract-type.d.ts +18 -0
  252. package/dist/esm/domain/type/abstract-type.js +57 -0
  253. package/dist/esm/domain/type/array-type.d.ts +17 -0
  254. package/dist/esm/domain/type/array-type.js +60 -0
  255. package/dist/esm/domain/type/boolean-type.d.ts +4 -0
  256. package/dist/esm/domain/type/boolean-type.js +12 -0
  257. package/dist/esm/domain/type/composite/composite-brand.d.ts +4 -0
  258. package/dist/esm/domain/type/composite/composite-brand.js +11 -0
  259. package/dist/esm/domain/type/composite/composite-field.d.ts +18 -0
  260. package/dist/esm/domain/type/composite/composite-field.js +82 -0
  261. package/dist/esm/domain/type/composite/composite-issues.d.ts +6 -0
  262. package/dist/esm/domain/type/composite/composite-issues.js +31 -0
  263. package/dist/esm/domain/type/composite/composite.d.ts +26 -0
  264. package/dist/esm/domain/type/composite/composite.js +48 -0
  265. package/dist/esm/domain/type/date-type.d.ts +19 -0
  266. package/dist/esm/domain/type/date-type.js +64 -0
  267. package/dist/esm/domain/type/enum-type.d.ts +7 -0
  268. package/dist/esm/domain/type/enum-type.js +26 -0
  269. package/dist/esm/domain/type/id-type.d.ts +7 -0
  270. package/dist/esm/domain/type/id-type.js +13 -0
  271. package/dist/esm/domain/type/index.d.ts +15 -0
  272. package/dist/esm/domain/type/index.js +12 -0
  273. package/dist/esm/domain/type/json-type.d.ts +9 -0
  274. package/dist/esm/domain/type/json-type.js +42 -0
  275. package/dist/esm/domain/type/number-type.d.ts +4 -0
  276. package/dist/esm/domain/type/number-type.js +12 -0
  277. package/dist/esm/domain/type/required/required-mark.d.ts +8 -0
  278. package/dist/esm/domain/type/required/required-mark.js +9 -0
  279. package/dist/esm/domain/type/required/required-type.d.ts +7 -0
  280. package/dist/esm/domain/type/required/required-type.js +18 -0
  281. package/dist/esm/domain/type/string-type.d.ts +4 -0
  282. package/dist/esm/domain/type/string-type.js +12 -0
  283. package/dist/esm/domain/type/uuid-type.d.ts +7 -0
  284. package/dist/esm/domain/type/uuid-type.js +23 -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 +46 -0
  299. package/dist/esm/infrastructure/exceptions/event-delivery.exception.d.ts +5 -0
  300. package/dist/esm/infrastructure/exceptions/event-delivery.exception.js +16 -0
  301. package/dist/esm/infrastructure/exceptions/infrastructure-exception-code.d.ts +6 -0
  302. package/dist/esm/infrastructure/exceptions/infrastructure-exception-code.js +7 -0
  303. package/dist/esm/infrastructure/exceptions/infrastructure.exception.d.ts +6 -0
  304. package/dist/esm/infrastructure/exceptions/infrastructure.exception.js +12 -0
  305. package/dist/esm/infrastructure/exceptions/internal-error.exception.d.ts +5 -0
  306. package/dist/esm/infrastructure/exceptions/internal-error.exception.js +13 -0
  307. package/dist/esm/infrastructure/exceptions/kind/exception-classifier.d.ts +4 -0
  308. package/dist/esm/infrastructure/exceptions/kind/exception-classifier.js +30 -0
  309. package/dist/esm/infrastructure/exceptions/kind/exception-kind.d.ts +9 -0
  310. package/dist/esm/infrastructure/exceptions/kind/exception-kind.js +10 -0
  311. package/dist/esm/infrastructure/exceptions/unknown-event.exception.d.ts +4 -0
  312. package/dist/esm/infrastructure/exceptions/unknown-event.exception.js +15 -0
  313. package/dist/esm/infrastructure/index.d.ts +21 -0
  314. package/dist/esm/infrastructure/index.js +15 -0
  315. package/dist/esm/infrastructure/logging/console-logger.d.ts +17 -0
  316. package/dist/esm/infrastructure/logging/console-logger.js +33 -0
  317. package/dist/esm/infrastructure/logging/in-memory-logger.d.ts +15 -0
  318. package/dist/esm/infrastructure/logging/in-memory-logger.js +23 -0
  319. package/dist/esm/infrastructure/logging/log-serializer.d.ts +7 -0
  320. package/dist/esm/infrastructure/logging/log-serializer.js +55 -0
  321. package/dist/esm/infrastructure/logging/silent-logger.d.ts +7 -0
  322. package/dist/esm/infrastructure/logging/silent-logger.js +14 -0
  323. package/dist/esm/package.json +3 -0
  324. package/dist/esm/shared/exceptions/abstract.exception.d.ts +25 -0
  325. package/dist/esm/shared/exceptions/abstract.exception.js +55 -0
  326. package/dist/esm/shared/exceptions/brand/exception-brand.d.ts +6 -0
  327. package/dist/esm/shared/exceptions/brand/exception-brand.js +25 -0
  328. package/dist/esm/shared/exceptions/received/received-value.d.ts +4 -0
  329. package/dist/esm/shared/exceptions/received/received-value.js +9 -0
  330. package/dist/esm/shared/index.d.ts +8 -0
  331. package/dist/esm/shared/index.js +5 -0
  332. package/dist/esm/shared/issue-collection-error.d.ts +9 -0
  333. package/dist/esm/shared/issue-collection-error.js +7 -0
  334. package/dist/esm/shared/issue-collector.d.ts +8 -0
  335. package/dist/esm/shared/issue-collector.js +37 -0
  336. package/package.json +95 -4
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export declare abstract class UseCase<Input, Command, Output> {
2
+ execute(input: Input): Promise<Output>;
3
+ protected abstract toCommand(input: Input): Command;
4
+ protected abstract handle(command: Command): Promise<Output> | Output;
5
+ private static describe;
6
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UseCase = void 0;
4
+ const validation_1 = require("@archi-code/validation");
5
+ const index_1 = require("../../shared/index");
6
+ const unexpected_error_exception_1 = require("../exceptions/unexpected-error.exception");
7
+ class UseCase {
8
+ async execute(input) {
9
+ try {
10
+ return await this.handle(this.toCommand(input));
11
+ }
12
+ catch (error) {
13
+ if (error instanceof index_1.AbstractException) {
14
+ throw error;
15
+ }
16
+ throw new unexpected_error_exception_1.UnexpectedErrorException(`${this.constructor.name}: ${UseCase.describe(error)}`, {
17
+ cause: error,
18
+ });
19
+ }
20
+ }
21
+ static describe(error) {
22
+ return error instanceof Error ? error.message : (0, validation_1.anyToString)(error);
23
+ }
24
+ }
25
+ exports.UseCase = UseCase;
@@ -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 ValueObjectBuilder {
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 validated;
13
+ private static read;
14
+ private static isThenable;
15
+ }
16
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValueObjectBuilder = void 0;
4
+ const index_1 = require("../../domain/index");
5
+ const index_2 = require("../../shared/index");
6
+ const unexpected_error_exception_1 = require("../exceptions/unexpected-error.exception");
7
+ class ValueObjectBuilder {
8
+ static build(factories) {
9
+ const builds = Object.fromEntries(Object.entries(factories).map(([field, factory]) => [
10
+ field,
11
+ () => ValueObjectBuilder.synchronous(field, factory()),
12
+ ]));
13
+ return ValueObjectBuilder.validated(() => index_2.IssueCollector.collectFields(builds, ValueObjectBuilder.read));
14
+ }
15
+ static buildList(values, factory) {
16
+ return ValueObjectBuilder.validated(() => index_2.IssueCollector.collectItems(values, (value, index) => ValueObjectBuilder.synchronous(String(index), factory(value, index)), ValueObjectBuilder.read));
17
+ }
18
+ static synchronous(field, result) {
19
+ if (!ValueObjectBuilder.isThenable(result)) {
20
+ return result;
21
+ }
22
+ result.then(undefined, () => undefined);
23
+ throw new unexpected_error_exception_1.UnexpectedErrorException(`ValueObjectBuilder: the factory of "${field}" returned a Promise; build value objects synchronously`);
24
+ }
25
+ static validated(collect) {
26
+ try {
27
+ return collect();
28
+ }
29
+ catch (error) {
30
+ if (error instanceof index_2.IssueCollectionError) {
31
+ throw new index_1.ValidationException(error.issues);
32
+ }
33
+ throw error;
34
+ }
35
+ }
36
+ static read(error) {
37
+ if (error instanceof index_1.ValidationException) {
38
+ return error.errors;
39
+ }
40
+ if (error instanceof index_1.DomainException) {
41
+ return [{ field: null, code: error.code, message: error.message }];
42
+ }
43
+ return null;
44
+ }
45
+ static isThenable(result) {
46
+ return ((typeof result === 'object' || typeof result === 'function') &&
47
+ result !== null &&
48
+ typeof result.then === 'function');
49
+ }
50
+ }
51
+ exports.ValueObjectBuilder = ValueObjectBuilder;
@@ -0,0 +1,9 @@
1
+ import { Entity } from '../entity/entity';
2
+ import type { EntityId } from '../entity/entity';
3
+ import type { EventBase } from '../event/event-base';
4
+ import type { IdType } from '../type/id-type';
5
+ export declare abstract class AggregateRoot<Id extends EntityId = IdType, Event extends EventBase = EventBase> extends Entity<Id> {
6
+ private readonly domainEvents;
7
+ protected record(event: Event): void;
8
+ pullDomainEvents(): Event[];
9
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AggregateRoot = void 0;
4
+ const entity_1 = require("../entity/entity");
5
+ class AggregateRoot extends entity_1.Entity {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.domainEvents = [];
9
+ }
10
+ record(event) {
11
+ this.domainEvents.push(event);
12
+ }
13
+ pullDomainEvents() {
14
+ return this.domainEvents.splice(0);
15
+ }
16
+ }
17
+ exports.AggregateRoot = AggregateRoot;
@@ -0,0 +1,9 @@
1
+ import type { AbstractType } from '../type/abstract-type';
2
+ import type { IdType } from '../type/id-type';
3
+ import type { RequiredMarked } from '../type/required/required-mark';
4
+ export type EntityId = AbstractType<any> & RequiredMarked;
5
+ export declare abstract class Entity<Id extends EntityId = IdType> {
6
+ readonly id: Id;
7
+ constructor(id: Id);
8
+ equals(other: unknown): boolean;
9
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Entity = void 0;
4
+ const required_value_exception_1 = require("../exceptions/required-value.exception");
5
+ class Entity {
6
+ constructor(id) {
7
+ this.id = id;
8
+ if (id?.isNull !== false) {
9
+ throw new required_value_exception_1.RequiredValueException(`${new.target.name}.id`, id?.value);
10
+ }
11
+ }
12
+ equals(other) {
13
+ return (typeof other === 'object' &&
14
+ other !== null &&
15
+ other.constructor === this.constructor &&
16
+ this.id.equals(other.id));
17
+ }
18
+ }
19
+ exports.Entity = Entity;
@@ -0,0 +1,23 @@
1
+ export interface EventMetadata {
2
+ eventId?: string;
3
+ occurredOn?: Date | string;
4
+ clock?: {
5
+ now(): Date;
6
+ };
7
+ }
8
+ export interface SerializedEvent {
9
+ eventName: string;
10
+ eventId: string;
11
+ occurredOn: string;
12
+ [payload: string]: unknown;
13
+ }
14
+ export interface EventClass<Event extends EventBase = EventBase> {
15
+ readonly eventName: string;
16
+ new (...args: any[]): Event;
17
+ }
18
+ export declare abstract class EventBase {
19
+ readonly eventName: string;
20
+ readonly eventId: string;
21
+ readonly occurredOn: string;
22
+ constructor(metadata?: EventMetadata);
23
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventBase = void 0;
4
+ const date_type_1 = require("../type/date-type");
5
+ const id_type_1 = require("../type/id-type");
6
+ const uuid_type_1 = require("../type/uuid-type");
7
+ const invalid_event_definition_exception_1 = require("../exceptions/invalid-event-definition.exception");
8
+ class EventBase {
9
+ constructor(metadata = {}) {
10
+ const { eventName } = this.constructor;
11
+ if (typeof eventName !== 'string' || eventName.trim() === '') {
12
+ throw new invalid_event_definition_exception_1.InvalidEventDefinitionException(this.constructor.name);
13
+ }
14
+ this.eventName = eventName;
15
+ this.eventId = new id_type_1.IdType(metadata.eventId ?? uuid_type_1.UuidType.random()).value;
16
+ this.occurredOn = (metadata.occurredOn === undefined
17
+ ? date_type_1.CreatedAt.now(metadata.clock)
18
+ : new date_type_1.CreatedAt(metadata.occurredOn)).value.toISOString();
19
+ }
20
+ }
21
+ exports.EventBase = EventBase;
@@ -0,0 +1,7 @@
1
+ export declare enum DomainExceptionCode {
2
+ DomainException = "DOM000",
3
+ ValidationFailed = "DOM001",
4
+ TypeFailed = "DOM003",
5
+ RequiredValue = "DOM004",
6
+ InvalidEventDefinition = "DOM005"
7
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DomainExceptionCode = void 0;
4
+ var DomainExceptionCode;
5
+ (function (DomainExceptionCode) {
6
+ DomainExceptionCode["DomainException"] = "DOM000";
7
+ DomainExceptionCode["ValidationFailed"] = "DOM001";
8
+ DomainExceptionCode["TypeFailed"] = "DOM003";
9
+ DomainExceptionCode["RequiredValue"] = "DOM004";
10
+ DomainExceptionCode["InvalidEventDefinition"] = "DOM005";
11
+ })(DomainExceptionCode || (exports.DomainExceptionCode = DomainExceptionCode = {}));
@@ -0,0 +1,6 @@
1
+ import { AbstractException } from '../../shared/index';
2
+ import type { ExceptionOptions } from '../../shared/index';
3
+ import { DomainExceptionCode } from './domain-exception-code';
4
+ export declare class DomainException extends AbstractException {
5
+ constructor(message: string, exceptionCodes?: (DomainExceptionCode | string)[], options?: ExceptionOptions);
6
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.DomainException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const domain_exception_code_1 = require("./domain-exception-code");
7
+ class DomainException extends index_1.AbstractException {
8
+ constructor(message, exceptionCodes = [], options = {}) {
9
+ super(message, [domain_exception_code_1.DomainExceptionCode.DomainException, ...exceptionCodes], options, domain_exception_code_1.DomainExceptionCode);
10
+ }
11
+ }
12
+ exports.DomainException = DomainException;
13
+ _a = DomainException;
14
+ (() => {
15
+ index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.DomainException);
16
+ })();
@@ -0,0 +1,4 @@
1
+ import { DomainException } from './domain.exception';
2
+ export declare class InvalidEventDefinitionException extends DomainException {
3
+ constructor(eventClassName: string);
4
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.InvalidEventDefinitionException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const domain_exception_code_1 = require("./domain-exception-code");
7
+ const domain_exception_1 = require("./domain.exception");
8
+ class InvalidEventDefinitionException extends domain_exception_1.DomainException {
9
+ constructor(eventClassName) {
10
+ super(`${eventClassName} must declare a static eventName`, [
11
+ domain_exception_code_1.DomainExceptionCode.InvalidEventDefinition,
12
+ ]);
13
+ }
14
+ }
15
+ exports.InvalidEventDefinitionException = InvalidEventDefinitionException;
16
+ _a = InvalidEventDefinitionException;
17
+ (() => {
18
+ index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.InvalidEventDefinition);
19
+ })();
@@ -0,0 +1,4 @@
1
+ import { DomainException } from './domain.exception';
2
+ export declare class RequiredValueException extends DomainException {
3
+ constructor(typeName: string, receivedValue: unknown);
4
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RequiredValueException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const domain_exception_code_1 = require("./domain-exception-code");
7
+ const domain_exception_1 = require("./domain.exception");
8
+ class RequiredValueException extends domain_exception_1.DomainException {
9
+ constructor(typeName, receivedValue) {
10
+ const received = index_1.ReceivedValue.describe(receivedValue);
11
+ super(`Validation Error: ${typeName} is required, but received ${received}.`, [
12
+ domain_exception_code_1.DomainExceptionCode.RequiredValue,
13
+ ]);
14
+ }
15
+ }
16
+ exports.RequiredValueException = RequiredValueException;
17
+ _a = RequiredValueException;
18
+ (() => {
19
+ index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.RequiredValue);
20
+ })();
@@ -0,0 +1,4 @@
1
+ import { DomainException } from './domain.exception';
2
+ export declare class TypePrimitiveException extends DomainException {
3
+ constructor(expectedType: string, receivedValue: unknown, template?: string);
4
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.TypePrimitiveException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const domain_exception_code_1 = require("./domain-exception-code");
7
+ const domain_exception_1 = require("./domain.exception");
8
+ class TypePrimitiveException extends domain_exception_1.DomainException {
9
+ constructor(expectedType, receivedValue, template = 'Expected a valid ') {
10
+ const received = index_1.ReceivedValue.describe(receivedValue);
11
+ super(`Validation Error: ${template}${expectedType}, but received ${received}.`, [
12
+ domain_exception_code_1.DomainExceptionCode.TypeFailed,
13
+ ]);
14
+ }
15
+ }
16
+ exports.TypePrimitiveException = TypePrimitiveException;
17
+ _a = TypePrimitiveException;
18
+ (() => {
19
+ index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.TypeFailed);
20
+ })();
@@ -0,0 +1,14 @@
1
+ import { DomainException } from './domain.exception';
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,23 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ValidationException = void 0;
5
+ const index_1 = require("../../shared/index");
6
+ const domain_exception_code_1 = require("./domain-exception-code");
7
+ const domain_exception_1 = require("./domain.exception");
8
+ class ValidationException extends domain_exception_1.DomainException {
9
+ constructor(errors) {
10
+ super(`Validation failed, ${errors.map(_a.describe).join(', ')}`, [
11
+ domain_exception_code_1.DomainExceptionCode.ValidationFailed,
12
+ ]);
13
+ this.errors = Object.freeze(errors.map(({ field, code = domain_exception_code_1.DomainExceptionCode.ValidationFailed, message }) => Object.freeze({ field, code, message })));
14
+ }
15
+ static describe(issue) {
16
+ return issue.field === null ? issue.message : `${issue.field}: ${issue.message}`;
17
+ }
18
+ }
19
+ exports.ValidationException = ValidationException;
20
+ _a = ValidationException;
21
+ (() => {
22
+ index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.ValidationFailed);
23
+ })();
@@ -0,0 +1,17 @@
1
+ export * from './event/event-base';
2
+ export * from './entity/entity';
3
+ export * from './aggregate/aggregate-root';
4
+ export * from './type/index';
5
+ export * from './primitive/primitive-types';
6
+ export type { AggregateFinder } from './repository/aggregate-finder';
7
+ export type { AggregateSaver } from './repository/aggregate-saver';
8
+ export type { AggregateRemover } from './repository/aggregate-remover';
9
+ export { Specification } from './specification/specification';
10
+ export type { SatisfiedBy } from './specification/specification';
11
+ export { DomainException } from './exceptions/domain.exception';
12
+ export { ValidationException } from './exceptions/validation.exception';
13
+ export type { ValidationIssue, ValidationIssueInput } from './exceptions/validation.exception';
14
+ export { TypePrimitiveException } from './exceptions/type-primitive.exception';
15
+ export { RequiredValueException } from './exceptions/required-value.exception';
16
+ export { InvalidEventDefinitionException } from './exceptions/invalid-event-definition.exception';
17
+ export { DomainExceptionCode } from './exceptions/domain-exception-code';
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.DomainExceptionCode = exports.InvalidEventDefinitionException = exports.RequiredValueException = exports.TypePrimitiveException = exports.ValidationException = exports.DomainException = exports.Specification = void 0;
18
+ __exportStar(require("./event/event-base"), exports);
19
+ __exportStar(require("./entity/entity"), exports);
20
+ __exportStar(require("./aggregate/aggregate-root"), exports);
21
+ __exportStar(require("./type/index"), exports);
22
+ __exportStar(require("./primitive/primitive-types"), exports);
23
+ var specification_1 = require("./specification/specification");
24
+ Object.defineProperty(exports, "Specification", { enumerable: true, get: function () { return specification_1.Specification; } });
25
+ var domain_exception_1 = require("./exceptions/domain.exception");
26
+ Object.defineProperty(exports, "DomainException", { enumerable: true, get: function () { return domain_exception_1.DomainException; } });
27
+ var validation_exception_1 = require("./exceptions/validation.exception");
28
+ Object.defineProperty(exports, "ValidationException", { enumerable: true, get: function () { return validation_exception_1.ValidationException; } });
29
+ var type_primitive_exception_1 = require("./exceptions/type-primitive.exception");
30
+ Object.defineProperty(exports, "TypePrimitiveException", { enumerable: true, get: function () { return type_primitive_exception_1.TypePrimitiveException; } });
31
+ var required_value_exception_1 = require("./exceptions/required-value.exception");
32
+ Object.defineProperty(exports, "RequiredValueException", { enumerable: true, get: function () { return required_value_exception_1.RequiredValueException; } });
33
+ var invalid_event_definition_exception_1 = require("./exceptions/invalid-event-definition.exception");
34
+ Object.defineProperty(exports, "InvalidEventDefinitionException", { enumerable: true, get: function () { return invalid_event_definition_exception_1.InvalidEventDefinitionException; } });
35
+ var domain_exception_code_1 = require("./exceptions/domain-exception-code");
36
+ Object.defineProperty(exports, "DomainExceptionCode", { enumerable: true, get: function () { return domain_exception_code_1.DomainExceptionCode; } });
@@ -0,0 +1,20 @@
1
+ import type { AbstractType } from '../type/abstract-type';
2
+ export type Methods<T> = {
3
+ [P in keyof T]-?: T[P] extends Function ? P : never;
4
+ }[keyof T];
5
+ export type MethodsAndProperties<T> = {
6
+ [key in keyof T]: T[key];
7
+ };
8
+ export type Properties<T> = Omit<MethodsAndProperties<T>, Methods<T>>;
9
+ export type MutablePropertiesData<T> = Mutable<Required<Properties<T>>>;
10
+ export type PropertiesData<T> = Required<Properties<T>>;
11
+ type RemoveUnderscore<S extends string> = S extends `_${infer R}` ? R : S;
12
+ type Mutable<T> = {
13
+ -readonly [P in keyof T]: T[P];
14
+ };
15
+ export type PrimitiveTypes<T> = {
16
+ [key in keyof Mutable<Properties<T>> as RemoveUnderscore<string & key>]: PrimitiveType<T[key]>;
17
+ };
18
+ export type DataTypes<T> = Partial<PrimitiveTypes<T>>;
19
+ export type PrimitiveType<T> = T extends (infer U)[] ? PrimitiveType<U>[] : T extends AbstractType<any> ? T['value'] : T extends null ? null : T extends Date ? never : T extends object ? PrimitiveTypes<T> : never;
20
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import type { AggregateRoot } from '../aggregate/aggregate-root';
2
+ export interface AggregateFinder<Aggregate extends AggregateRoot<any, any>> {
3
+ findById(id: Aggregate['id']): Promise<Aggregate | null>;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import type { AggregateRoot } from '../aggregate/aggregate-root';
2
+ export interface AggregateRemover<Aggregate extends AggregateRoot<any, any>> {
3
+ remove(aggregate: Aggregate): Promise<void>;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import type { AggregateRoot } from '../aggregate/aggregate-root';
2
+ export interface AggregateSaver<Aggregate extends AggregateRoot<any, any>> {
3
+ save(aggregate: Aggregate): Promise<void>;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ export interface SatisfiedBy<Candidate> {
2
+ isSatisfiedBy(candidate: Candidate): boolean;
3
+ }
4
+ export declare abstract class Specification<Candidate> implements SatisfiedBy<Candidate> {
5
+ abstract isSatisfiedBy(candidate: Candidate): boolean;
6
+ and(other: SatisfiedBy<Candidate>): Specification<Candidate>;
7
+ or(other: SatisfiedBy<Candidate>): Specification<Candidate>;
8
+ not(): Specification<Candidate>;
9
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Specification = void 0;
4
+ class Specification {
5
+ and(other) {
6
+ return new BothSpecification(this, other);
7
+ }
8
+ or(other) {
9
+ return new EitherSpecification(this, other);
10
+ }
11
+ not() {
12
+ return new NegatedSpecification(this);
13
+ }
14
+ }
15
+ exports.Specification = Specification;
16
+ class BothSpecification extends Specification {
17
+ constructor(left, right) {
18
+ super();
19
+ this.left = left;
20
+ this.right = right;
21
+ }
22
+ isSatisfiedBy(candidate) {
23
+ return this.left.isSatisfiedBy(candidate) && this.right.isSatisfiedBy(candidate);
24
+ }
25
+ }
26
+ class EitherSpecification extends Specification {
27
+ constructor(left, right) {
28
+ super();
29
+ this.left = left;
30
+ this.right = right;
31
+ }
32
+ isSatisfiedBy(candidate) {
33
+ return this.left.isSatisfiedBy(candidate) || this.right.isSatisfiedBy(candidate);
34
+ }
35
+ }
36
+ class NegatedSpecification extends Specification {
37
+ constructor(negated) {
38
+ super();
39
+ this.negated = negated;
40
+ }
41
+ isSatisfiedBy(candidate) {
42
+ return !this.negated.isSatisfiedBy(candidate);
43
+ }
44
+ }
@@ -0,0 +1,18 @@
1
+ import type { Validatable, ValidationResult } from '@archi-code/validation';
2
+ import type { RequiredMarked } from './required/required-mark';
3
+ import type { ValidationIssue } from '../exceptions/validation.exception';
4
+ export type ValueOf<T, I> = I extends RequiredMarked ? T : T | null;
5
+ export declare abstract class AbstractType<T, Input = T> implements Validatable<T | null> {
6
+ protected readonly _value: T | null;
7
+ static [Symbol.hasInstance](candidate: unknown): boolean;
8
+ constructor(value?: Input | null);
9
+ get value(): ValueOf<T, this>;
10
+ get isNull(): boolean;
11
+ toString(): string;
12
+ equals<E extends AbstractType<any>>(other: E): boolean;
13
+ protected hasSameValue(other: this): boolean;
14
+ validate(): ValidationResult<ValueOf<T, this>>;
15
+ protected brokenRules(value: unknown): ValidationIssue[];
16
+ protected abstract filter(value: unknown): T | null;
17
+ private runRules;
18
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.AbstractType = void 0;
5
+ const validation_1 = require("@archi-code/validation");
6
+ const required_mark_1 = require("./required/required-mark");
7
+ const required_value_exception_1 = require("../exceptions/required-value.exception");
8
+ const validation_exception_1 = require("../exceptions/validation.exception");
9
+ const VALUE_OBJECT = Symbol.for('@archi-code/ddd/value-object.v1');
10
+ class AbstractType {
11
+ static [Symbol.hasInstance](candidate) {
12
+ return (Function.prototype[Symbol.hasInstance].call(this, candidate) ||
13
+ (this === _a &&
14
+ typeof candidate === 'object' &&
15
+ candidate !== null &&
16
+ candidate[VALUE_OBJECT] === true));
17
+ }
18
+ constructor(value = null) {
19
+ this._value = value === null || value === undefined ? null : this.filter(value);
20
+ if (this._value === null && required_mark_1.RequiredMark.isMarked(this)) {
21
+ throw new required_value_exception_1.RequiredValueException(this.constructor.name, value);
22
+ }
23
+ const brokenRules = this.brokenRules(this._value);
24
+ if (brokenRules.length > 0) {
25
+ throw new validation_exception_1.ValidationException(brokenRules);
26
+ }
27
+ }
28
+ get value() {
29
+ return this._value;
30
+ }
31
+ get isNull() {
32
+ return this._value === null;
33
+ }
34
+ toString() {
35
+ return this.isNull ? '' : (0, validation_1.anyToString)(this._value);
36
+ }
37
+ equals(other) {
38
+ return other?.constructor === this.constructor && this.hasSameValue(other);
39
+ }
40
+ hasSameValue(other) {
41
+ return this._value === other._value;
42
+ }
43
+ validate() {
44
+ return this.runRules(this._value);
45
+ }
46
+ brokenRules(value) {
47
+ return this.runRules(value).errors.map((error) => ({
48
+ field: null,
49
+ code: 'validator' in error ? error.validator : error.custom,
50
+ message: `${this.constructor.name}: ${error.message}`,
51
+ }));
52
+ }
53
+ runRules(value) {
54
+ return (0, validation_1.runValidations)(this.constructor, value);
55
+ }
56
+ }
57
+ exports.AbstractType = AbstractType;
58
+ _a = AbstractType;
59
+ (() => {
60
+ Object.defineProperty(_a.prototype, VALUE_OBJECT, { value: true });
61
+ })();