@iobroker/db-objects-jsonl
Advanced tools
Comparing version 6.0.1-alpha.0-20240603-3deca26fa to 6.0.1-alpha.0-20240603-8378eb65c
@@ -12,4 +12,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
constructor(settings: any); | ||
/** @type {Map<string, SubscriptionClient>} */ | ||
serverConnections: Map<string, SubscriptionClient>; | ||
serverConnections: {}; | ||
namespaceObjects: string; | ||
@@ -36,20 +35,10 @@ 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 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): number; | ||
publishToClients(client: any, type: any, id: any, obj: any): number; | ||
/** | ||
@@ -56,0 +45,0 @@ * Generate ID for a File |
@@ -43,3 +43,3 @@ "use strict"; | ||
super(settings); | ||
this.serverConnections = /* @__PURE__ */ new Map(); | ||
this.serverConnections = {}; | ||
this.namespaceObjects = (this.settings.redisNamespace || settings.connection && settings.connection.redisNamespace || "cfg") + "."; | ||
@@ -125,34 +125,31 @@ this.namespaceFile = this.namespaceObjects + "f."; | ||
} | ||
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); | ||
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; | ||
} | ||
return publishCount; | ||
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]); | ||
} 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) { | ||
@@ -630,6 +627,6 @@ if (id.endsWith(".admin")) { | ||
if (this.server) { | ||
for (const [connName, connection] of this.serverConnections) { | ||
connection.close(); | ||
this.serverConnections.delete(connName); | ||
} | ||
Object.keys(this.serverConnections).forEach((s) => { | ||
this.serverConnections[s].close(); | ||
delete this.serverConnections[s]; | ||
}); | ||
await new Promise((resolve) => { | ||
@@ -723,6 +720,6 @@ if (!this.server) { | ||
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]; | ||
} | ||
@@ -729,0 +726,0 @@ }); |
@@ -12,4 +12,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
constructor(settings: any); | ||
/** @type {Map<string, SubscriptionClient>} */ | ||
serverConnections: Map<string, SubscriptionClient>; | ||
serverConnections: {}; | ||
namespaceObjects: string; | ||
@@ -36,20 +35,10 @@ 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 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): number; | ||
publishToClients(client: any, type: any, id: any, obj: any): number; | ||
/** | ||
@@ -56,0 +45,0 @@ * Generate ID for a File |
@@ -50,4 +50,3 @@ /** | ||
super(settings); | ||
/** @type {Map<string, SubscriptionClient>} */ | ||
this.serverConnections = new Map(); | ||
this.serverConnections = {}; | ||
this.namespaceObjects = | ||
@@ -60,2 +59,3 @@ (this.settings.redisNamespace || (settings.connection && settings.connection.redisNamespace) || 'cfg') + | ||
this.namespaceSetLen = this.namespaceSet.length; | ||
// this.namespaceObjectsLen = this.namespaceObjects.length; | ||
this.namespaceFileLen = this.namespaceFile.length; | ||
@@ -157,51 +157,39 @@ this.namespaceObjLen = this.namespaceObj.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.namespaceMeta + pattern; | ||
const sendId = this.namespaceMeta + id; | ||
client.sendArray(null, ['pmessage', sendPattern, sendId, obj]); | ||
publishToClients(client, type, id, obj) { | ||
if (!client._subscribe || !client._subscribe[type]) { | ||
return 0; | ||
} | ||
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]); | ||
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 { | ||
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; | ||
return 0; | ||
} | ||
@@ -809,6 +797,6 @@ /** | ||
if (this.server) { | ||
for (const [connName, connection] of this.serverConnections) { | ||
connection.close(); | ||
this.serverConnections.delete(connName); | ||
} | ||
Object.keys(this.serverConnections).forEach(s => { | ||
this.serverConnections[s].close(); | ||
delete this.serverConnections[s]; | ||
}); | ||
await new Promise(resolve => { | ||
@@ -928,6 +916,6 @@ if (!this.server) { | ||
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]; | ||
} | ||
@@ -934,0 +922,0 @@ }); |
{ | ||
"name": "@iobroker/db-objects-jsonl", | ||
"type": "module", | ||
"version": "6.0.1-alpha.0-20240603-3deca26fa", | ||
"version": "6.0.1-alpha.0-20240603-8378eb65c", | ||
"engines": { | ||
@@ -10,5 +10,5 @@ "node": ">=12.0.0" | ||
"@alcalzone/jsonl-db": "~3.1.1", | ||
"@iobroker/db-base": "6.0.1-alpha.0-20240603-3deca26fa", | ||
"@iobroker/db-objects-file": "6.0.1-alpha.0-20240603-3deca26fa", | ||
"@iobroker/db-objects-redis": "6.0.1-alpha.0-20240603-3deca26fa", | ||
"@iobroker/db-base": "6.0.1-alpha.0-20240603-8378eb65c", | ||
"@iobroker/db-objects-file": "6.0.1-alpha.0-20240603-8378eb65c", | ||
"@iobroker/db-objects-redis": "6.0.1-alpha.0-20240603-8378eb65c", | ||
"deep-clone": "^3.0.3", | ||
@@ -53,3 +53,3 @@ "fs-extra": "^11.1.0" | ||
], | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
294388
2540
+ Added@iobroker/db-base@6.0.1-alpha.0-20240603-8378eb65c(transitive)
+ Added@iobroker/db-objects-file@6.0.1-alpha.0-20240603-8378eb65c(transitive)
+ Added@iobroker/db-objects-redis@6.0.1-alpha.0-20240603-8378eb65c(transitive)
+ Added@iobroker/js-controller-common-db@6.0.1-alpha.0-20240603-8378eb65c(transitive)
- Removed@iobroker/db-base@6.0.1-alpha.0-20240603-3deca26fa(transitive)
- Removed@iobroker/db-objects-file@6.0.1-alpha.0-20240603-3deca26fa(transitive)
- Removed@iobroker/db-objects-redis@6.0.1-alpha.0-20240603-3deca26fa(transitive)
- Removed@iobroker/js-controller-common-db@6.0.1-alpha.0-20240603-3deca26fa(transitive)
Updated@iobroker/db-objects-file@6.0.1-alpha.0-20240603-8378eb65c
Updated@iobroker/db-objects-redis@6.0.1-alpha.0-20240603-8378eb65c