@abtnode/rbac 1.16.11-next-ca5f18b5 → 1.16.11-next-3e55bc95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/core/base.js CHANGED
@@ -25,7 +25,7 @@ module.exports = class Base {
25
25
  * @method Base#remove
26
26
  * @return {boolean}
27
27
  */
28
- async add() {
28
+ add() {
29
29
  const { rbac } = this;
30
30
  return rbac.add(this);
31
31
  }
@@ -35,7 +35,7 @@ module.exports = class Base {
35
35
  * @method Base#remove
36
36
  * @return {boolean}
37
37
  */
38
- async remove() {
38
+ remove() {
39
39
  const { rbac } = this;
40
40
  return rbac.remove(this);
41
41
  }
package/lib/core/rbac.js CHANGED
@@ -47,7 +47,7 @@ module.exports = class RBAC {
47
47
  this.storage.useRBAC(this);
48
48
  }
49
49
 
50
- async init() {
50
+ init() {
51
51
  const { roles, permissions, grants } = this.options;
52
52
 
53
53
  return this.create(roles, permissions, grants);
@@ -58,7 +58,7 @@ module.exports = class RBAC {
58
58
  * @method RBAC#get
59
59
  * @param {String} name Name of item
60
60
  */
61
- async get(name) {
61
+ get(name) {
62
62
  return this.storage.get(name);
63
63
  }
64
64
 
@@ -67,7 +67,7 @@ module.exports = class RBAC {
67
67
  * @method RBAC#add
68
68
  * @param {Base} item Instance of Base
69
69
  */
70
- async add(item) {
70
+ add(item) {
71
71
  if (!item) {
72
72
  throw new Error('Item is undefined');
73
73
  }
@@ -84,7 +84,7 @@ module.exports = class RBAC {
84
84
  * @method RBAC#remove
85
85
  * @param {Base} item Instance of role or permission
86
86
  */
87
- async remove(item) {
87
+ remove(item) {
88
88
  if (!item) {
89
89
  throw new Error('Item is undefined');
90
90
  }
@@ -116,7 +116,7 @@ module.exports = class RBAC {
116
116
  * @param {Role} role Instance of the role
117
117
  * @param {Base} child Instance of the role or permission
118
118
  */
119
- async grant(role, child) {
119
+ grant(role, child) {
120
120
  if (!role || !child) {
121
121
  throw new Error('One of item is undefined');
122
122
  }
@@ -138,7 +138,7 @@ module.exports = class RBAC {
138
138
  * @param {Role} role Instance of the role
139
139
  * @param {Base} child Instance of the role or permission
140
140
  */
141
- async revoke(role, child) {
141
+ revoke(role, child) {
142
142
  if (!role || !child) {
143
143
  throw new Error('One of item is undefined');
144
144
  }
@@ -220,7 +220,7 @@ module.exports = class RBAC {
220
220
  * @method RBAC#exists
221
221
  * @param {String} name Name of item
222
222
  */
223
- async exists(name) {
223
+ exists(name) {
224
224
  return this.storage.exists(name);
225
225
  }
226
226
 
@@ -229,7 +229,7 @@ module.exports = class RBAC {
229
229
  * @method RBAC#existsRole
230
230
  * @param {String} name Name of item
231
231
  */
232
- async existsRole(name) {
232
+ existsRole(name) {
233
233
  return this.storage.existsRole(name);
234
234
  }
235
235
 
@@ -239,7 +239,7 @@ module.exports = class RBAC {
239
239
  * @param {String} action Name of action
240
240
  * @param {String} resource Name of resource
241
241
  */
242
- async existsPermission(action, resource) {
242
+ existsPermission(action, resource) {
243
243
  return this.storage.existsPermission(action, resource);
244
244
  }
245
245
 
@@ -248,7 +248,7 @@ module.exports = class RBAC {
248
248
  * @method RBAC#getRole
249
249
  * @param {String} name Name of role
250
250
  */
251
- async getRole(name) {
251
+ getRole(name) {
252
252
  return this.storage.getRole(name);
253
253
  }
254
254
 
@@ -256,7 +256,7 @@ module.exports = class RBAC {
256
256
  * Return all instances of Role
257
257
  * @method RBAC#getRoles
258
258
  */
259
- async getRoles() {
259
+ getRoles() {
260
260
  return this.storage.getRoles();
261
261
  }
262
262
 
@@ -266,7 +266,7 @@ module.exports = class RBAC {
266
266
  * @param {String} action Name of action
267
267
  * @param {String} resource Name of resource
268
268
  */
269
- async getPermission(action, resource) {
269
+ getPermission(action, resource) {
270
270
  return this.storage.getPermission(action, resource);
271
271
  }
272
272
 
@@ -275,7 +275,7 @@ module.exports = class RBAC {
275
275
  * @method RBAC#getPermission
276
276
  * @param {String} name Name of permission
277
277
  */
278
- async getPermissionByName(name) {
278
+ getPermissionByName(name) {
279
279
  const data = Permission.decodeName(name, this.options.delimiter);
280
280
  return this.storage.getPermission(data.action, data.resource);
281
281
  }
@@ -284,7 +284,7 @@ module.exports = class RBAC {
284
284
  * Return all instances of Permission
285
285
  * @method RBAC#getPermissions
286
286
  */
287
- async getPermissions() {
287
+ getPermissions() {
288
288
  return this.storage.getPermissions();
289
289
  }
290
290
 
package/lib/core/role.js CHANGED
@@ -25,7 +25,7 @@ module.exports = class Role extends Base {
25
25
  * @method Role#grant
26
26
  * @param {Role|Permission} item Instance of role or permission
27
27
  */
28
- async grant(item) {
28
+ grant(item) {
29
29
  return this.rbac.grant(this, item);
30
30
  }
31
31
 
@@ -34,7 +34,7 @@ module.exports = class Role extends Base {
34
34
  * @method Role#revoke
35
35
  * @param {Role|Permission} item Instance of role or permission
36
36
  */
37
- async revoke(item) {
37
+ revoke(item) {
38
38
  return this.rbac.revoke(this, item);
39
39
  }
40
40
 
@@ -44,7 +44,7 @@ module.exports = class Role extends Base {
44
44
  * @param {string} action Name of action
45
45
  * @param {string} resource Name of resource
46
46
  */
47
- async can(action, resource) {
47
+ can(action, resource) {
48
48
  return this.rbac.can(this.name, action, resource);
49
49
  }
50
50
 
@@ -53,7 +53,7 @@ module.exports = class Role extends Base {
53
53
  * @method Role#canAny
54
54
  * @param {Array} permissions List of permissions. Each has structure (String action, String resource)
55
55
  */
56
- async canAny(permissions) {
56
+ canAny(permissions) {
57
57
  return this.rbac.canAny(this.name, permissions);
58
58
  }
59
59
 
@@ -62,7 +62,7 @@ module.exports = class Role extends Base {
62
62
  * @method Role#canAll
63
63
  * @param {Array} permissions List of permissions. Each has structure (String action, String resource)
64
64
  */
65
- async canAll(permissions) {
65
+ canAll(permissions) {
66
66
  return this.rbac.canAll(this.name, permissions);
67
67
  }
68
68
 
@@ -71,7 +71,7 @@ module.exports = class Role extends Base {
71
71
  * @method Role#hasRole
72
72
  * @param {String} roleChildName Name of role
73
73
  */
74
- async hasRole(roleChildName) {
74
+ hasRole(roleChildName) {
75
75
  return this.rbac.hasRole(this.name, roleChildName);
76
76
  }
77
77
 
@@ -79,7 +79,7 @@ module.exports = class Role extends Base {
79
79
  * Return array of permission assigned to actual role
80
80
  * @method Role#getScope
81
81
  */
82
- async getScope() {
82
+ getScope() {
83
83
  return this.rbac.getScope(this.name);
84
84
  }
85
85
  };
@@ -16,7 +16,7 @@ module.exports = class Storage {
16
16
  * @param {Base} item Instance of role or permission
17
17
  */
18
18
  // eslint-disable-next-line no-unused-vars
19
- async add(item) {
19
+ add(item) {
20
20
  throw new Error('Storage method add is not implemented');
21
21
  }
22
22
 
@@ -26,7 +26,7 @@ module.exports = class Storage {
26
26
  * @param {Base} item Instance of role or permission
27
27
  */
28
28
  // eslint-disable-next-line no-unused-vars
29
- async remove(item) {
29
+ remove(item) {
30
30
  throw new Error('Storage method remove is not implemented');
31
31
  }
32
32
 
@@ -37,7 +37,7 @@ module.exports = class Storage {
37
37
  * @param {Base} child Instance of role or permission
38
38
  */
39
39
  // eslint-disable-next-line no-unused-vars
40
- async grant(role, child) {
40
+ grant(role, child) {
41
41
  throw new Error('Storage method grant is not implemented');
42
42
  }
43
43
 
@@ -48,7 +48,7 @@ module.exports = class Storage {
48
48
  * @param {Base} child Instance of role or permission
49
49
  */
50
50
  // eslint-disable-next-line no-unused-vars
51
- async revoke(role, child) {
51
+ revoke(role, child) {
52
52
  throw new Error('Storage method revoke is not implemented');
53
53
  }
54
54
 
@@ -59,7 +59,7 @@ module.exports = class Storage {
59
59
  * @return {Base}
60
60
  */
61
61
  // eslint-disable-next-line no-unused-vars
62
- async get(name) {
62
+ get(name) {
63
63
  throw new Error('Storage method get is not implemented');
64
64
  }
65
65
 
@@ -68,11 +68,11 @@ module.exports = class Storage {
68
68
  * @method Storage#getRoles
69
69
  * @return {Role[]}
70
70
  */
71
- async getRoles() {
71
+ getRoles() {
72
72
  throw new Error('Storage method getRoles is not implemented');
73
73
  }
74
74
 
75
- async updateGrants() {
75
+ updateGrants() {
76
76
  throw new Error('Storage method updateGrants is not implemented');
77
77
  }
78
78
 
@@ -81,7 +81,7 @@ module.exports = class Storage {
81
81
  * @method Storage#getPermissions
82
82
  * @return {Permission[]}
83
83
  */
84
- async getPermissions() {
84
+ getPermissions() {
85
85
  throw new Error('Storage method getPermissions is not implemented');
86
86
  }
87
87
 
@@ -92,7 +92,7 @@ module.exports = class Storage {
92
92
  * @return {Base[]}
93
93
  */
94
94
  // eslint-disable-next-line no-unused-vars
95
- async getGrants(role) {
95
+ getGrants(role) {
96
96
  throw new Error('Storage method getGrants is not implemented');
97
97
  }
98
98
 
@@ -8,7 +8,7 @@ class Memory extends Storage {
8
8
  this.items = {};
9
9
  }
10
10
 
11
- async add(item) {
11
+ add(item) {
12
12
  const { name } = item;
13
13
  if (this.items[name]) {
14
14
  throw new Error(`Item ${name} already exists`);
@@ -26,7 +26,7 @@ class Memory extends Storage {
26
26
  return true;
27
27
  }
28
28
 
29
- async remove(item) {
29
+ remove(item) {
30
30
  const { items } = this;
31
31
  const { name } = item;
32
32
  if (!items[name]) {
@@ -49,7 +49,7 @@ class Memory extends Storage {
49
49
  return true;
50
50
  }
51
51
 
52
- async update(item, { title, description, extra }) {
52
+ update(item, { title, description, extra }) {
53
53
  const { items } = this;
54
54
  const { name } = item;
55
55
  if (!items[name]) {
@@ -69,7 +69,7 @@ class Memory extends Storage {
69
69
  return items[name].instance;
70
70
  }
71
71
 
72
- async grant(role, child) {
72
+ grant(role, child) {
73
73
  const { name } = role;
74
74
  const { name: childName } = child;
75
75
 
@@ -98,7 +98,7 @@ class Memory extends Storage {
98
98
  return true;
99
99
  }
100
100
 
101
- async revoke(role, child) {
101
+ revoke(role, child) {
102
102
  const { name } = role;
103
103
  const { name: childName } = child;
104
104
 
@@ -121,7 +121,7 @@ class Memory extends Storage {
121
121
  return true;
122
122
  }
123
123
 
124
- async get(name) {
124
+ get(name) {
125
125
  if (name && this.items[name]) {
126
126
  return this.items[name].instance;
127
127
  }
@@ -129,7 +129,7 @@ class Memory extends Storage {
129
129
  return undefined;
130
130
  }
131
131
 
132
- async getRoles() {
132
+ getRoles() {
133
133
  return Object.keys(this.items)
134
134
  .map((k) => this.items[k])
135
135
  .reduce((filtered, item) => {
@@ -143,7 +143,7 @@ class Memory extends Storage {
143
143
  }, []);
144
144
  }
145
145
 
146
- async getPermissions() {
146
+ getPermissions() {
147
147
  return Object.keys(this.items)
148
148
  .map((k) => this.items[k])
149
149
  .reduce((filtered, item) => {
@@ -157,7 +157,7 @@ class Memory extends Storage {
157
157
  }, []);
158
158
  }
159
159
 
160
- async getGrants(role) {
160
+ getGrants(role) {
161
161
  if (role && this.items[role]) {
162
162
  const currentGrants = this.items[role].grants;
163
163
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.11-next-ca5f18b5",
6
+ "version": "1.16.11-next-3e55bc95",
7
7
  "description": "Simple lib to manage access controls in ABT Node",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,12 +19,12 @@
19
19
  "author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
20
20
  "license": "Apache-2.0",
21
21
  "dependencies": {
22
- "@abtnode/db": "1.16.11-next-ca5f18b5",
22
+ "@abtnode/db": "1.16.11-next-3e55bc95",
23
23
  "fs-extra": "^10.1.0",
24
24
  "lodash": "^4.17.21"
25
25
  },
26
26
  "devDependencies": {
27
27
  "jest": "^27.5.1"
28
28
  },
29
- "gitHead": "d797d0177d585b66d17876c99c994fda4d812f37"
29
+ "gitHead": "cf0251c2d85c617b03151495b5944061ceb373e5"
30
30
  }