import { ORG_ROLES, type OrgRole } from "../db/schema"; /** * The role ladder, kept apart from `./scope.ts` because that module opens a * database connection on import and this comparison needs nothing but the * enum. Tests can exercise the ladder without Postgres. */ const RANK: Record = Object.fromEntries( ORG_ROLES.map((role, index) => [role, index]), ) as Record; /** Whether `actual` is at least as privileged as `minimum`. */ export function roleSatisfies(actual: OrgRole, minimum: OrgRole): boolean { return RANK[actual] >= RANK[minimum]; } export { ORG_ROLES, type OrgRole };