dbgate-api 4.4.4 → 4.6.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.
@@ -7,14 +7,14 @@ function pickObjectNames(array) {
7
7
  }
8
8
 
9
9
  module.exports = {
10
- // tableData_meta: 'get',
10
+ // tableData_meta: true,
11
11
  // async tableData({ conid, database, schemaName, pureName }) {
12
12
  // const opened = await databaseConnections.ensureOpened(conid, database);
13
13
  // const res = await databaseConnections.sendRequest(opened, { msgtype: 'tableData', schemaName, pureName });
14
14
  // return res;
15
15
  // },
16
16
 
17
- listObjects_meta: 'get',
17
+ listObjects_meta: true,
18
18
  async listObjects({ conid, database }) {
19
19
  const opened = await databaseConnections.ensureOpened(conid, database);
20
20
  const types = ['tables', 'collections', 'views', 'procedures', 'functions', 'triggers'];
@@ -27,7 +27,7 @@ module.exports = {
27
27
  );
28
28
  },
29
29
 
30
- tableInfo_meta: 'get',
30
+ tableInfo_meta: true,
31
31
  async tableInfo({ conid, database, schemaName, pureName }) {
32
32
  const opened = await databaseConnections.ensureOpened(conid, database);
33
33
  const table = opened.structure.tables.find(x => x.pureName == pureName && x.schemaName == schemaName);
@@ -38,7 +38,7 @@ module.exports = {
38
38
  };
39
39
  },
40
40
 
41
- sqlObjectInfo_meta: 'get',
41
+ sqlObjectInfo_meta: true,
42
42
  async sqlObjectInfo({ objectTypeField, conid, database, schemaName, pureName }) {
43
43
  const opened = await databaseConnections.ensureOpened(conid, database);
44
44
  const res = opened.structure[objectTypeField].find(x => x.pureName == pureName && x.schemaName == schemaName);
@@ -12,7 +12,7 @@ const _ = require('lodash');
12
12
  const packagedPluginsContent = require('../packagedPluginsContent');
13
13
 
14
14
  module.exports = {
15
- script_meta: 'get',
15
+ script_meta: true,
16
16
  async script({ packageName }) {
17
17
  const packagedContent = packagedPluginsContent();
18
18
 
@@ -30,7 +30,7 @@ module.exports = {
30
30
  return data;
31
31
  },
32
32
 
33
- search_meta: 'get',
33
+ search_meta: true,
34
34
  async search({ filter }) {
35
35
  // DOCS: https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#get-v1search
36
36
  const resp = await axios.default.get(
@@ -40,7 +40,7 @@ module.exports = {
40
40
  return (objects || []).map(x => x.package);
41
41
  },
42
42
 
43
- info_meta: 'get',
43
+ info_meta: true,
44
44
  async info({ packageName }) {
45
45
  try {
46
46
  const infoResp = await axios.default.get(`https://registry.npmjs.org/${packageName}`);
@@ -63,7 +63,7 @@ module.exports = {
63
63
  }
64
64
  },
65
65
 
66
- installed_meta: 'get',
66
+ installed_meta: true,
67
67
  async installed() {
68
68
  const packagedContent = packagedPluginsContent();
69
69
 
@@ -107,7 +107,7 @@ module.exports = {
107
107
  // await fs.writeFile(path.join(datadir(), 'removed-plugins'), this.removedPlugins.join('\n'));
108
108
  // },
109
109
 
110
- install_meta: 'post',
110
+ install_meta: true,
111
111
  async install({ packageName }) {
112
112
  if (!hasPermission(`plugins/install`)) return;
113
113
  const dir = path.join(pluginsdir(), packageName);
@@ -120,7 +120,7 @@ module.exports = {
120
120
  // await this.saveRemovePlugins();
121
121
  },
122
122
 
123
- uninstall_meta: 'post',
123
+ uninstall_meta: true,
124
124
  async uninstall({ packageName }) {
125
125
  if (!hasPermission(`plugins/install`)) return;
126
126
  const dir = path.join(pluginsdir(), packageName);
@@ -130,7 +130,7 @@ module.exports = {
130
130
  await this.saveRemovePlugins();
131
131
  },
132
132
 
133
- upgrade_meta: 'post',
133
+ upgrade_meta: true,
134
134
  async upgrade({ packageName }) {
135
135
  if (!hasPermission(`plugins/install`)) return;
136
136
  const dir = path.join(pluginsdir(), packageName);
@@ -143,13 +143,13 @@ module.exports = {
143
143
  socket.emitChanged(`installed-plugins-changed`);
144
144
  },
145
145
 
146
- command_meta: 'post',
146
+ command_meta: true,
147
147
  async command({ packageName, command, args }) {
148
148
  const content = requirePlugin(packageName);
149
149
  return content.commands[command](args);
150
150
  },
151
151
 
152
- authTypes_meta: 'get',
152
+ authTypes_meta: true,
153
153
  async authTypes({ engine }) {
154
154
  const packageName = extractPackageName(engine);
155
155
  const content = requirePlugin(packageName);
@@ -34,7 +34,7 @@ function readCore(reader, skip, limit, filter) {
34
34
  }
35
35
 
36
36
  module.exports = {
37
- read_meta: 'get',
37
+ read_meta: true,
38
38
  async read({ skip, limit, filter }) {
39
39
  const fileName = path.join(datadir(), 'query-history.jsonl');
40
40
  // @ts-ignore
@@ -44,7 +44,7 @@ module.exports = {
44
44
  return res;
45
45
  },
46
46
 
47
- write_meta: 'post',
47
+ write_meta: true,
48
48
  async write({ data }) {
49
49
  const fileName = path.join(datadir(), 'query-history.jsonl');
50
50
  await fs.appendFile(fileName, JSON.stringify(data) + '\n');
@@ -8,6 +8,7 @@ const { fork } = require('child_process');
8
8
  const { rundir, uploadsdir, pluginsdir, getPluginBackendPath, packagedPluginList } = require('../utility/directories');
9
9
  const { extractShellApiPlugins, extractShellApiFunctionName } = require('dbgate-tools');
10
10
  const { handleProcessCommunication } = require('../utility/processComm');
11
+ const processArgs = require('../utility/processArgs');
11
12
 
12
13
  function extractPlugins(script) {
13
14
  const requireRegex = /\s*\/\/\s*@require\s+([^\s]+)\s*\n/g;
@@ -98,15 +99,22 @@ module.exports = {
98
99
  const pluginNames = _.union(fs.readdirSync(pluginsdir()), packagedPluginList);
99
100
  console.log(`RUNNING SCRIPT ${scriptFile}`);
100
101
  // const subprocess = fork(scriptFile, ['--checkParent', '--max-old-space-size=8192'], {
101
- const subprocess = fork(scriptFile, ['--checkParent', ...process.argv.slice(3)], {
102
- cwd: directory,
103
- stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
104
- env: {
105
- ...process.env,
106
- DBGATE_API: global['dbgateApiModulePath'] || process.argv[1],
107
- ..._.fromPairs(pluginNames.map(name => [`PLUGIN_${_.camelCase(name)}`, getPluginBackendPath(name)])),
108
- },
109
- });
102
+ const subprocess = fork(
103
+ scriptFile,
104
+ [
105
+ '--checkParent', // ...process.argv.slice(3)
106
+ ...processArgs.getPassArgs(),
107
+ ],
108
+ {
109
+ cwd: directory,
110
+ stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
111
+ env: {
112
+ ...process.env,
113
+ DBGATE_API: global['API_PACKAGE'] || global['dbgateApiModulePath'] || process.argv[1],
114
+ ..._.fromPairs(pluginNames.map(name => [`PLUGIN_${_.camelCase(name)}`, getPluginBackendPath(name)])),
115
+ },
116
+ }
117
+ );
110
118
  const pipeDispatcher = severity => data =>
111
119
  this.dispatchMessage(runid, { severity, message: data.toString().trim() });
112
120
 
@@ -136,21 +144,21 @@ module.exports = {
136
144
  if (handleProcessCommunication(message, subprocess)) return;
137
145
  this[`handle_${msgtype}`](runid, message);
138
146
  });
139
- return newOpened;
147
+ return _.pick(newOpened, ['runid']);
140
148
  },
141
149
 
142
- start_meta: 'post',
150
+ start_meta: true,
143
151
  async start({ script }) {
144
152
  const runid = uuidv1();
145
153
  return this.startCore(runid, scriptTemplate(script, false));
146
154
  },
147
155
 
148
- getNodeScript_meta: 'post',
156
+ getNodeScript_meta: true,
149
157
  async getNodeScript({ script }) {
150
158
  return scriptTemplate(script, true);
151
159
  },
152
160
 
153
- cancel_meta: 'post',
161
+ cancel_meta: true,
154
162
  async cancel({ runid }) {
155
163
  const runner = this.opened.find(x => x.runid == runid);
156
164
  if (!runner) {
@@ -160,7 +168,7 @@ module.exports = {
160
168
  return { state: 'ok' };
161
169
  },
162
170
 
163
- files_meta: 'get',
171
+ files_meta: true,
164
172
  async files({ runid }) {
165
173
  const directory = path.join(rundir(), runid);
166
174
  const files = await fs.readdir(directory);
@@ -176,7 +184,7 @@ module.exports = {
176
184
  return res;
177
185
  },
178
186
 
179
- loadReader_meta: 'post',
187
+ loadReader_meta: true,
180
188
  async loadReader({ functionName, props }) {
181
189
  const promise = new Promise((resolve, reject) => {
182
190
  const runid = uuidv1();
@@ -6,6 +6,7 @@ const AsyncLock = require('async-lock');
6
6
  const { handleProcessCommunication } = require('../utility/processComm');
7
7
  const lock = new AsyncLock();
8
8
  const config = require('./config');
9
+ const processArgs = require('../utility/processArgs');
9
10
 
10
11
  module.exports = {
11
12
  opened: [],
@@ -37,10 +38,12 @@ module.exports = {
37
38
  const existing = this.opened.find(x => x.conid == conid);
38
39
  if (existing) return existing;
39
40
  const connection = await connections.get({ conid });
40
- const subprocess = fork(process.argv[1], [
41
+ const subprocess = fork(global['API_PACKAGE'] || process.argv[1], [
42
+ '--is-forked-api',
41
43
  '--start-process',
42
44
  'serverConnectionProcess',
43
- ...process.argv.slice(3),
45
+ ...processArgs.getPassArgs(),
46
+ // ...process.argv.slice(3),
44
47
  ]);
45
48
  const newOpened = {
46
49
  conid,
@@ -86,25 +89,25 @@ module.exports = {
86
89
  }
87
90
  },
88
91
 
89
- disconnect_meta: 'post',
92
+ disconnect_meta: true,
90
93
  async disconnect({ conid }) {
91
94
  await this.close(conid, true);
92
95
  return { status: 'ok' };
93
96
  },
94
97
 
95
- listDatabases_meta: 'get',
98
+ listDatabases_meta: true,
96
99
  async listDatabases({ conid }) {
97
100
  const opened = await this.ensureOpened(conid);
98
101
  return opened.databases;
99
102
  },
100
103
 
101
- version_meta: 'get',
104
+ version_meta: true,
102
105
  async version({ conid }) {
103
106
  const opened = await this.ensureOpened(conid);
104
107
  return opened.version;
105
108
  },
106
109
 
107
- serverStatus_meta: 'get',
110
+ serverStatus_meta: true,
108
111
  async serverStatus() {
109
112
  return {
110
113
  ...this.closed,
@@ -112,7 +115,7 @@ module.exports = {
112
115
  };
113
116
  },
114
117
 
115
- ping_meta: 'post',
118
+ ping_meta: true,
116
119
  async ping({ connections }) {
117
120
  await Promise.all(
118
121
  _.uniq(connections).map(async conid => {
@@ -128,7 +131,7 @@ module.exports = {
128
131
  return { status: 'ok' };
129
132
  },
130
133
 
131
- refresh_meta: 'post',
134
+ refresh_meta: true,
132
135
  async refresh({ conid, keepOpen }) {
133
136
  if (!keepOpen) this.close(conid);
134
137
 
@@ -136,7 +139,7 @@ module.exports = {
136
139
  return { status: 'ok' };
137
140
  },
138
141
 
139
- createDatabase_meta: 'post',
142
+ createDatabase_meta: true,
140
143
  async createDatabase({ conid, name }) {
141
144
  const opened = await this.ensureOpened(conid);
142
145
  opened.subprocess.send({ msgtype: 'createDatabase', name });
@@ -5,6 +5,7 @@ const socket = require('../utility/socket');
5
5
  const { fork } = require('child_process');
6
6
  const jsldata = require('./jsldata');
7
7
  const { handleProcessCommunication } = require('../utility/processComm');
8
+ const processArgs = require('../utility/processArgs');
8
9
 
9
10
  module.exports = {
10
11
  /** @type {import('dbgate-types').OpenedSession[]} */
@@ -61,11 +62,17 @@ module.exports = {
61
62
 
62
63
  handle_ping() {},
63
64
 
64
- create_meta: 'post',
65
+ create_meta: true,
65
66
  async create({ conid, database }) {
66
67
  const sesid = uuidv1();
67
68
  const connection = await connections.get({ conid });
68
- const subprocess = fork(process.argv[1], ['--start-process', 'sessionProcess', ...process.argv.slice(3)]);
69
+ const subprocess = fork(global['API_PACKAGE'] || process.argv[1], [
70
+ '--is-forked-api',
71
+ '--start-process',
72
+ 'sessionProcess',
73
+ ...processArgs.getPassArgs(),
74
+ // ...process.argv.slice(3),
75
+ ]);
69
76
  const newOpened = {
70
77
  conid,
71
78
  database,
@@ -81,10 +88,10 @@ module.exports = {
81
88
  this[`handle_${msgtype}`](sesid, message);
82
89
  });
83
90
  subprocess.send({ msgtype: 'connect', ...connection, database });
84
- return newOpened;
91
+ return _.pick(newOpened, ['conid', 'database', 'sesid']);
85
92
  },
86
93
 
87
- executeQuery_meta: 'post',
94
+ executeQuery_meta: true,
88
95
  async executeQuery({ sesid, sql }) {
89
96
  const session = this.opened.find(x => x.sesid == sesid);
90
97
  if (!session) {
@@ -98,7 +105,7 @@ module.exports = {
98
105
  return { state: 'ok' };
99
106
  },
100
107
 
101
- // cancel_meta: 'post',
108
+ // cancel_meta: true,
102
109
  // async cancel({ sesid }) {
103
110
  // const session = this.opened.find((x) => x.sesid == sesid);
104
111
  // if (!session) {
@@ -108,7 +115,7 @@ module.exports = {
108
115
  // return { state: 'ok' };
109
116
  // },
110
117
 
111
- kill_meta: 'post',
118
+ kill_meta: true,
112
119
  async kill({ sesid }) {
113
120
  const session = this.opened.find(x => x.sesid == sesid);
114
121
  if (!session) {
@@ -119,7 +126,7 @@ module.exports = {
119
126
  return { state: 'ok' };
120
127
  },
121
128
 
122
- // runCommand_meta: 'post',
129
+ // runCommand_meta: true,
123
130
  // async runCommand({ conid, database, sql }) {
124
131
  // console.log(`Running SQL command , conid=${conid}, database=${database}, sql=${sql}`);
125
132
  // const opened = await this.ensureOpened(conid, database);
@@ -1,5 +1,5 @@
1
1
 
2
2
  module.exports = {
3
- version: '4.4.4',
4
- buildTime: '2021-12-10T19:15:01.248Z'
3
+ version: '4.6.0',
4
+ buildTime: '2022-01-26T16:57:37.630Z'
5
5
  };
package/src/index.js CHANGED
@@ -8,7 +8,7 @@ if (processArgs.startProcess) {
8
8
  const proc = require('./proc');
9
9
  const module = proc[processArgs.startProcess];
10
10
  module.start();
11
- } else if (!module['parent'] && !processArgs.checkParent) {
11
+ } else if (!processArgs.checkParent && !global['API_PACKAGE'] && !global['dbgateApiModulePath']) {
12
12
  const main = require('./main');
13
13
 
14
14
  main.start();
package/src/main.js CHANGED
@@ -4,12 +4,8 @@ const bodyParser = require('body-parser');
4
4
  const fileUpload = require('express-fileupload');
5
5
  const http = require('http');
6
6
  const cors = require('cors');
7
- const io = require('socket.io');
8
- const fs = require('fs');
9
7
  const getPort = require('get-port');
10
- const childProcessChecker = require('./utility/childProcessChecker');
11
8
  const path = require('path');
12
- const crypto = require('crypto');
13
9
 
14
10
  const useController = require('./utility/useController');
15
11
  const socket = require('./utility/socket');
@@ -31,10 +27,7 @@ const queryHistory = require('./controllers/queryHistory');
31
27
 
32
28
  const { rundir } = require('./utility/directories');
33
29
  const platformInfo = require('./utility/platformInfo');
34
- const processArgs = require('./utility/processArgs');
35
- const timingSafeCheckToken = require('./utility/timingSafeCheckToken');
36
30
 
37
- let authorization = null;
38
31
  let checkLocalhostOrigin = null;
39
32
 
40
33
  function start() {
@@ -43,7 +36,6 @@ function start() {
43
36
  const app = express();
44
37
 
45
38
  const server = http.createServer(app);
46
- socket.set(io(server));
47
39
 
48
40
  if (process.env.LOGIN && process.env.PASSWORD) {
49
41
  app.use(
@@ -58,9 +50,6 @@ function start() {
58
50
  }
59
51
 
60
52
  app.use(function (req, res, next) {
61
- if (authorization && !timingSafeCheckToken(req.headers.authorization, authorization)) {
62
- return res.status(403).json({ error: 'Not authorized!' });
63
- }
64
53
  if (checkLocalhostOrigin) {
65
54
  if (
66
55
  req.headers.origin &&
@@ -81,6 +70,20 @@ function start() {
81
70
  });
82
71
 
83
72
  app.use(cors());
73
+
74
+ app.get('/stream', async function (req, res) {
75
+ res.set({
76
+ 'Cache-Control': 'no-cache',
77
+ 'Content-Type': 'text/event-stream',
78
+ Connection: 'keep-alive',
79
+ });
80
+ res.flushHeaders();
81
+
82
+ // Tell the client to retry every 10 seconds if connectivity is lost
83
+ res.write('retry: 10000\n\n');
84
+ socket.setSseResponse(res);
85
+ });
86
+
84
87
  app.use(bodyParser.json({ limit: '50mb' }));
85
88
 
86
89
  app.use(
@@ -90,20 +93,7 @@ function start() {
90
93
  })
91
94
  );
92
95
 
93
- useController(app, '/connections', connections);
94
- useController(app, '/server-connections', serverConnections);
95
- useController(app, '/database-connections', databaseConnections);
96
- useController(app, '/metadata', metadata);
97
- useController(app, '/sessions', sessions);
98
- useController(app, '/runners', runners);
99
- useController(app, '/jsldata', jsldata);
100
- useController(app, '/config', config);
101
- useController(app, '/archive', archive);
102
- useController(app, '/uploads', uploads);
103
- useController(app, '/plugins', plugins);
104
- useController(app, '/files', files);
105
- useController(app, '/scheduler', scheduler);
106
- useController(app, '/query-history', queryHistory);
96
+ useAllControllers(app, null);
107
97
 
108
98
  // if (process.env.PAGES_DIRECTORY) {
109
99
  // app.use('/pages', express.static(process.env.PAGES_DIRECTORY));
@@ -122,19 +112,7 @@ function start() {
122
112
  }
123
113
  }
124
114
 
125
- if (processArgs.dynport) {
126
- childProcessChecker();
127
-
128
- authorization = crypto.randomBytes(32).toString('hex');
129
-
130
- getPort().then(port => {
131
- checkLocalhostOrigin = `localhost:${port}`;
132
- server.listen(port, () => {
133
- console.log(`DbGate API listening on port ${port}`);
134
- process.send({ msgtype: 'listening', port, authorization });
135
- });
136
- });
137
- } else if (platformInfo.isNpmDist) {
115
+ if (platformInfo.isNpmDist) {
138
116
  app.use(express.static(path.join(__dirname, '../../dbgate-web/public')));
139
117
  getPort({ port: 5000 }).then(port => {
140
118
  server.listen(port, () => {
@@ -142,8 +120,47 @@ function start() {
142
120
  });
143
121
  });
144
122
  } else {
145
- server.listen(3000);
123
+ const port = process.env.PORT || 3000;
124
+ console.log('DbGate API listening on port', port);
125
+ server.listen(port);
126
+ }
127
+
128
+ function shutdown() {
129
+ console.log('\nShutting down DbGate API server');
130
+ server.close(() => {
131
+ console.log('Server shut down, terminating');
132
+ process.exit(0);
133
+ });
134
+ setTimeout(() => {
135
+ console.log('Server close timeout, terminating');
136
+ process.exit(0);
137
+ }, 1000);
146
138
  }
139
+
140
+ process.on('SIGINT', shutdown);
141
+ process.on('SIGTERM', shutdown);
142
+ process.on('SIGBREAK', shutdown);
143
+ }
144
+
145
+ function useAllControllers(app, electron) {
146
+ useController(app, electron, '/connections', connections);
147
+ useController(app, electron, '/server-connections', serverConnections);
148
+ useController(app, electron, '/database-connections', databaseConnections);
149
+ useController(app, electron, '/metadata', metadata);
150
+ useController(app, electron, '/sessions', sessions);
151
+ useController(app, electron, '/runners', runners);
152
+ useController(app, electron, '/jsldata', jsldata);
153
+ useController(app, electron, '/config', config);
154
+ useController(app, electron, '/archive', archive);
155
+ useController(app, electron, '/uploads', uploads);
156
+ useController(app, electron, '/plugins', plugins);
157
+ useController(app, electron, '/files', files);
158
+ useController(app, electron, '/scheduler', scheduler);
159
+ useController(app, electron, '/query-history', queryHistory);
160
+ }
161
+
162
+ function initializeElectronSender(electronSender) {
163
+ socket.setElectronSender(electronSender);
147
164
  }
148
165
 
149
- module.exports = { start };
166
+ module.exports = { start, useAllControllers, initializeElectronSender };
@@ -1,5 +1,13 @@
1
1
  const argIndex = process.argv.indexOf('--native-modules');
2
- const redirectFile = argIndex > 0 ? process.argv[argIndex + 1] : null;
2
+ const redirectFile = global['NATIVE_MODULES'] || (argIndex > 0 ? process.argv[argIndex + 1] : null);
3
3
 
4
- // @ts-ignore
5
- module.exports = redirectFile ? __non_webpack_require__(redirectFile) : require('./nativeModulesContent');
4
+ function requireDynamic(file) {
5
+ try {
6
+ // @ts-ignore
7
+ return __non_webpack_require__(redirectFile);
8
+ } catch (err) {
9
+ return require(redirectFile);
10
+ }
11
+ }
12
+
13
+ module.exports = redirectFile ? requireDynamic(redirectFile) : require('./nativeModulesContent');
@@ -2,6 +2,6 @@
2
2
  // this file is generated automatically by script fillNativeModules.js, do not edit it manually
3
3
  const content = {};
4
4
 
5
- content['better-sqlite3-with-prebuilds'] = () => require('better-sqlite3-with-prebuilds');
5
+ content['better-sqlite3'] = () => require('better-sqlite3');
6
6
 
7
7
  module.exports = content;
@@ -2,17 +2,9 @@ const childProcessChecker = require('../utility/childProcessChecker');
2
2
  const requireEngineDriver = require('../utility/requireEngineDriver');
3
3
  const connectUtility = require('../utility/connectUtility');
4
4
  const { handleProcessCommunication } = require('../utility/processComm');
5
+ const { pickSafeConnectionInfo } = require('../utility/crypting');
5
6
  const _ = require('lodash');
6
7
 
7
- function pickSafeConnectionInfo(connection) {
8
- return _.mapValues(connection, (v, k) => {
9
- if (k == 'engine' || k == 'port' || k == 'authType' || k == 'sshMode' || k == 'passwordMode') return v;
10
- if (v === null || v === true || v === false) return v;
11
- if (v) return '***';
12
- return undefined;
13
- });
14
- }
15
-
16
8
  const formatErrorDetail = (e, connection) => `${e.stack}
17
9
 
18
10
  Error JSON: ${JSON.stringify(e, undefined, 2)}
@@ -270,6 +270,7 @@ function start() {
270
270
  try {
271
271
  await handleMessage(message);
272
272
  } catch (e) {
273
+ console.error('Error in DB connection', e);
273
274
  process.send({ msgtype: 'error', error: e.message });
274
275
  }
275
276
  });
@@ -1,6 +1,7 @@
1
1
  const { fork } = require('child_process');
2
2
  const uuidv1 = require('uuid/v1');
3
3
  const { handleProcessCommunication } = require('./processComm');
4
+ const processArgs = require('../utility/processArgs');
4
5
 
5
6
  class DatastoreProxy {
6
7
  constructor(file) {
@@ -29,7 +30,13 @@ class DatastoreProxy {
29
30
 
30
31
  async ensureSubprocess() {
31
32
  if (!this.subprocess) {
32
- this.subprocess = fork(process.argv[1], ['--start-process', 'jslDatastoreProcess', ...process.argv.slice(3)]);
33
+ this.subprocess = fork(global['API_PACKAGE'] || process.argv[1], [
34
+ '--is-forked-api',
35
+ '--start-process',
36
+ 'jslDatastoreProcess',
37
+ ...processArgs.getPassArgs(),
38
+ // ...process.argv.slice(3),
39
+ ]);
33
40
 
34
41
  this.subprocess.on('message', message => {
35
42
  // @ts-ignore
@@ -2,6 +2,7 @@ const crypto = require('crypto');
2
2
  const simpleEncryptor = require('simple-encryptor');
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
+ const _ = require('lodash');
5
6
 
6
7
  const { datadir } = require('./directories');
7
8
 
@@ -81,8 +82,18 @@ function decryptConnection(connection) {
81
82
  return connection;
82
83
  }
83
84
 
85
+ function pickSafeConnectionInfo(connection) {
86
+ return _.mapValues(connection, (v, k) => {
87
+ if (k == 'engine' || k == 'port' || k == 'authType' || k == 'sshMode' || k == 'passwordMode') return v;
88
+ if (v === null || v === true || v === false) return v;
89
+ if (v) return '***';
90
+ return undefined;
91
+ });
92
+ }
93
+
84
94
  module.exports = {
85
95
  loadEncryptionKey,
86
96
  encryptConnection,
87
97
  decryptConnection,
98
+ pickSafeConnectionInfo,
88
99
  };
@@ -41,6 +41,10 @@ const archivedir = dirFunc('archive');
41
41
  const filesdir = dirFunc('files');
42
42
 
43
43
  function packagedPluginsDir() {
44
+ // console.log('CALL DIR FROM', new Error('xxx').stack);
45
+ // console.log('__dirname', __dirname);
46
+ // console.log('platformInfo.isElectronBundle', platformInfo.isElectronBundle);
47
+ // console.log('platformInfo.isForkedApi', platformInfo.isForkedApi);
44
48
  if (platformInfo.isDevMode) {
45
49
  return path.resolve(__dirname, '../../../../plugins');
46
50
  }
@@ -53,6 +57,12 @@ function packagedPluginsDir() {
53
57
  }
54
58
  if (platformInfo.isElectronBundle) {
55
59
  return path.resolve(__dirname, '../../plugins');
60
+
61
+ // if (platformInfo.isForkedApi) {
62
+ // return path.resolve(__dirname, '../plugins');
63
+ // } else {
64
+ // return path.resolve(__dirname, '../../plugins');
65
+ // }
56
66
  }
57
67
  return null;
58
68
  }
@@ -7,6 +7,9 @@ const getChartExport = (title, config, imageFile) => {
7
7
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.0/chart.min.js" integrity="sha512-GMGzUEevhWh8Tc/njS0bDpwgxdCJLQBWG3Z2Ct+JGOpVnEmjvNx6ts4v6A2XJf1HOrtOsfhv3hBKpK9kE5z8AQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
8
8
  <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
9
9
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-adapter-moment/1.0.0/chartjs-adapter-moment.min.js" integrity="sha512-oh5t+CdSBsaVVAvxcZKy3XJdP7ZbYUBSRCXDTVn0ODewMDDNnELsrG9eDm8rVZAQg7RsDD/8K3MjPAFB13o6eA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js" integrity="sha512-UXumZrZNiOwnTcZSHLOfcTs0aos2MzBWHXOHOuB0J/R44QB0dwY5JgfbvljXcklVf65Gc4El6RjZ+lnwd2az2g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-zoom/1.2.0/chartjs-plugin-zoom.min.js" integrity="sha512-TT0wAMqqtjXVzpc48sI0G84rBP+oTkBZPgeRYIOVRGUdwJsyS3WPipsNh///ay2LJ+onCM23tipnz6EvEy2/UA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
12
+
10
13
  <style>
11
14
  a { text-decoration: none }
12
15