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,50 @@
|
||||
/**
|
||||
* In-Memory FieldSession Repository
|
||||
*
|
||||
* Adapter: Implements FieldSessionRepository using a Map.
|
||||
* Purpose: Testing, development, CI/CD pipelines.
|
||||
* NOT for production.
|
||||
*
|
||||
* ADR-006: In-memory adapters for testing
|
||||
* - Fast, isolated, no external dependencies
|
||||
* - Reset between tests
|
||||
* - Never used in production
|
||||
*/
|
||||
|
||||
import {
|
||||
FieldSession,
|
||||
SessionId,
|
||||
} from '@landvex/domain';
|
||||
import { FieldSessionRepository } from '../repositories/repository-interfaces';
|
||||
|
||||
export class InMemoryFieldSessionRepository implements FieldSessionRepository {
|
||||
private sessions = new Map<string, FieldSession>();
|
||||
|
||||
async save(session: FieldSession): Promise<void> {
|
||||
this.sessions.set(session.id, session);
|
||||
}
|
||||
|
||||
async findById(id: SessionId): Promise<FieldSession | null> {
|
||||
return this.sessions.get(id) ?? null;
|
||||
}
|
||||
|
||||
async findActive(): Promise<FieldSession[]> {
|
||||
return Array.from(this.sessions.values())
|
||||
.filter(s => s.status === 'planned' || s.status === 'active');
|
||||
}
|
||||
|
||||
async findByDateRange(start: Date, end: Date): Promise<FieldSession[]> {
|
||||
return Array.from(this.sessions.values())
|
||||
.filter(s => s.date >= start && s.date <= end);
|
||||
}
|
||||
|
||||
/** Reset for testing */
|
||||
clear(): void {
|
||||
this.sessions.clear();
|
||||
}
|
||||
|
||||
/** Count for assertions */
|
||||
count(): number {
|
||||
return this.sessions.size;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user