Comparing version
@@ -437,3 +437,3 @@ "use strict"; | ||
AccessControl.prototype.grant = function (role) { | ||
return new core_1.Access(this._grants, role, false); | ||
return new core_1.Access(this._grants, role); | ||
}; | ||
@@ -440,0 +440,0 @@ /** |
@@ -41,3 +41,3 @@ import { IAccessInfo } from '../core'; | ||
*/ | ||
constructor(grants: any, roleOrInfo?: string | string[] | IAccessInfo, denied?: boolean); | ||
constructor(grants: any, roleOrInfo?: string | string[] | IAccessInfo); | ||
/** | ||
@@ -60,2 +60,8 @@ * A chainer method that sets the role(s) for this `Access` instance. | ||
/** | ||
* Commits the grant | ||
* @returns {Access} | ||
* Self instance of `Access`. | ||
*/ | ||
commit(): Access; | ||
/** | ||
* Sets the resource and possession to `"any"` and commits the | ||
@@ -81,3 +87,3 @@ * current access instance to the underlying grant model. | ||
*/ | ||
onAny(resource: string | string[], attributes?: string | string[]): Access; | ||
onAny(resource?: string | string[], attributes?: string | string[]): Access; | ||
/** | ||
@@ -104,7 +110,7 @@ * Sets the resource and possession to `"own"` and commits the | ||
*/ | ||
onOwn(resource: string | string[], attributes?: string | string[]): Access; | ||
onOwn(resource?: string | string[], attributes?: string | string[]): Access; | ||
/** | ||
* Alias of `onAny` | ||
*/ | ||
on(resource: string | string[], attributes?: string | string[]): Access; | ||
on(resource?: string | string[], attributes?: string | string[]): Access; | ||
/** | ||
@@ -151,18 +157,2 @@ * Sets the array of allowed attributes for this `Access` instance. | ||
/** | ||
* Shorthand to switch to a new `Access` instance with a different | ||
* (or same) role within the method chain. | ||
* | ||
* @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} | ||
* A new `Access` instance. | ||
* | ||
* @example | ||
* ac.grant('admin').createAny('video') | ||
* .deny('user').deleteAny('video'); | ||
*/ | ||
deny(roleOrInfo?: string | string[] | IAccessInfo): Access; | ||
/** | ||
* Sets the action. | ||
@@ -179,2 +169,6 @@ * | ||
/** | ||
* Alias of `execute` | ||
*/ | ||
action(action: string): Access; | ||
/** | ||
* Sets the condition for access. | ||
@@ -181,0 +175,0 @@ * |
@@ -31,4 +31,3 @@ "use strict"; | ||
*/ | ||
function Access(grants, roleOrInfo, denied) { | ||
if (denied === void 0) { denied = false; } | ||
function Access(grants, roleOrInfo) { | ||
/** | ||
@@ -47,6 +46,7 @@ * Inner `IAccessInfo` object. | ||
// should directly commit it to grants. | ||
this._ = utils_1.default.resetAttributes(roleOrInfo); | ||
if (utils_1.default.isInfoFulfilled(this._)) | ||
utils_1.default.commitToGrants(this._grants, this._, true); | ||
this._ = roleOrInfo; | ||
} | ||
if (utils_1.default.isInfoFulfilled(this._)) { | ||
utils_1.default.commitToGrants(grants, this._, true); | ||
} | ||
} | ||
@@ -79,2 +79,11 @@ // ------------------------------- | ||
/** | ||
* Commits the grant | ||
* @returns {Access} | ||
* Self instance of `Access`. | ||
*/ | ||
Access.prototype.commit = function () { | ||
utils_1.default.commitToGrants(this._grants, this._, true); | ||
return this; | ||
}; | ||
/** | ||
* Sets the resource and possession to `"any"` and commits the | ||
@@ -182,23 +191,5 @@ * current access instance to the underlying grant model. | ||
Access.prototype.grant = function (roleOrInfo) { | ||
return (new Access(this._grants, roleOrInfo, false)).attributes(['*']); | ||
return (new Access(this._grants, roleOrInfo)).attributes(['*']); | ||
}; | ||
/** | ||
* Shorthand to switch to a new `Access` instance with a different | ||
* (or same) role within the method chain. | ||
* | ||
* @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} | ||
* A new `Access` instance. | ||
* | ||
* @example | ||
* ac.grant('admin').createAny('video') | ||
* .deny('user').deleteAny('video'); | ||
*/ | ||
Access.prototype.deny = function (roleOrInfo) { | ||
return (new Access(this._grants, roleOrInfo, true)).attributes([]); | ||
}; | ||
/** | ||
* Sets the action. | ||
@@ -218,2 +209,9 @@ * | ||
/** | ||
* Alias of `execute` | ||
*/ | ||
Access.prototype.action = function (action) { | ||
this._.action = action; | ||
return this; | ||
}; | ||
/** | ||
* Sets the condition for access. | ||
@@ -220,0 +218,0 @@ * |
{ | ||
"name": "role-acl", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Role, Attribute and Condition based Access Control for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
165428
-0.46%3847
-0.21%