dbgate-api 5.0.2 → 5.0.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.
package/.env CHANGED
@@ -1,4 +1,6 @@
1
1
  DEVMODE=1
2
+ SHELL_SCRIPTING=1
3
+
2
4
  # PERMISSIONS=~widgets/app,~widgets/plugins
3
5
  # DISABLE_SHELL=1
4
6
  # HIDE_APP_EDITOR=1
package/env/portal/.env CHANGED
@@ -1,6 +1,6 @@
1
1
  DEVMODE=1
2
2
 
3
- CONNECTIONS=mysql,postgres,mongo,mongo2,mysqlssh,sqlite
3
+ CONNECTIONS=mysql,postgres,mongo,mongo2,mysqlssh,sqlite,relational
4
4
 
5
5
  LABEL_mysql=MySql localhost
6
6
  SERVER_mysql=localhost
@@ -41,4 +41,11 @@ LABEL_sqlite=sqlite
41
41
  FILE_sqlite=/home/jena/.dbgate/files/sqlite/feeds.sqlite
42
42
  ENGINE_sqlite=sqlite@dbgate-plugin-sqlite
43
43
 
44
+ LABEL_relational=Relational dataset repo
45
+ SERVER_relational=relational.fit.cvut.cz
46
+ USER_relational=guest
47
+ PASSWORD_relational=relational
48
+ ENGINE_relational=mariadb@dbgate-plugin-mysql
49
+ READONLY_relational=1
50
+
44
51
  # docker run -p 3000:3000 -e CONNECTIONS=mongo -e URL_mongo=mongodb://localhost:27017 -e ENGINE_mongo=mongo@dbgate-plugin-mongo -e LABEL_mongo=mongo dbgate/dbgate:beta
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dbgate-api",
3
3
  "main": "src/index.js",
4
- "version": "5.0.2",
4
+ "version": "5.0.4-alpha.7",
5
5
  "homepage": "https://dbgate.org/",
6
6
  "repository": {
7
7
  "type": "git",
@@ -26,8 +26,8 @@
26
26
  "cors": "^2.8.5",
27
27
  "cross-env": "^6.0.3",
28
28
  "dbgate-query-splitter": "^4.9.0",
29
- "dbgate-sqltree": "^5.0.2",
30
- "dbgate-tools": "^5.0.2",
29
+ "dbgate-sqltree": "^5.0.4-alpha.7",
30
+ "dbgate-tools": "^5.0.4-alpha.7",
31
31
  "diff": "^5.0.0",
32
32
  "diff2html": "^3.4.13",
33
33
  "eslint": "^6.8.0",
@@ -52,18 +52,18 @@
52
52
  "uuid": "^3.4.0"
53
53
  },
54
54
  "scripts": {
55
- "start": "env-cmd node src/index.js",
56
- "start:portal": "env-cmd -f env/portal/.env node src/index.js",
57
- "start:singledb": "env-cmd -f env/singledb/.env node src/index.js",
58
- "start:filedb": "env-cmd node src/index.js /home/jena/test/chinook/Chinook.db",
59
- "start:singleconn": "env-cmd node src/index.js --server localhost --user root --port 3307 --engine mysql@dbgate-plugin-mysql --password test",
55
+ "start": "env-cmd node src/index.js --listen-api",
56
+ "start:portal": "env-cmd -f env/portal/.env node src/index.js --listen-api",
57
+ "start:singledb": "env-cmd -f env/singledb/.env node src/index.js --listen-api",
58
+ "start:filedb": "env-cmd node src/index.js /home/jena/test/chinook/Chinook.db --listen-api",
59
+ "start:singleconn": "env-cmd node src/index.js --server localhost --user root --port 3307 --engine mysql@dbgate-plugin-mysql --password test --listen-api",
60
60
  "ts": "tsc",
61
61
  "build": "webpack"
62
62
  },
63
63
  "devDependencies": {
64
64
  "@types/fs-extra": "^9.0.11",
65
65
  "@types/lodash": "^4.14.149",
66
- "dbgate-types": "^5.0.2",
66
+ "dbgate-types": "^5.0.4-alpha.7",
67
67
  "env-cmd": "^10.1.0",
68
68
  "node-loader": "^1.0.2",
69
69
  "nodemon": "^2.0.2",
@@ -1,11 +1,8 @@
1
1
  const fs = require('fs-extra');
2
- const stream = require('stream');
3
2
  const readline = require('readline');
4
3
  const path = require('path');
5
- const { formatWithOptions } = require('util');
6
4
  const { archivedir, clearArchiveLinksCache, resolveArchiveFolder } = require('../utility/directories');
7
5
  const socket = require('../utility/socket');
8
- const JsonLinesDatastore = require('../utility/JsonLinesDatastore');
9
6
  const { saveFreeTableData } = require('../utility/freeTableStorage');
10
7
  const loadFilesRecursive = require('../utility/loadFilesRecursive');
11
8
 
@@ -45,29 +42,34 @@ module.exports = {
45
42
 
46
43
  files_meta: true,
47
44
  async files({ folder }) {
48
- const dir = resolveArchiveFolder(folder);
49
- if (!(await fs.exists(dir))) return [];
50
- const files = await loadFilesRecursive(dir); // fs.readdir(dir);
51
-
52
- function fileType(ext, type) {
53
- return files
54
- .filter(name => name.endsWith(ext))
55
- .map(name => ({
56
- name: name.slice(0, -ext.length),
57
- label: path.parse(name.slice(0, -ext.length)).base,
58
- type,
59
- }));
45
+ try {
46
+ const dir = resolveArchiveFolder(folder);
47
+ if (!(await fs.exists(dir))) return [];
48
+ const files = await loadFilesRecursive(dir); // fs.readdir(dir);
49
+
50
+ function fileType(ext, type) {
51
+ return files
52
+ .filter(name => name.endsWith(ext))
53
+ .map(name => ({
54
+ name: name.slice(0, -ext.length),
55
+ label: path.parse(name.slice(0, -ext.length)).base,
56
+ type,
57
+ }));
58
+ }
59
+
60
+ return [
61
+ ...fileType('.jsonl', 'jsonl'),
62
+ ...fileType('.table.yaml', 'table.yaml'),
63
+ ...fileType('.view.sql', 'view.sql'),
64
+ ...fileType('.proc.sql', 'proc.sql'),
65
+ ...fileType('.func.sql', 'func.sql'),
66
+ ...fileType('.trigger.sql', 'trigger.sql'),
67
+ ...fileType('.matview.sql', 'matview.sql'),
68
+ ];
69
+ } catch (err) {
70
+ console.log('Error reading archive files', err.message);
71
+ return [];
60
72
  }
61
-
62
- return [
63
- ...fileType('.jsonl', 'jsonl'),
64
- ...fileType('.table.yaml', 'table.yaml'),
65
- ...fileType('.view.sql', 'view.sql'),
66
- ...fileType('.proc.sql', 'proc.sql'),
67
- ...fileType('.func.sql', 'func.sql'),
68
- ...fileType('.trigger.sql', 'trigger.sql'),
69
- ...fileType('.matview.sql', 'matview.sql'),
70
- ];
71
73
  },
72
74
 
73
75
  refreshFiles_meta: true,
@@ -36,7 +36,7 @@ module.exports = {
36
36
  singleDatabase: connections.singleDatabase,
37
37
  // hideAppEditor: !!process.env.HIDE_APP_EDITOR,
38
38
  allowShellConnection: platformInfo.allowShellConnection,
39
- allowShellScripting: platformInfo.allowShellConnection,
39
+ allowShellScripting: platformInfo.allowShellScripting,
40
40
  isDocker: platformInfo.isDocker,
41
41
  permissions,
42
42
  login,
@@ -271,9 +271,9 @@ module.exports = {
271
271
  },
272
272
 
273
273
  syncModel_meta: true,
274
- async syncModel({ conid, database }) {
274
+ async syncModel({ conid, database, isFullRefresh }) {
275
275
  const conn = await this.ensureOpened(conid, database);
276
- conn.subprocess.send({ msgtype: 'syncModel' });
276
+ conn.subprocess.send({ msgtype: 'syncModel', isFullRefresh });
277
277
  return { status: 'ok' };
278
278
  },
279
279
 
@@ -8,6 +8,7 @@ const socket = require('../utility/socket');
8
8
  const scheduler = require('./scheduler');
9
9
  const getDiagramExport = require('../utility/getDiagramExport');
10
10
  const apps = require('./apps');
11
+ const getMapExport = require('../utility/getMapExport');
11
12
 
12
13
  function serialize(format, data) {
13
14
  if (format == 'text') return data;
@@ -187,6 +188,12 @@ module.exports = {
187
188
  return true;
188
189
  },
189
190
 
191
+ exportMap_meta: true,
192
+ async exportMap({ filePath, geoJson }) {
193
+ await fs.writeFile(filePath, getMapExport(geoJson));
194
+ return true;
195
+ },
196
+
190
197
  exportDiagram_meta: true,
191
198
  async exportDiagram({ filePath, html, css, themeType, themeClassName }) {
192
199
  await fs.writeFile(filePath, getDiagramExport(html, css, themeType, themeClassName));
@@ -1,5 +1,5 @@
1
1
 
2
2
  module.exports = {
3
- version: '5.0.2',
4
- buildTime: '2022-06-02T06:31:05.058Z'
3
+ version: '5.0.4-alpha.7',
4
+ buildTime: '2022-06-12T17:48:11.030Z'
5
5
  };
package/src/index.js CHANGED
@@ -8,9 +8,10 @@ if (processArgs.startProcess) {
8
8
  const proc = require('./proc');
9
9
  const module = proc[processArgs.startProcess];
10
10
  module.start();
11
- } else if (!processArgs.checkParent && !global['API_PACKAGE']) {
12
- const main = require('./main');
11
+ }
13
12
 
13
+ if (processArgs.listenApi) {
14
+ const main = require('./main');
14
15
  main.start();
15
16
  }
16
17
 
@@ -15,6 +15,7 @@ let afterConnectCallbacks = [];
15
15
  let afterAnalyseCallbacks = [];
16
16
  let analysedStructure = null;
17
17
  let lastPing = null;
18
+ let lastStatusString = null;
18
19
  let lastStatus = null;
19
20
  let analysedTime = 0;
20
21
  let serverVersion;
@@ -78,21 +79,24 @@ async function handleIncrementalRefresh(forceSend) {
78
79
  resolveAnalysedPromises();
79
80
  }
80
81
 
81
- function handleSyncModel() {
82
+ function handleSyncModel({ isFullRefresh }) {
82
83
  if (loadingModel) return;
83
- handleIncrementalRefresh();
84
+ if (isFullRefresh) handleFullRefresh();
85
+ else handleIncrementalRefresh();
84
86
  }
85
87
 
86
88
  function setStatus(status) {
87
- const statusString = stableStringify(status);
88
- if (lastStatus != statusString) {
89
- process.send({ msgtype: 'status', status: { ...status, counter: getStatusCounter() } });
90
- lastStatus = statusString;
89
+ const newStatus = { ...lastStatus, ...status };
90
+ const statusString = stableStringify(newStatus);
91
+ if (lastStatusString != statusString) {
92
+ process.send({ msgtype: 'status', status: { ...newStatus, counter: getStatusCounter() } });
93
+ lastStatusString = statusString;
94
+ lastStatus = newStatus;
91
95
  }
92
96
  }
93
97
 
94
98
  function setStatusName(name) {
95
- setStatus({ name });
99
+ setStatus({ name, message: null });
96
100
  }
97
101
 
98
102
  async function readVersion() {
@@ -109,6 +113,7 @@ async function handleConnect({ connection, structure, globalSettings }) {
109
113
  if (!structure) setStatusName('pending');
110
114
  const driver = requireEngineDriver(storedConnection);
111
115
  systemConnection = await checkedAsyncCall(connectUtility(driver, storedConnection, 'app'));
116
+ systemConnection.feedback = feedback => setStatus({ feedback });
112
117
  await checkedAsyncCall(readVersion());
113
118
  if (structure) {
114
119
  analysedStructure = structure;
@@ -0,0 +1,77 @@
1
+ const getMapExport = (geoJson) => {
2
+ return `<html>
3
+ <meta charset='utf-8'>
4
+
5
+ <head>
6
+ <link rel="stylesheet" href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css"
7
+ integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ=="
8
+ crossorigin=""/>
9
+
10
+ <script src="https://unpkg.com/leaflet@1.8.0/dist/leaflet.js"
11
+ integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ=="
12
+ crossorigin=""></script>
13
+
14
+ <script>
15
+ function createMap() {
16
+ map = leaflet.map('map').setView([50, 15], 13);
17
+
18
+ leaflet
19
+ .tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
20
+ maxZoom: 19,
21
+ attribution: '<a href="https://dbgate.org" title="Exported from DbGate">DbGate</a> | © OpenStreetMap',
22
+ })
23
+ .addTo(map);
24
+
25
+ const geoJsonObj = leaflet
26
+ .geoJSON(${JSON.stringify(geoJson)}, {
27
+ style: function () {
28
+ return {
29
+ weight: 2,
30
+ fillColor: '#ff7800',
31
+ color: '#ff7800',
32
+ opacity: 0.8,
33
+ fillOpacity: 0.4,
34
+ };
35
+ },
36
+ pointToLayer: (feature, latlng) => {
37
+ return leaflet.circleMarker(latlng, {
38
+ radius: 7,
39
+ weight: 2,
40
+ fillColor: '#ff0000',
41
+ color: '#ff0000',
42
+ opacity: 0.9,
43
+ fillOpacity: 0.9,
44
+ });
45
+ },
46
+ onEachFeature: (feature, layer) => {
47
+ // does this feature have a property named popupContent?
48
+ if (feature.properties && feature.properties.popupContent) {
49
+ layer.bindPopup(feature.properties.popupContent);
50
+ layer.bindTooltip(feature.properties.popupContent);
51
+ }
52
+ },
53
+ })
54
+ .addTo(map);
55
+ map.fitBounds(geoJsonObj.getBounds());
56
+ }
57
+ </script>
58
+
59
+ <style>
60
+ #map {
61
+ position: fixed;
62
+ left: 0;
63
+ top: 0;
64
+ right: 0;
65
+ bottom: 0;
66
+ }
67
+ </style>
68
+ </head>
69
+
70
+ <body onload='createMap()'>
71
+ <div id='map'></div>
72
+ </body>
73
+
74
+ </html>`;
75
+ };
76
+
77
+ module.exports = getMapExport;
@@ -11,6 +11,7 @@ const startProcess = getNamedArg('--start-process');
11
11
  const isForkedApi = process.argv.includes('--is-forked-api');
12
12
  const pluginsDir = getNamedArg('--plugins-dir');
13
13
  const workspaceDir = getNamedArg('--workspace-dir');
14
+ const listenApi = process.argv.includes('--listen-api');
14
15
 
15
16
  function getPassArgs() {
16
17
  const res = [];
@@ -30,4 +31,5 @@ module.exports = {
30
31
  getPassArgs,
31
32
  pluginsDir,
32
33
  workspaceDir,
34
+ listenApi,
33
35
  };