dbgate-tools 4.7.4-alpha.7 → 4.7.4-alpha.8

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.
@@ -1,2 +1,7 @@
1
- export declare function compilePermissions(permissions: string[] | string): RegExp[];
2
- export declare function testPermission(tested: string, permissions: RegExp[]): boolean;
1
+ interface CompiledPermissions {
2
+ revoke: RegExp;
3
+ allow: RegExp;
4
+ }
5
+ export declare function compilePermissions(permissions: string[] | string): CompiledPermissions;
6
+ export declare function testPermission(tested: string, permissions: CompiledPermissions): boolean;
7
+ export {};
@@ -6,21 +6,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.testPermission = exports.compilePermissions = void 0;
7
7
  const escapeRegExp_1 = __importDefault(require("lodash/escapeRegExp"));
8
8
  const isString_1 = __importDefault(require("lodash/isString"));
9
+ const compact_1 = __importDefault(require("lodash/compact"));
10
+ function compileRegexp(permissions) {
11
+ if (permissions.length == 0)
12
+ return null;
13
+ return new RegExp(permissions.map(x => '^' + (0, escapeRegExp_1.default)(x).replace(/\\\*/g, '.*') + '$').join('|'));
14
+ }
9
15
  function compilePermissions(permissions) {
10
16
  if (!permissions)
11
17
  return null;
12
18
  if ((0, isString_1.default)(permissions))
13
19
  permissions = permissions.split(',');
14
- return permissions.map(x => new RegExp('^' + (0, escapeRegExp_1.default)(x).replace(/\\\*/g, '.*') + '$'));
20
+ permissions = (0, compact_1.default)(permissions.map(x => x.trim()));
21
+ const revoke = permissions.filter(x => x.startsWith('~')).map(x => x.substring(1));
22
+ const allow = permissions.filter(x => !x.startsWith('~'));
23
+ return {
24
+ revoke: compileRegexp(revoke),
25
+ allow: compileRegexp(allow),
26
+ };
15
27
  }
16
28
  exports.compilePermissions = compilePermissions;
17
29
  function testPermission(tested, permissions) {
18
30
  if (!permissions)
19
31
  return true;
20
- for (const permission of permissions) {
21
- if (tested.match(permission))
22
- return true;
32
+ if (!permissions.revoke)
33
+ return true;
34
+ if (tested.match(permissions.revoke)) {
35
+ if (!tested.match(permissions.allow)) {
36
+ return false;
37
+ }
23
38
  }
24
- return false;
39
+ return true;
25
40
  }
26
41
  exports.testPermission = testPermission;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.7.4-alpha.7",
2
+ "version": "4.7.4-alpha.8",
3
3
  "name": "dbgate-tools",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -25,15 +25,15 @@
25
25
  ],
26
26
  "devDependencies": {
27
27
  "@types/node": "^13.7.0",
28
- "dbgate-types": "^4.7.4-alpha.7",
28
+ "dbgate-types": "^4.7.4-alpha.8",
29
29
  "jest": "^24.9.0",
30
30
  "ts-jest": "^25.2.1",
31
31
  "typescript": "^4.4.3"
32
32
  },
33
33
  "dependencies": {
34
34
  "lodash": "^4.17.21",
35
- "dbgate-query-splitter": "^4.7.4-alpha.7",
36
- "dbgate-sqltree": "^4.7.4-alpha.7",
35
+ "dbgate-query-splitter": "^4.7.4-alpha.8",
36
+ "dbgate-sqltree": "^4.7.4-alpha.8",
37
37
  "uuid": "^3.4.0"
38
38
  }
39
39
  }