dbgate-tools 4.7.4-alpha.8 → 4.8.1

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.
@@ -15,6 +15,7 @@ export declare const driverBase: {
15
15
  };
16
16
  };
17
17
  databaseEngineTypes: string[];
18
+ supportedCreateDatabase: boolean;
18
19
  analyseFull(pool: any, version: any): Promise<any>;
19
20
  analyseSingleObject(pool: any, name: any, typeField?: string): Promise<any>;
20
21
  analyseSingleTable(pool: any, name: any): any;
package/lib/driverBase.js CHANGED
@@ -36,6 +36,7 @@ exports.driverBase = {
36
36
  dumperClass: SqlDumper_1.SqlDumper,
37
37
  dialect,
38
38
  databaseEngineTypes: ['sql'],
39
+ supportedCreateDatabase: true,
39
40
  analyseFull(pool, version) {
40
41
  return __awaiter(this, void 0, void 0, function* () {
41
42
  const analyser = new this.analyserClass(pool, this, version);
package/lib/filterName.js CHANGED
@@ -35,6 +35,26 @@ const compact_1 = __importDefault(require("lodash/compact"));
35
35
  // if (Filter.All(Char.IsUpper)) return camelMatch;
36
36
  // return DoMatch(Filter, value) || camelMatch;
37
37
  // }
38
+ function fuzzysearch(needle, haystack) {
39
+ var hlen = haystack.length;
40
+ var nlen = needle.length;
41
+ if (nlen > hlen) {
42
+ return false;
43
+ }
44
+ if (nlen === hlen) {
45
+ return needle === haystack;
46
+ }
47
+ outer: for (var i = 0, j = 0; i < nlen; i++) {
48
+ var nch = needle.charCodeAt(i);
49
+ while (j < hlen) {
50
+ if (haystack.charCodeAt(j++) === nch) {
51
+ continue outer;
52
+ }
53
+ }
54
+ return false;
55
+ }
56
+ return true;
57
+ }
38
58
  function filterName(filter, ...names) {
39
59
  if (!filter)
40
60
  return true;
@@ -43,7 +63,7 @@ function filterName(filter, ...names) {
43
63
  const namesCompacted = (0, compact_1.default)(names);
44
64
  for (const token of tokens) {
45
65
  const tokenUpper = token.toUpperCase();
46
- const found = namesCompacted.find(name => name.toUpperCase().includes(tokenUpper));
66
+ const found = namesCompacted.find(name => fuzzysearch(tokenUpper, name.toUpperCase()));
47
67
  if (!found)
48
68
  return false;
49
69
  }
@@ -1,6 +1,9 @@
1
+ interface CompiledPermissionLevel {
2
+ re: RegExp;
3
+ type: 'allow' | 'deny';
4
+ }
1
5
  interface CompiledPermissions {
2
- revoke: RegExp;
3
- allow: RegExp;
6
+ levels: CompiledPermissionLevel[];
4
7
  }
5
8
  export declare function compilePermissions(permissions: string[] | string): CompiledPermissions;
6
9
  export declare function testPermission(tested: string, permissions: CompiledPermissions): boolean;
@@ -7,6 +7,7 @@ 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
9
  const compact_1 = __importDefault(require("lodash/compact"));
10
+ const flatten_1 = __importDefault(require("lodash/flatten"));
10
11
  function compileRegexp(permissions) {
11
12
  if (permissions.length == 0)
12
13
  return null;
@@ -16,26 +17,50 @@ function compilePermissions(permissions) {
16
17
  if (!permissions)
17
18
  return null;
18
19
  if ((0, isString_1.default)(permissions))
19
- permissions = permissions.split(',');
20
+ permissions = permissions.split(/,|;|\||\s/);
21
+ else
22
+ permissions = (0, flatten_1.default)(permissions.map(x => x.split(/,|;|\||\s/)));
20
23
  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),
24
+ let lastType = null;
25
+ let lastItems = [];
26
+ const res = {
27
+ levels: [],
26
28
  };
29
+ for (const item of permissions) {
30
+ const type = item.startsWith('~') ? 'deny' : 'allow';
31
+ const perm = item.startsWith('~') ? item.substring(1) : item;
32
+ if (lastType != null && type != lastType) {
33
+ res.levels.push({
34
+ re: compileRegexp(lastItems),
35
+ type: lastType,
36
+ });
37
+ lastItems = [];
38
+ }
39
+ lastItems.push(perm);
40
+ lastType = type;
41
+ }
42
+ if (lastItems.length > 0) {
43
+ res.levels.push({
44
+ re: compileRegexp(lastItems),
45
+ type: lastType,
46
+ });
47
+ }
48
+ return res;
27
49
  }
28
50
  exports.compilePermissions = compilePermissions;
29
51
  function testPermission(tested, permissions) {
30
- if (!permissions)
31
- return true;
32
- if (!permissions.revoke)
52
+ let allow = true;
53
+ if (!permissions) {
33
54
  return true;
34
- if (tested.match(permissions.revoke)) {
35
- if (!tested.match(permissions.allow)) {
36
- return false;
55
+ }
56
+ for (const level of permissions.levels) {
57
+ if (tested.match(level.re)) {
58
+ if (level.type == 'allow')
59
+ allow = true;
60
+ if (level.type == 'deny')
61
+ allow = false;
37
62
  }
38
63
  }
39
- return true;
64
+ return allow;
40
65
  }
41
66
  exports.testPermission = testPermission;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.7.4-alpha.8",
2
+ "version": "4.8.1",
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.8",
28
+ "dbgate-types": "^4.8.1",
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.8",
36
- "dbgate-sqltree": "^4.7.4-alpha.8",
35
+ "dbgate-query-splitter": "^4.8.1",
36
+ "dbgate-sqltree": "^4.8.1",
37
37
  "uuid": "^3.4.0"
38
38
  }
39
39
  }