export = PermissionSet; /** * @exports PermissionSet * @class PermissionSet * @extends Set * @author 7kasper * @classdesc * Special set implementation for permissions. * Permissions are stored internally as a string set. * This class provides many helper functions to check * and insert or delete permissions with wildcard capability * and the like. Most set functions are overridden to * provide an easy to use permission system. */ declare class PermissionSet extends Set { /** * Formats a permission to the internal (array) format. * This method only accepts strings (the outside format). * @param {string} permission - The permission to format. * @returns the permission in internal format. * @throws Exception if permission given is not a valid string. */ static formatPermission(permission: string): string[]; /** * Checks if `thisPerm` grants access to the permission `checkPerm`. * @param {string[]} thisPerm - The permission to check with, in split array format. * @param {string[]} checkPerm - The permission to check for, in split array format. * @returns true, if `checkPerm` is granted by `thisPerm`. */ static checkPermission(thisPerm: string[], checkPerm: string[]): boolean; /** * Checks wether an object is iteratable. * @param {*} obj * @returns true, if object is itertable. */ static isIterable(obj: any): boolean; /** * Checks wether an object is similar to array. * Basically this means an object is iteratable * but not a string. * @param {*} obj * @returns true, if an object looks or is like an array. */ static isArrayLike(obj: any): boolean; constructor(values?: readonly any[]); constructor(iterable?: Iterable); /** * Adds permissions in the way described in `upgradeAll()`. * @param {...string} args The permissions to upgrade to. * Can be either a spread out list of * permissions or an iterable object containing full string permissions. * @throws Exception if any permission given is not a valid string. */ add(...args: string[]): void; /** * Adds permissions in the way described in `upgradeAll()`. * @param {...string} args The permissions to upgrade to. * Can be either a spread out list of * permissions or an iterable object containing full string permissions. * @throws Exception if any permission given is not a valid string. */ grant(...args: string[]): void; /** * Deletes permission in the way described in `deleteAll()`. * @param {...string} args The permissions to delete. * Can be either a spread out list of * permissions or an iterable object containing full string permissions. * @throws Exception if any permission given is not a valid string. */ revoke(...args: string[]): void; /** * Adds all permissions specified and upgrades the set to contain no * lesser permissions of those specified. (For optimisation purposes) * @param {...string} args The permissions to upgrade to. * Can be either a spread out list of * permissions or an iterable object containing full string permissions. * @throws Exception if any permission given is not a valid string. */ upgradeAll(...args: string[]): void; /** * Adds specified permission and skims off any lesser permissions in this set. * (For optimisation purposes) * @param {string} permission - The permission to upgrade to. * @throws Exception the permission given is not a valid string. */ upgrade(permission: string): void; /** * Adds all permissions specified and downgrades the set to contain no * superior permissions of those specified. * @param {...string} args The permissions to downgrade to. * Can be either a spread out list of * permissions or an iterable object containing full string permissions. * @throws Exception if any permission given is not a valid string. */ downgradeAll(...args: string[]): void; /** * Adds specified permission and skims off any superior or lesser permissions in this set. * @param {string} permission - The permission to downgrade to. * @throws Exception the permission given is not a valid string. */ downgrade(permission: string): void; /** * Deletes only a single full-matching permission from the list. * Example: `delete('dogs.*.kick')` would remove `dogs.*.kick` but not `dogs.tekkel.kick` * @param {string} permission the permission to remove. */ deleteMatch(permission: string): void; /** * Removes all specified and all permissions falling under those from the set. * Example: `delete('dogs.*.kick')` would remove `dogs.*.kick` but also `dogs.tekkel.kick` * Also `delete('*')` is effectively the same as `clear()` * but not `dogs.tekkel.kick` or `dogs.*.kick.hard` * @param {...string} args - The permissions to delete. * Can be either a spread out list of * permissions or an iterable object containing full string permissions. * @throws Exception if any permission given is not a valid string. */ deleteAll(...args: string[]): void; /** * Removes specified and all permissions falling under it from the set. * Example: `delete('dogs.*.kick')` would remove `dogs.*.kick` but also `dogs.tekkel.kick` * Also `delete('*')` is effectively the same as `clear()` * but not `dogs.tekkel.kick` or `dogs.*.kick.hard` * @param {string} permission - The Permission to chain delete from. * @throws Exception if any permission given is not a valid string. */ delete(permission: string): void; /** * Removes all superiors containing specified permission from the set. * Example: `delete('dogs.*.kick')` would remove `dogs.*.kick` and `*.*.kick` * but not `dogs.tekkel.kick` or `dogs.*.kick.hard` * @param {string} permission - The Permission to chain delete from. * @throws Exception the permission given is not a valid string. */ deleteSuperiors(permission: string): void; /** * Checks if the set grants access to all permissions specified. * @param {...string} args Can be either a spread out list of * permissions or an iterable object containing full string permissions. * @returns true, if all permissions are granted. * @throws Exception if any permission given is not a valid string. */ hasAll(...args: string[]): boolean; /** * Checks if the set grants access to a certain permission. * @param {string} permission - The permission to check (string format) * @returns true, if the permission is granted. * @throws Exception if the permission given is not a valid string. */ has(permission: string): boolean; /** * Returns the clamp of `this` and `other` as a new `PermissionSet`. * For each `(a, b)` in `self × other`, takes the more-specific perm * when one grants the other; pairs that don't grant either way are * dropped. Useful for relayed permission propagation: when a trusted * peer attaches a caller's claimed perms to an envelope, the receiver * intersects them against the link's connection perms (the cap) to * bound what the relay may honor. * * Example: `cap=pitch.*` ∩ `claimed=[pitch.motor, api.unrelated]` * yields `[pitch.motor]`. `cap=pitch.set_telem` ∩ `claimed=[pitch.*]` * yields `[pitch.set_telem]` (clamped down to the cap). * * @param {PermissionSet|Iterable} other - the perm set to * clamp against. * @returns {PermissionSet} a new optimised set. */ intersect(other: PermissionSet | Iterable): PermissionSet; }