dbgate-api 5.1.4 → 5.1.6

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.1.4",
4
+ "version": "5.1.6",
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.2",
29
- "dbgate-sqltree": "^5.1.4",
30
- "dbgate-tools": "^5.1.4",
29
+ "dbgate-sqltree": "^5.1.6",
30
+ "dbgate-tools": "^5.1.6",
31
31
  "debug": "^4.3.4",
32
32
  "diff": "^5.0.0",
33
33
  "diff2html": "^3.4.13",
@@ -65,7 +65,7 @@
65
65
  "devDependencies": {
66
66
  "@types/fs-extra": "^9.0.11",
67
67
  "@types/lodash": "^4.14.149",
68
- "dbgate-types": "^5.1.4",
68
+ "dbgate-types": "^5.1.6",
69
69
  "env-cmd": "^10.1.0",
70
70
  "node-loader": "^1.0.2",
71
71
  "nodemon": "^2.0.2",
@@ -53,6 +53,8 @@ function getPortalCollections() {
53
53
  databaseUrl: process.env[`URL_${id}`],
54
54
  useDatabaseUrl: !!process.env[`URL_${id}`],
55
55
  databaseFile: process.env[`FILE_${id}`],
56
+ socketPath: process.env[`SOCKET_PATH_${id}`],
57
+ authType: process.env[`AUTH_TYPE_${id}`] || (process.env[`SOCKET_PATH_${id}`] ? 'socket' : undefined),
56
58
  defaultDatabase:
57
59
  process.env[`DATABASE_${id}`] ||
58
60
  (process.env[`FILE_${id}`] ? getDatabaseFileLabel(process.env[`FILE_${id}`]) : null),
@@ -60,6 +62,7 @@ function getPortalCollections() {
60
62
  displayName: process.env[`LABEL_${id}`],
61
63
  isReadOnly: process.env[`READONLY_${id}`],
62
64
  databases: process.env[`DBCONFIG_${id}`] ? safeJsonParse(process.env[`DBCONFIG_${id}`]) : null,
65
+ parent: process.env[`PARENT_${id}`] || undefined,
63
66
 
64
67
  // SSH tunnel
65
68
  useSshTunnel: process.env[`USE_SSH_${id}`],
@@ -103,6 +103,12 @@ module.exports = {
103
103
  if (handleProcessCommunication(message, subprocess)) return;
104
104
  this[`handle_${msgtype}`](sesid, message);
105
105
  });
106
+ subprocess.on('exit', () => {
107
+ this.opened = this.opened.filter(x => x.sesid != sesid);
108
+ this.dispatchMessage(sesid, 'Query session closed');
109
+ socket.emit(`session-closed-${sesid}`);
110
+ });
111
+
106
112
  subprocess.send({ msgtype: 'connect', ...connection, database });
107
113
  return _.pick(newOpened, ['conid', 'database', 'sesid']);
108
114
  },
@@ -165,6 +171,17 @@ module.exports = {
165
171
  return { state: 'ok' };
166
172
  },
167
173
 
174
+ ping_meta: true,
175
+ async ping({ sesid }) {
176
+ const session = this.opened.find(x => x.sesid == sesid);
177
+ if (!session) {
178
+ throw new Error('Invalid session');
179
+ }
180
+ session.subprocess.send({ msgtype: 'ping' });
181
+
182
+ return { state: 'ok' };
183
+ },
184
+
168
185
  // runCommand_meta: true,
169
186
  // async runCommand({ conid, database, sql }) {
170
187
  // console.log(`Running SQL command , conid=${conid}, database=${database}, sql=${sql}`);
@@ -1,5 +1,5 @@
1
1
 
2
2
  module.exports = {
3
- version: '5.1.4',
4
- buildTime: '2022-10-02T18:55:05.151Z'
3
+ version: '5.1.6',
4
+ buildTime: '2022-11-14T18:39:13.832Z'
5
5
  };
@@ -177,7 +177,7 @@ async function handleQueryData({ msgid, sql }, skipReadonlyCheck = false) {
177
177
  const res = await driver.query(systemConnection, sql);
178
178
  process.send({ msgtype: 'response', msgid, ...res });
179
179
  } catch (err) {
180
- process.send({ msgtype: 'response', msgid, errorMessage: err.message });
180
+ process.send({ msgtype: 'response', msgid, errorMessage: err.message || 'Error executing SQL script' });
181
181
  }
182
182
  }
183
183
 
@@ -335,11 +335,11 @@ function start() {
335
335
 
336
336
  setInterval(() => {
337
337
  const time = new Date().getTime();
338
- if (time - lastPing > 120 * 1000) {
338
+ if (time - lastPing > 40 * 1000) {
339
339
  console.log('Database connection not alive, exiting');
340
340
  process.exit(0);
341
341
  }
342
- }, 60 * 1000);
342
+ }, 10 * 1000);
343
343
 
344
344
  process.on('message', async message => {
345
345
  if (handleProcessCommunication(message)) return;
@@ -111,11 +111,11 @@ function start() {
111
111
 
112
112
  setInterval(() => {
113
113
  const time = new Date().getTime();
114
- if (time - lastPing > 120 * 1000) {
114
+ if (time - lastPing > 40 * 1000) {
115
115
  console.log('Server connection not alive, exiting');
116
116
  process.exit(0);
117
117
  }
118
- }, 60 * 1000);
118
+ }, 10 * 1000);
119
119
 
120
120
  process.on('message', async message => {
121
121
  if (handleProcessCommunication(message)) return;
@@ -15,6 +15,7 @@ let systemConnection;
15
15
  let storedConnection;
16
16
  let afterConnectCallbacks = [];
17
17
  // let currentHandlers = [];
18
+ let lastPing = null;
18
19
 
19
20
  class TableWriter {
20
21
  constructor() {
@@ -271,10 +272,15 @@ async function handleExecuteReader({ jslid, sql, fileName }) {
271
272
  });
272
273
  }
273
274
 
275
+ function handlePing() {
276
+ lastPing = new Date().getTime();
277
+ }
278
+
274
279
  const messageHandlers = {
275
280
  connect: handleConnect,
276
281
  executeQuery: handleExecuteQuery,
277
282
  executeReader: handleExecuteReader,
283
+ ping: handlePing,
278
284
  // cancel: handleCancel,
279
285
  };
280
286
 
@@ -285,6 +291,17 @@ async function handleMessage({ msgtype, ...other }) {
285
291
 
286
292
  function start() {
287
293
  childProcessChecker();
294
+
295
+ lastPing = new Date().getTime();
296
+
297
+ setInterval(() => {
298
+ const time = new Date().getTime();
299
+ if (time - lastPing > 25 * 1000) {
300
+ console.log('Session not alive, exiting');
301
+ process.exit(0);
302
+ }
303
+ }, 10 * 1000);
304
+
288
305
  process.on('message', async message => {
289
306
  if (handleProcessCommunication(message)) return;
290
307
  try {