Socket
Socket
Sign inDemoInstall

@bonio-tw/casbin-mongoose-adapter

Package Overview
Dependencies
Maintainers
7
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bonio-tw/casbin-mongoose-adapter - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2-rc

2

dist/bundle.js

@@ -1,2 +0,2 @@

function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=require("casbin"),n=e(require("ioredis")),r=e(require("lodash.get")),i=e(require("lodash.flatten")),o=e(require("mongoose"));const c=function(){function e(){}return e.prototype.then=function(t,n){const r=new e,i=this.s;if(i){const e=1&i?t:n;if(e){try{u(r,1,e(this.v))}catch(e){u(r,2,e)}return r}return this}return this.o=function(e){try{const i=e.v;1&e.s?u(r,1,t?t(i):i):n?u(r,1,n(i)):u(r,2,i)}catch(e){u(r,2,e)}},r},e}();function u(e,t,n){if(!e.s){if(n instanceof c){if(!n.s)return void(n.o=u.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(u.bind(null,e,t),u.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}function s(e){return e instanceof c&&1&e.s}const a="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function f(e,t,n){if("function"==typeof e[a]){var r,i,o,f=e[a]();if(function e(a){try{for(;!((r=f.next()).done||n&&n());)if((a=t(r.value))&&a.then){if(!s(a))return void a.then(e,o||(o=u.bind(null,i=new c,2)));a=a.v}i?u(i,1,a):i=a}catch(e){u(i||(i=new c),2,e)}}(),f.return){var h=function(e){try{r.done||f.return()}catch(e){}return e};if(i&&i.then)return i.then(h,function(e){throw h(e)});h()}return i}if(!("length"in e))throw new TypeError("Object is not iterable");for(var v=[],l=0;l<e.length;l++)v.push(e[l]);return function(e,t,n){var r,i,o=-1;return function a(f){try{for(;++o<e.length&&(!n||!n());)if((f=t(o))&&f.then){if(!s(f))return void f.then(a,i||(i=u.bind(null,r=new c,2)));f=f.v}r?u(r,1,f):r=f}catch(e){u(r||(r=new c),2,e)}}(),r}(v,function(e){return t(v[e])},n)}function h(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var v=function(e,t){if("function"!=typeof e)throw new Error("batchExecFn is not function");this._batchExecFn=e,this._promiseCache=new Map,this._queue=[],this._options=t};v.prototype.execute=function(e){var t=this,n=this._promiseCache.get(e);if(n)return n;var r=new Promise(function(n,r){t._queue.push({key:e,resolve:n,reject:r}),1===t._queue.length&&Promise.resolve().then(function(){return process.nextTick(function(){t.dispatchQueue()})})});return this._promiseCache.set(e,r),r},v.prototype.executeMany=function(e){var t=this;if(!Array.isArray(e))throw new TypeError("The Batch.execMany() function must be called with Array<key> but got: "+e+".");return Promise.all(e.map(function(e){return t.execute(e)}))},v.prototype.dispatchQueue=function(){var e=this,t=this._options,n=this._queue;this._queue=[];var r=n.map(function(e){return e.key});this._batchExecFn(r,t).then(function(e){n.forEach(function(t,n){var r=t.resolve,i=e[n];i instanceof Error?(0,t.reject)(i):r(i)})}).finally(function(){e._promiseCache.clear()})};var l=o.Schema,p=new l({p_type:{type:l.Types.String,required:!0,index:!0},v0:{type:l.Types.String,index:!0},v1:{type:l.Types.String,index:!0},v2:{type:l.Types.String,index:!0},v3:{type:l.Types.String,index:!0},v4:{type:l.Types.String,index:!0},v5:{type:l.Types.String,index:!0}},{collection:"casbin_rule",minimize:!1,timestamps:!1}),y=o.model("CasbinRule",p,"casbin_rule"),m=["string","number","boolean"];function d(e){return e?"casbin-"+String(e):""}var g=function(e,t){try{var n=e.pipeline();return t.forEach(function(e,t){n.set(d(t),e,"EX",900)}),Promise.resolve(n.exec()).then(function(){})}catch(e){return Promise.reject(e)}},P=function(e,t,n,r){try{var i=e.pipeline();return t.forEach(function(e){i.get(d(e),function(t,i){t||!i?r(e):n(e,i)})}),Promise.resolve(i.exec()).then(function(){})}catch(e){return Promise.reject(e)}};function b(e){return y.find(e)}var x={fetch:function(e,t){try{var n=!1;function r(t){if(n)return t;var r=new Map,c=[];return Promise.resolve(P(o,e,function(e,t){r.set(e,t)},function(e){c.push(e)})).then(function(){function t(){return Promise.resolve(g(o,r)).then(function(){return e.map(function(e){return JSON.parse(r.get(e))})})}var n=function(){var e;if(c.length>0)return Promise.resolve(b((e={},e[i]={$in:c},e))).then(function(e){c.forEach(function(t){r.set(t,JSON.stringify(e.filter(function(e){return e[i]===t})))})})}();return n&&n.then?n.then(t):t()})}var i=t.field,o=t.redisClient,c=function(){var t;if(!o)return Promise.resolve(b((t={},t[i]={$in:e},t))).then(function(t){return n=!0,e.map(function(e){return t.filter(function(t){return t[i]===e})})})}();return Promise.resolve(c&&c.then?c.then(r):r(c))}catch(e){return Promise.reject(e)}},create:function(e,t){var n=t.ptype;try{return Promise.resolve(h(function(){var t=e.map(function(e){var t=e[0],r=e[1],i=e[2],o=e[3],c=e[4],u=e[5];return{updateOne:{filter:Object.assign({},{p_type:n},t?{v0:t}:{},r?{v1:r}:{},i?{v2:i}:{},o?{v3:o}:{},c?{v4:c}:{},u?{v5:u}:{}),update:{$setOnInsert:Object.assign({},{p_type:n},t?{v0:t}:{},r?{v1:r}:{},i?{v2:i}:{},o?{v3:o}:{},c?{v4:c}:{},u?{v5:u}:{})},upsert:!0}}});return Promise.resolve(y.bulkWrite(t)).then(function(t){return e.map(function(){return{ok:t.ok}})})},function(t){return e.map(function(){return new Error("Bulk create failed: ",JSON.stringify(t))})}))}catch(e){return Promise.reject(e)}},remove:function(e,t){var n=t.ptype;try{return Promise.resolve(h(function(){var t=e.map(function(e){var t=e[0],r=e[1],i=e[2],o=e[3],c=e[4],u=e[5];return{deleteOne:{filter:Object.assign({},{p_type:n},t?{v0:t}:{v0:{$exists:!1}},r?{v1:r}:{v1:{$exists:!1}},i?{v2:i}:{v2:{$exists:!1}},o?{v3:o}:{v3:{$exists:!1}},c?{v4:c}:{v4:{$exists:!1}},u?{v5:u}:{v5:{$exists:!1}})}}});return Promise.resolve(y.bulkWrite(t)).then(function(t){return e.map(function(){return{ok:t.ok}})})},function(t){return e.map(function(){return new Error("Bulk remove failed: ",JSON.stringify(t))})}))}catch(e){return Promise.reject(e)}}},w=function(e,t){var i=this;if(!e||"string"!=typeof e)throw new Error("You must provide Mongo URI to connect to!");this.isFiltered=!1,this.executionMap=new Map;var c=r(t,"mongoose",{});o.connect(e,Object.assign({},c)).then(function(e){i.mongoseInstance=e});var u=r(t,"redis.host"),s=r(t,"redis.port");u&&s&&(this.redisClient=new n({host:u,port:s}))};w.newAdapter=function(e,t){void 0===t&&(t={});try{var n=new w(e,t);return Promise.resolve(new Promise(function(e){return o.connection.once("connected",e)})).then(function(){return n})}catch(e){return Promise.reject(e)}},w.newFilteredAdapter=function(e,t){void 0===t&&(t={});try{return Promise.resolve(w.newAdapter(e,t)).then(function(e){return e.setFiltered(!0),e})}catch(e){return Promise.reject(e)}},w.prototype.setFiltered=function(e){void 0===e&&(e=!0),this.isFiltered=e},w.prototype.loadPolicyLine=function(e,n){var r=e.p_type;e.v0&&(r+=", "+e.v0),e.v1&&(r+=", "+e.v1),e.v2&&(r+=", "+e.v2),e.v3&&(r+=", "+e.v3),e.v4&&(r+=", "+e.v4),e.v5&&(r+=", "+e.v5),t.Helper.loadPolicyLine(r,n)},w.prototype.loadPolicy=function(e){try{return Promise.resolve(this.loadFilteredPolicy(e))}catch(e){return Promise.reject(e)}},w.prototype.getExecution=function(e){var t=e.type,n=e.field,r=e.ptype,i=function(e){var t=e.type,n=e.field,r=e.ptype;return"fetch"===t?String(t)+"-"+String(n):String(t)+"-"+String(r)}({type:t,field:n,ptype:r});if(this.executionMap.has(i))return this.executionMap.get(i);var o=new v(x[t],{field:n,ptype:r,redisClient:"v0"===n?this.redisClient:null});return this.executionMap.set(i,o),o},w.prototype.fetchPolicy=function(e){try{var t=!1,n=this;return Promise.resolve(h(function(){function r(e){var n=!1;if(t)return e;function r(e){return n?e:[]}var o=function(){if(Array.isArray(u.$in)&&u.$in.length>0)return Promise.resolve(s.executeMany(u.$in)).then(function(e){return n=!0,i(e)})}();return o&&o.then?o.then(r):r(o)}var o=i(Object.entries(e)),c=o[0],u=o[1];if(!c||!u)return[];var s=n.getExecution({type:"fetch",field:c}),a=function(){if(m.includes(typeof u))return Promise.resolve(s.execute(u)).then(function(e){return t=!0,e})}();return a&&a.then?a.then(r):r(a)},function(e){throw new Error("Casbin Adapter Fetch Policy Error: ",JSON.stringify(e))}))}catch(e){return Promise.reject(e)}},w.prototype.clearCache=function(e){if(this.redisClient){var t=this.redisClient.scanStream({match:"casbin-"+e+"*"}),n=this.redisClient.pipeline();t.on("data",function(e){e.length>0&&e.forEach(function(e){n.del(e)})}),t.on("end",function(){n.exec()})}},w.prototype.loadFilteredPolicy=function(e,t){try{var n=this;return t?Promise.resolve(n.fetchPolicy(t)).then(function(t){for(var r=0,i=t;r<i.length;r+=1)n.loadPolicyLine(i[r],e)}):Promise.resolve()}catch(e){return Promise.reject(e)}},w.prototype.savePolicyLine=function(e,t){var n=new y({p_type:e});return t.length>0&&(n.v0=t[0]),t.length>1&&(n.v1=t[1]),t.length>2&&(n.v2=t[2]),t.length>3&&(n.v3=t[3]),t.length>4&&(n.v4=t[4]),t.length>5&&(n.v5=t[5]),n},w.prototype.savePolicy=function(e){try{var t=this;function n(){var e=f(i,function(e){var n=e[0],r=f(e[1].policy,function(e){var r=t.savePolicyLine(n,e);return Promise.resolve(r.save()).then(function(){})});if(r&&r.then)return r.then(function(){})});return!e||!e.then||e.then(function(){return!0})}var r=e.model.get("p"),i=e.model.get("g"),o=f(r,function(e){var n=e[0],r=f(e[1].policy,function(e){var r=t.savePolicyLine(n,e);return Promise.resolve(r.save()).then(function(){})});if(r&&r.then)return r.then(function(){})});return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}},w.prototype.addPolicy=function(e,t,n){try{this.clearCache(n[0]);var r=this.getExecution({type:"create",ptype:t});return Promise.resolve(r.execute(n)).then(function(e){if(!e.ok)throw new Error("addPolicy failed: ",JSON.stringify(n))})}catch(e){return Promise.reject(e)}},w.prototype.removePolicy=function(e,t,n){try{this.clearCache(n[0]);var r=this.getExecution({type:"remove",ptype:t});return Promise.resolve(r.execute(n)).then(function(e){if(!e.ok)throw new Error("removePolicy failed: ",JSON.stringify(n))})}catch(e){return Promise.reject(e)}},w.prototype.removeFilteredPolicy=function(e,t,n){for(var r=[],i=arguments.length-3;i-- >0;)r[i]=arguments[i+3];try{var o={p_type:t};return n<=0&&n+r.length>0&&r[0-n]&&(o.v0=r[0-n]),n<=1&&n+r.length>1&&r[1-n]&&(o.v1=r[1-n]),n<=2&&n+r.length>2&&r[2-n]&&(o.v2=r[2-n]),n<=3&&n+r.length>3&&r[3-n]&&(o.v3=r[3-n]),n<=4&&n+r.length>4&&r[4-n]&&(o.v4=r[4-n]),n<=5&&n+r.length>5&&r[5-n]&&(o.v5=r[5-n]),Promise.resolve(y.deleteMany(o)).then(function(){})}catch(e){return Promise.reject(e)}},w.prototype.close=function(){try{return this.mongoseInstance&&this.mongoseInstance.connection&&this.mongoseInstance.connection.close(),Promise.resolve()}catch(e){return Promise.reject(e)}},module.exports=w;
function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=require("casbin"),n=e(require("ioredis")),r=e(require("lodash.get")),i=e(require("lodash.flatten")),o=e(require("mongoose"));const c=function(){function e(){}return e.prototype.then=function(t,n){const r=new e,i=this.s;if(i){const e=1&i?t:n;if(e){try{u(r,1,e(this.v))}catch(e){u(r,2,e)}return r}return this}return this.o=function(e){try{const i=e.v;1&e.s?u(r,1,t?t(i):i):n?u(r,1,n(i)):u(r,2,i)}catch(e){u(r,2,e)}},r},e}();function u(e,t,n){if(!e.s){if(n instanceof c){if(!n.s)return void(n.o=u.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(u.bind(null,e,t),u.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}function s(e){return e instanceof c&&1&e.s}const a="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function f(e,t,n){if("function"==typeof e[a]){var r,i,o,f=e[a]();if(function e(a){try{for(;!((r=f.next()).done||n&&n());)if((a=t(r.value))&&a.then){if(!s(a))return void a.then(e,o||(o=u.bind(null,i=new c,2)));a=a.v}i?u(i,1,a):i=a}catch(e){u(i||(i=new c),2,e)}}(),f.return){var h=function(e){try{r.done||f.return()}catch(e){}return e};if(i&&i.then)return i.then(h,function(e){throw h(e)});h()}return i}if(!("length"in e))throw new TypeError("Object is not iterable");for(var v=[],l=0;l<e.length;l++)v.push(e[l]);return function(e,t,n){var r,i,o=-1;return function a(f){try{for(;++o<e.length&&(!n||!n());)if((f=t(o))&&f.then){if(!s(f))return void f.then(a,i||(i=u.bind(null,r=new c,2)));f=f.v}r?u(r,1,f):r=f}catch(e){u(r||(r=new c),2,e)}}(),r}(v,function(e){return t(v[e])},n)}function h(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var v=function(e,t){if("function"!=typeof e)throw new Error("batchExecFn is not function");this._batchExecFn=e,this._promiseCache=new Map,this._queue=[],this._options=t};v.prototype.execute=function(e){var t=this,n=this._promiseCache.get(e);if(n)return n;var r=new Promise(function(n,r){t._queue.push({key:e,resolve:n,reject:r}),1===t._queue.length&&Promise.resolve().then(function(){return process.nextTick(function(){t.dispatchQueue()})})});return this._promiseCache.set(e,r),r},v.prototype.executeMany=function(e){var t=this;if(!Array.isArray(e))throw new TypeError("The Batch.execMany() function must be called with Array<key> but got: "+e+".");return Promise.all(e.map(function(e){return t.execute(e)}))},v.prototype.dispatchQueue=function(){var e=this,t=this._options,n=this._queue;this._queue=[];var r=n.map(function(e){return e.key});this._batchExecFn(r,t).then(function(e){n.forEach(function(t,n){var r=t.resolve,i=e[n];i instanceof Error?(0,t.reject)(i):r(i)})}).finally(function(){e._promiseCache.clear()})};var l=o.Schema,p=new l({p_type:{type:l.Types.String,required:!0,index:!0},v0:{type:l.Types.String,index:!0},v1:{type:l.Types.String,index:!0},v2:{type:l.Types.String,index:!0},v3:{type:l.Types.String,index:!0},v4:{type:l.Types.String,index:!0},v5:{type:l.Types.String,index:!0}},{collection:"casbin_rule",minimize:!1,timestamps:!1}),y=o.model("CasbinRule",p,"casbin_rule"),m=["string","number","boolean"];function d(e){return e?"casbin-"+String(e):""}var g=function(e,t){try{var n=e.pipeline();return t.forEach(function(e,t){n.set(d(t),e,"EX",900)}),Promise.resolve(n.exec()).then(function(){})}catch(e){return Promise.reject(e)}},P=function(e,t,n,r){try{var i=e.pipeline();return t.forEach(function(e){i.get(d(e),function(t,i){t||!i?r(e):n(e,i)})}),Promise.resolve(i.exec()).then(function(){})}catch(e){return Promise.reject(e)}};function b(e){return y.find(e)}var x={fetch:function(e,t){try{var n=!1;function r(t){if(n)return t;var r=new Map,c=[];return Promise.resolve(P(o,e,function(e,t){r.set(e,t)},function(e){c.push(e)})).then(function(){function t(){return Promise.resolve(g(o,r)).then(function(){return e.map(function(e){return JSON.parse(r.get(e))})})}var n=function(){var e;if(c.length>0)return Promise.resolve(b((e={},e[i]={$in:c},e))).then(function(e){c.forEach(function(t){r.set(t,JSON.stringify(e.filter(function(e){return e[i]===t})))})})}();return n&&n.then?n.then(t):t()})}var i=t.field,o=t.redisClient,c=function(){var t;if(!o)return Promise.resolve(b((t={},t[i]={$in:e},t))).then(function(t){return n=!0,e.map(function(e){return t.filter(function(t){return t[i]===e})})})}();return Promise.resolve(c&&c.then?c.then(r):r(c))}catch(e){return Promise.reject(e)}},create:function(e,t){var n=t.ptype;try{return Promise.resolve(h(function(){var t=e.map(function(e){var t=e[0],r=e[1],i=e[2],o=e[3],c=e[4],u=e[5];return{updateOne:{filter:Object.assign({},{p_type:n},t?{v0:t}:{},r?{v1:r}:{},i?{v2:i}:{},o?{v3:o}:{},c?{v4:c}:{},u?{v5:u}:{}),update:{$setOnInsert:Object.assign({},{p_type:n},t?{v0:t}:{},r?{v1:r}:{},i?{v2:i}:{},o?{v3:o}:{},c?{v4:c}:{},u?{v5:u}:{})},upsert:!0}}});return Promise.resolve(y.bulkWrite(t)).then(function(t){return e.map(function(){return{ok:t.ok}})})},function(t){return e.map(function(){return new Error("Bulk create failed: ",JSON.stringify(t))})}))}catch(e){return Promise.reject(e)}},remove:function(e,t){var n=t.ptype;try{return Promise.resolve(h(function(){var t=e.map(function(e){var t=e[0],r=e[1],i=e[2],o=e[3],c=e[4],u=e[5];return{deleteOne:{filter:Object.assign({},{p_type:n},t?{v0:t}:{v0:{$exists:!1}},r?{v1:r}:{v1:{$exists:!1}},i?{v2:i}:{v2:{$exists:!1}},o?{v3:o}:{v3:{$exists:!1}},c?{v4:c}:{v4:{$exists:!1}},u?{v5:u}:{v5:{$exists:!1}})}}});return Promise.resolve(y.bulkWrite(t)).then(function(t){return e.map(function(){return{ok:t.ok}})})},function(t){return e.map(function(){return new Error("Bulk remove failed: ",JSON.stringify(t))})}))}catch(e){return Promise.reject(e)}}},w=function(e,t){var i=this,c=t.redis,u=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&-1===t.indexOf(r)&&(n[r]=e[r]);return n}(t,["redis"]);if(!e||"string"!=typeof e)throw new Error("You must provide Mongo URI to connect to!");this.isFiltered=!1,this.executionMap=new Map,o.connect(e,Object.assign({},u)).then(function(e){i.mongooseInstance=e});var s=r(c,"host"),a=r(c,"port");s&&a&&(this.redisClient=new n({host:s,port:a}))};w.newAdapter=function(e,t){void 0===t&&(t={});try{var n=new w(e,t);return Promise.resolve(new Promise(function(e){return o.connection.once("connected",e)})).then(function(){return n})}catch(e){return Promise.reject(e)}},w.newFilteredAdapter=function(e,t){void 0===t&&(t={});try{return Promise.resolve(w.newAdapter(e,t)).then(function(e){return e.setFiltered(!0),e})}catch(e){return Promise.reject(e)}},w.prototype.setFiltered=function(e){void 0===e&&(e=!0),this.isFiltered=e},w.prototype.loadPolicyLine=function(e,n){var r=e.p_type;e.v0&&(r+=", "+e.v0),e.v1&&(r+=", "+e.v1),e.v2&&(r+=", "+e.v2),e.v3&&(r+=", "+e.v3),e.v4&&(r+=", "+e.v4),e.v5&&(r+=", "+e.v5),t.Helper.loadPolicyLine(r,n)},w.prototype.loadPolicy=function(e){try{return Promise.resolve(this.loadFilteredPolicy(e))}catch(e){return Promise.reject(e)}},w.prototype.getExecution=function(e){var t=e.type,n=e.field,r=e.ptype,i=function(e){var t=e.type,n=e.field,r=e.ptype;return"fetch"===t?String(t)+"-"+String(n):String(t)+"-"+String(r)}({type:t,field:n,ptype:r});if(this.executionMap.has(i))return this.executionMap.get(i);var o=new v(x[t],{field:n,ptype:r,redisClient:"v0"===n?this.redisClient:null});return this.executionMap.set(i,o),o},w.prototype.fetchPolicy=function(e){try{var t=!1,n=this;return Promise.resolve(h(function(){function r(e){var n=!1;if(t)return e;function r(e){return n?e:[]}var o=function(){if(Array.isArray(u.$in)&&u.$in.length>0)return Promise.resolve(s.executeMany(u.$in)).then(function(e){return n=!0,i(e)})}();return o&&o.then?o.then(r):r(o)}var o=i(Object.entries(e)),c=o[0],u=o[1];if(!c||!u)return[];var s=n.getExecution({type:"fetch",field:c}),a=function(){if(m.includes(typeof u))return Promise.resolve(s.execute(u)).then(function(e){return t=!0,e})}();return a&&a.then?a.then(r):r(a)},function(e){throw new Error("Casbin Adapter Fetch Policy Error: ",JSON.stringify(e))}))}catch(e){return Promise.reject(e)}},w.prototype.clearCache=function(e){if(this.redisClient){var t=this.redisClient.scanStream({match:"casbin-"+e+"*"}),n=this.redisClient.pipeline();t.on("data",function(e){e.length>0&&e.forEach(function(e){n.del(e)})}),t.on("end",function(){n.exec()})}},w.prototype.loadFilteredPolicy=function(e,t){try{var n=this;return t?Promise.resolve(n.fetchPolicy(t)).then(function(t){for(var r=0,i=t;r<i.length;r+=1)n.loadPolicyLine(i[r],e)}):Promise.resolve()}catch(e){return Promise.reject(e)}},w.prototype.savePolicyLine=function(e,t){var n=new y({p_type:e});return t.length>0&&(n.v0=t[0]),t.length>1&&(n.v1=t[1]),t.length>2&&(n.v2=t[2]),t.length>3&&(n.v3=t[3]),t.length>4&&(n.v4=t[4]),t.length>5&&(n.v5=t[5]),n},w.prototype.savePolicy=function(e){try{var t=this;function n(){var e=f(i,function(e){var n=e[0],r=f(e[1].policy,function(e){var r=t.savePolicyLine(n,e);return Promise.resolve(r.save()).then(function(){})});if(r&&r.then)return r.then(function(){})});return!e||!e.then||e.then(function(){return!0})}var r=e.model.get("p"),i=e.model.get("g"),o=f(r,function(e){var n=e[0],r=f(e[1].policy,function(e){var r=t.savePolicyLine(n,e);return Promise.resolve(r.save()).then(function(){})});if(r&&r.then)return r.then(function(){})});return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}},w.prototype.addPolicy=function(e,t,n){try{this.clearCache(n[0]);var r=this.getExecution({type:"create",ptype:t});return Promise.resolve(r.execute(n)).then(function(e){if(!e.ok)throw new Error("addPolicy failed: ",JSON.stringify(n))})}catch(e){return Promise.reject(e)}},w.prototype.removePolicy=function(e,t,n){try{this.clearCache(n[0]);var r=this.getExecution({type:"remove",ptype:t});return Promise.resolve(r.execute(n)).then(function(e){if(!e.ok)throw new Error("removePolicy failed: ",JSON.stringify(n))})}catch(e){return Promise.reject(e)}},w.prototype.removeFilteredPolicy=function(e,t,n){for(var r=[],i=arguments.length-3;i-- >0;)r[i]=arguments[i+3];try{var o={p_type:t};return n<=0&&n+r.length>0&&r[0-n]&&(o.v0=r[0-n]),n<=1&&n+r.length>1&&r[1-n]&&(o.v1=r[1-n]),n<=2&&n+r.length>2&&r[2-n]&&(o.v2=r[2-n]),n<=3&&n+r.length>3&&r[3-n]&&(o.v3=r[3-n]),n<=4&&n+r.length>4&&r[4-n]&&(o.v4=r[4-n]),n<=5&&n+r.length>5&&r[5-n]&&(o.v5=r[5-n]),Promise.resolve(y.deleteMany(o)).then(function(){})}catch(e){return Promise.reject(e)}},w.prototype.close=function(){try{return this.mongooseInstance&&this.mongooseInstance.connection&&this.mongooseInstance.connection.close(),Promise.resolve()}catch(e){return Promise.reject(e)}},module.exports=w;
//# sourceMappingURL=bundle.js.map
{
"name": "@bonio-tw/casbin-mongoose-adapter",
"version": "1.0.1",
"version": "1.0.2-rc",
"description": "Adapter for Casbin",

@@ -5,0 +5,0 @@ "source": "src/adapter.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc