New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@iobroker/db-objects-jsonl

Package Overview
Dependencies
Maintainers
6
Versions
423
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 4.0.0-alpha.25-20211211-1232a951 to 4.0.0-alpha.26-20211214-19e8d05e

9

lib/objects/objectsInMemJsonlDB.js

@@ -16,3 +16,3 @@ /**

const ObjectsInMemoryFileDB = require('@iobroker/db-objects-file').ObjectsInMemoryFileDB;
const ObjectsInMemoryFileDB = require('@iobroker/db-objects-file').ObjectsInMemoryFileDB;
const { JsonlDB } = require('@alcalzone/jsonl-db');

@@ -26,3 +26,2 @@ const path = require('path');

class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
constructor(settings) {

@@ -53,6 +52,3 @@ settings = settings || {};

/** @type {JsonlDB<any>} */
this._db = new JsonlDB(
path.join(this.dataDir, settings.jsonlDB.fileName),
jsonlOptions
);
this._db = new JsonlDB(path.join(this.dataDir, settings.jsonlDB.fileName), jsonlOptions);
}

@@ -109,5 +105,4 @@

}
}
module.exports = ObjectsInMemoryJsonlDB;

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

class ObjectsInMemoryServerClass extends ObjectsInRedisClient {
constructor(settings) {

@@ -28,3 +27,3 @@ settings.autoConnect = false; // delay Client connection to when we need it

const serverSettings = {
namespace: settings.namespace ? `${settings.namespace}-Server` : 'Server',
namespace: settings.namespace ? `${settings.namespace}-Server` : 'Server',
connection: settings.connection,

@@ -31,0 +30,0 @@ logger: settings.logger,

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

'use strict';
const net = require('net');
const fs = require('fs-extra');
const path = require('path');
const net = require('net');
const fs = require('fs-extra');
const path = require('path');
const crypto = require('crypto');
const utils = require('@iobroker/db-objects-redis').objectsUtils;
const tools = require('@iobroker/db-base').tools;
const utils = require('@iobroker/db-objects-redis').objectsUtils;
const tools = require('@iobroker/db-base').tools;
const RedisHandler = require('@iobroker/db-base').redisHandler;
const RedisHandler = require('@iobroker/db-base').redisHandler;
const ObjectsInMemoryJsonlDB = require('./objectsInMemJsonlDB');

@@ -61,8 +61,13 @@

this.serverConnections = {};
this.namespaceObjects = (this.settings.redisNamespace || (settings.connection && settings.connection.redisNamespace) || 'cfg') + '.';
this.namespaceFile = this.namespaceObjects + 'f.';
this.namespaceObj = this.namespaceObjects + 'o.';
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;
// this.namespaceObjectsLen = this.namespaceObjects.length;
this.namespaceFileLen = this.namespaceFile.length;
this.namespaceObjLen = this.namespaceObj.length;
this.namespaceFileLen = this.namespaceFile.length;
this.namespaceObjLen = this.namespaceObj.length;

@@ -74,14 +79,25 @@ this.knownScripts = {};

this.open().then(() => {
return this._initRedisServer(this.settings.connection);
}).then(() => {
this.log.debug(this.namespace + ' ' + (settings.secure ? 'Secure ' : '') + ' Redis inMem-objects listening on port ' + (settings.port || 9001));
this.open()
.then(() => {
return this._initRedisServer(this.settings.connection);
})
.then(() => {
this.log.debug(
this.namespace +
' ' +
(settings.secure ? 'Secure ' : '') +
' Redis inMem-objects listening on port ' +
(settings.port || 9001)
);
if (typeof this.settings.connected === 'function') {
setImmediate(() => this.settings.connected());
}
}).catch(e => {
this.log.error(this.namespace + ' Cannot start inMem-objects on port ' + (settings.port || 9001) + ': ' + e.message);
process.exit(24); // todo: replace it with exitcode
});
if (typeof this.settings.connected === 'function') {
setImmediate(() => this.settings.connected());
}
})
.catch(e => {
this.log.error(
this.namespace + ' Cannot start inMem-objects on port ' + (settings.port || 9001) + ': ' + e.message
);
process.exit(24); // todo: replace it with exitcode
});
}

@@ -104,3 +120,3 @@

idWithNamespace.forEach(el => {
const {id, namespace} = this._normalizeId(el);
const { id, namespace } = this._normalizeId(el);
ids.push(id);

@@ -118,2 +134,4 @@ ns = namespace; // we ignore the pot. case from arrays with different namespaces

idx = this.namespaceFileLen;
} else if (idWithNamespace.startsWith(this.namespaceSet)) {
idx = this.namespaceSetLen;
}

@@ -129,3 +147,3 @@ if (idx !== -1) {

name = fileIdDetails[2] || '';
isMeta = (fileIdDetails[3] === 'meta');
isMeta = fileIdDetails[3] === 'meta';
} else {

@@ -145,3 +163,3 @@ fileIdDetails = id.match(this.normalizeFileRegex2);

}
return {id, namespace: ns, name, isMeta};
return { id, namespace: ns, name, isMeta };
}

@@ -169,3 +187,3 @@

const sendId = (type === 'objects' ? this.namespaceObj : this.namespaceObjects) + id;
client.sendArray(null,['pmessage', sendPattern, sendId, objString]);
client.sendArray(null, ['pmessage', sendPattern, sendId, objString]);
return 1;

@@ -188,5 +206,4 @@ }

name = name.replace(/^admin\//, '');
} else
// e.g. ekey.admin and iobroker.ekey/admin/ekey.png
if (name.match(/^iobroker.[-\d\w]\/admin\//i)) {
} else if (name.match(/^iobroker.[-\d\w]\/admin\//i)) {
// e.g. ekey.admin and iobroker.ekey/admin/ekey.png
name = name.replace(/^iobroker.[-\d\w]\/admin\//i, '');

@@ -255,11 +272,19 @@ }

this.knownScripts[scriptChecksum] = {design: design, search: search};
this.knownScripts[scriptChecksum] = { design: design, search: search };
if (this.settings.connection.enhancedLogging) {
this.log.silly(`${namespaceLog} Register View LUA Script: ${scriptChecksum} = ${JSON.stringify(this.knownScripts[scriptChecksum])}`);
this.log.silly(
`${namespaceLog} Register View LUA Script: ${scriptChecksum} = ${JSON.stringify(
this.knownScripts[scriptChecksum]
)}`
);
}
handler.sendBulk(responseId, scriptChecksum);
} else if (scriptFunc && scriptFunc[1]) {
this.knownScripts[scriptChecksum] = {func: scriptFunc[1]};
this.knownScripts[scriptChecksum] = { func: scriptFunc[1] };
if (this.settings.connection.enhancedLogging) {
this.log.silly(`${namespaceLog} Register Func LUA Script: ${scriptChecksum} = ${JSON.stringify(this.knownScripts[scriptChecksum])}`);
this.log.silly(
`${namespaceLog} Register Func LUA Script: ${scriptChecksum} = ${JSON.stringify(
this.knownScripts[scriptChecksum]
)}`
);
}

@@ -291,3 +316,5 @@ handler.sendBulk(responseId, scriptChecksum);

if (this.settings.connection.enhancedLogging) {
this.log.silly(`${namespaceLog} Script transformed into getObjectView: design=${scriptDesign}, search=${scriptSearch}`);
this.log.silly(
`${namespaceLog} Script transformed into getObjectView: design=${scriptDesign}, search=${scriptSearch}`
);
}

@@ -302,3 +329,8 @@ let objs;

} catch (err) {
return void handler.sendError(responseId, new Error('_getObjectView Error for ' + scriptDesign + '/' + scriptSearch + ': ' + err.message));
return void handler.sendError(
responseId,
new Error(
'_getObjectView Error for ' + scriptDesign + '/' + scriptSearch + ': ' + err.message
)
);
}

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

} else if (this.knownScripts[data[0]].func && data.length > 4) {
const scriptFunc = {map: this.knownScripts[data[0]].func.replace('%1', data[5])};
const scriptFunc = { map: this.knownScripts[data[0]].func.replace('%1', data[5]) };
if (this.settings.connection.enhancedLogging) {

@@ -329,5 +361,6 @@ this.log.silly(`${namespaceLog} Script transformed into _applyView: func=${scriptFunc.map}`);

handler.on('publish', (data, responseId) => {
const {id, namespace} = this._normalizeId(data[0]);
const { id, namespace } = this._normalizeId(data[0]);
if (namespace === this.namespaceObj) { // a "set" always comes afterwards, so do not publish
if (namespace === this.namespaceObj) {
// a "set" always comes afterwards, so do not publish
return void handler.sendInteger(responseId, 0); // do not publish for now

@@ -344,3 +377,3 @@ }

}
const {namespace, isMeta} = this._normalizeId(data[0]);
const { namespace, isMeta } = this._normalizeId(data[0]);

@@ -350,6 +383,8 @@ if (namespace === this.namespaceObj) {

data.forEach(dataId => {
const {id, namespace} = this._normalizeId(dataId);
const { id, namespace } = this._normalizeId(dataId);
if (namespace !== this.namespaceObj) {
keys.push(null);
this.log.warn(`${namespaceLog} Got MGET request for non Object-ID in Objects-ID chunk for ${namespace} / ${dataId}`);
this.log.warn(
`${namespaceLog} Got MGET request for non Object-ID in Objects-ID chunk for ${namespace} / ${dataId}`
);
return;

@@ -365,3 +400,3 @@ }

}
result = result.map(el => el ? JSON.stringify(el) : null);
result = result.map(el => (el ? JSON.stringify(el) : null));
handler.sendArray(responseId, result);

@@ -373,6 +408,8 @@ } else if (namespace === this.namespaceFile) {

data.forEach(dataId => {
const {id, namespace, name} = this._normalizeId(dataId);
const { id, namespace, name } = this._normalizeId(dataId);
if (namespace !== this.namespaceFile) {
response.push(null);
this.log.warn(`${namespaceLog} Got MGET request for non File ID in File-ID chunk for ${dataId}`);
this.log.warn(
`${namespaceLog} Got MGET request for non File ID in File-ID chunk for ${dataId}`
);
return;

@@ -391,3 +428,5 @@ }

if (!name.endsWith('/_data.json')) {
this.log.warn(`${namespaceLog} Got MGET request for non existing file ${dataId}, err: ${err.message}`);
this.log.warn(
`${namespaceLog} Got MGET request for non existing file ${dataId}, err: ${err.message}`
);
}

@@ -405,3 +444,6 @@ response.push(null);

} else {
handler.sendError(responseId, new Error('MGET-UNSUPPORTED for namespace ' + namespace + ': Data=' + JSON.stringify(data)));
handler.sendError(
responseId,
new Error('MGET-UNSUPPORTED for namespace ' + namespace + ': Data=' + JSON.stringify(data))
);
}

@@ -412,3 +454,3 @@ });

handler.on('get', (data, responseId) => {
const {id, namespace, name, isMeta} = this._normalizeId(data[0]);
const { id, namespace, name, isMeta } = this._normalizeId(data[0]);

@@ -432,7 +474,10 @@ if (namespace === this.namespaceObj) {

if (stats.isDirectory()) {
return void handler.sendBulk(responseId, JSON.stringify({
file: name,
stats: {},
isDir: true
}));
return void handler.sendBulk(
responseId,
JSON.stringify({
file: name,
stats: {},
isDir: true
})
);
}

@@ -449,5 +494,12 @@ this._loadFileSettings(id);

acl: {
owner: (this.defaultNewAcl && this.defaultNewAcl.owner) || utils.CONSTS.SYSTEM_ADMIN_USER,
ownerGroup: (this.defaultNewAcl && this.defaultNewAcl.ownerGroup) || utils.CONSTS.SYSTEM_ADMIN_GROUP,
permissions: (this.defaultNewAcl && this.defaultNewAcl.file.permissions) || (utils.CONSTS.ACCESS_USER_ALL | utils.CONSTS.ACCESS_GROUP_ALL | utils.CONSTS.ACCESS_EVERY_ALL) // 777
owner:
(this.defaultNewAcl && this.defaultNewAcl.owner) || utils.CONSTS.SYSTEM_ADMIN_USER,
ownerGroup:
(this.defaultNewAcl && this.defaultNewAcl.ownerGroup) ||
utils.CONSTS.SYSTEM_ADMIN_GROUP,
permissions:
(this.defaultNewAcl && this.defaultNewAcl.file.permissions) ||
utils.CONSTS.ACCESS_USER_ALL |
utils.CONSTS.ACCESS_GROUP_ALL |
utils.CONSTS.ACCESS_EVERY_ALL // 777
}

@@ -473,3 +525,5 @@ };

fileData = JSON.stringify(fileData);
this.log.warn(`${namespaceLog} Data of "${id}/${name}" has invalid structure at file data request: ${fileData}`);
this.log.warn(
`${namespaceLog} Data of "${id}/${name}" has invalid structure at file data request: ${fileData}`
);
}

@@ -479,3 +533,6 @@ handler.sendBufBulk(responseId, Buffer.from(fileData));

} else {
handler.sendError(responseId, new Error('GET-UNSUPPORTED for namespace ' + namespace + ': Data=' + JSON.stringify(data)));
handler.sendError(
responseId,
new Error('GET-UNSUPPORTED for namespace ' + namespace + ': Data=' + JSON.stringify(data))
);
}

@@ -486,3 +543,3 @@ });

handler.on('set', (data, responseId) => {
const {id, namespace, name, isMeta} = this._normalizeId(data[0]);
const { id, namespace, name, isMeta } = this._normalizeId(data[0]);

@@ -509,6 +566,12 @@ if (namespace === this.namespaceObj) {

this.fileOptions[id][name] = JSON.parse(data[1].toString('utf-8'));
fs.writeFileSync(path.join(this.objectsDir, id, '_data.json'), JSON.stringify(this.fileOptions[id]));
fs.writeFileSync(
path.join(this.objectsDir, id, '_data.json'),
JSON.stringify(this.fileOptions[id])
);
}
} catch (err) {
return void handler.sendError(responseId, new Error(`ERROR writeFile-Meta id=${id}: ${err.message}`));
return void handler.sendError(
responseId,
new Error(`ERROR writeFile-Meta id=${id}: ${err.message}`)
);
}

@@ -521,3 +584,6 @@ handler.sendString(responseId, 'OK');

} catch (err) {
return void handler.sendError(responseId, new Error(`ERROR writeFile id=${id}: ${err.message}`));
return void handler.sendError(
responseId,
new Error(`ERROR writeFile id=${id}: ${err.message}`)
);
}

@@ -527,3 +593,6 @@ handler.sendString(responseId, 'OK');

} else {
handler.sendError(responseId, new Error(`SET-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`));
handler.sendError(
responseId,
new Error(`SET-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`)
);
}

@@ -539,3 +608,6 @@ });

if (oldDetails.id !== newDetails.id) {
return void handler.sendError(responseId, new Error('ERROR renameObject: id needs to stay the same'));
return void handler.sendError(
responseId,
new Error('ERROR renameObject: id needs to stay the same')
);
}

@@ -556,3 +628,6 @@

} else {
handler.sendError(responseId, new Error(`RENAME-UNSUPPORTED for namespace ${oldDetails.namespace}: Data=${JSON.stringify(data)}`));
handler.sendError(
responseId,
new Error(`RENAME-UNSUPPORTED for namespace ${oldDetails.namespace}: Data=${JSON.stringify(data)}`)
);
}

@@ -563,3 +638,3 @@ });

handler.on('del', (data, responseId) => {
const {id, namespace, name, isMeta} = this._normalizeId(data[0]);
const { id, namespace, name, isMeta } = this._normalizeId(data[0]);

@@ -588,3 +663,6 @@ if (namespace === this.namespaceObj) {

} else {
handler.sendError(responseId, new Error(`DEL-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`));
handler.sendError(
responseId,
new Error(`DEL-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`)
);
}

@@ -599,3 +677,3 @@ });

// Note: we only simulate single key existence check
const {id, namespace, name} = this._normalizeId(data[0]);
const { id, namespace, name } = this._normalizeId(data[0]);

@@ -618,2 +696,5 @@ if (namespace === this.namespaceObj) {

handler.sendInteger(responseId, exists ? 1 : 0);
} else if (namespace === this.namespaceSet) {
// we are not using sets in simulator, so just say it exists
return void handler.sendInteger(responseId, 1);
} else {

@@ -642,5 +723,32 @@ handler.sendError(responseId, new Error(`EXISTS-UNSUPPORTED for namespace ${namespace}`));

// MULTI/EXEC is never used with return values, thus we just answer with syntactic correct responses
handler.on('multi', (data, responseId) => {
return void handler.sendString(responseId, 'OK');
});
handler.on('exec', (data, reponseId) => {
return void handler.sendArray(reponseId, []);
});
// commands for redis SETS, just dummies
handler.on('sadd', (data, responseId) => {
return void handler.sendInteger(responseId, 1);
});
handler.on('srem', (data, responseId) => {
return void handler.sendInteger(responseId, 1);
});
handler.on('sscan', (data, responseId) => {
// for file DB it does the same as scan but data looks different
if (!data || data.length < 4) {
return void handler.sendArray(responseId, ['0', []]);
}
return this._handleScanOrKeys(handler, data[3], responseId, true);
});
// Handle Redis "PSUBSCRIBE" request for state, log and session namespace
handler.on('psubscribe', (data, responseId) => {
const {id, namespace} = this._normalizeId(data[0]);
const { id, namespace } = this._normalizeId(data[0]);

@@ -651,3 +759,6 @@ if (namespace === this.namespaceObj) {

} else {
handler.sendError(responseId, new Error('PSUBSCRIBE-UNSUPPORTED for namespace ' + namespace + ': Data=' + JSON.stringify(data)));
handler.sendError(
responseId,
new Error('PSUBSCRIBE-UNSUPPORTED for namespace ' + namespace + ': Data=' + JSON.stringify(data))
);
}

@@ -658,3 +769,3 @@ });

handler.on('punsubscribe', (data, responseId) => {
const {id, namespace} = this._normalizeId(data[0]);
const { id, namespace } = this._normalizeId(data[0]);

@@ -665,3 +776,6 @@ if (namespace === this.namespaceObj) {

} else {
handler.sendError(responseId, new Error('PUNSUBSCRIBE-UNSUPPORTED for namespace ' + namespace + ': Data=' + JSON.stringify(data)));
handler.sendError(
responseId,
new Error('PUNSUBSCRIBE-UNSUPPORTED for namespace ' + namespace + ': Data=' + JSON.stringify(data))
);
}

@@ -726,13 +840,15 @@ });

return /** @type {Promise<void>} */ (new Promise(resolve => {
if (!this.server) {
return void resolve();
}
try {
this.server.close(() => resolve());
} catch (e) {
console.log(e.message);
resolve();
}
}));
return /** @type {Promise<void>} */ (
new Promise(resolve => {
if (!this.server) {
return void resolve();
}
try {
this.server.close(() => resolve());
} catch (e) {
console.log(e.message);
resolve();
}
})
);
}

@@ -751,9 +867,10 @@ }

_handleScanOrKeys(handler, pattern, responseId, isScan = false) {
const {id, namespace, name, isMeta} = this._normalizeId(pattern);
const { id, namespace, name, isMeta } = this._normalizeId(pattern);
let response = [];
if (namespace === this.namespaceObj || namespace === this.namespaceObjects) {
response = this._getKeys(id).map(val => this.namespaceObj + val);
response = this._getKeys(id).map(val => this.namespaceObj + val);
// if scan, we send the cursor as first argument
if (namespace !== this.namespaceObjects) { // When it was not the full DB namespace send out response
if (namespace !== this.namespaceObjects) {
// When it was not the full DB namespace send out response
return void handler.sendArray(responseId, isScan ? ['0', response] : response);

@@ -769,9 +886,11 @@ }

if (!res || !res.length) {
res = [{
file: '_data.json',
stats: {},
isDir: false,
virtualFile: true,
notExists: true
}];
res = [
{
file: '_data.json',
stats: {},
isDir: false,
virtualFile: true,
notExists: true
}
];
}

@@ -803,7 +922,13 @@ } catch (err) {

handler.sendArray(responseId, isScan ? ['0', response] : response); // send out file or full db response
} else { // such a request should never happen
} else {
// such a request should never happen
handler.sendArray(responseId, isScan ? ['0', []] : []); // send out file or full db response
}
} else if (namespace === this.namespaceSet) {
handler.sendArray(responseId, isScan ? ['0', []] : []); // send out empty array, we have no sets
} else {
handler.sendError(responseId, new Error(`${isScan ? 'SCAN' : 'KEYS'}-UNSUPPORTED for namespace ${namespace}: Pattern=${pattern}`));
handler.sendError(
responseId,
new Error(`${isScan ? 'SCAN' : 'KEYS'}-UNSUPPORTED for namespace ${namespace}: Pattern=${pattern}`)
);
}

@@ -852,3 +977,8 @@ }

this.server.on('error', err =>
this.log.info(`${this.namespace} ${settings.secure ? 'Secure ' : ''} Error inMem-objects listening on port ${settings.port || 9001}: ${err}`));
this.log.info(
`${this.namespace} ${settings.secure ? 'Secure ' : ''} Error inMem-objects listening on port ${
settings.port || 9001
}: ${err}`
)
);
this.server.on('connection', socket => this._initSocket(socket));

@@ -855,0 +985,0 @@

{
"name": "@iobroker/db-objects-jsonl",
"version": "4.0.0-alpha.25-20211211-1232a951",
"version": "4.0.0-alpha.26-20211214-19e8d05e",
"engines": {

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

"@alcalzone/jsonl-db": "^2.2.0",
"@iobroker/db-base": "4.0.0-alpha.25-20211211-1232a951",
"@iobroker/db-objects-file": "4.0.0-alpha.25-20211211-1232a951",
"@iobroker/db-objects-redis": "4.0.0-alpha.25-20211211-1232a951",
"@iobroker/db-base": "4.0.0-alpha.26-20211214-19e8d05e",
"@iobroker/db-objects-file": "4.0.0-alpha.26-20211214-19e8d05e",
"@iobroker/db-objects-redis": "4.0.0-alpha.26-20211214-19e8d05e",
"deep-clone": "^3.0.3",

@@ -42,3 +42,3 @@ "fs-extra": "^10.0.0",

],
"gitHead": "f1cdd329b8fd9a6c442ace4fd1c50a1e7f53d381"
"gitHead": "b192169960992cc360b1f6c297a6ec0877e2558f"
}
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