dbgate-api 5.0.3 → 5.0.4-alpha.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dbgate-api",
3
3
  "main": "src/index.js",
4
- "version": "5.0.3",
4
+ "version": "5.0.4-alpha.2",
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.3",
30
- "dbgate-tools": "^5.0.3",
29
+ "dbgate-sqltree": "^5.0.4-alpha.2",
30
+ "dbgate-tools": "^5.0.4-alpha.2",
31
31
  "diff": "^5.0.0",
32
32
  "diff2html": "^3.4.13",
33
33
  "eslint": "^6.8.0",
@@ -63,7 +63,7 @@
63
63
  "devDependencies": {
64
64
  "@types/fs-extra": "^9.0.11",
65
65
  "@types/lodash": "^4.14.149",
66
- "dbgate-types": "^5.0.3",
66
+ "dbgate-types": "^5.0.4-alpha.2",
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,
@@ -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.3',
4
- buildTime: '2022-06-10T18:31:02.360Z'
3
+ version: '5.0.4-alpha.2',
4
+ buildTime: '2022-06-12T07:51:14.028Z'
5
5
  };
@@ -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;