mirror of
https://github.com/urbit/shrub.git
synced 2024-12-21 09:51:36 +03:00
16 lines
537 B
TypeScript
16 lines
537 B
TypeScript
import { roleTags, RoleTags, Group, Resource } from '../types/group-update';
|
|
import { PatpNoSig, Path } from '../types/noun';
|
|
|
|
|
|
export function roleForShip(group: Group, ship: PatpNoSig): RoleTags | undefined {
|
|
return roleTags.reduce((currRole, role) => {
|
|
const roleShips = group.tags.role[role];
|
|
return roleShips && roleShips.has(ship) ? role : currRole;
|
|
}, undefined as RoleTags | undefined);
|
|
}
|
|
|
|
export function resourceFromPath(path: Path): Resource {
|
|
const [, , ship, name] = path.split('/');
|
|
return { ship, name }
|
|
}
|