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

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