Skip to content

Commit

Permalink
Merge pull request #25 from jawad-maqsood/master
Browse files Browse the repository at this point in the history
Refactored backend type in ACL and updated constructor to support Backend memory module
  • Loading branch information
koresar authored Jan 14, 2025
2 parents 3735e86 + d6a96fd commit 32cbc3d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ declare module "acl2" {
}

class Acl {
constructor(backend: Acl.MongoBackend);
constructor(backend: Acl.MongoBackend | Acl.Backend);

allow(rolesPermissions: RolePermission[] | string, resources?: string | string[], permissions?: string | string[]): Promise<void>;

addUserRoles(userId: string | number, roles: string | string[]): Promise<void>;
addUserRoles(userId: string, roles: string | string[]): Promise<void>;

removeUserRoles(userId: string | number, roles: string | string[]): Promise<void>;
removeUserRoles(userId: string, roles: string | string[]): Promise<void>;

userRoles(userId: string | number): Promise<string[]>;
userRoles(userId: string): Promise<string[]>;

hasRole(userId: string | number, role: string): Promise<boolean>;
hasRole(userId: string, role: string): Promise<boolean>;

addRoleParents(role: string, parents: string | string[]): Promise<void>;

removeRoleParents(role: string, parents: string | string[]): Promise<void>;

whatResources(roles: string | string[]): Promise<Record<string, string[]>>;

isAllowed(userId: string | number, resources: string | string[], permissions: string | string[]): Promise<boolean>;
isAllowed(userId: string, resources: string | string[], permissions: string | string[]): Promise<boolean>;

areAnyRolesAllowed(roles: string | string[], resources: string | string[], permissions: string | string[]): Promise<boolean>;

Expand All @@ -36,7 +36,7 @@ declare module "acl2" {

middleware(
numPathComponents?: number,
userId?: (req: any) => string | number,
userId?: (req: any) => string,
actions?: string | string[]
): (req: any, res: any, next: (err?: any) => void) => void;

Expand All @@ -50,13 +50,13 @@ declare module "acl2" {
}

interface Backend {
new (db: Db, prefix: string): Backend;
new (): Backend;
}

function mongodbBackend(db: Db, prefix: string): void;

// Memory Backend
function memoryBackend(): Backend;
function memoryBackend(): void;

// Redis Backend
function redisBackend(client: any, prefix: string): Backend;
Expand Down

0 comments on commit 32cbc3d

Please sign in to comment.