@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,17 @@
|
|
|
1
|
+
import type { ValidationResult } from '@archi-code/validation';
|
|
2
|
+
import { AbstractType } from './abstract-type';
|
|
3
|
+
import type { ValueOf } from './abstract-type';
|
|
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,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrayType = void 0;
|
|
4
|
+
const validation_1 = require("@archi-code/validation");
|
|
5
|
+
const abstract_type_1 = require("./abstract-type");
|
|
6
|
+
const type_primitive_exception_1 = require("../exceptions/type-primitive.exception");
|
|
7
|
+
class ArrayType extends abstract_type_1.AbstractType {
|
|
8
|
+
get items() {
|
|
9
|
+
return (this._value ?? []).map((value) => this.createItem(value));
|
|
10
|
+
}
|
|
11
|
+
toString() {
|
|
12
|
+
return this.items.map((item) => item.toString()).join(', ');
|
|
13
|
+
}
|
|
14
|
+
hasItem(value) {
|
|
15
|
+
const item = this.createItem(value);
|
|
16
|
+
return (this._value ?? []).some((current) => this.createItem(current).equals(item));
|
|
17
|
+
}
|
|
18
|
+
withItem(value) {
|
|
19
|
+
return this.copyWith([...(this._value ?? []), value]);
|
|
20
|
+
}
|
|
21
|
+
withoutItem(value) {
|
|
22
|
+
if (this._value === null) {
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
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]))));
|
|
35
|
+
}
|
|
36
|
+
filter(value) {
|
|
37
|
+
const converted = (0, validation_1.toArray)(value);
|
|
38
|
+
if (!converted.ok) {
|
|
39
|
+
throw new type_primitive_exception_1.TypePrimitiveException('Array', value);
|
|
40
|
+
}
|
|
41
|
+
const items = converted.value.map((item) => this.createItem(item).value);
|
|
42
|
+
Object.freeze(items);
|
|
43
|
+
return items;
|
|
44
|
+
}
|
|
45
|
+
validate() {
|
|
46
|
+
const own = super.validate();
|
|
47
|
+
const itemErrors = (this._value ?? []).flatMap((itemValue, index) => this.createItem(itemValue)
|
|
48
|
+
.validate()
|
|
49
|
+
.errors.map((error) => Object.freeze({ ...error, message: `Item ${index + 1}: ${error.message}` })));
|
|
50
|
+
if (itemErrors.length === 0) {
|
|
51
|
+
return own;
|
|
52
|
+
}
|
|
53
|
+
return Object.freeze({
|
|
54
|
+
ok: false,
|
|
55
|
+
value: own.value,
|
|
56
|
+
errors: Object.freeze([...own.errors, ...itemErrors]),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
copyWith(values) {
|
|
60
|
+
const SameType = this.constructor;
|
|
61
|
+
return new SameType(values);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.ArrayType = ArrayType;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BooleanType = void 0;
|
|
4
|
+
const validation_1 = require("@archi-code/validation");
|
|
5
|
+
const abstract_type_1 = require("./abstract-type");
|
|
6
|
+
const type_primitive_exception_1 = require("../exceptions/type-primitive.exception");
|
|
7
|
+
class BooleanType extends abstract_type_1.AbstractType {
|
|
8
|
+
filter(value) {
|
|
9
|
+
const converted = (0, validation_1.toBoolean)(value);
|
|
10
|
+
if (!converted.ok) {
|
|
11
|
+
throw new type_primitive_exception_1.TypePrimitiveException('Boolean', value);
|
|
12
|
+
}
|
|
13
|
+
return converted.value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.BooleanType = BooleanType;
|
|
@@ -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;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AbstractType } from '../abstract-type';
|
|
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,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CompositeField = void 0;
|
|
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");
|
|
8
|
+
class CompositeField {
|
|
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);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CompositeField = CompositeField;
|
|
20
|
+
class SingleField extends CompositeField {
|
|
21
|
+
constructor(fieldClass) {
|
|
22
|
+
super();
|
|
23
|
+
this.fieldClass = fieldClass;
|
|
24
|
+
}
|
|
25
|
+
get typeName() {
|
|
26
|
+
return this.fieldClass.name;
|
|
27
|
+
}
|
|
28
|
+
accept(path, value) {
|
|
29
|
+
if (value === null || value === undefined) {
|
|
30
|
+
throw new required_value_exception_1.RequiredValueException(path, value);
|
|
31
|
+
}
|
|
32
|
+
if (!(value instanceof this.fieldClass)) {
|
|
33
|
+
throw new type_primitive_exception_1.TypePrimitiveException(`${this.typeName} for ${path}`, value);
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
equals(left, right) {
|
|
38
|
+
return left.equals(right);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class ValueField extends SingleField {
|
|
42
|
+
fromPrimitive(primitive) {
|
|
43
|
+
return new this.fieldClass(primitive);
|
|
44
|
+
}
|
|
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);
|
|
68
|
+
}
|
|
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);
|
|
74
|
+
}
|
|
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])));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -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;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FieldSpec } from './composite-field';
|
|
2
|
+
import type { PrimitiveType } from '../../primitive/primitive-types';
|
|
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,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Composite = Composite;
|
|
4
|
+
const validation_1 = require("@archi-code/validation");
|
|
5
|
+
const composite_brand_1 = require("./composite-brand");
|
|
6
|
+
const composite_field_1 = require("./composite-field");
|
|
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");
|
|
10
|
+
function Composite(schema) {
|
|
11
|
+
const fields = Object.entries(schema).map(([name, spec]) => [name, composite_field_1.CompositeField.of(spec)]);
|
|
12
|
+
class CompositeValueObject {
|
|
13
|
+
static fromPrimitives(primitives) {
|
|
14
|
+
if (typeof primitives !== 'object' || primitives === null || Array.isArray(primitives)) {
|
|
15
|
+
throw new type_primitive_exception_1.TypePrimitiveException(this.name, primitives);
|
|
16
|
+
}
|
|
17
|
+
const record = primitives;
|
|
18
|
+
const builds = Object.fromEntries(fields.map(([name, field]) => [name, () => field.fromPrimitive(record[name])]));
|
|
19
|
+
return new this(composite_issues_1.CompositeIssues.collectFields(builds));
|
|
20
|
+
}
|
|
21
|
+
constructor(props) {
|
|
22
|
+
const owner = this.constructor.name;
|
|
23
|
+
for (const [name, field] of fields) {
|
|
24
|
+
Object.defineProperty(this, name, {
|
|
25
|
+
value: field.accept(`${owner}.${name}`, props?.[name]),
|
|
26
|
+
enumerable: true,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const brokenRules = (0, validation_1.runValidations)(this.constructor, this).errors;
|
|
30
|
+
if (brokenRules.length > 0) {
|
|
31
|
+
throw new validation_exception_1.ValidationException(brokenRules.map((error) => ({
|
|
32
|
+
field: null,
|
|
33
|
+
code: 'custom' in error ? error.custom : error.validator,
|
|
34
|
+
message: `${owner}: ${error.message}`,
|
|
35
|
+
})));
|
|
36
|
+
}
|
|
37
|
+
Object.freeze(this);
|
|
38
|
+
}
|
|
39
|
+
equals(other) {
|
|
40
|
+
return (typeof other === 'object' &&
|
|
41
|
+
other !== null &&
|
|
42
|
+
other.constructor === this.constructor &&
|
|
43
|
+
fields.every(([name, field]) => field.equals(this[name], other[name])));
|
|
44
|
+
}
|
|
45
|
+
toPrimitives() {
|
|
46
|
+
return Object.fromEntries(fields.map(([name, field]) => [name, field.toPrimitive(this[name])]));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
composite_brand_1.CompositeBrand.mark(CompositeValueObject.prototype);
|
|
50
|
+
return CompositeValueObject;
|
|
51
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AbstractType } from './abstract-type';
|
|
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").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").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,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpdatedAt = exports.CreatedAt = exports.DateType = void 0;
|
|
4
|
+
const validation_1 = require("@archi-code/validation");
|
|
5
|
+
const abstract_type_1 = require("./abstract-type");
|
|
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
|
+
})();
|
|
41
|
+
const TIME_WITHOUT_ZONE = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?$/;
|
|
42
|
+
class DateType extends abstract_type_1.AbstractType {
|
|
43
|
+
filter(value) {
|
|
44
|
+
const converted = (0, validation_1.toDate)(value, { iso: true });
|
|
45
|
+
if (!converted.ok || (typeof value === 'string' && TIME_WITHOUT_ZONE.test(value))) {
|
|
46
|
+
throw new type_primitive_exception_1.TypePrimitiveException('Date', value);
|
|
47
|
+
}
|
|
48
|
+
return new ImmutableDate(converted.value);
|
|
49
|
+
}
|
|
50
|
+
toString() {
|
|
51
|
+
return this._value === null ? '' : this._value.toISOString();
|
|
52
|
+
}
|
|
53
|
+
hasSameValue(other) {
|
|
54
|
+
return this._value?.getTime() === other._value?.getTime();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.DateType = DateType;
|
|
58
|
+
const SYSTEM_TIME = { now: () => new Date() };
|
|
59
|
+
class CreatedAt extends (0, required_type_1.Required)(DateType) {
|
|
60
|
+
static now(clock = SYSTEM_TIME) {
|
|
61
|
+
return new CreatedAt(clock.now());
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.CreatedAt = CreatedAt;
|
|
65
|
+
class UpdatedAt extends (0, required_type_1.Required)(DateType) {
|
|
66
|
+
static now(clock = SYSTEM_TIME) {
|
|
67
|
+
return new UpdatedAt(clock.now());
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.UpdatedAt = UpdatedAt;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AbstractType } from './abstract-type';
|
|
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,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnumType = void 0;
|
|
4
|
+
const abstract_type_1 = require("./abstract-type");
|
|
5
|
+
const type_primitive_exception_1 = require("../exceptions/type-primitive.exception");
|
|
6
|
+
const NUMERIC_TEXT = /^-?\d+(?:\.\d+)?$/;
|
|
7
|
+
class EnumType extends abstract_type_1.AbstractType {
|
|
8
|
+
filter(value) {
|
|
9
|
+
const options = this.options();
|
|
10
|
+
const option = options.find((candidate) => EnumType.matches(candidate, value));
|
|
11
|
+
if (option === undefined) {
|
|
12
|
+
throw new type_primitive_exception_1.TypePrimitiveException(`Expected one of [${options.join(', ')}]`, value, '');
|
|
13
|
+
}
|
|
14
|
+
return option;
|
|
15
|
+
}
|
|
16
|
+
static matches(option, value) {
|
|
17
|
+
return (option === value ||
|
|
18
|
+
(typeof option === 'number' &&
|
|
19
|
+
typeof value === 'string' &&
|
|
20
|
+
NUMERIC_TEXT.test(value) &&
|
|
21
|
+
Number(value) === option));
|
|
22
|
+
}
|
|
23
|
+
options() {
|
|
24
|
+
const enumObject = this.getEnum();
|
|
25
|
+
return Object.entries(enumObject)
|
|
26
|
+
.filter(([, option]) => typeof enumObject[option] !== 'number')
|
|
27
|
+
.map(([, option]) => option);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.EnumType = EnumType;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UuidType } from './uuid-type';
|
|
2
|
+
declare const IdType_base: import("./required/required-type").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,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IdType = void 0;
|
|
4
|
+
const required_type_1 = require("./required/required-type");
|
|
5
|
+
const uuid_type_1 = require("./uuid-type");
|
|
6
|
+
const type_primitive_exception_1 = require("../exceptions/type-primitive.exception");
|
|
7
|
+
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;
|
|
8
|
+
class IdType extends (0, required_type_1.Required)(uuid_type_1.UuidType) {
|
|
9
|
+
filter(value) {
|
|
10
|
+
const id = super.filter(value);
|
|
11
|
+
if (NIL_OR_MAX_UUID.test(id)) {
|
|
12
|
+
throw new type_primitive_exception_1.TypePrimitiveException('Id', value);
|
|
13
|
+
}
|
|
14
|
+
return id;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.IdType = IdType;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { AbstractType } from './abstract-type';
|
|
2
|
+
export { Required } from './required/required-type';
|
|
3
|
+
export type { RequiredType } from './required/required-type';
|
|
4
|
+
export { ArrayType } from './array-type';
|
|
5
|
+
export { BooleanType } from './boolean-type';
|
|
6
|
+
export { CreatedAt, DateType, UpdatedAt } from './date-type';
|
|
7
|
+
export { EnumType } from './enum-type';
|
|
8
|
+
export { JsonType } from './json-type';
|
|
9
|
+
export type { JsonTypeValue } from './json-type';
|
|
10
|
+
export { NumberType } from './number-type';
|
|
11
|
+
export { StringType } from './string-type';
|
|
12
|
+
export { IdType } from './id-type';
|
|
13
|
+
export { UuidType } from './uuid-type';
|
|
14
|
+
export { Composite } from './composite/composite';
|
|
15
|
+
export type { CompositeInput, CompositePrimitives, CompositeProps, CompositeSchema, CompositeType, CompositeValue, } from './composite/composite';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Composite = exports.UuidType = exports.IdType = exports.StringType = exports.NumberType = exports.JsonType = exports.EnumType = exports.UpdatedAt = exports.DateType = exports.CreatedAt = exports.BooleanType = exports.ArrayType = exports.Required = exports.AbstractType = void 0;
|
|
4
|
+
var abstract_type_1 = require("./abstract-type");
|
|
5
|
+
Object.defineProperty(exports, "AbstractType", { enumerable: true, get: function () { return abstract_type_1.AbstractType; } });
|
|
6
|
+
var required_type_1 = require("./required/required-type");
|
|
7
|
+
Object.defineProperty(exports, "Required", { enumerable: true, get: function () { return required_type_1.Required; } });
|
|
8
|
+
var array_type_1 = require("./array-type");
|
|
9
|
+
Object.defineProperty(exports, "ArrayType", { enumerable: true, get: function () { return array_type_1.ArrayType; } });
|
|
10
|
+
var boolean_type_1 = require("./boolean-type");
|
|
11
|
+
Object.defineProperty(exports, "BooleanType", { enumerable: true, get: function () { return boolean_type_1.BooleanType; } });
|
|
12
|
+
var date_type_1 = require("./date-type");
|
|
13
|
+
Object.defineProperty(exports, "CreatedAt", { enumerable: true, get: function () { return date_type_1.CreatedAt; } });
|
|
14
|
+
Object.defineProperty(exports, "DateType", { enumerable: true, get: function () { return date_type_1.DateType; } });
|
|
15
|
+
Object.defineProperty(exports, "UpdatedAt", { enumerable: true, get: function () { return date_type_1.UpdatedAt; } });
|
|
16
|
+
var enum_type_1 = require("./enum-type");
|
|
17
|
+
Object.defineProperty(exports, "EnumType", { enumerable: true, get: function () { return enum_type_1.EnumType; } });
|
|
18
|
+
var json_type_1 = require("./json-type");
|
|
19
|
+
Object.defineProperty(exports, "JsonType", { enumerable: true, get: function () { return json_type_1.JsonType; } });
|
|
20
|
+
var number_type_1 = require("./number-type");
|
|
21
|
+
Object.defineProperty(exports, "NumberType", { enumerable: true, get: function () { return number_type_1.NumberType; } });
|
|
22
|
+
var string_type_1 = require("./string-type");
|
|
23
|
+
Object.defineProperty(exports, "StringType", { enumerable: true, get: function () { return string_type_1.StringType; } });
|
|
24
|
+
var id_type_1 = require("./id-type");
|
|
25
|
+
Object.defineProperty(exports, "IdType", { enumerable: true, get: function () { return id_type_1.IdType; } });
|
|
26
|
+
var uuid_type_1 = require("./uuid-type");
|
|
27
|
+
Object.defineProperty(exports, "UuidType", { enumerable: true, get: function () { return uuid_type_1.UuidType; } });
|
|
28
|
+
var composite_1 = require("./composite/composite");
|
|
29
|
+
Object.defineProperty(exports, "Composite", { enumerable: true, get: function () { return composite_1.Composite; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AbstractType } from './abstract-type';
|
|
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,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonType = void 0;
|
|
4
|
+
const validation_1 = require("@archi-code/validation");
|
|
5
|
+
const abstract_type_1 = require("./abstract-type");
|
|
6
|
+
const type_primitive_exception_1 = require("../exceptions/type-primitive.exception");
|
|
7
|
+
class JsonType extends abstract_type_1.AbstractType {
|
|
8
|
+
filter(value) {
|
|
9
|
+
const converted = (0, validation_1.toJson)(value);
|
|
10
|
+
if (!converted.ok) {
|
|
11
|
+
throw new type_primitive_exception_1.TypePrimitiveException('Json', value);
|
|
12
|
+
}
|
|
13
|
+
return JsonType.deepFreeze(JSON.parse(JSON.stringify(converted.value)));
|
|
14
|
+
}
|
|
15
|
+
hasSameValue(other) {
|
|
16
|
+
return JsonType.sameJson(this._value, other._value);
|
|
17
|
+
}
|
|
18
|
+
static sameJson(left, right) {
|
|
19
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
20
|
+
return (Array.isArray(left) &&
|
|
21
|
+
Array.isArray(right) &&
|
|
22
|
+
left.length === right.length &&
|
|
23
|
+
left.every((item, index) => JsonType.sameJson(item, right[index])));
|
|
24
|
+
}
|
|
25
|
+
if (JsonType.isObject(left) && JsonType.isObject(right)) {
|
|
26
|
+
const keys = Object.keys(left);
|
|
27
|
+
return (keys.length === Object.keys(right).length &&
|
|
28
|
+
keys.every((key) => Object.prototype.hasOwnProperty.call(right, key) &&
|
|
29
|
+
JsonType.sameJson(left[key], right[key])));
|
|
30
|
+
}
|
|
31
|
+
return left === right;
|
|
32
|
+
}
|
|
33
|
+
static deepFreeze(value) {
|
|
34
|
+
if (JsonType.isObject(value)) {
|
|
35
|
+
Object.freeze(value);
|
|
36
|
+
for (const child of Object.values(value)) {
|
|
37
|
+
JsonType.deepFreeze(child);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
static isObject(value) {
|
|
43
|
+
return typeof value === 'object' && value !== null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.JsonType = JsonType;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumberType = void 0;
|
|
4
|
+
const validation_1 = require("@archi-code/validation");
|
|
5
|
+
const abstract_type_1 = require("./abstract-type");
|
|
6
|
+
const type_primitive_exception_1 = require("../exceptions/type-primitive.exception");
|
|
7
|
+
class NumberType extends abstract_type_1.AbstractType {
|
|
8
|
+
filter(value) {
|
|
9
|
+
const converted = (0, validation_1.toFloat)(value);
|
|
10
|
+
if (!converted.ok) {
|
|
11
|
+
throw new type_primitive_exception_1.TypePrimitiveException('Number', value);
|
|
12
|
+
}
|
|
13
|
+
return converted.value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.NumberType = NumberType;
|