1
1
import { Access , IAccessInfo , Query , IQueryInfo , Permission } from './core' ;
2
+ import type { ValidRoleOrArray , ValidRole } from '.' ;
2
3
/**
3
4
* @classdesc
4
5
* AccessControl class that implements RBAC (Role-Based Access Control) basics
@@ -118,7 +119,7 @@ declare class AccessControl {
118
119
* @name AccessControl#isLocked
119
120
* @type {Boolean }
120
121
*/
121
- readonly isLocked : boolean ;
122
+ get isLocked ( ) : boolean ;
122
123
/**
123
124
* Gets the internal grants object that stores all current grants.
124
125
*
@@ -234,7 +235,7 @@ declare class AccessControl {
234
235
* @throws {AccessControlError } - If a role is extended by itself or a
235
236
* non-existent role. Or if called after `.lock()` is called.
236
237
*/
237
- extendRole ( roles : string | string [ ] , extenderRoles : string | string [ ] ) : AccessControl ;
238
+ extendRole ( roles : ValidRoleOrArray , extenderRoles : ValidRoleOrArray ) : AccessControl ;
238
239
/**
239
240
* Removes all the given role(s) and their granted permissions, at once.
240
241
* @chainable
@@ -246,7 +247,7 @@ declare class AccessControl {
246
247
*
247
248
* @throws {AccessControlError } - If called after `.lock()` is called.
248
249
*/
249
- removeRoles ( roles : string | string [ ] ) : AccessControl ;
250
+ removeRoles ( roles : ValidRoleOrArray ) : AccessControl ;
250
251
/**
251
252
* Removes all the given resources for all roles, at once.
252
253
* Pass the `roles` argument to remove access to resources for those
@@ -263,7 +264,7 @@ declare class AccessControl {
263
264
*
264
265
* @throws {AccessControlError } - If called after `.lock()` is called.
265
266
*/
266
- removeResources ( resources : string | string [ ] , roles ?: string | string [ ] ) : AccessControl ;
267
+ removeResources ( resources : ValidRoleOrArray , roles ?: ValidRoleOrArray ) : AccessControl ;
267
268
/**
268
269
* Gets all the unique roles that have at least one access information.
269
270
*
@@ -284,12 +285,12 @@ declare class AccessControl {
284
285
*
285
286
* @returns {Array<String> }
286
287
*/
287
- getInheritedRolesOf ( role : string ) : string [ ] ;
288
+ getInheritedRolesOf ( role : ValidRole ) : ValidRole [ ] ;
288
289
/**
289
290
* Alias of `getInheritedRolesOf`
290
291
* @private
291
292
*/
292
- getExtendedRolesOf ( role : string ) : string [ ] ;
293
+ getExtendedRolesOf ( role : ValidRole ) : ValidRole [ ] ;
293
294
/**
294
295
* Gets all the unique resources that are granted access for at
295
296
* least one role.
@@ -305,7 +306,7 @@ declare class AccessControl {
305
306
*
306
307
* @returns {Boolean }
307
308
*/
308
- hasRole ( role : string | string [ ] ) : boolean ;
309
+ hasRole ( role : ValidRoleOrArray ) : boolean ;
309
310
/**
310
311
* Checks whether grants include the given resource or resources.
311
312
*
@@ -314,7 +315,7 @@ declare class AccessControl {
314
315
*
315
316
* @returns {Boolean }
316
317
*/
317
- hasResource ( resource : string | string [ ] ) : boolean ;
318
+ hasResource ( resource : ValidRoleOrArray ) : boolean ;
318
319
/**
319
320
* Gets an instance of `Query` object. This is used to check whether the
320
321
* defined access is allowed for the given role(s) and resource. This
@@ -347,12 +348,12 @@ declare class AccessControl {
347
348
* ac.can(['admin', 'user']).createOwn('profile');
348
349
* // Note: when multiple roles checked, acquired attributes are unioned (merged).
349
350
*/
350
- can ( role : string | string [ ] | IQueryInfo ) : Query ;
351
+ can ( role : ValidRoleOrArray | IQueryInfo ) : Query ;
351
352
/**
352
353
* Alias of `can()`.
353
354
* @private
354
355
*/
355
- query ( role : string | string [ ] | IQueryInfo ) : Query ;
356
+ query ( role : ValidRoleOrArray | IQueryInfo ) : Query ;
356
357
/**
357
358
* Gets an instance of `Permission` object that checks and defines the
358
359
* granted access permissions for the target resource and role. Normally
@@ -437,12 +438,12 @@ declare class AccessControl {
437
438
* // Note: when attributes is omitted, it will default to `['*']`
438
439
* // which means all attributes (of the resource) are allowed.
439
440
*/
440
- grant ( role ?: string | string [ ] | IAccessInfo ) : Access ;
441
+ grant ( role ?: ValidRoleOrArray | IAccessInfo ) : Access ;
441
442
/**
442
443
* Alias of `grant()`.
443
444
* @private
444
445
*/
445
- allow ( role ?: string | string [ ] | IAccessInfo ) : Access ;
446
+ allow ( role ?: ValidRoleOrArray | IAccessInfo ) : Access ;
446
447
/**
447
448
* Gets an instance of `Access` object. This is used to deny access to
448
449
* specified resource(s) for the given role(s). Denying will only remove a
@@ -495,31 +496,31 @@ declare class AccessControl {
495
496
* // To deny same resource for multiple roles:
496
497
* ac.deny(['admin', 'user']).createOwn('profile');
497
498
*/
498
- deny ( role ?: string | string [ ] | IAccessInfo ) : Access ;
499
+ deny ( role ?: ValidRoleOrArray | IAccessInfo ) : Access ;
499
500
/**
500
501
* Alias of `deny()`.
501
502
* @private
502
503
*/
503
- reject ( role ?: string | string [ ] | IAccessInfo ) : Access ;
504
+ reject ( role ?: ValidRoleOrArray | IAccessInfo ) : Access ;
504
505
/**
505
506
* @private
506
507
*/
507
- _removePermission ( resources : string | string [ ] , roles ?: string | string [ ] , actionPossession ?: string ) : void ;
508
+ _removePermission ( resources : ValidRoleOrArray , roles ?: ValidRoleOrArray , actionPossession ?: string ) : void ;
508
509
/**
509
510
* Documented separately in enums/Action
510
511
* @private
511
512
*/
512
- static readonly Action : any ;
513
+ static get Action ( ) : any ;
513
514
/**
514
515
* Documented separately in enums/Possession
515
516
* @private
516
517
*/
517
- static readonly Possession : any ;
518
+ static get Possession ( ) : any ;
518
519
/**
519
520
* Documented separately in AccessControlError
520
521
* @private
521
522
*/
522
- static readonly Error : any ;
523
+ static get Error ( ) : any ;
523
524
/**
524
525
* A utility method for deep cloning the given data object(s) while
525
526
* filtering its properties by the given attribute (glob) notations.
0 commit comments