@archi-code/ddd 0.0.0-stage → 3.0.0-alpha.1
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 +2693 -2
- package/SKILL.md +104 -0
- package/ddd-skills/archi-code-ddd/imports.md +84 -0
- package/ddd-skills/archi-code-ddd/layers.md +299 -0
- package/ddd-skills/archi-code-ddd/patterns.md +676 -0
- package/ddd-skills/archi-code-ddd/what-not-to-do.md +189 -0
- package/ddd-skills/archi-code-ddd/where-each-class-goes.md +63 -0
- package/ddd-skills/ddd-agregados/GUIA.md +114 -0
- package/ddd-skills/ddd-agregados/references/consistencia-eventual.md +159 -0
- package/ddd-skills/ddd-agregados/references/ejemplo-ecommerce.md +52 -0
- package/ddd-skills/ddd-agregados/references/fabricas.md +196 -0
- package/ddd-skills/ddd-agregados/references/implementacion-ts.md +711 -0
- package/ddd-skills/ddd-arquitectura/GUIA.md +80 -0
- package/ddd-skills/ddd-arquitectura/assets/dependency-cruiser.cjs +92 -0
- package/ddd-skills/ddd-arquitectura/references/estilos-adicionales.md +51 -0
- package/ddd-skills/ddd-arquitectura/references/estructura-hexagonal-ts.md +352 -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 +316 -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 +404 -0
- package/ddd-skills/ddd-context-mapping/references/estilos-integracion.md +155 -0
- package/ddd-skills/ddd-event-sourcing-cqrs/GUIA.md +92 -0
- package/ddd-skills/ddd-event-sourcing-cqrs/references/event-sourcing-ts.md +471 -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 +131 -0
- package/ddd-skills/ddd-eventos-dominio/references/ejemplo-ecommerce.md +240 -0
- package/ddd-skills/ddd-eventos-dominio/references/publicacion-ts.md +526 -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 +296 -0
- package/ddd-skills/ddd-repositorios-persistencia/references/tests-repositorios.md +177 -0
- package/ddd-skills/ddd-repositorios-persistencia/references/transacciones-ts.md +294 -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 +324 -0
- package/ddd-skills/ddd-servicios-capa-aplicacion/references/servicios-dominio-ts.md +191 -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 +220 -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 +377 -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/index.d.ts +7 -0
- package/dist/cjs/application/index.js +9 -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 +24 -0
- package/dist/cjs/domain/aggregate/aggregate-root.d.ts +14 -0
- package/dist/cjs/domain/aggregate/aggregate-root.js +33 -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 +29 -0
- package/dist/cjs/domain/event/event-base.js +51 -0
- package/dist/cjs/domain/index.d.ts +10 -0
- package/dist/cjs/domain/index.js +24 -0
- package/dist/cjs/domain/primitive/primitive-types.d.ts +22 -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 +20 -0
- package/dist/cjs/domain/type/abstract-type.js +69 -0
- package/dist/cjs/domain/type/array-type.d.ts +16 -0
- package/dist/cjs/domain/type/array-type.js +65 -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-field.d.ts +19 -0
- package/dist/cjs/domain/type/composite/composite-field.js +63 -0
- package/dist/cjs/domain/type/composite/composite.d.ts +26 -0
- package/dist/cjs/domain/type/composite/composite.js +55 -0
- package/dist/cjs/domain/type/date-type.d.ts +18 -0
- package/dist/cjs/domain/type/date-type.js +35 -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/equality/value-equality.d.ts +7 -0
- package/dist/cjs/domain/type/equality/value-equality.js +41 -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/immutable/immutable-date.d.ts +4 -0
- package/dist/cjs/domain/type/immutable/immutable-date.js +37 -0
- package/dist/cjs/domain/type/immutable/immutable.d.ts +4 -0
- package/dist/cjs/domain/type/immutable/immutable.js +19 -0
- package/dist/cjs/domain/type/index.d.ts +17 -0
- package/dist/cjs/domain/type/index.js +33 -0
- package/dist/cjs/domain/type/json-type.d.ts +5 -0
- package/dist/cjs/domain/type/json-type.js +17 -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 +9 -0
- package/dist/cjs/domain/type/required/required-mark.js +13 -0
- package/dist/cjs/domain/type/required/required.d.ts +7 -0
- package/dist/cjs/domain/type/required/required.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/domain/type/value-objects/value-objects.d.ts +16 -0
- package/dist/cjs/domain/type/value-objects/value-objects.js +70 -0
- package/dist/cjs/exceptions/abstract.exception.d.ts +23 -0
- package/dist/cjs/exceptions/abstract.exception.js +66 -0
- package/dist/cjs/exceptions/application/aggregate-not-found.exception.d.ts +5 -0
- package/dist/cjs/exceptions/application/aggregate-not-found.exception.js +17 -0
- package/dist/cjs/exceptions/application/application.exception.d.ts +6 -0
- package/dist/cjs/exceptions/application/application.exception.js +17 -0
- package/dist/cjs/exceptions/application/concurrency.exception.d.ts +5 -0
- package/dist/cjs/exceptions/application/concurrency.exception.js +17 -0
- package/dist/cjs/exceptions/application/not-allowed.exception.d.ts +5 -0
- package/dist/cjs/exceptions/application/not-allowed.exception.js +17 -0
- package/dist/cjs/exceptions/brand/exception-brand.d.ts +6 -0
- package/dist/cjs/exceptions/brand/exception-brand.js +29 -0
- package/dist/cjs/exceptions/domain/domain.exception.d.ts +6 -0
- package/dist/cjs/exceptions/domain/domain.exception.js +17 -0
- package/dist/cjs/exceptions/domain/required-value.exception.d.ts +4 -0
- package/dist/cjs/exceptions/domain/required-value.exception.js +21 -0
- package/dist/cjs/exceptions/domain/type-primitive.exception.d.ts +4 -0
- package/dist/cjs/exceptions/domain/type-primitive.exception.js +21 -0
- package/dist/cjs/exceptions/domain/validation.exception.d.ts +14 -0
- package/dist/cjs/exceptions/domain/validation.exception.js +23 -0
- package/dist/cjs/exceptions/exception-code.d.ts +15 -0
- package/dist/cjs/exceptions/exception-code.js +19 -0
- package/dist/cjs/exceptions/index.d.ts +14 -0
- package/dist/cjs/exceptions/index.js +30 -0
- package/dist/cjs/exceptions/infrastructure/event-delivery.exception.d.ts +5 -0
- package/dist/cjs/exceptions/infrastructure/event-delivery.exception.js +20 -0
- package/dist/cjs/exceptions/infrastructure/infrastructure.exception.d.ts +6 -0
- package/dist/cjs/exceptions/infrastructure/infrastructure.exception.js +17 -0
- package/dist/cjs/exceptions/infrastructure/internal-error.exception.d.ts +5 -0
- package/dist/cjs/exceptions/infrastructure/internal-error.exception.js +17 -0
- package/dist/cjs/exceptions/infrastructure/unknown-event.exception.d.ts +4 -0
- package/dist/cjs/exceptions/infrastructure/unknown-event.exception.js +19 -0
- package/dist/cjs/exceptions/received/received-value.d.ts +4 -0
- package/dist/cjs/exceptions/received/received-value.js +13 -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 +51 -0
- package/dist/cjs/infrastructure/http/http-error-mapper.d.ts +23 -0
- package/dist/cjs/infrastructure/http/http-error-mapper.js +63 -0
- package/dist/cjs/infrastructure/index.d.ts +16 -0
- package/dist/cjs/infrastructure/index.js +21 -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/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/index.d.ts +7 -0
- package/dist/esm/application/index.js +3 -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 +20 -0
- package/dist/esm/domain/aggregate/aggregate-root.d.ts +14 -0
- package/dist/esm/domain/aggregate/aggregate-root.js +29 -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 +29 -0
- package/dist/esm/domain/event/event-base.js +47 -0
- package/dist/esm/domain/index.d.ts +10 -0
- package/dist/esm/domain/index.js +6 -0
- package/dist/esm/domain/primitive/primitive-types.d.ts +22 -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 +20 -0
- package/dist/esm/domain/type/abstract-type.js +65 -0
- package/dist/esm/domain/type/array-type.d.ts +16 -0
- package/dist/esm/domain/type/array-type.js +61 -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-field.d.ts +19 -0
- package/dist/esm/domain/type/composite/composite-field.js +59 -0
- package/dist/esm/domain/type/composite/composite.d.ts +26 -0
- package/dist/esm/domain/type/composite/composite.js +52 -0
- package/dist/esm/domain/type/date-type.d.ts +18 -0
- package/dist/esm/domain/type/date-type.js +29 -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/equality/value-equality.d.ts +7 -0
- package/dist/esm/domain/type/equality/value-equality.js +37 -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/immutable/immutable-date.d.ts +4 -0
- package/dist/esm/domain/type/immutable/immutable-date.js +33 -0
- package/dist/esm/domain/type/immutable/immutable.d.ts +4 -0
- package/dist/esm/domain/type/immutable/immutable.js +15 -0
- package/dist/esm/domain/type/index.d.ts +17 -0
- package/dist/esm/domain/type/index.js +14 -0
- package/dist/esm/domain/type/json-type.d.ts +5 -0
- package/dist/esm/domain/type/json-type.js +13 -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 +9 -0
- package/dist/esm/domain/type/required/required-mark.js +9 -0
- package/dist/esm/domain/type/required/required.d.ts +7 -0
- package/dist/esm/domain/type/required/required.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/domain/type/value-objects/value-objects.d.ts +16 -0
- package/dist/esm/domain/type/value-objects/value-objects.js +66 -0
- package/dist/esm/exceptions/abstract.exception.d.ts +23 -0
- package/dist/esm/exceptions/abstract.exception.js +62 -0
- package/dist/esm/exceptions/application/aggregate-not-found.exception.d.ts +5 -0
- package/dist/esm/exceptions/application/aggregate-not-found.exception.js +13 -0
- package/dist/esm/exceptions/application/application.exception.d.ts +6 -0
- package/dist/esm/exceptions/application/application.exception.js +13 -0
- package/dist/esm/exceptions/application/concurrency.exception.d.ts +5 -0
- package/dist/esm/exceptions/application/concurrency.exception.js +13 -0
- package/dist/esm/exceptions/application/not-allowed.exception.d.ts +5 -0
- package/dist/esm/exceptions/application/not-allowed.exception.js +13 -0
- package/dist/esm/exceptions/brand/exception-brand.d.ts +6 -0
- package/dist/esm/exceptions/brand/exception-brand.js +25 -0
- package/dist/esm/exceptions/domain/domain.exception.d.ts +6 -0
- package/dist/esm/exceptions/domain/domain.exception.js +13 -0
- package/dist/esm/exceptions/domain/required-value.exception.d.ts +4 -0
- package/dist/esm/exceptions/domain/required-value.exception.js +17 -0
- package/dist/esm/exceptions/domain/type-primitive.exception.d.ts +4 -0
- package/dist/esm/exceptions/domain/type-primitive.exception.js +17 -0
- package/dist/esm/exceptions/domain/validation.exception.d.ts +14 -0
- package/dist/esm/exceptions/domain/validation.exception.js +19 -0
- package/dist/esm/exceptions/exception-code.d.ts +15 -0
- package/dist/esm/exceptions/exception-code.js +16 -0
- package/dist/esm/exceptions/index.d.ts +14 -0
- package/dist/esm/exceptions/index.js +14 -0
- package/dist/esm/exceptions/infrastructure/event-delivery.exception.d.ts +5 -0
- package/dist/esm/exceptions/infrastructure/event-delivery.exception.js +16 -0
- package/dist/esm/exceptions/infrastructure/infrastructure.exception.d.ts +6 -0
- package/dist/esm/exceptions/infrastructure/infrastructure.exception.js +13 -0
- package/dist/esm/exceptions/infrastructure/internal-error.exception.d.ts +5 -0
- package/dist/esm/exceptions/infrastructure/internal-error.exception.js +13 -0
- package/dist/esm/exceptions/infrastructure/unknown-event.exception.d.ts +4 -0
- package/dist/esm/exceptions/infrastructure/unknown-event.exception.js +15 -0
- package/dist/esm/exceptions/received/received-value.d.ts +4 -0
- package/dist/esm/exceptions/received/received-value.js +9 -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 +47 -0
- package/dist/esm/infrastructure/http/http-error-mapper.d.ts +23 -0
- package/dist/esm/infrastructure/http/http-error-mapper.js +59 -0
- package/dist/esm/infrastructure/index.d.ts +16 -0
- package/dist/esm/infrastructure/index.js +9 -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/package.json +106 -4
|
@@ -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 index_1 = require("../../exceptions/index");
|
|
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 index_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,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValueEquality = void 0;
|
|
4
|
+
class ValueEquality {
|
|
5
|
+
static equals(left, right) {
|
|
6
|
+
if (left === right || (Number.isNaN(left) && Number.isNaN(right))) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (left instanceof Date || right instanceof Date) {
|
|
10
|
+
return ValueEquality.sameInstant(left, right);
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
13
|
+
return ValueEquality.sameItems(left, right);
|
|
14
|
+
}
|
|
15
|
+
if (ValueEquality.isRecord(left) && ValueEquality.isRecord(right)) {
|
|
16
|
+
return ValueEquality.sameEntries(left, right);
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
static sameInstant(left, right) {
|
|
21
|
+
return (left instanceof Date &&
|
|
22
|
+
right instanceof Date &&
|
|
23
|
+
ValueEquality.equals(left.getTime(), right.getTime()));
|
|
24
|
+
}
|
|
25
|
+
static sameItems(left, right) {
|
|
26
|
+
return (Array.isArray(left) &&
|
|
27
|
+
Array.isArray(right) &&
|
|
28
|
+
left.length === right.length &&
|
|
29
|
+
left.every((item, index) => ValueEquality.equals(item, right[index])));
|
|
30
|
+
}
|
|
31
|
+
static sameEntries(left, right) {
|
|
32
|
+
const keys = Object.keys(left);
|
|
33
|
+
return (keys.length === Object.keys(right).length &&
|
|
34
|
+
keys.every((key) => Object.prototype.hasOwnProperty.call(right, key) &&
|
|
35
|
+
ValueEquality.equals(left[key], right[key])));
|
|
36
|
+
}
|
|
37
|
+
static isRecord(value) {
|
|
38
|
+
return typeof value === 'object' && value !== null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.ValueEquality = ValueEquality;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UuidType } from './uuid-type';
|
|
2
|
+
declare const IdType_base: import("./required/required").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_1 = require("./required/required");
|
|
5
|
+
const uuid_type_1 = require("./uuid-type");
|
|
6
|
+
const index_1 = require("../../exceptions/index");
|
|
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_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 index_1.TypePrimitiveException('Id', value);
|
|
13
|
+
}
|
|
14
|
+
return id;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.IdType = IdType;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImmutableDate = void 0;
|
|
4
|
+
class ImmutableDate extends Date {
|
|
5
|
+
constructor(date) {
|
|
6
|
+
super(date.getTime());
|
|
7
|
+
Object.freeze(this);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ImmutableDate = ImmutableDate;
|
|
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
|
+
})();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Immutable = void 0;
|
|
4
|
+
const immutable_date_1 = require("./immutable-date");
|
|
5
|
+
class Immutable {
|
|
6
|
+
static freeze(value) {
|
|
7
|
+
if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
8
|
+
Object.freeze(value);
|
|
9
|
+
for (const child of Object.values(value)) {
|
|
10
|
+
Immutable.freeze(child);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
static date(date) {
|
|
16
|
+
return new immutable_date_1.ImmutableDate(date);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.Immutable = Immutable;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { AbstractType } from './abstract-type';
|
|
2
|
+
export { Required } from './required/required';
|
|
3
|
+
export type { RequiredType } from './required/required';
|
|
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 { Immutable } from './immutable/immutable';
|
|
15
|
+
export { ValueObjects } from './value-objects/value-objects';
|
|
16
|
+
export { Composite } from './composite/composite';
|
|
17
|
+
export type { CompositeInput, CompositePrimitives, CompositeProps, CompositeSchema, CompositeType, CompositeValue, } from './composite/composite';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Composite = exports.ValueObjects = exports.Immutable = 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_1 = require("./required/required");
|
|
7
|
+
Object.defineProperty(exports, "Required", { enumerable: true, get: function () { return required_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 immutable_1 = require("./immutable/immutable");
|
|
29
|
+
Object.defineProperty(exports, "Immutable", { enumerable: true, get: function () { return immutable_1.Immutable; } });
|
|
30
|
+
var value_objects_1 = require("./value-objects/value-objects");
|
|
31
|
+
Object.defineProperty(exports, "ValueObjects", { enumerable: true, get: function () { return value_objects_1.ValueObjects; } });
|
|
32
|
+
var composite_1 = require("./composite/composite");
|
|
33
|
+
Object.defineProperty(exports, "Composite", { enumerable: true, get: function () { return composite_1.Composite; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
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 immutable_1 = require("./immutable/immutable");
|
|
7
|
+
const index_1 = require("../../exceptions/index");
|
|
8
|
+
class JsonType extends abstract_type_1.AbstractType {
|
|
9
|
+
filter(value) {
|
|
10
|
+
const converted = (0, validation_1.toJson)(value);
|
|
11
|
+
if (!converted.ok) {
|
|
12
|
+
throw new index_1.TypePrimitiveException('Json', value);
|
|
13
|
+
}
|
|
14
|
+
return immutable_1.Immutable.freeze(JSON.parse(JSON.stringify(converted.value)));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
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 index_1 = require("../../exceptions/index");
|
|
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 index_1.TypePrimitiveException('Number', value);
|
|
12
|
+
}
|
|
13
|
+
return converted.value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.NumberType = NumberType;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class RequiredMark {
|
|
2
|
+
static readonly symbol: unique symbol;
|
|
3
|
+
static isMarked(instance: object): boolean;
|
|
4
|
+
static mark(prototype: object): void;
|
|
5
|
+
}
|
|
6
|
+
export interface RequiredMarked {
|
|
7
|
+
readonly [RequiredMark.symbol]: true;
|
|
8
|
+
}
|
|
9
|
+
export type ValueOf<T, I> = I extends RequiredMarked ? T : T | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequiredMark = void 0;
|
|
4
|
+
class RequiredMark {
|
|
5
|
+
static isMarked(instance) {
|
|
6
|
+
return instance[RequiredMark.symbol] === true;
|
|
7
|
+
}
|
|
8
|
+
static mark(prototype) {
|
|
9
|
+
Object.defineProperty(prototype, RequiredMark.symbol, { value: true });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.RequiredMark = RequiredMark;
|
|
13
|
+
RequiredMark.symbol = Symbol.for('@archi-code/ddd/required.v1');
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AbstractType } from '../abstract-type';
|
|
2
|
+
import type { RequiredMarked } from './required-mark';
|
|
3
|
+
type TypeClass = abstract new (value?: any) => AbstractType<any>;
|
|
4
|
+
type RequiredValueOf<C extends TypeClass> = Exclude<ConstructorParameters<C>[0], null | undefined>;
|
|
5
|
+
export type RequiredType<C extends TypeClass> = Omit<C, 'prototype'> & (abstract new (value: RequiredValueOf<C>) => InstanceType<C> & RequiredMarked);
|
|
6
|
+
export declare function Required<C extends TypeClass>(Base: C): RequiredType<C>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Required = Required;
|
|
10
|
+
const validation_1 = require("@archi-code/validation");
|
|
11
|
+
const required_mark_1 = require("./required-mark");
|
|
12
|
+
function Required(Base) {
|
|
13
|
+
let RequiredValue = class RequiredValue extends Base {
|
|
14
|
+
};
|
|
15
|
+
RequiredValue = __decorate([
|
|
16
|
+
(0, validation_1.Validations)([{ validator: 'isRequired' }])
|
|
17
|
+
], RequiredValue);
|
|
18
|
+
Object.defineProperty(RequiredValue, 'name', { value: `Required(${Base.name})` });
|
|
19
|
+
required_mark_1.RequiredMark.mark(RequiredValue.prototype);
|
|
20
|
+
return RequiredValue;
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringType = void 0;
|
|
4
|
+
const validation_1 = require("@archi-code/validation");
|
|
5
|
+
const abstract_type_1 = require("./abstract-type");
|
|
6
|
+
const index_1 = require("../../exceptions/index");
|
|
7
|
+
class StringType extends abstract_type_1.AbstractType {
|
|
8
|
+
filter(value) {
|
|
9
|
+
const converted = (0, validation_1.toString)(value);
|
|
10
|
+
if (!converted.ok) {
|
|
11
|
+
throw new index_1.TypePrimitiveException('String', value);
|
|
12
|
+
}
|
|
13
|
+
return converted.value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.StringType = StringType;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AbstractType } from './abstract-type';
|
|
2
|
+
export declare class UuidType extends AbstractType<string> {
|
|
3
|
+
static random(): string;
|
|
4
|
+
static generate<T extends AbstractType<string>>(this: new (value: string) => T): T;
|
|
5
|
+
static fromValue(value: string, namespace?: string): string;
|
|
6
|
+
protected filter(value: unknown): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UuidType = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const validation_1 = require("@archi-code/validation");
|
|
6
|
+
const abstract_type_1 = require("./abstract-type");
|
|
7
|
+
const index_1 = require("../../exceptions/index");
|
|
8
|
+
const DNS_NAMESPACE = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
|
9
|
+
class UuidType extends abstract_type_1.AbstractType {
|
|
10
|
+
static random() {
|
|
11
|
+
return (0, uuid_1.v4)();
|
|
12
|
+
}
|
|
13
|
+
static generate() {
|
|
14
|
+
return new this((0, uuid_1.v4)());
|
|
15
|
+
}
|
|
16
|
+
static fromValue(value, namespace = DNS_NAMESPACE) {
|
|
17
|
+
return (0, uuid_1.v5)(value, namespace);
|
|
18
|
+
}
|
|
19
|
+
filter(value) {
|
|
20
|
+
const converted = (0, validation_1.toString)(value);
|
|
21
|
+
if (!converted.ok || !(0, validation_1.isUUID)(converted.value)) {
|
|
22
|
+
throw new index_1.TypePrimitiveException('UUID', value);
|
|
23
|
+
}
|
|
24
|
+
return converted.value.toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.UuidType = UuidType;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type Factories = Record<string, () => unknown>;
|
|
2
|
+
type Built<F extends Factories> = {
|
|
3
|
+
[Field in keyof F]: ReturnType<F[Field]>;
|
|
4
|
+
};
|
|
5
|
+
type Synchronous<F extends Factories> = {
|
|
6
|
+
[Field in keyof F]: [ReturnType<F[Field]>] extends [never] ? F[Field] : [ReturnType<F[Field]>] extends [PromiseLike<unknown>] ? never : F[Field];
|
|
7
|
+
};
|
|
8
|
+
export declare class ValueObjects {
|
|
9
|
+
static build<F extends Factories>(factories: F & Synchronous<F>): Built<F>;
|
|
10
|
+
static buildList<Value, Item>(values: readonly Value[], factory: (value: Value, index: number) => Item): Item[];
|
|
11
|
+
private static synchronous;
|
|
12
|
+
private static isThenable;
|
|
13
|
+
private static issuesOf;
|
|
14
|
+
private static assertNoIssues;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValueObjects = void 0;
|
|
4
|
+
const index_1 = require("../../../exceptions/index");
|
|
5
|
+
class ValueObjects {
|
|
6
|
+
static build(factories) {
|
|
7
|
+
const built = {};
|
|
8
|
+
const issues = [];
|
|
9
|
+
for (const [field, factory] of Object.entries(factories)) {
|
|
10
|
+
try {
|
|
11
|
+
Object.defineProperty(built, field, {
|
|
12
|
+
value: ValueObjects.synchronous(field, factory()),
|
|
13
|
+
enumerable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
issues.push(...ValueObjects.issuesOf(field, error));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
ValueObjects.assertNoIssues(issues);
|
|
23
|
+
return built;
|
|
24
|
+
}
|
|
25
|
+
static buildList(values, factory) {
|
|
26
|
+
const built = [];
|
|
27
|
+
const issues = [];
|
|
28
|
+
values.forEach((value, index) => {
|
|
29
|
+
try {
|
|
30
|
+
built.push(ValueObjects.synchronous(String(index), factory(value, index)));
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
issues.push(...ValueObjects.issuesOf(String(index), error));
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
ValueObjects.assertNoIssues(issues);
|
|
37
|
+
return built;
|
|
38
|
+
}
|
|
39
|
+
static synchronous(field, result) {
|
|
40
|
+
if (!ValueObjects.isThenable(result)) {
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
result.then(undefined, () => undefined);
|
|
44
|
+
throw new index_1.InternalErrorException(`ValueObjects: the factory of "${field}" returned a Promise; build value objects synchronously`);
|
|
45
|
+
}
|
|
46
|
+
static isThenable(result) {
|
|
47
|
+
return ((typeof result === 'object' || typeof result === 'function') &&
|
|
48
|
+
result !== null &&
|
|
49
|
+
typeof result.then === 'function');
|
|
50
|
+
}
|
|
51
|
+
static issuesOf(field, error) {
|
|
52
|
+
if (error instanceof index_1.ValidationException) {
|
|
53
|
+
return error.errors.map((issue) => ({
|
|
54
|
+
field: issue.field === null ? field : `${field}.${issue.field}`,
|
|
55
|
+
code: issue.code,
|
|
56
|
+
message: issue.message,
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
if (error instanceof index_1.DomainException) {
|
|
60
|
+
return [{ field, code: error.code, message: error.message }];
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
static assertNoIssues(issues) {
|
|
65
|
+
if (issues.length > 0) {
|
|
66
|
+
throw new index_1.ValidationException(issues);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.ValueObjects = ValueObjects;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ExceptionCode } from './exception-code';
|
|
2
|
+
export interface ExceptionOptions {
|
|
3
|
+
cause?: unknown;
|
|
4
|
+
}
|
|
5
|
+
export declare abstract class AbstractException extends Error {
|
|
6
|
+
readonly cause?: unknown;
|
|
7
|
+
private readonly exceptionCodes;
|
|
8
|
+
readonly code: ExceptionCode | string;
|
|
9
|
+
private readonly createdAt;
|
|
10
|
+
static [Symbol.hasInstance](candidate: unknown): boolean;
|
|
11
|
+
constructor(message: string, exceptionCodes: (ExceptionCode | string)[], options?: ExceptionOptions);
|
|
12
|
+
static readonly ExceptionCodeStrings: Record<ExceptionCode, string>;
|
|
13
|
+
get timestamp(): Date;
|
|
14
|
+
get description(): string;
|
|
15
|
+
print(): string;
|
|
16
|
+
toJSON(): {
|
|
17
|
+
name: string;
|
|
18
|
+
message: string;
|
|
19
|
+
code: string;
|
|
20
|
+
description: string;
|
|
21
|
+
timestamp: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.AbstractException = void 0;
|
|
5
|
+
const exception_code_1 = require("./exception-code");
|
|
6
|
+
const exception_brand_1 = require("./brand/exception-brand");
|
|
7
|
+
class AbstractException extends Error {
|
|
8
|
+
static [Symbol.hasInstance](candidate) {
|
|
9
|
+
return (Function.prototype[Symbol.hasInstance].call(this, candidate) ||
|
|
10
|
+
exception_brand_1.ExceptionBrand.matches(this, candidate));
|
|
11
|
+
}
|
|
12
|
+
constructor(message, exceptionCodes, options = {}) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = this.constructor.name;
|
|
15
|
+
this.exceptionCodes = exceptionCodes;
|
|
16
|
+
this.code =
|
|
17
|
+
exceptionCodes.length > 0
|
|
18
|
+
? exceptionCodes[exceptionCodes.length - 1]
|
|
19
|
+
: exception_code_1.ExceptionCode.ErrorException;
|
|
20
|
+
this.createdAt = Date.now();
|
|
21
|
+
if ('cause' in options) {
|
|
22
|
+
Object.defineProperty(this, 'cause', {
|
|
23
|
+
value: options.cause,
|
|
24
|
+
writable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exception_brand_1.ExceptionBrand.brandInstance(this, exceptionCodes);
|
|
29
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
30
|
+
}
|
|
31
|
+
get timestamp() {
|
|
32
|
+
return new Date(this.createdAt);
|
|
33
|
+
}
|
|
34
|
+
get description() {
|
|
35
|
+
return this.exceptionCodes
|
|
36
|
+
.map((code) => {
|
|
37
|
+
const codeString = _a.ExceptionCodeStrings[code] ?? this.name;
|
|
38
|
+
return `${codeString} (${code})`;
|
|
39
|
+
})
|
|
40
|
+
.join(', ');
|
|
41
|
+
}
|
|
42
|
+
print() {
|
|
43
|
+
return `[${this.description}]: ${this.message}, ${this.timestamp.toISOString()}`;
|
|
44
|
+
}
|
|
45
|
+
toJSON() {
|
|
46
|
+
return {
|
|
47
|
+
name: this.name,
|
|
48
|
+
message: this.message,
|
|
49
|
+
code: this.code,
|
|
50
|
+
description: this.description,
|
|
51
|
+
timestamp: this.timestamp.toISOString(),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.AbstractException = AbstractException;
|
|
56
|
+
_a = AbstractException;
|
|
57
|
+
(() => {
|
|
58
|
+
exception_brand_1.ExceptionBrand.brandClass(_a, exception_brand_1.ExceptionBrand.anyCode);
|
|
59
|
+
})();
|
|
60
|
+
AbstractException.ExceptionCodeStrings = Object.keys(exception_code_1.ExceptionCode)
|
|
61
|
+
.filter((key) => isNaN(Number(key)))
|
|
62
|
+
.reduce((acc, key) => {
|
|
63
|
+
const value = exception_code_1.ExceptionCode[key];
|
|
64
|
+
acc[value] = key.replace(/([A-Z])/g, ' $1').trim();
|
|
65
|
+
return acc;
|
|
66
|
+
}, {});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ApplicationException } from './application.exception';
|
|
2
|
+
import type { ExceptionOptions } from '../abstract.exception';
|
|
3
|
+
export declare class AggregateNotFoundException extends ApplicationException {
|
|
4
|
+
constructor(entity: string, id: string, options?: ExceptionOptions);
|
|
5
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.AggregateNotFoundException = void 0;
|
|
5
|
+
const application_exception_1 = require("./application.exception");
|
|
6
|
+
const exception_brand_1 = require("../brand/exception-brand");
|
|
7
|
+
const exception_code_1 = require("../exception-code");
|
|
8
|
+
class AggregateNotFoundException extends application_exception_1.ApplicationException {
|
|
9
|
+
constructor(entity, id, options = {}) {
|
|
10
|
+
super(`${entity} with ID ${id} not found.`, [exception_code_1.ExceptionCode.AggregateNotFound], options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.AggregateNotFoundException = AggregateNotFoundException;
|
|
14
|
+
_a = AggregateNotFoundException;
|
|
15
|
+
(() => {
|
|
16
|
+
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.AggregateNotFound);
|
|
17
|
+
})();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AbstractException } from '../abstract.exception';
|
|
2
|
+
import type { ExceptionOptions } from '../abstract.exception';
|
|
3
|
+
import { ExceptionCode } from '../exception-code';
|
|
4
|
+
export declare class ApplicationException extends AbstractException {
|
|
5
|
+
constructor(message: string, exceptionCodes?: (ExceptionCode | string)[], options?: ExceptionOptions);
|
|
6
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ApplicationException = void 0;
|
|
5
|
+
const abstract_exception_1 = require("../abstract.exception");
|
|
6
|
+
const exception_brand_1 = require("../brand/exception-brand");
|
|
7
|
+
const exception_code_1 = require("../exception-code");
|
|
8
|
+
class ApplicationException extends abstract_exception_1.AbstractException {
|
|
9
|
+
constructor(message, exceptionCodes = [], options = {}) {
|
|
10
|
+
super(message, [exception_code_1.ExceptionCode.ApplicationException, ...exceptionCodes], options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.ApplicationException = ApplicationException;
|
|
14
|
+
_a = ApplicationException;
|
|
15
|
+
(() => {
|
|
16
|
+
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.ApplicationException);
|
|
17
|
+
})();
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ApplicationException } from './application.exception';
|
|
2
|
+
import type { ExceptionOptions } from '../abstract.exception';
|
|
3
|
+
export declare class ConcurrencyException extends ApplicationException {
|
|
4
|
+
constructor(aggregateName: string, id: string, expectedVersion: number, options?: ExceptionOptions);
|
|
5
|
+
}
|