@iobroker/db-objects-file 7.2.2 → 7.2.3-alpha.1-20260621-61726ea22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/lib/objects/objectsInMemFileDB.d.ts +139 -6
- package/build/cjs/lib/objects/objectsInMemFileDB.js +141 -28
- package/build/cjs/lib/objects/objectsInMemFileDB.js.map +2 -2
- package/build/cjs/lib/objects/objectsInMemServerClass.d.ts +17 -0
- package/build/cjs/lib/objects/objectsInMemServerClass.js +20 -0
- package/build/cjs/lib/objects/objectsInMemServerClass.js.map +2 -2
- package/build/cjs/lib/objects/objectsInMemServerRedis.d.ts +2 -8
- package/build/cjs/lib/objects/objectsInMemServerRedis.js +2 -2
- package/build/cjs/lib/objects/objectsInMemServerRedis.js.map +1 -1
- package/build/esm/lib/objects/objectsInMemFileDB.d.ts +139 -6
- package/build/esm/lib/objects/objectsInMemFileDB.d.ts.map +1 -1
- package/build/esm/lib/objects/objectsInMemFileDB.js +142 -29
- package/build/esm/lib/objects/objectsInMemFileDB.js.map +1 -1
- package/build/esm/lib/objects/objectsInMemServerClass.d.ts +17 -0
- package/build/esm/lib/objects/objectsInMemServerClass.d.ts.map +1 -1
- package/build/esm/lib/objects/objectsInMemServerClass.js +23 -0
- package/build/esm/lib/objects/objectsInMemServerClass.js.map +1 -1
- package/build/esm/lib/objects/objectsInMemServerRedis.d.ts +2 -8
- package/build/esm/lib/objects/objectsInMemServerRedis.d.ts.map +1 -1
- package/build/esm/lib/objects/objectsInMemServerRedis.js +2 -2
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/objects/objectsInMemServerRedis.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * Objects DB in memory - Server with Redis protocol\n *\n * Copyright 2013-2024 bluefox <dogafox@gmail.com>\n *\n * MIT License\n *\n */\n\nimport net from 'node:net';\nimport fs from 'fs-extra';\nimport path from 'node:path';\nimport crypto from 'node:crypto';\nimport { objectsUtils as utils } from '@iobroker/db-objects-redis';\nimport { tools } from '@iobroker/db-base';\nimport { getLocalAddress } from '@iobroker/js-controller-common-db/tools';\nimport { EXIT_CODES } from '@iobroker/js-controller-common-db';\n\nimport { RedisHandler } from '@iobroker/db-base';\nimport { ObjectsInMemoryFileDB } from './objectsInMemFileDB.js';\n\n// settings = {\n// change: function (id, state) {},\n// connected: function (nameOfServer) {},\n// logger: {\n// silly: function (msg) {},\n// debug: function (msg) {},\n// info: function (msg) {},\n// warn: function (msg) {},\n// error: function (msg) {}\n// },\n// connection: {\n// dataDir: 'relative path'\n// },\n// auth: null, //unused\n// secure: true/false,\n// certificates: as required by createServer\n// port: 9001,\n// host: localhost\n// };\n//\n\n/**\n * This class inherits statesInMemoryFileDB class and adds redis communication layer\n * to access the methods via redis protocol\n */\nexport class ObjectsInMemoryServer extends ObjectsInMemoryFileDB {\n /**\n * Constructor\n *\n * @param settings State and InMem-DB settings\n */\n constructor(settings) {\n super(settings);\n\n this.serverConnections = {};\n this.namespaceObjects = `${\n this.settings.redisNamespace || (settings.connection && settings.connection.redisNamespace) || 'cfg'\n }.`;\n this.namespaceFile = `${this.namespaceObjects}f.`;\n this.namespaceObj = `${this.namespaceObjects}o.`;\n this.namespaceSet = `${this.namespaceObjects}s.`;\n this.namespaceSetLen = this.namespaceSet.length;\n\n // this.namespaceObjectsLen = this.namespaceObjects.length;\n this.namespaceFileLen = this.namespaceFile.length;\n this.namespaceObjLen = this.namespaceObj.length;\n this.namespaceMeta = `${this.settings.namespaceMeta || 'meta'}.`;\n this.namespaceMetaLen = this.namespaceMeta.length;\n\n this.knownScripts = {};\n\n this.normalizeFileRegex1 = new RegExp('^(.*)\\\\$%\\\\$(.*)\\\\$%\\\\$(meta|data)$');\n this.normalizeFileRegex2 = new RegExp('^(.*)\\\\$%\\\\$(.*)\\\\/?\\\\*$');\n\n this.open()\n .then(() => {\n return this._initRedisServer(this.settings.connection);\n })\n .then(() => {\n this.log.debug(\n `${this.namespace} ${settings.secure ? 'Secure ' : ''} Redis inMem-objects listening on port ${\n this.settings.connection.port || 9001\n }`,\n );\n\n if (typeof this.settings.connected === 'function') {\n setImmediate(() => this.settings.connected());\n }\n })\n .catch(e => {\n this.log.error(\n `${this.namespace} Cannot start inMem-objects on port ${this.settings.connection.port || 9001}: ${e.message}`,\n );\n process.exit(EXIT_CODES.NO_CONNECTION_TO_OBJ_DB);\n });\n }\n\n /**\n * Separate Namespace from ID and return both\n *\n * @param idWithNamespace ID or Array of IDs containing a redis namespace and the real ID\n * @returns Object with namespace and the\n * ID/Array of IDs without the namespace\n */\n _normalizeId(idWithNamespace) {\n let ns = this.namespaceObjects;\n let id = null;\n let name = '';\n let isMeta;\n if (Array.isArray(idWithNamespace)) {\n const ids = [];\n idWithNamespace.forEach(el => {\n const { id, namespace } = this._normalizeId(el);\n ids.push(id);\n ns = namespace; // we ignore the pot. case from arrays with different namespaces\n });\n id = ids;\n } else if (typeof idWithNamespace === 'string') {\n id = idWithNamespace;\n if (idWithNamespace.startsWith(this.namespaceObjects)) {\n let idx = -1;\n if (idWithNamespace.startsWith(this.namespaceObj)) {\n idx = this.namespaceObjLen;\n } else if (idWithNamespace.startsWith(this.namespaceFile)) {\n idx = this.namespaceFileLen;\n } else if (idWithNamespace.startsWith(this.namespaceSet)) {\n idx = this.namespaceSetLen;\n }\n\n if (idx !== -1) {\n ns = idWithNamespace.substr(0, idx);\n id = idWithNamespace.substr(idx);\n }\n if (ns === this.namespaceFile) {\n let fileIdDetails = id.match(this.normalizeFileRegex1);\n if (fileIdDetails) {\n id = fileIdDetails[1];\n name = fileIdDetails[2] || '';\n isMeta = fileIdDetails[3] === 'meta';\n } else {\n fileIdDetails = id.match(this.normalizeFileRegex2);\n if (fileIdDetails) {\n id = fileIdDetails[1];\n name = fileIdDetails[2] || '';\n isMeta = undefined;\n } else {\n name = '';\n isMeta = undefined;\n }\n }\n }\n } else if (idWithNamespace.startsWith(this.namespaceMeta)) {\n const idx = this.namespaceMetaLen;\n if (idx !== -1) {\n ns = idWithNamespace.substr(0, idx);\n id = idWithNamespace.substr(idx);\n }\n }\n }\n return { id, namespace: ns, name, isMeta };\n }\n\n /**\n * Publish a subscribed value to one of the redis connections in redis format\n *\n * @param client Instance of RedisHandler\n * @param type Type of subscribed key\n * @param id Subscribed ID\n * @param obj Object to publish\n * @returns Publish counter 0 or 1 depending on if send out or not\n */\n publishToClients(client, type, id, obj) {\n if (!client._subscribe || !client._subscribe[type]) {\n return 0;\n }\n const s = client._subscribe[type];\n\n const found = s.find(sub => sub.regex.test(id));\n\n if (found) {\n if (type === 'meta') {\n this.log.silly(`${this.namespace} Redis Publish Meta ${id}=${obj}`);\n const sendPattern = this.namespaceMeta + found.pattern;\n const sendId = this.namespaceMeta + id;\n client.sendArray(null, ['pmessage', sendPattern, sendId, obj]);\n } else if (type === 'files') {\n const objString = JSON.stringify(obj);\n this.log.silly(`${this.namespace} Redis Publish File ${id}=${objString}`);\n const sendPattern = this.namespaceFile + found.pattern;\n const sendId = this.namespaceFile + id;\n client.sendArray(null, ['pmessage', sendPattern, sendId, objString]);\n } else {\n const objString = JSON.stringify(obj);\n this.log.silly(`${this.namespace} Redis Publish Object ${id}=${objString}`);\n const sendPattern = (type === 'objects' ? '' : this.namespaceObjects) + found.pattern;\n const sendId = (type === 'objects' ? this.namespaceObj : this.namespaceObjects) + id;\n client.sendArray(null, ['pmessage', sendPattern, sendId, objString]);\n }\n return 1;\n }\n return 0;\n }\n\n /**\n * Generate ID for a File\n *\n * @param id ID of the File\n * @param name Name of the file\n * @param isMeta generate a META ID or a Data ID?\n * @returns File-ID\n */\n getFileId(id, name, isMeta) {\n // e.g. ekey.admin and admin/ekey.png\n if (id.endsWith('.admin')) {\n if (name.startsWith('admin/')) {\n name = name.replace(/^admin\\//, '');\n } else if (name.match(/^iobroker.[-\\d\\w]\\/admin\\//i)) {\n // e.g. ekey.admin and iobroker.ekey/admin/ekey.png\n name = name.replace(/^iobroker.[-\\d\\w]\\/admin\\//i, '');\n }\n }\n\n return `${this.namespaceFile + id}$%$${name}${isMeta !== undefined ? (isMeta ? '$%$meta' : '$%$data') : ''}`;\n }\n\n /**\n * Register all event listeners for Handler and implement the relevant logic\n *\n * @param handler RedisHandler instance\n */\n _socketEvents(handler) {\n let connectionName = null;\n let namespaceLog = this.namespace;\n\n // Handle Redis \"INFO\" request\n handler.on('info', (_data, responseId) => {\n let infoString = '# Server\\r\\n';\n infoString += 'redis_version:3.0.0-iobroker\\r\\n';\n infoString += '# Clients\\r\\n';\n infoString += '# Memory\\r\\n';\n infoString += '# Persistence\\r\\n';\n infoString += '# Stats\\r\\n';\n infoString += '# Replication\\r\\n';\n infoString += '# CPU\\r\\n';\n infoString += '# Cluster\\r\\n';\n infoString += '# Keyspace\\r\\n';\n infoString += `db0:keys=${Object.keys(this.dataset).length},expires=0,avg_ttl=98633637897`;\n handler.sendBulk(responseId, infoString);\n });\n\n // Handle Redis \"QUIT\" request\n handler.on('quit', (_data, responseId) => {\n this.log.silly(`${namespaceLog} Redis QUIT received, close connection`);\n handler.sendString(responseId, 'OK');\n handler.close();\n });\n\n // Handle Redis \"SCRIPT\" request\n handler.on('script', (data, responseId) => {\n data[0] = data[0].toLowerCase();\n if (data[0] === 'exists') {\n data.shift();\n const scripts = [];\n data.forEach(checksum => scripts.push(this.knownScripts[checksum] ? 1 : 0));\n handler.sendArray(responseId, scripts);\n } else if (data[0] === 'load') {\n const shasum = crypto.createHash('sha1');\n const buf = Buffer.from(data[1]);\n shasum.update(buf);\n const scriptChecksum = shasum.digest('hex');\n\n const scriptDesign = data[1].match(/^-- design: ([a-z0-9A-Z-.]+)\\s/m);\n const scriptFunc = data[1].match(/^-- func: (.+)$/m);\n if (scriptDesign && scriptDesign[1]) {\n const design = scriptDesign[1];\n let search = null;\n const scriptSearch = data[1].match(/^-- search: ([a-z0-9A-Z-.]*)\\s/m);\n if (scriptSearch && scriptSearch[1]) {\n search = scriptSearch[1];\n }\n\n this.knownScripts[scriptChecksum] = { design: design, search: search };\n if (this.settings.connection.enhancedLogging) {\n this.log.silly(\n `${namespaceLog} Register View LUA Script: ${scriptChecksum} = ${JSON.stringify(\n this.knownScripts[scriptChecksum],\n )}`,\n );\n }\n handler.sendBulk(responseId, scriptChecksum);\n } else if (scriptFunc && scriptFunc[1]) {\n this.knownScripts[scriptChecksum] = { func: scriptFunc[1] };\n if (this.settings.connection.enhancedLogging) {\n this.log.silly(\n `${namespaceLog} Register Func LUA Script: ${scriptChecksum} = ${JSON.stringify(\n this.knownScripts[scriptChecksum],\n )}`,\n );\n }\n handler.sendBulk(responseId, scriptChecksum);\n } else if (data[1].includes('-- REDLOCK SCRIPT')) {\n // redlock scripts are currently not needed for Simulator\n this.knownScripts[scriptChecksum] = { redlock: true };\n if (this.settings.connection.enhancedLogging) {\n this.log.silly(\n `${namespaceLog} Register Func LUA Script: ${scriptChecksum} = ${JSON.stringify(\n this.knownScripts[scriptChecksum],\n )}`,\n );\n }\n handler.sendBulk(responseId, scriptChecksum);\n } else {\n handler.sendError(responseId, new Error(`Unknown LUA script ${data[1]}`));\n }\n } else {\n handler.sendError(responseId, new Error(`Unsupported Script command ${data[0]}`));\n }\n });\n\n // Handle Redis \"EVALSHA\" request\n handler.on('evalsha', (data, responseId) => {\n if (!this.knownScripts[data[0]]) {\n return void handler.sendError(responseId, new Error(`Unknown Script ${data[0]}`));\n }\n if (this.knownScripts[data[0]].design) {\n const scriptDesign = this.knownScripts[data[0]].design;\n if (typeof data[2] === 'string' && data[2].startsWith(this.namespaceObj) && data.length > 4) {\n let scriptSearch = this.knownScripts[data[0]].search;\n if (scriptDesign === 'system' && !scriptSearch && data[5]) {\n scriptSearch = data[5];\n }\n if (!scriptSearch) {\n scriptSearch = 'state';\n }\n if (this.settings.connection.enhancedLogging) {\n this.log.silly(\n `${namespaceLog} Script transformed into getObjectView: design=${scriptDesign}, search=${scriptSearch}`,\n );\n }\n let objs;\n try {\n objs = this._getObjectView(scriptDesign, scriptSearch, {\n startkey: data[3],\n endkey: data[4],\n include_docs: true,\n });\n } catch (err) {\n return void handler.sendError(\n responseId,\n new Error(`_getObjectView Error for ${scriptDesign}/${scriptSearch}: ${err.message}`),\n );\n }\n\n const res = objs.rows.map(obj => JSON.stringify(this.dataset[obj.value._id || obj.id]));\n handler.sendArray(responseId, res);\n }\n } else if (this.knownScripts[data[0]].func && data.length > 4) {\n const scriptFunc = { map: this.knownScripts[data[0]].func.replace('%1', data[5]) };\n if (this.settings.connection.enhancedLogging) {\n this.log.silly(`${namespaceLog} Script transformed into _applyView: func=${scriptFunc.map}`);\n }\n const objs = this._applyView(scriptFunc, {\n startkey: data[3],\n endkey: data[4],\n include_docs: true,\n });\n const res = objs.rows.map(obj => JSON.stringify(this.dataset[obj.value._id || obj.id]));\n\n return void handler.sendArray(responseId, res);\n } else if (this.knownScripts[data[0]].redlock) {\n // just return a dummy\n return void handler.sendArray(responseId, [0]);\n } else {\n handler.sendError(responseId, new Error(`Unknown LUA script eval call ${JSON.stringify(data)}`));\n }\n });\n\n // Handle Redis \"PUBLISH\" request\n handler.on('publish', (data, responseId) => {\n const { id, namespace } = this._normalizeId(data[0]);\n\n if (\n namespace === this.namespaceObj ||\n namespace === this.namespaceMeta ||\n namespace === this.namespaceFile\n ) {\n // a \"set\" always comes afterwards, so do not publish\n return void handler.sendInteger(responseId, 0); // do not publish for now\n }\n const publishCount = this.publishAll(namespace.substr(0, namespace.length - 1), id, JSON.parse(data[1]));\n handler.sendInteger(responseId, publishCount);\n });\n\n // Handle Redis \"MGET\" requests\n handler.on('mget', (data, responseId) => {\n if (!data || !data.length) {\n return void handler.sendArray(responseId, []);\n }\n const { namespace, isMeta } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n const keys = [];\n data.forEach(dataId => {\n const { id, namespace } = this._normalizeId(dataId);\n if (namespace !== this.namespaceObj) {\n keys.push(null);\n this.log.warn(\n `${namespaceLog} Got MGET request for non Object-ID in Objects-ID chunk for ${namespace} / ${dataId}`,\n );\n return;\n }\n keys.push(id);\n });\n let result;\n try {\n result = this._getObjects(keys);\n } catch (err) {\n return void handler.sendError(responseId, new Error(`ERROR _getObjects: ${err.message}`));\n }\n result = result.map(el => (el ? JSON.stringify(el) : null));\n handler.sendArray(responseId, result);\n } else if (namespace === this.namespaceFile) {\n // Handle request for Meta data for files\n if (isMeta) {\n const response = [];\n data.forEach(dataId => {\n const { id, namespace, name } = this._normalizeId(dataId);\n if (namespace !== this.namespaceFile) {\n response.push(null);\n this.log.warn(\n `${namespaceLog} Got MGET request for non File ID in File-ID chunk for ${dataId}`,\n );\n return;\n }\n this._loadFileSettings(id);\n if (!this.fileOptions[id] || !this.fileOptions[id][name]) {\n response.push(null);\n return;\n }\n const obj = this._clone(this.fileOptions[id][name]);\n try {\n obj.stats = fs.statSync(path.join(this.objectsDir, id, name));\n } catch (err) {\n if (!name.endsWith('/_data.json')) {\n this.log.warn(\n `${namespaceLog} Got MGET request for non existing file ${dataId}, err: ${err.message}`,\n );\n }\n response.push(null);\n return;\n }\n response.push(JSON.stringify(obj));\n });\n handler.sendArray(responseId, response);\n } else {\n // Handle request for File data\n handler.sendError(responseId, new Error('MGET-UNSUPPORTED for file data'));\n }\n } else {\n handler.sendError(\n responseId,\n new Error(`MGET-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n // Handle Redis \"GET\" requests\n handler.on('get', (data, responseId) => {\n const { id, namespace, name, isMeta } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n const result = this._getObject(id);\n if (!result) {\n handler.sendNull(responseId);\n } else {\n handler.sendBulk(responseId, JSON.stringify(result));\n }\n } else if (namespace === this.namespaceFile) {\n // Handle request for Meta data for files\n if (isMeta) {\n let stats;\n try {\n stats = fs.statSync(path.join(this.objectsDir, id, name));\n } catch {\n return void handler.sendNull(responseId);\n }\n if (stats.isDirectory()) {\n return void handler.sendBulk(\n responseId,\n JSON.stringify({\n file: name,\n stats: {},\n isDir: true,\n }),\n );\n }\n this._loadFileSettings(id);\n if (!this.fileOptions[id] || !this.fileOptions[id][name]) {\n return void handler.sendNull(responseId);\n }\n\n let obj = this._clone(this.fileOptions[id][name]);\n if (typeof obj !== 'object') {\n obj = {\n mimeType: obj,\n acl: {\n owner:\n (this.defaultNewAcl && this.defaultNewAcl.owner) || utils.CONSTS.SYSTEM_ADMIN_USER,\n ownerGroup:\n (this.defaultNewAcl && this.defaultNewAcl.ownerGroup) ||\n utils.CONSTS.SYSTEM_ADMIN_GROUP,\n permissions:\n (this.defaultNewAcl && this.defaultNewAcl.file.permissions) ||\n utils.CONSTS.ACCESS_USER_ALL |\n utils.CONSTS.ACCESS_GROUP_ALL |\n utils.CONSTS.ACCESS_EVERY_ALL, // 777\n },\n };\n }\n obj.stats = stats;\n handler.sendBulk(responseId, JSON.stringify(obj));\n } else {\n // Handle request for File data\n let data;\n try {\n data = this._readFile(id, name);\n } catch {\n return void handler.sendNull(responseId);\n }\n if (data.fileContent === undefined || data.fileContent === null) {\n return void handler.sendNull(responseId);\n }\n let fileData = data.fileContent;\n if (!Buffer.isBuffer(fileData) && tools.isObject(fileData)) {\n // if its an invalid object, stringify it and log warning\n fileData = JSON.stringify(fileData);\n this.log.warn(\n `${namespaceLog} Data of \"${id}/${name}\" has invalid structure at file data request: ${fileData}`,\n );\n }\n handler.sendBufBulk(responseId, Buffer.from(fileData));\n }\n } else if (namespace === this.namespaceMeta) {\n // special handling for the primaryHost\n if (id === 'objects.primaryHost') {\n // we are the server -> we are primary\n handler.sendString(this.settings.hostname);\n } else {\n const result = this.getMeta(id);\n if (result === undefined || result === null) {\n handler.sendNull(responseId);\n } else {\n handler.sendBulk(responseId, result);\n }\n }\n } else {\n handler.sendError(\n responseId,\n new Error(`GET-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n // Handle Redis \"SET\" requests\n handler.on('set', (data, responseId) => {\n const { id, namespace, name, isMeta } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n try {\n const obj = JSON.parse(data[1].toString('utf-8'));\n this._setObjectDirect(id, obj);\n } catch (err) {\n return void handler.sendError(responseId, new Error(`ERROR setObject id=${id}: ${err.message}`));\n }\n handler.sendString(responseId, 'OK');\n } else if (namespace === this.namespaceFile) {\n // Handle request to set meta-data, we ignore it because\n // will be set when data are written\n if (isMeta) {\n this._loadFileSettings(id);\n\n try {\n fs.ensureDirSync(path.join(this.objectsDir, id, path.dirname(name)));\n\n // only set if the meta-object is already/still existing\n if (this.fileOptions[id]) {\n this.fileOptions[id][name] = JSON.parse(data[1].toString('utf-8'));\n fs.writeFileSync(\n path.join(this.objectsDir, id, '_data.json'),\n JSON.stringify(this.fileOptions[id]),\n );\n }\n } catch (err) {\n return void handler.sendError(\n responseId,\n new Error(`ERROR writeFile-Meta id=${id}: ${err.message}`),\n );\n }\n handler.sendString(responseId, 'OK');\n } else {\n // Handle request to write the file\n try {\n this._writeFile(id, name, data[1]);\n } catch (err) {\n return void handler.sendError(\n responseId,\n new Error(`ERROR writeFile id=${id}: ${err.message}`),\n );\n }\n handler.sendString(responseId, 'OK');\n }\n } else if (namespace === this.namespaceMeta) {\n this.setMeta(id, data[1].toString('utf-8'));\n handler.sendString(responseId, 'OK');\n } else {\n handler.sendError(\n responseId,\n new Error(`SET-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n // Handle Redis \"RENAME\" requests\n handler.on('rename', (data, responseId) => {\n const oldDetails = this._normalizeId(data[0]);\n const newDetails = this._normalizeId(data[1]);\n\n if (oldDetails.namespace === this.namespaceFile) {\n if (oldDetails.id !== newDetails.id) {\n return void handler.sendError(\n responseId,\n new Error('ERROR renameObject: id needs to stay the same'),\n );\n }\n\n // Handle request for Meta data for files\n if (oldDetails.isMeta) {\n handler.sendString(responseId, 'OK');\n } else {\n // Handle request for File data\n try {\n this._rename(oldDetails.id, oldDetails.name, newDetails.name);\n } catch {\n return void handler.sendNull(responseId);\n }\n handler.sendString(responseId, 'OK');\n }\n } else {\n handler.sendError(\n responseId,\n new Error(`RENAME-UNSUPPORTED for namespace ${oldDetails.namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n // Handle Redis \"DEL\" request for state and session namespace\n handler.on('del', (data, responseId) => {\n const { id, namespace, name, isMeta } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n try {\n this._delObject(id);\n } catch (err) {\n return void handler.sendError(responseId, err);\n }\n handler.sendInteger(responseId, 1);\n } else if (namespace === this.namespaceFile) {\n // Handle request to delete meta-data, we ignore it because\n // will be removed when data are deleted\n if (isMeta) {\n handler.sendString(responseId, 'OK');\n } else {\n // Handle request to remove the file\n try {\n this._unlink(id, name);\n } catch (err) {\n return void handler.sendError(responseId, err);\n }\n handler.sendString(responseId, 'OK');\n }\n } else {\n handler.sendError(\n responseId,\n new Error(`DEL-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n handler.on('exists', (data, responseId) => {\n if (!data || !data.length) {\n return void handler.sendInteger(responseId, 0);\n }\n\n // Note: we only simulate single key existence check\n const { id, namespace, name } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n let exists;\n try {\n exists = this._objectExists(id);\n } catch (e) {\n return void handler.sendError(responseId, e);\n }\n handler.sendInteger(responseId, exists ? 1 : 0);\n } else if (namespace === this.namespaceFile) {\n let exists;\n try {\n exists = this._fileExists(id, name);\n } catch (e) {\n return void handler.sendError(responseId, e);\n }\n handler.sendInteger(responseId, exists ? 1 : 0);\n } else if (namespace === this.namespaceSet) {\n // we are not using sets in simulator, so just say it exists\n return void handler.sendInteger(responseId, 1);\n } else {\n handler.sendError(responseId, new Error(`EXISTS-UNSUPPORTED for namespace ${namespace}`));\n }\n });\n\n // handle Redis \"SCAN\" request for objects namespace\n handler.on('scan', (data, responseId) => {\n if (!data || data.length < 3) {\n return void handler.sendArray(responseId, ['0', []]);\n }\n\n return this._handleScanOrKeys(handler, data[2], responseId, true);\n });\n\n // Handle Redis \"KEYS\" request for state namespace\n handler.on('keys', (data, responseId) => {\n if (!data || !data.length) {\n return void handler.sendArray(responseId, []);\n }\n\n return this._handleScanOrKeys(handler, data[0], responseId);\n });\n\n // commands for redis SETS, just dummies\n handler.on('sadd', (data, responseId) => {\n return void handler.sendInteger(responseId, 1);\n });\n\n handler.on('srem', (data, responseId) => {\n return void handler.sendInteger(responseId, 1);\n });\n\n handler.on('eval', (data, responseId) => {\n return void handler.sendNull(responseId);\n });\n\n handler.on('sscan', (data, responseId) => {\n // for file DB it does the same as scan but data looks different\n if (!data || data.length < 4) {\n return void handler.sendArray(responseId, ['0', []]);\n }\n\n return this._handleScanOrKeys(handler, data[3], responseId, true);\n });\n\n // Handle Redis \"PSUBSCRIBE\" request for state, log and session namespace\n handler.on('psubscribe', (data, responseId) => {\n const { id, namespace, name } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n this._subscribeConfigForClient(handler, id);\n handler.sendArray(responseId, ['psubscribe', data[0], 1]);\n } else if (namespace === this.namespaceMeta) {\n this._subscribeMeta(handler, id);\n handler.sendArray(responseId, ['psubscribe', data[0], 1]);\n } else if (namespace === this.namespaceFile) {\n this._subscribeFileForClient(handler, id, name);\n handler.sendArray(responseId, ['psubscribe', data[0], 1]);\n } else {\n handler.sendError(\n responseId,\n new Error(`PSUBSCRIBE-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n // Handle Redis \"UNSUBSCRIBE\" request for state, log and session namespace\n handler.on('punsubscribe', (data, responseId) => {\n const { id, namespace, name } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n this._unsubscribeConfigForClient(handler, id);\n handler.sendArray(responseId, ['punsubscribe', data[0], 1]);\n } else if (namespace === this.namespaceFile) {\n this._unsubscribeFileForClient(handler, id, name);\n handler.sendArray(responseId, ['punsubscribe', data[0], 1]);\n } else {\n handler.sendError(\n responseId,\n new Error(`PUNSUBSCRIBE-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n // Handle Redis \"SUBSCRIBE\" ... currently mainly ignored\n handler.on('subscribe', (data, responseId) => {\n if (data[0].startsWith('__keyevent@')) {\n // we ignore these type of events because we publish expires anyway directly\n handler.sendArray(responseId, ['subscribe', data[0], 1]);\n } else {\n handler.sendError(responseId, new Error(`SUBSCRIBE-UNSUPPORTED for ${data[0]}`));\n }\n });\n\n // Handle Redis \"CONFIG\" ... currently mainly ignored\n handler.on('config', (data, responseId) => {\n const command = typeof data[0] === 'string' ? data[0].toLowerCase() : data[0].toString().toLowerCase();\n if (command === 'set' && data[1] === 'notify-keyspace-events') {\n // we ignore these type of commands for now, should only be to subscribe to keyspace events\n handler.sendString(responseId, 'OK');\n } else if (command === 'set' && data[1] === 'lua-time-limit') {\n // we ignore these type of commands for now, irrelevant\n handler.sendString(responseId, 'OK');\n } else {\n handler.sendError(responseId, new Error(`CONFIG-UNSUPPORTED for ${JSON.stringify(data)}`));\n }\n });\n\n // handle client SETNAME/GETNAME\n handler.on('client', (data, responseId) => {\n if (data[0] === 'setname' && typeof data[1] === 'string') {\n if (data[1] === '') {\n // on empty string redis sets null again and sends 'OK'\n connectionName = null;\n } else {\n connectionName = data[1];\n namespaceLog = connectionName;\n }\n handler.sendString(responseId, 'OK');\n } else if (data[0] === 'getname') {\n if (typeof connectionName === 'string' && connectionName !== '') {\n handler.sendString(responseId, connectionName);\n } else {\n // redis sends null if no name defined\n handler.sendNull(responseId);\n }\n } else {\n handler.sendError(responseId, new Error(`CLIENT-UNSUPPORTED for ${JSON.stringify(data)}`));\n }\n });\n\n handler.on('error', err => this.log.warn(`${namespaceLog} Redis objects: ${err}`));\n }\n\n /**\n * Return connected RedisHandlers/Connections\n *\n * @returns\n */\n getClients() {\n return this.serverConnections;\n }\n\n /**\n * Destructor of the class. Called by shutting down.\n */\n async destroy() {\n if (this.server) {\n Object.keys(this.serverConnections).forEach(s => {\n this.serverConnections[s].close();\n delete this.serverConnections[s];\n });\n\n await new Promise(resolve => {\n if (!this.server) {\n return void resolve();\n }\n try {\n this.server.close(() => resolve());\n } catch (e) {\n console.log(e.message);\n resolve();\n }\n });\n }\n\n await super.destroy();\n }\n\n /**\n * Get keys matching pattern and send it to given responseId, for \"SCAN\" and \"KEYS\" - Objects and files supported\n *\n * @param handler RedisHandler instance\n * @param pattern - pattern without namespace prefix\n * @param responseId - Id where response will be sent to\n * @param isScan - if used by \"SCAN\" this flag should be true\n */\n _handleScanOrKeys(handler, pattern, responseId, isScan = false) {\n const { id, namespace, name, isMeta } = this._normalizeId(pattern);\n\n let response = [];\n if (namespace === this.namespaceObj || namespace === this.namespaceObjects) {\n try {\n response = this._getKeys(id).map(val => this.namespaceObj + val);\n } catch (e) {\n return void handler.sendError(responseId, e);\n }\n\n // if scan, we send the cursor as first argument\n if (namespace !== this.namespaceObjects) {\n // When it was not the full DB namespace send out response\n return void handler.sendArray(responseId, isScan ? ['0', response] : response);\n }\n }\n if (namespace === this.namespaceFile || namespace === this.namespaceObjects) {\n // Handle request to get meta data keys\n if (isMeta === undefined) {\n let res;\n try {\n res = this._readDir(id, name);\n if (!res || !res.length) {\n res = [\n {\n file: '_data.json',\n stats: {},\n isDir: false,\n virtualFile: true,\n notExists: true,\n },\n ];\n }\n } catch (e) {\n if (!e.message.endsWith(utils.ERRORS.ERROR_NOT_FOUND)) {\n return void handler.sendError(responseId, new Error(`ERROR readDir id=${id}: ${e.message}`));\n }\n res = [];\n }\n let baseName = name || '';\n if (baseName.length && !baseName.endsWith('/')) {\n baseName += '/';\n }\n res.forEach(arr => {\n let entryId = id;\n if (arr.isDir) {\n if (entryId === '' || entryId === '*') {\n entryId = arr.file;\n arr.file = '_data.json'; // We return a \"virtual file\" to mark the directory as existing\n } else {\n arr.file += '/_data.json'; // We return a \"virtual file\" to mark the directory as existing\n }\n }\n // We need to simulate the Meta data here, so return both\n response.push(this.getFileId(entryId, baseName + arr.file, true));\n response.push(this.getFileId(entryId, baseName + arr.file, false));\n });\n handler.sendArray(responseId, isScan ? ['0', response] : response); // send out file or full db response\n } else {\n // such a request should never happen\n handler.sendArray(responseId, isScan ? ['0', []] : []); // send out file or full db response\n }\n } else if (namespace === this.namespaceSet) {\n handler.sendArray(responseId, isScan ? ['0', []] : []); // send out empty array, we have no sets\n } else {\n handler.sendError(\n responseId,\n new Error(`${isScan ? 'SCAN' : 'KEYS'}-UNSUPPORTED for namespace ${namespace}: Pattern=${pattern}`),\n );\n }\n }\n\n /**\n * Initialize RedisHandler for a new network connection\n *\n * @param socket Network socket\n */\n _initSocket(socket) {\n if (this.settings.connection.enhancedLogging) {\n this.log.silly(`${this.namespace} Handling new Redis Objects connection`);\n }\n const options = {\n log: this.log,\n logScope: `${this.settings.namespace || ''} Objects`,\n handleAsBuffers: true,\n enhancedLogging: this.settings.connection.enhancedLogging,\n };\n const handler = new RedisHandler(socket, options);\n this._socketEvents(handler);\n\n this.serverConnections[`${socket.remoteAddress}:${socket.remotePort}`] = handler;\n socket.on('close', () => {\n if (this.serverConnections[`${socket.remoteAddress}:${socket.remotePort}`]) {\n delete this.serverConnections[`${socket.remoteAddress}:${socket.remotePort}`];\n }\n });\n }\n\n /**\n * Initialize Redis Server\n *\n * @param settings Settings object\n * @returns\n */\n _initRedisServer(settings) {\n return new Promise((resolve, reject) => {\n if (settings.secure) {\n reject(new Error('Secure Redis unsupported for File-DB'));\n }\n try {\n this.server = net.createServer();\n this.server.on('error', err =>\n this.log.info(\n `${this.namespace} ${settings.secure ? 'Secure ' : ''} Error inMem-objects listening on port ${\n settings.port || 9001\n }: ${err}`,\n ),\n );\n this.server.on('connection', socket => this._initSocket(socket));\n\n this.server.listen(\n settings.port || 9001,\n settings.host === 'localhost' ? getLocalAddress() : settings.host ? settings.host : undefined,\n () => resolve(),\n );\n } catch (err) {\n reject(err);\n }\n });\n }\n}\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * Objects DB in memory - Server with Redis protocol\n *\n * Copyright 2013-2024 bluefox <dogafox@gmail.com>\n *\n * MIT License\n *\n */\n\nimport net from 'node:net';\nimport fs from 'fs-extra';\nimport path from 'node:path';\nimport crypto from 'node:crypto';\nimport { objectsUtils as utils } from '@iobroker/db-objects-redis';\nimport { tools } from '@iobroker/db-base';\nimport { getLocalAddress } from '@iobroker/js-controller-common-db/tools';\nimport { EXIT_CODES } from '@iobroker/js-controller-common-db';\n\nimport { RedisHandler } from '@iobroker/db-base';\nimport { ObjectsInMemoryFileDB } from './objectsInMemFileDB.js';\n\n// settings = {\n// change: function (id, state) {},\n// connected: function (nameOfServer) {},\n// logger: {\n// silly: function (msg) {},\n// debug: function (msg) {},\n// info: function (msg) {},\n// warn: function (msg) {},\n// error: function (msg) {}\n// },\n// connection: {\n// dataDir: 'relative path'\n// },\n// auth: null, //unused\n// secure: true/false,\n// certificates: as required by createServer\n// port: 9001,\n// host: localhost\n// };\n//\n\n/**\n * This class inherits statesInMemoryFileDB class and adds redis communication layer\n * to access the methods via redis protocol\n */\nexport class ObjectsInMemoryServer extends ObjectsInMemoryFileDB {\n /**\n * Constructor\n *\n * @param settings State and InMem-DB settings\n */\n constructor(settings) {\n super(settings);\n\n this.serverConnections = {};\n this.namespaceObjects = `${\n this.settings.redisNamespace || (settings.connection && settings.connection.redisNamespace) || 'cfg'\n }.`;\n this.namespaceFile = `${this.namespaceObjects}f.`;\n this.namespaceObj = `${this.namespaceObjects}o.`;\n this.namespaceSet = `${this.namespaceObjects}s.`;\n this.namespaceSetLen = this.namespaceSet.length;\n\n // this.namespaceObjectsLen = this.namespaceObjects.length;\n this.namespaceFileLen = this.namespaceFile.length;\n this.namespaceObjLen = this.namespaceObj.length;\n this.namespaceMeta = `${this.settings.namespaceMeta || 'meta'}.`;\n this.namespaceMetaLen = this.namespaceMeta.length;\n\n this.knownScripts = {};\n\n this.normalizeFileRegex1 = new RegExp('^(.*)\\\\$%\\\\$(.*)\\\\$%\\\\$(meta|data)$');\n this.normalizeFileRegex2 = new RegExp('^(.*)\\\\$%\\\\$(.*)\\\\/?\\\\*$');\n\n this.open()\n .then(() => {\n return this._initRedisServer(this.settings.connection);\n })\n .then(() => {\n this.log.debug(\n `${this.namespace} ${settings.secure ? 'Secure ' : ''} Redis inMem-objects listening on port ${\n this.settings.connection.port || 9001\n }`,\n );\n\n if (typeof this.settings.connected === 'function') {\n setImmediate(() => this.settings.connected());\n }\n })\n .catch(e => {\n this.log.error(\n `${this.namespace} Cannot start inMem-objects on port ${this.settings.connection.port || 9001}: ${e.message}`,\n );\n process.exit(EXIT_CODES.NO_CONNECTION_TO_OBJ_DB);\n });\n }\n\n /**\n * Separate Namespace from ID and return both\n *\n * @param idWithNamespace ID or Array of IDs containing a redis namespace and the real ID\n * @returns Object with namespace and the\n * ID/Array of IDs without the namespace\n */\n _normalizeId(idWithNamespace) {\n let ns = this.namespaceObjects;\n let id = null;\n let name = '';\n let isMeta;\n if (Array.isArray(idWithNamespace)) {\n const ids = [];\n idWithNamespace.forEach(el => {\n const { id, namespace } = this._normalizeId(el);\n ids.push(id);\n ns = namespace; // we ignore the pot. case from arrays with different namespaces\n });\n id = ids;\n } else if (typeof idWithNamespace === 'string') {\n id = idWithNamespace;\n if (idWithNamespace.startsWith(this.namespaceObjects)) {\n let idx = -1;\n if (idWithNamespace.startsWith(this.namespaceObj)) {\n idx = this.namespaceObjLen;\n } else if (idWithNamespace.startsWith(this.namespaceFile)) {\n idx = this.namespaceFileLen;\n } else if (idWithNamespace.startsWith(this.namespaceSet)) {\n idx = this.namespaceSetLen;\n }\n\n if (idx !== -1) {\n ns = idWithNamespace.substr(0, idx);\n id = idWithNamespace.substr(idx);\n }\n if (ns === this.namespaceFile) {\n let fileIdDetails = id.match(this.normalizeFileRegex1);\n if (fileIdDetails) {\n id = fileIdDetails[1];\n name = fileIdDetails[2] || '';\n isMeta = fileIdDetails[3] === 'meta';\n } else {\n fileIdDetails = id.match(this.normalizeFileRegex2);\n if (fileIdDetails) {\n id = fileIdDetails[1];\n name = fileIdDetails[2] || '';\n isMeta = undefined;\n } else {\n name = '';\n isMeta = undefined;\n }\n }\n }\n } else if (idWithNamespace.startsWith(this.namespaceMeta)) {\n const idx = this.namespaceMetaLen;\n if (idx !== -1) {\n ns = idWithNamespace.substr(0, idx);\n id = idWithNamespace.substr(idx);\n }\n }\n }\n return { id, namespace: ns, name, isMeta };\n }\n\n /**\n * Publish a subscribed value to one of the redis connections in redis format\n *\n * @param client Instance of RedisHandler\n * @param type Type of subscribed key\n * @param id Subscribed ID\n * @param obj Object to publish\n * @returns Publish counter 0 or 1 depending on if send out or not\n */\n publishToClients(client, type, id, obj) {\n if (!client._subscribe || !client._subscribe[type]) {\n return 0;\n }\n const s = client._subscribe[type];\n\n const found = s.find(sub => sub.regex.test(id));\n\n if (found) {\n if (type === 'meta') {\n this.log.silly(`${this.namespace} Redis Publish Meta ${id}=${obj}`);\n const sendPattern = this.namespaceMeta + found.pattern;\n const sendId = this.namespaceMeta + id;\n client.sendArray(null, ['pmessage', sendPattern, sendId, obj]);\n } else if (type === 'files') {\n const objString = JSON.stringify(obj);\n this.log.silly(`${this.namespace} Redis Publish File ${id}=${objString}`);\n const sendPattern = this.namespaceFile + found.pattern;\n const sendId = this.namespaceFile + id;\n client.sendArray(null, ['pmessage', sendPattern, sendId, objString]);\n } else {\n const objString = JSON.stringify(obj);\n this.log.silly(`${this.namespace} Redis Publish Object ${id}=${objString}`);\n const sendPattern = (type === 'objects' ? '' : this.namespaceObjects) + found.pattern;\n const sendId = (type === 'objects' ? this.namespaceObj : this.namespaceObjects) + id;\n client.sendArray(null, ['pmessage', sendPattern, sendId, objString]);\n }\n return 1;\n }\n return 0;\n }\n\n /**\n * Generate ID for a File\n *\n * @param id ID of the File\n * @param name Name of the file\n * @param isMeta generate a META ID or a Data ID?\n * @returns File-ID\n */\n getFileId(id, name, isMeta) {\n // e.g. ekey.admin and admin/ekey.png\n if (id.endsWith('.admin')) {\n if (name.startsWith('admin/')) {\n name = name.replace(/^admin\\//, '');\n } else if (name.match(/^iobroker.[-\\d\\w]\\/admin\\//i)) {\n // e.g. ekey.admin and iobroker.ekey/admin/ekey.png\n name = name.replace(/^iobroker.[-\\d\\w]\\/admin\\//i, '');\n }\n }\n\n return `${this.namespaceFile + id}$%$${name}${isMeta !== undefined ? (isMeta ? '$%$meta' : '$%$data') : ''}`;\n }\n\n /**\n * Register all event listeners for Handler and implement the relevant logic\n *\n * @param handler RedisHandler instance\n */\n _socketEvents(handler) {\n let connectionName = null;\n let namespaceLog = this.namespace;\n\n // Handle Redis \"INFO\" request\n handler.on('info', (_data, responseId) => {\n let infoString = '# Server\\r\\n';\n infoString += 'redis_version:3.0.0-iobroker\\r\\n';\n infoString += '# Clients\\r\\n';\n infoString += '# Memory\\r\\n';\n infoString += '# Persistence\\r\\n';\n infoString += '# Stats\\r\\n';\n infoString += '# Replication\\r\\n';\n infoString += '# CPU\\r\\n';\n infoString += '# Cluster\\r\\n';\n infoString += '# Keyspace\\r\\n';\n infoString += `db0:keys=${Object.keys(this.dataset).length},expires=0,avg_ttl=98633637897`;\n handler.sendBulk(responseId, infoString);\n });\n\n // Handle Redis \"QUIT\" request\n handler.on('quit', (_data, responseId) => {\n this.log.silly(`${namespaceLog} Redis QUIT received, close connection`);\n handler.sendString(responseId, 'OK');\n handler.close();\n });\n\n // Handle Redis \"SCRIPT\" request\n handler.on('script', (data, responseId) => {\n data[0] = data[0].toLowerCase();\n if (data[0] === 'exists') {\n data.shift();\n const scripts = [];\n data.forEach(checksum => scripts.push(this.knownScripts[checksum] ? 1 : 0));\n handler.sendArray(responseId, scripts);\n } else if (data[0] === 'load') {\n const shasum = crypto.createHash('sha1');\n const buf = Buffer.from(data[1]);\n shasum.update(buf);\n const scriptChecksum = shasum.digest('hex');\n\n const scriptDesign = data[1].match(/^-- design: ([a-z0-9A-Z-.]+)\\s/m);\n const scriptFunc = data[1].match(/^-- func: (.+)$/m);\n if (scriptDesign && scriptDesign[1]) {\n const design = scriptDesign[1];\n let search = null;\n const scriptSearch = data[1].match(/^-- search: ([a-z0-9A-Z-.]*)\\s/m);\n if (scriptSearch && scriptSearch[1]) {\n search = scriptSearch[1];\n }\n\n this.knownScripts[scriptChecksum] = { design: design, search: search };\n if (this.settings.connection.enhancedLogging) {\n this.log.silly(\n `${namespaceLog} Register View LUA Script: ${scriptChecksum} = ${JSON.stringify(\n this.knownScripts[scriptChecksum],\n )}`,\n );\n }\n handler.sendBulk(responseId, scriptChecksum);\n } else if (scriptFunc && scriptFunc[1]) {\n this.knownScripts[scriptChecksum] = { func: scriptFunc[1] };\n if (this.settings.connection.enhancedLogging) {\n this.log.silly(\n `${namespaceLog} Register Func LUA Script: ${scriptChecksum} = ${JSON.stringify(\n this.knownScripts[scriptChecksum],\n )}`,\n );\n }\n handler.sendBulk(responseId, scriptChecksum);\n } else if (data[1].includes('-- REDLOCK SCRIPT')) {\n // redlock scripts are currently not needed for Simulator\n this.knownScripts[scriptChecksum] = { redlock: true };\n if (this.settings.connection.enhancedLogging) {\n this.log.silly(\n `${namespaceLog} Register Func LUA Script: ${scriptChecksum} = ${JSON.stringify(\n this.knownScripts[scriptChecksum],\n )}`,\n );\n }\n handler.sendBulk(responseId, scriptChecksum);\n } else {\n handler.sendError(responseId, new Error(`Unknown LUA script ${data[1]}`));\n }\n } else {\n handler.sendError(responseId, new Error(`Unsupported Script command ${data[0]}`));\n }\n });\n\n // Handle Redis \"EVALSHA\" request\n handler.on('evalsha', (data, responseId) => {\n if (!this.knownScripts[data[0]]) {\n return void handler.sendError(responseId, new Error(`Unknown Script ${data[0]}`));\n }\n if (this.knownScripts[data[0]].design) {\n const scriptDesign = this.knownScripts[data[0]].design;\n if (typeof data[2] === 'string' && data[2].startsWith(this.namespaceObj) && data.length > 4) {\n let scriptSearch = this.knownScripts[data[0]].search;\n if (scriptDesign === 'system' && !scriptSearch && data[5]) {\n scriptSearch = data[5];\n }\n if (!scriptSearch) {\n scriptSearch = 'state';\n }\n if (this.settings.connection.enhancedLogging) {\n this.log.silly(\n `${namespaceLog} Script transformed into getObjectView: design=${scriptDesign}, search=${scriptSearch}`,\n );\n }\n let objs;\n try {\n objs = this._getObjectView(scriptDesign, scriptSearch, {\n startkey: data[3],\n endkey: data[4],\n include_docs: true,\n });\n } catch (err) {\n return void handler.sendError(\n responseId,\n new Error(`_getObjectView Error for ${scriptDesign}/${scriptSearch}: ${err.message}`),\n );\n }\n\n const res = objs.rows.map(obj => JSON.stringify(this.dataset[obj.value._id || obj.id]));\n handler.sendArray(responseId, res);\n }\n } else if (this.knownScripts[data[0]].func && data.length > 4) {\n const scriptFunc = { map: this.knownScripts[data[0]].func.replace('%1', data[5]) };\n if (this.settings.connection.enhancedLogging) {\n this.log.silly(`${namespaceLog} Script transformed into _applyView: func=${scriptFunc.map}`);\n }\n const objs = this._applyView(scriptFunc, {\n startkey: data[3],\n endkey: data[4],\n include_docs: true,\n });\n const res = objs.rows.map(obj => JSON.stringify(this.dataset[obj.value._id || obj.id]));\n\n return void handler.sendArray(responseId, res);\n } else if (this.knownScripts[data[0]].redlock) {\n // just return a dummy\n return void handler.sendArray(responseId, [0]);\n } else {\n handler.sendError(responseId, new Error(`Unknown LUA script eval call ${JSON.stringify(data)}`));\n }\n });\n\n // Handle Redis \"PUBLISH\" request\n handler.on('publish', (data, responseId) => {\n const { id, namespace } = this._normalizeId(data[0]);\n\n if (\n namespace === this.namespaceObj ||\n namespace === this.namespaceMeta ||\n namespace === this.namespaceFile\n ) {\n // a \"set\" always comes afterwards, so do not publish\n return void handler.sendInteger(responseId, 0); // do not publish for now\n }\n const publishCount = this.publishAll(namespace.substr(0, namespace.length - 1), id, JSON.parse(data[1]));\n handler.sendInteger(responseId, publishCount);\n });\n\n // Handle Redis \"MGET\" requests\n handler.on('mget', (data, responseId) => {\n if (!data || !data.length) {\n return void handler.sendArray(responseId, []);\n }\n const { namespace, isMeta } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n const keys = [];\n data.forEach(dataId => {\n const { id, namespace } = this._normalizeId(dataId);\n if (namespace !== this.namespaceObj) {\n keys.push(null);\n this.log.warn(\n `${namespaceLog} Got MGET request for non Object-ID in Objects-ID chunk for ${namespace} / ${dataId}`,\n );\n return;\n }\n keys.push(id);\n });\n let result;\n try {\n result = this._getObjects(keys);\n } catch (err) {\n return void handler.sendError(responseId, new Error(`ERROR _getObjects: ${err.message}`));\n }\n result = result.map(el => (el ? JSON.stringify(el) : null));\n handler.sendArray(responseId, result);\n } else if (namespace === this.namespaceFile) {\n // Handle request for Meta data for files\n if (isMeta) {\n const response = [];\n data.forEach(dataId => {\n const { id, namespace, name } = this._normalizeId(dataId);\n if (namespace !== this.namespaceFile) {\n response.push(null);\n this.log.warn(\n `${namespaceLog} Got MGET request for non File ID in File-ID chunk for ${dataId}`,\n );\n return;\n }\n this._loadFileSettings(id);\n if (!this.fileOptions[id] || !this.fileOptions[id][name]) {\n response.push(null);\n return;\n }\n const obj = this._clone(this.fileOptions[id][name]);\n try {\n obj.stats = fs.statSync(path.join(this.objectsDir, id, name));\n } catch (err) {\n if (!name.endsWith('/_data.json')) {\n this.log.warn(\n `${namespaceLog} Got MGET request for non existing file ${dataId}, err: ${err.message}`,\n );\n }\n response.push(null);\n return;\n }\n response.push(JSON.stringify(obj));\n });\n handler.sendArray(responseId, response);\n } else {\n // Handle request for File data\n handler.sendError(responseId, new Error('MGET-UNSUPPORTED for file data'));\n }\n } else {\n handler.sendError(\n responseId,\n new Error(`MGET-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n // Handle Redis \"GET\" requests\n handler.on('get', (data, responseId) => {\n const { id, namespace, name, isMeta } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n const result = this._getObject(id);\n if (!result) {\n handler.sendNull(responseId);\n } else {\n handler.sendBulk(responseId, JSON.stringify(result));\n }\n } else if (namespace === this.namespaceFile) {\n // Handle request for Meta data for files\n if (isMeta) {\n let stats;\n try {\n stats = fs.statSync(path.join(this.objectsDir, id, name));\n } catch {\n return void handler.sendNull(responseId);\n }\n if (stats.isDirectory()) {\n return void handler.sendBulk(\n responseId,\n JSON.stringify({\n file: name,\n stats: {},\n isDir: true,\n }),\n );\n }\n this._loadFileSettings(id);\n if (!this.fileOptions[id] || !this.fileOptions[id][name]) {\n return void handler.sendNull(responseId);\n }\n\n let obj = this._clone(this.fileOptions[id][name]);\n if (typeof obj !== 'object') {\n obj = {\n mimeType: obj,\n acl: {\n owner:\n (this.defaultNewAcl && this.defaultNewAcl.owner) || utils.CONSTS.SYSTEM_ADMIN_USER,\n ownerGroup:\n (this.defaultNewAcl && this.defaultNewAcl.ownerGroup) ||\n utils.CONSTS.SYSTEM_ADMIN_GROUP,\n permissions:\n (this.defaultNewAcl && this.defaultNewAcl.file.permissions) ||\n utils.CONSTS.ACCESS_USER_ALL |\n utils.CONSTS.ACCESS_GROUP_ALL |\n utils.CONSTS.ACCESS_EVERY_ALL, // 777\n },\n };\n }\n obj.stats = stats;\n handler.sendBulk(responseId, JSON.stringify(obj));\n } else {\n // Handle request for File data\n let data;\n try {\n data = this._readFile(id, name);\n } catch {\n return void handler.sendNull(responseId);\n }\n if (data.fileContent === undefined || data.fileContent === null) {\n return void handler.sendNull(responseId);\n }\n let fileData = data.fileContent;\n if (!Buffer.isBuffer(fileData) && tools.isObject(fileData)) {\n // if its an invalid object, stringify it and log warning\n fileData = JSON.stringify(fileData);\n this.log.warn(\n `${namespaceLog} Data of \"${id}/${name}\" has invalid structure at file data request: ${fileData}`,\n );\n }\n handler.sendBufBulk(responseId, Buffer.from(fileData));\n }\n } else if (namespace === this.namespaceMeta) {\n // special handling for the primaryHost\n if (id === 'objects.primaryHost') {\n // we are the server -> we are primary\n handler.sendString(this.settings.hostname);\n } else {\n const result = this.getMeta(id);\n if (result === undefined || result === null) {\n handler.sendNull(responseId);\n } else {\n handler.sendBulk(responseId, result);\n }\n }\n } else {\n handler.sendError(\n responseId,\n new Error(`GET-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n // Handle Redis \"SET\" requests\n handler.on('set', (data, responseId) => {\n const { id, namespace, name, isMeta } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n try {\n const obj = JSON.parse(data[1].toString('utf-8'));\n this._setObjectDirect(id, obj);\n } catch (err) {\n return void handler.sendError(responseId, new Error(`ERROR setObject id=${id}: ${err.message}`));\n }\n handler.sendString(responseId, 'OK');\n } else if (namespace === this.namespaceFile) {\n // Handle request to set meta-data, we ignore it because\n // will be set when data are written\n if (isMeta) {\n this._loadFileSettings(id);\n\n try {\n fs.ensureDirSync(path.join(this.objectsDir, id, path.dirname(name)));\n\n // only set if the meta-object is already/still existing\n if (this.fileOptions[id]) {\n this.fileOptions[id][name] = JSON.parse(data[1].toString('utf-8'));\n fs.writeFileSync(\n path.join(this.objectsDir, id, '_data.json'),\n JSON.stringify(this.fileOptions[id]),\n );\n }\n } catch (err) {\n return void handler.sendError(\n responseId,\n new Error(`ERROR writeFile-Meta id=${id}: ${err.message}`),\n );\n }\n handler.sendString(responseId, 'OK');\n } else {\n // Handle request to write the file\n try {\n this._writeFile(id, name, data[1]);\n } catch (err) {\n return void handler.sendError(\n responseId,\n new Error(`ERROR writeFile id=${id}: ${err.message}`),\n );\n }\n handler.sendString(responseId, 'OK');\n }\n } else if (namespace === this.namespaceMeta) {\n this.setMeta(id, data[1].toString('utf-8'));\n handler.sendString(responseId, 'OK');\n } else {\n handler.sendError(\n responseId,\n new Error(`SET-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n // Handle Redis \"RENAME\" requests\n handler.on('rename', (data, responseId) => {\n const oldDetails = this._normalizeId(data[0]);\n const newDetails = this._normalizeId(data[1]);\n\n if (oldDetails.namespace === this.namespaceFile) {\n if (oldDetails.id !== newDetails.id) {\n return void handler.sendError(\n responseId,\n new Error('ERROR renameObject: id needs to stay the same'),\n );\n }\n\n // Handle request for Meta data for files\n if (oldDetails.isMeta) {\n handler.sendString(responseId, 'OK');\n } else {\n // Handle request for File data\n try {\n this._rename(oldDetails.id, oldDetails.name, newDetails.name);\n } catch {\n return void handler.sendNull(responseId);\n }\n handler.sendString(responseId, 'OK');\n }\n } else {\n handler.sendError(\n responseId,\n new Error(`RENAME-UNSUPPORTED for namespace ${oldDetails.namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n // Handle Redis \"DEL\" request for state and session namespace\n handler.on('del', (data, responseId) => {\n const { id, namespace, name, isMeta } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n try {\n this._delObject(id);\n } catch (err) {\n return void handler.sendError(responseId, err);\n }\n handler.sendInteger(responseId, 1);\n } else if (namespace === this.namespaceFile) {\n // Handle request to delete meta-data, we ignore it because\n // will be removed when data are deleted\n if (isMeta) {\n handler.sendString(responseId, 'OK');\n } else {\n // Handle request to remove the file\n try {\n this._unlink(id, name);\n } catch (err) {\n return void handler.sendError(responseId, err);\n }\n handler.sendString(responseId, 'OK');\n }\n } else {\n handler.sendError(\n responseId,\n new Error(`DEL-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n handler.on('exists', (data, responseId) => {\n if (!data || !data.length) {\n return void handler.sendInteger(responseId, 0);\n }\n\n // Note: we only simulate single key existence check\n const { id, namespace, name } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n let exists;\n try {\n exists = this._objectExists(id);\n } catch (e) {\n return void handler.sendError(responseId, e);\n }\n handler.sendInteger(responseId, exists ? 1 : 0);\n } else if (namespace === this.namespaceFile) {\n let exists;\n try {\n exists = this._fileExists(id, name);\n } catch (e) {\n return void handler.sendError(responseId, e);\n }\n handler.sendInteger(responseId, exists ? 1 : 0);\n } else if (namespace === this.namespaceSet) {\n // we are not using sets in simulator, so just say it exists\n return void handler.sendInteger(responseId, 1);\n } else {\n handler.sendError(responseId, new Error(`EXISTS-UNSUPPORTED for namespace ${namespace}`));\n }\n });\n\n // handle Redis \"SCAN\" request for objects namespace\n handler.on('scan', (data, responseId) => {\n if (!data || data.length < 3) {\n return void handler.sendArray(responseId, ['0', []]);\n }\n\n return this._handleScanOrKeys(handler, data[2], responseId, true);\n });\n\n // Handle Redis \"KEYS\" request for state namespace\n handler.on('keys', (data, responseId) => {\n if (!data || !data.length) {\n return void handler.sendArray(responseId, []);\n }\n\n return this._handleScanOrKeys(handler, data[0], responseId);\n });\n\n // commands for redis SETS, just dummies\n handler.on('sadd', (data, responseId) => {\n return void handler.sendInteger(responseId, 1);\n });\n\n handler.on('srem', (data, responseId) => {\n return void handler.sendInteger(responseId, 1);\n });\n\n handler.on('eval', (data, responseId) => {\n return void handler.sendNull(responseId);\n });\n\n handler.on('sscan', (data, responseId) => {\n // for file DB it does the same as scan but data looks different\n if (!data || data.length < 4) {\n return void handler.sendArray(responseId, ['0', []]);\n }\n\n return this._handleScanOrKeys(handler, data[3], responseId, true);\n });\n\n // Handle Redis \"PSUBSCRIBE\" request for state, log and session namespace\n handler.on('psubscribe', (data, responseId) => {\n const { id, namespace, name } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n this._subscribeConfigForClient(handler, id);\n handler.sendArray(responseId, ['psubscribe', data[0], 1]);\n } else if (namespace === this.namespaceMeta) {\n this._subscribeMeta(handler, id);\n handler.sendArray(responseId, ['psubscribe', data[0], 1]);\n } else if (namespace === this.namespaceFile) {\n this._subscribeFileForClient(handler, id, name);\n handler.sendArray(responseId, ['psubscribe', data[0], 1]);\n } else {\n handler.sendError(\n responseId,\n new Error(`PSUBSCRIBE-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n // Handle Redis \"UNSUBSCRIBE\" request for state, log and session namespace\n handler.on('punsubscribe', (data, responseId) => {\n const { id, namespace, name } = this._normalizeId(data[0]);\n\n if (namespace === this.namespaceObj) {\n this._unsubscribeConfigForClient(handler, id);\n handler.sendArray(responseId, ['punsubscribe', data[0], 1]);\n } else if (namespace === this.namespaceFile) {\n this._unsubscribeFileForClient(handler, id, name);\n handler.sendArray(responseId, ['punsubscribe', data[0], 1]);\n } else {\n handler.sendError(\n responseId,\n new Error(`PUNSUBSCRIBE-UNSUPPORTED for namespace ${namespace}: Data=${JSON.stringify(data)}`),\n );\n }\n });\n\n // Handle Redis \"SUBSCRIBE\" ... currently mainly ignored\n handler.on('subscribe', (data, responseId) => {\n if (data[0].startsWith('__keyevent@')) {\n // we ignore these type of events because we publish expires anyway directly\n handler.sendArray(responseId, ['subscribe', data[0], 1]);\n } else {\n handler.sendError(responseId, new Error(`SUBSCRIBE-UNSUPPORTED for ${data[0]}`));\n }\n });\n\n // Handle Redis \"CONFIG\" ... currently mainly ignored\n handler.on('config', (data, responseId) => {\n const command = typeof data[0] === 'string' ? data[0].toLowerCase() : data[0].toString().toLowerCase();\n if (command === 'set' && data[1] === 'notify-keyspace-events') {\n // we ignore these type of commands for now, should only be to subscribe to keyspace events\n handler.sendString(responseId, 'OK');\n } else if (command === 'set' && data[1] === 'lua-time-limit') {\n // we ignore these type of commands for now, irrelevant\n handler.sendString(responseId, 'OK');\n } else {\n handler.sendError(responseId, new Error(`CONFIG-UNSUPPORTED for ${JSON.stringify(data)}`));\n }\n });\n\n // handle client SETNAME/GETNAME\n handler.on('client', (data, responseId) => {\n if (data[0] === 'setname' && typeof data[1] === 'string') {\n if (data[1] === '') {\n // on empty string redis sets null again and sends 'OK'\n connectionName = null;\n } else {\n connectionName = data[1];\n namespaceLog = connectionName;\n }\n handler.sendString(responseId, 'OK');\n } else if (data[0] === 'getname') {\n if (typeof connectionName === 'string' && connectionName !== '') {\n handler.sendString(responseId, connectionName);\n } else {\n // redis sends null if no name defined\n handler.sendNull(responseId);\n }\n } else {\n handler.sendError(responseId, new Error(`CLIENT-UNSUPPORTED for ${JSON.stringify(data)}`));\n }\n });\n\n handler.on('error', err => this.log.warn(`${namespaceLog} Redis objects: ${err}`));\n }\n\n /**\n * Return connected RedisHandlers/Connections\n *\n * @returns the currently connected RedisHandlers/Connections\n */\n getClients() {\n return this.serverConnections;\n }\n\n /**\n * Destructor of the class. Called by shutting down.\n */\n async destroy() {\n if (this.server) {\n Object.keys(this.serverConnections).forEach(s => {\n this.serverConnections[s].close();\n delete this.serverConnections[s];\n });\n\n await new Promise(resolve => {\n if (!this.server) {\n return void resolve();\n }\n try {\n this.server.close(() => resolve());\n } catch (e) {\n console.log(e.message);\n resolve();\n }\n });\n }\n\n await super.destroy();\n }\n\n /**\n * Get keys matching pattern and send it to given responseId, for \"SCAN\" and \"KEYS\" - Objects and files supported\n *\n * @param handler RedisHandler instance\n * @param pattern - pattern without namespace prefix\n * @param responseId - Id where response will be sent to\n * @param isScan - if used by \"SCAN\" this flag should be true\n */\n _handleScanOrKeys(handler, pattern, responseId, isScan = false) {\n const { id, namespace, name, isMeta } = this._normalizeId(pattern);\n\n let response = [];\n if (namespace === this.namespaceObj || namespace === this.namespaceObjects) {\n try {\n response = this._getKeys(id).map(val => this.namespaceObj + val);\n } catch (e) {\n return void handler.sendError(responseId, e);\n }\n\n // if scan, we send the cursor as first argument\n if (namespace !== this.namespaceObjects) {\n // When it was not the full DB namespace send out response\n return void handler.sendArray(responseId, isScan ? ['0', response] : response);\n }\n }\n if (namespace === this.namespaceFile || namespace === this.namespaceObjects) {\n // Handle request to get meta data keys\n if (isMeta === undefined) {\n let res;\n try {\n res = this._readDir(id, name);\n if (!res || !res.length) {\n res = [\n {\n file: '_data.json',\n stats: {},\n isDir: false,\n virtualFile: true,\n notExists: true,\n },\n ];\n }\n } catch (e) {\n if (!e.message.endsWith(utils.ERRORS.ERROR_NOT_FOUND)) {\n return void handler.sendError(responseId, new Error(`ERROR readDir id=${id}: ${e.message}`));\n }\n res = [];\n }\n let baseName = name || '';\n if (baseName.length && !baseName.endsWith('/')) {\n baseName += '/';\n }\n res.forEach(arr => {\n let entryId = id;\n if (arr.isDir) {\n if (entryId === '' || entryId === '*') {\n entryId = arr.file;\n arr.file = '_data.json'; // We return a \"virtual file\" to mark the directory as existing\n } else {\n arr.file += '/_data.json'; // We return a \"virtual file\" to mark the directory as existing\n }\n }\n // We need to simulate the Meta data here, so return both\n response.push(this.getFileId(entryId, baseName + arr.file, true));\n response.push(this.getFileId(entryId, baseName + arr.file, false));\n });\n handler.sendArray(responseId, isScan ? ['0', response] : response); // send out file or full db response\n } else {\n // such a request should never happen\n handler.sendArray(responseId, isScan ? ['0', []] : []); // send out file or full db response\n }\n } else if (namespace === this.namespaceSet) {\n handler.sendArray(responseId, isScan ? ['0', []] : []); // send out empty array, we have no sets\n } else {\n handler.sendError(\n responseId,\n new Error(`${isScan ? 'SCAN' : 'KEYS'}-UNSUPPORTED for namespace ${namespace}: Pattern=${pattern}`),\n );\n }\n }\n\n /**\n * Initialize RedisHandler for a new network connection\n *\n * @param socket Network socket\n */\n _initSocket(socket) {\n if (this.settings.connection.enhancedLogging) {\n this.log.silly(`${this.namespace} Handling new Redis Objects connection`);\n }\n const options = {\n log: this.log,\n logScope: `${this.settings.namespace || ''} Objects`,\n handleAsBuffers: true,\n enhancedLogging: this.settings.connection.enhancedLogging,\n };\n const handler = new RedisHandler(socket, options);\n this._socketEvents(handler);\n\n this.serverConnections[`${socket.remoteAddress}:${socket.remotePort}`] = handler;\n socket.on('close', () => {\n if (this.serverConnections[`${socket.remoteAddress}:${socket.remotePort}`]) {\n delete this.serverConnections[`${socket.remoteAddress}:${socket.remotePort}`];\n }\n });\n }\n\n /**\n * Initialize Redis Server\n *\n * @param settings Settings object\n * @returns a promise that resolves once the Redis server is listening\n */\n _initRedisServer(settings) {\n return new Promise((resolve, reject) => {\n if (settings.secure) {\n reject(new Error('Secure Redis unsupported for File-DB'));\n }\n try {\n this.server = net.createServer();\n this.server.on('error', err =>\n this.log.info(\n `${this.namespace} ${settings.secure ? 'Secure ' : ''} Error inMem-objects listening on port ${\n settings.port || 9001\n }: ${err}`,\n ),\n );\n this.server.on('connection', socket => this._initSocket(socket));\n\n this.server.listen(\n settings.port || 9001,\n settings.host === 'localhost' ? getLocalAddress() : settings.host ? settings.host : undefined,\n () => resolve(),\n );\n } catch (err) {\n reject(err);\n }\n });\n }\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AASA,sBAAgB;AAChB,sBAAe;AACf,uBAAiB;AACjB,yBAAmB;AACnB,8BAAsC;AACtC,qBAAsB;AACtB,mBAAgC;AAChC,qCAA2B;AAE3B,IAAAA,kBAA6B;AAC7B,gCAAsC;AA2BhC,MAAO,8BAA8B,gDAAqB;;;;;;EAM5D,YAAY,UAAQ;AAChB,UAAM,QAAQ;AAEd,SAAK,oBAAoB,CAAA;AACzB,SAAK,mBAAmB,GACpB,KAAK,SAAS,kBAAmB,SAAS,cAAc,SAAS,WAAW,kBAAmB,KACnG;AACA,SAAK,gBAAgB,GAAG,KAAK,gBAAgB;AAC7C,SAAK,eAAe,GAAG,KAAK,gBAAgB;AAC5C,SAAK,eAAe,GAAG,KAAK,gBAAgB;AAC5C,SAAK,kBAAkB,KAAK,aAAa;AAGzC,SAAK,mBAAmB,KAAK,cAAc;AAC3C,SAAK,kBAAkB,KAAK,aAAa;AACzC,SAAK,gBAAgB,GAAG,KAAK,SAAS,iBAAiB,MAAM;AAC7D,SAAK,mBAAmB,KAAK,cAAc;AAE3C,SAAK,eAAe,CAAA;AAEpB,SAAK,sBAAsB,IAAI,OAAO,qCAAqC;AAC3E,SAAK,sBAAsB,IAAI,OAAO,0BAA0B;AAEhE,SAAK,KAAI,EACJ,KAAK,MAAK;AACP,aAAO,KAAK,iBAAiB,KAAK,SAAS,UAAU;IACzD,CAAC,EACA,KAAK,MAAK;AACP,WAAK,IAAI,MACL,GAAG,KAAK,SAAS,IAAI,SAAS,SAAS,YAAY,EAAE,0CACjD,KAAK,SAAS,WAAW,QAAQ,IACrC,EAAE;AAGN,UAAI,OAAO,KAAK,SAAS,cAAc,YAA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,KAAK,SAAS,wCAAwC;IAC5E;AACA,UAAM,UAAU;MACZ,KAAK,KAAK;MACV,UAAU,GAAG,KAAK,SAAS,aAAa,EAAE;MAC1C,iBAAiB;MACjB,iBAAiB,KAAK,SAAS,WAAW;;AAE9C,UAAM,UAAU,IAAI,6BAAa,QAAQ,OAAO;AAChD,SAAK,cAAc,OAAO;AAE1B,SAAK,kBAAkB,GAAG,OAAO,aAAa,IAAI,OAAO,UAAU,EAAE,IAAI;AACzE,WAAO,GAAG,SAAS,MAAK;AACpB,UAAI,KAAK,kBAAkB,GAAG,OAAO,aAAa,IAAI,OAAO,UAAU,EAAE,GAAG;AACxE,eAAO,KAAK,kBAAkB,GAAG,OAAO,aAAa,IAAI,OAAO,UAAU,EAAE;MAChF;IACJ,CAAC;EACL;;;;;;;EAQA,iBAAiB,UAAQ;AACrB,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAU;AACnC,UAAI,SAAS,QAAQ;AACjB,eAAO,IAAI,MAAM,sCAAsC,CAAC;MAC5D;AACA,UAAI;AACA,aAAK,SAAS,gBAAAE,QAAI,aAAY;AAC9B,aAAK,OAAO,GAAG,SAAS,SACpB,KAAK,IAAI,KACL,GAAG,KAAK,SAAS,IAAI,SAAS,SAAS,YAAY,EAAE,0CACjD,SAAS,QAAQ,IACrB,KAAK,GAAG,EAAE,CACb;AAEL,aAAK,OAAO,GAAG,cAAc,YAAU,KAAK,YAAY,MAAM,CAAC;AAE/D,aAAK,OAAO,OACR,SAAS,QAAQ,MACjB,SAAS,SAAS,kBAAc,8BAAe,IAAK,SAAS,OAAO,SAAS,OAAO,QACpF,MAAM,QAAO,CAAE;MAEvB,SAAS,KAAK;AACV,eAAO,GAAG;MACd;IACJ,CAAC;EACL;;",
|
|
6
6
|
"names": ["import_db_base", "id", "crypto", "namespace", "fs", "path", "utils", "data", "net"]
|
|
7
7
|
}
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
* including the available methods for use by js-controller directly
|
|
4
4
|
*/
|
|
5
5
|
export class ObjectsInMemoryFileDB extends InMemoryFileDB {
|
|
6
|
+
/**
|
|
7
|
+
* @param settings Settings for the objects database
|
|
8
|
+
*/
|
|
6
9
|
constructor(settings: any);
|
|
7
10
|
change: any;
|
|
8
11
|
META_ID: string;
|
|
@@ -16,14 +19,50 @@ export class ObjectsInMemoryFileDB extends InMemoryFileDB {
|
|
|
16
19
|
writeFileInterval: number;
|
|
17
20
|
objectsDir: string;
|
|
18
21
|
existingMetaObjects: {};
|
|
22
|
+
/**
|
|
23
|
+
* Normalize a file name by collapsing slashes and backslashes into a single forward slash
|
|
24
|
+
*
|
|
25
|
+
* @param name The file name to normalize
|
|
26
|
+
*/
|
|
19
27
|
_normalizeFilename(name: any): any;
|
|
28
|
+
/**
|
|
29
|
+
* Schedule writing the file settings (_data.json) to disk
|
|
30
|
+
*
|
|
31
|
+
* @param id The object ID whose file settings should be saved, or a boolean used as the force flag
|
|
32
|
+
* @param force If true, write the settings immediately instead of debounced
|
|
33
|
+
*/
|
|
20
34
|
_saveFileSettings(id: any, force: any): void;
|
|
35
|
+
/**
|
|
36
|
+
* Load the file settings (_data.json) for the given object ID into memory
|
|
37
|
+
*
|
|
38
|
+
* @param id The object ID whose file settings should be loaded
|
|
39
|
+
*/
|
|
21
40
|
_loadFileSettings(id: any): void;
|
|
41
|
+
/**
|
|
42
|
+
* Synchronize the in-memory file metadata with the files actually present on disk (server only)
|
|
43
|
+
*
|
|
44
|
+
* @param limitId Optional object ID to limit the synchronization to
|
|
45
|
+
*/
|
|
22
46
|
syncFileDirectory(limitId: any): {
|
|
23
47
|
numberSuccess: number;
|
|
24
48
|
notifications: any[];
|
|
25
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Write a file into an object's file storage (used by the server)
|
|
52
|
+
*
|
|
53
|
+
* @param id The object ID owning the file
|
|
54
|
+
* @param name The file name
|
|
55
|
+
* @param data The file content
|
|
56
|
+
* @param options Optional write options, or the mime type as a string
|
|
57
|
+
*/
|
|
26
58
|
_writeFile(id: any, name: any, data: any, options: any): void;
|
|
59
|
+
/**
|
|
60
|
+
* Read a file from an object's file storage (used by the server)
|
|
61
|
+
*
|
|
62
|
+
* @param id The object ID owning the file
|
|
63
|
+
* @param name The file name
|
|
64
|
+
* @param options Optional read options
|
|
65
|
+
*/
|
|
27
66
|
_readFile(id: any, name: any, options: any): {
|
|
28
67
|
fileContent: any;
|
|
29
68
|
fileMime: any;
|
|
@@ -40,7 +79,7 @@ export class ObjectsInMemoryFileDB extends InMemoryFileDB {
|
|
|
40
79
|
*
|
|
41
80
|
* @param id id of the namespace
|
|
42
81
|
* @param [name] name of the file
|
|
43
|
-
* @returns
|
|
82
|
+
* @returns true if the file exists
|
|
44
83
|
*/
|
|
45
84
|
_fileExists(id: any, name?: any): boolean;
|
|
46
85
|
/**
|
|
@@ -48,10 +87,23 @@ export class ObjectsInMemoryFileDB extends InMemoryFileDB {
|
|
|
48
87
|
*
|
|
49
88
|
* @param id id of the namespace
|
|
50
89
|
* @param [name] name of the directory
|
|
51
|
-
* @returns
|
|
90
|
+
* @returns true if the directory exists
|
|
52
91
|
*/
|
|
53
92
|
dirExists(id: any, name?: any): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Delete a file or directory from an object's file storage (used by the server)
|
|
95
|
+
*
|
|
96
|
+
* @param id The object ID owning the file
|
|
97
|
+
* @param name The file or directory name to delete
|
|
98
|
+
*/
|
|
54
99
|
_unlink(id: any, name: any): void;
|
|
100
|
+
/**
|
|
101
|
+
* List the contents of a directory in an object's file storage (used by the server)
|
|
102
|
+
*
|
|
103
|
+
* @param id The object ID owning the files
|
|
104
|
+
* @param name The directory name to list
|
|
105
|
+
* @param options Optional read options
|
|
106
|
+
*/
|
|
55
107
|
_readDir(id: any, name: any, options: any): {
|
|
56
108
|
file: string;
|
|
57
109
|
stats: fs.Stats;
|
|
@@ -60,31 +112,99 @@ export class ObjectsInMemoryFileDB extends InMemoryFileDB {
|
|
|
60
112
|
modifiedAt: any;
|
|
61
113
|
createdAt: any;
|
|
62
114
|
}[];
|
|
115
|
+
/**
|
|
116
|
+
* Rename a file or directory in an object's file storage (used by the server)
|
|
117
|
+
*
|
|
118
|
+
* @param id The object ID owning the file
|
|
119
|
+
* @param oldName The current file or directory name
|
|
120
|
+
* @param newName The new file or directory name
|
|
121
|
+
*/
|
|
63
122
|
_rename(id: any, oldName: any, newName: any): void;
|
|
123
|
+
/**
|
|
124
|
+
* Create a deep clone of the given object
|
|
125
|
+
*
|
|
126
|
+
* @param obj The object to clone
|
|
127
|
+
*/
|
|
64
128
|
_clone(obj: any): any;
|
|
129
|
+
/**
|
|
130
|
+
* Subscribe a client to meta changes
|
|
131
|
+
*
|
|
132
|
+
* @param client The client to subscribe
|
|
133
|
+
* @param pattern The pattern of meta IDs to subscribe to
|
|
134
|
+
*/
|
|
65
135
|
_subscribeMeta(client: any, pattern: any): void;
|
|
136
|
+
/**
|
|
137
|
+
* Subscribe a client to object changes (used by the server)
|
|
138
|
+
*
|
|
139
|
+
* @param client The client to subscribe
|
|
140
|
+
* @param pattern The pattern of object IDs to subscribe to
|
|
141
|
+
*/
|
|
66
142
|
_subscribeConfigForClient(client: any, pattern: any): void;
|
|
143
|
+
/**
|
|
144
|
+
* Unsubscribe a client from object changes (used by the server)
|
|
145
|
+
*
|
|
146
|
+
* @param client The client to unsubscribe
|
|
147
|
+
* @param pattern The pattern of object IDs to unsubscribe from
|
|
148
|
+
*/
|
|
67
149
|
_unsubscribeConfigForClient(client: any, pattern: any): void;
|
|
150
|
+
/**
|
|
151
|
+
* Subscribe a client to file changes of an object (used by the server)
|
|
152
|
+
*
|
|
153
|
+
* @param client The client to subscribe
|
|
154
|
+
* @param id The object ID owning the files
|
|
155
|
+
* @param pattern One or more file name patterns to subscribe to
|
|
156
|
+
*/
|
|
68
157
|
_subscribeFileForClient(client: any, id: any, pattern: any): void;
|
|
158
|
+
/**
|
|
159
|
+
* Unsubscribe a client from file changes of an object (used by the server)
|
|
160
|
+
*
|
|
161
|
+
* @param client The client to unsubscribe
|
|
162
|
+
* @param id The object ID owning the files
|
|
163
|
+
* @param pattern One or more file name patterns to unsubscribe from
|
|
164
|
+
*/
|
|
69
165
|
_unsubscribeFileForClient(client: any, id: any, pattern: any): void;
|
|
166
|
+
/**
|
|
167
|
+
* Get a single object by its ID (used by the server)
|
|
168
|
+
*
|
|
169
|
+
* @param id The object ID to read
|
|
170
|
+
*/
|
|
70
171
|
_getObject(id: any): any;
|
|
172
|
+
/**
|
|
173
|
+
* Get all object IDs matching the given pattern, sorted (used by the server)
|
|
174
|
+
*
|
|
175
|
+
* @param pattern The pattern to match object IDs against
|
|
176
|
+
*/
|
|
71
177
|
_getKeys(pattern: any): string[];
|
|
178
|
+
/**
|
|
179
|
+
* Get the values of the given object IDs (used by the server)
|
|
180
|
+
*
|
|
181
|
+
* @param keys The object IDs to read
|
|
182
|
+
*/
|
|
72
183
|
_getObjects(keys: any): any;
|
|
184
|
+
/**
|
|
185
|
+
* Get the meta dictionary, creating it if it does not exist yet
|
|
186
|
+
*/
|
|
73
187
|
_ensureMetaDict(): any;
|
|
74
188
|
/**
|
|
75
189
|
* Get value of given meta id
|
|
76
190
|
*
|
|
77
|
-
* @param id
|
|
78
|
-
* @returns
|
|
191
|
+
* @param id The meta ID to read
|
|
192
|
+
* @returns the stored meta value
|
|
79
193
|
*/
|
|
80
194
|
getMeta(id: any): any;
|
|
81
195
|
/**
|
|
82
196
|
* Sets given value to id in metaNamespace
|
|
83
197
|
*
|
|
84
|
-
* @param id
|
|
85
|
-
* @param value
|
|
198
|
+
* @param id The meta ID to write
|
|
199
|
+
* @param value The value to store
|
|
86
200
|
*/
|
|
87
201
|
setMeta(id: any, value: any): void;
|
|
202
|
+
/**
|
|
203
|
+
* Directly set an object value and publish the change (used by the server)
|
|
204
|
+
*
|
|
205
|
+
* @param id The object ID to set
|
|
206
|
+
* @param obj The object to store
|
|
207
|
+
*/
|
|
88
208
|
_setObjectDirect(id: any, obj: any): void;
|
|
89
209
|
/**
|
|
90
210
|
* Delete the given object from the dataset
|
|
@@ -92,9 +212,22 @@ export class ObjectsInMemoryFileDB extends InMemoryFileDB {
|
|
|
92
212
|
* @param id unique id of the object
|
|
93
213
|
*/
|
|
94
214
|
_delObject(id: any): void;
|
|
215
|
+
/**
|
|
216
|
+
* Apply a view's map function over all objects and collect the matching rows
|
|
217
|
+
*
|
|
218
|
+
* @param func The view definition containing the map function
|
|
219
|
+
* @param params Query parameters such as startkey and endkey
|
|
220
|
+
*/
|
|
95
221
|
_applyView(func: any, params: any): {
|
|
96
222
|
rows: never[];
|
|
97
223
|
};
|
|
224
|
+
/**
|
|
225
|
+
* Run a predefined object view (design document) and return the matching rows (used by the server)
|
|
226
|
+
*
|
|
227
|
+
* @param design The design document name
|
|
228
|
+
* @param search The view name within the design document
|
|
229
|
+
* @param params Query parameters such as startkey and endkey
|
|
230
|
+
*/
|
|
98
231
|
_getObjectView(design: any, search: any, params: any): {
|
|
99
232
|
rows: never[];
|
|
100
233
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectsInMemFileDB.d.ts","sourceRoot":"","sources":["../../../../src/lib/objects/objectsInMemFileDB.js"],"names":[],"mappings":"AAgBA;;;GAGG;AACH;IACI,2BAgDC;IAvCO,YAEC;IAGL,gBAAyB;IACzB,gBAAqB;IACrB,UAAe;IACf,kCAAsB;IACtB,gBAAkB;IAClB,2BAAkC;IAClC,mBAAwD;IACxD,eAAwE;IACxE,0BAGe;IAKf,mBAAkD;IAGlD,wBAA6B;
|
|
1
|
+
{"version":3,"file":"objectsInMemFileDB.d.ts","sourceRoot":"","sources":["../../../../src/lib/objects/objectsInMemFileDB.js"],"names":[],"mappings":"AAgBA;;;GAGG;AACH;IACI;;OAEG;IACH,2BAgDC;IAvCO,YAEC;IAGL,gBAAyB;IACzB,gBAAqB;IACrB,UAAe;IACf,kCAAsB;IACtB,gBAAkB;IAClB,2BAAkC;IAClC,mBAAwD;IACxD,eAAwE;IACxE,0BAGe;IAKf,mBAAkD;IAGlD,wBAA6B;IAiBjC;;;;OAIG;IACH,mCAEC;IAGD;;;;;OAKG;IACH,6CAuCC;IAED;;;;OAIG;IACH,iCA+BC;IAED;;;;OAIG;IACH;;;MA8FC;IAED;;;;;;;OAOG;IACH,8DA+FC;IAED;;;;;;OAMG;IACH;;;MAqGC;IAED;;;;;OAKG;IAEH,gCAYC;IAED;;;;;;OAMG;IAEH,0CAiBC;IAED;;;;;;OAMG;IAEH,wCAiBC;IAED;;;;;OAKG;IACH,kCA6DC;IAED;;;;;;OAMG;IACH;;;;;;;QA8JC;IAED;;;;;;OAMG;IACH,mDA+BC;IAED;;;;OAIG;IACH,sBAWC;IAED;;;;;OAKG;IACH,gDAEC;IAED;;;;;OAKG;IACH,2DAEC;IAED;;;;;OAKG;IACH,6DAEC;IAED;;;;;;OAMG;IACH,kEAMC;IAED;;;;;;OAMG;IACH,oEAMC;IAED;;;;OAIG;IACH,yBAEC;IAED;;;;OAIG;IACH,iCAKC;IAED;;;;OAIG;IACH,4BAMC;IAED;;OAEG;IACH,uBAOC;IAED;;;;;OAKG;IACH,sBAGC;IAED;;;;;OAKG;IACH,mCAeC;IAED;;;;;OAKG;IACH,0CAWC;IAED;;;;OAIG;IACH,0BAuBC;IAED;;;;;OAKG;IACH;;MA8CC;IAED;;;;;;OAMG;IACH;;MAWC;CAkBJ;+BAlmC8B,mBAAmB;eAFnC,UAAU"}
|