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

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.
@@ -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;
@@ -26,4 +26,5 @@ export declare const driverBase: {
26
26
  sql: string;
27
27
  }[];
28
28
  loadFieldValues(pool: any, name: any, columnName: any, search: any): Promise<any>;
29
+ readJsonQuery(pool: any, select: any, structure: any): any;
29
30
  };
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
@@ -17,3 +17,4 @@ export * from './yamlModelConv';
17
17
  export * from './stringTools';
18
18
  export * from './computeDiffRows';
19
19
  export * from './preloadedRowsTools';
20
+ export * from './ScriptWriter';
package/lib/index.js CHANGED
@@ -29,3 +29,4 @@ __exportStar(require("./yamlModelConv"), exports);
29
29
  __exportStar(require("./stringTools"), exports);
30
30
  __exportStar(require("./computeDiffRows"), exports);
31
31
  __exportStar(require("./preloadedRowsTools"), exports);
32
+ __exportStar(require("./ScriptWriter"), exports);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.7.4-alpha.3",
2
+ "version": "4.7.4-alpha.7",
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.3",
28
+ "dbgate-types": "^4.7.4-alpha.7",
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.3",
36
- "dbgate-sqltree": "^4.7.4-alpha.3",
35
+ "dbgate-query-splitter": "^4.7.4-alpha.7",
36
+ "dbgate-sqltree": "^4.7.4-alpha.7",
37
37
  "uuid": "^3.4.0"
38
38
  }
39
39
  }