@aspectus/permissions
Version:
Basement for permissions checking functionality.
6 lines • 2.54 kB
JavaScript
/*!
* permissions v0.10.20
* (c) 2020 Alex Tkachenko
* Released under the MIT License.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Permissions={})}(this,function(e){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&c(e,t)}function u(e){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function s(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}var f=function(){function e(){n(this,e)}return o(e,[{key:"hasAccess",value:function(){return!0}},{key:"onHasAccess",value:function(){var n=this,r=arguments;return new Promise(function(e,t){return n.hasAccess.apply(n,r)?e():t()})}}]),e}(),t=function(){function e(){return n(this,e),s(this,u(e).apply(this,arguments))}return i(e,f),e}(),a=function(){function t(){var e;return n(this,t),(e=s(this,u(t).call(this))).collection=Array.from(arguments),e}return i(t,f),o(t,[{key:"executeCollection",value:function(t){return this.collection.map(function(e){return e.onHasAccess.apply(e,t)})}}]),t}(),l=function(){function e(){return n(this,e),s(this,u(e).apply(this,arguments))}return i(e,a),o(e,[{key:"onHasAccess",value:function(){return Promise.any(this.executeCollection(arguments))}}]),e}(),p=function(){function e(){return n(this,e),s(this,u(e).apply(this,arguments))}return i(e,a),o(e,[{key:"onHasAccess",value:function(){return Promise.all(this.executeCollection(arguments))}}]),e}();e.AllowAny=t,e.And=p,e.Or=l,e.Permission=f,e.PermissionsCollection=a,e.hasAccess=function(e){for(var t=arguments.length,n=new Array(1<t?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return Promise.all(e.map(function(e){return e.onHasAccess.apply(e,n)}))},Object.defineProperty(e,"__esModule",{value:!0})});