Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@iobroker/db-objects-jsonl

Package Overview
Dependencies
Maintainers
6
Versions
422
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iobroker/db-objects-jsonl - npm Package Compare versions

Comparing version 4.0.0-alpha.31-20211221-5d2e6cde to 4.0.0-alpha.32-20211225-2bedca92

56

lib/objects/objectsInMemJsonlDB.js
/**
* Object DB in memory - Server
*
* Copyright 2013-2020 bluefox <dogafox@gmail.com>
* Copyright 2013-2021 bluefox <dogafox@gmail.com>
*

@@ -19,2 +19,4 @@ * MIT License

const path = require('path');
const fs = require('fs');
const os = require('os');

@@ -32,4 +34,6 @@ /**

};
super(settings);
/** @type {import("@alcalzone/jsonl-db").JsonlDBOptions<any>} */
const jsonlOptions = {
const jsonlOptions = this.settings.connection.jsonlOptions || {
autoCompress: {

@@ -46,6 +50,4 @@ sizeFactor: 2,

settings.jsonlDB = {
fileName: 'objects.jsonl',
options: jsonlOptions
fileName: 'objects.jsonl'
};
super(settings);

@@ -94,2 +96,8 @@ /** @type {JsonlDB<any>} */

});
if (this.settings.backup && this.settings.backup.period && !this.settings.backup.disabled) {
this._backupInterval = setInterval(() => {
this.saveBackup();
}, this.settings.backup.period);
}
}

@@ -101,2 +109,37 @@

// Is regularly called and stores a compressed backup of the DB
async saveBackup() {
const now = Date.now();
const tmpBackupFileName = path.join(os.tmpdir(), this.getTimeStr(now) + '_' + this.settings.jsonlDB.fileName);
const backupFileName = path.join(
this.backupDir,
this.getTimeStr(now) + '_' + this.settings.jsonlDB.fileName + '.gz'
);
try {
if (fs.existsSync(backupFileName)) {
return;
}
// Create a DB dump
await this._db.dump(tmpBackupFileName);
// and zip it
const zlib = require('zlib');
const input = fs.createReadStream(tmpBackupFileName);
const output = fs.createWriteStream(backupFileName);
output.on('error', err => {
this.log.error(`${this.namespace} Cannot save ${this.datasetName}: ${err}`);
});
const compress = zlib.createGzip();
input.pipe(compress).pipe(output);
fs.unlinkSync(tmpBackupFileName);
// analyse older files
this.deleteOldBackupFiles(this.settings.jsonlDB.fileName);
} catch (e) {
this.log.error(`${this.namespace} Cannot save backup ${backupFileName}: ${e.message}`);
}
}
async destroy() {

@@ -106,2 +149,5 @@ if (this._db) {

}
if (this._backupInterval) {
clearInterval(this._backupInterval);
}
}

@@ -108,0 +154,0 @@ }

2

lib/objects/objectsInMemServerClass.js
/**
* States DB in memory - Server with Redis protocol
*
* Copyright 2013-2020 bluefox <dogafox@gmail.com>
* Copyright 2013-2021 bluefox <dogafox@gmail.com>
*

@@ -6,0 +6,0 @@ * MIT License

{
"name": "@iobroker/db-objects-jsonl",
"version": "4.0.0-alpha.31-20211221-5d2e6cde",
"version": "4.0.0-alpha.32-20211225-2bedca92",
"engines": {

@@ -8,6 +8,6 @@ "node": ">=12.0.0"

"dependencies": {
"@alcalzone/jsonl-db": "^2.2.0",
"@iobroker/db-base": "4.0.0-alpha.31-20211221-5d2e6cde",
"@iobroker/db-objects-file": "4.0.0-alpha.31-20211221-5d2e6cde",
"@iobroker/db-objects-redis": "4.0.0-alpha.31-20211221-5d2e6cde",
"@alcalzone/jsonl-db": "~2.3.0",
"@iobroker/db-base": "4.0.0-alpha.32-20211225-2bedca92",
"@iobroker/db-objects-file": "4.0.0-alpha.32-20211225-2bedca92",
"@iobroker/db-objects-redis": "4.0.0-alpha.32-20211225-2bedca92",
"deep-clone": "^3.0.3",

@@ -42,3 +42,3 @@ "fs-extra": "^10.0.0",

],
"gitHead": "1360216c252693f9f7ed38e1ef385a5f4a4692d4"
"gitHead": "8bb1199a14b696c069bf84f3b88147aa23e61a31"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc