urbit/pkg/npm/api/groups/update.ts

178 lines
3.0 KiB
TypeScript
Raw Normal View History

2021-02-15 01:15:43 +03:00
import { PatpNoSig, Path, Jug, ShipRank, Enc } from '..';
import { roleTags } from './index';
export type RoleTags = typeof roleTags[number];
interface RoleTag {
tag: 'admin' | 'moderator' | 'janitor';
}
interface AppTag {
app: string;
resource: string;
tag: string;
}
export type Tag = AppTag | RoleTag;
export interface InvitePolicy {
invite: {
pending: Set<PatpNoSig>;
};
}
export interface OpenPolicy {
open: {
banned: Set<PatpNoSig>;
banRanks: Set<ShipRank>;
};
}
export interface Resource {
name: string;
ship: PatpNoSig;
}
export type OpenPolicyDiff =
| AllowRanksDiff
| BanRanksDiff
| AllowShipsDiff
| BanShipsDiff;
2021-02-25 06:54:00 +03:00
export interface AllowRanksDiff {
2021-02-15 01:15:43 +03:00
allowRanks: ShipRank[];
}
2021-02-25 06:54:00 +03:00
export interface BanRanksDiff {
2021-02-15 01:15:43 +03:00
banRanks: ShipRank[];
}
2021-02-25 06:54:00 +03:00
export interface AllowShipsDiff {
2021-02-15 01:15:43 +03:00
allowShips: PatpNoSig[];
}
2021-02-25 06:54:00 +03:00
export interface BanShipsDiff {
2021-02-15 01:15:43 +03:00
banShips: PatpNoSig[];
}
export type InvitePolicyDiff = AddInvitesDiff | RemoveInvitesDiff;
2021-02-25 06:54:00 +03:00
export interface AddInvitesDiff {
2021-02-15 01:15:43 +03:00
addInvites: PatpNoSig[];
}
2021-02-25 06:54:00 +03:00
export interface RemoveInvitesDiff {
2021-02-15 01:15:43 +03:00
removeInvites: PatpNoSig[];
}
2021-02-25 06:54:00 +03:00
export interface ReplacePolicyDiff {
2021-02-15 01:15:43 +03:00
replace: GroupPolicy;
}
export type GroupPolicyDiff =
| { open: OpenPolicyDiff }
| { invite: InvitePolicyDiff }
| ReplacePolicyDiff;
export type GroupPolicy = OpenPolicy | InvitePolicy;
2021-02-25 06:54:00 +03:00
export interface TaggedShips {
2021-02-15 01:15:43 +03:00
[tag: string]: Set<PatpNoSig>;
}
export interface Tags {
role: TaggedShips;
[app: string]: TaggedShips;
}
export interface Group {
members: Set<PatpNoSig>;
tags: Tags;
policy: GroupPolicy;
hidden: boolean;
}
export type Groups = {
[p in Path]: Group;
};
2021-02-25 06:54:00 +03:00
export interface GroupUpdateInitial {
2021-02-15 01:15:43 +03:00
initial: Enc<Groups>;
}
2021-02-25 06:54:00 +03:00
export interface GroupUpdateAddGroup {
2021-02-15 01:15:43 +03:00
addGroup: {
resource: Resource;
policy: Enc<GroupPolicy>;
hidden: boolean;
};
}
2021-02-25 06:54:00 +03:00
export interface GroupUpdateAddMembers {
2021-02-15 01:15:43 +03:00
addMembers: {
ships: PatpNoSig[];
resource: Resource;
};
}
2021-02-25 06:54:00 +03:00
export interface GroupUpdateRemoveMembers {
2021-02-15 01:15:43 +03:00
removeMembers: {
ships: PatpNoSig[];
resource: Resource;
};
}
2021-02-25 06:54:00 +03:00
export interface GroupUpdateAddTag {
2021-02-15 01:15:43 +03:00
addTag: {
tag: Tag;
resource: Resource;
ships: PatpNoSig[];
};
}
2021-02-25 06:54:00 +03:00
export interface GroupUpdateRemoveTag {
2021-02-15 01:15:43 +03:00
removeTag: {
tag: Tag;
resource: Resource;
ships: PatpNoSig[];
2021-02-15 01:15:43 +03:00
};
}
2021-02-25 06:54:00 +03:00
export interface GroupUpdateChangePolicy {
2021-02-15 01:15:43 +03:00
changePolicy: { resource: Resource; diff: GroupPolicyDiff };
}
2021-02-25 06:54:00 +03:00
export interface GroupUpdateRemoveGroup {
2021-02-15 01:15:43 +03:00
removeGroup: {
resource: Resource;
};
}
2021-02-25 06:54:00 +03:00
export interface GroupUpdateExpose {
2021-02-15 01:15:43 +03:00
expose: {
resource: Resource;
};
}
2021-02-25 06:54:00 +03:00
export interface GroupUpdateInitialGroup {
2021-02-15 01:15:43 +03:00
initialGroup: {
resource: Resource;
group: Enc<Group>;
};
}
export type GroupUpdate =
| GroupUpdateInitial
| GroupUpdateAddGroup
| GroupUpdateAddMembers
| GroupUpdateRemoveMembers
| GroupUpdateAddTag
| GroupUpdateRemoveTag
| GroupUpdateChangePolicy
| GroupUpdateRemoveGroup
| GroupUpdateExpose
| GroupUpdateInitialGroup;
export type GroupAction = Omit<GroupUpdate, 'initialGroup' | 'initial'>;