dbgate-api 5.5.7-alpha.60 → 6.0.0-alpha.1

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.5.7-alpha.60",
4
+ "version": "6.0.0-alpha.1",
5
5
  "homepage": "https://dbgate.org/",
6
6
  "repository": {
7
7
  "type": "git",
@@ -29,10 +29,10 @@
29
29
  "compare-versions": "^3.6.0",
30
30
  "cors": "^2.8.5",
31
31
  "cross-env": "^6.0.3",
32
- "dbgate-datalib": "^5.5.7-alpha.60",
32
+ "dbgate-datalib": "^6.0.0-alpha.1",
33
33
  "dbgate-query-splitter": "^4.11.2",
34
- "dbgate-sqltree": "^5.5.7-alpha.60",
35
- "dbgate-tools": "^5.5.7-alpha.60",
34
+ "dbgate-sqltree": "^6.0.0-alpha.1",
35
+ "dbgate-tools": "^6.0.0-alpha.1",
36
36
  "debug": "^4.3.4",
37
37
  "diff": "^5.0.0",
38
38
  "diff2html": "^3.4.13",
@@ -81,7 +81,7 @@
81
81
  "devDependencies": {
82
82
  "@types/fs-extra": "^9.0.11",
83
83
  "@types/lodash": "^4.14.149",
84
- "dbgate-types": "^5.5.7-alpha.60",
84
+ "dbgate-types": "^6.0.0-alpha.1",
85
85
  "env-cmd": "^10.1.0",
86
86
  "jsdoc-to-markdown": "^9.0.5",
87
87
  "node-loader": "^1.0.2",
@@ -62,6 +62,8 @@ module.exports = {
62
62
  const logoutUrl = storageConnectionError ? null : await authProvider.getLogoutUrl();
63
63
  const adminConfig = storageConnectionError ? null : await storage.readConfig({ group: 'admin' });
64
64
 
65
+ storage.startRefreshLicense();
66
+
65
67
  const isAdminPasswordMissing = !!(
66
68
  process.env.STORAGE_DATABASE &&
67
69
  !process.env.ADMIN_PASSWORD &&
@@ -81,7 +83,7 @@ module.exports = {
81
83
  isElectron: platformInfo.isElectron,
82
84
  isLicenseValid,
83
85
  isLicenseExpired: checkedLicense?.isExpired,
84
- trialDaysLeft: checkedLicense?.isGeneratedTrial && !checkedLicense?.isExpired ? checkedLicense?.daysLeft : null,
86
+ trialDaysLeft: checkedLicense?.licenseTypeObj?.isTrial && !checkedLicense?.isExpired ? checkedLicense?.daysLeft : null,
85
87
  checkedLicense,
86
88
  configurationError,
87
89
  logoutUrl,
@@ -201,6 +201,7 @@ module.exports = {
201
201
  // @ts-ignore
202
202
  this.datastore = new JsonLinesDatabase(path.join(dir, 'connections.jsonl'));
203
203
  }
204
+ await this.checkUnsavedConnectionsLimit();
204
205
  },
205
206
 
206
207
  list_meta: true,
@@ -300,6 +301,32 @@ module.exports = {
300
301
  return res;
301
302
  },
302
303
 
304
+ async checkUnsavedConnectionsLimit() {
305
+ if (!this.datastore) {
306
+ return;
307
+ }
308
+ const MAX_UNSAVED_CONNECTIONS = 5;
309
+ await this.datastore.transformAll(connections => {
310
+ const count = connections.filter(x => x.unsaved).length;
311
+ if (count > MAX_UNSAVED_CONNECTIONS) {
312
+ const res = [];
313
+ let unsavedToSkip = count - MAX_UNSAVED_CONNECTIONS;
314
+ for (const item of connections) {
315
+ if (item.unsaved) {
316
+ if (unsavedToSkip > 0) {
317
+ unsavedToSkip--;
318
+ } else {
319
+ res.push(item);
320
+ }
321
+ } else {
322
+ res.push(item);
323
+ }
324
+ }
325
+ return res;
326
+ }
327
+ });
328
+ },
329
+
303
330
  update_meta: true,
304
331
  async update({ _id, values }, req) {
305
332
  if (portalConnections) return;
@@ -111,7 +111,7 @@ module.exports = {
111
111
  const scriptFile = path.join(uploadsdir(), runid + '.js');
112
112
  fs.writeFileSync(`${scriptFile}`, scriptText);
113
113
  fs.mkdirSync(directory);
114
- const pluginNames = _.union(fs.readdirSync(pluginsdir()), packagedPluginList);
114
+ const pluginNames = extractPlugins(scriptText);
115
115
  logger.info({ scriptFile }, 'Running script');
116
116
  // const subprocess = fork(scriptFile, ['--checkParent', '--max-old-space-size=8192'], {
117
117
  const subprocess = fork(
@@ -52,7 +52,7 @@ module.exports = {
52
52
  if (existing) return existing;
53
53
  const connection = await connections.getCore({ conid });
54
54
  if (!connection) {
55
- throw new Error(`Connection with conid="${conid}" not fund`);
55
+ throw new Error(`Connection with conid="${conid}" not found`);
56
56
  }
57
57
  if (connection.passwordMode == 'askPassword' || connection.passwordMode == 'askUser') {
58
58
  throw new MissingCredentialsError({ conid, passwordMode: connection.passwordMode });
@@ -26,4 +26,6 @@ module.exports = {
26
26
  async readConfig({ group }) {
27
27
  return {};
28
28
  },
29
+
30
+ startRefreshLicense() {},
29
31
  };
@@ -1,5 +1,5 @@
1
1
 
2
2
  module.exports = {
3
- version: '5.5.7-alpha.60',
4
- buildTime: '2024-11-20T09:21:16.923Z'
3
+ version: '6.0.0-alpha.1',
4
+ buildTime: '2024-12-03T16:43:59.826Z'
5
5
  };
@@ -111,6 +111,15 @@ class JsonLinesDatabase {
111
111
  return removed;
112
112
  }
113
113
 
114
+ async transformAll(transformFunction) {
115
+ await this._ensureLoaded();
116
+ const newData = transformFunction(this.data);
117
+ if (newData) {
118
+ this.data = newData;
119
+ await this._save();
120
+ }
121
+ }
122
+
114
123
  // async _openReader() {
115
124
  // return new Promise((resolve, reject) =>
116
125
  // lineReader.open(this.filename, (err, reader) => {