import type { AccessChange, AccessGrant, AccessInheritedGrant, AccessPermission, AccessPrincipal, AccessRole } from './types.js'; /** A role someone has without holding it here themselves. */ export interface Holding { role: AccessRole; /** The group, or everyone, it comes through; undefined when it is their own. */ through?: AccessPrincipal | undefined; /** Where it was granted, when it was granted above the resource. */ from?: string | undefined; } /** The grants indexed for the questions the drawer asks of them. */ export interface AccessModel { roles: readonly AccessRole[]; /** The roles that can be granted here, in the roles' order. */ grantable: readonly AccessRole[]; roleById: ReadonlyMap; principalById: ReadonlyMap; everyone: AccessPrincipal | undefined; /** Holds every permission and can't be removed. */ owner: AccessPrincipal | undefined; /** The roles each principal holds itself, here, in the roles' order. */ held: ReadonlyMap; /** The principals holding each role here, in the order the host gave the principals. */ holders: ReadonlyMap; /** The roles each principal holds through somewhere above the resource, in the roles' order. */ inherited: ReadonlyMap; /** The principals holding each role through somewhere above the resource. */ inheritedHolders: ReadonlyMap; permissionLabel: (id: string) => string; } export interface ModelInput { roles: readonly AccessRole[]; principals: readonly AccessPrincipal[]; grants: readonly AccessGrant[]; permissions?: readonly AccessPermission[] | undefined; inherited?: readonly AccessInheritedGrant[] | undefined; owner?: string | undefined; } export declare function buildModel({ roles, principals, grants, permissions, inherited, owner, }: ModelInput): AccessModel; export declare const key: (grant: AccessGrant) => string; /** Whether `by` gives every permission `role` does. A role with no permissions covers nothing * and is covered by nothing, so two empty placeholders never read as duplicates. */ export declare function covers(by: AccessRole, role: AccessRole): boolean; export declare const isOwner: (model: AccessModel, principalId: string) => boolean; /** Who has access in the order the list shows them: the owner, everyone, then the rest in the * host's order. */ export declare function principalsWithAccess(model: AccessModel): AccessPrincipal[]; /** The groups, and everyone, whose roles a principal has as well as its own. */ export declare function sourcesOf(model: AccessModel, principalId: string): AccessPrincipal[]; /** Every role a principal has besides those it holds here itself: its own granted above the * resource, then its groups', then everyone's. */ export declare function alsoHas(model: AccessModel, principalId: string): Holding[]; /** The first holding of each role, so a role reached two ways is named once. */ export declare function firstOfEach(holdings: readonly Holding[]): Holding[]; /** Why a role a principal holds is redundant: it owns the resource, its other roles here give * everything this one does, or it has this one, or one that covers it, somewhere else. */ export interface Overlap { owner: boolean; coveredBy: AccessRole[]; elsewhere: Holding[]; } export declare function overlapOf(model: AccessModel, principalId: string, role: AccessRole): Overlap; /** What taking roles from a principal does to whoever it stands for. */ export interface Removal { /** The permissions no longer given by any role they keep, in the order the roles list them. */ lost: string[]; /** Its own roles here still giving some of what the removed roles gave. */ keep: AccessRole[]; /** Roles it has elsewhere still giving some of it: granted above, or through its groups or * everyone. */ keepElsewhere: Holding[]; /** The owner loses nothing, as owning gives every permission. */ owner: boolean; } /** What the principal loses: the removed roles' permissions that nothing it keeps still gives. */ export declare function removalOf(model: AccessModel, principalId: string, roleIds: readonly string[]): Removal; /** Granting each role to each principal: the grants that add something, and the pairs held * already. The owner holds every role already. */ export declare function grantPlan(model: AccessModel, principalIds: readonly string[], roleIds: readonly string[]): { grant: AccessGrant[]; held: AccessGrant[]; }; /** The change that takes `change` back. */ export declare function invert(change: AccessChange): AccessChange; /** Warns, in a development build, about props that would make the drawer wrong in a way that * is easy to miss: a duplicate id shows one of two, and an unknown id shows nothing. */ export declare function warnAboutMisuse({ roles, principals, grants, permissions, inherited, owner, }: ModelInput): void;