@iobroker/db-objects-jsonl
Advanced tools
Comparing version 4.0.0-alpha.3-20210903-1d3954b5 to 4.0.0-alpha.30-20211220-ce617590
@@ -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) { | ||
@@ -38,3 +37,3 @@ settings = settings || {}; | ||
sizeFactor: 2, | ||
sizeFactorMinimumSize: 1000 | ||
sizeFactorMinimumSize: 25000 | ||
}, | ||
@@ -54,6 +53,3 @@ ignoreReadErrors: true, | ||
/** @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); | ||
} | ||
@@ -110,5 +106,4 @@ | ||
} | ||
} | ||
module.exports = ObjectsInMemoryJsonlDB; |
@@ -21,24 +21,8 @@ /** | ||
class ObjectsInMemoryServerClass extends ObjectsInRedisClient { | ||
constructor(settings) { | ||
settings.autoConnect = false; // delay Client connection to when we need it | ||
// hack around testing problem where subscribe was called before connect | ||
// Should be removed for a later release | ||
const origConnected = settings.connected; | ||
settings.connected = () => { | ||
this.clientConnected = true; | ||
if (Array.isArray(this.storedSubscribes) && this.storedSubscribes.length) { | ||
this.log.warn(`${this.namespace} Replay ${this.storedSubscribes.length} subscription calls for Objects Server that were done before the client was connected initially`); | ||
this.storedSubscribes.forEach((s => this.subscribe(s.pattern, s.options, s.callback))); | ||
this.storedSubscribes = []; | ||
} | ||
origConnected(); | ||
}; | ||
super(settings); | ||
this.clientConnected = false; | ||
this.storedSubscribes = []; | ||
const serverSettings = { | ||
namespace: settings.namespace ? `${settings.namespace}-Server` : 'Server', | ||
namespace: settings.namespace ? `${settings.namespace}-Server` : 'Server', | ||
connection: settings.connection, | ||
@@ -70,11 +54,3 @@ logger: settings.logger, | ||
} | ||
subscribe(pattern, options, callback) { | ||
if (!this.clientConnected) { | ||
this.storedSubscribes.push({pattern, options, callback}); // we ignore the promise return because not used for this testing issue we work around here | ||
} else { | ||
return super.subscribe(pattern, options, callback); | ||
} | ||
} | ||
} | ||
module.exports = ObjectsInMemoryServerClass; |
@@ -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,15 @@ | ||
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; | ||
this.metaNamespace = (this.settings.metaNamespace || 'meta') + '.'; | ||
this.metaNamespaceLen = this.metaNamespace.length; | ||
@@ -74,14 +81,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 +122,3 @@ | ||
idWithNamespace.forEach(el => { | ||
const {id, namespace} = this._normalizeId(el); | ||
const { id, namespace } = this._normalizeId(el); | ||
ids.push(id); | ||
@@ -118,2 +136,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 +149,3 @@ if (idx !== -1) { | ||
name = fileIdDetails[2] || ''; | ||
isMeta = (fileIdDetails[3] === 'meta'); | ||
isMeta = fileIdDetails[3] === 'meta'; | ||
} else { | ||
@@ -143,5 +163,11 @@ fileIdDetails = id.match(this.normalizeFileRegex2); | ||
} | ||
} else if (idWithNamespace.startsWith(this.metaNamespace)) { | ||
const idx = this.metaNamespaceLen; | ||
if (idx !== -1) { | ||
ns = idWithNamespace.substr(0, idx); | ||
id = idWithNamespace.substr(idx); | ||
} | ||
} | ||
} | ||
return {id, namespace: ns, name, isMeta}; | ||
return { id, namespace: ns, name, isMeta }; | ||
} | ||
@@ -165,7 +191,14 @@ | ||
if (found) { | ||
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]); | ||
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 { | ||
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; | ||
@@ -185,8 +218,7 @@ } | ||
// e.g. ekey.admin and admin/ekey.png | ||
if (id.match(/\.admin$/)) { | ||
if (name.match(/^admin\//)) { | ||
if (id.endsWith('.admin')) { | ||
if (name.startsWith('admin/')) { | ||
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 +287,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 +331,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 +344,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 +356,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 +376,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 || namespace === this.metaNamespace) { | ||
// a "set" always comes afterwards, so do not publish | ||
return void handler.sendInteger(responseId, 0); // do not publish for now | ||
@@ -344,3 +392,3 @@ } | ||
} | ||
const {namespace, isMeta} = this._normalizeId(data[0]); | ||
const { namespace, isMeta } = this._normalizeId(data[0]); | ||
@@ -350,6 +398,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 +415,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 +423,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 +443,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 +459,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 +469,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 +489,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 +509,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,8 +540,20 @@ }; | ||
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}` | ||
); | ||
} | ||
handler.sendBufBulk(responseId, Buffer.from(fileData)); | ||
} | ||
} else if (namespace === this.metaNamespace) { | ||
const result = this.getMeta(id); | ||
if (result === undefined || result === null) { | ||
handler.sendNull(responseId); | ||
} else { | ||
handler.sendBulk(responseId, result); | ||
} | ||
} 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)) | ||
); | ||
} | ||
@@ -485,3 +564,3 @@ }); | ||
handler.on('set', (data, responseId) => { | ||
const {id, namespace, name, isMeta} = this._normalizeId(data[0]); | ||
const { id, namespace, name, isMeta } = this._normalizeId(data[0]); | ||
@@ -508,6 +587,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}`) | ||
); | ||
} | ||
@@ -520,8 +605,17 @@ 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}`) | ||
); | ||
} | ||
handler.sendString(responseId, 'OK'); | ||
} | ||
} else if (namespace === this.metaNamespace) { | ||
this.setMeta(id, data[1].toString('utf-8')); | ||
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)}`) | ||
); | ||
} | ||
@@ -537,3 +631,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') | ||
); | ||
} | ||
@@ -554,3 +651,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)}`) | ||
); | ||
} | ||
@@ -561,3 +661,3 @@ }); | ||
handler.on('del', (data, responseId) => { | ||
const {id, namespace, name, isMeta} = this._normalizeId(data[0]); | ||
const { id, namespace, name, isMeta } = this._normalizeId(data[0]); | ||
@@ -586,3 +686,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)}`) | ||
); | ||
} | ||
@@ -597,3 +700,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]); | ||
@@ -616,2 +719,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 { | ||
@@ -640,5 +746,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]); | ||
@@ -648,4 +781,10 @@ if (namespace === this.namespaceObj) { | ||
handler.sendArray(responseId, ['psubscribe', data[0], 1]); | ||
} else if (namespace === this.metaNamespace) { | ||
this._subscribeMeta(handler, id); | ||
handler.sendArray(responseId, ['psubscribe', data[0], 1]); | ||
} 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)) | ||
); | ||
} | ||
@@ -656,3 +795,3 @@ }); | ||
handler.on('punsubscribe', (data, responseId) => { | ||
const {id, namespace} = this._normalizeId(data[0]); | ||
const { id, namespace } = this._normalizeId(data[0]); | ||
@@ -663,3 +802,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)) | ||
); | ||
} | ||
@@ -724,13 +866,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(); | ||
} | ||
}) | ||
); | ||
} | ||
@@ -749,9 +893,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); | ||
@@ -767,9 +912,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 | ||
} | ||
]; | ||
} | ||
@@ -801,7 +948,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}`) | ||
); | ||
} | ||
@@ -850,3 +1003,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)); | ||
@@ -853,0 +1011,0 @@ |
{ | ||
"name": "@iobroker/db-objects-jsonl", | ||
"version": "4.0.0-alpha.3-20210903-1d3954b5", | ||
"version": "4.0.0-alpha.30-20211220-ce617590", | ||
"engines": { | ||
@@ -8,6 +8,6 @@ "node": ">=12.0.0" | ||
"dependencies": { | ||
"@alcalzone/jsonl-db": "^2.1.0", | ||
"@iobroker/db-base": "4.0.0-alpha.3-20210903-1d3954b5", | ||
"@iobroker/db-objects-file": "4.0.0-alpha.3-20210903-1d3954b5", | ||
"@iobroker/db-objects-redis": "4.0.0-alpha.3-20210903-1d3954b5", | ||
"@alcalzone/jsonl-db": "^2.2.0", | ||
"@iobroker/db-base": "4.0.0-alpha.30-20211220-ce617590", | ||
"@iobroker/db-objects-file": "4.0.0-alpha.30-20211220-ce617590", | ||
"@iobroker/db-objects-redis": "4.0.0-alpha.30-20211220-ce617590", | ||
"deep-clone": "^3.0.3", | ||
@@ -38,3 +38,7 @@ "fs-extra": "^10.0.0", | ||
}, | ||
"gitHead": "a291fda216ac33d5b40e65c8a3b2c93aea62ab03" | ||
"files": [ | ||
"lib/", | ||
"index.js" | ||
], | ||
"gitHead": "fafabd20af76b3cae124318c8af3d3826d2979c3" | ||
} |
56927
1058
8
+ Added@alcalzone/pak@0.7.0(transitive)
+ Added@iobroker/db-base@4.0.0-alpha.30-20211220-ce617590(transitive)
+ Added@iobroker/db-objects-file@4.0.0-alpha.30-20211220-ce617590(transitive)
+ Added@iobroker/db-objects-redis@4.0.0-alpha.30-20211220-ce617590(transitive)
+ Added@iobroker/js-controller-common@4.0.0-alpha.30-20211220-ce617590(transitive)
+ Addedbuffer-equal-constant-time@1.0.1(transitive)
+ Addedci-info@3.9.0(transitive)
+ Addedecdsa-sig-formatter@1.0.11(transitive)
+ Addedjsonwebtoken@8.5.1(transitive)
+ Addedjwa@1.4.1(transitive)
+ Addedjws@3.2.2(transitive)
+ Addedlodash.includes@4.3.0(transitive)
+ Addedlodash.isboolean@3.0.3(transitive)
+ Addedlodash.isinteger@4.0.4(transitive)
+ Addedlodash.isnumber@3.0.3(transitive)
+ Addedlodash.isplainobject@4.0.6(transitive)
+ Addedlodash.isstring@4.0.1(transitive)
+ Addedlodash.once@4.1.1(transitive)
+ Addedsemver@5.7.2(transitive)
- Removed@alcalzone/pak@0.6.0(transitive)
- Removed@iobroker/db-base@4.0.0-alpha.3-20210903-1d3954b5(transitive)
- Removed@iobroker/db-objects-file@4.0.0-alpha.3-20210903-1d3954b5(transitive)
- Removed@iobroker/db-objects-redis@4.0.0-alpha.3-20210903-1d3954b5(transitive)
- Removed@iobroker/js-controller-common@4.0.0-alpha.3-20210903-1d3954b5(transitive)
Updated@alcalzone/jsonl-db@^2.2.0
Updated@iobroker/db-objects-file@4.0.0-alpha.30-20211220-ce617590
Updated@iobroker/db-objects-redis@4.0.0-alpha.30-20211220-ce617590