import { REPORTS_ROOT } from "./paths"; import { LIFECYCLE_STATES as STATES, LifecycleError, lifecycleOf as lifecycleOfRead, readLifecycle as readAt, setLifecycle as setAt, } from "./lifecycle.mjs"; // The app's view of lib/lifecycle.mjs, typed and bound to REPORTS_ROOT. The // logic, the file format and the rules are there (plain ESM, unit-tested). export type LifecycleState = "active" | "parked" | "done"; export type LifecycleEntry = { state: LifecycleState; at: string; by?: string }; export type LifecycleRead = { pieces: Record; error?: string }; export const LIFECYCLE_STATES = STATES as LifecycleState[]; export { LifecycleError }; export const isLifecycleState = (s: unknown): s is LifecycleState => (LIFECYCLE_STATES as unknown[]).includes(s); export async function readLifecycle(): Promise { return (await readAt(REPORTS_ROOT)) as LifecycleRead; } export function lifecycleOf(read: LifecycleRead, id: string): LifecycleState { return lifecycleOfRead(read, id) as LifecycleState; } export async function setLifecycle(id: string, state: LifecycleState, by?: string): Promise { return (await setAt(REPORTS_ROOT, id, state, { by })) as LifecycleEntry & { id: string }; } /** Parked and done pieces are out of the way: their decisions are `hidden`. */ export const isQuiet = (state: LifecycleState): boolean => state !== "active";