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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/README.md +478 -376
  2. package/SKILL.md +10 -8
  3. package/ddd-skills/archi-code-ddd/imports.md +28 -18
  4. package/ddd-skills/archi-code-ddd/layers.md +68 -53
  5. package/ddd-skills/archi-code-ddd/patterns.md +50 -43
  6. package/ddd-skills/archi-code-ddd/what-not-to-do.md +25 -18
  7. package/ddd-skills/archi-code-ddd/where-each-class-goes.md +11 -10
  8. package/ddd-skills/ddd-agregados/GUIA.md +2 -2
  9. package/ddd-skills/ddd-agregados/references/consistencia-eventual.md +5 -6
  10. package/ddd-skills/ddd-agregados/references/fabricas.md +5 -8
  11. package/ddd-skills/ddd-agregados/references/implementacion-ts.md +22 -27
  12. package/ddd-skills/ddd-arquitectura/GUIA.md +4 -4
  13. package/ddd-skills/ddd-arquitectura/assets/dependency-cruiser.cjs +13 -6
  14. package/ddd-skills/ddd-arquitectura/references/estilos-adicionales.md +2 -2
  15. package/ddd-skills/ddd-arquitectura/references/estructura-hexagonal-ts.md +70 -16
  16. package/ddd-skills/ddd-auditoria-refactorizacion/GUIA.md +1 -1
  17. package/ddd-skills/ddd-auditoria-refactorizacion/references/ejemplo-auditoria.md +9 -11
  18. package/ddd-skills/ddd-auditoria-refactorizacion/references/lista-comprobacion.md +4 -4
  19. package/ddd-skills/ddd-auditoria-refactorizacion/references/plan-migracion.md +2 -2
  20. package/ddd-skills/ddd-context-mapping/GUIA.md +5 -5
  21. package/ddd-skills/ddd-context-mapping/references/anticorrupcion-ts.md +33 -18
  22. package/ddd-skills/ddd-context-mapping/references/estilos-integracion.md +4 -7
  23. package/ddd-skills/ddd-event-sourcing-cqrs/GUIA.md +2 -2
  24. package/ddd-skills/ddd-event-sourcing-cqrs/references/event-sourcing-ts.md +32 -27
  25. package/ddd-skills/ddd-event-sourcing-cqrs/references/proyecciones-cqrs-ts.md +7 -7
  26. package/ddd-skills/ddd-eventos-dominio/GUIA.md +3 -3
  27. package/ddd-skills/ddd-eventos-dominio/references/diseno-eventos.md +15 -16
  28. package/ddd-skills/ddd-eventos-dominio/references/ejemplo-ecommerce.md +11 -11
  29. package/ddd-skills/ddd-eventos-dominio/references/publicacion-ts.md +34 -31
  30. package/ddd-skills/ddd-repositorios-persistencia/GUIA.md +7 -7
  31. package/ddd-skills/ddd-repositorios-persistencia/references/implementacion-ts.md +50 -32
  32. package/ddd-skills/ddd-repositorios-persistencia/references/tests-repositorios.md +31 -17
  33. package/ddd-skills/ddd-repositorios-persistencia/references/transacciones-ts.md +21 -14
  34. package/ddd-skills/ddd-servicios-capa-aplicacion/GUIA.md +2 -2
  35. package/ddd-skills/ddd-servicios-capa-aplicacion/references/capa-aplicacion-ts.md +19 -19
  36. package/ddd-skills/ddd-servicios-capa-aplicacion/references/ejemplo-ecommerce.md +12 -15
  37. package/ddd-skills/ddd-servicios-capa-aplicacion/references/servicios-dominio-ts.md +5 -6
  38. package/ddd-skills/ddd-value-objects-entidades/GUIA.md +3 -3
  39. package/ddd-skills/ddd-value-objects-entidades/references/entidades-ts.md +7 -9
  40. package/ddd-skills/ddd-value-objects-entidades/references/persistencia-valores.md +5 -5
  41. package/ddd-skills/ddd-value-objects-entidades/references/validacion.md +9 -9
  42. package/ddd-skills/ddd-value-objects-entidades/references/value-objects-ts.md +2 -3
  43. package/dist/cjs/application/event/listens-to.js +4 -4
  44. package/dist/cjs/{exceptions/application → application/exceptions}/aggregate-not-found.exception.d.ts +1 -1
  45. package/dist/cjs/{exceptions/application → application/exceptions}/aggregate-not-found.exception.js +4 -4
  46. package/dist/cjs/application/exceptions/application-exception-code.d.ts +7 -0
  47. package/dist/cjs/application/exceptions/application-exception-code.js +11 -0
  48. package/dist/cjs/application/exceptions/application.exception.d.ts +6 -0
  49. package/dist/cjs/application/exceptions/application.exception.js +16 -0
  50. package/dist/cjs/{exceptions/application → application/exceptions}/concurrency.exception.d.ts +1 -1
  51. package/dist/cjs/{exceptions/application → application/exceptions}/concurrency.exception.js +4 -4
  52. package/dist/cjs/{exceptions/application → application/exceptions}/not-allowed.exception.d.ts +1 -1
  53. package/dist/cjs/{exceptions/application → application/exceptions}/not-allowed.exception.js +4 -4
  54. package/dist/cjs/application/exceptions/unexpected-error.exception.d.ts +5 -0
  55. package/dist/cjs/application/exceptions/unexpected-error.exception.js +17 -0
  56. package/dist/cjs/application/index.d.ts +7 -0
  57. package/dist/cjs/application/index.js +15 -1
  58. package/dist/cjs/application/use-case/use-case.js +3 -2
  59. package/dist/{esm/domain/type/value-objects/value-objects.d.ts → cjs/application/value-object-builder/value-object-builder.d.ts} +3 -3
  60. package/dist/cjs/application/value-object-builder/value-object-builder.js +51 -0
  61. package/dist/cjs/domain/aggregate/aggregate-root.d.ts +0 -5
  62. package/dist/cjs/domain/aggregate/aggregate-root.js +4 -20
  63. package/dist/cjs/domain/entity/entity.js +2 -2
  64. package/dist/cjs/domain/event/event-base.d.ts +3 -9
  65. package/dist/cjs/domain/event/event-base.js +8 -38
  66. package/dist/cjs/domain/exceptions/domain-exception-code.d.ts +7 -0
  67. package/dist/cjs/domain/exceptions/domain-exception-code.js +11 -0
  68. package/dist/cjs/domain/exceptions/domain.exception.d.ts +6 -0
  69. package/dist/cjs/domain/exceptions/domain.exception.js +16 -0
  70. package/dist/cjs/domain/exceptions/invalid-event-definition.exception.d.ts +4 -0
  71. package/dist/cjs/domain/exceptions/invalid-event-definition.exception.js +19 -0
  72. package/dist/cjs/{exceptions/domain → domain/exceptions}/required-value.exception.js +5 -6
  73. package/dist/cjs/{exceptions/domain → domain/exceptions}/type-primitive.exception.js +5 -6
  74. package/dist/cjs/{exceptions/domain → domain/exceptions}/validation.exception.js +5 -5
  75. package/dist/cjs/domain/index.d.ts +8 -1
  76. package/dist/cjs/domain/index.js +14 -2
  77. package/dist/cjs/domain/primitive/primitive-types.d.ts +1 -3
  78. package/dist/cjs/domain/type/abstract-type.d.ts +6 -8
  79. package/dist/cjs/domain/type/abstract-type.js +15 -23
  80. package/dist/cjs/domain/type/array-type.d.ts +2 -1
  81. package/dist/cjs/domain/type/array-type.js +17 -18
  82. package/dist/cjs/domain/type/boolean-type.js +2 -2
  83. package/dist/cjs/domain/type/composite/composite-brand.d.ts +4 -0
  84. package/dist/cjs/domain/type/composite/composite-brand.js +15 -0
  85. package/dist/cjs/domain/type/composite/composite-field.d.ts +7 -8
  86. package/dist/cjs/domain/type/composite/composite-field.js +70 -47
  87. package/dist/cjs/domain/type/composite/composite-issues.d.ts +6 -0
  88. package/dist/cjs/domain/type/composite/composite-issues.js +35 -0
  89. package/dist/cjs/domain/type/composite/composite.js +15 -19
  90. package/dist/cjs/domain/type/date-type.d.ts +3 -2
  91. package/dist/cjs/domain/type/date-type.js +42 -7
  92. package/dist/cjs/domain/type/enum-type.js +2 -2
  93. package/dist/cjs/domain/type/id-type.d.ts +1 -1
  94. package/dist/cjs/domain/type/id-type.js +4 -4
  95. package/dist/cjs/domain/type/index.d.ts +2 -4
  96. package/dist/cjs/domain/type/index.js +3 -7
  97. package/dist/cjs/domain/type/json-type.d.ts +4 -0
  98. package/dist/cjs/domain/type/json-type.js +33 -4
  99. package/dist/cjs/domain/type/number-type.js +2 -2
  100. package/dist/cjs/domain/type/required/required-mark.d.ts +0 -1
  101. package/dist/cjs/domain/type/string-type.js +2 -2
  102. package/dist/cjs/domain/type/uuid-type.js +2 -2
  103. package/dist/cjs/infrastructure/event/domain-event-bus.js +9 -9
  104. package/dist/cjs/infrastructure/event/event-registry.js +9 -9
  105. package/dist/cjs/infrastructure/event/in-memory/emitter.js +2 -2
  106. package/dist/cjs/infrastructure/event/in-memory/in-memory-event-channel.d.ts +1 -1
  107. package/dist/cjs/infrastructure/event/in-memory/in-memory-event-channel.js +6 -7
  108. package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/event-delivery.exception.js +4 -4
  109. package/dist/cjs/infrastructure/exceptions/infrastructure-exception-code.d.ts +6 -0
  110. package/dist/cjs/infrastructure/exceptions/infrastructure-exception-code.js +10 -0
  111. package/dist/cjs/infrastructure/exceptions/infrastructure.exception.d.ts +6 -0
  112. package/dist/cjs/infrastructure/exceptions/infrastructure.exception.js +16 -0
  113. package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/internal-error.exception.d.ts +1 -1
  114. package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/internal-error.exception.js +4 -4
  115. package/dist/cjs/infrastructure/exceptions/kind/exception-classifier.d.ts +4 -0
  116. package/dist/cjs/infrastructure/exceptions/kind/exception-classifier.js +34 -0
  117. package/dist/cjs/infrastructure/exceptions/kind/exception-kind.d.ts +9 -0
  118. package/dist/cjs/infrastructure/exceptions/kind/exception-kind.js +13 -0
  119. package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/unknown-event.exception.js +4 -4
  120. package/dist/cjs/infrastructure/index.d.ts +7 -2
  121. package/dist/cjs/infrastructure/index.js +15 -3
  122. package/dist/cjs/infrastructure/logging/console-logger.js +2 -2
  123. package/dist/{esm → cjs/shared}/exceptions/abstract.exception.d.ts +6 -4
  124. package/dist/cjs/{exceptions → shared/exceptions}/abstract.exception.js +9 -16
  125. package/dist/cjs/shared/index.d.ts +8 -0
  126. package/dist/cjs/shared/index.js +13 -0
  127. package/dist/cjs/shared/issue-collection-error.d.ts +9 -0
  128. package/dist/cjs/shared/issue-collection-error.js +11 -0
  129. package/dist/cjs/shared/issue-collector.d.ts +8 -0
  130. package/dist/cjs/shared/issue-collector.js +41 -0
  131. package/dist/esm/application/event/listens-to.js +1 -1
  132. package/dist/esm/{exceptions/application → application/exceptions}/aggregate-not-found.exception.d.ts +1 -1
  133. package/dist/esm/application/exceptions/aggregate-not-found.exception.js +13 -0
  134. package/dist/esm/application/exceptions/application-exception-code.d.ts +7 -0
  135. package/dist/esm/application/exceptions/application-exception-code.js +8 -0
  136. package/dist/esm/application/exceptions/application.exception.d.ts +6 -0
  137. package/dist/esm/application/exceptions/application.exception.js +12 -0
  138. package/dist/esm/{exceptions/application → application/exceptions}/concurrency.exception.d.ts +1 -1
  139. package/dist/esm/{exceptions/application → application/exceptions}/concurrency.exception.js +4 -4
  140. package/dist/esm/{exceptions/application → application/exceptions}/not-allowed.exception.d.ts +1 -1
  141. package/dist/esm/application/exceptions/not-allowed.exception.js +13 -0
  142. package/dist/esm/application/exceptions/unexpected-error.exception.d.ts +5 -0
  143. package/dist/esm/application/exceptions/unexpected-error.exception.js +13 -0
  144. package/dist/esm/application/index.d.ts +7 -0
  145. package/dist/esm/application/index.js +7 -0
  146. package/dist/esm/application/use-case/use-case.js +3 -2
  147. package/dist/{cjs/domain/type/value-objects/value-objects.d.ts → esm/application/value-object-builder/value-object-builder.d.ts} +3 -3
  148. package/dist/esm/application/value-object-builder/value-object-builder.js +47 -0
  149. package/dist/esm/domain/aggregate/aggregate-root.d.ts +0 -5
  150. package/dist/esm/domain/aggregate/aggregate-root.js +4 -20
  151. package/dist/esm/domain/entity/entity.js +1 -1
  152. package/dist/esm/domain/event/event-base.d.ts +3 -9
  153. package/dist/esm/domain/event/event-base.js +8 -38
  154. package/dist/esm/domain/exceptions/domain-exception-code.d.ts +7 -0
  155. package/dist/esm/domain/exceptions/domain-exception-code.js +8 -0
  156. package/dist/esm/domain/exceptions/domain.exception.d.ts +6 -0
  157. package/dist/esm/domain/exceptions/domain.exception.js +12 -0
  158. package/dist/esm/domain/exceptions/invalid-event-definition.exception.d.ts +4 -0
  159. package/dist/esm/domain/exceptions/invalid-event-definition.exception.js +15 -0
  160. package/dist/esm/{exceptions/domain → domain/exceptions}/required-value.exception.js +4 -5
  161. package/dist/esm/{exceptions/domain → domain/exceptions}/type-primitive.exception.js +4 -5
  162. package/dist/esm/{exceptions/domain → domain/exceptions}/validation.exception.js +5 -5
  163. package/dist/esm/domain/index.d.ts +7 -0
  164. package/dist/esm/domain/index.js +6 -0
  165. package/dist/esm/domain/primitive/primitive-types.d.ts +1 -3
  166. package/dist/esm/domain/type/abstract-type.d.ts +6 -8
  167. package/dist/esm/domain/type/abstract-type.js +14 -22
  168. package/dist/esm/domain/type/array-type.d.ts +2 -1
  169. package/dist/esm/domain/type/array-type.js +16 -17
  170. package/dist/esm/domain/type/boolean-type.js +1 -1
  171. package/dist/esm/domain/type/composite/composite-brand.d.ts +4 -0
  172. package/dist/esm/domain/type/composite/composite-brand.js +11 -0
  173. package/dist/esm/domain/type/composite/composite-field.d.ts +7 -8
  174. package/dist/esm/domain/type/composite/composite-field.js +69 -46
  175. package/dist/esm/domain/type/composite/composite-issues.d.ts +6 -0
  176. package/dist/esm/domain/type/composite/composite-issues.js +31 -0
  177. package/dist/esm/domain/type/composite/composite.js +13 -17
  178. package/dist/esm/domain/type/date-type.d.ts +3 -2
  179. package/dist/esm/domain/type/date-type.js +39 -4
  180. package/dist/esm/domain/type/enum-type.js +1 -1
  181. package/dist/esm/domain/type/id-type.d.ts +1 -1
  182. package/dist/esm/domain/type/id-type.js +2 -2
  183. package/dist/esm/domain/type/index.d.ts +2 -4
  184. package/dist/esm/domain/type/index.js +1 -3
  185. package/dist/esm/domain/type/json-type.d.ts +4 -0
  186. package/dist/esm/domain/type/json-type.js +32 -3
  187. package/dist/esm/domain/type/number-type.js +1 -1
  188. package/dist/esm/domain/type/required/required-mark.d.ts +0 -1
  189. package/dist/esm/domain/type/string-type.js +1 -1
  190. package/dist/esm/domain/type/uuid-type.js +1 -1
  191. package/dist/esm/infrastructure/event/domain-event-bus.js +5 -5
  192. package/dist/esm/infrastructure/event/event-registry.js +4 -4
  193. package/dist/esm/infrastructure/event/in-memory/emitter.js +1 -1
  194. package/dist/esm/infrastructure/event/in-memory/in-memory-event-channel.d.ts +1 -1
  195. package/dist/esm/infrastructure/event/in-memory/in-memory-event-channel.js +5 -6
  196. package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/event-delivery.exception.js +4 -4
  197. package/dist/esm/infrastructure/exceptions/infrastructure-exception-code.d.ts +6 -0
  198. package/dist/esm/infrastructure/exceptions/infrastructure-exception-code.js +7 -0
  199. package/dist/esm/infrastructure/exceptions/infrastructure.exception.d.ts +6 -0
  200. package/dist/esm/infrastructure/exceptions/infrastructure.exception.js +12 -0
  201. package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/internal-error.exception.d.ts +1 -1
  202. package/dist/esm/infrastructure/exceptions/internal-error.exception.js +13 -0
  203. package/dist/esm/infrastructure/exceptions/kind/exception-classifier.d.ts +4 -0
  204. package/dist/esm/infrastructure/exceptions/kind/exception-classifier.js +30 -0
  205. package/dist/esm/infrastructure/exceptions/kind/exception-kind.d.ts +9 -0
  206. package/dist/esm/infrastructure/exceptions/kind/exception-kind.js +10 -0
  207. package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/unknown-event.exception.js +4 -4
  208. package/dist/esm/infrastructure/index.d.ts +7 -2
  209. package/dist/esm/infrastructure/index.js +7 -1
  210. package/dist/esm/infrastructure/logging/console-logger.js +1 -1
  211. package/dist/{cjs → esm/shared}/exceptions/abstract.exception.d.ts +6 -4
  212. package/dist/esm/{exceptions → shared/exceptions}/abstract.exception.js +9 -16
  213. package/dist/esm/shared/index.d.ts +8 -0
  214. package/dist/esm/shared/index.js +5 -0
  215. package/dist/esm/shared/issue-collection-error.d.ts +9 -0
  216. package/dist/esm/shared/issue-collection-error.js +7 -0
  217. package/dist/esm/shared/issue-collector.d.ts +8 -0
  218. package/dist/esm/shared/issue-collector.js +37 -0
  219. package/package.json +7 -18
  220. package/dist/cjs/domain/type/equality/value-equality.d.ts +0 -7
  221. package/dist/cjs/domain/type/equality/value-equality.js +0 -41
  222. package/dist/cjs/domain/type/immutable/immutable-date.d.ts +0 -4
  223. package/dist/cjs/domain/type/immutable/immutable-date.js +0 -37
  224. package/dist/cjs/domain/type/immutable/immutable.d.ts +0 -4
  225. package/dist/cjs/domain/type/immutable/immutable.js +0 -19
  226. package/dist/cjs/domain/type/value-objects/value-objects.js +0 -70
  227. package/dist/cjs/exceptions/application/application.exception.d.ts +0 -6
  228. package/dist/cjs/exceptions/application/application.exception.js +0 -17
  229. package/dist/cjs/exceptions/domain/domain.exception.d.ts +0 -6
  230. package/dist/cjs/exceptions/domain/domain.exception.js +0 -17
  231. package/dist/cjs/exceptions/exception-code.d.ts +0 -15
  232. package/dist/cjs/exceptions/exception-code.js +0 -19
  233. package/dist/cjs/exceptions/index.d.ts +0 -14
  234. package/dist/cjs/exceptions/index.js +0 -30
  235. package/dist/cjs/exceptions/infrastructure/infrastructure.exception.d.ts +0 -6
  236. package/dist/cjs/exceptions/infrastructure/infrastructure.exception.js +0 -17
  237. package/dist/cjs/infrastructure/http/http-error-mapper.d.ts +0 -23
  238. package/dist/cjs/infrastructure/http/http-error-mapper.js +0 -63
  239. package/dist/esm/domain/type/equality/value-equality.d.ts +0 -7
  240. package/dist/esm/domain/type/equality/value-equality.js +0 -37
  241. package/dist/esm/domain/type/immutable/immutable-date.d.ts +0 -4
  242. package/dist/esm/domain/type/immutable/immutable-date.js +0 -33
  243. package/dist/esm/domain/type/immutable/immutable.d.ts +0 -4
  244. package/dist/esm/domain/type/immutable/immutable.js +0 -15
  245. package/dist/esm/domain/type/value-objects/value-objects.js +0 -66
  246. package/dist/esm/exceptions/application/aggregate-not-found.exception.js +0 -13
  247. package/dist/esm/exceptions/application/application.exception.d.ts +0 -6
  248. package/dist/esm/exceptions/application/application.exception.js +0 -13
  249. package/dist/esm/exceptions/application/not-allowed.exception.js +0 -13
  250. package/dist/esm/exceptions/domain/domain.exception.d.ts +0 -6
  251. package/dist/esm/exceptions/domain/domain.exception.js +0 -13
  252. package/dist/esm/exceptions/exception-code.d.ts +0 -15
  253. package/dist/esm/exceptions/exception-code.js +0 -16
  254. package/dist/esm/exceptions/index.d.ts +0 -14
  255. package/dist/esm/exceptions/index.js +0 -14
  256. package/dist/esm/exceptions/infrastructure/infrastructure.exception.d.ts +0 -6
  257. package/dist/esm/exceptions/infrastructure/infrastructure.exception.js +0 -13
  258. package/dist/esm/exceptions/infrastructure/internal-error.exception.js +0 -13
  259. package/dist/esm/infrastructure/http/http-error-mapper.d.ts +0 -23
  260. package/dist/esm/infrastructure/http/http-error-mapper.js +0 -59
  261. /package/dist/cjs/{exceptions/domain → domain/exceptions}/required-value.exception.d.ts +0 -0
  262. /package/dist/cjs/{exceptions/domain → domain/exceptions}/type-primitive.exception.d.ts +0 -0
  263. /package/dist/cjs/{exceptions/domain → domain/exceptions}/validation.exception.d.ts +0 -0
  264. /package/dist/cjs/domain/type/required/{required.d.ts → required-type.d.ts} +0 -0
  265. /package/dist/cjs/domain/type/required/{required.js → required-type.js} +0 -0
  266. /package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/event-delivery.exception.d.ts +0 -0
  267. /package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/unknown-event.exception.d.ts +0 -0
  268. /package/dist/cjs/{exceptions → shared/exceptions}/brand/exception-brand.d.ts +0 -0
  269. /package/dist/cjs/{exceptions → shared/exceptions}/brand/exception-brand.js +0 -0
  270. /package/dist/cjs/{exceptions → shared/exceptions}/received/received-value.d.ts +0 -0
  271. /package/dist/cjs/{exceptions → shared/exceptions}/received/received-value.js +0 -0
  272. /package/dist/esm/{exceptions/domain → domain/exceptions}/required-value.exception.d.ts +0 -0
  273. /package/dist/esm/{exceptions/domain → domain/exceptions}/type-primitive.exception.d.ts +0 -0
  274. /package/dist/esm/{exceptions/domain → domain/exceptions}/validation.exception.d.ts +0 -0
  275. /package/dist/esm/domain/type/required/{required.d.ts → required-type.d.ts} +0 -0
  276. /package/dist/esm/domain/type/required/{required.js → required-type.js} +0 -0
  277. /package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/event-delivery.exception.d.ts +0 -0
  278. /package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/unknown-event.exception.d.ts +0 -0
  279. /package/dist/esm/{exceptions → shared/exceptions}/brand/exception-brand.d.ts +0 -0
  280. /package/dist/esm/{exceptions → shared/exceptions}/brand/exception-brand.js +0 -0
  281. /package/dist/esm/{exceptions → shared/exceptions}/received/received-value.d.ts +0 -0
  282. /package/dist/esm/{exceptions → shared/exceptions}/received/received-value.js +0 -0
@@ -0,0 +1,4 @@
1
+ import { DomainException } from './domain.exception.js';
2
+ export declare class InvalidEventDefinitionException extends DomainException {
3
+ constructor(eventClassName: string);
4
+ }
@@ -0,0 +1,15 @@
1
+ var _a;
2
+ import { ExceptionBrand } from '../../shared/index.js';
3
+ import { DomainExceptionCode } from './domain-exception-code.js';
4
+ import { DomainException } from './domain.exception.js';
5
+ export class InvalidEventDefinitionException extends DomainException {
6
+ constructor(eventClassName) {
7
+ super(`${eventClassName} must declare a static eventName`, [
8
+ DomainExceptionCode.InvalidEventDefinition,
9
+ ]);
10
+ }
11
+ }
12
+ _a = InvalidEventDefinitionException;
13
+ (() => {
14
+ ExceptionBrand.brandClass(_a, DomainExceptionCode.InvalidEventDefinition);
15
+ })();
@@ -1,17 +1,16 @@
1
1
  var _a;
2
+ import { ExceptionBrand, ReceivedValue } from '../../shared/index.js';
3
+ import { DomainExceptionCode } from './domain-exception-code.js';
2
4
  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
5
  export class RequiredValueException extends DomainException {
7
6
  constructor(typeName, receivedValue) {
8
7
  const received = ReceivedValue.describe(receivedValue);
9
8
  super(`Validation Error: ${typeName} is required, but received ${received}.`, [
10
- ExceptionCode.RequiredValue,
9
+ DomainExceptionCode.RequiredValue,
11
10
  ]);
12
11
  }
13
12
  }
14
13
  _a = RequiredValueException;
15
14
  (() => {
16
- ExceptionBrand.brandClass(_a, ExceptionCode.RequiredValue);
15
+ ExceptionBrand.brandClass(_a, DomainExceptionCode.RequiredValue);
17
16
  })();
@@ -1,17 +1,16 @@
1
1
  var _a;
2
+ import { ExceptionBrand, ReceivedValue } from '../../shared/index.js';
3
+ import { DomainExceptionCode } from './domain-exception-code.js';
2
4
  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
5
  export class TypePrimitiveException extends DomainException {
7
6
  constructor(expectedType, receivedValue, template = 'Expected a valid ') {
8
7
  const received = ReceivedValue.describe(receivedValue);
9
8
  super(`Validation Error: ${template}${expectedType}, but received ${received}.`, [
10
- ExceptionCode.TypeFailed,
9
+ DomainExceptionCode.TypeFailed,
11
10
  ]);
12
11
  }
13
12
  }
14
13
  _a = TypePrimitiveException;
15
14
  (() => {
16
- ExceptionBrand.brandClass(_a, ExceptionCode.TypeFailed);
15
+ ExceptionBrand.brandClass(_a, DomainExceptionCode.TypeFailed);
17
16
  })();
@@ -1,13 +1,13 @@
1
1
  var _a;
2
+ import { ExceptionBrand } from '../../shared/index.js';
3
+ import { DomainExceptionCode } from './domain-exception-code.js';
2
4
  import { DomainException } from './domain.exception.js';
3
- import { ExceptionBrand } from '../brand/exception-brand.js';
4
- import { ExceptionCode } from '../exception-code.js';
5
5
  export class ValidationException extends DomainException {
6
6
  constructor(errors) {
7
7
  super(`Validation failed, ${errors.map(_a.describe).join(', ')}`, [
8
- ExceptionCode.ValidationFailed,
8
+ DomainExceptionCode.ValidationFailed,
9
9
  ]);
10
- this.errors = Object.freeze(errors.map(({ field, code = ExceptionCode.ValidationFailed, message }) => Object.freeze({ field, code, message })));
10
+ this.errors = Object.freeze(errors.map(({ field, code = DomainExceptionCode.ValidationFailed, message }) => Object.freeze({ field, code, message })));
11
11
  }
12
12
  static describe(issue) {
13
13
  return issue.field === null ? issue.message : `${issue.field}: ${issue.message}`;
@@ -15,5 +15,5 @@ export class ValidationException extends DomainException {
15
15
  }
16
16
  _a = ValidationException;
17
17
  (() => {
18
- ExceptionBrand.brandClass(_a, ExceptionCode.ValidationFailed);
18
+ ExceptionBrand.brandClass(_a, DomainExceptionCode.ValidationFailed);
19
19
  })();
@@ -8,3 +8,10 @@ export type { AggregateSaver } from './repository/aggregate-saver.js';
8
8
  export type { AggregateRemover } from './repository/aggregate-remover.js';
9
9
  export { Specification } from './specification/specification.js';
10
10
  export type { SatisfiedBy } from './specification/specification.js';
11
+ export { DomainException } from './exceptions/domain.exception.js';
12
+ export { ValidationException } from './exceptions/validation.exception.js';
13
+ export type { ValidationIssue, ValidationIssueInput } from './exceptions/validation.exception.js';
14
+ export { TypePrimitiveException } from './exceptions/type-primitive.exception.js';
15
+ export { RequiredValueException } from './exceptions/required-value.exception.js';
16
+ export { InvalidEventDefinitionException } from './exceptions/invalid-event-definition.exception.js';
17
+ export { DomainExceptionCode } from './exceptions/domain-exception-code.js';
@@ -4,3 +4,9 @@ export * from './aggregate/aggregate-root.js';
4
4
  export * from './type/index.js';
5
5
  export * from './primitive/primitive-types.js';
6
6
  export { Specification } from './specification/specification.js';
7
+ export { DomainException } from './exceptions/domain.exception.js';
8
+ export { ValidationException } from './exceptions/validation.exception.js';
9
+ export { TypePrimitiveException } from './exceptions/type-primitive.exception.js';
10
+ export { RequiredValueException } from './exceptions/required-value.exception.js';
11
+ export { InvalidEventDefinitionException } from './exceptions/invalid-event-definition.exception.js';
12
+ export { DomainExceptionCode } from './exceptions/domain-exception-code.js';
@@ -1,4 +1,3 @@
1
- import type { AggregateRoot } from '../aggregate/aggregate-root.js';
2
1
  import type { AbstractType } from '../type/abstract-type.js';
3
2
  export type Methods<T> = {
4
3
  [P in keyof T]-?: T[P] extends Function ? P : never;
@@ -13,9 +12,8 @@ type RemoveUnderscore<S extends string> = S extends `_${infer R}` ? R : S;
13
12
  type Mutable<T> = {
14
13
  -readonly [P in keyof T]: T[P];
15
14
  };
16
- type AggregateBookkeeping<T> = T extends AggregateRoot<any, any> ? 'version' : never;
17
15
  export type PrimitiveTypes<T> = {
18
- [key in keyof Mutable<Properties<T>> as key extends AggregateBookkeeping<T> ? never : RemoveUnderscore<string & key>]: PrimitiveType<T[key]>;
16
+ [key in keyof Mutable<Properties<T>> as RemoveUnderscore<string & key>]: PrimitiveType<T[key]>;
19
17
  };
20
18
  export type DataTypes<T> = Partial<PrimitiveTypes<T>>;
21
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;
@@ -1,7 +1,7 @@
1
1
  import type { Validatable, ValidationResult } from '@archi-code/validation';
2
- import type { ValueOf } from './required/required-mark.js';
3
- import type { ValidationIssue } from '../../exceptions/index.js';
4
- type JsonValue<T> = T extends Date ? string : T;
2
+ import type { RequiredMarked } from './required/required-mark.js';
3
+ import type { ValidationIssue } from '../exceptions/validation.exception.js';
4
+ export type ValueOf<T, I> = I extends RequiredMarked ? T : T | null;
5
5
  export declare abstract class AbstractType<T, Input = T> implements Validatable<T | null> {
6
6
  protected readonly _value: T | null;
7
7
  static [Symbol.hasInstance](candidate: unknown): boolean;
@@ -9,12 +9,10 @@ export declare abstract class AbstractType<T, Input = T> implements Validatable<
9
9
  get value(): ValueOf<T, this>;
10
10
  get isNull(): boolean;
11
11
  toString(): string;
12
- toJSON(): ValueOf<JsonValue<T>, this>;
13
- equals(other: unknown): boolean;
12
+ equals<E extends AbstractType<any>>(other: E): boolean;
13
+ protected hasSameValue(other: this): boolean;
14
14
  validate(): ValidationResult<ValueOf<T, this>>;
15
15
  protected brokenRules(value: unknown): ValidationIssue[];
16
16
  protected abstract filter(value: unknown): T | null;
17
- private acceptInput;
18
- private static isMissingInput;
17
+ private runRules;
19
18
  }
20
- export {};
@@ -1,8 +1,8 @@
1
1
  var _a;
2
2
  import { anyToString, runValidations } from '@archi-code/validation';
3
- import { ValueEquality } from './equality/value-equality.js';
4
3
  import { RequiredMark } from './required/required-mark.js';
5
- import { RequiredValueException, ValidationException } from '../../exceptions/index.js';
4
+ import { RequiredValueException } from '../exceptions/required-value.exception.js';
5
+ import { ValidationException } from '../exceptions/validation.exception.js';
6
6
  const VALUE_OBJECT = Symbol.for('@archi-code/ddd/value-object.v1');
7
7
  export class AbstractType {
8
8
  static [Symbol.hasInstance](candidate) {
@@ -13,7 +13,10 @@ export class AbstractType {
13
13
  candidate[VALUE_OBJECT] === true));
14
14
  }
15
15
  constructor(value = null) {
16
- this._value = this.acceptInput(value);
16
+ this._value = value === null || value === undefined ? null : this.filter(value);
17
+ if (this._value === null && RequiredMark.isMarked(this)) {
18
+ throw new RequiredValueException(this.constructor.name, value);
19
+ }
17
20
  const brokenRules = this.brokenRules(this._value);
18
21
  if (brokenRules.length > 0) {
19
22
  throw new ValidationException(brokenRules);
@@ -28,35 +31,24 @@ export class AbstractType {
28
31
  toString() {
29
32
  return this.isNull ? '' : anyToString(this._value);
30
33
  }
31
- toJSON() {
32
- const value = this._value;
33
- return (value instanceof Date ? value.toISOString() : value);
34
- }
35
34
  equals(other) {
36
- return (typeof other === 'object' &&
37
- other !== null &&
38
- other.constructor === this.constructor &&
39
- ValueEquality.equals(this._value, other._value));
35
+ return other?.constructor === this.constructor && this.hasSameValue(other);
36
+ }
37
+ hasSameValue(other) {
38
+ return this._value === other._value;
40
39
  }
41
40
  validate() {
42
- return runValidations(this.constructor, this._value);
41
+ return this.runRules(this._value);
43
42
  }
44
43
  brokenRules(value) {
45
- return runValidations(this.constructor, value).errors.map((error) => ({
44
+ return this.runRules(value).errors.map((error) => ({
46
45
  field: null,
47
46
  code: 'validator' in error ? error.validator : error.custom,
48
47
  message: `${this.constructor.name}: ${error.message}`,
49
48
  }));
50
49
  }
51
- acceptInput(value) {
52
- const accepted = _a.isMissingInput(value) ? null : this.filter(value);
53
- if (accepted === null && RequiredMark.isMarked(this)) {
54
- throw new RequiredValueException(this.constructor.name, value);
55
- }
56
- return accepted;
57
- }
58
- static isMissingInput(value) {
59
- return (value === null || value === undefined || (typeof value === 'string' && value.trim() === ''));
50
+ runRules(value) {
51
+ return runValidations(this.constructor, value);
60
52
  }
61
53
  }
62
54
  _a = AbstractType;
@@ -1,6 +1,6 @@
1
1
  import type { ValidationResult } from '@archi-code/validation';
2
2
  import { AbstractType } from './abstract-type.js';
3
- import type { ValueOf } from './required/required-mark.js';
3
+ import type { ValueOf } from './abstract-type.js';
4
4
  type ItemValue<Item extends AbstractType<any>> = Item['value'];
5
5
  export declare abstract class ArrayType<Item extends AbstractType<any>> extends AbstractType<ItemValue<Item>[]> {
6
6
  protected abstract createItem(value: unknown): Item;
@@ -9,6 +9,7 @@ export declare abstract class ArrayType<Item extends AbstractType<any>> extends
9
9
  hasItem(value: ItemValue<Item>): boolean;
10
10
  withItem(value: ItemValue<Item>): this;
11
11
  withoutItem(value: ItemValue<Item>): this;
12
+ protected hasSameValue(other: this): boolean;
12
13
  protected filter(value: unknown): ItemValue<Item>[];
13
14
  validate(): ValidationResult<ValueOf<ItemValue<Item>[], this>>;
14
15
  private copyWith;
@@ -1,9 +1,6 @@
1
1
  import { toArray } from '@archi-code/validation';
2
2
  import { AbstractType } from './abstract-type.js';
3
- import { Immutable } from './immutable/immutable.js';
4
- import { ValueEquality } from './equality/value-equality.js';
5
- import { ValueObjects } from './value-objects/value-objects.js';
6
- import { TypePrimitiveException, ValidationException } from '../../exceptions/index.js';
3
+ import { TypePrimitiveException } from '../exceptions/type-primitive.exception.js';
7
4
  export class ArrayType extends AbstractType {
8
5
  get items() {
9
6
  return (this._value ?? []).map((value) => this.createItem(value));
@@ -12,8 +9,8 @@ export class ArrayType extends AbstractType {
12
9
  return this.items.map((item) => item.toString()).join(', ');
13
10
  }
14
11
  hasItem(value) {
15
- const itemValue = this.createItem(value).value;
16
- return (this._value ?? []).some((current) => ValueEquality.equals(current, itemValue));
12
+ const item = this.createItem(value);
13
+ return (this._value ?? []).some((current) => this.createItem(current).equals(item));
17
14
  }
18
15
  withItem(value) {
19
16
  return this.copyWith([...(this._value ?? []), value]);
@@ -22,23 +19,25 @@ export class ArrayType extends AbstractType {
22
19
  if (this._value === null) {
23
20
  return this;
24
21
  }
25
- const itemValue = this.createItem(value).value;
26
- return this.copyWith(this._value.filter((current) => !ValueEquality.equals(current, itemValue)));
22
+ const item = this.createItem(value);
23
+ return this.copyWith(this._value.filter((current) => !this.createItem(current).equals(item)));
24
+ }
25
+ hasSameValue(other) {
26
+ const otherValue = other._value;
27
+ if (this._value === null || otherValue === null) {
28
+ return this._value === otherValue;
29
+ }
30
+ return (this._value.length === otherValue.length &&
31
+ this._value.every((value, index) => this.createItem(value).equals(this.createItem(otherValue[index]))));
27
32
  }
28
33
  filter(value) {
29
34
  const converted = toArray(value);
30
35
  if (!converted.ok) {
31
36
  throw new TypePrimitiveException('Array', value);
32
37
  }
33
- try {
34
- return Immutable.freeze(ValueObjects.buildList(converted.value, (item) => this.createItem(item).value));
35
- }
36
- catch (error) {
37
- if (error instanceof ValidationException) {
38
- throw new ValidationException([...this.brokenRules(converted.value), ...error.errors]);
39
- }
40
- throw error;
41
- }
38
+ const items = converted.value.map((item) => this.createItem(item).value);
39
+ Object.freeze(items);
40
+ return items;
42
41
  }
43
42
  validate() {
44
43
  const own = super.validate();
@@ -1,6 +1,6 @@
1
1
  import { toBoolean } from '@archi-code/validation';
2
2
  import { AbstractType } from './abstract-type.js';
3
- import { TypePrimitiveException } from '../../exceptions/index.js';
3
+ import { TypePrimitiveException } from '../exceptions/type-primitive.exception.js';
4
4
  export class BooleanType extends AbstractType {
5
5
  filter(value) {
6
6
  const converted = toBoolean(value);
@@ -0,0 +1,4 @@
1
+ export declare class CompositeBrand {
2
+ static mark(prototype: object): void;
3
+ static isComposite(value: unknown): boolean;
4
+ }
@@ -0,0 +1,11 @@
1
+ const COMPOSITE = Symbol.for('@archi-code/ddd/composite.v1');
2
+ export class CompositeBrand {
3
+ static mark(prototype) {
4
+ Object.defineProperty(prototype, COMPOSITE, { value: true });
5
+ }
6
+ static isComposite(value) {
7
+ return (typeof value === 'object' &&
8
+ value !== null &&
9
+ value[COMPOSITE] === true);
10
+ }
11
+ }
@@ -8,12 +8,11 @@ export interface CompositeClass {
8
8
  }
9
9
  export type FieldClass = ValueClass | CompositeClass;
10
10
  export type FieldSpec = FieldClass | readonly [FieldClass];
11
- export declare class CompositeField {
12
- static brand(prototype: object): void;
13
- static isComposite(value: unknown): boolean;
14
- static accept(owner: string, field: string, spec: FieldSpec, value: unknown): unknown;
15
- static fromPrimitive(spec: FieldSpec, primitive: unknown): unknown;
16
- static equals(left: unknown, right: unknown): boolean;
17
- static primitive(value: unknown): unknown;
18
- private static acceptOne;
11
+ export declare abstract class CompositeField {
12
+ static of(spec: FieldSpec): CompositeField;
13
+ abstract readonly typeName: string;
14
+ abstract accept(path: string, value: unknown): unknown;
15
+ abstract fromPrimitive(primitive: unknown): unknown;
16
+ abstract toPrimitive(value: unknown): unknown;
17
+ abstract equals(left: unknown, right: unknown): boolean;
19
18
  }
@@ -1,59 +1,82 @@
1
- import { ValueObjects } from '../value-objects/value-objects.js';
2
- import { RequiredValueException, TypePrimitiveException } from '../../../exceptions/index.js';
3
- const COMPOSITE = Symbol.for('@archi-code/ddd/composite.v1');
1
+ import { CompositeBrand } from './composite-brand.js';
2
+ import { CompositeIssues } from './composite-issues.js';
3
+ import { RequiredValueException } from '../../exceptions/required-value.exception.js';
4
+ import { TypePrimitiveException } from '../../exceptions/type-primitive.exception.js';
4
5
  export class CompositeField {
5
- static brand(prototype) {
6
- Object.defineProperty(prototype, COMPOSITE, { value: true });
6
+ static of(spec) {
7
+ if (Array.isArray(spec)) {
8
+ return new ListField(CompositeField.of(spec[0]));
9
+ }
10
+ const fieldClass = spec;
11
+ return CompositeBrand.isComposite(fieldClass.prototype)
12
+ ? new NestedCompositeField(fieldClass)
13
+ : new ValueField(fieldClass);
7
14
  }
8
- static isComposite(value) {
9
- return (typeof value === 'object' &&
10
- value !== null &&
11
- value[COMPOSITE] === true);
15
+ }
16
+ class SingleField extends CompositeField {
17
+ constructor(fieldClass) {
18
+ super();
19
+ this.fieldClass = fieldClass;
12
20
  }
13
- static accept(owner, field, spec, value) {
14
- if (!Array.isArray(spec)) {
15
- return CompositeField.acceptOne(owner, field, spec, value);
16
- }
17
- if (!Array.isArray(value)) {
18
- throw new TypePrimitiveException(`list for ${owner}.${field}`, value);
19
- }
20
- return Object.freeze(value.map((item, index) => CompositeField.acceptOne(owner, `${field}.${index}`, spec[0], item)));
21
+ get typeName() {
22
+ return this.fieldClass.name;
21
23
  }
22
- static fromPrimitive(spec, primitive) {
23
- if (Array.isArray(spec)) {
24
- if (!Array.isArray(primitive)) {
25
- throw new TypePrimitiveException('Array', primitive);
26
- }
27
- return ValueObjects.buildList(primitive, (item) => CompositeField.fromPrimitive(spec[0], item));
24
+ accept(path, value) {
25
+ if (value === null || value === undefined) {
26
+ throw new RequiredValueException(path, value);
28
27
  }
29
- const fieldClass = spec;
30
- return CompositeField.isComposite(fieldClass.prototype)
31
- ? fieldClass.fromPrimitives(primitive)
32
- : new fieldClass(primitive);
33
- }
34
- static equals(left, right) {
35
- if (Array.isArray(left)) {
36
- return (Array.isArray(right) &&
37
- left.length === right.length &&
38
- left.every((item, index) => CompositeField.equals(item, right[index])));
28
+ if (!(value instanceof this.fieldClass)) {
29
+ throw new TypePrimitiveException(`${this.typeName} for ${path}`, value);
39
30
  }
31
+ return value;
32
+ }
33
+ equals(left, right) {
40
34
  return left.equals(right);
41
35
  }
42
- static primitive(value) {
43
- if (Array.isArray(value)) {
44
- return value.map((item) => CompositeField.primitive(item));
45
- }
46
- return CompositeField.isComposite(value)
47
- ? value.toPrimitives()
48
- : value.value;
36
+ }
37
+ class ValueField extends SingleField {
38
+ fromPrimitive(primitive) {
39
+ return new this.fieldClass(primitive);
49
40
  }
50
- static acceptOne(owner, field, fieldClass, value) {
51
- if (value === null || value === undefined) {
52
- throw new RequiredValueException(`${owner}.${field}`, value);
41
+ toPrimitive(value) {
42
+ return value.value;
43
+ }
44
+ }
45
+ class NestedCompositeField extends SingleField {
46
+ fromPrimitive(primitive) {
47
+ return this.fieldClass.fromPrimitives(primitive);
48
+ }
49
+ toPrimitive(value) {
50
+ return value.toPrimitives();
51
+ }
52
+ }
53
+ class ListField extends CompositeField {
54
+ constructor(item) {
55
+ super();
56
+ this.item = item;
57
+ }
58
+ get typeName() {
59
+ return `list of ${this.item.typeName}`;
60
+ }
61
+ accept(path, value) {
62
+ if (!Array.isArray(value)) {
63
+ throw new TypePrimitiveException(`${this.typeName} for ${path}`, value);
53
64
  }
54
- if (!(value instanceof fieldClass)) {
55
- throw new TypePrimitiveException(`${fieldClass.name} for ${owner}.${field}`, value);
65
+ return Object.freeze(value.map((item, index) => this.item.accept(`${path}.${index}`, item)));
66
+ }
67
+ fromPrimitive(primitive) {
68
+ if (!Array.isArray(primitive)) {
69
+ throw new TypePrimitiveException(this.typeName, primitive);
56
70
  }
57
- return value;
71
+ return CompositeIssues.collectItems(primitive, (item) => this.item.fromPrimitive(item));
72
+ }
73
+ toPrimitive(value) {
74
+ return value.map((item) => this.item.toPrimitive(item));
75
+ }
76
+ equals(left, right) {
77
+ const items = left;
78
+ return (Array.isArray(right) &&
79
+ items.length === right.length &&
80
+ items.every((item, index) => this.item.equals(item, right[index])));
58
81
  }
59
82
  }
@@ -0,0 +1,6 @@
1
+ export declare class CompositeIssues {
2
+ static collectFields(builds: Readonly<Record<string, () => unknown>>): Record<string, unknown>;
3
+ static collectItems<Item, Built>(items: readonly Item[], build: (item: Item, index: number) => Built): Built[];
4
+ private static validated;
5
+ private static read;
6
+ }
@@ -0,0 +1,31 @@
1
+ import { IssueCollectionError, IssueCollector } from '../../../shared/index.js';
2
+ import { DomainException } from '../../exceptions/domain.exception.js';
3
+ import { ValidationException } from '../../exceptions/validation.exception.js';
4
+ export class CompositeIssues {
5
+ static collectFields(builds) {
6
+ return CompositeIssues.validated(() => IssueCollector.collectFields(builds, CompositeIssues.read));
7
+ }
8
+ static collectItems(items, build) {
9
+ return CompositeIssues.validated(() => IssueCollector.collectItems(items, build, CompositeIssues.read));
10
+ }
11
+ static validated(collect) {
12
+ try {
13
+ return collect();
14
+ }
15
+ catch (error) {
16
+ if (error instanceof IssueCollectionError) {
17
+ throw new ValidationException(error.issues);
18
+ }
19
+ throw error;
20
+ }
21
+ }
22
+ static read(error) {
23
+ if (error instanceof ValidationException) {
24
+ return error.errors;
25
+ }
26
+ if (error instanceof DomainException) {
27
+ return [{ field: null, code: error.code, message: error.message }];
28
+ }
29
+ return null;
30
+ }
31
+ }
@@ -1,26 +1,25 @@
1
1
  import { runValidations } from '@archi-code/validation';
2
+ import { CompositeBrand } from './composite-brand.js';
2
3
  import { CompositeField } from './composite-field.js';
3
- import { ValueObjects } from '../value-objects/value-objects.js';
4
- import { TypePrimitiveException, ValidationException } from '../../../exceptions/index.js';
4
+ import { CompositeIssues } from './composite-issues.js';
5
+ import { TypePrimitiveException } from '../../exceptions/type-primitive.exception.js';
6
+ import { ValidationException } from '../../exceptions/validation.exception.js';
5
7
  export function Composite(schema) {
6
- const fields = Object.keys(schema);
8
+ const fields = Object.entries(schema).map(([name, spec]) => [name, CompositeField.of(spec)]);
7
9
  class CompositeValueObject {
8
10
  static fromPrimitives(primitives) {
9
11
  if (typeof primitives !== 'object' || primitives === null || Array.isArray(primitives)) {
10
12
  throw new TypePrimitiveException(this.name, primitives);
11
13
  }
12
14
  const record = primitives;
13
- const props = ValueObjects.build(Object.fromEntries(fields.map((field) => [
14
- field,
15
- () => CompositeField.fromPrimitive(schema[field], record[field]),
16
- ])));
17
- return new this(props);
15
+ const builds = Object.fromEntries(fields.map(([name, field]) => [name, () => field.fromPrimitive(record[name])]));
16
+ return new this(CompositeIssues.collectFields(builds));
18
17
  }
19
18
  constructor(props) {
20
19
  const owner = this.constructor.name;
21
- for (const field of fields) {
22
- Object.defineProperty(this, field, {
23
- value: CompositeField.accept(owner, field, schema[field], props?.[field]),
20
+ for (const [name, field] of fields) {
21
+ Object.defineProperty(this, name, {
22
+ value: field.accept(`${owner}.${name}`, props?.[name]),
24
23
  enumerable: true,
25
24
  });
26
25
  }
@@ -38,15 +37,12 @@ export function Composite(schema) {
38
37
  return (typeof other === 'object' &&
39
38
  other !== null &&
40
39
  other.constructor === this.constructor &&
41
- fields.every((field) => CompositeField.equals(this[field], other[field])));
40
+ fields.every(([name, field]) => field.equals(this[name], other[name])));
42
41
  }
43
42
  toPrimitives() {
44
- return Object.fromEntries(fields.map((field) => [
45
- field,
46
- CompositeField.primitive(this[field]),
47
- ]));
43
+ return Object.fromEntries(fields.map(([name, field]) => [name, field.toPrimitive(this[name])]));
48
44
  }
49
45
  }
50
- CompositeField.brand(CompositeValueObject.prototype);
46
+ CompositeBrand.mark(CompositeValueObject.prototype);
51
47
  return CompositeValueObject;
52
48
  }
@@ -2,14 +2,15 @@ import { AbstractType } from './abstract-type.js';
2
2
  export declare class DateType extends AbstractType<Date, Date | string> {
3
3
  protected filter(value: unknown): Date;
4
4
  toString(): string;
5
+ protected hasSameValue(other: this): boolean;
5
6
  }
6
- declare const CreatedAt_base: import("./required/required.js").RequiredType<typeof DateType>;
7
+ declare const CreatedAt_base: import("./required/required-type.js").RequiredType<typeof DateType>;
7
8
  export declare class CreatedAt extends CreatedAt_base {
8
9
  static now(clock?: {
9
10
  now(): Date;
10
11
  }): CreatedAt;
11
12
  }
12
- declare const UpdatedAt_base: import("./required/required.js").RequiredType<typeof DateType>;
13
+ declare const UpdatedAt_base: import("./required/required-type.js").RequiredType<typeof DateType>;
13
14
  export declare class UpdatedAt extends UpdatedAt_base {
14
15
  static now(clock?: {
15
16
  now(): Date;