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

@iobroker/db-states-file

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

22

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

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

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

@@ -31,10 +32,20 @@ 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 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): 0 | 1;
/**

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

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

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

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

var import_tools = require("@iobroker/js-controller-common/tools");
var import_js_controller_common = require("@iobroker/js-controller-common");
class StatesInMemoryServer extends import_statesInMemFileDB.StatesInMemoryFileDB {
constructor(settings) {
super(settings);
this.serverConnections = {};
this.serverConnections = /* @__PURE__ */ new Map();
this.namespaceStates = (this.settings.redisNamespace || "io") + ".";

@@ -57,3 +58,3 @@ this.namespaceMsg = (this.settings.namespaceMsg || "messagebox") + ".";

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

@@ -84,30 +85,33 @@ }

}
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.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]);
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;
}
return 1;
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 0;
return 1;
}

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

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

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

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

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

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

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

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

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

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

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

@@ -31,10 +32,20 @@ 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 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): 0 | 1;
/**

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

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

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

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

import { getLocalAddress } from '@iobroker/js-controller-common/tools';
import { EXIT_CODES } from '@iobroker/js-controller-common';
// settings = {

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

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

@@ -52,6 +54,4 @@ 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') + '.';

@@ -71,3 +71,3 @@ this.metaNamespaceLen = this.metaNamespace.length;

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

@@ -107,40 +107,52 @@ }

/**
* 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.metaNamespace + pattern;
const sendId = this.metaNamespace + 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.metaNamespace + found.pattern;
const sendId = this.metaNamespace + id;
client.sendArray(null, ['pmessage', sendPattern, sendId, obj]);
else {
let objString;
try {
objString = JSON.stringify(obj);
}
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]);
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;
}
return 1;
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 0;
return 1;
}

@@ -340,7 +352,7 @@ /**

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

@@ -369,7 +381,7 @@ }

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

@@ -431,3 +443,2 @@ }

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

@@ -442,5 +453,5 @@ getClients() {

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

@@ -478,6 +489,6 @@ await new Promise(resolve => {

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

@@ -484,0 +495,0 @@ });

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

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

"dependencies": {
"@iobroker/db-base": "5.0.20-alpha.0-20240508-d36cddc8d",
"@iobroker/db-states-redis": "5.0.20-alpha.0-20240508-d36cddc8d"
"@iobroker/db-base": "5.0.20-alpha.0-20240510-819f1976e",
"@iobroker/db-states-redis": "5.0.20-alpha.0-20240510-819f1976e"
},

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

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

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