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

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
Simon Smith 2024-11-26 18:01:12 +00:00 committed by GitHub
parent 462c383b77
commit 975e49a190
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 13 deletions

26
db.js
View File

@ -611,7 +611,7 @@ module.exports.CreateDB = function (parent, func) {
obj.GetAllType('mesh', function (err, docs) { obj.GetAllType('mesh', function (err, docs) {
if (err == null) { for (var i in docs) { count++; obj.Set(docs[i]); } } if (err == null) { for (var i in docs) { count++; obj.Set(docs[i]); } }
if (obj.databaseType == DB_NEDB) { // If we are using NeDB, compact the database. if (obj.databaseType == DB_NEDB) { // If we are using NeDB, compact the database.
obj.file.persistence.compactDatafile(); obj.file.compactDatafile();
obj.file.on('compaction.done', function () { func(count); }); // It's important to wait for compaction to finish before exit, otherwise NeDB may corrupt. obj.file.on('compaction.done', function () { func(count); }); // It's important to wait for compaction to finish before exit, otherwise NeDB may corrupt.
} else { } else {
func(count); // For all other databases, normal exit. func(count); // For all other databases, normal exit.
@ -1239,8 +1239,11 @@ module.exports.CreateDB = function (parent, func) {
} else { } else {
// Use NeDB (The default) // Use NeDB (The default)
obj.databaseType = DB_NEDB; obj.databaseType = DB_NEDB;
try { Datastore = require('@yetzt/nedb'); } catch (ex) { } // This is the NeDB with fixed security dependencies. try { Datastore = require('@seald-io/nedb'); } catch (ex) { } // This is the NeDB with Node 23 support.
if (Datastore == null) { Datastore = require('nedb'); } // So not to break any existing installations, if the old NeDB is present, use it. if (Datastore == null) {
try { Datastore = require('@yetzt/nedb'); } catch (ex) { } // This is the NeDB with fixed security dependencies.
if (Datastore == null) { Datastore = require('nedb'); } // So not to break any existing installations, if the old NeDB is present, use it.
}
var datastoreOptions = { filename: parent.getConfigFilePath('meshcentral.db'), autoload: true }; var datastoreOptions = { filename: parent.getConfigFilePath('meshcentral.db'), autoload: true };
// If a DB encryption key is provided, perform database encryption // If a DB encryption key is provided, perform database encryption
@ -1267,7 +1270,7 @@ module.exports.CreateDB = function (parent, func) {
// Start NeDB main collection and setup indexes // Start NeDB main collection and setup indexes
obj.file = new Datastore(datastoreOptions); obj.file = new Datastore(datastoreOptions);
obj.file.persistence.setAutocompactionInterval(86400000); // Compact once a day obj.file.setAutocompactionInterval(86400000); // Compact once a day
obj.file.ensureIndex({ fieldName: 'type' }); obj.file.ensureIndex({ fieldName: 'type' });
obj.file.ensureIndex({ fieldName: 'domain' }); obj.file.ensureIndex({ fieldName: 'domain' });
obj.file.ensureIndex({ fieldName: 'meshid', sparse: true }); obj.file.ensureIndex({ fieldName: 'meshid', sparse: true });
@ -1276,7 +1279,7 @@ module.exports.CreateDB = function (parent, func) {
// Setup the events collection and setup indexes // Setup the events collection and setup indexes
obj.eventsfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-events.db'), autoload: true, corruptAlertThreshold: 1 }); obj.eventsfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-events.db'), autoload: true, corruptAlertThreshold: 1 });
obj.eventsfile.persistence.setAutocompactionInterval(86400000); // Compact once a day obj.eventsfile.setAutocompactionInterval(86400000); // Compact once a day
obj.eventsfile.ensureIndex({ fieldName: 'ids' }); // TODO: Not sure if this is a good index, this is a array field. obj.eventsfile.ensureIndex({ fieldName: 'ids' }); // TODO: Not sure if this is a good index, this is a array field.
obj.eventsfile.ensureIndex({ fieldName: 'nodeid', sparse: true }); obj.eventsfile.ensureIndex({ fieldName: 'nodeid', sparse: true });
obj.eventsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expireEventsSeconds }); obj.eventsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expireEventsSeconds });
@ -1284,7 +1287,7 @@ module.exports.CreateDB = function (parent, func) {
// Setup the power collection and setup indexes // Setup the power collection and setup indexes
obj.powerfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-power.db'), autoload: true, corruptAlertThreshold: 1 }); obj.powerfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-power.db'), autoload: true, corruptAlertThreshold: 1 });
obj.powerfile.persistence.setAutocompactionInterval(86400000); // Compact once a day obj.powerfile.setAutocompactionInterval(86400000); // Compact once a day
obj.powerfile.ensureIndex({ fieldName: 'nodeid' }); obj.powerfile.ensureIndex({ fieldName: 'nodeid' });
obj.powerfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expirePowerEventsSeconds }); obj.powerfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expirePowerEventsSeconds });
obj.powerfile.remove({ time: { '$lt': new Date(Date.now() - (expirePowerEventsSeconds * 1000)) } }, { multi: true }); // Force delete older events 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) {
// Setup the server stats collection and setup indexes // Setup the server stats collection and setup indexes
obj.serverstatsfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-stats.db'), autoload: true, corruptAlertThreshold: 1 }); obj.serverstatsfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-stats.db'), autoload: true, corruptAlertThreshold: 1 });
obj.serverstatsfile.persistence.setAutocompactionInterval(86400000); // Compact once a day obj.serverstatsfile.setAutocompactionInterval(86400000); // Compact once a day
obj.serverstatsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expireServerStatsSeconds }); obj.serverstatsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expireServerStatsSeconds });
obj.serverstatsfile.ensureIndex({ fieldName: 'expire', expireAfterSeconds: 0 }); // Auto-expire events obj.serverstatsfile.ensureIndex({ fieldName: 'expire', expireAfterSeconds: 0 }); // Auto-expire events
obj.serverstatsfile.remove({ time: { '$lt': new Date(Date.now() - (expireServerStatsSeconds * 1000)) } }, { multi: true }); // Force delete older events 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) {
// Setup plugin info collection // Setup plugin info collection
if (obj.pluginsActive) { if (obj.pluginsActive) {
obj.pluginsfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-plugins.db'), autoload: true }); obj.pluginsfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-plugins.db'), autoload: true });
obj.pluginsfile.persistence.setAutocompactionInterval(86400000); // Compact once a day obj.pluginsfile.setAutocompactionInterval(86400000); // Compact once a day
} }
setupFunctions(func); // Completed setup of NeDB setupFunctions(func); // Completed setup of NeDB
@ -3970,8 +3973,11 @@ module.exports.CreateDB = function (parent, func) {
// Transfer NeDB data into the current database // Transfer NeDB data into the current database
obj.nedbtodb = function (func) { obj.nedbtodb = function (func) {
var nedbDatastore = null; var nedbDatastore = null;
try { nedbDatastore = require('@yetzt/nedb'); } catch (ex) { } // This is the NeDB with fixed security dependencies. try { nedbDatastore = require('@seald-io/nedb'); } catch (ex) { } // This is the NeDB with Node 23 support.
if (nedbDatastore == null) { nedbDatastore = require('nedb'); } // So not to break any existing installations, if the old NeDB is present, use it. if (nedbDatastore == null) {
try { nedbDatastore = require('@yetzt/nedb'); } catch (ex) { } // This is the NeDB with fixed security dependencies.
if (nedbDatastore == null) { nedbDatastore = require('nedb'); } // So not to break any existing installations, if the old NeDB is present, use it.
}
var datastoreOptions = { filename: parent.getConfigFilePath('meshcentral.db'), autoload: true }; var datastoreOptions = { filename: parent.getConfigFilePath('meshcentral.db'), autoload: true };

View File

@ -1,4 +1,4 @@
"@yetzt/nedb": "1.8.0", "@seald-io/nedb": "4.0.4",
"archiver": "7.0.1", "archiver": "7.0.1",
"body-parser": "1.20.3", "body-parser": "1.20.3",
"cbor": "5.2.0", "cbor": "5.2.0",

View File

@ -4212,7 +4212,7 @@ function mainStart() {
// Build the list of required modules // Build the list of required modules
// NOTE: ALL MODULES MUST HAVE A VERSION NUMBER AND THE VERSION MUST MATCH THAT USED IN Dockerfile // NOTE: ALL MODULES MUST HAVE A VERSION NUMBER AND THE VERSION MUST MATCH THAT USED IN Dockerfile
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']; 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'];
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 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
if (ldap == true) { modules.push('ldapauth-fork@5.0.5'); } if (ldap == true) { modules.push('ldapauth-fork@5.0.5'); }
if (ssh == true) { modules.push('ssh2@1.16.0'); } if (ssh == true) { modules.push('ssh2@1.16.0'); }

View File

@ -37,7 +37,7 @@
"sample-config-advanced.json" "sample-config-advanced.json"
], ],
"dependencies": { "dependencies": {
"@yetzt/nedb": "1.8.0", "@seald-io/nedb": "4.0.4",
"archiver": "7.0.1", "archiver": "7.0.1",
"body-parser": "1.20.3", "body-parser": "1.20.3",
"cbor": "5.2.0", "cbor": "5.2.0",