dbgate-tools 4.7.4-alpha.2 → 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.
- package/lib/ScriptWriter.d.ts +36 -0
- package/lib/ScriptWriter.js +151 -0
- package/lib/driverBase.d.ts +1 -0
- package/lib/driverBase.js +5 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/testPermission.d.ts +7 -2
- package/lib/testPermission.js +20 -5
- package/package.json +4 -4
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare class ScriptWriter {
|
|
2
|
+
s: string;
|
|
3
|
+
packageNames: string[];
|
|
4
|
+
varCount: number;
|
|
5
|
+
constructor(varCount?: string);
|
|
6
|
+
allocVariable(prefix?: string): string;
|
|
7
|
+
_put(s?: string): void;
|
|
8
|
+
endLine(): void;
|
|
9
|
+
assignCore(variableName: any, functionName: any, props: any): void;
|
|
10
|
+
assign(variableName: any, functionName: any, props: any): void;
|
|
11
|
+
assignValue(variableName: any, jsonValue: any): void;
|
|
12
|
+
requirePackage(packageName: any): void;
|
|
13
|
+
copyStream(sourceVar: any, targetVar: any, colmapVar?: any): void;
|
|
14
|
+
comment(s: any): void;
|
|
15
|
+
getScript(schedule?: any): string;
|
|
16
|
+
}
|
|
17
|
+
export declare class ScriptWriterJson {
|
|
18
|
+
s: string;
|
|
19
|
+
packageNames: string[];
|
|
20
|
+
varCount: number;
|
|
21
|
+
commands: any[];
|
|
22
|
+
constructor(varCount?: string);
|
|
23
|
+
allocVariable(prefix?: string): string;
|
|
24
|
+
endLine(): void;
|
|
25
|
+
assign(variableName: any, functionName: any, props: any): void;
|
|
26
|
+
assignValue(variableName: any, jsonValue: any): void;
|
|
27
|
+
copyStream(sourceVar: any, targetVar: any, colmapVar?: any): void;
|
|
28
|
+
comment(text: any): void;
|
|
29
|
+
getScript(schedule?: any): {
|
|
30
|
+
type: string;
|
|
31
|
+
schedule: any;
|
|
32
|
+
commands: any[];
|
|
33
|
+
packageNames: string[];
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export declare function jsonScriptToJavascript(json: any): string;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.jsonScriptToJavascript = exports.ScriptWriterJson = exports.ScriptWriter = void 0;
|
|
7
|
+
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
8
|
+
const packageTools_1 = require("./packageTools");
|
|
9
|
+
class ScriptWriter {
|
|
10
|
+
constructor(varCount = '0') {
|
|
11
|
+
this.s = '';
|
|
12
|
+
this.packageNames = [];
|
|
13
|
+
this.varCount = 0;
|
|
14
|
+
this.varCount = parseInt(varCount) || 0;
|
|
15
|
+
}
|
|
16
|
+
allocVariable(prefix = 'var') {
|
|
17
|
+
this.varCount += 1;
|
|
18
|
+
return `${prefix}${this.varCount}`;
|
|
19
|
+
}
|
|
20
|
+
_put(s = '') {
|
|
21
|
+
this.s += s;
|
|
22
|
+
this.s += '\n';
|
|
23
|
+
}
|
|
24
|
+
endLine() {
|
|
25
|
+
this._put();
|
|
26
|
+
}
|
|
27
|
+
assignCore(variableName, functionName, props) {
|
|
28
|
+
this._put(`const ${variableName} = await ${functionName}(${JSON.stringify(props)});`);
|
|
29
|
+
}
|
|
30
|
+
assign(variableName, functionName, props) {
|
|
31
|
+
this.assignCore(variableName, (0, packageTools_1.extractShellApiFunctionName)(functionName), props);
|
|
32
|
+
this.packageNames.push(...(0, packageTools_1.extractShellApiPlugins)(functionName, props));
|
|
33
|
+
}
|
|
34
|
+
assignValue(variableName, jsonValue) {
|
|
35
|
+
this._put(`const ${variableName} = ${JSON.stringify(jsonValue)};`);
|
|
36
|
+
}
|
|
37
|
+
requirePackage(packageName) {
|
|
38
|
+
this.packageNames.push(packageName);
|
|
39
|
+
}
|
|
40
|
+
copyStream(sourceVar, targetVar, colmapVar = null) {
|
|
41
|
+
if (colmapVar) {
|
|
42
|
+
this._put(`await dbgateApi.copyStream(${sourceVar}, ${targetVar}, {columns: ${colmapVar}});`);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this._put(`await dbgateApi.copyStream(${sourceVar}, ${targetVar});`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
comment(s) {
|
|
49
|
+
this._put(`// ${s}`);
|
|
50
|
+
}
|
|
51
|
+
getScript(schedule = null) {
|
|
52
|
+
const packageNames = this.packageNames;
|
|
53
|
+
let prefix = (0, uniq_1.default)(packageNames)
|
|
54
|
+
.map(packageName => `// @require ${packageName}\n`)
|
|
55
|
+
.join('');
|
|
56
|
+
if (schedule)
|
|
57
|
+
prefix += `// @schedule ${schedule}`;
|
|
58
|
+
if (prefix)
|
|
59
|
+
prefix += '\n';
|
|
60
|
+
return prefix + this.s;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ScriptWriter = ScriptWriter;
|
|
64
|
+
class ScriptWriterJson {
|
|
65
|
+
constructor(varCount = '0') {
|
|
66
|
+
this.s = '';
|
|
67
|
+
this.packageNames = [];
|
|
68
|
+
this.varCount = 0;
|
|
69
|
+
this.commands = [];
|
|
70
|
+
this.varCount = parseInt(varCount) || 0;
|
|
71
|
+
}
|
|
72
|
+
allocVariable(prefix = 'var') {
|
|
73
|
+
this.varCount += 1;
|
|
74
|
+
return `${prefix}${this.varCount}`;
|
|
75
|
+
}
|
|
76
|
+
endLine() {
|
|
77
|
+
this.commands.push({
|
|
78
|
+
type: 'endline',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
assign(variableName, functionName, props) {
|
|
82
|
+
this.commands.push({
|
|
83
|
+
type: 'assign',
|
|
84
|
+
variableName,
|
|
85
|
+
functionName: (0, packageTools_1.extractShellApiFunctionName)(functionName),
|
|
86
|
+
props,
|
|
87
|
+
});
|
|
88
|
+
this.packageNames.push(...(0, packageTools_1.extractShellApiPlugins)(functionName, props));
|
|
89
|
+
}
|
|
90
|
+
assignValue(variableName, jsonValue) {
|
|
91
|
+
this.commands.push({
|
|
92
|
+
type: 'assignValue',
|
|
93
|
+
variableName,
|
|
94
|
+
jsonValue,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
copyStream(sourceVar, targetVar, colmapVar = null) {
|
|
98
|
+
this.commands.push({
|
|
99
|
+
type: 'copyStream',
|
|
100
|
+
sourceVar,
|
|
101
|
+
targetVar,
|
|
102
|
+
colmapVar,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
comment(text) {
|
|
106
|
+
this.commands.push({
|
|
107
|
+
type: 'comment',
|
|
108
|
+
text,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
getScript(schedule = null) {
|
|
112
|
+
return {
|
|
113
|
+
type: 'json',
|
|
114
|
+
schedule,
|
|
115
|
+
commands: this.commands,
|
|
116
|
+
packageNames: this.packageNames,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.ScriptWriterJson = ScriptWriterJson;
|
|
121
|
+
function jsonScriptToJavascript(json) {
|
|
122
|
+
const { schedule, commands, packageNames } = json;
|
|
123
|
+
const script = new ScriptWriter();
|
|
124
|
+
for (const packageName of packageNames) {
|
|
125
|
+
if (!/^dbgate-plugin-.*$/.test(packageName)) {
|
|
126
|
+
throw new Error('Unallowed package name:' + packageName);
|
|
127
|
+
}
|
|
128
|
+
script.packageNames.push(packageName);
|
|
129
|
+
}
|
|
130
|
+
for (const cmd of commands) {
|
|
131
|
+
switch (cmd.type) {
|
|
132
|
+
case 'assign':
|
|
133
|
+
script.assignCore(cmd.variableName, cmd.functionName, cmd.props);
|
|
134
|
+
break;
|
|
135
|
+
case 'assignValue':
|
|
136
|
+
script.assignValue(cmd.variableName, cmd.jsonValue);
|
|
137
|
+
break;
|
|
138
|
+
case 'copyStream':
|
|
139
|
+
script.copyStream(cmd.sourceVar, cmd.targetVar, cmd.colmapVar);
|
|
140
|
+
break;
|
|
141
|
+
case 'endLine':
|
|
142
|
+
script.endLine();
|
|
143
|
+
break;
|
|
144
|
+
case 'comment':
|
|
145
|
+
script.comment(cmd.text);
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return script.getScript(schedule);
|
|
150
|
+
}
|
|
151
|
+
exports.jsonScriptToJavascript = jsonScriptToJavascript;
|
package/lib/driverBase.d.ts
CHANGED
package/lib/driverBase.js
CHANGED
|
@@ -123,4 +123,9 @@ exports.driverBase = {
|
|
|
123
123
|
return resp.rows;
|
|
124
124
|
});
|
|
125
125
|
},
|
|
126
|
+
readJsonQuery(pool, select, structure) {
|
|
127
|
+
const dmp = this.createDumper();
|
|
128
|
+
(0, dbgate_sqltree_1.dumpSqlSelect)(dmp, select);
|
|
129
|
+
return this.readQuery(pool, dmp.s, structure);
|
|
130
|
+
},
|
|
126
131
|
};
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/testPermission.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 {};
|
package/lib/testPermission.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
36
|
-
"dbgate-sqltree": "^4.7.4-alpha.
|
|
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
|
}
|