64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import { Schema } from "effect";
|
|
|
|
export const WorkStatus = Schema.Literals([
|
|
"proposed",
|
|
"defining",
|
|
"awaiting-definition-approval",
|
|
"designing",
|
|
"awaiting-design-approval",
|
|
"ready",
|
|
"executing",
|
|
"verifying",
|
|
"needs-input",
|
|
"blocked",
|
|
"completed",
|
|
"failed",
|
|
"cancelled",
|
|
]);
|
|
export type WorkStatus = typeof WorkStatus.Type;
|
|
|
|
export const WORK_TRANSITIONS: Readonly<
|
|
Record<WorkStatus, readonly WorkStatus[]>
|
|
> = {
|
|
"awaiting-definition-approval": ["defining", "cancelled"],
|
|
"awaiting-design-approval": ["designing", "cancelled"],
|
|
blocked: ["ready", "defining", "designing", "executing", "cancelled"],
|
|
cancelled: ["ready"],
|
|
completed: [],
|
|
defining: ["designing", "proposed"],
|
|
designing: ["ready", "defining"],
|
|
executing: [
|
|
"ready",
|
|
"verifying",
|
|
"needs-input",
|
|
"blocked",
|
|
"completed",
|
|
"failed",
|
|
"cancelled",
|
|
],
|
|
failed: ["ready", "executing", "cancelled"],
|
|
"needs-input": ["ready", "executing", "cancelled"],
|
|
proposed: ["defining"],
|
|
ready: ["executing", "designing", "cancelled"],
|
|
verifying: [
|
|
"ready",
|
|
"executing",
|
|
"completed",
|
|
"blocked",
|
|
"failed",
|
|
"cancelled",
|
|
],
|
|
};
|
|
|
|
export const canTransitionWork = (from: WorkStatus, to: WorkStatus): boolean =>
|
|
WORK_TRANSITIONS[from].includes(to);
|
|
|
|
export const assertWorkTransition = (
|
|
from: WorkStatus,
|
|
to: WorkStatus
|
|
): void => {
|
|
if (!canTransitionWork(from, to)) {
|
|
throw new Error(`Invalid Work transition: ${from} -> ${to}`);
|
|
}
|
|
};
|