@nangazaki/vue-rbac
Version:
Role-Based Access Control (RBAC) implementation for Vue.js
23 lines (22 loc) • 1.18 kB
TypeScript
import type { Permission, RoleKey, RolesConfig } from "../types/index";
/**
* Retrieves all permissions associated with a specific role, including inherited permissions.
* This function handles role inheritance by recursively collecting permissions from parent roles
* while preventing circular dependencies.
*
* @param roleKey - The key identifier of the role to get permissions for
* @param rolesConfig - The configuration object containing all roles and their permissions
* @param processedRoles - A Set to track processed roles and prevent circular dependencies
* @returns An array of unique permissions associated with the role and its inherited roles
*
* @example
* ```typescript
* const permissions = getAllPermissionsForRole('admin', rolesConfig);
* ```
*
* @remarks
* - The function uses recursion to traverse the role hierarchy
* - Duplicate permissions are automatically removed from the final result
* - Circular role dependencies are handled by tracking processed roles
*/
export declare function getAllPermissionsForRole(roleKey: RoleKey, rolesConfig: RolesConfig, processed?: Set<RoleKey>, cache?: Map<RoleKey, Permission[]>): Permission[];