Socket
Socket
Sign inDemoInstall

@iobroker/db-objects-jsonl

Package Overview
Dependencies
Maintainers
6
Versions
404
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 5.0.20-alpha.0-20240508-d36cddc8d to 5.0.20-alpha.0-20240510-819f1976e

2

build/cjs/lib/objects/objectsInMemJsonlDB.d.ts

@@ -9,3 +9,3 @@ /**

_db: JsonlDB<any>;
_backupInterval: NodeJS.Timer | undefined;
_backupInterval: NodeJS.Timeout | undefined;
/**

@@ -12,0 +12,0 @@ * Checks if an existing file DB should be migrated to JSONL

@@ -12,3 +12,4 @@ /// <reference types="node" resolution-mode="require"/>

constructor(settings: any);
serverConnections: {};
/** @type {Map<string, SubscriptionClient>} */
serverConnections: Map<string, SubscriptionClient>;
namespaceObjects: string;

@@ -35,10 +36,20 @@ namespaceFile: string;

/**
* Publish a subscribed value to one of the redis connection by pattern in redis format
*
* @param patternInformation all redis handler for given pattern and pattern itself
* @param type Type of subscribed key
* @param id Subscribed ID
* @param obj Object to publish
* @returns Publish counter
*/
publishPattern(patternInformation: any, type: any, id: any, obj: any): number;
/**
* Publish a subscribed value to one of the redis connections in redis format
* @param client Instance of RedisHandler
* @param clientOptions Instance of RedisHandler and pattern
* @param type Type of subscribed key
* @param id Subscribed ID
* @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;
publishToClient(clientOptions: any, type: any, id: any, obj: any): number;
/**

@@ -45,0 +56,0 @@ * Generate ID for a File

@@ -39,6 +39,7 @@ "use strict";

var import_objectsInMemJsonlDB = require("./objectsInMemJsonlDB.js");
var import_js_controller_common = require("@iobroker/js-controller-common");
class ObjectsInMemoryServer extends import_objectsInMemJsonlDB.ObjectsInMemoryJsonlDB {
constructor(settings) {
super(settings);
this.serverConnections = {};
this.serverConnections = /* @__PURE__ */ new Map();
this.namespaceObjects = (this.settings.redisNamespace || settings.connection && settings.connection.redisNamespace || "cfg") + ".";

@@ -65,3 +66,3 @@ this.namespaceFile = this.namespaceObjects + "f.";

this.log.error(`${this.namespace} Cannot start inMem-objects on port ${settings.port || 9001}: ${e.message}`);
process.exit(24);
process.exit(import_js_controller_common.EXIT_CODES.NO_CONNECTION_TO_OBJ_DB);
});

@@ -125,31 +126,34 @@ }

}
publishToClients(client, type, id, obj) {
if (!client._subscribe || !client._subscribe[type]) {
return 0;
publishPattern(patternInformation, type, id, obj) {
let publishCount = 0;
if (!patternInformation.regex.test(id)) {
return publishCount;
}
const s = client._subscribe[type];
const found = s.find((sub) => sub.regex.test(id));
if (found) {
if (type === "meta") {
this.log.silly(`${this.namespace} Redis Publish Meta ${id}=${obj}`);
const sendPattern = this.namespaceMeta + found.pattern;
const sendId = this.namespaceMeta + id;
client.sendArray(null, ["pmessage", sendPattern, sendId, obj]);
} else if (type === "files") {
const objString = JSON.stringify(obj);
this.log.silly(`${this.namespace} Redis Publish File ${id}=${objString}`);
const sendPattern = this.namespaceFile + found.pattern;
const sendId = this.namespaceFile + id;
client.sendArray(null, ["pmessage", sendPattern, sendId, objString]);
} else {
const objString = JSON.stringify(obj);
this.log.silly(`${this.namespace} Redis Publish Object ${id}=${objString}`);
const sendPattern = (type === "objects" ? "" : this.namespaceObjects) + found.pattern;
const sendId = (type === "objects" ? this.namespaceObj : this.namespaceObjects) + id;
client.sendArray(null, ["pmessage", sendPattern, sendId, objString]);
}
return 1;
for (const client of patternInformation.clients) {
publishCount += this.publishToClient(client, type, id, obj);
}
return 0;
return publishCount;
}
publishToClient(clientOptions, type, id, obj) {
const { client, pattern } = clientOptions;
if (type === "meta") {
this.log.silly(`${this.namespace} Redis Publish Meta ${id}=${obj}`);
const sendPattern = this.namespaceMeta + pattern;
const sendId = this.namespaceMeta + id;
client.sendArray(null, ["pmessage", sendPattern, sendId, obj]);
} else if (type === "files") {
const objString = JSON.stringify(obj);
this.log.silly(`${this.namespace} Redis Publish File ${id}=${objString}`);
const sendPattern = this.namespaceFile + pattern;
const sendId = this.namespaceFile + id;
client.sendArray(null, ["pmessage", sendPattern, sendId, objString]);
} else {
const objString = JSON.stringify(obj);
this.log.silly(`${this.namespace} Redis Publish Object ${id}=${objString}`);
const sendPattern = (type === "objects" ? "" : this.namespaceObjects) + pattern;
const sendId = (type === "objects" ? this.namespaceObj : this.namespaceObjects) + id;
client.sendArray(null, ["pmessage", sendPattern, sendId, objString]);
}
return 1;
}
getFileId(id, name, isMeta) {

@@ -627,6 +631,6 @@ if (id.endsWith(".admin")) {

if (this.server) {
Object.keys(this.serverConnections).forEach((s) => {
this.serverConnections[s].close();
delete this.serverConnections[s];
});
for (const [connName, connection] of this.serverConnections) {
connection.close();
this.serverConnections.delete(connName);
}
await new Promise((resolve) => {

@@ -720,6 +724,6 @@ if (!this.server) {

this._socketEvents(handler);
this.serverConnections[socket.remoteAddress + ":" + socket.remotePort] = handler;
this.serverConnections.set(`${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.has(`${socket.remoteAddress}:${socket.remotePort}`)) {
this.serverConnections.delete(`${socket.remoteAddress}:${socket.remotePort}`);
}

@@ -726,0 +730,0 @@ });

@@ -9,3 +9,3 @@ /**

_db: JsonlDB<any>;
_backupInterval: NodeJS.Timer | undefined;
_backupInterval: NodeJS.Timeout | undefined;
/**

@@ -12,0 +12,0 @@ * Checks if an existing file DB should be migrated to JSONL

@@ -12,3 +12,4 @@ /// <reference types="node" resolution-mode="require"/>

constructor(settings: any);
serverConnections: {};
/** @type {Map<string, SubscriptionClient>} */
serverConnections: Map<string, SubscriptionClient>;
namespaceObjects: string;

@@ -35,10 +36,20 @@ namespaceFile: string;

/**
* Publish a subscribed value to one of the redis connection by pattern in redis format
*
* @param patternInformation all redis handler for given pattern and pattern itself
* @param type Type of subscribed key
* @param id Subscribed ID
* @param obj Object to publish
* @returns Publish counter
*/
publishPattern(patternInformation: any, type: any, id: any, obj: any): number;
/**
* Publish a subscribed value to one of the redis connections in redis format
* @param client Instance of RedisHandler
* @param clientOptions Instance of RedisHandler and pattern
* @param type Type of subscribed key
* @param id Subscribed ID
* @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;
publishToClient(clientOptions: any, type: any, id: any, obj: any): number;
/**

@@ -45,0 +56,0 @@ * Generate ID for a File

@@ -18,2 +18,3 @@ /**

import { ObjectsInMemoryJsonlDB } from './objectsInMemJsonlDB.js';
import { EXIT_CODES } from '@iobroker/js-controller-common';
// settings = {

@@ -50,3 +51,4 @@ // change: function (id, state) {},

super(settings);
this.serverConnections = {};
/** @type {Map<string, SubscriptionClient>} */
this.serverConnections = new Map();
this.namespaceObjects =

@@ -59,3 +61,2 @@ (this.settings.redisNamespace || (settings.connection && settings.connection.redisNamespace) || 'cfg') +

this.namespaceSetLen = this.namespaceSet.length;
// this.namespaceObjectsLen = this.namespaceObjects.length;
this.namespaceFileLen = this.namespaceFile.length;

@@ -84,3 +85,3 @@ this.namespaceObjLen = this.namespaceObj.length;

this.log.error(`${this.namespace} Cannot start inMem-objects on port ${settings.port || 9001}: ${e.message}`);
process.exit(24); // todo: replace it with exitcode
process.exit(EXIT_CODES.NO_CONNECTION_TO_OBJ_DB);
});

@@ -158,39 +159,51 @@ }

/**
* Publish a subscribed value to one of the redis connection by pattern in redis format
*
* @param patternInformation all redis handler for given pattern and pattern itself
* @param type Type of subscribed key
* @param id Subscribed ID
* @param obj Object to publish
* @returns Publish counter
*/
publishPattern(patternInformation, type, id, obj) {
let publishCount = 0;
if (!patternInformation.regex.test(id)) {
return publishCount;
}
for (const client of patternInformation.clients) {
publishCount += this.publishToClient(client, type, id, obj);
}
return publishCount;
}
/**
* Publish a subscribed value to one of the redis connections in redis format
* @param client Instance of RedisHandler
* @param clientOptions Instance of RedisHandler and pattern
* @param type Type of subscribed key
* @param id Subscribed ID
* @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, type, id, obj) {
if (!client._subscribe || !client._subscribe[type]) {
return 0;
publishToClient(clientOptions, type, id, obj) {
const { client, pattern } = clientOptions;
if (type === 'meta') {
this.log.silly(`${this.namespace} Redis Publish Meta ${id}=${obj}`);
const sendPattern = this.namespaceMeta + pattern;
const sendId = this.namespaceMeta + id;
client.sendArray(null, ['pmessage', sendPattern, sendId, obj]);
}
const s = client._subscribe[type];
const found = s.find(sub => sub.regex.test(id));
if (found) {
if (type === 'meta') {
this.log.silly(`${this.namespace} Redis Publish Meta ${id}=${obj}`);
const sendPattern = this.namespaceMeta + found.pattern;
const sendId = this.namespaceMeta + id;
client.sendArray(null, ['pmessage', sendPattern, sendId, obj]);
}
else if (type === 'files') {
const objString = JSON.stringify(obj);
this.log.silly(`${this.namespace} Redis Publish File ${id}=${objString}`);
const sendPattern = this.namespaceFile + found.pattern;
const sendId = this.namespaceFile + id;
client.sendArray(null, ['pmessage', sendPattern, sendId, objString]);
}
else {
const objString = JSON.stringify(obj);
this.log.silly(`${this.namespace} Redis Publish Object ${id}=${objString}`);
const sendPattern = (type === 'objects' ? '' : this.namespaceObjects) + found.pattern;
const sendId = (type === 'objects' ? this.namespaceObj : this.namespaceObjects) + id;
client.sendArray(null, ['pmessage', sendPattern, sendId, objString]);
}
return 1;
else if (type === 'files') {
const objString = JSON.stringify(obj);
this.log.silly(`${this.namespace} Redis Publish File ${id}=${objString}`);
const sendPattern = this.namespaceFile + pattern;
const sendId = this.namespaceFile + id;
client.sendArray(null, ['pmessage', sendPattern, sendId, objString]);
}
return 0;
else {
const objString = JSON.stringify(obj);
this.log.silly(`${this.namespace} Redis Publish Object ${id}=${objString}`);
const sendPattern = (type === 'objects' ? '' : this.namespaceObjects) + pattern;
const sendId = (type === 'objects' ? this.namespaceObj : this.namespaceObjects) + id;
client.sendArray(null, ['pmessage', sendPattern, sendId, objString]);
}
return 1;
}

@@ -798,6 +811,6 @@ /**

if (this.server) {
Object.keys(this.serverConnections).forEach(s => {
this.serverConnections[s].close();
delete this.serverConnections[s];
});
for (const [connName, connection] of this.serverConnections) {
connection.close();
this.serverConnections.delete(connName);
}
await new Promise(resolve => {

@@ -917,6 +930,6 @@ if (!this.server) {

this._socketEvents(handler);
this.serverConnections[socket.remoteAddress + ':' + socket.remotePort] = handler;
this.serverConnections.set(`${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.has(`${socket.remoteAddress}:${socket.remotePort}`)) {
this.serverConnections.delete(`${socket.remoteAddress}:${socket.remotePort}`);
}

@@ -923,0 +936,0 @@ });

{
"name": "@iobroker/db-objects-jsonl",
"type": "module",
"version": "5.0.20-alpha.0-20240508-d36cddc8d",
"version": "5.0.20-alpha.0-20240510-819f1976e",
"engines": {

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

"@alcalzone/jsonl-db": "~3.1.1",
"@iobroker/db-base": "5.0.20-alpha.0-20240508-d36cddc8d",
"@iobroker/db-objects-file": "5.0.20-alpha.0-20240508-d36cddc8d",
"@iobroker/db-objects-redis": "5.0.20-alpha.0-20240508-d36cddc8d",
"@iobroker/db-base": "5.0.20-alpha.0-20240510-819f1976e",
"@iobroker/db-objects-file": "5.0.20-alpha.0-20240510-819f1976e",
"@iobroker/db-objects-redis": "5.0.20-alpha.0-20240510-819f1976e",
"deep-clone": "^3.0.3",

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

],
"gitHead": "a1bf1c4c5ca460d8d1faaf73dcc7cfe1d93ed3b7"
"gitHead": "9189372e5c7449f16964b737db9bbe85d7491619"
}

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