mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Typing for "easy-rbac" (#43149)
Co-authored-by: Adam Zerella <adamzerella@users.noreply.github.com>
This commit is contained in:
parent
83570fa572
commit
76168b497f
27
types/easy-rbac/easy-rbac-tests.ts
Normal file
27
types/easy-rbac/easy-rbac-tests.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import RBAC = require('easy-rbac');
|
||||
import rbac = require('easy-rbac');
|
||||
|
||||
const roles = {
|
||||
manager: {
|
||||
can: ['post:save', 'post:delete', 'account:*'],
|
||||
inherits: ['user']
|
||||
},
|
||||
user: {
|
||||
can: [
|
||||
'post:add',
|
||||
{
|
||||
name: 'post:save',
|
||||
when: async () => true,
|
||||
},
|
||||
'user:create'
|
||||
],
|
||||
inherits: ['manager']
|
||||
}
|
||||
};
|
||||
|
||||
const RBACInstance = new RBAC(roles);
|
||||
RBACInstance.can(['user', 'manager'], 'post:save', { userId: 1, ownerId: 2 });
|
||||
|
||||
const RBACFunction = rbac.create(roles);
|
||||
RBACFunction.can('user', 'post:save', { userId: 1, ownerId: 2 });
|
||||
RBACFunction.can(['user', 'manager'], 'post:save', { userId: 1 });
|
||||
26
types/easy-rbac/index.d.ts
vendored
Normal file
26
types/easy-rbac/index.d.ts
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
// Type definitions for easy-rbac 3.1
|
||||
// Project: https://github.com/DeadAlready/easy-rbac
|
||||
// Definitions by: Adam Zerella <https://github.com/adamzerella>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
interface RoleObject {
|
||||
name: string;
|
||||
when: (params: object) => Promise<boolean>;
|
||||
}
|
||||
|
||||
interface Roles {
|
||||
[key: string]: {
|
||||
can: Array<string|RoleObject>;
|
||||
inherits?: string[];
|
||||
};
|
||||
}
|
||||
|
||||
type Options = Roles | (() => Promise<Roles>) | Promise<Roles>;
|
||||
|
||||
declare class RBAC {
|
||||
constructor(opts: Options);
|
||||
can(role: string|string[]|Roles[], operation: string, params?: object): Promise<boolean>;
|
||||
static create(opts: Options): RBAC;
|
||||
}
|
||||
|
||||
export = RBAC;
|
||||
25
types/easy-rbac/tsconfig.json
Normal file
25
types/easy-rbac/tsconfig.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [
|
||||
|
||||
],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"easy-rbac-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/easy-rbac/tslint.json
Normal file
3
types/easy-rbac/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user