Socket
Socket
Sign inDemoInstall

@iobroker/db-states-file

Package Overview
Dependencies
Maintainers
6
Versions
417
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 6.0.1-alpha.0-20240603-3deca26fa to 6.0.1-alpha.0-20240603-8378eb65c

22

build/cjs/lib/states/statesInMemServerRedis.d.ts

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

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

@@ -32,20 +31,10 @@ namespaceMsg: 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 clientOptions Instance of RedisHandler and pattern
* @param client Instance of RedisHandler
* @param type Type of subscribed key
* @param id Subscribed ID
* @param obj Object to publish
* @returns Publish counter 0 or 1 depending on if send out or not
* @returns {number} Publish counter 0 or 1 depending on if send out or not
*/
publishToClient(clientOptions: any, type: any, id: any, obj: any): 0 | 1;
publishToClients(client: any, type: any, id: any, obj: any): number;
/**

@@ -59,4 +48,5 @@ * Register all event listeners for Handler and implement the relevant logic

* Return connected RedisHandlers/Connections
* @returns {{}|*}
*/
getClients(): Map<string, SubscriptionClient>;
getClients(): {} | any;
/**

@@ -63,0 +53,0 @@ * Initialize RedisHandler for a new network connection

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

super(settings);
this.serverConnections = /* @__PURE__ */ new Map();
this.serverConnections = {};
this.namespaceStates = (this.settings.redisNamespace || "io") + ".";

@@ -84,33 +84,30 @@ this.namespaceMsg = (this.settings.namespaceMsg || "messagebox") + ".";

}
publishPattern(patternInformation, type, id, obj) {
let publishCount = 0;
if (!patternInformation.regex.test(id)) {
return publishCount;
publishToClients(client, type, id, obj) {
if (!client._subscribe || !client._subscribe[type]) {
return 0;
}
for (const client of patternInformation.clients) {
publishCount += this.publishToClient(client, type, id, obj);
}
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.metaNamespace + pattern;
const sendId = this.metaNamespace + id;
client.sendArray(null, ["pmessage", sendPattern, sendId, obj]);
} else {
let objString;
try {
objString = JSON.stringify(obj);
} catch (e) {
this.log.error(`${this.namespace} Error on publishing state: ${id}=${(0, import_node_util.inspect)(obj)}: ${e.message}`);
return 0;
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.metaNamespace + found.pattern;
const sendId = this.metaNamespace + id;
client.sendArray(null, ["pmessage", sendPattern, sendId, obj]);
} else {
let objString;
try {
objString = JSON.stringify(obj);
} catch (e) {
this.log.error(`${this.namespace} Error on publishing state: ${id}=${(0, import_node_util.inspect)(obj)}: ${e.message}`);
return 0;
}
this.log.silly(`${this.namespace} Redis Publish State ${id}=${objString}`);
const sendPattern = (type === "state" ? "" : this.namespaceStates) + found.pattern;
const sendId = (type === "state" ? "" : this.namespaceStates) + id;
client.sendArray(null, ["pmessage", sendPattern, sendId, objString]);
}
this.log.silly(`${this.namespace} Redis Publish State ${id}=${objString}`);
const sendPattern = (type === "state" ? "" : this.namespaceStates) + pattern;
const sendId = (type === "state" ? "" : this.namespaceStates) + id;
client.sendArray(null, ["pmessage", sendPattern, sendId, objString]);
return 1;
}
return 1;
return 0;
}

@@ -274,6 +271,6 @@ _socketEvents(handler) {

if (namespace === this.namespaceMsg) {
this._subscribeMessageForClient(handler, id.substring(this.namespaceMsgLen));
this._subscribeMessageForClient(handler, id.substr(this.namespaceMsgLen));
handler.sendArray(responseId, ["psubscribe", data[0], 1]);
} else if (namespace === this.namespaceLog) {
this._subscribeLogForClient(handler, id.substring(this.namespaceLogLen));
this._subscribeLogForClient(handler, id.substr(this.namespaceLogLen));
handler.sendArray(responseId, ["psubscribe", data[0], 1]);

@@ -297,6 +294,6 @@ } else if (namespace === this.namespaceStates) {

if (namespace === this.namespaceMsg) {
this._unsubscribeMessageForClient(handler, id.substring(this.namespaceMsgLen));
this._unsubscribeMessageForClient(handler, id.substr(this.namespaceMsgLen));
handler.sendArray(responseId, ["punsubscribe", data[0], 1]);
} else if (namespace === this.namespaceLog) {
this._unsubscribeLogForClient(handler, id.substring(this.namespaceLogLen));
this._unsubscribeLogForClient(handler, id.substr(this.namespaceLogLen));
handler.sendArray(responseId, ["punsubscribe", data[0], 1]);

@@ -346,5 +343,5 @@ } else if (namespace === this.namespaceStates) {

if (this.server) {
for (const [connectionName, connection] of this.serverConnections) {
connection.close();
this.serverConnections.delete(connectionName);
for (const s of Object.keys(this.serverConnections)) {
this.serverConnections[s].close();
delete this.serverConnections[s];
}

@@ -375,6 +372,6 @@ await new Promise((resolve) => {

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

@@ -381,0 +378,0 @@ });

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

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

@@ -32,20 +31,10 @@ namespaceMsg: 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 clientOptions Instance of RedisHandler and pattern
* @param client Instance of RedisHandler
* @param type Type of subscribed key
* @param id Subscribed ID
* @param obj Object to publish
* @returns Publish counter 0 or 1 depending on if send out or not
* @returns {number} Publish counter 0 or 1 depending on if send out or not
*/
publishToClient(clientOptions: any, type: any, id: any, obj: any): 0 | 1;
publishToClients(client: any, type: any, id: any, obj: any): number;
/**

@@ -59,4 +48,5 @@ * Register all event listeners for Handler and implement the relevant logic

* Return connected RedisHandlers/Connections
* @returns {{}|*}
*/
getClients(): Map<string, SubscriptionClient>;
getClients(): {} | any;
/**

@@ -63,0 +53,0 @@ * Initialize RedisHandler for a new network connection

@@ -46,4 +46,3 @@ /**

super(settings);
/** @type {Map<string, SubscriptionClient>} */
this.serverConnections = new Map();
this.serverConnections = {};
this.namespaceStates = (this.settings.redisNamespace || 'io') + '.';

@@ -53,4 +52,6 @@ this.namespaceMsg = (this.settings.namespaceMsg || 'messagebox') + '.';

this.namespaceSession = (this.settings.namespaceSession || 'session') + '.';
//this.namespaceStatesLen = this.namespaceStates.length;
this.namespaceMsgLen = this.namespaceMsg.length;
this.namespaceLogLen = this.namespaceLog.length;
//this.namespaceSessionlen = this.namespaceSession.length;
this.metaNamespace = (this.settings.metaNamespace || 'meta') + '.';

@@ -105,52 +106,40 @@ this.metaNamespaceLen = this.metaNamespace.length;

/**
* 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 clientOptions Instance of RedisHandler and pattern
* @param client Instance of RedisHandler
* @param type Type of subscribed key
* @param id Subscribed ID
* @param obj Object to publish
* @returns Publish counter 0 or 1 depending on if send out or not
* @returns {number} Publish counter 0 or 1 depending on if send out or not
*/
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.metaNamespace + pattern;
const sendId = this.metaNamespace + id;
client.sendArray(null, ['pmessage', sendPattern, sendId, obj]);
publishToClients(client, type, id, obj) {
if (!client._subscribe || !client._subscribe[type]) {
return 0;
}
else {
let objString;
try {
objString = JSON.stringify(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.metaNamespace + found.pattern;
const sendId = this.metaNamespace + id;
client.sendArray(null, ['pmessage', sendPattern, sendId, obj]);
}
catch (e) {
// mainly catch circular structures - thus log object with inspect
this.log.error(`${this.namespace} Error on publishing state: ${id}=${inspect(obj)}: ${e.message}`);
return 0;
else {
let objString;
try {
objString = JSON.stringify(obj);
}
catch (e) {
// mainly catch circular structures - thus log object with inspect
this.log.error(`${this.namespace} Error on publishing state: ${id}=${inspect(obj)}: ${e.message}`);
return 0;
}
this.log.silly(`${this.namespace} Redis Publish State ${id}=${objString}`);
const sendPattern = (type === 'state' ? '' : this.namespaceStates) + found.pattern;
const sendId = (type === 'state' ? '' : this.namespaceStates) + id;
client.sendArray(null, ['pmessage', sendPattern, sendId, objString]);
}
this.log.silly(`${this.namespace} Redis Publish State ${id}=${objString}`);
const sendPattern = (type === 'state' ? '' : this.namespaceStates) + pattern;
const sendId = (type === 'state' ? '' : this.namespaceStates) + id;
client.sendArray(null, ['pmessage', sendPattern, sendId, objString]);
return 1;
}
return 1;
return 0;
}

@@ -350,7 +339,7 @@ /**

if (namespace === this.namespaceMsg) {
this._subscribeMessageForClient(handler, id.substring(this.namespaceMsgLen));
this._subscribeMessageForClient(handler, id.substr(this.namespaceMsgLen));
handler.sendArray(responseId, ['psubscribe', data[0], 1]);
}
else if (namespace === this.namespaceLog) {
this._subscribeLogForClient(handler, id.substring(this.namespaceLogLen));
this._subscribeLogForClient(handler, id.substr(this.namespaceLogLen));
handler.sendArray(responseId, ['psubscribe', data[0], 1]);

@@ -379,7 +368,7 @@ }

if (namespace === this.namespaceMsg) {
this._unsubscribeMessageForClient(handler, id.substring(this.namespaceMsgLen));
this._unsubscribeMessageForClient(handler, id.substr(this.namespaceMsgLen));
handler.sendArray(responseId, ['punsubscribe', data[0], 1]);
}
else if (namespace === this.namespaceLog) {
this._unsubscribeLogForClient(handler, id.substring(this.namespaceLogLen));
this._unsubscribeLogForClient(handler, id.substr(this.namespaceLogLen));
handler.sendArray(responseId, ['punsubscribe', data[0], 1]);

@@ -441,2 +430,3 @@ }

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

@@ -451,5 +441,5 @@ getClients() {

if (this.server) {
for (const [connectionName, connection] of this.serverConnections) {
connection.close();
this.serverConnections.delete(connectionName);
for (const s of Object.keys(this.serverConnections)) {
this.serverConnections[s].close();
delete this.serverConnections[s];
}

@@ -487,6 +477,6 @@ await new Promise(resolve => {

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

@@ -493,0 +483,0 @@ });

{
"name": "@iobroker/db-states-file",
"type": "module",
"version": "6.0.1-alpha.0-20240603-3deca26fa",
"version": "6.0.1-alpha.0-20240603-8378eb65c",
"engines": {

@@ -9,4 +9,4 @@ "node": ">=12.0.0"

"dependencies": {
"@iobroker/db-base": "6.0.1-alpha.0-20240603-3deca26fa",
"@iobroker/db-states-redis": "6.0.1-alpha.0-20240603-3deca26fa"
"@iobroker/db-base": "6.0.1-alpha.0-20240603-8378eb65c",
"@iobroker/db-states-redis": "6.0.1-alpha.0-20240603-8378eb65c"
},

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

],
"gitHead": "59c191f7ef1995375ade77815af6d3cf5b6efadf"
"gitHead": "8e55b654ff30dec37857c4495d27022d48055a29"
}

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