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

@iobroker/db-states-jsonl

Package Overview
Dependencies
Maintainers
0
Versions
410
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 6.0.12-alpha.0-20240922-1ea0ace13 to 6.0.12-alpha.0-20240924-4e8189ae0

8

build/cjs/lib/states/statesInMemJsonlDB.d.ts
/**
* This class inherits InMemoryFileDB class and adds all relevant logic for states
* including the available methods for use by js-controller directly
**/
*/
export class StatesInMemoryJsonlDB extends StatesInMemoryFileDB {
constructor(settings: any);
/** @type {JsonlDB<any>} */
_db: JsonlDB<any>;
_db: JsonlDB<unknown>;
_backupInterval: NodeJS.Timeout | undefined;
/**
* Checks if an existing file DB should be migrated to JSONL
* @returns {Promise<boolean>} true if the file DB was migrated. false if not.
*
* @returns true if the file DB was migrated. false if not.
* If this returns true, the jsonl DB was opened and doesn't need to be opened again.

@@ -14,0 +14,0 @@ */

@@ -130,3 +130,3 @@ "use strict";

const jsonFileName = import_node_path.default.join(this.dataDir, this.settings.fileDB.fileName);
const bakFileName = import_node_path.default.join(this.dataDir, this.settings.fileDB.fileName + ".bak");
const bakFileName = import_node_path.default.join(this.dataDir, `${this.settings.fileDB.fileName}.bak`);
let jsonlTimeStamp = 0;

@@ -133,0 +133,0 @@ let jsonTimeStamp = 0;

@@ -40,9 +40,9 @@ "use strict";

this.serverConnections = {};
this.namespaceStates = (this.settings.redisNamespace || "io") + ".";
this.namespaceMsg = (this.settings.namespaceMsg || "messagebox") + ".";
this.namespaceLog = (this.settings.namespaceLog || "log") + ".";
this.namespaceSession = (this.settings.namespaceSession || "session") + ".";
this.namespaceStates = `${this.settings.redisNamespace || "io"}.`;
this.namespaceMsg = `${this.settings.namespaceMsg || "messagebox"}.`;
this.namespaceLog = `${this.settings.namespaceLog || "log"}.`;
this.namespaceSession = `${this.settings.namespaceSession || "session"}.`;
this.namespaceMsgLen = this.namespaceMsg.length;
this.namespaceLogLen = this.namespaceLog.length;
this.metaNamespace = (this.settings.metaNamespace || "meta") + ".";
this.metaNamespace = `${this.settings.metaNamespace || "meta"}.`;
this.metaNamespaceLen = this.metaNamespace.length;

@@ -362,3 +362,3 @@ this.open().then(() => {

log: this.log,
logScope: this.namespace + " States",
logScope: `${this.namespace} States`,
handleAsBuffers: true,

@@ -369,6 +369,6 @@ enhancedLogging: this.settings.connection.enhancedLogging

this._socketEvents(handler);
this.serverConnections[socket.remoteAddress + ":" + socket.remotePort] = handler;
this.serverConnections[`${socket.remoteAddress}:${socket.remotePort}`] = handler;
socket.on("close", () => {
if (this.serverConnections[socket.remoteAddress + ":" + socket.remotePort]) {
delete this.serverConnections[socket.remoteAddress + ":" + socket.remotePort];
if (this.serverConnections[`${socket.remoteAddress}:${socket.remotePort}`]) {
delete this.serverConnections[`${socket.remoteAddress}:${socket.remotePort}`];
}

@@ -375,0 +375,0 @@ });

/**
* This class inherits InMemoryFileDB class and adds all relevant logic for states
* including the available methods for use by js-controller directly
**/
*/
export class StatesInMemoryJsonlDB extends StatesInMemoryFileDB {
constructor(settings: any);
/** @type {JsonlDB<any>} */
_db: JsonlDB<any>;
_db: JsonlDB<unknown>;
_backupInterval: NodeJS.Timeout | undefined;
/**
* Checks if an existing file DB should be migrated to JSONL
* @returns {Promise<boolean>} true if the file DB was migrated. false if not.
*
* @returns true if the file DB was migrated. false if not.
* If this returns true, the jsonl DB was opened and doesn't need to be opened again.

@@ -14,0 +14,0 @@ */

@@ -37,7 +37,7 @@ /**

* Normalizes options for the JsonlDB
* @param {Record<string, any> | undefined} conf The jsonlOptions options from iobroker.json
* @returns {import("@alcalzone/jsonl-db").JsonlDBOptions<any>}
*
* @param conf The jsonlOptions options from iobroker.json
* @returns
*/
function normalizeJsonlOptions(conf = {}) {
/** @type {import("@alcalzone/jsonl-db").JsonlDBOptions<any>} */
const ret = {

@@ -50,3 +50,3 @@ autoCompress: {

// but big binary states are updated regularly
intervalMs: 1000 * 60 * 60 * 23
intervalMs: 1000 * 60 * 60 * 23,
},

@@ -56,3 +56,3 @@ ignoreReadErrors: true,

intervalMs: 60000,
maxBufferedCommands: 2000
maxBufferedCommands: 2000,
},

@@ -65,4 +65,4 @@ lockfile: {

// This makes sure the DB stays locked for maximum 2s even if the process crashes
staleMs: 2000
}
staleMs: 2000,
},
};

@@ -101,3 +101,3 @@ // Be really careful what we allow here. Incorrect settings may cause problems in production.

* including the available methods for use by js-controller directly
**/
*/
export class StatesInMemoryJsonlDB extends StatesInMemoryFileDB {

@@ -109,10 +109,9 @@ constructor(settings) {

fileName: 'states.json',
backupDirName: 'backup-objects'
backupDirName: 'backup-objects',
};
const jsonlOptions = normalizeJsonlOptions(settings.connection.jsonlOptions);
settings.jsonlDB = {
fileName: 'states.jsonl'
fileName: 'states.jsonl',
};
super(settings);
/** @type {JsonlDB<any>} */
this._db = new JsonlDB(path.join(this.dataDir, settings.jsonlDB.fileName), jsonlOptions);

@@ -126,11 +125,21 @@ }

this.dataset = new Proxy(this._db, {
/** @param {any} prop */
/**
* @param target
* @param prop
*/
get(target, prop) {
return target.get(prop);
},
/** @param {any} prop */
/**
* @param target
* @param prop
*/
has(target, prop) {
return target.has(prop);
},
/** @param {any} prop */
/**
* @param target
* @param prop
* @param value
*/
set(target, prop, value) {

@@ -140,3 +149,6 @@ target.set(prop, value);

},
/** @param {any} prop */
/**
* @param target
* @param prop
*/
deleteProperty(target, prop) {

@@ -148,3 +160,6 @@ return target.delete(prop);

},
/** @param {any} prop */
/**
* @param target
* @param prop
*/
getOwnPropertyDescriptor(target, prop) {

@@ -158,5 +173,5 @@ if (!target.has(prop)) {

writable: true,
value: target.get(prop)
value: target.get(prop),
};
}
},
});

@@ -171,3 +186,4 @@ if (this.settings.backup && this.settings.backup.period && !this.settings.backup.disabled) {

* Checks if an existing file DB should be migrated to JSONL
* @returns {Promise<boolean>} true if the file DB was migrated. false if not.
*
* @returns true if the file DB was migrated. false if not.
* If this returns true, the jsonl DB was opened and doesn't need to be opened again.

@@ -178,3 +194,3 @@ */

const jsonFileName = path.join(this.dataDir, this.settings.fileDB.fileName);
const bakFileName = path.join(this.dataDir, this.settings.fileDB.fileName + '.bak');
const bakFileName = path.join(this.dataDir, `${this.settings.fileDB.fileName}.bak`);
// Check the timestamps of each file, defaulting to 0 if they don't exist

@@ -212,3 +228,2 @@ let jsonlTimeStamp = 0;

// Figure out which file needs to be imported
/** @type {string} */
let importFilename;

@@ -215,0 +230,0 @@ if (jsonTimeStamp > 0 && jsonTimeStamp >= bakTimeStamp && jsonTimeStamp >= jsonlTimeStamp) {

@@ -22,3 +22,3 @@ /**

this.connectDb(); // now that server is connected also connect client
}
},
};

@@ -25,0 +25,0 @@ this.statesServer = new StatesInMemoryServer(serverSettings);

@@ -48,6 +48,6 @@ /**

this.serverConnections = {};
this.namespaceStates = (this.settings.redisNamespace || 'io') + '.';
this.namespaceMsg = (this.settings.namespaceMsg || 'messagebox') + '.';
this.namespaceLog = (this.settings.namespaceLog || 'log') + '.';
this.namespaceSession = (this.settings.namespaceSession || 'session') + '.';
this.namespaceStates = `${this.settings.redisNamespace || 'io'}.`;
this.namespaceMsg = `${this.settings.namespaceMsg || 'messagebox'}.`;
this.namespaceLog = `${this.settings.namespaceLog || 'log'}.`;
this.namespaceSession = `${this.settings.namespaceSession || 'session'}.`;
//this.namespaceStatesLen = this.namespaceStates.length;

@@ -57,3 +57,3 @@ this.namespaceMsgLen = this.namespaceMsg.length;

//this.namespaceSessionlen = this.namespaceSession.length;
this.metaNamespace = (this.settings.metaNamespace || 'meta') + '.';
this.metaNamespace = `${this.settings.metaNamespace || 'meta'}.`;
this.metaNamespaceLen = this.metaNamespace.length;

@@ -469,12 +469,12 @@ this.open()

log: this.log,
logScope: this.namespace + ' States',
logScope: `${this.namespace} States`,
handleAsBuffers: true,
enhancedLogging: this.settings.connection.enhancedLogging
enhancedLogging: this.settings.connection.enhancedLogging,
};
const handler = new RedisHandler(socket, options);
this._socketEvents(handler);
this.serverConnections[socket.remoteAddress + ':' + socket.remotePort] = handler;
this.serverConnections[`${socket.remoteAddress}:${socket.remotePort}`] = handler;
socket.on('close', () => {
if (this.serverConnections[socket.remoteAddress + ':' + socket.remotePort]) {
delete this.serverConnections[socket.remoteAddress + ':' + socket.remotePort];
if (this.serverConnections[`${socket.remoteAddress}:${socket.remotePort}`]) {
delete this.serverConnections[`${socket.remoteAddress}:${socket.remotePort}`];
}

@@ -481,0 +481,0 @@ });

{
"name": "@iobroker/db-states-jsonl",
"type": "module",
"version": "6.0.12-alpha.0-20240922-1ea0ace13",
"version": "6.0.12-alpha.0-20240924-4e8189ae0",
"engines": {

@@ -10,5 +10,5 @@ "node": ">=12.0.0"

"@alcalzone/jsonl-db": "~3.1.1",
"@iobroker/db-base": "6.0.12-alpha.0-20240922-1ea0ace13",
"@iobroker/db-states-file": "6.0.12-alpha.0-20240922-1ea0ace13",
"@iobroker/db-states-redis": "6.0.12-alpha.0-20240922-1ea0ace13"
"@iobroker/db-base": "6.0.12-alpha.0-20240924-4e8189ae0",
"@iobroker/db-states-file": "6.0.12-alpha.0-20240924-4e8189ae0",
"@iobroker/db-states-redis": "6.0.12-alpha.0-20240924-4e8189ae0"
},

@@ -51,3 +51,3 @@ "keywords": [

],
"gitHead": "f864a31b47322c8d4994b2a4336beaf44d364a55"
"gitHead": "3540964b91b0991a6e81f1d6f9d6e90b9e46dbff"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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