@archi-code/ddd 0.0.0-stage → 3.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +46 -0
- package/README.md +2795 -2
- package/SKILL.md +106 -0
- package/ddd-skills/archi-code-ddd/imports.md +94 -0
- package/ddd-skills/archi-code-ddd/layers.md +314 -0
- package/ddd-skills/archi-code-ddd/patterns.md +683 -0
- package/ddd-skills/archi-code-ddd/what-not-to-do.md +196 -0
- package/ddd-skills/archi-code-ddd/where-each-class-goes.md +64 -0
- package/ddd-skills/ddd-agregados/GUIA.md +114 -0
- package/ddd-skills/ddd-agregados/references/consistencia-eventual.md +158 -0
- package/ddd-skills/ddd-agregados/references/ejemplo-ecommerce.md +52 -0
- package/ddd-skills/ddd-agregados/references/fabricas.md +193 -0
- package/ddd-skills/ddd-agregados/references/implementacion-ts.md +706 -0
- package/ddd-skills/ddd-arquitectura/GUIA.md +80 -0
- package/ddd-skills/ddd-arquitectura/assets/dependency-cruiser.cjs +99 -0
- package/ddd-skills/ddd-arquitectura/references/estilos-adicionales.md +51 -0
- package/ddd-skills/ddd-arquitectura/references/estructura-hexagonal-ts.md +406 -0
- package/ddd-skills/ddd-arquitectura/references/modulos.md +48 -0
- package/ddd-skills/ddd-auditoria-refactorizacion/GUIA.md +85 -0
- package/ddd-skills/ddd-auditoria-refactorizacion/references/ejemplo-auditoria.md +314 -0
- package/ddd-skills/ddd-auditoria-refactorizacion/references/lista-comprobacion.md +54 -0
- package/ddd-skills/ddd-auditoria-refactorizacion/references/plan-migracion.md +73 -0
- package/ddd-skills/ddd-auditoria-refactorizacion/scripts/scan_ddd_smells.py +264 -0
- package/ddd-skills/ddd-context-mapping/GUIA.md +83 -0
- package/ddd-skills/ddd-context-mapping/references/anticorrupcion-ts.md +419 -0
- package/ddd-skills/ddd-context-mapping/references/estilos-integracion.md +152 -0
- package/ddd-skills/ddd-event-sourcing-cqrs/GUIA.md +92 -0
- package/ddd-skills/ddd-event-sourcing-cqrs/references/event-sourcing-ts.md +476 -0
- package/ddd-skills/ddd-event-sourcing-cqrs/references/proyecciones-cqrs-ts.md +285 -0
- package/ddd-skills/ddd-eventos-dominio/GUIA.md +106 -0
- package/ddd-skills/ddd-eventos-dominio/references/diseno-eventos.md +130 -0
- package/ddd-skills/ddd-eventos-dominio/references/ejemplo-ecommerce.md +240 -0
- package/ddd-skills/ddd-eventos-dominio/references/publicacion-ts.md +529 -0
- package/ddd-skills/ddd-orquestador/GUIA.md +40 -0
- package/ddd-skills/ddd-orquestador/references/chuleta-reglas.md +35 -0
- package/ddd-skills/ddd-repositorios-persistencia/GUIA.md +121 -0
- package/ddd-skills/ddd-repositorios-persistencia/references/implementacion-ts.md +314 -0
- package/ddd-skills/ddd-repositorios-persistencia/references/tests-repositorios.md +191 -0
- package/ddd-skills/ddd-repositorios-persistencia/references/transacciones-ts.md +301 -0
- package/ddd-skills/ddd-servicios-capa-aplicacion/GUIA.md +99 -0
- package/ddd-skills/ddd-servicios-capa-aplicacion/references/capa-aplicacion-ts.md +264 -0
- package/ddd-skills/ddd-servicios-capa-aplicacion/references/ejemplo-ecommerce.md +321 -0
- package/ddd-skills/ddd-servicios-capa-aplicacion/references/servicios-dominio-ts.md +190 -0
- package/ddd-skills/ddd-value-objects-entidades/GUIA.md +118 -0
- package/ddd-skills/ddd-value-objects-entidades/references/ejemplo-ecommerce.md +87 -0
- package/ddd-skills/ddd-value-objects-entidades/references/entidades-ts.md +218 -0
- package/ddd-skills/ddd-value-objects-entidades/references/persistencia-valores.md +88 -0
- package/ddd-skills/ddd-value-objects-entidades/references/specification-y-diseno-flexible.md +119 -0
- package/ddd-skills/ddd-value-objects-entidades/references/validacion.md +96 -0
- package/ddd-skills/ddd-value-objects-entidades/references/value-objects-ts.md +376 -0
- package/dist/cjs/application/event/event-bus.d.ts +4 -0
- package/dist/cjs/application/event/event-bus.js +2 -0
- package/dist/cjs/application/event/event-listener.d.ts +4 -0
- package/dist/cjs/application/event/event-listener.js +6 -0
- package/dist/cjs/application/event/listens-to.d.ts +15 -0
- package/dist/cjs/application/event/listens-to.js +28 -0
- package/dist/cjs/application/exceptions/aggregate-not-found.exception.d.ts +5 -0
- package/dist/cjs/application/exceptions/aggregate-not-found.exception.js +17 -0
- package/dist/cjs/application/exceptions/application-exception-code.d.ts +7 -0
- package/dist/cjs/application/exceptions/application-exception-code.js +11 -0
- package/dist/cjs/application/exceptions/application.exception.d.ts +6 -0
- package/dist/cjs/application/exceptions/application.exception.js +16 -0
- package/dist/cjs/application/exceptions/concurrency.exception.d.ts +5 -0
- package/dist/cjs/application/exceptions/concurrency.exception.js +17 -0
- package/dist/cjs/application/exceptions/not-allowed.exception.d.ts +5 -0
- package/dist/cjs/application/exceptions/not-allowed.exception.js +17 -0
- package/dist/cjs/application/exceptions/unexpected-error.exception.d.ts +5 -0
- package/dist/cjs/application/exceptions/unexpected-error.exception.js +17 -0
- package/dist/cjs/application/index.d.ts +14 -0
- package/dist/cjs/application/index.js +23 -0
- package/dist/cjs/application/ports/clock.d.ts +3 -0
- package/dist/cjs/application/ports/clock.js +2 -0
- package/dist/cjs/application/ports/logger.d.ts +8 -0
- package/dist/cjs/application/ports/logger.js +2 -0
- package/dist/cjs/application/use-case/use-case.d.ts +6 -0
- package/dist/cjs/application/use-case/use-case.js +25 -0
- package/dist/cjs/application/value-object-builder/value-object-builder.d.ts +16 -0
- package/dist/cjs/application/value-object-builder/value-object-builder.js +51 -0
- package/dist/cjs/domain/aggregate/aggregate-root.d.ts +9 -0
- package/dist/cjs/domain/aggregate/aggregate-root.js +17 -0
- package/dist/cjs/domain/entity/entity.d.ts +9 -0
- package/dist/cjs/domain/entity/entity.js +19 -0
- package/dist/cjs/domain/event/event-base.d.ts +23 -0
- package/dist/cjs/domain/event/event-base.js +21 -0
- package/dist/cjs/domain/exceptions/domain-exception-code.d.ts +7 -0
- package/dist/cjs/domain/exceptions/domain-exception-code.js +11 -0
- package/dist/cjs/domain/exceptions/domain.exception.d.ts +6 -0
- package/dist/cjs/domain/exceptions/domain.exception.js +16 -0
- package/dist/cjs/domain/exceptions/invalid-event-definition.exception.d.ts +4 -0
- package/dist/cjs/domain/exceptions/invalid-event-definition.exception.js +19 -0
- package/dist/cjs/domain/exceptions/required-value.exception.d.ts +4 -0
- package/dist/cjs/domain/exceptions/required-value.exception.js +20 -0
- package/dist/cjs/domain/exceptions/type-primitive.exception.d.ts +4 -0
- package/dist/cjs/domain/exceptions/type-primitive.exception.js +20 -0
- package/dist/cjs/domain/exceptions/validation.exception.d.ts +14 -0
- package/dist/cjs/domain/exceptions/validation.exception.js +23 -0
- package/dist/cjs/domain/index.d.ts +17 -0
- package/dist/cjs/domain/index.js +36 -0
- package/dist/cjs/domain/primitive/primitive-types.d.ts +20 -0
- package/dist/cjs/domain/primitive/primitive-types.js +2 -0
- package/dist/cjs/domain/repository/aggregate-finder.d.ts +4 -0
- package/dist/cjs/domain/repository/aggregate-finder.js +2 -0
- package/dist/cjs/domain/repository/aggregate-remover.d.ts +4 -0
- package/dist/cjs/domain/repository/aggregate-remover.js +2 -0
- package/dist/cjs/domain/repository/aggregate-saver.d.ts +4 -0
- package/dist/cjs/domain/repository/aggregate-saver.js +2 -0
- package/dist/cjs/domain/specification/specification.d.ts +9 -0
- package/dist/cjs/domain/specification/specification.js +44 -0
- package/dist/cjs/domain/type/abstract-type.d.ts +18 -0
- package/dist/cjs/domain/type/abstract-type.js +61 -0
- package/dist/cjs/domain/type/array-type.d.ts +17 -0
- package/dist/cjs/domain/type/array-type.js +64 -0
- package/dist/cjs/domain/type/boolean-type.d.ts +4 -0
- package/dist/cjs/domain/type/boolean-type.js +16 -0
- package/dist/cjs/domain/type/composite/composite-brand.d.ts +4 -0
- package/dist/cjs/domain/type/composite/composite-brand.js +15 -0
- package/dist/cjs/domain/type/composite/composite-field.d.ts +18 -0
- package/dist/cjs/domain/type/composite/composite-field.js +86 -0
- package/dist/cjs/domain/type/composite/composite-issues.d.ts +6 -0
- package/dist/cjs/domain/type/composite/composite-issues.js +35 -0
- package/dist/cjs/domain/type/composite/composite.d.ts +26 -0
- package/dist/cjs/domain/type/composite/composite.js +51 -0
- package/dist/cjs/domain/type/date-type.d.ts +19 -0
- package/dist/cjs/domain/type/date-type.js +70 -0
- package/dist/cjs/domain/type/enum-type.d.ts +7 -0
- package/dist/cjs/domain/type/enum-type.js +30 -0
- package/dist/cjs/domain/type/id-type.d.ts +7 -0
- package/dist/cjs/domain/type/id-type.js +17 -0
- package/dist/cjs/domain/type/index.d.ts +15 -0
- package/dist/cjs/domain/type/index.js +29 -0
- package/dist/cjs/domain/type/json-type.d.ts +9 -0
- package/dist/cjs/domain/type/json-type.js +46 -0
- package/dist/cjs/domain/type/number-type.d.ts +4 -0
- package/dist/cjs/domain/type/number-type.js +16 -0
- package/dist/cjs/domain/type/required/required-mark.d.ts +8 -0
- package/dist/cjs/domain/type/required/required-mark.js +13 -0
- package/dist/cjs/domain/type/required/required-type.d.ts +7 -0
- package/dist/cjs/domain/type/required/required-type.js +21 -0
- package/dist/cjs/domain/type/string-type.d.ts +4 -0
- package/dist/cjs/domain/type/string-type.js +16 -0
- package/dist/cjs/domain/type/uuid-type.d.ts +7 -0
- package/dist/cjs/domain/type/uuid-type.js +27 -0
- package/dist/cjs/infrastructure/clock/fixed-clock.d.ts +8 -0
- package/dist/cjs/infrastructure/clock/fixed-clock.js +19 -0
- package/dist/cjs/infrastructure/clock/system-clock.d.ts +4 -0
- package/dist/cjs/infrastructure/clock/system-clock.js +9 -0
- package/dist/cjs/infrastructure/event/domain-event-bus.d.ts +16 -0
- package/dist/cjs/infrastructure/event/domain-event-bus.js +60 -0
- package/dist/cjs/infrastructure/event/event-channel.d.ts +9 -0
- package/dist/cjs/infrastructure/event/event-channel.js +2 -0
- package/dist/cjs/infrastructure/event/event-registry.d.ts +9 -0
- package/dist/cjs/infrastructure/event/event-registry.js +43 -0
- package/dist/cjs/infrastructure/event/in-memory/emitter.d.ts +11 -0
- package/dist/cjs/infrastructure/event/in-memory/emitter.js +54 -0
- package/dist/cjs/infrastructure/event/in-memory/in-memory-event-channel.d.ts +16 -0
- package/dist/cjs/infrastructure/event/in-memory/in-memory-event-channel.js +50 -0
- package/dist/cjs/infrastructure/exceptions/event-delivery.exception.d.ts +5 -0
- package/dist/cjs/infrastructure/exceptions/event-delivery.exception.js +20 -0
- package/dist/cjs/infrastructure/exceptions/infrastructure-exception-code.d.ts +6 -0
- package/dist/cjs/infrastructure/exceptions/infrastructure-exception-code.js +10 -0
- package/dist/cjs/infrastructure/exceptions/infrastructure.exception.d.ts +6 -0
- package/dist/cjs/infrastructure/exceptions/infrastructure.exception.js +16 -0
- package/dist/cjs/infrastructure/exceptions/internal-error.exception.d.ts +5 -0
- package/dist/cjs/infrastructure/exceptions/internal-error.exception.js +17 -0
- package/dist/cjs/infrastructure/exceptions/kind/exception-classifier.d.ts +4 -0
- package/dist/cjs/infrastructure/exceptions/kind/exception-classifier.js +34 -0
- package/dist/cjs/infrastructure/exceptions/kind/exception-kind.d.ts +9 -0
- package/dist/cjs/infrastructure/exceptions/kind/exception-kind.js +13 -0
- package/dist/cjs/infrastructure/exceptions/unknown-event.exception.d.ts +4 -0
- package/dist/cjs/infrastructure/exceptions/unknown-event.exception.js +19 -0
- package/dist/cjs/infrastructure/index.d.ts +21 -0
- package/dist/cjs/infrastructure/index.js +33 -0
- package/dist/cjs/infrastructure/logging/console-logger.d.ts +17 -0
- package/dist/cjs/infrastructure/logging/console-logger.js +37 -0
- package/dist/cjs/infrastructure/logging/in-memory-logger.d.ts +15 -0
- package/dist/cjs/infrastructure/logging/in-memory-logger.js +27 -0
- package/dist/cjs/infrastructure/logging/log-serializer.d.ts +7 -0
- package/dist/cjs/infrastructure/logging/log-serializer.js +59 -0
- package/dist/cjs/infrastructure/logging/silent-logger.d.ts +7 -0
- package/dist/cjs/infrastructure/logging/silent-logger.js +18 -0
- package/dist/cjs/shared/exceptions/abstract.exception.d.ts +25 -0
- package/dist/cjs/shared/exceptions/abstract.exception.js +59 -0
- package/dist/cjs/shared/exceptions/brand/exception-brand.d.ts +6 -0
- package/dist/cjs/shared/exceptions/brand/exception-brand.js +29 -0
- package/dist/cjs/shared/exceptions/received/received-value.d.ts +4 -0
- package/dist/cjs/shared/exceptions/received/received-value.js +13 -0
- package/dist/cjs/shared/index.d.ts +8 -0
- package/dist/cjs/shared/index.js +13 -0
- package/dist/cjs/shared/issue-collection-error.d.ts +9 -0
- package/dist/cjs/shared/issue-collection-error.js +11 -0
- package/dist/cjs/shared/issue-collector.d.ts +8 -0
- package/dist/cjs/shared/issue-collector.js +41 -0
- package/dist/esm/application/event/event-bus.d.ts +4 -0
- package/dist/esm/application/event/event-bus.js +1 -0
- package/dist/esm/application/event/event-listener.d.ts +4 -0
- package/dist/esm/application/event/event-listener.js +2 -0
- package/dist/esm/application/event/listens-to.d.ts +15 -0
- package/dist/esm/application/event/listens-to.js +25 -0
- package/dist/esm/application/exceptions/aggregate-not-found.exception.d.ts +5 -0
- package/dist/esm/application/exceptions/aggregate-not-found.exception.js +13 -0
- package/dist/esm/application/exceptions/application-exception-code.d.ts +7 -0
- package/dist/esm/application/exceptions/application-exception-code.js +8 -0
- package/dist/esm/application/exceptions/application.exception.d.ts +6 -0
- package/dist/esm/application/exceptions/application.exception.js +12 -0
- package/dist/esm/application/exceptions/concurrency.exception.d.ts +5 -0
- package/dist/esm/application/exceptions/concurrency.exception.js +13 -0
- package/dist/esm/application/exceptions/not-allowed.exception.d.ts +5 -0
- package/dist/esm/application/exceptions/not-allowed.exception.js +13 -0
- package/dist/esm/application/exceptions/unexpected-error.exception.d.ts +5 -0
- package/dist/esm/application/exceptions/unexpected-error.exception.js +13 -0
- package/dist/esm/application/index.d.ts +14 -0
- package/dist/esm/application/index.js +10 -0
- package/dist/esm/application/ports/clock.d.ts +3 -0
- package/dist/esm/application/ports/clock.js +1 -0
- package/dist/esm/application/ports/logger.d.ts +8 -0
- package/dist/esm/application/ports/logger.js +1 -0
- package/dist/esm/application/use-case/use-case.d.ts +6 -0
- package/dist/esm/application/use-case/use-case.js +21 -0
- package/dist/esm/application/value-object-builder/value-object-builder.d.ts +16 -0
- package/dist/esm/application/value-object-builder/value-object-builder.js +47 -0
- package/dist/esm/domain/aggregate/aggregate-root.d.ts +9 -0
- package/dist/esm/domain/aggregate/aggregate-root.js +13 -0
- package/dist/esm/domain/entity/entity.d.ts +9 -0
- package/dist/esm/domain/entity/entity.js +15 -0
- package/dist/esm/domain/event/event-base.d.ts +23 -0
- package/dist/esm/domain/event/event-base.js +17 -0
- package/dist/esm/domain/exceptions/domain-exception-code.d.ts +7 -0
- package/dist/esm/domain/exceptions/domain-exception-code.js +8 -0
- package/dist/esm/domain/exceptions/domain.exception.d.ts +6 -0
- package/dist/esm/domain/exceptions/domain.exception.js +12 -0
- package/dist/esm/domain/exceptions/invalid-event-definition.exception.d.ts +4 -0
- package/dist/esm/domain/exceptions/invalid-event-definition.exception.js +15 -0
- package/dist/esm/domain/exceptions/required-value.exception.d.ts +4 -0
- package/dist/esm/domain/exceptions/required-value.exception.js +16 -0
- package/dist/esm/domain/exceptions/type-primitive.exception.d.ts +4 -0
- package/dist/esm/domain/exceptions/type-primitive.exception.js +16 -0
- package/dist/esm/domain/exceptions/validation.exception.d.ts +14 -0
- package/dist/esm/domain/exceptions/validation.exception.js +19 -0
- package/dist/esm/domain/index.d.ts +17 -0
- package/dist/esm/domain/index.js +12 -0
- package/dist/esm/domain/primitive/primitive-types.d.ts +20 -0
- package/dist/esm/domain/primitive/primitive-types.js +1 -0
- package/dist/esm/domain/repository/aggregate-finder.d.ts +4 -0
- package/dist/esm/domain/repository/aggregate-finder.js +1 -0
- package/dist/esm/domain/repository/aggregate-remover.d.ts +4 -0
- package/dist/esm/domain/repository/aggregate-remover.js +1 -0
- package/dist/esm/domain/repository/aggregate-saver.d.ts +4 -0
- package/dist/esm/domain/repository/aggregate-saver.js +1 -0
- package/dist/esm/domain/specification/specification.d.ts +9 -0
- package/dist/esm/domain/specification/specification.js +40 -0
- package/dist/esm/domain/type/abstract-type.d.ts +18 -0
- package/dist/esm/domain/type/abstract-type.js +57 -0
- package/dist/esm/domain/type/array-type.d.ts +17 -0
- package/dist/esm/domain/type/array-type.js +60 -0
- package/dist/esm/domain/type/boolean-type.d.ts +4 -0
- package/dist/esm/domain/type/boolean-type.js +12 -0
- package/dist/esm/domain/type/composite/composite-brand.d.ts +4 -0
- package/dist/esm/domain/type/composite/composite-brand.js +11 -0
- package/dist/esm/domain/type/composite/composite-field.d.ts +18 -0
- package/dist/esm/domain/type/composite/composite-field.js +82 -0
- package/dist/esm/domain/type/composite/composite-issues.d.ts +6 -0
- package/dist/esm/domain/type/composite/composite-issues.js +31 -0
- package/dist/esm/domain/type/composite/composite.d.ts +26 -0
- package/dist/esm/domain/type/composite/composite.js +48 -0
- package/dist/esm/domain/type/date-type.d.ts +19 -0
- package/dist/esm/domain/type/date-type.js +64 -0
- package/dist/esm/domain/type/enum-type.d.ts +7 -0
- package/dist/esm/domain/type/enum-type.js +26 -0
- package/dist/esm/domain/type/id-type.d.ts +7 -0
- package/dist/esm/domain/type/id-type.js +13 -0
- package/dist/esm/domain/type/index.d.ts +15 -0
- package/dist/esm/domain/type/index.js +12 -0
- package/dist/esm/domain/type/json-type.d.ts +9 -0
- package/dist/esm/domain/type/json-type.js +42 -0
- package/dist/esm/domain/type/number-type.d.ts +4 -0
- package/dist/esm/domain/type/number-type.js +12 -0
- package/dist/esm/domain/type/required/required-mark.d.ts +8 -0
- package/dist/esm/domain/type/required/required-mark.js +9 -0
- package/dist/esm/domain/type/required/required-type.d.ts +7 -0
- package/dist/esm/domain/type/required/required-type.js +18 -0
- package/dist/esm/domain/type/string-type.d.ts +4 -0
- package/dist/esm/domain/type/string-type.js +12 -0
- package/dist/esm/domain/type/uuid-type.d.ts +7 -0
- package/dist/esm/domain/type/uuid-type.js +23 -0
- package/dist/esm/infrastructure/clock/fixed-clock.d.ts +8 -0
- package/dist/esm/infrastructure/clock/fixed-clock.js +15 -0
- package/dist/esm/infrastructure/clock/system-clock.d.ts +4 -0
- package/dist/esm/infrastructure/clock/system-clock.js +5 -0
- package/dist/esm/infrastructure/event/domain-event-bus.d.ts +16 -0
- package/dist/esm/infrastructure/event/domain-event-bus.js +56 -0
- package/dist/esm/infrastructure/event/event-channel.d.ts +9 -0
- package/dist/esm/infrastructure/event/event-channel.js +1 -0
- package/dist/esm/infrastructure/event/event-registry.d.ts +9 -0
- package/dist/esm/infrastructure/event/event-registry.js +39 -0
- package/dist/esm/infrastructure/event/in-memory/emitter.d.ts +11 -0
- package/dist/esm/infrastructure/event/in-memory/emitter.js +50 -0
- package/dist/esm/infrastructure/event/in-memory/in-memory-event-channel.d.ts +16 -0
- package/dist/esm/infrastructure/event/in-memory/in-memory-event-channel.js +46 -0
- package/dist/esm/infrastructure/exceptions/event-delivery.exception.d.ts +5 -0
- package/dist/esm/infrastructure/exceptions/event-delivery.exception.js +16 -0
- package/dist/esm/infrastructure/exceptions/infrastructure-exception-code.d.ts +6 -0
- package/dist/esm/infrastructure/exceptions/infrastructure-exception-code.js +7 -0
- package/dist/esm/infrastructure/exceptions/infrastructure.exception.d.ts +6 -0
- package/dist/esm/infrastructure/exceptions/infrastructure.exception.js +12 -0
- package/dist/esm/infrastructure/exceptions/internal-error.exception.d.ts +5 -0
- package/dist/esm/infrastructure/exceptions/internal-error.exception.js +13 -0
- package/dist/esm/infrastructure/exceptions/kind/exception-classifier.d.ts +4 -0
- package/dist/esm/infrastructure/exceptions/kind/exception-classifier.js +30 -0
- package/dist/esm/infrastructure/exceptions/kind/exception-kind.d.ts +9 -0
- package/dist/esm/infrastructure/exceptions/kind/exception-kind.js +10 -0
- package/dist/esm/infrastructure/exceptions/unknown-event.exception.d.ts +4 -0
- package/dist/esm/infrastructure/exceptions/unknown-event.exception.js +15 -0
- package/dist/esm/infrastructure/index.d.ts +21 -0
- package/dist/esm/infrastructure/index.js +15 -0
- package/dist/esm/infrastructure/logging/console-logger.d.ts +17 -0
- package/dist/esm/infrastructure/logging/console-logger.js +33 -0
- package/dist/esm/infrastructure/logging/in-memory-logger.d.ts +15 -0
- package/dist/esm/infrastructure/logging/in-memory-logger.js +23 -0
- package/dist/esm/infrastructure/logging/log-serializer.d.ts +7 -0
- package/dist/esm/infrastructure/logging/log-serializer.js +55 -0
- package/dist/esm/infrastructure/logging/silent-logger.d.ts +7 -0
- package/dist/esm/infrastructure/logging/silent-logger.js +14 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/shared/exceptions/abstract.exception.d.ts +25 -0
- package/dist/esm/shared/exceptions/abstract.exception.js +55 -0
- package/dist/esm/shared/exceptions/brand/exception-brand.d.ts +6 -0
- package/dist/esm/shared/exceptions/brand/exception-brand.js +25 -0
- package/dist/esm/shared/exceptions/received/received-value.d.ts +4 -0
- package/dist/esm/shared/exceptions/received/received-value.js +9 -0
- package/dist/esm/shared/index.d.ts +8 -0
- package/dist/esm/shared/index.js +5 -0
- package/dist/esm/shared/issue-collection-error.d.ts +9 -0
- package/dist/esm/shared/issue-collection-error.js +7 -0
- package/dist/esm/shared/issue-collector.d.ts +8 -0
- package/dist/esm/shared/issue-collector.js +37 -0
- package/package.json +95 -4
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { anyToString, runValidations } from '@archi-code/validation';
|
|
3
|
+
import { RequiredMark } from './required/required-mark.js';
|
|
4
|
+
import { RequiredValueException } from '../exceptions/required-value.exception.js';
|
|
5
|
+
import { ValidationException } from '../exceptions/validation.exception.js';
|
|
6
|
+
const VALUE_OBJECT = Symbol.for('@archi-code/ddd/value-object.v1');
|
|
7
|
+
export class AbstractType {
|
|
8
|
+
static [Symbol.hasInstance](candidate) {
|
|
9
|
+
return (Function.prototype[Symbol.hasInstance].call(this, candidate) ||
|
|
10
|
+
(this === _a &&
|
|
11
|
+
typeof candidate === 'object' &&
|
|
12
|
+
candidate !== null &&
|
|
13
|
+
candidate[VALUE_OBJECT] === true));
|
|
14
|
+
}
|
|
15
|
+
constructor(value = null) {
|
|
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
|
+
}
|
|
20
|
+
const brokenRules = this.brokenRules(this._value);
|
|
21
|
+
if (brokenRules.length > 0) {
|
|
22
|
+
throw new ValidationException(brokenRules);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
get value() {
|
|
26
|
+
return this._value;
|
|
27
|
+
}
|
|
28
|
+
get isNull() {
|
|
29
|
+
return this._value === null;
|
|
30
|
+
}
|
|
31
|
+
toString() {
|
|
32
|
+
return this.isNull ? '' : anyToString(this._value);
|
|
33
|
+
}
|
|
34
|
+
equals(other) {
|
|
35
|
+
return other?.constructor === this.constructor && this.hasSameValue(other);
|
|
36
|
+
}
|
|
37
|
+
hasSameValue(other) {
|
|
38
|
+
return this._value === other._value;
|
|
39
|
+
}
|
|
40
|
+
validate() {
|
|
41
|
+
return this.runRules(this._value);
|
|
42
|
+
}
|
|
43
|
+
brokenRules(value) {
|
|
44
|
+
return this.runRules(value).errors.map((error) => ({
|
|
45
|
+
field: null,
|
|
46
|
+
code: 'validator' in error ? error.validator : error.custom,
|
|
47
|
+
message: `${this.constructor.name}: ${error.message}`,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
runRules(value) {
|
|
51
|
+
return runValidations(this.constructor, value);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
_a = AbstractType;
|
|
55
|
+
(() => {
|
|
56
|
+
Object.defineProperty(_a.prototype, VALUE_OBJECT, { value: true });
|
|
57
|
+
})();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ValidationResult } from '@archi-code/validation';
|
|
2
|
+
import { AbstractType } from './abstract-type.js';
|
|
3
|
+
import type { ValueOf } from './abstract-type.js';
|
|
4
|
+
type ItemValue<Item extends AbstractType<any>> = Item['value'];
|
|
5
|
+
export declare abstract class ArrayType<Item extends AbstractType<any>> extends AbstractType<ItemValue<Item>[]> {
|
|
6
|
+
protected abstract createItem(value: unknown): Item;
|
|
7
|
+
get items(): Item[];
|
|
8
|
+
toString(): string;
|
|
9
|
+
hasItem(value: ItemValue<Item>): boolean;
|
|
10
|
+
withItem(value: ItemValue<Item>): this;
|
|
11
|
+
withoutItem(value: ItemValue<Item>): this;
|
|
12
|
+
protected hasSameValue(other: this): boolean;
|
|
13
|
+
protected filter(value: unknown): ItemValue<Item>[];
|
|
14
|
+
validate(): ValidationResult<ValueOf<ItemValue<Item>[], this>>;
|
|
15
|
+
private copyWith;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { toArray } from '@archi-code/validation';
|
|
2
|
+
import { AbstractType } from './abstract-type.js';
|
|
3
|
+
import { TypePrimitiveException } from '../exceptions/type-primitive.exception.js';
|
|
4
|
+
export class ArrayType extends AbstractType {
|
|
5
|
+
get items() {
|
|
6
|
+
return (this._value ?? []).map((value) => this.createItem(value));
|
|
7
|
+
}
|
|
8
|
+
toString() {
|
|
9
|
+
return this.items.map((item) => item.toString()).join(', ');
|
|
10
|
+
}
|
|
11
|
+
hasItem(value) {
|
|
12
|
+
const item = this.createItem(value);
|
|
13
|
+
return (this._value ?? []).some((current) => this.createItem(current).equals(item));
|
|
14
|
+
}
|
|
15
|
+
withItem(value) {
|
|
16
|
+
return this.copyWith([...(this._value ?? []), value]);
|
|
17
|
+
}
|
|
18
|
+
withoutItem(value) {
|
|
19
|
+
if (this._value === null) {
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
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]))));
|
|
32
|
+
}
|
|
33
|
+
filter(value) {
|
|
34
|
+
const converted = toArray(value);
|
|
35
|
+
if (!converted.ok) {
|
|
36
|
+
throw new TypePrimitiveException('Array', value);
|
|
37
|
+
}
|
|
38
|
+
const items = converted.value.map((item) => this.createItem(item).value);
|
|
39
|
+
Object.freeze(items);
|
|
40
|
+
return items;
|
|
41
|
+
}
|
|
42
|
+
validate() {
|
|
43
|
+
const own = super.validate();
|
|
44
|
+
const itemErrors = (this._value ?? []).flatMap((itemValue, index) => this.createItem(itemValue)
|
|
45
|
+
.validate()
|
|
46
|
+
.errors.map((error) => Object.freeze({ ...error, message: `Item ${index + 1}: ${error.message}` })));
|
|
47
|
+
if (itemErrors.length === 0) {
|
|
48
|
+
return own;
|
|
49
|
+
}
|
|
50
|
+
return Object.freeze({
|
|
51
|
+
ok: false,
|
|
52
|
+
value: own.value,
|
|
53
|
+
errors: Object.freeze([...own.errors, ...itemErrors]),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
copyWith(values) {
|
|
57
|
+
const SameType = this.constructor;
|
|
58
|
+
return new SameType(values);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { toBoolean } from '@archi-code/validation';
|
|
2
|
+
import { AbstractType } from './abstract-type.js';
|
|
3
|
+
import { TypePrimitiveException } from '../exceptions/type-primitive.exception.js';
|
|
4
|
+
export class BooleanType extends AbstractType {
|
|
5
|
+
filter(value) {
|
|
6
|
+
const converted = toBoolean(value);
|
|
7
|
+
if (!converted.ok) {
|
|
8
|
+
throw new TypePrimitiveException('Boolean', value);
|
|
9
|
+
}
|
|
10
|
+
return converted.value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AbstractType } from '../abstract-type.js';
|
|
2
|
+
export type ValueClass = new (value: any) => AbstractType<any>;
|
|
3
|
+
export interface CompositeClass {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly prototype: object;
|
|
6
|
+
new (props: any): object;
|
|
7
|
+
fromPrimitives(primitives: any): object;
|
|
8
|
+
}
|
|
9
|
+
export type FieldClass = ValueClass | CompositeClass;
|
|
10
|
+
export type FieldSpec = FieldClass | readonly [FieldClass];
|
|
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;
|
|
18
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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';
|
|
5
|
+
export class CompositeField {
|
|
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);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
class SingleField extends CompositeField {
|
|
17
|
+
constructor(fieldClass) {
|
|
18
|
+
super();
|
|
19
|
+
this.fieldClass = fieldClass;
|
|
20
|
+
}
|
|
21
|
+
get typeName() {
|
|
22
|
+
return this.fieldClass.name;
|
|
23
|
+
}
|
|
24
|
+
accept(path, value) {
|
|
25
|
+
if (value === null || value === undefined) {
|
|
26
|
+
throw new RequiredValueException(path, value);
|
|
27
|
+
}
|
|
28
|
+
if (!(value instanceof this.fieldClass)) {
|
|
29
|
+
throw new TypePrimitiveException(`${this.typeName} for ${path}`, value);
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
equals(left, right) {
|
|
34
|
+
return left.equals(right);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
class ValueField extends SingleField {
|
|
38
|
+
fromPrimitive(primitive) {
|
|
39
|
+
return new this.fieldClass(primitive);
|
|
40
|
+
}
|
|
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);
|
|
64
|
+
}
|
|
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);
|
|
70
|
+
}
|
|
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])));
|
|
81
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FieldSpec } from './composite-field.js';
|
|
2
|
+
import type { PrimitiveType } from '../../primitive/primitive-types.js';
|
|
3
|
+
export type CompositeSchema = Record<string, FieldSpec>;
|
|
4
|
+
type FieldOf<Spec> = Spec extends readonly [infer Item] ? FieldOf<Item>[] : Spec extends abstract new (...args: any[]) => infer Instance ? Instance : never;
|
|
5
|
+
export type CompositeProps<Schema extends CompositeSchema> = {
|
|
6
|
+
readonly [Field in keyof Schema]: FieldOf<Schema[Field]>;
|
|
7
|
+
};
|
|
8
|
+
export type CompositePrimitives<Schema extends CompositeSchema> = {
|
|
9
|
+
[Field in keyof Schema]: PrimitiveType<FieldOf<Schema[Field]>>;
|
|
10
|
+
};
|
|
11
|
+
type InputOf<Spec> = Spec extends readonly [infer Item] ? InputOf<Item>[] : Spec extends {
|
|
12
|
+
fromPrimitives(this: any, primitives: infer Primitives): unknown;
|
|
13
|
+
} ? Primitives : Spec extends abstract new (value: infer Value) => unknown ? Exclude<Value, undefined> : never;
|
|
14
|
+
export type CompositeInput<Schema extends CompositeSchema> = {
|
|
15
|
+
[Field in keyof Schema]: InputOf<Schema[Field]>;
|
|
16
|
+
};
|
|
17
|
+
export interface CompositeValue<Schema extends CompositeSchema> {
|
|
18
|
+
equals(other: unknown): boolean;
|
|
19
|
+
toPrimitives(): CompositePrimitives<Schema>;
|
|
20
|
+
}
|
|
21
|
+
export interface CompositeType<Schema extends CompositeSchema> {
|
|
22
|
+
new (props: CompositeProps<Schema>): CompositeProps<Schema> & CompositeValue<Schema>;
|
|
23
|
+
fromPrimitives<Composed>(this: new (props: CompositeProps<Schema>) => Composed, primitives: CompositeInput<Schema>): Composed;
|
|
24
|
+
}
|
|
25
|
+
export declare function Composite<Schema extends CompositeSchema>(schema: Schema): CompositeType<Schema>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { runValidations } from '@archi-code/validation';
|
|
2
|
+
import { CompositeBrand } from './composite-brand.js';
|
|
3
|
+
import { CompositeField } from './composite-field.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';
|
|
7
|
+
export function Composite(schema) {
|
|
8
|
+
const fields = Object.entries(schema).map(([name, spec]) => [name, CompositeField.of(spec)]);
|
|
9
|
+
class CompositeValueObject {
|
|
10
|
+
static fromPrimitives(primitives) {
|
|
11
|
+
if (typeof primitives !== 'object' || primitives === null || Array.isArray(primitives)) {
|
|
12
|
+
throw new TypePrimitiveException(this.name, primitives);
|
|
13
|
+
}
|
|
14
|
+
const record = primitives;
|
|
15
|
+
const builds = Object.fromEntries(fields.map(([name, field]) => [name, () => field.fromPrimitive(record[name])]));
|
|
16
|
+
return new this(CompositeIssues.collectFields(builds));
|
|
17
|
+
}
|
|
18
|
+
constructor(props) {
|
|
19
|
+
const owner = this.constructor.name;
|
|
20
|
+
for (const [name, field] of fields) {
|
|
21
|
+
Object.defineProperty(this, name, {
|
|
22
|
+
value: field.accept(`${owner}.${name}`, props?.[name]),
|
|
23
|
+
enumerable: true,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const brokenRules = runValidations(this.constructor, this).errors;
|
|
27
|
+
if (brokenRules.length > 0) {
|
|
28
|
+
throw new ValidationException(brokenRules.map((error) => ({
|
|
29
|
+
field: null,
|
|
30
|
+
code: 'custom' in error ? error.custom : error.validator,
|
|
31
|
+
message: `${owner}: ${error.message}`,
|
|
32
|
+
})));
|
|
33
|
+
}
|
|
34
|
+
Object.freeze(this);
|
|
35
|
+
}
|
|
36
|
+
equals(other) {
|
|
37
|
+
return (typeof other === 'object' &&
|
|
38
|
+
other !== null &&
|
|
39
|
+
other.constructor === this.constructor &&
|
|
40
|
+
fields.every(([name, field]) => field.equals(this[name], other[name])));
|
|
41
|
+
}
|
|
42
|
+
toPrimitives() {
|
|
43
|
+
return Object.fromEntries(fields.map(([name, field]) => [name, field.toPrimitive(this[name])]));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
CompositeBrand.mark(CompositeValueObject.prototype);
|
|
47
|
+
return CompositeValueObject;
|
|
48
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AbstractType } from './abstract-type.js';
|
|
2
|
+
export declare class DateType extends AbstractType<Date, Date | string> {
|
|
3
|
+
protected filter(value: unknown): Date;
|
|
4
|
+
toString(): string;
|
|
5
|
+
protected hasSameValue(other: this): boolean;
|
|
6
|
+
}
|
|
7
|
+
declare const CreatedAt_base: import("./required/required-type.js").RequiredType<typeof DateType>;
|
|
8
|
+
export declare class CreatedAt extends CreatedAt_base {
|
|
9
|
+
static now(clock?: {
|
|
10
|
+
now(): Date;
|
|
11
|
+
}): CreatedAt;
|
|
12
|
+
}
|
|
13
|
+
declare const UpdatedAt_base: import("./required/required-type.js").RequiredType<typeof DateType>;
|
|
14
|
+
export declare class UpdatedAt extends UpdatedAt_base {
|
|
15
|
+
static now(clock?: {
|
|
16
|
+
now(): Date;
|
|
17
|
+
}): UpdatedAt;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { toDate } from '@archi-code/validation';
|
|
2
|
+
import { AbstractType } from './abstract-type.js';
|
|
3
|
+
import { Required } from './required/required-type.js';
|
|
4
|
+
import { TypePrimitiveException } from '../exceptions/type-primitive.exception.js';
|
|
5
|
+
class ImmutableDate extends Date {
|
|
6
|
+
constructor(date) {
|
|
7
|
+
super(date.getTime());
|
|
8
|
+
Object.freeze(this);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
ImmutableDate.setters = [
|
|
12
|
+
'setDate',
|
|
13
|
+
'setFullYear',
|
|
14
|
+
'setHours',
|
|
15
|
+
'setMilliseconds',
|
|
16
|
+
'setMinutes',
|
|
17
|
+
'setMonth',
|
|
18
|
+
'setSeconds',
|
|
19
|
+
'setTime',
|
|
20
|
+
'setUTCDate',
|
|
21
|
+
'setUTCFullYear',
|
|
22
|
+
'setUTCHours',
|
|
23
|
+
'setUTCMilliseconds',
|
|
24
|
+
'setUTCMinutes',
|
|
25
|
+
'setUTCMonth',
|
|
26
|
+
'setUTCSeconds',
|
|
27
|
+
'setYear',
|
|
28
|
+
];
|
|
29
|
+
(() => {
|
|
30
|
+
for (const setter of ImmutableDate.setters) {
|
|
31
|
+
Object.defineProperty(ImmutableDate.prototype, setter, {
|
|
32
|
+
value() {
|
|
33
|
+
throw new TypeError(`Cannot call ${setter}: the date is immutable`);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
})();
|
|
38
|
+
const TIME_WITHOUT_ZONE = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?$/;
|
|
39
|
+
export class DateType extends AbstractType {
|
|
40
|
+
filter(value) {
|
|
41
|
+
const converted = toDate(value, { iso: true });
|
|
42
|
+
if (!converted.ok || (typeof value === 'string' && TIME_WITHOUT_ZONE.test(value))) {
|
|
43
|
+
throw new TypePrimitiveException('Date', value);
|
|
44
|
+
}
|
|
45
|
+
return new ImmutableDate(converted.value);
|
|
46
|
+
}
|
|
47
|
+
toString() {
|
|
48
|
+
return this._value === null ? '' : this._value.toISOString();
|
|
49
|
+
}
|
|
50
|
+
hasSameValue(other) {
|
|
51
|
+
return this._value?.getTime() === other._value?.getTime();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const SYSTEM_TIME = { now: () => new Date() };
|
|
55
|
+
export class CreatedAt extends Required(DateType) {
|
|
56
|
+
static now(clock = SYSTEM_TIME) {
|
|
57
|
+
return new CreatedAt(clock.now());
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export class UpdatedAt extends Required(DateType) {
|
|
61
|
+
static now(clock = SYSTEM_TIME) {
|
|
62
|
+
return new UpdatedAt(clock.now());
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AbstractType } from './abstract-type.js';
|
|
2
|
+
export declare abstract class EnumType<T extends string | number> extends AbstractType<T> {
|
|
3
|
+
protected abstract getEnum(): Record<string, string | number>;
|
|
4
|
+
protected filter(value: unknown): T;
|
|
5
|
+
private static matches;
|
|
6
|
+
private options;
|
|
7
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AbstractType } from './abstract-type.js';
|
|
2
|
+
import { TypePrimitiveException } from '../exceptions/type-primitive.exception.js';
|
|
3
|
+
const NUMERIC_TEXT = /^-?\d+(?:\.\d+)?$/;
|
|
4
|
+
export class EnumType extends AbstractType {
|
|
5
|
+
filter(value) {
|
|
6
|
+
const options = this.options();
|
|
7
|
+
const option = options.find((candidate) => EnumType.matches(candidate, value));
|
|
8
|
+
if (option === undefined) {
|
|
9
|
+
throw new TypePrimitiveException(`Expected one of [${options.join(', ')}]`, value, '');
|
|
10
|
+
}
|
|
11
|
+
return option;
|
|
12
|
+
}
|
|
13
|
+
static matches(option, value) {
|
|
14
|
+
return (option === value ||
|
|
15
|
+
(typeof option === 'number' &&
|
|
16
|
+
typeof value === 'string' &&
|
|
17
|
+
NUMERIC_TEXT.test(value) &&
|
|
18
|
+
Number(value) === option));
|
|
19
|
+
}
|
|
20
|
+
options() {
|
|
21
|
+
const enumObject = this.getEnum();
|
|
22
|
+
return Object.entries(enumObject)
|
|
23
|
+
.filter(([, option]) => typeof enumObject[option] !== 'number')
|
|
24
|
+
.map(([, option]) => option);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UuidType } from './uuid-type.js';
|
|
2
|
+
declare const IdType_base: import("./required/required-type.js").RequiredType<typeof UuidType>;
|
|
3
|
+
export declare class IdType<Brand extends string = string> extends IdType_base {
|
|
4
|
+
protected readonly idBrand: Brand;
|
|
5
|
+
protected filter(value: unknown): string;
|
|
6
|
+
}
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Required } from './required/required-type.js';
|
|
2
|
+
import { UuidType } from './uuid-type.js';
|
|
3
|
+
import { TypePrimitiveException } from '../exceptions/type-primitive.exception.js';
|
|
4
|
+
const NIL_OR_MAX_UUID = /^(?:0{8}-0{4}-0{4}-0{4}-0{12}|f{8}-f{4}-f{4}-f{4}-f{12})$/i;
|
|
5
|
+
export class IdType extends Required(UuidType) {
|
|
6
|
+
filter(value) {
|
|
7
|
+
const id = super.filter(value);
|
|
8
|
+
if (NIL_OR_MAX_UUID.test(id)) {
|
|
9
|
+
throw new TypePrimitiveException('Id', value);
|
|
10
|
+
}
|
|
11
|
+
return id;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { AbstractType } from './abstract-type.js';
|
|
2
|
+
export { Required } from './required/required-type.js';
|
|
3
|
+
export type { RequiredType } from './required/required-type.js';
|
|
4
|
+
export { ArrayType } from './array-type.js';
|
|
5
|
+
export { BooleanType } from './boolean-type.js';
|
|
6
|
+
export { CreatedAt, DateType, UpdatedAt } from './date-type.js';
|
|
7
|
+
export { EnumType } from './enum-type.js';
|
|
8
|
+
export { JsonType } from './json-type.js';
|
|
9
|
+
export type { JsonTypeValue } from './json-type.js';
|
|
10
|
+
export { NumberType } from './number-type.js';
|
|
11
|
+
export { StringType } from './string-type.js';
|
|
12
|
+
export { IdType } from './id-type.js';
|
|
13
|
+
export { UuidType } from './uuid-type.js';
|
|
14
|
+
export { Composite } from './composite/composite.js';
|
|
15
|
+
export type { CompositeInput, CompositePrimitives, CompositeProps, CompositeSchema, CompositeType, CompositeValue, } from './composite/composite.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { AbstractType } from './abstract-type.js';
|
|
2
|
+
export { Required } from './required/required-type.js';
|
|
3
|
+
export { ArrayType } from './array-type.js';
|
|
4
|
+
export { BooleanType } from './boolean-type.js';
|
|
5
|
+
export { CreatedAt, DateType, UpdatedAt } from './date-type.js';
|
|
6
|
+
export { EnumType } from './enum-type.js';
|
|
7
|
+
export { JsonType } from './json-type.js';
|
|
8
|
+
export { NumberType } from './number-type.js';
|
|
9
|
+
export { StringType } from './string-type.js';
|
|
10
|
+
export { IdType } from './id-type.js';
|
|
11
|
+
export { UuidType } from './uuid-type.js';
|
|
12
|
+
export { Composite } from './composite/composite.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AbstractType } from './abstract-type.js';
|
|
2
|
+
export type JsonTypeValue = Record<string, any>;
|
|
3
|
+
export declare class JsonType<T extends JsonTypeValue = JsonTypeValue> extends AbstractType<T> {
|
|
4
|
+
protected filter(value: unknown): T;
|
|
5
|
+
protected hasSameValue(other: this): boolean;
|
|
6
|
+
private static sameJson;
|
|
7
|
+
private static deepFreeze;
|
|
8
|
+
private static isObject;
|
|
9
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { toJson } from '@archi-code/validation';
|
|
2
|
+
import { AbstractType } from './abstract-type.js';
|
|
3
|
+
import { TypePrimitiveException } from '../exceptions/type-primitive.exception.js';
|
|
4
|
+
export class JsonType extends AbstractType {
|
|
5
|
+
filter(value) {
|
|
6
|
+
const converted = toJson(value);
|
|
7
|
+
if (!converted.ok) {
|
|
8
|
+
throw new TypePrimitiveException('Json', value);
|
|
9
|
+
}
|
|
10
|
+
return JsonType.deepFreeze(JSON.parse(JSON.stringify(converted.value)));
|
|
11
|
+
}
|
|
12
|
+
hasSameValue(other) {
|
|
13
|
+
return JsonType.sameJson(this._value, other._value);
|
|
14
|
+
}
|
|
15
|
+
static sameJson(left, right) {
|
|
16
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
17
|
+
return (Array.isArray(left) &&
|
|
18
|
+
Array.isArray(right) &&
|
|
19
|
+
left.length === right.length &&
|
|
20
|
+
left.every((item, index) => JsonType.sameJson(item, right[index])));
|
|
21
|
+
}
|
|
22
|
+
if (JsonType.isObject(left) && JsonType.isObject(right)) {
|
|
23
|
+
const keys = Object.keys(left);
|
|
24
|
+
return (keys.length === Object.keys(right).length &&
|
|
25
|
+
keys.every((key) => Object.prototype.hasOwnProperty.call(right, key) &&
|
|
26
|
+
JsonType.sameJson(left[key], right[key])));
|
|
27
|
+
}
|
|
28
|
+
return left === right;
|
|
29
|
+
}
|
|
30
|
+
static deepFreeze(value) {
|
|
31
|
+
if (JsonType.isObject(value)) {
|
|
32
|
+
Object.freeze(value);
|
|
33
|
+
for (const child of Object.values(value)) {
|
|
34
|
+
JsonType.deepFreeze(child);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
static isObject(value) {
|
|
40
|
+
return typeof value === 'object' && value !== null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { toFloat } from '@archi-code/validation';
|
|
2
|
+
import { AbstractType } from './abstract-type.js';
|
|
3
|
+
import { TypePrimitiveException } from '../exceptions/type-primitive.exception.js';
|
|
4
|
+
export class NumberType extends AbstractType {
|
|
5
|
+
filter(value) {
|
|
6
|
+
const converted = toFloat(value);
|
|
7
|
+
if (!converted.ok) {
|
|
8
|
+
throw new TypePrimitiveException('Number', value);
|
|
9
|
+
}
|
|
10
|
+
return converted.value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export class RequiredMark {
|
|
2
|
+
static isMarked(instance) {
|
|
3
|
+
return instance[RequiredMark.symbol] === true;
|
|
4
|
+
}
|
|
5
|
+
static mark(prototype) {
|
|
6
|
+
Object.defineProperty(prototype, RequiredMark.symbol, { value: true });
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
RequiredMark.symbol = Symbol.for('@archi-code/ddd/required.v1');
|