import type { WorkflowActivationPolicy, WorkflowId } from "@codemation/core"; import { injectable } from "@codemation/core"; import type { WorkflowActivationRepository } from "../../domain/workflows/WorkflowActivationRepository"; @injectable() export class RuntimeWorkflowActivationPolicy implements WorkflowActivationPolicy { private readonly activeByWorkflowId = new Map(); async hydrateFromRepository(repository: WorkflowActivationRepository): Promise { const rows = await repository.loadAll(); this.activeByWorkflowId.clear(); for (const row of rows) { this.activeByWorkflowId.set(decodeURIComponent(row.workflowId), row.isActive); } } set(workflowId: string, active: boolean): void { this.activeByWorkflowId.set(decodeURIComponent(workflowId), active); } isActive(workflowId: WorkflowId): boolean { return this.activeByWorkflowId.get(workflowId) ?? false; } }