import { CommonUtil } from './../utils/' ; import { IAccessInfo } from '../core' ; import { ICondition } from './ICondition' ; class inner memberof class Access { protected type { IAccessInfo } protected _ : IAccessInfo = { } ; protected type { Any } protected _grants : any ; private param { Any } grants param { String | Array < String > | IAccessInfo } roleOrInfo param { Boolean } denied constructor ( grants , roleOrInfo ? ) { this . _grants = grants ; if ( typeof roleOrInfo === 'string' || Array . isArray ( roleOrInfo ) ) { this . role ( roleOrInfo ) ; } else if ( CommonUtil . type ( roleOrInfo ) === 'object' ) { this . _ = roleOrInfo ; } if ( CommonUtil . isInfoFulfilled ( this . _ ) ) { CommonUtil . commitToGrants ( grants , this . _ ) ; } } param { String | Array < String > } value returns { Access } role ( value ) { this . _ . role = value ; return this ; } param { String | Array < String > } value returns { Access } resource ( value ) { this . _ . resource = value ; return this ; } returns { Access } commit ( ) { CommonUtil . commitToGrants ( this . _grants , this . _ ) ; return this ; } param { String | Array < String > } resource param { String | Array < String > } attributes throws returns { Access } on ( resource ? , attributes ? ) { return this . _prepareAndCommit ( this . _ . action , resource , attributes ) ; } param { String | Array < String > } value returns { Access } attributes ( value ) { this . _ . attributes = value ; return this ; } param { ICondition | string | Function } value returns { Access } condition ( value ) { this . _ . condition = value ; return this ; } param { String | Array < String > } roles returns { Access } extend ( roles ) { return this . extendSync ( roles ) ; } param { String | Array < String > } roles returns { Access } extendSync ( roles ) { CommonUtil . extendRoleSync ( this . _grants , this . _ . role , roles ) ; return this ; } param { String | Array < String > | IAccessInfo } roleOrInfo Either a single or an array of roles or an
     *          {@link ?api=ac#AccessControl~IAccessInfo|`IAccessInfo` object} .
     *
     *   returns { Access } example grant ( roleOrInfo ? ) { return ( new Access ( this . _grants , roleOrInfo ) ) . attributes ( [ '*' ] ) ; } param { String } action returns { Access } execute ( action ) { this . _ . action = action ; return this ; } /**
     * Alias of `execute`
     */ action ( action ) { this . _ . action = action ; return this ; } param { String } condition returns { Access } when ( condition ) { this . _ . condition = condition ; return this ; } private param { String } action param { String | Array < String > } resource param { String | Array < String > } attributes returns { Access } private _prepareAndCommit ( action , resource ? , attributes ? ) { this . _ . action = action ; if ( resource ) this . _ . resource = resource ; if ( attributes ) this . _ . attributes = attributes ; CommonUtil . commitToGrants ( this . _grants , this . _ ) ; this . _ . attributes = undefined ; return this ; } } export { Access } ;