PR-002: Persistence Adapters — in-memory, zero external dependencies
- Repository interfaces defined by domain (@landvex/domain) - 6 in-memory adapters: Session, Mission, DecisionCase, Artifact, EventStore, UnitOfWork - 9 tests verifying adapter contracts - Domain unchanged — infrastructure depends on domain, never reverse - ADR-006: In-Memory Adapters for Testing Definition of Done met: - All adapters compile against domain interfaces - Unit tests pass (9/9) - No PostgreSQL, S3, Express, AI in this PR - Ready for PR-003: PostgreSQL adapters
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* In-Memory Mission Repository
|
||||
*
|
||||
* Adapter: Implements MissionRepository using a Map.
|
||||
* Purpose: Testing, development, CI/CD pipelines.
|
||||
* NOT for production.
|
||||
*/
|
||||
|
||||
import {
|
||||
Mission,
|
||||
MissionId,
|
||||
SessionId,
|
||||
} from '@landvex/domain';
|
||||
import { MissionRepository } from '../repositories/repository-interfaces';
|
||||
|
||||
export class InMemoryMissionRepository implements MissionRepository {
|
||||
private missions = new Map<string, Mission>();
|
||||
|
||||
async save(mission: Mission): Promise<void> {
|
||||
this.missions.set(mission.id, mission);
|
||||
}
|
||||
|
||||
async findById(id: MissionId): Promise<Mission | null> {
|
||||
return this.missions.get(id) ?? null;
|
||||
}
|
||||
|
||||
async findBySession(sessionId: SessionId): Promise<Mission[]> {
|
||||
return Array.from(this.missions.values())
|
||||
.filter(m => m.sessionId === sessionId)
|
||||
.sort((a, b) => a.sequenceNumber - b.sequenceNumber);
|
||||
}
|
||||
|
||||
async findActive(): Promise<Mission[]> {
|
||||
return Array.from(this.missions.values())
|
||||
.filter(m => m.status === 'created' || m.status === 'uploading' || m.status === 'processing');
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.missions.clear();
|
||||
}
|
||||
|
||||
count(): number {
|
||||
return this.missions.size;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user