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
0
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 6.0.12-alpha.0-20240922-1ea0ace13 to 6.0.12-alpha.0-20240924-4e8189ae0

8

build/cjs/lib/objects/objectsInMemJsonlDB.d.ts
/**
* This class inherits InMemoryFileDB class and adds all relevant logic for objects
* including the available methods for use by js-controller directly
**/
*/
export class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
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;

@@ -5,6 +5,7 @@ /// <reference types="node" resolution-mode="require"/>

* to access the methods via redis protocol
**/
*/
export class ObjectsInMemoryServer extends ObjectsInMemoryJsonlDB {
/**
* Constructor
*
* @param settings State and InMem-DB settings

@@ -28,10 +29,16 @@ */

* Separate Namespace from ID and return both
*
* @param idWithNamespace ID or Array of IDs containing a redis namespace and the real ID
* @returns {{namespace: (string); id: string; name?: string; isMeta?: boolean}} Object with namespace and the
* @returns Object with namespace and the
* ID/Array of IDs without the namespace
* @private
*/
private _normalizeId;
_normalizeId(idWithNamespace: any): {
id: string | any[] | null;
namespace: string;
name: string;
isMeta: boolean | undefined;
};
/**
* Publish a subscribed value to one of the redis connections in redis format
*
* @param client Instance of RedisHandler

@@ -41,11 +48,12 @@ * @param type Type of subscribed key

* @param obj Object to publish
* @returns {number} Publish counter 0 or 1 depending on if send out or not
* @returns Publish counter 0 or 1 depending on if send out or not
*/
publishToClients(client: any, type: any, id: any, obj: any): number;
publishToClients(client: any, type: any, id: any, obj: any): 0 | 1;
/**
* Generate ID for a File
*
* @param id ID of the File
* @param name Name of the file
* @param isMeta generate a META ID or a Data ID?
* @returns {string} File-ID
* @returns File-ID
*/

@@ -55,11 +63,12 @@ getFileId(id: any, name: any, isMeta: any): string;

* Register all event listeners for Handler and implement the relevant logic
*
* @param handler RedisHandler instance
* @private
*/
private _socketEvents;
_socketEvents(handler: any): void;
/**
* Return connected RedisHandlers/Connections
* @returns {{}|*}
*
* @returns
*/
getClients(): {} | any;
getClients(): {};
/**

@@ -69,21 +78,20 @@ * Get keys matching pattern and send it to given responseId, for "SCAN" and "KEYS" - Objects and files supported

* @param handler RedisHandler instance
* @param {string} pattern - pattern without namespace prefix
* @param {number} responseId - Id where response will be sent to
* @param {boolean} isScan - if used by "SCAN" this flag should be true
* @private
* @param pattern - pattern without namespace prefix
* @param responseId - Id where response will be sent to
* @param isScan - if used by "SCAN" this flag should be true
*/
private _handleScanOrKeys;
_handleScanOrKeys(handler: any, pattern: any, responseId: any, isScan?: boolean): undefined;
/**
* Initialize RedisHandler for a new network connection
*
* @param socket Network socket
* @private
*/
private _initSocket;
_initSocket(socket: any): void;
/**
* Initialize Redis Server
*
* @param settings Settings object
* @private
* @return {Promise<void>}
* @returns
*/
private _initRedisServer;
_initRedisServer(settings: any): Promise<any>;
server: net.Server | undefined;

@@ -90,0 +98,0 @@ }

@@ -44,6 +44,6 @@ "use strict";

this.serverConnections = {};
this.namespaceObjects = (this.settings.redisNamespace || settings.connection && settings.connection.redisNamespace || "cfg") + ".";
this.namespaceFile = this.namespaceObjects + "f.";
this.namespaceObj = this.namespaceObjects + "o.";
this.namespaceSet = this.namespaceObjects + "s.";
this.namespaceObjects = `${this.settings.redisNamespace || settings.connection && settings.connection.redisNamespace || "cfg"}.`;
this.namespaceFile = `${this.namespaceObjects}f.`;
this.namespaceObj = `${this.namespaceObjects}o.`;
this.namespaceSet = `${this.namespaceObjects}s.`;
this.namespaceSetLen = this.namespaceSet.length;

@@ -60,3 +60,3 @@ this.namespaceFileLen = this.namespaceFile.length;

}).then(() => {
this.log.debug(this.namespace + " " + (settings.secure ? "Secure " : "") + " Redis inMem-objects listening on port " + (settings.port || 9001));
this.log.debug(`${this.namespace} ${settings.secure ? "Secure " : ""} Redis inMem-objects listening on port ${settings.port || 9001}`);
if (typeof this.settings.connected === "function") {

@@ -163,3 +163,3 @@ setImmediate(() => this.settings.connected());

}
return this.namespaceFile + id + "$%$" + name + (isMeta !== void 0 ? isMeta ? "$%$meta" : "$%$data" : "");
return `${this.namespaceFile + id}$%$${name}${isMeta !== void 0 ? isMeta ? "$%$meta" : "$%$data" : ""}`;
}

@@ -184,3 +184,3 @@ _socketEvents(handler) {

handler.on("quit", (_data, responseId) => {
this.log.silly(namespaceLog + " Redis QUIT received, close connection");
this.log.silly(`${namespaceLog} Redis QUIT received, close connection`);
handler.sendString(responseId, "OK");

@@ -310,3 +310,3 @@ handler.close();

} catch (err) {
return void handler.sendError(responseId, new Error("ERROR _getObjects: " + err.message));
return void handler.sendError(responseId, new Error(`ERROR _getObjects: ${err.message}`));
}

@@ -712,3 +712,3 @@ result = result.map((el) => el ? JSON.stringify(el) : null);

if (this.settings.connection.enhancedLogging) {
this.log.silly(this.namespace + " Handling new Redis Objects connection");
this.log.silly(`${this.namespace} Handling new Redis Objects connection`);
}

@@ -723,6 +723,6 @@ const 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}`];
}

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

/**
* This class inherits InMemoryFileDB class and adds all relevant logic for objects
* including the available methods for use by js-controller directly
**/
*/
export class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
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 @@ */

@@ -17,7 +17,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 = {

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

// but big objects are updated regularly (e.g. the repositories)
intervalMs: 1000 * 60 * 60 * 23
intervalMs: 1000 * 60 * 60 * 23,
},

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

intervalMs: 60000,
maxBufferedCommands: 1000
maxBufferedCommands: 1000,
},

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

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

@@ -81,3 +81,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 ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {

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

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

@@ -105,11 +104,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) {

@@ -119,3 +128,6 @@ target.set(prop, value);

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

@@ -127,3 +139,6 @@ return target.delete(prop);

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

@@ -137,5 +152,5 @@ if (!target.has(prop)) {

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

@@ -150,3 +165,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.

@@ -157,3 +173,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

@@ -191,3 +207,2 @@ let jsonlTimeStamp = 0;

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

@@ -194,0 +209,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.objectsServer = new ObjectsInMemoryServer(serverSettings);

@@ -5,6 +5,7 @@ /// <reference types="node" resolution-mode="require"/>

* to access the methods via redis protocol
**/
*/
export class ObjectsInMemoryServer extends ObjectsInMemoryJsonlDB {
/**
* Constructor
*
* @param settings State and InMem-DB settings

@@ -28,10 +29,16 @@ */

* Separate Namespace from ID and return both
*
* @param idWithNamespace ID or Array of IDs containing a redis namespace and the real ID
* @returns {{namespace: (string); id: string; name?: string; isMeta?: boolean}} Object with namespace and the
* @returns Object with namespace and the
* ID/Array of IDs without the namespace
* @private
*/
private _normalizeId;
_normalizeId(idWithNamespace: any): {
id: string | any[] | null;
namespace: string;
name: string;
isMeta: boolean | undefined;
};
/**
* Publish a subscribed value to one of the redis connections in redis format
*
* @param client Instance of RedisHandler

@@ -41,11 +48,12 @@ * @param type Type of subscribed key

* @param obj Object to publish
* @returns {number} Publish counter 0 or 1 depending on if send out or not
* @returns Publish counter 0 or 1 depending on if send out or not
*/
publishToClients(client: any, type: any, id: any, obj: any): number;
publishToClients(client: any, type: any, id: any, obj: any): 0 | 1;
/**
* Generate ID for a File
*
* @param id ID of the File
* @param name Name of the file
* @param isMeta generate a META ID or a Data ID?
* @returns {string} File-ID
* @returns File-ID
*/

@@ -55,11 +63,12 @@ getFileId(id: any, name: any, isMeta: any): string;

* Register all event listeners for Handler and implement the relevant logic
*
* @param handler RedisHandler instance
* @private
*/
private _socketEvents;
_socketEvents(handler: any): void;
/**
* Return connected RedisHandlers/Connections
* @returns {{}|*}
*
* @returns
*/
getClients(): {} | any;
getClients(): {};
/**

@@ -69,21 +78,20 @@ * Get keys matching pattern and send it to given responseId, for "SCAN" and "KEYS" - Objects and files supported

* @param handler RedisHandler instance
* @param {string} pattern - pattern without namespace prefix
* @param {number} responseId - Id where response will be sent to
* @param {boolean} isScan - if used by "SCAN" this flag should be true
* @private
* @param pattern - pattern without namespace prefix
* @param responseId - Id where response will be sent to
* @param isScan - if used by "SCAN" this flag should be true
*/
private _handleScanOrKeys;
_handleScanOrKeys(handler: any, pattern: any, responseId: any, isScan?: boolean): undefined;
/**
* Initialize RedisHandler for a new network connection
*
* @param socket Network socket
* @private
*/
private _initSocket;
_initSocket(socket: any): void;
/**
* Initialize Redis Server
*
* @param settings Settings object
* @private
* @return {Promise<void>}
* @returns
*/
private _initRedisServer;
_initRedisServer(settings: any): Promise<any>;
server: net.Server | undefined;

@@ -90,0 +98,0 @@ }

@@ -42,6 +42,7 @@ /**

* to access the methods via redis protocol
**/
*/
export class ObjectsInMemoryServer extends ObjectsInMemoryJsonlDB {
/**
* Constructor
*
* @param settings State and InMem-DB settings

@@ -52,8 +53,6 @@ */

this.serverConnections = {};
this.namespaceObjects =
(this.settings.redisNamespace || (settings.connection && settings.connection.redisNamespace) || 'cfg') +
'.';
this.namespaceFile = this.namespaceObjects + 'f.';
this.namespaceObj = this.namespaceObjects + 'o.';
this.namespaceSet = this.namespaceObjects + 's.';
this.namespaceObjects = `${this.settings.redisNamespace || (settings.connection && settings.connection.redisNamespace) || 'cfg'}.`;
this.namespaceFile = `${this.namespaceObjects}f.`;
this.namespaceObj = `${this.namespaceObjects}o.`;
this.namespaceSet = `${this.namespaceObjects}s.`;
this.namespaceSetLen = this.namespaceSet.length;

@@ -73,7 +72,3 @@ // this.namespaceObjectsLen = this.namespaceObjects.length;

.then(() => {
this.log.debug(this.namespace +
' ' +
(settings.secure ? 'Secure ' : '') +
' Redis inMem-objects listening on port ' +
(settings.port || 9001));
this.log.debug(`${this.namespace} ${settings.secure ? 'Secure ' : ''} Redis inMem-objects listening on port ${settings.port || 9001}`);
if (typeof this.settings.connected === 'function') {

@@ -90,6 +85,6 @@ setImmediate(() => this.settings.connected());

* Separate Namespace from ID and return both
*
* @param idWithNamespace ID or Array of IDs containing a redis namespace and the real ID
* @returns {{namespace: (string); id: string; name?: string; isMeta?: boolean}} Object with namespace and the
* @returns Object with namespace and the
* ID/Array of IDs without the namespace
* @private
*/

@@ -160,2 +155,3 @@ _normalizeId(idWithNamespace) {

* Publish a subscribed value to one of the redis connections in redis format
*
* @param client Instance of RedisHandler

@@ -165,3 +161,3 @@ * @param type Type of subscribed key

* @param obj Object to publish
* @returns {number} Publish counter 0 or 1 depending on if send out or not
* @returns Publish counter 0 or 1 depending on if send out or not
*/

@@ -201,6 +197,7 @@ publishToClients(client, type, id, obj) {

* Generate ID for a File
*
* @param id ID of the File
* @param name Name of the file
* @param isMeta generate a META ID or a Data ID?
* @returns {string} File-ID
* @returns File-ID
*/

@@ -218,8 +215,8 @@ getFileId(id, name, isMeta) {

}
return this.namespaceFile + id + '$%$' + name + (isMeta !== undefined ? (isMeta ? '$%$meta' : '$%$data') : '');
return `${this.namespaceFile + id}$%$${name}${isMeta !== undefined ? (isMeta ? '$%$meta' : '$%$data') : ''}`;
}
/**
* Register all event listeners for Handler and implement the relevant logic
*
* @param handler RedisHandler instance
* @private
*/

@@ -246,3 +243,3 @@ _socketEvents(handler) {

handler.on('quit', (_data, responseId) => {
this.log.silly(namespaceLog + ' Redis QUIT received, close connection');
this.log.silly(`${namespaceLog} Redis QUIT received, close connection`);
handler.sendString(responseId, 'OK');

@@ -326,3 +323,3 @@ handler.close();

endkey: data[4],
include_docs: true
include_docs: true,
});

@@ -345,3 +342,3 @@ }

endkey: data[4],
include_docs: true
include_docs: true,
});

@@ -393,3 +390,3 @@ const res = objs.rows.map(obj => JSON.stringify(this.dataset[obj.value._id || obj.id]));

catch (err) {
return void handler.sendError(responseId, new Error('ERROR _getObjects: ' + err.message));
return void handler.sendError(responseId, new Error(`ERROR _getObjects: ${err.message}`));
}

@@ -417,3 +414,2 @@ result = result.map(el => (el ? JSON.stringify(el) : null));

try {
// @ts-ignore
obj.stats = fs.statSync(path.join(this.objectsDir, id, name));

@@ -467,3 +463,3 @@ }

stats: {},
isDir: true
isDir: true,
}));

@@ -486,4 +482,4 @@ }

utils.CONSTS.ACCESS_GROUP_ALL |
utils.CONSTS.ACCESS_EVERY_ALL // 777
}
utils.CONSTS.ACCESS_EVERY_ALL, // 777
},
};

@@ -799,3 +795,4 @@ }

* Return connected RedisHandlers/Connections
* @returns {{}|*}
*
* @returns
*/

@@ -833,6 +830,5 @@ getClients() {

* @param handler RedisHandler instance
* @param {string} pattern - pattern without namespace prefix
* @param {number} responseId - Id where response will be sent to
* @param {boolean} isScan - if used by "SCAN" this flag should be true
* @private
* @param pattern - pattern without namespace prefix
* @param responseId - Id where response will be sent to
* @param isScan - if used by "SCAN" this flag should be true
*/

@@ -868,4 +864,4 @@ _handleScanOrKeys(handler, pattern, responseId, isScan = false) {

virtualFile: true,
notExists: true
}
notExists: true,
},
];

@@ -915,8 +911,8 @@ }

* Initialize RedisHandler for a new network connection
*
* @param socket Network socket
* @private
*/
_initSocket(socket) {
if (this.settings.connection.enhancedLogging) {
this.log.silly(this.namespace + ' Handling new Redis Objects connection');
this.log.silly(`${this.namespace} Handling new Redis Objects connection`);
}

@@ -927,10 +923,10 @@ const options = {

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}`];
}

@@ -941,5 +937,5 @@ });

* Initialize Redis Server
*
* @param settings Settings object
* @private
* @return {Promise<void>}
* @returns
*/

@@ -946,0 +942,0 @@ _initRedisServer(settings) {

{
"name": "@iobroker/db-objects-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-objects-file": "6.0.12-alpha.0-20240922-1ea0ace13",
"@iobroker/db-objects-redis": "6.0.12-alpha.0-20240922-1ea0ace13",
"@iobroker/db-base": "6.0.12-alpha.0-20240924-4e8189ae0",
"@iobroker/db-objects-file": "6.0.12-alpha.0-20240924-4e8189ae0",
"@iobroker/db-objects-redis": "6.0.12-alpha.0-20240924-4e8189ae0",
"deep-clone": "^3.0.3",

@@ -53,3 +53,3 @@ "fs-extra": "^11.1.0"

],
"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