use @seald-io/nedb for node23 support (#6561)

Signed-off-by: si458 <simonsmith5521@gmail.com>

Simon Smith committed Nov 26, 2024 at 18:01 UTC 975e49a1905a9c9559ea09bbd7907867f457144a
4 files changed +19 -13
db.js
+16 -10
@@ -611,7 +611,7 @@ module.exports.CreateDB = function (parent, func) {
611 obj.GetAllType('mesh', function (err, docs) {
612 if (err == null) { for (var i in docs) { count++; obj.Set(docs[i]); } }
613 if (obj.databaseType == DB_NEDB) { // If we are using NeDB, compact the database.
614 - obj.file.persistence.compactDatafile();
614 + obj.file.compactDatafile();
615 obj.file.on('compaction.done', function () { func(count); }); // It's important to wait for compaction to finish before exit, otherwise NeDB may corrupt.
616 } else {
617 func(count); // For all other databases, normal exit.
@@ -1239,8 +1239,11 @@ module.exports.CreateDB = function (parent, func) {
1239 } else {
1240 // Use NeDB (The default)
1241 obj.databaseType = DB_NEDB;
1242 - try { Datastore = require('@yetzt/nedb'); } catch (ex) { } // This is the NeDB with fixed security dependencies.
1243 - if (Datastore == null) { Datastore = require('nedb'); } // So not to break any existing installations, if the old NeDB is present, use it.
1242 + try { Datastore = require('@seald-io/nedb'); } catch (ex) { } // This is the NeDB with Node 23 support.
1243 + if (Datastore == null) {
1244 + try { Datastore = require('@yetzt/nedb'); } catch (ex) { } // This is the NeDB with fixed security dependencies.
1245 + if (Datastore == null) { Datastore = require('nedb'); } // So not to break any existing installations, if the old NeDB is present, use it.
1246 + }
1247 var datastoreOptions = { filename: parent.getConfigFilePath('meshcentral.db'), autoload: true };
1248
1249 // If a DB encryption key is provided, perform database encryption
@@ -1267,7 +1270,7 @@ module.exports.CreateDB = function (parent, func) {
1270
1271 // Start NeDB main collection and setup indexes
1272 obj.file = new Datastore(datastoreOptions);
1270 - obj.file.persistence.setAutocompactionInterval(86400000); // Compact once a day
1273 + obj.file.setAutocompactionInterval(86400000); // Compact once a day
1274 obj.file.ensureIndex({ fieldName: 'type' });
1275 obj.file.ensureIndex({ fieldName: 'domain' });
1276 obj.file.ensureIndex({ fieldName: 'meshid', sparse: true });
@@ -1276,7 +1279,7 @@ module.exports.CreateDB = function (parent, func) {
1279
1280 // Setup the events collection and setup indexes
1281 obj.eventsfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-events.db'), autoload: true, corruptAlertThreshold: 1 });
1279 - obj.eventsfile.persistence.setAutocompactionInterval(86400000); // Compact once a day
1282 + obj.eventsfile.setAutocompactionInterval(86400000); // Compact once a day
1283 obj.eventsfile.ensureIndex({ fieldName: 'ids' }); // TODO: Not sure if this is a good index, this is a array field.
1284 obj.eventsfile.ensureIndex({ fieldName: 'nodeid', sparse: true });
1285 obj.eventsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expireEventsSeconds });
@@ -1284,7 +1287,7 @@ module.exports.CreateDB = function (parent, func) {
1287
1288 // Setup the power collection and setup indexes
1289 obj.powerfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-power.db'), autoload: true, corruptAlertThreshold: 1 });
1287 - obj.powerfile.persistence.setAutocompactionInterval(86400000); // Compact once a day
1290 + obj.powerfile.setAutocompactionInterval(86400000); // Compact once a day
1291 obj.powerfile.ensureIndex({ fieldName: 'nodeid' });
1292 obj.powerfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expirePowerEventsSeconds });
1293 obj.powerfile.remove({ time: { '$lt': new Date(Date.now() - (expirePowerEventsSeconds * 1000)) } }, { multi: true }); // Force delete older events
@@ -1295,7 +1298,7 @@ module.exports.CreateDB = function (parent, func) {
1298
1299 // Setup the server stats collection and setup indexes
1300 obj.serverstatsfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-stats.db'), autoload: true, corruptAlertThreshold: 1 });
1298 - obj.serverstatsfile.persistence.setAutocompactionInterval(86400000); // Compact once a day
1301 + obj.serverstatsfile.setAutocompactionInterval(86400000); // Compact once a day
1302 obj.serverstatsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expireServerStatsSeconds });
1303 obj.serverstatsfile.ensureIndex({ fieldName: 'expire', expireAfterSeconds: 0 }); // Auto-expire events
1304 obj.serverstatsfile.remove({ time: { '$lt': new Date(Date.now() - (expireServerStatsSeconds * 1000)) } }, { multi: true }); // Force delete older events
@@ -1303,7 +1306,7 @@ module.exports.CreateDB = function (parent, func) {
1306 // Setup plugin info collection
1307 if (obj.pluginsActive) {
1308 obj.pluginsfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-plugins.db'), autoload: true });
1306 - obj.pluginsfile.persistence.setAutocompactionInterval(86400000); // Compact once a day
1309 + obj.pluginsfile.setAutocompactionInterval(86400000); // Compact once a day
1310 }
1311
1312 setupFunctions(func); // Completed setup of NeDB
@@ -3970,8 +3973,11 @@ module.exports.CreateDB = function (parent, func) {
3973 // Transfer NeDB data into the current database
3974 obj.nedbtodb = function (func) {
3975 var nedbDatastore = null;
3973 - try { nedbDatastore = require('@yetzt/nedb'); } catch (ex) { } // This is the NeDB with fixed security dependencies.
3974 - if (nedbDatastore == null) { nedbDatastore = require('nedb'); } // So not to break any existing installations, if the old NeDB is present, use it.
3976 + try { nedbDatastore = require('@seald-io/nedb'); } catch (ex) { } // This is the NeDB with Node 23 support.
3977 + if (nedbDatastore == null) {
3978 + try { nedbDatastore = require('@yetzt/nedb'); } catch (ex) { } // This is the NeDB with fixed security dependencies.
3979 + if (nedbDatastore == null) { nedbDatastore = require('nedb'); } // So not to break any existing installations, if the old NeDB is present, use it.
3980 + }
3981
3982 var datastoreOptions = { filename: parent.getConfigFilePath('meshcentral.db'), autoload: true };
3983
dependencies.txt
+1 -1
@@ -1,4 +1,4 @@
1 - "@yetzt/nedb": "1.8.0",
1 + "@seald-io/nedb": "4.0.4",
2 "archiver": "7.0.1",
3 "body-parser": "1.20.3",
4 "cbor": "5.2.0",
meshcentral.js
+1 -1
@@ -4212,7 +4212,7 @@ function mainStart() {
4212
4213 // Build the list of required modules
4214 // NOTE: ALL MODULES MUST HAVE A VERSION NUMBER AND THE VERSION MUST MATCH THAT USED IN Dockerfile
4215 - var modules = ['archiver@7.0.1', 'body-parser@1.20.3', 'cbor@5.2.0', 'compression@1.7.4', 'cookie-session@2.1.0', 'express@4.21.1', 'express-handlebars@7.1.3', 'express-ws@5.0.2', 'ipcheck@0.1.0', 'minimist@1.2.8', 'multiparty@4.2.3', '@yetzt/nedb', 'node-forge@1.3.1', 'ua-parser-js@1.0.39', 'ws@8.18.0', 'yauzl@2.10.0'];
4215 + var modules = ['archiver@7.0.1', 'body-parser@1.20.3', 'cbor@5.2.0', 'compression@1.7.4', 'cookie-session@2.1.0', 'express@4.21.1', 'express-handlebars@7.1.3', 'express-ws@5.0.2', 'ipcheck@0.1.0', 'minimist@1.2.8', 'multiparty@4.2.3', '@seald-io/nedb', 'node-forge@1.3.1', 'ua-parser-js@1.0.39', 'ws@8.18.0', 'yauzl@2.10.0'];
4216 if (require('os').platform() == 'win32') { modules.push('node-windows@0.1.14'); modules.push('loadavg-windows@1.1.1'); if (sspi == true) { modules.push('node-sspi@0.2.10'); } } // Add Windows modules
4217 if (ldap == true) { modules.push('ldapauth-fork@5.0.5'); }
4218 if (ssh == true) { modules.push('ssh2@1.16.0'); }
package.json
+1 -1
@@ -37,7 +37,7 @@
37 "sample-config-advanced.json"
38 ],
39 "dependencies": {
40 - "@yetzt/nedb": "1.8.0",
40 + "@seald-io/nedb": "4.0.4",
41 "archiver": "7.0.1",
42 "body-parser": "1.20.3",
43 "cbor": "5.2.0",