@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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { ExceptionBrand } from '../../shared/index.js';
|
|
3
|
+
import { DomainExceptionCode } from './domain-exception-code.js';
|
|
4
|
+
import { DomainException } from './domain.exception.js';
|
|
5
|
+
export class InvalidEventDefinitionException extends DomainException {
|
|
6
|
+
constructor(eventClassName) {
|
|
7
|
+
super(`${eventClassName} must declare a static eventName`, [
|
|
8
|
+
DomainExceptionCode.InvalidEventDefinition,
|
|
9
|
+
]);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
_a = InvalidEventDefinitionException;
|
|
13
|
+
(() => {
|
|
14
|
+
ExceptionBrand.brandClass(_a, DomainExceptionCode.InvalidEventDefinition);
|
|
15
|
+
})();
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
var _a;
|
|
2
|
+
import { ExceptionBrand, ReceivedValue } from '../../shared/index.js';
|
|
3
|
+
import { DomainExceptionCode } from './domain-exception-code.js';
|
|
2
4
|
import { DomainException } from './domain.exception.js';
|
|
3
|
-
import { ExceptionBrand } from '../brand/exception-brand.js';
|
|
4
|
-
import { ExceptionCode } from '../exception-code.js';
|
|
5
|
-
import { ReceivedValue } from '../received/received-value.js';
|
|
6
5
|
export class RequiredValueException extends DomainException {
|
|
7
6
|
constructor(typeName, receivedValue) {
|
|
8
7
|
const received = ReceivedValue.describe(receivedValue);
|
|
9
8
|
super(`Validation Error: ${typeName} is required, but received ${received}.`, [
|
|
10
|
-
|
|
9
|
+
DomainExceptionCode.RequiredValue,
|
|
11
10
|
]);
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
13
|
_a = RequiredValueException;
|
|
15
14
|
(() => {
|
|
16
|
-
ExceptionBrand.brandClass(_a,
|
|
15
|
+
ExceptionBrand.brandClass(_a, DomainExceptionCode.RequiredValue);
|
|
17
16
|
})();
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
var _a;
|
|
2
|
+
import { ExceptionBrand, ReceivedValue } from '../../shared/index.js';
|
|
3
|
+
import { DomainExceptionCode } from './domain-exception-code.js';
|
|
2
4
|
import { DomainException } from './domain.exception.js';
|
|
3
|
-
import { ExceptionBrand } from '../brand/exception-brand.js';
|
|
4
|
-
import { ExceptionCode } from '../exception-code.js';
|
|
5
|
-
import { ReceivedValue } from '../received/received-value.js';
|
|
6
5
|
export class TypePrimitiveException extends DomainException {
|
|
7
6
|
constructor(expectedType, receivedValue, template = 'Expected a valid ') {
|
|
8
7
|
const received = ReceivedValue.describe(receivedValue);
|
|
9
8
|
super(`Validation Error: ${template}${expectedType}, but received ${received}.`, [
|
|
10
|
-
|
|
9
|
+
DomainExceptionCode.TypeFailed,
|
|
11
10
|
]);
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
13
|
_a = TypePrimitiveException;
|
|
15
14
|
(() => {
|
|
16
|
-
ExceptionBrand.brandClass(_a,
|
|
15
|
+
ExceptionBrand.brandClass(_a, DomainExceptionCode.TypeFailed);
|
|
17
16
|
})();
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
var _a;
|
|
2
|
+
import { ExceptionBrand } from '../../shared/index.js';
|
|
3
|
+
import { DomainExceptionCode } from './domain-exception-code.js';
|
|
2
4
|
import { DomainException } from './domain.exception.js';
|
|
3
|
-
import { ExceptionBrand } from '../brand/exception-brand.js';
|
|
4
|
-
import { ExceptionCode } from '../exception-code.js';
|
|
5
5
|
export class ValidationException extends DomainException {
|
|
6
6
|
constructor(errors) {
|
|
7
7
|
super(`Validation failed, ${errors.map(_a.describe).join(', ')}`, [
|
|
8
|
-
|
|
8
|
+
DomainExceptionCode.ValidationFailed,
|
|
9
9
|
]);
|
|
10
|
-
this.errors = Object.freeze(errors.map(({ field, code =
|
|
10
|
+
this.errors = Object.freeze(errors.map(({ field, code = DomainExceptionCode.ValidationFailed, message }) => Object.freeze({ field, code, message })));
|
|
11
11
|
}
|
|
12
12
|
static describe(issue) {
|
|
13
13
|
return issue.field === null ? issue.message : `${issue.field}: ${issue.message}`;
|
|
@@ -15,5 +15,5 @@ export class ValidationException extends DomainException {
|
|
|
15
15
|
}
|
|
16
16
|
_a = ValidationException;
|
|
17
17
|
(() => {
|
|
18
|
-
ExceptionBrand.brandClass(_a,
|
|
18
|
+
ExceptionBrand.brandClass(_a, DomainExceptionCode.ValidationFailed);
|
|
19
19
|
})();
|
|
@@ -8,3 +8,10 @@ export type { AggregateSaver } from './repository/aggregate-saver.js';
|
|
|
8
8
|
export type { AggregateRemover } from './repository/aggregate-remover.js';
|
|
9
9
|
export { Specification } from './specification/specification.js';
|
|
10
10
|
export type { SatisfiedBy } from './specification/specification.js';
|
|
11
|
+
export { DomainException } from './exceptions/domain.exception.js';
|
|
12
|
+
export { ValidationException } from './exceptions/validation.exception.js';
|
|
13
|
+
export type { ValidationIssue, ValidationIssueInput } from './exceptions/validation.exception.js';
|
|
14
|
+
export { TypePrimitiveException } from './exceptions/type-primitive.exception.js';
|
|
15
|
+
export { RequiredValueException } from './exceptions/required-value.exception.js';
|
|
16
|
+
export { InvalidEventDefinitionException } from './exceptions/invalid-event-definition.exception.js';
|
|
17
|
+
export { DomainExceptionCode } from './exceptions/domain-exception-code.js';
|
package/dist/esm/domain/index.js
CHANGED
|
@@ -4,3 +4,9 @@ export * from './aggregate/aggregate-root.js';
|
|
|
4
4
|
export * from './type/index.js';
|
|
5
5
|
export * from './primitive/primitive-types.js';
|
|
6
6
|
export { Specification } from './specification/specification.js';
|
|
7
|
+
export { DomainException } from './exceptions/domain.exception.js';
|
|
8
|
+
export { ValidationException } from './exceptions/validation.exception.js';
|
|
9
|
+
export { TypePrimitiveException } from './exceptions/type-primitive.exception.js';
|
|
10
|
+
export { RequiredValueException } from './exceptions/required-value.exception.js';
|
|
11
|
+
export { InvalidEventDefinitionException } from './exceptions/invalid-event-definition.exception.js';
|
|
12
|
+
export { DomainExceptionCode } from './exceptions/domain-exception-code.js';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AggregateRoot } from '../aggregate/aggregate-root.js';
|
|
2
1
|
import type { AbstractType } from '../type/abstract-type.js';
|
|
3
2
|
export type Methods<T> = {
|
|
4
3
|
[P in keyof T]-?: T[P] extends Function ? P : never;
|
|
@@ -13,9 +12,8 @@ type RemoveUnderscore<S extends string> = S extends `_${infer R}` ? R : S;
|
|
|
13
12
|
type Mutable<T> = {
|
|
14
13
|
-readonly [P in keyof T]: T[P];
|
|
15
14
|
};
|
|
16
|
-
type AggregateBookkeeping<T> = T extends AggregateRoot<any, any> ? 'version' : never;
|
|
17
15
|
export type PrimitiveTypes<T> = {
|
|
18
|
-
[key in keyof Mutable<Properties<T>> as
|
|
16
|
+
[key in keyof Mutable<Properties<T>> as RemoveUnderscore<string & key>]: PrimitiveType<T[key]>;
|
|
19
17
|
};
|
|
20
18
|
export type DataTypes<T> = Partial<PrimitiveTypes<T>>;
|
|
21
19
|
export type PrimitiveType<T> = T extends (infer U)[] ? PrimitiveType<U>[] : T extends AbstractType<any> ? T['value'] : T extends null ? null : T extends Date ? never : T extends object ? PrimitiveTypes<T> : never;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Validatable, ValidationResult } from '@archi-code/validation';
|
|
2
|
-
import type {
|
|
3
|
-
import type { ValidationIssue } from '
|
|
4
|
-
type
|
|
2
|
+
import type { RequiredMarked } from './required/required-mark.js';
|
|
3
|
+
import type { ValidationIssue } from '../exceptions/validation.exception.js';
|
|
4
|
+
export type ValueOf<T, I> = I extends RequiredMarked ? T : T | null;
|
|
5
5
|
export declare abstract class AbstractType<T, Input = T> implements Validatable<T | null> {
|
|
6
6
|
protected readonly _value: T | null;
|
|
7
7
|
static [Symbol.hasInstance](candidate: unknown): boolean;
|
|
@@ -9,12 +9,10 @@ export declare abstract class AbstractType<T, Input = T> implements Validatable<
|
|
|
9
9
|
get value(): ValueOf<T, this>;
|
|
10
10
|
get isNull(): boolean;
|
|
11
11
|
toString(): string;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
equals<E extends AbstractType<any>>(other: E): boolean;
|
|
13
|
+
protected hasSameValue(other: this): boolean;
|
|
14
14
|
validate(): ValidationResult<ValueOf<T, this>>;
|
|
15
15
|
protected brokenRules(value: unknown): ValidationIssue[];
|
|
16
16
|
protected abstract filter(value: unknown): T | null;
|
|
17
|
-
private
|
|
18
|
-
private static isMissingInput;
|
|
17
|
+
private runRules;
|
|
19
18
|
}
|
|
20
|
-
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
import { anyToString, runValidations } from '@archi-code/validation';
|
|
3
|
-
import { ValueEquality } from './equality/value-equality.js';
|
|
4
3
|
import { RequiredMark } from './required/required-mark.js';
|
|
5
|
-
import { RequiredValueException
|
|
4
|
+
import { RequiredValueException } from '../exceptions/required-value.exception.js';
|
|
5
|
+
import { ValidationException } from '../exceptions/validation.exception.js';
|
|
6
6
|
const VALUE_OBJECT = Symbol.for('@archi-code/ddd/value-object.v1');
|
|
7
7
|
export class AbstractType {
|
|
8
8
|
static [Symbol.hasInstance](candidate) {
|
|
@@ -13,7 +13,10 @@ export class AbstractType {
|
|
|
13
13
|
candidate[VALUE_OBJECT] === true));
|
|
14
14
|
}
|
|
15
15
|
constructor(value = null) {
|
|
16
|
-
this._value = this.
|
|
16
|
+
this._value = value === null || value === undefined ? null : this.filter(value);
|
|
17
|
+
if (this._value === null && RequiredMark.isMarked(this)) {
|
|
18
|
+
throw new RequiredValueException(this.constructor.name, value);
|
|
19
|
+
}
|
|
17
20
|
const brokenRules = this.brokenRules(this._value);
|
|
18
21
|
if (brokenRules.length > 0) {
|
|
19
22
|
throw new ValidationException(brokenRules);
|
|
@@ -28,35 +31,24 @@ export class AbstractType {
|
|
|
28
31
|
toString() {
|
|
29
32
|
return this.isNull ? '' : anyToString(this._value);
|
|
30
33
|
}
|
|
31
|
-
toJSON() {
|
|
32
|
-
const value = this._value;
|
|
33
|
-
return (value instanceof Date ? value.toISOString() : value);
|
|
34
|
-
}
|
|
35
34
|
equals(other) {
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
return other?.constructor === this.constructor && this.hasSameValue(other);
|
|
36
|
+
}
|
|
37
|
+
hasSameValue(other) {
|
|
38
|
+
return this._value === other._value;
|
|
40
39
|
}
|
|
41
40
|
validate() {
|
|
42
|
-
return
|
|
41
|
+
return this.runRules(this._value);
|
|
43
42
|
}
|
|
44
43
|
brokenRules(value) {
|
|
45
|
-
return
|
|
44
|
+
return this.runRules(value).errors.map((error) => ({
|
|
46
45
|
field: null,
|
|
47
46
|
code: 'validator' in error ? error.validator : error.custom,
|
|
48
47
|
message: `${this.constructor.name}: ${error.message}`,
|
|
49
48
|
}));
|
|
50
49
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (accepted === null && RequiredMark.isMarked(this)) {
|
|
54
|
-
throw new RequiredValueException(this.constructor.name, value);
|
|
55
|
-
}
|
|
56
|
-
return accepted;
|
|
57
|
-
}
|
|
58
|
-
static isMissingInput(value) {
|
|
59
|
-
return (value === null || value === undefined || (typeof value === 'string' && value.trim() === ''));
|
|
50
|
+
runRules(value) {
|
|
51
|
+
return runValidations(this.constructor, value);
|
|
60
52
|
}
|
|
61
53
|
}
|
|
62
54
|
_a = AbstractType;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ValidationResult } from '@archi-code/validation';
|
|
2
2
|
import { AbstractType } from './abstract-type.js';
|
|
3
|
-
import type { ValueOf } from './
|
|
3
|
+
import type { ValueOf } from './abstract-type.js';
|
|
4
4
|
type ItemValue<Item extends AbstractType<any>> = Item['value'];
|
|
5
5
|
export declare abstract class ArrayType<Item extends AbstractType<any>> extends AbstractType<ItemValue<Item>[]> {
|
|
6
6
|
protected abstract createItem(value: unknown): Item;
|
|
@@ -9,6 +9,7 @@ export declare abstract class ArrayType<Item extends AbstractType<any>> extends
|
|
|
9
9
|
hasItem(value: ItemValue<Item>): boolean;
|
|
10
10
|
withItem(value: ItemValue<Item>): this;
|
|
11
11
|
withoutItem(value: ItemValue<Item>): this;
|
|
12
|
+
protected hasSameValue(other: this): boolean;
|
|
12
13
|
protected filter(value: unknown): ItemValue<Item>[];
|
|
13
14
|
validate(): ValidationResult<ValueOf<ItemValue<Item>[], this>>;
|
|
14
15
|
private copyWith;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { toArray } from '@archi-code/validation';
|
|
2
2
|
import { AbstractType } from './abstract-type.js';
|
|
3
|
-
import {
|
|
4
|
-
import { ValueEquality } from './equality/value-equality.js';
|
|
5
|
-
import { ValueObjects } from './value-objects/value-objects.js';
|
|
6
|
-
import { TypePrimitiveException, ValidationException } from '../../exceptions/index.js';
|
|
3
|
+
import { TypePrimitiveException } from '../exceptions/type-primitive.exception.js';
|
|
7
4
|
export class ArrayType extends AbstractType {
|
|
8
5
|
get items() {
|
|
9
6
|
return (this._value ?? []).map((value) => this.createItem(value));
|
|
@@ -12,8 +9,8 @@ export class ArrayType extends AbstractType {
|
|
|
12
9
|
return this.items.map((item) => item.toString()).join(', ');
|
|
13
10
|
}
|
|
14
11
|
hasItem(value) {
|
|
15
|
-
const
|
|
16
|
-
return (this._value ?? []).some((current) =>
|
|
12
|
+
const item = this.createItem(value);
|
|
13
|
+
return (this._value ?? []).some((current) => this.createItem(current).equals(item));
|
|
17
14
|
}
|
|
18
15
|
withItem(value) {
|
|
19
16
|
return this.copyWith([...(this._value ?? []), value]);
|
|
@@ -22,23 +19,25 @@ export class ArrayType extends AbstractType {
|
|
|
22
19
|
if (this._value === null) {
|
|
23
20
|
return this;
|
|
24
21
|
}
|
|
25
|
-
const
|
|
26
|
-
return this.copyWith(this._value.filter((current) => !
|
|
22
|
+
const item = this.createItem(value);
|
|
23
|
+
return this.copyWith(this._value.filter((current) => !this.createItem(current).equals(item)));
|
|
24
|
+
}
|
|
25
|
+
hasSameValue(other) {
|
|
26
|
+
const otherValue = other._value;
|
|
27
|
+
if (this._value === null || otherValue === null) {
|
|
28
|
+
return this._value === otherValue;
|
|
29
|
+
}
|
|
30
|
+
return (this._value.length === otherValue.length &&
|
|
31
|
+
this._value.every((value, index) => this.createItem(value).equals(this.createItem(otherValue[index]))));
|
|
27
32
|
}
|
|
28
33
|
filter(value) {
|
|
29
34
|
const converted = toArray(value);
|
|
30
35
|
if (!converted.ok) {
|
|
31
36
|
throw new TypePrimitiveException('Array', value);
|
|
32
37
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
catch (error) {
|
|
37
|
-
if (error instanceof ValidationException) {
|
|
38
|
-
throw new ValidationException([...this.brokenRules(converted.value), ...error.errors]);
|
|
39
|
-
}
|
|
40
|
-
throw error;
|
|
41
|
-
}
|
|
38
|
+
const items = converted.value.map((item) => this.createItem(item).value);
|
|
39
|
+
Object.freeze(items);
|
|
40
|
+
return items;
|
|
42
41
|
}
|
|
43
42
|
validate() {
|
|
44
43
|
const own = super.validate();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toBoolean } from '@archi-code/validation';
|
|
2
2
|
import { AbstractType } from './abstract-type.js';
|
|
3
|
-
import { TypePrimitiveException } from '
|
|
3
|
+
import { TypePrimitiveException } from '../exceptions/type-primitive.exception.js';
|
|
4
4
|
export class BooleanType extends AbstractType {
|
|
5
5
|
filter(value) {
|
|
6
6
|
const converted = toBoolean(value);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const COMPOSITE = Symbol.for('@archi-code/ddd/composite.v1');
|
|
2
|
+
export class CompositeBrand {
|
|
3
|
+
static mark(prototype) {
|
|
4
|
+
Object.defineProperty(prototype, COMPOSITE, { value: true });
|
|
5
|
+
}
|
|
6
|
+
static isComposite(value) {
|
|
7
|
+
return (typeof value === 'object' &&
|
|
8
|
+
value !== null &&
|
|
9
|
+
value[COMPOSITE] === true);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -8,12 +8,11 @@ export interface CompositeClass {
|
|
|
8
8
|
}
|
|
9
9
|
export type FieldClass = ValueClass | CompositeClass;
|
|
10
10
|
export type FieldSpec = FieldClass | readonly [FieldClass];
|
|
11
|
-
export declare class CompositeField {
|
|
12
|
-
static
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
private static acceptOne;
|
|
11
|
+
export declare abstract class CompositeField {
|
|
12
|
+
static of(spec: FieldSpec): CompositeField;
|
|
13
|
+
abstract readonly typeName: string;
|
|
14
|
+
abstract accept(path: string, value: unknown): unknown;
|
|
15
|
+
abstract fromPrimitive(primitive: unknown): unknown;
|
|
16
|
+
abstract toPrimitive(value: unknown): unknown;
|
|
17
|
+
abstract equals(left: unknown, right: unknown): boolean;
|
|
19
18
|
}
|
|
@@ -1,59 +1,82 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { CompositeBrand } from './composite-brand.js';
|
|
2
|
+
import { CompositeIssues } from './composite-issues.js';
|
|
3
|
+
import { RequiredValueException } from '../../exceptions/required-value.exception.js';
|
|
4
|
+
import { TypePrimitiveException } from '../../exceptions/type-primitive.exception.js';
|
|
4
5
|
export class CompositeField {
|
|
5
|
-
static
|
|
6
|
-
|
|
6
|
+
static of(spec) {
|
|
7
|
+
if (Array.isArray(spec)) {
|
|
8
|
+
return new ListField(CompositeField.of(spec[0]));
|
|
9
|
+
}
|
|
10
|
+
const fieldClass = spec;
|
|
11
|
+
return CompositeBrand.isComposite(fieldClass.prototype)
|
|
12
|
+
? new NestedCompositeField(fieldClass)
|
|
13
|
+
: new ValueField(fieldClass);
|
|
7
14
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
}
|
|
16
|
+
class SingleField extends CompositeField {
|
|
17
|
+
constructor(fieldClass) {
|
|
18
|
+
super();
|
|
19
|
+
this.fieldClass = fieldClass;
|
|
12
20
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return CompositeField.acceptOne(owner, field, spec, value);
|
|
16
|
-
}
|
|
17
|
-
if (!Array.isArray(value)) {
|
|
18
|
-
throw new TypePrimitiveException(`list for ${owner}.${field}`, value);
|
|
19
|
-
}
|
|
20
|
-
return Object.freeze(value.map((item, index) => CompositeField.acceptOne(owner, `${field}.${index}`, spec[0], item)));
|
|
21
|
+
get typeName() {
|
|
22
|
+
return this.fieldClass.name;
|
|
21
23
|
}
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
throw new TypePrimitiveException('Array', primitive);
|
|
26
|
-
}
|
|
27
|
-
return ValueObjects.buildList(primitive, (item) => CompositeField.fromPrimitive(spec[0], item));
|
|
24
|
+
accept(path, value) {
|
|
25
|
+
if (value === null || value === undefined) {
|
|
26
|
+
throw new RequiredValueException(path, value);
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
? fieldClass.fromPrimitives(primitive)
|
|
32
|
-
: new fieldClass(primitive);
|
|
33
|
-
}
|
|
34
|
-
static equals(left, right) {
|
|
35
|
-
if (Array.isArray(left)) {
|
|
36
|
-
return (Array.isArray(right) &&
|
|
37
|
-
left.length === right.length &&
|
|
38
|
-
left.every((item, index) => CompositeField.equals(item, right[index])));
|
|
28
|
+
if (!(value instanceof this.fieldClass)) {
|
|
29
|
+
throw new TypePrimitiveException(`${this.typeName} for ${path}`, value);
|
|
39
30
|
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
equals(left, right) {
|
|
40
34
|
return left.equals(right);
|
|
41
35
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return CompositeField.isComposite(value)
|
|
47
|
-
? value.toPrimitives()
|
|
48
|
-
: value.value;
|
|
36
|
+
}
|
|
37
|
+
class ValueField extends SingleField {
|
|
38
|
+
fromPrimitive(primitive) {
|
|
39
|
+
return new this.fieldClass(primitive);
|
|
49
40
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
toPrimitive(value) {
|
|
42
|
+
return value.value;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
class NestedCompositeField extends SingleField {
|
|
46
|
+
fromPrimitive(primitive) {
|
|
47
|
+
return this.fieldClass.fromPrimitives(primitive);
|
|
48
|
+
}
|
|
49
|
+
toPrimitive(value) {
|
|
50
|
+
return value.toPrimitives();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class ListField extends CompositeField {
|
|
54
|
+
constructor(item) {
|
|
55
|
+
super();
|
|
56
|
+
this.item = item;
|
|
57
|
+
}
|
|
58
|
+
get typeName() {
|
|
59
|
+
return `list of ${this.item.typeName}`;
|
|
60
|
+
}
|
|
61
|
+
accept(path, value) {
|
|
62
|
+
if (!Array.isArray(value)) {
|
|
63
|
+
throw new TypePrimitiveException(`${this.typeName} for ${path}`, value);
|
|
53
64
|
}
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
return Object.freeze(value.map((item, index) => this.item.accept(`${path}.${index}`, item)));
|
|
66
|
+
}
|
|
67
|
+
fromPrimitive(primitive) {
|
|
68
|
+
if (!Array.isArray(primitive)) {
|
|
69
|
+
throw new TypePrimitiveException(this.typeName, primitive);
|
|
56
70
|
}
|
|
57
|
-
return
|
|
71
|
+
return CompositeIssues.collectItems(primitive, (item) => this.item.fromPrimitive(item));
|
|
72
|
+
}
|
|
73
|
+
toPrimitive(value) {
|
|
74
|
+
return value.map((item) => this.item.toPrimitive(item));
|
|
75
|
+
}
|
|
76
|
+
equals(left, right) {
|
|
77
|
+
const items = left;
|
|
78
|
+
return (Array.isArray(right) &&
|
|
79
|
+
items.length === right.length &&
|
|
80
|
+
items.every((item, index) => this.item.equals(item, right[index])));
|
|
58
81
|
}
|
|
59
82
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare class CompositeIssues {
|
|
2
|
+
static collectFields(builds: Readonly<Record<string, () => unknown>>): Record<string, unknown>;
|
|
3
|
+
static collectItems<Item, Built>(items: readonly Item[], build: (item: Item, index: number) => Built): Built[];
|
|
4
|
+
private static validated;
|
|
5
|
+
private static read;
|
|
6
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IssueCollectionError, IssueCollector } from '../../../shared/index.js';
|
|
2
|
+
import { DomainException } from '../../exceptions/domain.exception.js';
|
|
3
|
+
import { ValidationException } from '../../exceptions/validation.exception.js';
|
|
4
|
+
export class CompositeIssues {
|
|
5
|
+
static collectFields(builds) {
|
|
6
|
+
return CompositeIssues.validated(() => IssueCollector.collectFields(builds, CompositeIssues.read));
|
|
7
|
+
}
|
|
8
|
+
static collectItems(items, build) {
|
|
9
|
+
return CompositeIssues.validated(() => IssueCollector.collectItems(items, build, CompositeIssues.read));
|
|
10
|
+
}
|
|
11
|
+
static validated(collect) {
|
|
12
|
+
try {
|
|
13
|
+
return collect();
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error instanceof IssueCollectionError) {
|
|
17
|
+
throw new ValidationException(error.issues);
|
|
18
|
+
}
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
static read(error) {
|
|
23
|
+
if (error instanceof ValidationException) {
|
|
24
|
+
return error.errors;
|
|
25
|
+
}
|
|
26
|
+
if (error instanceof DomainException) {
|
|
27
|
+
return [{ field: null, code: error.code, message: error.message }];
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import { runValidations } from '@archi-code/validation';
|
|
2
|
+
import { CompositeBrand } from './composite-brand.js';
|
|
2
3
|
import { CompositeField } from './composite-field.js';
|
|
3
|
-
import {
|
|
4
|
-
import { TypePrimitiveException
|
|
4
|
+
import { CompositeIssues } from './composite-issues.js';
|
|
5
|
+
import { TypePrimitiveException } from '../../exceptions/type-primitive.exception.js';
|
|
6
|
+
import { ValidationException } from '../../exceptions/validation.exception.js';
|
|
5
7
|
export function Composite(schema) {
|
|
6
|
-
const fields = Object.
|
|
8
|
+
const fields = Object.entries(schema).map(([name, spec]) => [name, CompositeField.of(spec)]);
|
|
7
9
|
class CompositeValueObject {
|
|
8
10
|
static fromPrimitives(primitives) {
|
|
9
11
|
if (typeof primitives !== 'object' || primitives === null || Array.isArray(primitives)) {
|
|
10
12
|
throw new TypePrimitiveException(this.name, primitives);
|
|
11
13
|
}
|
|
12
14
|
const record = primitives;
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
() => CompositeField.fromPrimitive(schema[field], record[field]),
|
|
16
|
-
])));
|
|
17
|
-
return new this(props);
|
|
15
|
+
const builds = Object.fromEntries(fields.map(([name, field]) => [name, () => field.fromPrimitive(record[name])]));
|
|
16
|
+
return new this(CompositeIssues.collectFields(builds));
|
|
18
17
|
}
|
|
19
18
|
constructor(props) {
|
|
20
19
|
const owner = this.constructor.name;
|
|
21
|
-
for (const field of fields) {
|
|
22
|
-
Object.defineProperty(this,
|
|
23
|
-
value:
|
|
20
|
+
for (const [name, field] of fields) {
|
|
21
|
+
Object.defineProperty(this, name, {
|
|
22
|
+
value: field.accept(`${owner}.${name}`, props?.[name]),
|
|
24
23
|
enumerable: true,
|
|
25
24
|
});
|
|
26
25
|
}
|
|
@@ -38,15 +37,12 @@ export function Composite(schema) {
|
|
|
38
37
|
return (typeof other === 'object' &&
|
|
39
38
|
other !== null &&
|
|
40
39
|
other.constructor === this.constructor &&
|
|
41
|
-
fields.every((field) =>
|
|
40
|
+
fields.every(([name, field]) => field.equals(this[name], other[name])));
|
|
42
41
|
}
|
|
43
42
|
toPrimitives() {
|
|
44
|
-
return Object.fromEntries(fields.map((field) => [
|
|
45
|
-
field,
|
|
46
|
-
CompositeField.primitive(this[field]),
|
|
47
|
-
]));
|
|
43
|
+
return Object.fromEntries(fields.map(([name, field]) => [name, field.toPrimitive(this[name])]));
|
|
48
44
|
}
|
|
49
45
|
}
|
|
50
|
-
|
|
46
|
+
CompositeBrand.mark(CompositeValueObject.prototype);
|
|
51
47
|
return CompositeValueObject;
|
|
52
48
|
}
|
|
@@ -2,14 +2,15 @@ import { AbstractType } from './abstract-type.js';
|
|
|
2
2
|
export declare class DateType extends AbstractType<Date, Date | string> {
|
|
3
3
|
protected filter(value: unknown): Date;
|
|
4
4
|
toString(): string;
|
|
5
|
+
protected hasSameValue(other: this): boolean;
|
|
5
6
|
}
|
|
6
|
-
declare const CreatedAt_base: import("./required/required.js").RequiredType<typeof DateType>;
|
|
7
|
+
declare const CreatedAt_base: import("./required/required-type.js").RequiredType<typeof DateType>;
|
|
7
8
|
export declare class CreatedAt extends CreatedAt_base {
|
|
8
9
|
static now(clock?: {
|
|
9
10
|
now(): Date;
|
|
10
11
|
}): CreatedAt;
|
|
11
12
|
}
|
|
12
|
-
declare const UpdatedAt_base: import("./required/required.js").RequiredType<typeof DateType>;
|
|
13
|
+
declare const UpdatedAt_base: import("./required/required-type.js").RequiredType<typeof DateType>;
|
|
13
14
|
export declare class UpdatedAt extends UpdatedAt_base {
|
|
14
15
|
static now(clock?: {
|
|
15
16
|
now(): Date;
|