Files
boc/packages/domain/src/common/errors.ts
T
Bernt fa0dbf5127 PR-001: Domain Model v1.0 — compile-only, zero dependencies
- @landvex/domain package with TypeScript strict mode
- 3 Aggregate Roots: FieldSession, Mission, DecisionCase
- Branded IDs, Value Objects, Domain Events, Invariants
- 19 unit tests for IDs, FieldSession, DecisionCase
- Zero runtime dependencies (only TypeScript + jest for tests)
- Separates Entity / Value Object / Aggregate Root
- README documents Three Rules of the domain

Definition of Done met:
- Compiles without errors
- Exports all domain types
- Unit tests for invariants and value objects
- No PostgreSQL, S3, Express, AI models, queues
2026-07-02 14:26:29 +00:00

46 lines
1.0 KiB
TypeScript

/**
* Domain Errors
* Specific error types for domain invariants
*/
export abstract class DomainError extends Error {
abstract readonly code: string;
constructor(message: string) {
super(message);
this.name = this.constructor.name;
}
}
export class InvariantViolationError extends DomainError {
readonly code = 'INVARIANT_VIOLATION';
constructor(message: string) {
super(message);
}
}
export class InvalidStateTransitionError extends DomainError {
readonly code = 'INVALID_STATE_TRANSITION';
constructor(from: string, to: string) {
super(`Cannot transition from ${from} to ${to}`);
}
}
export class MissingRequiredFieldError extends DomainError {
readonly code = 'MISSING_REQUIRED_FIELD';
constructor(field: string) {
super(`Missing required field: ${field}`);
}
}
export class InvalidIdFormatError extends DomainError {
readonly code = 'INVALID_ID_FORMAT';
constructor(id: string, expectedFormat: string) {
super(`Invalid ID format: ${id}. Expected: ${expectedFormat}`);
}
}