@archi-code/ddd 3.0.0-alpha.1 → 3.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +478 -376
- package/SKILL.md +10 -8
- package/ddd-skills/archi-code-ddd/imports.md +28 -18
- package/ddd-skills/archi-code-ddd/layers.md +68 -53
- package/ddd-skills/archi-code-ddd/patterns.md +50 -43
- package/ddd-skills/archi-code-ddd/what-not-to-do.md +25 -18
- package/ddd-skills/archi-code-ddd/where-each-class-goes.md +11 -10
- package/ddd-skills/ddd-agregados/GUIA.md +2 -2
- package/ddd-skills/ddd-agregados/references/consistencia-eventual.md +5 -6
- package/ddd-skills/ddd-agregados/references/fabricas.md +5 -8
- package/ddd-skills/ddd-agregados/references/implementacion-ts.md +22 -27
- package/ddd-skills/ddd-arquitectura/GUIA.md +4 -4
- package/ddd-skills/ddd-arquitectura/assets/dependency-cruiser.cjs +13 -6
- package/ddd-skills/ddd-arquitectura/references/estilos-adicionales.md +2 -2
- package/ddd-skills/ddd-arquitectura/references/estructura-hexagonal-ts.md +70 -16
- package/ddd-skills/ddd-auditoria-refactorizacion/GUIA.md +1 -1
- package/ddd-skills/ddd-auditoria-refactorizacion/references/ejemplo-auditoria.md +9 -11
- package/ddd-skills/ddd-auditoria-refactorizacion/references/lista-comprobacion.md +4 -4
- package/ddd-skills/ddd-auditoria-refactorizacion/references/plan-migracion.md +2 -2
- package/ddd-skills/ddd-context-mapping/GUIA.md +5 -5
- package/ddd-skills/ddd-context-mapping/references/anticorrupcion-ts.md +33 -18
- package/ddd-skills/ddd-context-mapping/references/estilos-integracion.md +4 -7
- package/ddd-skills/ddd-event-sourcing-cqrs/GUIA.md +2 -2
- package/ddd-skills/ddd-event-sourcing-cqrs/references/event-sourcing-ts.md +32 -27
- package/ddd-skills/ddd-event-sourcing-cqrs/references/proyecciones-cqrs-ts.md +7 -7
- package/ddd-skills/ddd-eventos-dominio/GUIA.md +3 -3
- package/ddd-skills/ddd-eventos-dominio/references/diseno-eventos.md +15 -16
- package/ddd-skills/ddd-eventos-dominio/references/ejemplo-ecommerce.md +11 -11
- package/ddd-skills/ddd-eventos-dominio/references/publicacion-ts.md +34 -31
- package/ddd-skills/ddd-repositorios-persistencia/GUIA.md +7 -7
- package/ddd-skills/ddd-repositorios-persistencia/references/implementacion-ts.md +50 -32
- package/ddd-skills/ddd-repositorios-persistencia/references/tests-repositorios.md +31 -17
- package/ddd-skills/ddd-repositorios-persistencia/references/transacciones-ts.md +21 -14
- package/ddd-skills/ddd-servicios-capa-aplicacion/GUIA.md +2 -2
- package/ddd-skills/ddd-servicios-capa-aplicacion/references/capa-aplicacion-ts.md +19 -19
- package/ddd-skills/ddd-servicios-capa-aplicacion/references/ejemplo-ecommerce.md +12 -15
- package/ddd-skills/ddd-servicios-capa-aplicacion/references/servicios-dominio-ts.md +5 -6
- package/ddd-skills/ddd-value-objects-entidades/GUIA.md +3 -3
- package/ddd-skills/ddd-value-objects-entidades/references/entidades-ts.md +7 -9
- package/ddd-skills/ddd-value-objects-entidades/references/persistencia-valores.md +5 -5
- package/ddd-skills/ddd-value-objects-entidades/references/validacion.md +9 -9
- package/ddd-skills/ddd-value-objects-entidades/references/value-objects-ts.md +2 -3
- package/dist/cjs/application/event/listens-to.js +4 -4
- package/dist/cjs/{exceptions/application → application/exceptions}/aggregate-not-found.exception.d.ts +1 -1
- package/dist/cjs/{exceptions/application → application/exceptions}/aggregate-not-found.exception.js +4 -4
- package/dist/cjs/application/exceptions/application-exception-code.d.ts +7 -0
- package/dist/cjs/application/exceptions/application-exception-code.js +11 -0
- package/dist/cjs/application/exceptions/application.exception.d.ts +6 -0
- package/dist/cjs/application/exceptions/application.exception.js +16 -0
- package/dist/cjs/{exceptions/application → application/exceptions}/concurrency.exception.d.ts +1 -1
- package/dist/cjs/{exceptions/application → application/exceptions}/concurrency.exception.js +4 -4
- package/dist/cjs/{exceptions/application → application/exceptions}/not-allowed.exception.d.ts +1 -1
- package/dist/cjs/{exceptions/application → application/exceptions}/not-allowed.exception.js +4 -4
- package/dist/cjs/application/exceptions/unexpected-error.exception.d.ts +5 -0
- package/dist/cjs/application/exceptions/unexpected-error.exception.js +17 -0
- package/dist/cjs/application/index.d.ts +7 -0
- package/dist/cjs/application/index.js +15 -1
- package/dist/cjs/application/use-case/use-case.js +3 -2
- package/dist/{esm/domain/type/value-objects/value-objects.d.ts → cjs/application/value-object-builder/value-object-builder.d.ts} +3 -3
- package/dist/cjs/application/value-object-builder/value-object-builder.js +51 -0
- package/dist/cjs/domain/aggregate/aggregate-root.d.ts +0 -5
- package/dist/cjs/domain/aggregate/aggregate-root.js +4 -20
- package/dist/cjs/domain/entity/entity.js +2 -2
- package/dist/cjs/domain/event/event-base.d.ts +3 -9
- package/dist/cjs/domain/event/event-base.js +8 -38
- package/dist/cjs/domain/exceptions/domain-exception-code.d.ts +7 -0
- package/dist/cjs/domain/exceptions/domain-exception-code.js +11 -0
- package/dist/cjs/domain/exceptions/domain.exception.d.ts +6 -0
- package/dist/cjs/domain/exceptions/domain.exception.js +16 -0
- package/dist/cjs/domain/exceptions/invalid-event-definition.exception.d.ts +4 -0
- package/dist/cjs/domain/exceptions/invalid-event-definition.exception.js +19 -0
- package/dist/cjs/{exceptions/domain → domain/exceptions}/required-value.exception.js +5 -6
- package/dist/cjs/{exceptions/domain → domain/exceptions}/type-primitive.exception.js +5 -6
- package/dist/cjs/{exceptions/domain → domain/exceptions}/validation.exception.js +5 -5
- package/dist/cjs/domain/index.d.ts +8 -1
- package/dist/cjs/domain/index.js +14 -2
- package/dist/cjs/domain/primitive/primitive-types.d.ts +1 -3
- package/dist/cjs/domain/type/abstract-type.d.ts +6 -8
- package/dist/cjs/domain/type/abstract-type.js +15 -23
- package/dist/cjs/domain/type/array-type.d.ts +2 -1
- package/dist/cjs/domain/type/array-type.js +17 -18
- package/dist/cjs/domain/type/boolean-type.js +2 -2
- package/dist/cjs/domain/type/composite/composite-brand.d.ts +4 -0
- package/dist/cjs/domain/type/composite/composite-brand.js +15 -0
- package/dist/cjs/domain/type/composite/composite-field.d.ts +7 -8
- package/dist/cjs/domain/type/composite/composite-field.js +70 -47
- package/dist/cjs/domain/type/composite/composite-issues.d.ts +6 -0
- package/dist/cjs/domain/type/composite/composite-issues.js +35 -0
- package/dist/cjs/domain/type/composite/composite.js +15 -19
- package/dist/cjs/domain/type/date-type.d.ts +3 -2
- package/dist/cjs/domain/type/date-type.js +42 -7
- package/dist/cjs/domain/type/enum-type.js +2 -2
- package/dist/cjs/domain/type/id-type.d.ts +1 -1
- package/dist/cjs/domain/type/id-type.js +4 -4
- package/dist/cjs/domain/type/index.d.ts +2 -4
- package/dist/cjs/domain/type/index.js +3 -7
- package/dist/cjs/domain/type/json-type.d.ts +4 -0
- package/dist/cjs/domain/type/json-type.js +33 -4
- package/dist/cjs/domain/type/number-type.js +2 -2
- package/dist/cjs/domain/type/required/required-mark.d.ts +0 -1
- package/dist/cjs/domain/type/string-type.js +2 -2
- package/dist/cjs/domain/type/uuid-type.js +2 -2
- package/dist/cjs/infrastructure/event/domain-event-bus.js +9 -9
- package/dist/cjs/infrastructure/event/event-registry.js +9 -9
- package/dist/cjs/infrastructure/event/in-memory/emitter.js +2 -2
- package/dist/cjs/infrastructure/event/in-memory/in-memory-event-channel.d.ts +1 -1
- package/dist/cjs/infrastructure/event/in-memory/in-memory-event-channel.js +6 -7
- package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/event-delivery.exception.js +4 -4
- package/dist/cjs/infrastructure/exceptions/infrastructure-exception-code.d.ts +6 -0
- package/dist/cjs/infrastructure/exceptions/infrastructure-exception-code.js +10 -0
- package/dist/cjs/infrastructure/exceptions/infrastructure.exception.d.ts +6 -0
- package/dist/cjs/infrastructure/exceptions/infrastructure.exception.js +16 -0
- package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/internal-error.exception.d.ts +1 -1
- package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/internal-error.exception.js +4 -4
- package/dist/cjs/infrastructure/exceptions/kind/exception-classifier.d.ts +4 -0
- package/dist/cjs/infrastructure/exceptions/kind/exception-classifier.js +34 -0
- package/dist/cjs/infrastructure/exceptions/kind/exception-kind.d.ts +9 -0
- package/dist/cjs/infrastructure/exceptions/kind/exception-kind.js +13 -0
- package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/unknown-event.exception.js +4 -4
- package/dist/cjs/infrastructure/index.d.ts +7 -2
- package/dist/cjs/infrastructure/index.js +15 -3
- package/dist/cjs/infrastructure/logging/console-logger.js +2 -2
- package/dist/{esm → cjs/shared}/exceptions/abstract.exception.d.ts +6 -4
- package/dist/cjs/{exceptions → shared/exceptions}/abstract.exception.js +9 -16
- package/dist/cjs/shared/index.d.ts +8 -0
- package/dist/cjs/shared/index.js +13 -0
- package/dist/cjs/shared/issue-collection-error.d.ts +9 -0
- package/dist/cjs/shared/issue-collection-error.js +11 -0
- package/dist/cjs/shared/issue-collector.d.ts +8 -0
- package/dist/cjs/shared/issue-collector.js +41 -0
- package/dist/esm/application/event/listens-to.js +1 -1
- package/dist/esm/{exceptions/application → application/exceptions}/aggregate-not-found.exception.d.ts +1 -1
- package/dist/esm/application/exceptions/aggregate-not-found.exception.js +13 -0
- package/dist/esm/application/exceptions/application-exception-code.d.ts +7 -0
- package/dist/esm/application/exceptions/application-exception-code.js +8 -0
- package/dist/esm/application/exceptions/application.exception.d.ts +6 -0
- package/dist/esm/application/exceptions/application.exception.js +12 -0
- package/dist/esm/{exceptions/application → application/exceptions}/concurrency.exception.d.ts +1 -1
- package/dist/esm/{exceptions/application → application/exceptions}/concurrency.exception.js +4 -4
- package/dist/esm/{exceptions/application → application/exceptions}/not-allowed.exception.d.ts +1 -1
- package/dist/esm/application/exceptions/not-allowed.exception.js +13 -0
- package/dist/esm/application/exceptions/unexpected-error.exception.d.ts +5 -0
- package/dist/esm/application/exceptions/unexpected-error.exception.js +13 -0
- package/dist/esm/application/index.d.ts +7 -0
- package/dist/esm/application/index.js +7 -0
- package/dist/esm/application/use-case/use-case.js +3 -2
- package/dist/{cjs/domain/type/value-objects/value-objects.d.ts → esm/application/value-object-builder/value-object-builder.d.ts} +3 -3
- package/dist/esm/application/value-object-builder/value-object-builder.js +47 -0
- package/dist/esm/domain/aggregate/aggregate-root.d.ts +0 -5
- package/dist/esm/domain/aggregate/aggregate-root.js +4 -20
- package/dist/esm/domain/entity/entity.js +1 -1
- package/dist/esm/domain/event/event-base.d.ts +3 -9
- package/dist/esm/domain/event/event-base.js +8 -38
- package/dist/esm/domain/exceptions/domain-exception-code.d.ts +7 -0
- package/dist/esm/domain/exceptions/domain-exception-code.js +8 -0
- package/dist/esm/domain/exceptions/domain.exception.d.ts +6 -0
- package/dist/esm/domain/exceptions/domain.exception.js +12 -0
- package/dist/esm/domain/exceptions/invalid-event-definition.exception.d.ts +4 -0
- package/dist/esm/domain/exceptions/invalid-event-definition.exception.js +15 -0
- package/dist/esm/{exceptions/domain → domain/exceptions}/required-value.exception.js +4 -5
- package/dist/esm/{exceptions/domain → domain/exceptions}/type-primitive.exception.js +4 -5
- package/dist/esm/{exceptions/domain → domain/exceptions}/validation.exception.js +5 -5
- package/dist/esm/domain/index.d.ts +7 -0
- package/dist/esm/domain/index.js +6 -0
- package/dist/esm/domain/primitive/primitive-types.d.ts +1 -3
- package/dist/esm/domain/type/abstract-type.d.ts +6 -8
- package/dist/esm/domain/type/abstract-type.js +14 -22
- package/dist/esm/domain/type/array-type.d.ts +2 -1
- package/dist/esm/domain/type/array-type.js +16 -17
- package/dist/esm/domain/type/boolean-type.js +1 -1
- package/dist/esm/domain/type/composite/composite-brand.d.ts +4 -0
- package/dist/esm/domain/type/composite/composite-brand.js +11 -0
- package/dist/esm/domain/type/composite/composite-field.d.ts +7 -8
- package/dist/esm/domain/type/composite/composite-field.js +69 -46
- package/dist/esm/domain/type/composite/composite-issues.d.ts +6 -0
- package/dist/esm/domain/type/composite/composite-issues.js +31 -0
- package/dist/esm/domain/type/composite/composite.js +13 -17
- package/dist/esm/domain/type/date-type.d.ts +3 -2
- package/dist/esm/domain/type/date-type.js +39 -4
- package/dist/esm/domain/type/enum-type.js +1 -1
- package/dist/esm/domain/type/id-type.d.ts +1 -1
- package/dist/esm/domain/type/id-type.js +2 -2
- package/dist/esm/domain/type/index.d.ts +2 -4
- package/dist/esm/domain/type/index.js +1 -3
- package/dist/esm/domain/type/json-type.d.ts +4 -0
- package/dist/esm/domain/type/json-type.js +32 -3
- package/dist/esm/domain/type/number-type.js +1 -1
- package/dist/esm/domain/type/required/required-mark.d.ts +0 -1
- package/dist/esm/domain/type/string-type.js +1 -1
- package/dist/esm/domain/type/uuid-type.js +1 -1
- package/dist/esm/infrastructure/event/domain-event-bus.js +5 -5
- package/dist/esm/infrastructure/event/event-registry.js +4 -4
- package/dist/esm/infrastructure/event/in-memory/emitter.js +1 -1
- package/dist/esm/infrastructure/event/in-memory/in-memory-event-channel.d.ts +1 -1
- package/dist/esm/infrastructure/event/in-memory/in-memory-event-channel.js +5 -6
- package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/event-delivery.exception.js +4 -4
- package/dist/esm/infrastructure/exceptions/infrastructure-exception-code.d.ts +6 -0
- package/dist/esm/infrastructure/exceptions/infrastructure-exception-code.js +7 -0
- package/dist/esm/infrastructure/exceptions/infrastructure.exception.d.ts +6 -0
- package/dist/esm/infrastructure/exceptions/infrastructure.exception.js +12 -0
- package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/internal-error.exception.d.ts +1 -1
- package/dist/esm/infrastructure/exceptions/internal-error.exception.js +13 -0
- package/dist/esm/infrastructure/exceptions/kind/exception-classifier.d.ts +4 -0
- package/dist/esm/infrastructure/exceptions/kind/exception-classifier.js +30 -0
- package/dist/esm/infrastructure/exceptions/kind/exception-kind.d.ts +9 -0
- package/dist/esm/infrastructure/exceptions/kind/exception-kind.js +10 -0
- package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/unknown-event.exception.js +4 -4
- package/dist/esm/infrastructure/index.d.ts +7 -2
- package/dist/esm/infrastructure/index.js +7 -1
- package/dist/esm/infrastructure/logging/console-logger.js +1 -1
- package/dist/{cjs → esm/shared}/exceptions/abstract.exception.d.ts +6 -4
- package/dist/esm/{exceptions → shared/exceptions}/abstract.exception.js +9 -16
- package/dist/esm/shared/index.d.ts +8 -0
- package/dist/esm/shared/index.js +5 -0
- package/dist/esm/shared/issue-collection-error.d.ts +9 -0
- package/dist/esm/shared/issue-collection-error.js +7 -0
- package/dist/esm/shared/issue-collector.d.ts +8 -0
- package/dist/esm/shared/issue-collector.js +37 -0
- package/package.json +7 -18
- package/dist/cjs/domain/type/equality/value-equality.d.ts +0 -7
- package/dist/cjs/domain/type/equality/value-equality.js +0 -41
- package/dist/cjs/domain/type/immutable/immutable-date.d.ts +0 -4
- package/dist/cjs/domain/type/immutable/immutable-date.js +0 -37
- package/dist/cjs/domain/type/immutable/immutable.d.ts +0 -4
- package/dist/cjs/domain/type/immutable/immutable.js +0 -19
- package/dist/cjs/domain/type/value-objects/value-objects.js +0 -70
- package/dist/cjs/exceptions/application/application.exception.d.ts +0 -6
- package/dist/cjs/exceptions/application/application.exception.js +0 -17
- package/dist/cjs/exceptions/domain/domain.exception.d.ts +0 -6
- package/dist/cjs/exceptions/domain/domain.exception.js +0 -17
- package/dist/cjs/exceptions/exception-code.d.ts +0 -15
- package/dist/cjs/exceptions/exception-code.js +0 -19
- package/dist/cjs/exceptions/index.d.ts +0 -14
- package/dist/cjs/exceptions/index.js +0 -30
- package/dist/cjs/exceptions/infrastructure/infrastructure.exception.d.ts +0 -6
- package/dist/cjs/exceptions/infrastructure/infrastructure.exception.js +0 -17
- package/dist/cjs/infrastructure/http/http-error-mapper.d.ts +0 -23
- package/dist/cjs/infrastructure/http/http-error-mapper.js +0 -63
- package/dist/esm/domain/type/equality/value-equality.d.ts +0 -7
- package/dist/esm/domain/type/equality/value-equality.js +0 -37
- package/dist/esm/domain/type/immutable/immutable-date.d.ts +0 -4
- package/dist/esm/domain/type/immutable/immutable-date.js +0 -33
- package/dist/esm/domain/type/immutable/immutable.d.ts +0 -4
- package/dist/esm/domain/type/immutable/immutable.js +0 -15
- package/dist/esm/domain/type/value-objects/value-objects.js +0 -66
- package/dist/esm/exceptions/application/aggregate-not-found.exception.js +0 -13
- package/dist/esm/exceptions/application/application.exception.d.ts +0 -6
- package/dist/esm/exceptions/application/application.exception.js +0 -13
- package/dist/esm/exceptions/application/not-allowed.exception.js +0 -13
- package/dist/esm/exceptions/domain/domain.exception.d.ts +0 -6
- package/dist/esm/exceptions/domain/domain.exception.js +0 -13
- package/dist/esm/exceptions/exception-code.d.ts +0 -15
- package/dist/esm/exceptions/exception-code.js +0 -16
- package/dist/esm/exceptions/index.d.ts +0 -14
- package/dist/esm/exceptions/index.js +0 -14
- package/dist/esm/exceptions/infrastructure/infrastructure.exception.d.ts +0 -6
- package/dist/esm/exceptions/infrastructure/infrastructure.exception.js +0 -13
- package/dist/esm/exceptions/infrastructure/internal-error.exception.js +0 -13
- package/dist/esm/infrastructure/http/http-error-mapper.d.ts +0 -23
- package/dist/esm/infrastructure/http/http-error-mapper.js +0 -59
- /package/dist/cjs/{exceptions/domain → domain/exceptions}/required-value.exception.d.ts +0 -0
- /package/dist/cjs/{exceptions/domain → domain/exceptions}/type-primitive.exception.d.ts +0 -0
- /package/dist/cjs/{exceptions/domain → domain/exceptions}/validation.exception.d.ts +0 -0
- /package/dist/cjs/domain/type/required/{required.d.ts → required-type.d.ts} +0 -0
- /package/dist/cjs/domain/type/required/{required.js → required-type.js} +0 -0
- /package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/event-delivery.exception.d.ts +0 -0
- /package/dist/cjs/{exceptions/infrastructure → infrastructure/exceptions}/unknown-event.exception.d.ts +0 -0
- /package/dist/cjs/{exceptions → shared/exceptions}/brand/exception-brand.d.ts +0 -0
- /package/dist/cjs/{exceptions → shared/exceptions}/brand/exception-brand.js +0 -0
- /package/dist/cjs/{exceptions → shared/exceptions}/received/received-value.d.ts +0 -0
- /package/dist/cjs/{exceptions → shared/exceptions}/received/received-value.js +0 -0
- /package/dist/esm/{exceptions/domain → domain/exceptions}/required-value.exception.d.ts +0 -0
- /package/dist/esm/{exceptions/domain → domain/exceptions}/type-primitive.exception.d.ts +0 -0
- /package/dist/esm/{exceptions/domain → domain/exceptions}/validation.exception.d.ts +0 -0
- /package/dist/esm/domain/type/required/{required.d.ts → required-type.d.ts} +0 -0
- /package/dist/esm/domain/type/required/{required.js → required-type.js} +0 -0
- /package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/event-delivery.exception.d.ts +0 -0
- /package/dist/esm/{exceptions/infrastructure → infrastructure/exceptions}/unknown-event.exception.d.ts +0 -0
- /package/dist/esm/{exceptions → shared/exceptions}/brand/exception-brand.d.ts +0 -0
- /package/dist/esm/{exceptions → shared/exceptions}/brand/exception-brand.js +0 -0
- /package/dist/esm/{exceptions → shared/exceptions}/received/received-value.d.ts +0 -0
- /package/dist/esm/{exceptions → shared/exceptions}/received/received-value.js +0 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ListensTo = ListensTo;
|
|
4
|
-
const
|
|
4
|
+
const application_exception_1 = require("../exceptions/application.exception");
|
|
5
5
|
const LISTENED_EVENT = Symbol.for('@archi-code/ddd/listens-to.v1');
|
|
6
6
|
function ListensTo(event, options) {
|
|
7
7
|
return (listener) => {
|
|
8
8
|
if (Object.prototype.hasOwnProperty.call(listener, LISTENED_EVENT)) {
|
|
9
|
-
throw new
|
|
9
|
+
throw new application_exception_1.ApplicationException(`${listener.name} already listens to an event`);
|
|
10
10
|
}
|
|
11
11
|
const consumer = options?.consumer;
|
|
12
12
|
if (typeof consumer !== 'string' || consumer.trim() === '') {
|
|
13
|
-
throw new
|
|
13
|
+
throw new application_exception_1.ApplicationException(`${listener.name} needs a consumer name: @ListensTo(<event class>, { consumer: '<name>' })`);
|
|
14
14
|
}
|
|
15
15
|
const subscription = Object.freeze({
|
|
16
16
|
eventName: event.eventName,
|
|
@@ -22,7 +22,7 @@ function ListensTo(event, options) {
|
|
|
22
22
|
ListensTo.subscriptionOf = (listener) => {
|
|
23
23
|
const listenerClass = listener.constructor;
|
|
24
24
|
if (!Object.prototype.hasOwnProperty.call(listenerClass, LISTENED_EVENT)) {
|
|
25
|
-
throw new
|
|
25
|
+
throw new application_exception_1.ApplicationException(`${listenerClass.name} needs @ListensTo(<event class>, { consumer: '<name>' })`);
|
|
26
26
|
}
|
|
27
27
|
return listenerClass[LISTENED_EVENT];
|
|
28
28
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { ExceptionOptions } from '../../shared/index';
|
|
1
2
|
import { ApplicationException } from './application.exception';
|
|
2
|
-
import type { ExceptionOptions } from '../abstract.exception';
|
|
3
3
|
export declare class AggregateNotFoundException extends ApplicationException {
|
|
4
4
|
constructor(entity: string, id: string, options?: ExceptionOptions);
|
|
5
5
|
}
|
package/dist/cjs/{exceptions/application → application/exceptions}/aggregate-not-found.exception.js
RENAMED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.AggregateNotFoundException = void 0;
|
|
5
|
+
const index_1 = require("../../shared/index");
|
|
6
|
+
const application_exception_code_1 = require("./application-exception-code");
|
|
5
7
|
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
8
|
class AggregateNotFoundException extends application_exception_1.ApplicationException {
|
|
9
9
|
constructor(entity, id, options = {}) {
|
|
10
|
-
super(`${entity} with ID ${id} not found.`, [
|
|
10
|
+
super(`${entity} with ID ${id} not found.`, [application_exception_code_1.ApplicationExceptionCode.AggregateNotFound], options);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.AggregateNotFoundException = AggregateNotFoundException;
|
|
14
14
|
_a = AggregateNotFoundException;
|
|
15
15
|
(() => {
|
|
16
|
-
|
|
16
|
+
index_1.ExceptionBrand.brandClass(_a, application_exception_code_1.ApplicationExceptionCode.AggregateNotFound);
|
|
17
17
|
})();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplicationExceptionCode = void 0;
|
|
4
|
+
var ApplicationExceptionCode;
|
|
5
|
+
(function (ApplicationExceptionCode) {
|
|
6
|
+
ApplicationExceptionCode["ApplicationException"] = "APP000";
|
|
7
|
+
ApplicationExceptionCode["ConcurrencyConflict"] = "APP001";
|
|
8
|
+
ApplicationExceptionCode["AggregateNotFound"] = "APP002";
|
|
9
|
+
ApplicationExceptionCode["NotAllowed"] = "APP003";
|
|
10
|
+
ApplicationExceptionCode["UnexpectedError"] = "APP004";
|
|
11
|
+
})(ApplicationExceptionCode || (exports.ApplicationExceptionCode = ApplicationExceptionCode = {}));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AbstractException } from '../../shared/index';
|
|
2
|
+
import type { ExceptionOptions } from '../../shared/index';
|
|
3
|
+
import { ApplicationExceptionCode } from './application-exception-code';
|
|
4
|
+
export declare class ApplicationException extends AbstractException {
|
|
5
|
+
constructor(message: string, exceptionCodes?: (ApplicationExceptionCode | string)[], options?: ExceptionOptions);
|
|
6
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ApplicationException = void 0;
|
|
5
|
+
const index_1 = require("../../shared/index");
|
|
6
|
+
const application_exception_code_1 = require("./application-exception-code");
|
|
7
|
+
class ApplicationException extends index_1.AbstractException {
|
|
8
|
+
constructor(message, exceptionCodes = [], options = {}) {
|
|
9
|
+
super(message, [application_exception_code_1.ApplicationExceptionCode.ApplicationException, ...exceptionCodes], options, application_exception_code_1.ApplicationExceptionCode);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ApplicationException = ApplicationException;
|
|
13
|
+
_a = ApplicationException;
|
|
14
|
+
(() => {
|
|
15
|
+
index_1.ExceptionBrand.brandClass(_a, application_exception_code_1.ApplicationExceptionCode.ApplicationException);
|
|
16
|
+
})();
|
package/dist/cjs/{exceptions/application → application/exceptions}/concurrency.exception.d.ts
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { ExceptionOptions } from '../../shared/index';
|
|
1
2
|
import { ApplicationException } from './application.exception';
|
|
2
|
-
import type { ExceptionOptions } from '../abstract.exception';
|
|
3
3
|
export declare class ConcurrencyException extends ApplicationException {
|
|
4
4
|
constructor(aggregateName: string, id: string, expectedVersion: number, options?: ExceptionOptions);
|
|
5
5
|
}
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.ConcurrencyException = void 0;
|
|
5
|
+
const index_1 = require("../../shared/index");
|
|
6
|
+
const application_exception_code_1 = require("./application-exception-code");
|
|
5
7
|
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
8
|
class ConcurrencyException extends application_exception_1.ApplicationException {
|
|
9
9
|
constructor(aggregateName, id, expectedVersion, options = {}) {
|
|
10
|
-
super(`${aggregateName} with ID ${id} was changed by someone else: expected version ${expectedVersion}.`, [
|
|
10
|
+
super(`${aggregateName} with ID ${id} was changed by someone else: expected version ${expectedVersion}.`, [application_exception_code_1.ApplicationExceptionCode.ConcurrencyConflict], options);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.ConcurrencyException = ConcurrencyException;
|
|
14
14
|
_a = ConcurrencyException;
|
|
15
15
|
(() => {
|
|
16
|
-
|
|
16
|
+
index_1.ExceptionBrand.brandClass(_a, application_exception_code_1.ApplicationExceptionCode.ConcurrencyConflict);
|
|
17
17
|
})();
|
package/dist/cjs/{exceptions/application → application/exceptions}/not-allowed.exception.d.ts
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { ExceptionOptions } from '../../shared/index';
|
|
1
2
|
import { ApplicationException } from './application.exception';
|
|
2
|
-
import type { ExceptionOptions } from '../abstract.exception';
|
|
3
3
|
export declare class NotAllowedException extends ApplicationException {
|
|
4
4
|
constructor(message: string, options?: ExceptionOptions);
|
|
5
5
|
}
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.NotAllowedException = void 0;
|
|
5
|
+
const index_1 = require("../../shared/index");
|
|
6
|
+
const application_exception_code_1 = require("./application-exception-code");
|
|
5
7
|
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
8
|
class NotAllowedException extends application_exception_1.ApplicationException {
|
|
9
9
|
constructor(message, options = {}) {
|
|
10
|
-
super(message, [
|
|
10
|
+
super(message, [application_exception_code_1.ApplicationExceptionCode.NotAllowed], options);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.NotAllowedException = NotAllowedException;
|
|
14
14
|
_a = NotAllowedException;
|
|
15
15
|
(() => {
|
|
16
|
-
|
|
16
|
+
index_1.ExceptionBrand.brandClass(_a, application_exception_code_1.ApplicationExceptionCode.NotAllowed);
|
|
17
17
|
})();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.UnexpectedErrorException = void 0;
|
|
5
|
+
const index_1 = require("../../shared/index");
|
|
6
|
+
const application_exception_code_1 = require("./application-exception-code");
|
|
7
|
+
const application_exception_1 = require("./application.exception");
|
|
8
|
+
class UnexpectedErrorException extends application_exception_1.ApplicationException {
|
|
9
|
+
constructor(message, options = {}) {
|
|
10
|
+
super(`Failed, unexpected error: ${message}`, [application_exception_code_1.ApplicationExceptionCode.UnexpectedError], options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.UnexpectedErrorException = UnexpectedErrorException;
|
|
14
|
+
_a = UnexpectedErrorException;
|
|
15
|
+
(() => {
|
|
16
|
+
index_1.ExceptionBrand.brandClass(_a, application_exception_code_1.ApplicationExceptionCode.UnexpectedError);
|
|
17
|
+
})();
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
export { UseCase } from './use-case/use-case';
|
|
2
|
+
export { ValueObjectBuilder } from './value-object-builder/value-object-builder';
|
|
2
3
|
export { EventListener } from './event/event-listener';
|
|
3
4
|
export { ListensTo } from './event/listens-to';
|
|
4
5
|
export type { ListenerSubscription, ListensToOptions } from './event/listens-to';
|
|
5
6
|
export type { EventBus } from './event/event-bus';
|
|
6
7
|
export type { Clock } from './ports/clock';
|
|
7
8
|
export type { LogContext, Logger, LogLevel } from './ports/logger';
|
|
9
|
+
export { ApplicationException } from './exceptions/application.exception';
|
|
10
|
+
export { ConcurrencyException } from './exceptions/concurrency.exception';
|
|
11
|
+
export { AggregateNotFoundException } from './exceptions/aggregate-not-found.exception';
|
|
12
|
+
export { NotAllowedException } from './exceptions/not-allowed.exception';
|
|
13
|
+
export { UnexpectedErrorException } from './exceptions/unexpected-error.exception';
|
|
14
|
+
export { ApplicationExceptionCode } from './exceptions/application-exception-code';
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ListensTo = exports.EventListener = exports.UseCase = void 0;
|
|
3
|
+
exports.ApplicationExceptionCode = exports.UnexpectedErrorException = exports.NotAllowedException = exports.AggregateNotFoundException = exports.ConcurrencyException = exports.ApplicationException = exports.ListensTo = exports.EventListener = exports.ValueObjectBuilder = exports.UseCase = void 0;
|
|
4
4
|
var use_case_1 = require("./use-case/use-case");
|
|
5
5
|
Object.defineProperty(exports, "UseCase", { enumerable: true, get: function () { return use_case_1.UseCase; } });
|
|
6
|
+
var value_object_builder_1 = require("./value-object-builder/value-object-builder");
|
|
7
|
+
Object.defineProperty(exports, "ValueObjectBuilder", { enumerable: true, get: function () { return value_object_builder_1.ValueObjectBuilder; } });
|
|
6
8
|
var event_listener_1 = require("./event/event-listener");
|
|
7
9
|
Object.defineProperty(exports, "EventListener", { enumerable: true, get: function () { return event_listener_1.EventListener; } });
|
|
8
10
|
var listens_to_1 = require("./event/listens-to");
|
|
9
11
|
Object.defineProperty(exports, "ListensTo", { enumerable: true, get: function () { return listens_to_1.ListensTo; } });
|
|
12
|
+
var application_exception_1 = require("./exceptions/application.exception");
|
|
13
|
+
Object.defineProperty(exports, "ApplicationException", { enumerable: true, get: function () { return application_exception_1.ApplicationException; } });
|
|
14
|
+
var concurrency_exception_1 = require("./exceptions/concurrency.exception");
|
|
15
|
+
Object.defineProperty(exports, "ConcurrencyException", { enumerable: true, get: function () { return concurrency_exception_1.ConcurrencyException; } });
|
|
16
|
+
var aggregate_not_found_exception_1 = require("./exceptions/aggregate-not-found.exception");
|
|
17
|
+
Object.defineProperty(exports, "AggregateNotFoundException", { enumerable: true, get: function () { return aggregate_not_found_exception_1.AggregateNotFoundException; } });
|
|
18
|
+
var not_allowed_exception_1 = require("./exceptions/not-allowed.exception");
|
|
19
|
+
Object.defineProperty(exports, "NotAllowedException", { enumerable: true, get: function () { return not_allowed_exception_1.NotAllowedException; } });
|
|
20
|
+
var unexpected_error_exception_1 = require("./exceptions/unexpected-error.exception");
|
|
21
|
+
Object.defineProperty(exports, "UnexpectedErrorException", { enumerable: true, get: function () { return unexpected_error_exception_1.UnexpectedErrorException; } });
|
|
22
|
+
var application_exception_code_1 = require("./exceptions/application-exception-code");
|
|
23
|
+
Object.defineProperty(exports, "ApplicationExceptionCode", { enumerable: true, get: function () { return application_exception_code_1.ApplicationExceptionCode; } });
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UseCase = void 0;
|
|
4
4
|
const validation_1 = require("@archi-code/validation");
|
|
5
|
-
const index_1 = require("../../
|
|
5
|
+
const index_1 = require("../../shared/index");
|
|
6
|
+
const unexpected_error_exception_1 = require("../exceptions/unexpected-error.exception");
|
|
6
7
|
class UseCase {
|
|
7
8
|
async execute(input) {
|
|
8
9
|
try {
|
|
@@ -12,7 +13,7 @@ class UseCase {
|
|
|
12
13
|
if (error instanceof index_1.AbstractException) {
|
|
13
14
|
throw error;
|
|
14
15
|
}
|
|
15
|
-
throw new
|
|
16
|
+
throw new unexpected_error_exception_1.UnexpectedErrorException(`${this.constructor.name}: ${UseCase.describe(error)}`, {
|
|
16
17
|
cause: error,
|
|
17
18
|
});
|
|
18
19
|
}
|
|
@@ -5,12 +5,12 @@ type Built<F extends Factories> = {
|
|
|
5
5
|
type Synchronous<F extends Factories> = {
|
|
6
6
|
[Field in keyof F]: [ReturnType<F[Field]>] extends [never] ? F[Field] : [ReturnType<F[Field]>] extends [PromiseLike<unknown>] ? never : F[Field];
|
|
7
7
|
};
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class ValueObjectBuilder {
|
|
9
9
|
static build<F extends Factories>(factories: F & Synchronous<F>): Built<F>;
|
|
10
10
|
static buildList<Value, Item>(values: readonly Value[], factory: (value: Value, index: number) => Item): Item[];
|
|
11
11
|
private static synchronous;
|
|
12
|
+
private static validated;
|
|
13
|
+
private static read;
|
|
12
14
|
private static isThenable;
|
|
13
|
-
private static issuesOf;
|
|
14
|
-
private static assertNoIssues;
|
|
15
15
|
}
|
|
16
16
|
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValueObjectBuilder = void 0;
|
|
4
|
+
const index_1 = require("../../domain/index");
|
|
5
|
+
const index_2 = require("../../shared/index");
|
|
6
|
+
const unexpected_error_exception_1 = require("../exceptions/unexpected-error.exception");
|
|
7
|
+
class ValueObjectBuilder {
|
|
8
|
+
static build(factories) {
|
|
9
|
+
const builds = Object.fromEntries(Object.entries(factories).map(([field, factory]) => [
|
|
10
|
+
field,
|
|
11
|
+
() => ValueObjectBuilder.synchronous(field, factory()),
|
|
12
|
+
]));
|
|
13
|
+
return ValueObjectBuilder.validated(() => index_2.IssueCollector.collectFields(builds, ValueObjectBuilder.read));
|
|
14
|
+
}
|
|
15
|
+
static buildList(values, factory) {
|
|
16
|
+
return ValueObjectBuilder.validated(() => index_2.IssueCollector.collectItems(values, (value, index) => ValueObjectBuilder.synchronous(String(index), factory(value, index)), ValueObjectBuilder.read));
|
|
17
|
+
}
|
|
18
|
+
static synchronous(field, result) {
|
|
19
|
+
if (!ValueObjectBuilder.isThenable(result)) {
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
result.then(undefined, () => undefined);
|
|
23
|
+
throw new unexpected_error_exception_1.UnexpectedErrorException(`ValueObjectBuilder: the factory of "${field}" returned a Promise; build value objects synchronously`);
|
|
24
|
+
}
|
|
25
|
+
static validated(collect) {
|
|
26
|
+
try {
|
|
27
|
+
return collect();
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof index_2.IssueCollectionError) {
|
|
31
|
+
throw new index_1.ValidationException(error.issues);
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
static read(error) {
|
|
37
|
+
if (error instanceof index_1.ValidationException) {
|
|
38
|
+
return error.errors;
|
|
39
|
+
}
|
|
40
|
+
if (error instanceof index_1.DomainException) {
|
|
41
|
+
return [{ field: null, code: error.code, message: error.message }];
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
static isThenable(result) {
|
|
46
|
+
return ((typeof result === 'object' || typeof result === 'function') &&
|
|
47
|
+
result !== null &&
|
|
48
|
+
typeof result.then === 'function');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ValueObjectBuilder = ValueObjectBuilder;
|
|
@@ -4,11 +4,6 @@ import type { EventBase } from '../event/event-base';
|
|
|
4
4
|
import type { IdType } from '../type/id-type';
|
|
5
5
|
export declare abstract class AggregateRoot<Id extends EntityId = IdType, Event extends EventBase = EventBase> extends Entity<Id> {
|
|
6
6
|
private readonly domainEvents;
|
|
7
|
-
private persistedVersion;
|
|
8
|
-
constructor(id: Id);
|
|
9
|
-
get version(): number;
|
|
10
7
|
protected record(event: Event): void;
|
|
11
8
|
pullDomainEvents(): Event[];
|
|
12
|
-
restoreVersion(version: number): this;
|
|
13
|
-
markPersisted(): void;
|
|
14
9
|
}
|
|
@@ -2,32 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AggregateRoot = void 0;
|
|
4
4
|
const entity_1 = require("../entity/entity");
|
|
5
|
-
const immutable_1 = require("../type/immutable/immutable");
|
|
6
|
-
const index_1 = require("../../exceptions/index");
|
|
7
5
|
class AggregateRoot extends entity_1.Entity {
|
|
8
|
-
constructor(
|
|
9
|
-
super(
|
|
10
|
-
|
|
11
|
-
Object.defineProperty(this, 'persistedVersion', { value: 0, writable: true });
|
|
12
|
-
}
|
|
13
|
-
get version() {
|
|
14
|
-
return this.persistedVersion;
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.domainEvents = [];
|
|
15
9
|
}
|
|
16
10
|
record(event) {
|
|
17
|
-
this.domainEvents.push(
|
|
11
|
+
this.domainEvents.push(event);
|
|
18
12
|
}
|
|
19
13
|
pullDomainEvents() {
|
|
20
14
|
return this.domainEvents.splice(0);
|
|
21
15
|
}
|
|
22
|
-
restoreVersion(version) {
|
|
23
|
-
if (!Number.isSafeInteger(version) || version < 0) {
|
|
24
|
-
throw new index_1.InternalErrorException(`${this.constructor.name} cannot be restored with version ${String(version)}`);
|
|
25
|
-
}
|
|
26
|
-
this.persistedVersion = version;
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
markPersisted() {
|
|
30
|
-
this.persistedVersion += 1;
|
|
31
|
-
}
|
|
32
16
|
}
|
|
33
17
|
exports.AggregateRoot = AggregateRoot;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Entity = void 0;
|
|
4
|
-
const
|
|
4
|
+
const required_value_exception_1 = require("../exceptions/required-value.exception");
|
|
5
5
|
class Entity {
|
|
6
6
|
constructor(id) {
|
|
7
7
|
this.id = id;
|
|
8
8
|
if (id?.isNull !== false) {
|
|
9
|
-
throw new
|
|
9
|
+
throw new required_value_exception_1.RequiredValueException(`${new.target.name}.id`, id?.value);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
equals(other) {
|
|
@@ -7,23 +7,17 @@ export interface EventMetadata {
|
|
|
7
7
|
}
|
|
8
8
|
export interface SerializedEvent {
|
|
9
9
|
eventName: string;
|
|
10
|
-
eventVersion: number;
|
|
11
10
|
eventId: string;
|
|
12
|
-
aggregateId: string;
|
|
13
11
|
occurredOn: string;
|
|
14
12
|
[payload: string]: unknown;
|
|
15
13
|
}
|
|
16
14
|
export interface EventClass<Event extends EventBase = EventBase> {
|
|
17
15
|
readonly eventName: string;
|
|
18
|
-
readonly eventVersion?: number;
|
|
19
16
|
new (...args: any[]): Event;
|
|
20
17
|
}
|
|
21
18
|
export declare abstract class EventBase {
|
|
19
|
+
readonly eventName: string;
|
|
22
20
|
readonly eventId: string;
|
|
23
|
-
readonly
|
|
24
|
-
|
|
25
|
-
constructor(aggregateId: string, metadata?: EventMetadata);
|
|
26
|
-
eventName(): string;
|
|
27
|
-
eventVersion(): number;
|
|
28
|
-
toJSON(): SerializedEvent;
|
|
21
|
+
readonly occurredOn: string;
|
|
22
|
+
constructor(metadata?: EventMetadata);
|
|
29
23
|
}
|
|
@@ -4,48 +4,18 @@ exports.EventBase = void 0;
|
|
|
4
4
|
const date_type_1 = require("../type/date-type");
|
|
5
5
|
const id_type_1 = require("../type/id-type");
|
|
6
6
|
const uuid_type_1 = require("../type/uuid-type");
|
|
7
|
-
const
|
|
7
|
+
const invalid_event_definition_exception_1 = require("../exceptions/invalid-event-definition.exception");
|
|
8
8
|
class EventBase {
|
|
9
|
-
constructor(
|
|
10
|
-
const { eventName
|
|
9
|
+
constructor(metadata = {}) {
|
|
10
|
+
const { eventName } = this.constructor;
|
|
11
11
|
if (typeof eventName !== 'string' || eventName.trim() === '') {
|
|
12
|
-
throw new
|
|
12
|
+
throw new invalid_event_definition_exception_1.InvalidEventDefinitionException(this.constructor.name);
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
throw new index_1.InternalErrorException(`${this.constructor.name}.eventVersion must be a whole number from 1`);
|
|
16
|
-
}
|
|
17
|
-
if (aggregateId === null ||
|
|
18
|
-
aggregateId === undefined ||
|
|
19
|
-
(typeof aggregateId === 'string' && aggregateId.trim() === '')) {
|
|
20
|
-
throw new index_1.RequiredValueException(`${this.constructor.name}.aggregateId`, aggregateId);
|
|
21
|
-
}
|
|
22
|
-
this.aggregateId = aggregateId;
|
|
14
|
+
this.eventName = eventName;
|
|
23
15
|
this.eventId = new id_type_1.IdType(metadata.eventId ?? uuid_type_1.UuidType.random()).value;
|
|
24
|
-
this.occurredOn =
|
|
25
|
-
metadata.
|
|
26
|
-
|
|
27
|
-
: new date_type_1.CreatedAt(metadata.occurredOn).value;
|
|
28
|
-
}
|
|
29
|
-
eventName() {
|
|
30
|
-
return this.constructor.eventName;
|
|
31
|
-
}
|
|
32
|
-
eventVersion() {
|
|
33
|
-
return this.constructor.eventVersion ?? 1;
|
|
34
|
-
}
|
|
35
|
-
toJSON() {
|
|
36
|
-
const serialized = {
|
|
37
|
-
eventName: this.eventName(),
|
|
38
|
-
eventVersion: this.eventVersion(),
|
|
39
|
-
eventId: this.eventId,
|
|
40
|
-
aggregateId: this.aggregateId,
|
|
41
|
-
occurredOn: this.occurredOn.toISOString(),
|
|
42
|
-
};
|
|
43
|
-
for (const [key, value] of Object.entries(this)) {
|
|
44
|
-
if (!(key in serialized)) {
|
|
45
|
-
serialized[key] = value;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return serialized;
|
|
16
|
+
this.occurredOn = (metadata.occurredOn === undefined
|
|
17
|
+
? date_type_1.CreatedAt.now(metadata.clock)
|
|
18
|
+
: new date_type_1.CreatedAt(metadata.occurredOn)).value.toISOString();
|
|
49
19
|
}
|
|
50
20
|
}
|
|
51
21
|
exports.EventBase = EventBase;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DomainExceptionCode = void 0;
|
|
4
|
+
var DomainExceptionCode;
|
|
5
|
+
(function (DomainExceptionCode) {
|
|
6
|
+
DomainExceptionCode["DomainException"] = "DOM000";
|
|
7
|
+
DomainExceptionCode["ValidationFailed"] = "DOM001";
|
|
8
|
+
DomainExceptionCode["TypeFailed"] = "DOM003";
|
|
9
|
+
DomainExceptionCode["RequiredValue"] = "DOM004";
|
|
10
|
+
DomainExceptionCode["InvalidEventDefinition"] = "DOM005";
|
|
11
|
+
})(DomainExceptionCode || (exports.DomainExceptionCode = DomainExceptionCode = {}));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AbstractException } from '../../shared/index';
|
|
2
|
+
import type { ExceptionOptions } from '../../shared/index';
|
|
3
|
+
import { DomainExceptionCode } from './domain-exception-code';
|
|
4
|
+
export declare class DomainException extends AbstractException {
|
|
5
|
+
constructor(message: string, exceptionCodes?: (DomainExceptionCode | string)[], options?: ExceptionOptions);
|
|
6
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.DomainException = void 0;
|
|
5
|
+
const index_1 = require("../../shared/index");
|
|
6
|
+
const domain_exception_code_1 = require("./domain-exception-code");
|
|
7
|
+
class DomainException extends index_1.AbstractException {
|
|
8
|
+
constructor(message, exceptionCodes = [], options = {}) {
|
|
9
|
+
super(message, [domain_exception_code_1.DomainExceptionCode.DomainException, ...exceptionCodes], options, domain_exception_code_1.DomainExceptionCode);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.DomainException = DomainException;
|
|
13
|
+
_a = DomainException;
|
|
14
|
+
(() => {
|
|
15
|
+
index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.DomainException);
|
|
16
|
+
})();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.InvalidEventDefinitionException = void 0;
|
|
5
|
+
const index_1 = require("../../shared/index");
|
|
6
|
+
const domain_exception_code_1 = require("./domain-exception-code");
|
|
7
|
+
const domain_exception_1 = require("./domain.exception");
|
|
8
|
+
class InvalidEventDefinitionException extends domain_exception_1.DomainException {
|
|
9
|
+
constructor(eventClassName) {
|
|
10
|
+
super(`${eventClassName} must declare a static eventName`, [
|
|
11
|
+
domain_exception_code_1.DomainExceptionCode.InvalidEventDefinition,
|
|
12
|
+
]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.InvalidEventDefinitionException = InvalidEventDefinitionException;
|
|
16
|
+
_a = InvalidEventDefinitionException;
|
|
17
|
+
(() => {
|
|
18
|
+
index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.InvalidEventDefinition);
|
|
19
|
+
})();
|
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.RequiredValueException = void 0;
|
|
5
|
+
const index_1 = require("../../shared/index");
|
|
6
|
+
const domain_exception_code_1 = require("./domain-exception-code");
|
|
5
7
|
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
8
|
class RequiredValueException extends domain_exception_1.DomainException {
|
|
10
9
|
constructor(typeName, receivedValue) {
|
|
11
|
-
const received =
|
|
10
|
+
const received = index_1.ReceivedValue.describe(receivedValue);
|
|
12
11
|
super(`Validation Error: ${typeName} is required, but received ${received}.`, [
|
|
13
|
-
|
|
12
|
+
domain_exception_code_1.DomainExceptionCode.RequiredValue,
|
|
14
13
|
]);
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
exports.RequiredValueException = RequiredValueException;
|
|
18
17
|
_a = RequiredValueException;
|
|
19
18
|
(() => {
|
|
20
|
-
|
|
19
|
+
index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.RequiredValue);
|
|
21
20
|
})();
|
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.TypePrimitiveException = void 0;
|
|
5
|
+
const index_1 = require("../../shared/index");
|
|
6
|
+
const domain_exception_code_1 = require("./domain-exception-code");
|
|
5
7
|
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
8
|
class TypePrimitiveException extends domain_exception_1.DomainException {
|
|
10
9
|
constructor(expectedType, receivedValue, template = 'Expected a valid ') {
|
|
11
|
-
const received =
|
|
10
|
+
const received = index_1.ReceivedValue.describe(receivedValue);
|
|
12
11
|
super(`Validation Error: ${template}${expectedType}, but received ${received}.`, [
|
|
13
|
-
|
|
12
|
+
domain_exception_code_1.DomainExceptionCode.TypeFailed,
|
|
14
13
|
]);
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
exports.TypePrimitiveException = TypePrimitiveException;
|
|
18
17
|
_a = TypePrimitiveException;
|
|
19
18
|
(() => {
|
|
20
|
-
|
|
19
|
+
index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.TypeFailed);
|
|
21
20
|
})();
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.ValidationException = void 0;
|
|
5
|
+
const index_1 = require("../../shared/index");
|
|
6
|
+
const domain_exception_code_1 = require("./domain-exception-code");
|
|
5
7
|
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
8
|
class ValidationException extends domain_exception_1.DomainException {
|
|
9
9
|
constructor(errors) {
|
|
10
10
|
super(`Validation failed, ${errors.map(_a.describe).join(', ')}`, [
|
|
11
|
-
|
|
11
|
+
domain_exception_code_1.DomainExceptionCode.ValidationFailed,
|
|
12
12
|
]);
|
|
13
|
-
this.errors = Object.freeze(errors.map(({ field, code =
|
|
13
|
+
this.errors = Object.freeze(errors.map(({ field, code = domain_exception_code_1.DomainExceptionCode.ValidationFailed, message }) => Object.freeze({ field, code, message })));
|
|
14
14
|
}
|
|
15
15
|
static describe(issue) {
|
|
16
16
|
return issue.field === null ? issue.message : `${issue.field}: ${issue.message}`;
|
|
@@ -19,5 +19,5 @@ class ValidationException extends domain_exception_1.DomainException {
|
|
|
19
19
|
exports.ValidationException = ValidationException;
|
|
20
20
|
_a = ValidationException;
|
|
21
21
|
(() => {
|
|
22
|
-
|
|
22
|
+
index_1.ExceptionBrand.brandClass(_a, domain_exception_code_1.DomainExceptionCode.ValidationFailed);
|
|
23
23
|
})();
|