import type { FeatureLifecycleStage, IFeatureLifecycleStore, FeatureLifecycleView, NewStage, } from './feature-lifecycle-store-type.js'; export class FakeFeatureLifecycleStore implements IFeatureLifecycleStore { private lifecycles: Record = {}; async insert( featureLifecycleStages: FeatureLifecycleStage[], ): Promise { const results = await Promise.all( featureLifecycleStages.map(async (stage) => { const success = await this.insertOne(stage); if (success) { return { feature: stage.feature, stage: stage.stage, }; } return null; }), ); return results.filter((result) => result !== null) as NewStage[]; } async backfill() {} private async insertOne( featureLifecycleStage: FeatureLifecycleStage, ): Promise { if (await this.stageExists(featureLifecycleStage)) { return false; } const newStages: NewStage[] = []; const existingStages = await this.get(featureLifecycleStage.feature); this.lifecycles[featureLifecycleStage.feature] = [ ...existingStages, { stage: featureLifecycleStage.stage, ...(featureLifecycleStage.status ? { status: featureLifecycleStage.status } : {}), enteredStageAt: new Date(), }, ]; return true; } async get(feature: string): Promise { return this.lifecycles[feature] || []; } async delete(feature: string): Promise { this.lifecycles[feature] = []; } async deleteAll(): Promise { this.lifecycles = {}; } async stageExists(stage: FeatureLifecycleStage): Promise { const lifecycle = await this.get(stage.feature); return Boolean(lifecycle.find((s) => s.stage === stage.stage)); } async deleteStage(stage: FeatureLifecycleStage): Promise { if (!this.lifecycles[stage.feature]) { return; } const updatedStages = this.lifecycles[stage.feature].filter( (s) => s.stage !== stage.stage, ); this.lifecycles[stage.feature] = updatedStages; } }