@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,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ConcurrencyException = 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 ConcurrencyException extends application_exception_1.ApplicationException {
|
|
9
|
+
constructor(aggregateName, id, expectedVersion, options = {}) {
|
|
10
|
+
super(`${aggregateName} with ID ${id} was changed by someone else: expected version ${expectedVersion}.`, [exception_code_1.ExceptionCode.ConcurrencyConflict], options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.ConcurrencyException = ConcurrencyException;
|
|
14
|
+
_a = ConcurrencyException;
|
|
15
|
+
(() => {
|
|
16
|
+
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.ConcurrencyConflict);
|
|
17
|
+
})();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.NotAllowedException = 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 NotAllowedException extends application_exception_1.ApplicationException {
|
|
9
|
+
constructor(message, options = {}) {
|
|
10
|
+
super(message, [exception_code_1.ExceptionCode.NotAllowed], options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.NotAllowedException = NotAllowedException;
|
|
14
|
+
_a = NotAllowedException;
|
|
15
|
+
(() => {
|
|
16
|
+
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.NotAllowed);
|
|
17
|
+
})();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare class ExceptionBrand {
|
|
2
|
+
static readonly anyCode = "*";
|
|
3
|
+
static brandClass(exceptionClass: object, code: string): void;
|
|
4
|
+
static brandInstance(exception: object, codes: readonly string[]): void;
|
|
5
|
+
static matches(exceptionClass: object, candidate: unknown): boolean;
|
|
6
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExceptionBrand = void 0;
|
|
4
|
+
const INSTANCE_CODES = Symbol.for('@archi-code/ddd/exception-codes.v1');
|
|
5
|
+
const CLASS_CODE = Symbol.for('@archi-code/ddd/exception-class-code.v1');
|
|
6
|
+
class ExceptionBrand {
|
|
7
|
+
static brandClass(exceptionClass, code) {
|
|
8
|
+
Object.defineProperty(exceptionClass, CLASS_CODE, { value: code });
|
|
9
|
+
}
|
|
10
|
+
static brandInstance(exception, codes) {
|
|
11
|
+
Object.defineProperty(exception, INSTANCE_CODES, { value: Object.freeze([...codes]) });
|
|
12
|
+
}
|
|
13
|
+
static matches(exceptionClass, candidate) {
|
|
14
|
+
if (!Object.prototype.hasOwnProperty.call(exceptionClass, CLASS_CODE)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (typeof candidate !== 'object' || candidate === null) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const codes = candidate[INSTANCE_CODES];
|
|
21
|
+
if (!Array.isArray(codes)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const code = exceptionClass[CLASS_CODE];
|
|
25
|
+
return code === ExceptionBrand.anyCode || codes.includes(code);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ExceptionBrand = ExceptionBrand;
|
|
29
|
+
ExceptionBrand.anyCode = '*';
|
|
@@ -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 DomainException 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.DomainException = 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 DomainException extends abstract_exception_1.AbstractException {
|
|
9
|
+
constructor(message, exceptionCodes = [], options = {}) {
|
|
10
|
+
super(message, [exception_code_1.ExceptionCode.DomainException, ...exceptionCodes], options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.DomainException = DomainException;
|
|
14
|
+
_a = DomainException;
|
|
15
|
+
(() => {
|
|
16
|
+
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.DomainException);
|
|
17
|
+
})();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.RequiredValueException = void 0;
|
|
5
|
+
const domain_exception_1 = require("./domain.exception");
|
|
6
|
+
const exception_brand_1 = require("../brand/exception-brand");
|
|
7
|
+
const exception_code_1 = require("../exception-code");
|
|
8
|
+
const received_value_1 = require("../received/received-value");
|
|
9
|
+
class RequiredValueException extends domain_exception_1.DomainException {
|
|
10
|
+
constructor(typeName, receivedValue) {
|
|
11
|
+
const received = received_value_1.ReceivedValue.describe(receivedValue);
|
|
12
|
+
super(`Validation Error: ${typeName} is required, but received ${received}.`, [
|
|
13
|
+
exception_code_1.ExceptionCode.RequiredValue,
|
|
14
|
+
]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.RequiredValueException = RequiredValueException;
|
|
18
|
+
_a = RequiredValueException;
|
|
19
|
+
(() => {
|
|
20
|
+
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.RequiredValue);
|
|
21
|
+
})();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TypePrimitiveException = void 0;
|
|
5
|
+
const domain_exception_1 = require("./domain.exception");
|
|
6
|
+
const exception_brand_1 = require("../brand/exception-brand");
|
|
7
|
+
const exception_code_1 = require("../exception-code");
|
|
8
|
+
const received_value_1 = require("../received/received-value");
|
|
9
|
+
class TypePrimitiveException extends domain_exception_1.DomainException {
|
|
10
|
+
constructor(expectedType, receivedValue, template = 'Expected a valid ') {
|
|
11
|
+
const received = received_value_1.ReceivedValue.describe(receivedValue);
|
|
12
|
+
super(`Validation Error: ${template}${expectedType}, but received ${received}.`, [
|
|
13
|
+
exception_code_1.ExceptionCode.TypeFailed,
|
|
14
|
+
]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.TypePrimitiveException = TypePrimitiveException;
|
|
18
|
+
_a = TypePrimitiveException;
|
|
19
|
+
(() => {
|
|
20
|
+
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.TypeFailed);
|
|
21
|
+
})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DomainException } from './domain.exception';
|
|
2
|
+
export interface ValidationIssue {
|
|
3
|
+
readonly field: string | null;
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly message: string;
|
|
6
|
+
}
|
|
7
|
+
export type ValidationIssueInput = Omit<ValidationIssue, 'code'> & {
|
|
8
|
+
readonly code?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class ValidationException extends DomainException {
|
|
11
|
+
readonly errors: readonly ValidationIssue[];
|
|
12
|
+
constructor(errors: readonly ValidationIssueInput[]);
|
|
13
|
+
private static describe;
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ValidationException = void 0;
|
|
5
|
+
const domain_exception_1 = require("./domain.exception");
|
|
6
|
+
const exception_brand_1 = require("../brand/exception-brand");
|
|
7
|
+
const exception_code_1 = require("../exception-code");
|
|
8
|
+
class ValidationException extends domain_exception_1.DomainException {
|
|
9
|
+
constructor(errors) {
|
|
10
|
+
super(`Validation failed, ${errors.map(_a.describe).join(', ')}`, [
|
|
11
|
+
exception_code_1.ExceptionCode.ValidationFailed,
|
|
12
|
+
]);
|
|
13
|
+
this.errors = Object.freeze(errors.map(({ field, code = exception_code_1.ExceptionCode.ValidationFailed, message }) => Object.freeze({ field, code, message })));
|
|
14
|
+
}
|
|
15
|
+
static describe(issue) {
|
|
16
|
+
return issue.field === null ? issue.message : `${issue.field}: ${issue.message}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.ValidationException = ValidationException;
|
|
20
|
+
_a = ValidationException;
|
|
21
|
+
(() => {
|
|
22
|
+
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.ValidationFailed);
|
|
23
|
+
})();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare enum ExceptionCode {
|
|
2
|
+
DomainException = "DOM000",
|
|
3
|
+
ValidationFailed = "DOM001",
|
|
4
|
+
TypeFailed = "DOM003",
|
|
5
|
+
RequiredValue = "DOM004",
|
|
6
|
+
ApplicationException = "APP000",
|
|
7
|
+
ConcurrencyConflict = "APP001",
|
|
8
|
+
AggregateNotFound = "APP002",
|
|
9
|
+
NotAllowed = "APP003",
|
|
10
|
+
InfrastructureException = "INF000",
|
|
11
|
+
InternalError = "INF001",
|
|
12
|
+
UnknownEvent = "INF002",
|
|
13
|
+
EventDelivery = "INF003",
|
|
14
|
+
ErrorException = "E000"
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExceptionCode = void 0;
|
|
4
|
+
var ExceptionCode;
|
|
5
|
+
(function (ExceptionCode) {
|
|
6
|
+
ExceptionCode["DomainException"] = "DOM000";
|
|
7
|
+
ExceptionCode["ValidationFailed"] = "DOM001";
|
|
8
|
+
ExceptionCode["TypeFailed"] = "DOM003";
|
|
9
|
+
ExceptionCode["RequiredValue"] = "DOM004";
|
|
10
|
+
ExceptionCode["ApplicationException"] = "APP000";
|
|
11
|
+
ExceptionCode["ConcurrencyConflict"] = "APP001";
|
|
12
|
+
ExceptionCode["AggregateNotFound"] = "APP002";
|
|
13
|
+
ExceptionCode["NotAllowed"] = "APP003";
|
|
14
|
+
ExceptionCode["InfrastructureException"] = "INF000";
|
|
15
|
+
ExceptionCode["InternalError"] = "INF001";
|
|
16
|
+
ExceptionCode["UnknownEvent"] = "INF002";
|
|
17
|
+
ExceptionCode["EventDelivery"] = "INF003";
|
|
18
|
+
ExceptionCode["ErrorException"] = "E000";
|
|
19
|
+
})(ExceptionCode || (exports.ExceptionCode = ExceptionCode = {}));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './abstract.exception';
|
|
2
|
+
export * from './exception-code';
|
|
3
|
+
export * from './application/application.exception';
|
|
4
|
+
export * from './application/concurrency.exception';
|
|
5
|
+
export * from './application/aggregate-not-found.exception';
|
|
6
|
+
export * from './application/not-allowed.exception';
|
|
7
|
+
export * from './infrastructure/infrastructure.exception';
|
|
8
|
+
export * from './infrastructure/internal-error.exception';
|
|
9
|
+
export * from './infrastructure/unknown-event.exception';
|
|
10
|
+
export * from './infrastructure/event-delivery.exception';
|
|
11
|
+
export * from './domain/validation.exception';
|
|
12
|
+
export * from './domain/domain.exception';
|
|
13
|
+
export * from './domain/required-value.exception';
|
|
14
|
+
export * from './domain/type-primitive.exception';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./abstract.exception"), exports);
|
|
18
|
+
__exportStar(require("./exception-code"), exports);
|
|
19
|
+
__exportStar(require("./application/application.exception"), exports);
|
|
20
|
+
__exportStar(require("./application/concurrency.exception"), exports);
|
|
21
|
+
__exportStar(require("./application/aggregate-not-found.exception"), exports);
|
|
22
|
+
__exportStar(require("./application/not-allowed.exception"), exports);
|
|
23
|
+
__exportStar(require("./infrastructure/infrastructure.exception"), exports);
|
|
24
|
+
__exportStar(require("./infrastructure/internal-error.exception"), exports);
|
|
25
|
+
__exportStar(require("./infrastructure/unknown-event.exception"), exports);
|
|
26
|
+
__exportStar(require("./infrastructure/event-delivery.exception"), exports);
|
|
27
|
+
__exportStar(require("./domain/validation.exception"), exports);
|
|
28
|
+
__exportStar(require("./domain/domain.exception"), exports);
|
|
29
|
+
__exportStar(require("./domain/required-value.exception"), exports);
|
|
30
|
+
__exportStar(require("./domain/type-primitive.exception"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { InfrastructureException } from './infrastructure.exception';
|
|
2
|
+
export declare class EventDeliveryException extends InfrastructureException {
|
|
3
|
+
readonly errors: readonly unknown[];
|
|
4
|
+
constructor(eventName: string, errors: readonly unknown[], consumers: number);
|
|
5
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.EventDeliveryException = void 0;
|
|
5
|
+
const infrastructure_exception_1 = require("./infrastructure.exception");
|
|
6
|
+
const exception_brand_1 = require("../brand/exception-brand");
|
|
7
|
+
const exception_code_1 = require("../exception-code");
|
|
8
|
+
class EventDeliveryException extends infrastructure_exception_1.InfrastructureException {
|
|
9
|
+
constructor(eventName, errors, consumers) {
|
|
10
|
+
super(`${errors.length} of ${consumers} consumers of "${eventName}" failed.`, [
|
|
11
|
+
exception_code_1.ExceptionCode.EventDelivery,
|
|
12
|
+
]);
|
|
13
|
+
this.errors = Object.freeze([...errors]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.EventDeliveryException = EventDeliveryException;
|
|
17
|
+
_a = EventDeliveryException;
|
|
18
|
+
(() => {
|
|
19
|
+
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.EventDelivery);
|
|
20
|
+
})();
|
|
@@ -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 InfrastructureException 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.InfrastructureException = 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 InfrastructureException extends abstract_exception_1.AbstractException {
|
|
9
|
+
constructor(message, exceptionCodes = [], options = {}) {
|
|
10
|
+
super(message, [exception_code_1.ExceptionCode.InfrastructureException, ...exceptionCodes], options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.InfrastructureException = InfrastructureException;
|
|
14
|
+
_a = InfrastructureException;
|
|
15
|
+
(() => {
|
|
16
|
+
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.InfrastructureException);
|
|
17
|
+
})();
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { InfrastructureException } from './infrastructure.exception';
|
|
2
|
+
import type { ExceptionOptions } from '../abstract.exception';
|
|
3
|
+
export declare class InternalErrorException extends InfrastructureException {
|
|
4
|
+
constructor(message: string, options?: ExceptionOptions);
|
|
5
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.InternalErrorException = void 0;
|
|
5
|
+
const infrastructure_exception_1 = require("./infrastructure.exception");
|
|
6
|
+
const exception_brand_1 = require("../brand/exception-brand");
|
|
7
|
+
const exception_code_1 = require("../exception-code");
|
|
8
|
+
class InternalErrorException extends infrastructure_exception_1.InfrastructureException {
|
|
9
|
+
constructor(message, options = {}) {
|
|
10
|
+
super(`Failed, internal error: ${message}`, [exception_code_1.ExceptionCode.InternalError], options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.InternalErrorException = InternalErrorException;
|
|
14
|
+
_a = InternalErrorException;
|
|
15
|
+
(() => {
|
|
16
|
+
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.InternalError);
|
|
17
|
+
})();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.UnknownEventException = void 0;
|
|
5
|
+
const infrastructure_exception_1 = require("./infrastructure.exception");
|
|
6
|
+
const exception_brand_1 = require("../brand/exception-brand");
|
|
7
|
+
const exception_code_1 = require("../exception-code");
|
|
8
|
+
class UnknownEventException extends infrastructure_exception_1.InfrastructureException {
|
|
9
|
+
constructor(eventName) {
|
|
10
|
+
super(`Unknown event "${eventName}": register it before reading it.`, [
|
|
11
|
+
exception_code_1.ExceptionCode.UnknownEvent,
|
|
12
|
+
]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.UnknownEventException = UnknownEventException;
|
|
16
|
+
_a = UnknownEventException;
|
|
17
|
+
(() => {
|
|
18
|
+
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.UnknownEvent);
|
|
19
|
+
})();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReceivedValue = void 0;
|
|
4
|
+
const validation_1 = require("@archi-code/validation");
|
|
5
|
+
class ReceivedValue {
|
|
6
|
+
static describe(value) {
|
|
7
|
+
const text = typeof value === 'string' ? value : (0, validation_1.anyToString)(value);
|
|
8
|
+
const shown = text.length > ReceivedValue.maxLength ? `${text.slice(0, ReceivedValue.maxLength)}…` : text;
|
|
9
|
+
return typeof value === 'string' ? `"${shown}"` : shown;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ReceivedValue = ReceivedValue;
|
|
13
|
+
ReceivedValue.maxLength = 64;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FixedClock = void 0;
|
|
4
|
+
const index_1 = require("../../domain/index");
|
|
5
|
+
class FixedClock {
|
|
6
|
+
constructor(at) {
|
|
7
|
+
this.current = new index_1.CreatedAt(at).value;
|
|
8
|
+
}
|
|
9
|
+
now() {
|
|
10
|
+
return new Date(this.current.getTime());
|
|
11
|
+
}
|
|
12
|
+
set(at) {
|
|
13
|
+
this.current = new index_1.CreatedAt(at).value;
|
|
14
|
+
}
|
|
15
|
+
advance(milliseconds) {
|
|
16
|
+
this.current = new index_1.CreatedAt(new Date(this.current.getTime() + milliseconds)).value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.FixedClock = FixedClock;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EventBase } from '../../domain/index';
|
|
2
|
+
import type { EventBus, EventListener, Logger } from '../../application/index';
|
|
3
|
+
import type { EventChannel } from './event-channel';
|
|
4
|
+
import type { EventRegistry } from './event-registry';
|
|
5
|
+
export interface Subscription {
|
|
6
|
+
unsubscribe(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare class DomainEventBus<Event extends EventBase = EventBase> implements EventBus<Event> {
|
|
9
|
+
private readonly channel;
|
|
10
|
+
private readonly registry;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
constructor(channel: EventChannel, registry: EventRegistry<Event>, logger?: Logger);
|
|
13
|
+
publish(events: readonly Event[]): Promise<void>;
|
|
14
|
+
subscribe(listener: EventListener<Event>): Promise<Subscription>;
|
|
15
|
+
private deliver;
|
|
16
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DomainEventBus = void 0;
|
|
4
|
+
const index_1 = require("../../exceptions/index");
|
|
5
|
+
const index_2 = require("../../application/index");
|
|
6
|
+
const silent_logger_1 = require("../logging/silent-logger");
|
|
7
|
+
class DomainEventBus {
|
|
8
|
+
constructor(channel, registry, logger = new silent_logger_1.SilentLogger()) {
|
|
9
|
+
this.channel = channel;
|
|
10
|
+
this.registry = registry;
|
|
11
|
+
this.logger = logger;
|
|
12
|
+
}
|
|
13
|
+
async publish(events) {
|
|
14
|
+
await this.channel.send(events.map((event) => event.toJSON()));
|
|
15
|
+
this.logger.debug('domain_events_published', {
|
|
16
|
+
events: events.map((event) => ({
|
|
17
|
+
eventName: event.eventName(),
|
|
18
|
+
eventId: event.eventId,
|
|
19
|
+
aggregateId: event.aggregateId,
|
|
20
|
+
})),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async subscribe(listener) {
|
|
24
|
+
const subscription = index_2.ListensTo.subscriptionOf(listener);
|
|
25
|
+
const { eventName, consumer } = subscription;
|
|
26
|
+
if (!this.registry.has(eventName)) {
|
|
27
|
+
throw new index_1.UnknownEventException(eventName);
|
|
28
|
+
}
|
|
29
|
+
const channelSubscription = await this.channel.receive(eventName, consumer, (serialized) => this.deliver(listener, subscription, serialized));
|
|
30
|
+
this.logger.info('event_listener_subscribed', { eventName, consumer });
|
|
31
|
+
return {
|
|
32
|
+
unsubscribe: async () => {
|
|
33
|
+
await channelSubscription.close();
|
|
34
|
+
this.logger.info('event_listener_unsubscribed', { eventName, consumer });
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
async deliver(listener, { eventName, consumer }, serialized) {
|
|
39
|
+
try {
|
|
40
|
+
await listener.handle(this.registry.fromJSON(serialized));
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
const context = {
|
|
44
|
+
eventName,
|
|
45
|
+
consumer,
|
|
46
|
+
eventId: serialized.eventId,
|
|
47
|
+
aggregateId: serialized.aggregateId,
|
|
48
|
+
error,
|
|
49
|
+
};
|
|
50
|
+
if (error instanceof index_1.DomainException || error instanceof index_1.ApplicationException) {
|
|
51
|
+
this.logger.warn('event_listener_rejected', context);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
this.logger.error('event_listener_failed', context);
|
|
55
|
+
}
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.DomainEventBus = DomainEventBus;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SerializedEvent } from '../../domain/index';
|
|
2
|
+
export type ChannelHandler = (event: SerializedEvent) => Promise<void>;
|
|
3
|
+
export interface ChannelSubscription {
|
|
4
|
+
close(): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export interface EventChannel {
|
|
7
|
+
send(events: readonly SerializedEvent[]): Promise<void>;
|
|
8
|
+
receive(eventName: string, consumer: string, handler: ChannelHandler): Promise<ChannelSubscription>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EventBase, EventClass, SerializedEvent } from '../../domain/index';
|
|
2
|
+
export type EventFactory<Event extends EventBase> = (serialized: SerializedEvent) => Event;
|
|
3
|
+
export declare class EventRegistry<Event extends EventBase = EventBase> {
|
|
4
|
+
private readonly factories;
|
|
5
|
+
register<Registered extends Event>(event: EventClass<Registered>, factory: EventFactory<Registered>): this;
|
|
6
|
+
has(eventName: string): boolean;
|
|
7
|
+
fromJSON(event: SerializedEvent): Event;
|
|
8
|
+
private static assertSameIdentity;
|
|
9
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventRegistry = void 0;
|
|
4
|
+
const index_1 = require("../../exceptions/index");
|
|
5
|
+
const index_2 = require("../../domain/index");
|
|
6
|
+
class EventRegistry {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.factories = new Map();
|
|
9
|
+
}
|
|
10
|
+
register(event, factory) {
|
|
11
|
+
const { eventName } = event;
|
|
12
|
+
if (this.factories.has(eventName)) {
|
|
13
|
+
throw new index_1.InternalErrorException(`event "${eventName}" is already registered`);
|
|
14
|
+
}
|
|
15
|
+
this.factories.set(eventName, factory);
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
has(eventName) {
|
|
19
|
+
return this.factories.has(eventName);
|
|
20
|
+
}
|
|
21
|
+
fromJSON(event) {
|
|
22
|
+
if (typeof event !== 'object' || event === null) {
|
|
23
|
+
throw new index_1.InternalErrorException('a serialized event must be a JSON object');
|
|
24
|
+
}
|
|
25
|
+
if (typeof event.eventName !== 'string') {
|
|
26
|
+
throw new index_1.InternalErrorException('a serialized event needs its eventName');
|
|
27
|
+
}
|
|
28
|
+
const factory = this.factories.get(event.eventName);
|
|
29
|
+
if (factory === undefined) {
|
|
30
|
+
throw new index_1.UnknownEventException(event.eventName);
|
|
31
|
+
}
|
|
32
|
+
const rebuilt = factory(event);
|
|
33
|
+
EventRegistry.assertSameIdentity(event, rebuilt);
|
|
34
|
+
return index_2.Immutable.freeze(rebuilt);
|
|
35
|
+
}
|
|
36
|
+
static assertSameIdentity(serialized, rebuilt) {
|
|
37
|
+
if (rebuilt.eventId !== String(serialized.eventId).toLowerCase() ||
|
|
38
|
+
rebuilt.occurredOn.getTime() !== new Date(serialized.occurredOn).getTime()) {
|
|
39
|
+
throw new index_1.InternalErrorException(`the factory of "${serialized.eventName}" must pass the serialized event as metadata, so it keeps its eventId and occurredOn`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.EventRegistry = EventRegistry;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type EmitterListener<Data> = (data: Data) => Promise<void> | void;
|
|
2
|
+
export declare class Emitter<Data> {
|
|
3
|
+
private static readonly resolved;
|
|
4
|
+
private readonly events;
|
|
5
|
+
on(eventName: string, listener: EmitterListener<Data>): () => void;
|
|
6
|
+
private off;
|
|
7
|
+
emit(eventName: string, data: Data): Promise<void>;
|
|
8
|
+
emitSerial(eventName: string, data: Data): Promise<void>;
|
|
9
|
+
private listenersOf;
|
|
10
|
+
}
|
|
11
|
+
export {};
|