dbgate-api 6.3.2 → 6.4.0
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/package.json +9 -7
- package/src/controllers/archive.js +99 -6
- package/src/controllers/auth.js +3 -1
- package/src/controllers/config.js +135 -22
- package/src/controllers/connections.js +35 -2
- package/src/controllers/databaseConnections.js +101 -2
- package/src/controllers/files.js +59 -0
- package/src/controllers/jsldata.js +9 -0
- package/src/controllers/runners.js +25 -5
- package/src/controllers/serverConnections.js +22 -2
- package/src/controllers/storage.js +4 -0
- package/src/controllers/uploads.js +0 -46
- package/src/currentVersion.js +2 -2
- package/src/main.js +7 -1
- package/src/proc/connectProcess.js +14 -2
- package/src/proc/databaseConnectionProcess.js +70 -5
- package/src/proc/serverConnectionProcess.js +7 -1
- package/src/proc/sessionProcess.js +15 -178
- package/src/shell/archiveReader.js +3 -1
- package/src/shell/collectorWriter.js +2 -2
- package/src/shell/copyStream.js +1 -0
- package/src/shell/dataReplicator.js +96 -0
- package/src/shell/download.js +22 -6
- package/src/shell/index.js +12 -2
- package/src/shell/jsonLinesWriter.js +4 -3
- package/src/shell/queryReader.js +10 -3
- package/src/shell/unzipDirectory.js +91 -0
- package/src/shell/unzipJsonLinesData.js +60 -0
- package/src/shell/unzipJsonLinesFile.js +59 -0
- package/src/shell/zipDirectory.js +49 -0
- package/src/shell/zipJsonLinesData.js +49 -0
- package/src/storageModel.js +819 -0
- package/src/utility/DatastoreProxy.js +4 -0
- package/src/utility/cloudUpgrade.js +1 -59
- package/src/utility/connectUtility.js +3 -1
- package/src/utility/crypting.js +137 -22
- package/src/utility/extractSingleFileFromZip.js +77 -0
- package/src/utility/getMapExport.js +2 -0
- package/src/utility/handleQueryStream.js +186 -0
- package/src/utility/healthStatus.js +12 -1
- package/src/utility/listZipEntries.js +41 -0
- package/src/utility/processArgs.js +5 -0
- package/src/utility/sshTunnel.js +13 -2
- package/src/shell/dataDuplicator.js +0 -61
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const yauzl = require('yauzl');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { jsonLinesParse } = require('dbgate-tools');
|
|
4
|
+
|
|
5
|
+
function unzipJsonLinesFile(zipPath, fileInZip) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
// Open the zip file
|
|
8
|
+
yauzl.open(zipPath, { lazyEntries: true }, (err, zipfile) => {
|
|
9
|
+
if (err) {
|
|
10
|
+
return reject(err);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let result = null;
|
|
14
|
+
|
|
15
|
+
// Start reading entries
|
|
16
|
+
zipfile.readEntry();
|
|
17
|
+
|
|
18
|
+
zipfile.on('entry', entry => {
|
|
19
|
+
if (entry.fileName == fileInZip) {
|
|
20
|
+
zipfile.openReadStream(entry, (err, readStream) => {
|
|
21
|
+
if (err) {
|
|
22
|
+
return reject(err);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const chunks = [];
|
|
26
|
+
readStream.on('data', chunk => chunks.push(chunk));
|
|
27
|
+
readStream.on('end', () => {
|
|
28
|
+
try {
|
|
29
|
+
const fileContent = Buffer.concat(chunks).toString('utf-8');
|
|
30
|
+
const parsedJson = jsonLinesParse(fileContent);
|
|
31
|
+
result = parsedJson;
|
|
32
|
+
} catch (parseError) {
|
|
33
|
+
return reject(parseError);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Move to the next entry
|
|
37
|
+
zipfile.readEntry();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
// Not a JSON file, skip
|
|
42
|
+
zipfile.readEntry();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Resolve when no more entries
|
|
47
|
+
zipfile.on('end', () => {
|
|
48
|
+
resolve(result);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Catch errors from zipfile
|
|
52
|
+
zipfile.on('error', zipErr => {
|
|
53
|
+
reject(zipErr);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = unzipJsonLinesFile;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const archiver = require('archiver');
|
|
4
|
+
const { getLogger, extractErrorLogData } = require('dbgate-tools');
|
|
5
|
+
const { archivedir } = require('../utility/directories');
|
|
6
|
+
const logger = getLogger('compressDirectory');
|
|
7
|
+
|
|
8
|
+
function zipDirectory(inputDirectory, outputFile) {
|
|
9
|
+
if (outputFile.startsWith('archive:')) {
|
|
10
|
+
outputFile = path.join(archivedir(), outputFile.substring('archive:'.length));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const output = fs.createWriteStream(outputFile);
|
|
15
|
+
const archive = archiver('zip', { zlib: { level: 9 } }); // level: 9 => best compression
|
|
16
|
+
|
|
17
|
+
// Listen for all archive data to be written
|
|
18
|
+
output.on('close', () => {
|
|
19
|
+
logger.info(`ZIP file created (${archive.pointer()} total bytes)`);
|
|
20
|
+
resolve();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
archive.on('warning', err => {
|
|
24
|
+
logger.warn(extractErrorLogData(err), `Warning while creating ZIP: ${err.message}`);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
archive.on('error', err => {
|
|
28
|
+
logger.error(extractErrorLogData(err), `Error while creating ZIP: ${err.message}`);
|
|
29
|
+
reject(err);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Pipe archive data to the file
|
|
33
|
+
archive.pipe(output);
|
|
34
|
+
|
|
35
|
+
// Append files from a folder
|
|
36
|
+
archive.directory(inputDirectory, false, entryData => {
|
|
37
|
+
if (entryData.name.endsWith('.zip')) {
|
|
38
|
+
return false; // returning false means "do not include"
|
|
39
|
+
}
|
|
40
|
+
// otherwise, include it
|
|
41
|
+
return entryData;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Finalize the archive
|
|
45
|
+
archive.finalize();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = zipDirectory;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const archiver = require('archiver');
|
|
5
|
+
const { getLogger, extractErrorLogData, jsonLinesStringify } = require('dbgate-tools');
|
|
6
|
+
const { archivedir } = require('../utility/directories');
|
|
7
|
+
const logger = getLogger('compressDirectory');
|
|
8
|
+
|
|
9
|
+
function zipDirectory(jsonDb, outputFile) {
|
|
10
|
+
if (outputFile.startsWith('archive:')) {
|
|
11
|
+
outputFile = path.join(archivedir(), outputFile.substring('archive:'.length));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const output = fs.createWriteStream(outputFile);
|
|
16
|
+
const archive = archiver('zip', { zlib: { level: 9 } }); // level: 9 => best compression
|
|
17
|
+
|
|
18
|
+
// Listen for all archive data to be written
|
|
19
|
+
output.on('close', () => {
|
|
20
|
+
logger.info(`ZIP file created (${archive.pointer()} total bytes)`);
|
|
21
|
+
resolve();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
archive.on('warning', err => {
|
|
25
|
+
logger.warn(extractErrorLogData(err), `Warning while creating ZIP: ${err.message}`);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
archive.on('error', err => {
|
|
29
|
+
logger.error(extractErrorLogData(err), `Error while creating ZIP: ${err.message}`);
|
|
30
|
+
reject(err);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Pipe archive data to the file
|
|
34
|
+
archive.pipe(output);
|
|
35
|
+
|
|
36
|
+
for (const key in jsonDb) {
|
|
37
|
+
const data = jsonDb[key];
|
|
38
|
+
if (_.isArray(data)) {
|
|
39
|
+
const jsonString = jsonLinesStringify(data);
|
|
40
|
+
archive.append(jsonString, { name: `${key}.jsonl` });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Finalize the archive
|
|
45
|
+
archive.finalize();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = zipDirectory;
|