@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,8 @@
|
|
|
1
|
+
import type { CollectedIssue } from './issue-collection-error.js';
|
|
2
|
+
export type IssueReader = (error: unknown) => readonly CollectedIssue[] | null;
|
|
3
|
+
export declare class IssueCollector {
|
|
4
|
+
static collectFields(builds: Readonly<Record<string, () => unknown>>, readIssues: IssueReader): Record<string, unknown>;
|
|
5
|
+
static collectItems<Item, Built>(items: readonly Item[], build: (item: Item, index: number) => Built, readIssues: IssueReader): Built[];
|
|
6
|
+
private static collect;
|
|
7
|
+
private static issuesAt;
|
|
8
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { IssueCollectionError } from './issue-collection-error.js';
|
|
2
|
+
export class IssueCollector {
|
|
3
|
+
static collectFields(builds, readIssues) {
|
|
4
|
+
return Object.fromEntries(IssueCollector.collect(Object.entries(builds), readIssues));
|
|
5
|
+
}
|
|
6
|
+
static collectItems(items, build, readIssues) {
|
|
7
|
+
const builds = items.map((item, index) => [String(index), () => build(item, index)]);
|
|
8
|
+
return IssueCollector.collect(builds, readIssues).map(([, built]) => built);
|
|
9
|
+
}
|
|
10
|
+
static collect(builds, readIssues) {
|
|
11
|
+
const built = [];
|
|
12
|
+
const issues = [];
|
|
13
|
+
for (const [path, build] of builds) {
|
|
14
|
+
try {
|
|
15
|
+
built.push([path, build()]);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
issues.push(...IssueCollector.issuesAt(path, error, readIssues));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (issues.length > 0) {
|
|
22
|
+
throw new IssueCollectionError(issues);
|
|
23
|
+
}
|
|
24
|
+
return built;
|
|
25
|
+
}
|
|
26
|
+
static issuesAt(path, error, readIssues) {
|
|
27
|
+
const issues = readIssues(error);
|
|
28
|
+
if (issues === null) {
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
return issues.map((issue) => ({
|
|
32
|
+
field: issue.field === null ? path : `${path}.${issue.field}`,
|
|
33
|
+
code: issue.code,
|
|
34
|
+
message: issue.message,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@archi-code/ddd",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.2",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"DDD",
|
|
6
6
|
"domain-driven design",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"domain events",
|
|
12
12
|
"use case",
|
|
13
13
|
"repository",
|
|
14
|
-
"node"
|
|
14
|
+
"node",
|
|
15
|
+
"browser"
|
|
15
16
|
],
|
|
16
17
|
"author": "Jose Guillermo",
|
|
17
18
|
"license": "MIT",
|
|
@@ -26,16 +27,6 @@
|
|
|
26
27
|
"access": "public"
|
|
27
28
|
},
|
|
28
29
|
"exports": {
|
|
29
|
-
"./exceptions": {
|
|
30
|
-
"import": {
|
|
31
|
-
"types": "./dist/esm/exceptions/index.d.ts",
|
|
32
|
-
"default": "./dist/esm/exceptions/index.js"
|
|
33
|
-
},
|
|
34
|
-
"require": {
|
|
35
|
-
"types": "./dist/cjs/exceptions/index.d.ts",
|
|
36
|
-
"default": "./dist/cjs/exceptions/index.js"
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
30
|
"./domain": {
|
|
40
31
|
"import": {
|
|
41
32
|
"types": "./dist/esm/domain/index.d.ts",
|
|
@@ -70,9 +61,6 @@
|
|
|
70
61
|
},
|
|
71
62
|
"typesVersions": {
|
|
72
63
|
"*": {
|
|
73
|
-
"exceptions": [
|
|
74
|
-
"./dist/cjs/exceptions/index.d.ts"
|
|
75
|
-
],
|
|
76
64
|
"domain": [
|
|
77
65
|
"./dist/cjs/domain/index.d.ts"
|
|
78
66
|
],
|
|
@@ -89,6 +77,7 @@
|
|
|
89
77
|
"SKILL.md",
|
|
90
78
|
"ddd-skills/"
|
|
91
79
|
],
|
|
80
|
+
"sideEffects": false,
|
|
92
81
|
"scripts": {
|
|
93
82
|
"prebuild": "rm -rf dist || true",
|
|
94
83
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
@@ -97,12 +86,12 @@
|
|
|
97
86
|
"test": "vitest run",
|
|
98
87
|
"test:coverage": "vitest run --coverage",
|
|
99
88
|
"check:types": "tsc -p tsconfig.json --noEmit --incremental false",
|
|
100
|
-
"check:dist": "node ../../scripts/check-dist.js && attw --pack .",
|
|
89
|
+
"check:dist": "node ../../scripts/check-dist.js && attw --pack . && node ../../scripts/check-browser.js",
|
|
101
90
|
"check:all": "npm run check:types && npm run test:coverage && npm run build && npm run check:dist"
|
|
102
91
|
},
|
|
103
92
|
"dependencies": {
|
|
104
|
-
"@archi-code/validation": "3.0.0-alpha.
|
|
93
|
+
"@archi-code/validation": "3.0.0-alpha.6",
|
|
105
94
|
"uuid": "^11.1.1"
|
|
106
95
|
},
|
|
107
|
-
"releaseCommit": "
|
|
96
|
+
"releaseCommit": "90204648d023639e296f0946e2c715b8a32a47ef"
|
|
108
97
|
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValueEquality = void 0;
|
|
4
|
-
class ValueEquality {
|
|
5
|
-
static equals(left, right) {
|
|
6
|
-
if (left === right || (Number.isNaN(left) && Number.isNaN(right))) {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
if (left instanceof Date || right instanceof Date) {
|
|
10
|
-
return ValueEquality.sameInstant(left, right);
|
|
11
|
-
}
|
|
12
|
-
if (Array.isArray(left) || Array.isArray(right)) {
|
|
13
|
-
return ValueEquality.sameItems(left, right);
|
|
14
|
-
}
|
|
15
|
-
if (ValueEquality.isRecord(left) && ValueEquality.isRecord(right)) {
|
|
16
|
-
return ValueEquality.sameEntries(left, right);
|
|
17
|
-
}
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
static sameInstant(left, right) {
|
|
21
|
-
return (left instanceof Date &&
|
|
22
|
-
right instanceof Date &&
|
|
23
|
-
ValueEquality.equals(left.getTime(), right.getTime()));
|
|
24
|
-
}
|
|
25
|
-
static sameItems(left, right) {
|
|
26
|
-
return (Array.isArray(left) &&
|
|
27
|
-
Array.isArray(right) &&
|
|
28
|
-
left.length === right.length &&
|
|
29
|
-
left.every((item, index) => ValueEquality.equals(item, right[index])));
|
|
30
|
-
}
|
|
31
|
-
static sameEntries(left, right) {
|
|
32
|
-
const keys = Object.keys(left);
|
|
33
|
-
return (keys.length === Object.keys(right).length &&
|
|
34
|
-
keys.every((key) => Object.prototype.hasOwnProperty.call(right, key) &&
|
|
35
|
-
ValueEquality.equals(left[key], right[key])));
|
|
36
|
-
}
|
|
37
|
-
static isRecord(value) {
|
|
38
|
-
return typeof value === 'object' && value !== null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.ValueEquality = ValueEquality;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImmutableDate = void 0;
|
|
4
|
-
class ImmutableDate extends Date {
|
|
5
|
-
constructor(date) {
|
|
6
|
-
super(date.getTime());
|
|
7
|
-
Object.freeze(this);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.ImmutableDate = ImmutableDate;
|
|
11
|
-
ImmutableDate.setters = [
|
|
12
|
-
'setDate',
|
|
13
|
-
'setFullYear',
|
|
14
|
-
'setHours',
|
|
15
|
-
'setMilliseconds',
|
|
16
|
-
'setMinutes',
|
|
17
|
-
'setMonth',
|
|
18
|
-
'setSeconds',
|
|
19
|
-
'setTime',
|
|
20
|
-
'setUTCDate',
|
|
21
|
-
'setUTCFullYear',
|
|
22
|
-
'setUTCHours',
|
|
23
|
-
'setUTCMilliseconds',
|
|
24
|
-
'setUTCMinutes',
|
|
25
|
-
'setUTCMonth',
|
|
26
|
-
'setUTCSeconds',
|
|
27
|
-
'setYear',
|
|
28
|
-
];
|
|
29
|
-
(() => {
|
|
30
|
-
for (const setter of ImmutableDate.setters) {
|
|
31
|
-
Object.defineProperty(ImmutableDate.prototype, setter, {
|
|
32
|
-
value() {
|
|
33
|
-
throw new TypeError(`Cannot call ${setter}: the date is immutable`);
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
})();
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Immutable = void 0;
|
|
4
|
-
const immutable_date_1 = require("./immutable-date");
|
|
5
|
-
class Immutable {
|
|
6
|
-
static freeze(value) {
|
|
7
|
-
if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
8
|
-
Object.freeze(value);
|
|
9
|
-
for (const child of Object.values(value)) {
|
|
10
|
-
Immutable.freeze(child);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
static date(date) {
|
|
16
|
-
return new immutable_date_1.ImmutableDate(date);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.Immutable = Immutable;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValueObjects = void 0;
|
|
4
|
-
const index_1 = require("../../../exceptions/index");
|
|
5
|
-
class ValueObjects {
|
|
6
|
-
static build(factories) {
|
|
7
|
-
const built = {};
|
|
8
|
-
const issues = [];
|
|
9
|
-
for (const [field, factory] of Object.entries(factories)) {
|
|
10
|
-
try {
|
|
11
|
-
Object.defineProperty(built, field, {
|
|
12
|
-
value: ValueObjects.synchronous(field, factory()),
|
|
13
|
-
enumerable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
configurable: true,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
issues.push(...ValueObjects.issuesOf(field, error));
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
ValueObjects.assertNoIssues(issues);
|
|
23
|
-
return built;
|
|
24
|
-
}
|
|
25
|
-
static buildList(values, factory) {
|
|
26
|
-
const built = [];
|
|
27
|
-
const issues = [];
|
|
28
|
-
values.forEach((value, index) => {
|
|
29
|
-
try {
|
|
30
|
-
built.push(ValueObjects.synchronous(String(index), factory(value, index)));
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
issues.push(...ValueObjects.issuesOf(String(index), error));
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
ValueObjects.assertNoIssues(issues);
|
|
37
|
-
return built;
|
|
38
|
-
}
|
|
39
|
-
static synchronous(field, result) {
|
|
40
|
-
if (!ValueObjects.isThenable(result)) {
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
result.then(undefined, () => undefined);
|
|
44
|
-
throw new index_1.InternalErrorException(`ValueObjects: the factory of "${field}" returned a Promise; build value objects synchronously`);
|
|
45
|
-
}
|
|
46
|
-
static isThenable(result) {
|
|
47
|
-
return ((typeof result === 'object' || typeof result === 'function') &&
|
|
48
|
-
result !== null &&
|
|
49
|
-
typeof result.then === 'function');
|
|
50
|
-
}
|
|
51
|
-
static issuesOf(field, error) {
|
|
52
|
-
if (error instanceof index_1.ValidationException) {
|
|
53
|
-
return error.errors.map((issue) => ({
|
|
54
|
-
field: issue.field === null ? field : `${field}.${issue.field}`,
|
|
55
|
-
code: issue.code,
|
|
56
|
-
message: issue.message,
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
if (error instanceof index_1.DomainException) {
|
|
60
|
-
return [{ field, code: error.code, message: error.message }];
|
|
61
|
-
}
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
static assertNoIssues(issues) {
|
|
65
|
-
if (issues.length > 0) {
|
|
66
|
-
throw new index_1.ValidationException(issues);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.ValueObjects = ValueObjects;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { AbstractException } from '../abstract.exception';
|
|
2
|
-
import type { ExceptionOptions } from '../abstract.exception';
|
|
3
|
-
import { ExceptionCode } from '../exception-code';
|
|
4
|
-
export declare class ApplicationException extends AbstractException {
|
|
5
|
-
constructor(message: string, exceptionCodes?: (ExceptionCode | string)[], options?: ExceptionOptions);
|
|
6
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.ApplicationException = void 0;
|
|
5
|
-
const abstract_exception_1 = require("../abstract.exception");
|
|
6
|
-
const exception_brand_1 = require("../brand/exception-brand");
|
|
7
|
-
const exception_code_1 = require("../exception-code");
|
|
8
|
-
class ApplicationException extends abstract_exception_1.AbstractException {
|
|
9
|
-
constructor(message, exceptionCodes = [], options = {}) {
|
|
10
|
-
super(message, [exception_code_1.ExceptionCode.ApplicationException, ...exceptionCodes], options);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.ApplicationException = ApplicationException;
|
|
14
|
-
_a = ApplicationException;
|
|
15
|
-
(() => {
|
|
16
|
-
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.ApplicationException);
|
|
17
|
-
})();
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { AbstractException } from '../abstract.exception';
|
|
2
|
-
import type { ExceptionOptions } from '../abstract.exception';
|
|
3
|
-
import { ExceptionCode } from '../exception-code';
|
|
4
|
-
export declare class DomainException extends AbstractException {
|
|
5
|
-
constructor(message: string, exceptionCodes?: (ExceptionCode | string)[], options?: ExceptionOptions);
|
|
6
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.DomainException = void 0;
|
|
5
|
-
const abstract_exception_1 = require("../abstract.exception");
|
|
6
|
-
const exception_brand_1 = require("../brand/exception-brand");
|
|
7
|
-
const exception_code_1 = require("../exception-code");
|
|
8
|
-
class DomainException extends abstract_exception_1.AbstractException {
|
|
9
|
-
constructor(message, exceptionCodes = [], options = {}) {
|
|
10
|
-
super(message, [exception_code_1.ExceptionCode.DomainException, ...exceptionCodes], options);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.DomainException = DomainException;
|
|
14
|
-
_a = DomainException;
|
|
15
|
-
(() => {
|
|
16
|
-
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.DomainException);
|
|
17
|
-
})();
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare enum ExceptionCode {
|
|
2
|
-
DomainException = "DOM000",
|
|
3
|
-
ValidationFailed = "DOM001",
|
|
4
|
-
TypeFailed = "DOM003",
|
|
5
|
-
RequiredValue = "DOM004",
|
|
6
|
-
ApplicationException = "APP000",
|
|
7
|
-
ConcurrencyConflict = "APP001",
|
|
8
|
-
AggregateNotFound = "APP002",
|
|
9
|
-
NotAllowed = "APP003",
|
|
10
|
-
InfrastructureException = "INF000",
|
|
11
|
-
InternalError = "INF001",
|
|
12
|
-
UnknownEvent = "INF002",
|
|
13
|
-
EventDelivery = "INF003",
|
|
14
|
-
ErrorException = "E000"
|
|
15
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExceptionCode = void 0;
|
|
4
|
-
var ExceptionCode;
|
|
5
|
-
(function (ExceptionCode) {
|
|
6
|
-
ExceptionCode["DomainException"] = "DOM000";
|
|
7
|
-
ExceptionCode["ValidationFailed"] = "DOM001";
|
|
8
|
-
ExceptionCode["TypeFailed"] = "DOM003";
|
|
9
|
-
ExceptionCode["RequiredValue"] = "DOM004";
|
|
10
|
-
ExceptionCode["ApplicationException"] = "APP000";
|
|
11
|
-
ExceptionCode["ConcurrencyConflict"] = "APP001";
|
|
12
|
-
ExceptionCode["AggregateNotFound"] = "APP002";
|
|
13
|
-
ExceptionCode["NotAllowed"] = "APP003";
|
|
14
|
-
ExceptionCode["InfrastructureException"] = "INF000";
|
|
15
|
-
ExceptionCode["InternalError"] = "INF001";
|
|
16
|
-
ExceptionCode["UnknownEvent"] = "INF002";
|
|
17
|
-
ExceptionCode["EventDelivery"] = "INF003";
|
|
18
|
-
ExceptionCode["ErrorException"] = "E000";
|
|
19
|
-
})(ExceptionCode || (exports.ExceptionCode = ExceptionCode = {}));
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export * from './abstract.exception';
|
|
2
|
-
export * from './exception-code';
|
|
3
|
-
export * from './application/application.exception';
|
|
4
|
-
export * from './application/concurrency.exception';
|
|
5
|
-
export * from './application/aggregate-not-found.exception';
|
|
6
|
-
export * from './application/not-allowed.exception';
|
|
7
|
-
export * from './infrastructure/infrastructure.exception';
|
|
8
|
-
export * from './infrastructure/internal-error.exception';
|
|
9
|
-
export * from './infrastructure/unknown-event.exception';
|
|
10
|
-
export * from './infrastructure/event-delivery.exception';
|
|
11
|
-
export * from './domain/validation.exception';
|
|
12
|
-
export * from './domain/domain.exception';
|
|
13
|
-
export * from './domain/required-value.exception';
|
|
14
|
-
export * from './domain/type-primitive.exception';
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./abstract.exception"), exports);
|
|
18
|
-
__exportStar(require("./exception-code"), exports);
|
|
19
|
-
__exportStar(require("./application/application.exception"), exports);
|
|
20
|
-
__exportStar(require("./application/concurrency.exception"), exports);
|
|
21
|
-
__exportStar(require("./application/aggregate-not-found.exception"), exports);
|
|
22
|
-
__exportStar(require("./application/not-allowed.exception"), exports);
|
|
23
|
-
__exportStar(require("./infrastructure/infrastructure.exception"), exports);
|
|
24
|
-
__exportStar(require("./infrastructure/internal-error.exception"), exports);
|
|
25
|
-
__exportStar(require("./infrastructure/unknown-event.exception"), exports);
|
|
26
|
-
__exportStar(require("./infrastructure/event-delivery.exception"), exports);
|
|
27
|
-
__exportStar(require("./domain/validation.exception"), exports);
|
|
28
|
-
__exportStar(require("./domain/domain.exception"), exports);
|
|
29
|
-
__exportStar(require("./domain/required-value.exception"), exports);
|
|
30
|
-
__exportStar(require("./domain/type-primitive.exception"), exports);
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { AbstractException } from '../abstract.exception';
|
|
2
|
-
import type { ExceptionOptions } from '../abstract.exception';
|
|
3
|
-
import { ExceptionCode } from '../exception-code';
|
|
4
|
-
export declare class InfrastructureException extends AbstractException {
|
|
5
|
-
constructor(message: string, exceptionCodes?: (ExceptionCode | string)[], options?: ExceptionOptions);
|
|
6
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.InfrastructureException = void 0;
|
|
5
|
-
const abstract_exception_1 = require("../abstract.exception");
|
|
6
|
-
const exception_brand_1 = require("../brand/exception-brand");
|
|
7
|
-
const exception_code_1 = require("../exception-code");
|
|
8
|
-
class InfrastructureException extends abstract_exception_1.AbstractException {
|
|
9
|
-
constructor(message, exceptionCodes = [], options = {}) {
|
|
10
|
-
super(message, [exception_code_1.ExceptionCode.InfrastructureException, ...exceptionCodes], options);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.InfrastructureException = InfrastructureException;
|
|
14
|
-
_a = InfrastructureException;
|
|
15
|
-
(() => {
|
|
16
|
-
exception_brand_1.ExceptionBrand.brandClass(_a, exception_code_1.ExceptionCode.InfrastructureException);
|
|
17
|
-
})();
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { ValidationIssue } from '../../exceptions';
|
|
2
|
-
import type { Logger } from '../../application/index';
|
|
3
|
-
export interface HttpErrorBody {
|
|
4
|
-
code: string;
|
|
5
|
-
message: string;
|
|
6
|
-
errors?: readonly ValidationIssue[];
|
|
7
|
-
}
|
|
8
|
-
export interface HttpError {
|
|
9
|
-
status: number;
|
|
10
|
-
body: HttpErrorBody;
|
|
11
|
-
}
|
|
12
|
-
export interface HttpErrorMapperOptions {
|
|
13
|
-
readonly statusByCode?: Readonly<Record<string, number>>;
|
|
14
|
-
readonly logger?: Logger;
|
|
15
|
-
}
|
|
16
|
-
export declare class HttpErrorMapper {
|
|
17
|
-
private readonly statusByCode;
|
|
18
|
-
private readonly logger;
|
|
19
|
-
constructor({ statusByCode, logger }?: HttpErrorMapperOptions);
|
|
20
|
-
map(error: unknown): HttpError;
|
|
21
|
-
private toHttpError;
|
|
22
|
-
private static defaultStatus;
|
|
23
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpErrorMapper = void 0;
|
|
4
|
-
const exceptions_1 = require("../../exceptions");
|
|
5
|
-
const silent_logger_1 = require("../logging/silent-logger");
|
|
6
|
-
const INTERNAL_MESSAGE = 'Internal server error';
|
|
7
|
-
class HttpErrorMapper {
|
|
8
|
-
constructor({ statusByCode = {}, logger = new silent_logger_1.SilentLogger() } = {}) {
|
|
9
|
-
this.statusByCode = statusByCode;
|
|
10
|
-
this.logger = logger;
|
|
11
|
-
}
|
|
12
|
-
map(error) {
|
|
13
|
-
const mapped = this.toHttpError(error);
|
|
14
|
-
const { status, body } = mapped;
|
|
15
|
-
if (status >= 500) {
|
|
16
|
-
this.logger.error('http_request_failed', { status, code: body.code, error });
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
this.logger.debug('http_request_rejected', { status, code: body.code });
|
|
20
|
-
}
|
|
21
|
-
return mapped;
|
|
22
|
-
}
|
|
23
|
-
toHttpError(error) {
|
|
24
|
-
if (!(error instanceof exceptions_1.AbstractException)) {
|
|
25
|
-
return {
|
|
26
|
-
status: 500,
|
|
27
|
-
body: { code: exceptions_1.ExceptionCode.ErrorException, message: INTERNAL_MESSAGE },
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const status = Object.prototype.hasOwnProperty.call(this.statusByCode, error.code)
|
|
31
|
-
? this.statusByCode[error.code]
|
|
32
|
-
: HttpErrorMapper.defaultStatus(error);
|
|
33
|
-
if (status >= 500) {
|
|
34
|
-
return { status, body: { code: error.code, message: INTERNAL_MESSAGE } };
|
|
35
|
-
}
|
|
36
|
-
if (error instanceof exceptions_1.ValidationException) {
|
|
37
|
-
return { status, body: { code: error.code, message: error.message, errors: error.errors } };
|
|
38
|
-
}
|
|
39
|
-
return { status, body: { code: error.code, message: error.message } };
|
|
40
|
-
}
|
|
41
|
-
static defaultStatus(error) {
|
|
42
|
-
if (error instanceof exceptions_1.AggregateNotFoundException) {
|
|
43
|
-
return 404;
|
|
44
|
-
}
|
|
45
|
-
if (error instanceof exceptions_1.NotAllowedException) {
|
|
46
|
-
return 403;
|
|
47
|
-
}
|
|
48
|
-
if (error instanceof exceptions_1.ConcurrencyException) {
|
|
49
|
-
return 409;
|
|
50
|
-
}
|
|
51
|
-
if (error instanceof exceptions_1.TypePrimitiveException || error instanceof exceptions_1.RequiredValueException) {
|
|
52
|
-
return 400;
|
|
53
|
-
}
|
|
54
|
-
if (error instanceof exceptions_1.DomainException) {
|
|
55
|
-
return 422;
|
|
56
|
-
}
|
|
57
|
-
if (error instanceof exceptions_1.ApplicationException) {
|
|
58
|
-
return 400;
|
|
59
|
-
}
|
|
60
|
-
return 500;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.HttpErrorMapper = HttpErrorMapper;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export class ValueEquality {
|
|
2
|
-
static equals(left, right) {
|
|
3
|
-
if (left === right || (Number.isNaN(left) && Number.isNaN(right))) {
|
|
4
|
-
return true;
|
|
5
|
-
}
|
|
6
|
-
if (left instanceof Date || right instanceof Date) {
|
|
7
|
-
return ValueEquality.sameInstant(left, right);
|
|
8
|
-
}
|
|
9
|
-
if (Array.isArray(left) || Array.isArray(right)) {
|
|
10
|
-
return ValueEquality.sameItems(left, right);
|
|
11
|
-
}
|
|
12
|
-
if (ValueEquality.isRecord(left) && ValueEquality.isRecord(right)) {
|
|
13
|
-
return ValueEquality.sameEntries(left, right);
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
static sameInstant(left, right) {
|
|
18
|
-
return (left instanceof Date &&
|
|
19
|
-
right instanceof Date &&
|
|
20
|
-
ValueEquality.equals(left.getTime(), right.getTime()));
|
|
21
|
-
}
|
|
22
|
-
static sameItems(left, right) {
|
|
23
|
-
return (Array.isArray(left) &&
|
|
24
|
-
Array.isArray(right) &&
|
|
25
|
-
left.length === right.length &&
|
|
26
|
-
left.every((item, index) => ValueEquality.equals(item, right[index])));
|
|
27
|
-
}
|
|
28
|
-
static sameEntries(left, right) {
|
|
29
|
-
const keys = Object.keys(left);
|
|
30
|
-
return (keys.length === Object.keys(right).length &&
|
|
31
|
-
keys.every((key) => Object.prototype.hasOwnProperty.call(right, key) &&
|
|
32
|
-
ValueEquality.equals(left[key], right[key])));
|
|
33
|
-
}
|
|
34
|
-
static isRecord(value) {
|
|
35
|
-
return typeof value === 'object' && value !== null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export class ImmutableDate extends Date {
|
|
2
|
-
constructor(date) {
|
|
3
|
-
super(date.getTime());
|
|
4
|
-
Object.freeze(this);
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
ImmutableDate.setters = [
|
|
8
|
-
'setDate',
|
|
9
|
-
'setFullYear',
|
|
10
|
-
'setHours',
|
|
11
|
-
'setMilliseconds',
|
|
12
|
-
'setMinutes',
|
|
13
|
-
'setMonth',
|
|
14
|
-
'setSeconds',
|
|
15
|
-
'setTime',
|
|
16
|
-
'setUTCDate',
|
|
17
|
-
'setUTCFullYear',
|
|
18
|
-
'setUTCHours',
|
|
19
|
-
'setUTCMilliseconds',
|
|
20
|
-
'setUTCMinutes',
|
|
21
|
-
'setUTCMonth',
|
|
22
|
-
'setUTCSeconds',
|
|
23
|
-
'setYear',
|
|
24
|
-
];
|
|
25
|
-
(() => {
|
|
26
|
-
for (const setter of ImmutableDate.setters) {
|
|
27
|
-
Object.defineProperty(ImmutableDate.prototype, setter, {
|
|
28
|
-
value() {
|
|
29
|
-
throw new TypeError(`Cannot call ${setter}: the date is immutable`);
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
})();
|