@iobroker/db-objects-jsonl 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.
@@ -3,7 +3,6 @@
3
3
  * including the available methods for use by js-controller directly
4
4
  */
5
5
  export class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
6
- constructor(settings: any);
7
6
  _db: JsonlDB<unknown>;
8
7
  _backupInterval: NodeJS.Timeout | undefined;
9
8
  /**
@@ -13,6 +12,9 @@ export class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
13
12
  * If this returns true, the jsonl DB was opened and doesn't need to be opened again.
14
13
  */
15
14
  _maybeMigrateFileDB(): Promise<boolean>;
15
+ /**
16
+ * Regularly called to store a compressed backup of the DB
17
+ */
16
18
  saveBackup(): Promise<void>;
17
19
  }
18
20
  import { ObjectsInMemoryFileDB } from '@iobroker/db-objects-file';
@@ -82,6 +82,9 @@ function normalizeJsonlOptions(conf = {}) {
82
82
  return ret;
83
83
  }
84
84
  class ObjectsInMemoryJsonlDB extends import_db_objects_file.ObjectsInMemoryFileDB {
85
+ /**
86
+ * @param settings Settings for the objects database
87
+ */
85
88
  constructor(settings) {
86
89
  settings = settings || {};
87
90
  settings.fileDB = {
@@ -95,37 +98,40 @@ class ObjectsInMemoryJsonlDB extends import_db_objects_file.ObjectsInMemoryFileD
95
98
  super(settings);
96
99
  this._db = new import_jsonl_db.JsonlDB(import_node_path.default.join(this.dataDir, settings.jsonlDB.fileName), jsonlOptions);
97
100
  }
101
+ /**
102
+ * Open the JSONL database, migrating from the legacy file DB if necessary
103
+ */
98
104
  async open() {
99
105
  if (!await this._maybeMigrateFileDB()) {
100
106
  await this._db.open();
101
107
  }
102
108
  this.dataset = new Proxy(this._db, {
103
109
  /**
104
- * @param target
105
- * @param prop
110
+ * @param target The proxied JsonlDB instance
111
+ * @param prop The property key being read
106
112
  */
107
113
  get(target, prop) {
108
114
  return target.get(prop);
109
115
  },
110
116
  /**
111
- * @param target
112
- * @param prop
117
+ * @param target The proxied JsonlDB instance
118
+ * @param prop The property key being checked
113
119
  */
114
120
  has(target, prop) {
115
121
  return target.has(prop);
116
122
  },
117
123
  /**
118
- * @param target
119
- * @param prop
120
- * @param value
124
+ * @param target The proxied JsonlDB instance
125
+ * @param prop The property key being written
126
+ * @param value The value to store
121
127
  */
122
128
  set(target, prop, value) {
123
129
  target.set(prop, value);
124
130
  return true;
125
131
  },
126
132
  /**
127
- * @param target
128
- * @param prop
133
+ * @param target The proxied JsonlDB instance
134
+ * @param prop The property key being deleted
129
135
  */
130
136
  deleteProperty(target, prop) {
131
137
  return target.delete(prop);
@@ -134,8 +140,8 @@ class ObjectsInMemoryJsonlDB extends import_db_objects_file.ObjectsInMemoryFileD
134
140
  return [...target.keys()];
135
141
  },
136
142
  /**
137
- * @param target
138
- * @param prop
143
+ * @param target The proxied JsonlDB instance
144
+ * @param prop The property key to describe
139
145
  */
140
146
  getOwnPropertyDescriptor(target, prop) {
141
147
  if (!target.has(prop)) {
@@ -214,9 +220,14 @@ class ObjectsInMemoryJsonlDB extends import_db_objects_file.ObjectsInMemoryFileD
214
220
  }
215
221
  return true;
216
222
  }
223
+ /**
224
+ * Persist the state. Nothing to do here as the JSONL DB saves behind the scenes.
225
+ */
217
226
  async saveState() {
218
227
  }
219
- // Is regularly called and stores a compressed backup of the DB
228
+ /**
229
+ * Regularly called to store a compressed backup of the DB
230
+ */
220
231
  async saveBackup() {
221
232
  const now = Date.now();
222
233
  const tmpBackupFileName = import_node_path.default.join(import_node_os.default.tmpdir(), `${this.getTimeStr(now)}_${this.settings.jsonlDB.fileName}`);
@@ -236,6 +247,9 @@ class ObjectsInMemoryJsonlDB extends import_db_objects_file.ObjectsInMemoryFileD
236
247
  this.log.error(`${this.namespace} Cannot save backup ${backupFileName}: ${e.message}`);
237
248
  }
238
249
  }
250
+ /**
251
+ * Stop the backup interval, close the DB and clean up
252
+ */
239
253
  async destroy() {
240
254
  await super.destroy();
241
255
  if (this._backupInterval) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/objects/objectsInMemJsonlDB.js"],
4
- "sourcesContent": ["/**\n * Object DB in memory - Server\n *\n * Copyright 2013-2024 bluefox <dogafox@gmail.com>\n *\n * MIT License\n *\n */\n\nimport { ObjectsInMemoryFileDB } from '@iobroker/db-objects-file';\nimport { JsonlDB } from '@alcalzone/jsonl-db';\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport { tools } from '@iobroker/js-controller-common-db';\n\n/**\n * Normalizes options for the JsonlDB\n *\n * @param conf The jsonlOptions options from iobroker.json\n * @returns\n */\nfunction normalizeJsonlOptions(conf = {}) {\n const ret = {\n autoCompress: {\n // Compress when the number of uncompressed entries has grown a lot\n sizeFactor: 2,\n sizeFactorMinimumSize: 25000,\n // Compress at least daily to avoid a huge file when DBs have few objects\n // but big objects are updated regularly (e.g. the repositories)\n intervalMs: 1000 * 60 * 60 * 23,\n },\n ignoreReadErrors: true,\n throttleFS: {\n intervalMs: 60000,\n maxBufferedCommands: 1000,\n },\n lockfile: {\n // 5 retries starting at 250ms add up to just above 2s,\n // so the DB has 3 more seconds to load all data if it wants to stay within the 5s connectionTimeout\n retries: 5,\n retryMinTimeoutMs: 250,\n // This makes sure the DB stays locked for maximum 2s even if the process crashes\n staleMs: 2000,\n },\n };\n\n // Be really careful what we allow here. Incorrect settings may cause problems in production.\n if (tools.isObject(conf.autoCompress)) {\n const ac = conf.autoCompress;\n // Letting the DB grow more than 100x is risky\n if (typeof ac.sizeFactor === 'number' && ac.sizeFactor >= 2 && ac.sizeFactor <= 100) {\n ret.autoCompress.sizeFactor = ac.sizeFactor;\n }\n // Also we should definitely compress once the DB has reached 100k lines or it might grow too big\n if (\n typeof ac.sizeFactorMinimumSize === 'number' &&\n ac.sizeFactorMinimumSize >= 0 &&\n ac.sizeFactorMinimumSize <= 100000\n ) {\n ret.autoCompress.sizeFactorMinimumSize = ac.sizeFactorMinimumSize;\n }\n }\n if (tools.isObject(conf.throttleFS)) {\n const thr = conf.throttleFS;\n // Don't write more often than every second and write at least once every hour\n if (typeof thr.intervalMs === 'number' && thr.intervalMs >= 1000 && thr.intervalMs <= 3600000) {\n ret.throttleFS.intervalMs = thr.intervalMs;\n }\n // Don't keep too much in memory - 100k changes are more than enough\n if (\n typeof thr.maxBufferedCommands === 'number' &&\n thr.maxBufferedCommands >= 0 &&\n thr.maxBufferedCommands <= 100000\n ) {\n ret.throttleFS.maxBufferedCommands = thr.maxBufferedCommands;\n }\n }\n\n return ret;\n}\n\n/**\n * This class inherits InMemoryFileDB class and adds all relevant logic for objects\n * including the available methods for use by js-controller directly\n */\nexport class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {\n constructor(settings) {\n settings = settings || {};\n settings.fileDB = {\n fileName: 'objects.json',\n backupDirName: 'backup-objects',\n };\n\n const jsonlOptions = normalizeJsonlOptions(settings.connection.jsonlOptions);\n settings.jsonlDB = {\n fileName: 'objects.jsonl',\n };\n super(settings);\n\n this._db = new JsonlDB(path.join(this.dataDir, settings.jsonlDB.fileName), jsonlOptions);\n }\n\n async open() {\n if (!(await this._maybeMigrateFileDB())) {\n await this._db.open();\n }\n\n // Create an object-like wrapper around the internal Map\n this.dataset = new Proxy(this._db, {\n /**\n * @param target\n * @param prop\n */\n get(target, prop) {\n return target.get(prop);\n },\n /**\n * @param target\n * @param prop\n */\n has(target, prop) {\n return target.has(prop);\n },\n /**\n * @param target\n * @param prop\n * @param value\n */\n set(target, prop, value) {\n target.set(prop, value);\n return true;\n },\n /**\n * @param target\n * @param prop\n */\n deleteProperty(target, prop) {\n return target.delete(prop);\n },\n ownKeys(target) {\n return [...target.keys()];\n },\n /**\n * @param target\n * @param prop\n */\n getOwnPropertyDescriptor(target, prop) {\n if (!target.has(prop)) {\n return undefined;\n }\n return {\n configurable: true,\n enumerable: true,\n writable: true,\n value: target.get(prop),\n };\n },\n });\n\n if (this.settings.backup && this.settings.backup.period && !this.settings.backup.disabled) {\n this._backupInterval = setInterval(() => {\n this.saveBackup();\n }, this.settings.backup.period);\n }\n }\n\n /**\n * Checks if an existing file DB should be migrated to JSONL\n *\n * @returns true if the file DB was migrated. false if not.\n * If this returns true, the jsonl DB was opened and doesn't need to be opened again.\n */\n async _maybeMigrateFileDB() {\n const jsonlFileName = path.join(this.dataDir, this.settings.jsonlDB.fileName);\n const jsonFileName = path.join(this.dataDir, this.settings.fileDB.fileName);\n const bakFileName = path.join(this.dataDir, `${this.settings.fileDB.fileName}.bak`);\n\n // Check the timestamps of each file, defaulting to 0 if they don't exist\n let jsonlTimeStamp = 0;\n let jsonTimeStamp = 0;\n let bakTimeStamp = 0;\n try {\n const stat = fs.statSync(jsonlFileName);\n if (stat.isFile()) {\n jsonlTimeStamp = stat.mtime;\n }\n } catch {\n // ignore\n }\n try {\n const stat = fs.statSync(jsonFileName);\n if (stat.isFile()) {\n jsonTimeStamp = stat.mtime;\n }\n } catch {\n // ignore\n }\n try {\n const stat = fs.statSync(bakFileName);\n if (stat.isFile()) {\n bakTimeStamp = stat.mtime;\n }\n } catch {\n // ignore\n }\n\n // Figure out which file needs to be imported\n let importFilename;\n if (jsonTimeStamp > 0 && jsonTimeStamp >= bakTimeStamp && jsonTimeStamp >= jsonlTimeStamp) {\n importFilename = jsonFileName;\n } else if (bakTimeStamp > 0 && bakTimeStamp >= jsonTimeStamp && bakTimeStamp >= jsonlTimeStamp) {\n importFilename = bakFileName;\n } else {\n // None of the File DB files are newer than the JSONL file\n // There is nothing to restore, we're done\n return false;\n }\n\n await this._db.open();\n this._db.clear();\n await this._db.importJson(importFilename);\n\n // And rename the existing files to avoid redoing the work next time\n if (fs.existsSync(jsonFileName)) {\n try {\n fs.renameSync(jsonFileName, `${jsonFileName}.migrated`);\n } catch {\n // ignore\n }\n }\n if (fs.existsSync(bakFileName)) {\n try {\n fs.renameSync(bakFileName, `${bakFileName}.migrated`);\n } catch {\n // ignore\n }\n }\n\n // Signal to the caller that the DB is already open\n return true;\n }\n\n async saveState() {\n // Nothing to do, the DB saves behind the scenes\n }\n\n // Is regularly called and stores a compressed backup of the DB\n async saveBackup() {\n const now = Date.now();\n const tmpBackupFileName = path.join(os.tmpdir(), `${this.getTimeStr(now)}_${this.settings.jsonlDB.fileName}`);\n const backupFileName = path.join(\n this.backupDir,\n `${this.getTimeStr(now)}_${this.settings.jsonlDB.fileName}.gz`,\n );\n\n if (!this._db.isOpen) {\n this.log.warn(`${this.namespace} Cannot save backup ${backupFileName}: DB is closed`);\n return;\n }\n\n try {\n if (fs.existsSync(backupFileName)) {\n return;\n }\n\n // Create a DB dump\n await this._db.dump(tmpBackupFileName);\n // and zip it\n await tools.compressFileGZip(tmpBackupFileName, backupFileName, { deleteInput: true });\n // figure out if older files need to be deleted\n this.deleteOldBackupFiles(this.settings.jsonlDB.fileName);\n } catch (e) {\n this.log.error(`${this.namespace} Cannot save backup ${backupFileName}: ${e.message}`);\n }\n }\n\n async destroy() {\n await super.destroy();\n\n if (this._backupInterval) {\n clearInterval(this._backupInterval);\n }\n if (this._db) {\n await this._db.close();\n }\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AASA,6BAAsC;AACtC,sBAAwB;AACxB,uBAAiB;AACjB,qBAAe;AACf,qBAAe;AACf,qCAAsB;AAQtB,SAAS,sBAAsB,OAAO,CAAA,GAAE;AACpC,QAAM,MAAM;IACR,cAAc;;MAEV,YAAY;MACZ,uBAAuB;;;MAGvB,YAAY,MAAO,KAAK,KAAK;;IAEjC,kBAAkB;IAClB,YAAY;MACR,YAAY;MACZ,qBAAqB;;IAEzB,UAAU;;;MAGN,SAAS;MACT,mBAAmB;;MAEnB,SAAS;;;AAKjB,MAAI,qCAAM,SAAS,KAAK,YAAY,GAAG;AACnC,UAAM,KAAK,KAAK;AAEhB,QAAI,OAAO,GAAG,eAAe,YAAY,GAAG,cAAc,KAAK,GA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AE;IACzF;EACJ;EAEA,MAAM,UAAO;AACT,UAAM,MAAM,QAAO;AAEnB,QAAI,KAAK,iBAAiB;AACtB,oBAAc,KAAK,eAAe;IACtC;AACA,QAAI,KAAK,KAAK;AACV,YAAM,KAAK,IAAI,MAAK;IACxB;EACJ;;",
4
+ "sourcesContent": ["/**\n * Object DB in memory - Server\n *\n * Copyright 2013-2024 bluefox <dogafox@gmail.com>\n *\n * MIT License\n *\n */\n\nimport { ObjectsInMemoryFileDB } from '@iobroker/db-objects-file';\nimport { JsonlDB } from '@alcalzone/jsonl-db';\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport { tools } from '@iobroker/js-controller-common-db';\n\n/**\n * Normalizes options for the JsonlDB\n *\n * @param conf The jsonlOptions options from iobroker.json\n * @returns the normalized and validated JsonlDB options\n */\nfunction normalizeJsonlOptions(conf = {}) {\n const ret = {\n autoCompress: {\n // Compress when the number of uncompressed entries has grown a lot\n sizeFactor: 2,\n sizeFactorMinimumSize: 25000,\n // Compress at least daily to avoid a huge file when DBs have few objects\n // but big objects are updated regularly (e.g. the repositories)\n intervalMs: 1000 * 60 * 60 * 23,\n },\n ignoreReadErrors: true,\n throttleFS: {\n intervalMs: 60000,\n maxBufferedCommands: 1000,\n },\n lockfile: {\n // 5 retries starting at 250ms add up to just above 2s,\n // so the DB has 3 more seconds to load all data if it wants to stay within the 5s connectionTimeout\n retries: 5,\n retryMinTimeoutMs: 250,\n // This makes sure the DB stays locked for maximum 2s even if the process crashes\n staleMs: 2000,\n },\n };\n\n // Be really careful what we allow here. Incorrect settings may cause problems in production.\n if (tools.isObject(conf.autoCompress)) {\n const ac = conf.autoCompress;\n // Letting the DB grow more than 100x is risky\n if (typeof ac.sizeFactor === 'number' && ac.sizeFactor >= 2 && ac.sizeFactor <= 100) {\n ret.autoCompress.sizeFactor = ac.sizeFactor;\n }\n // Also we should definitely compress once the DB has reached 100k lines or it might grow too big\n if (\n typeof ac.sizeFactorMinimumSize === 'number' &&\n ac.sizeFactorMinimumSize >= 0 &&\n ac.sizeFactorMinimumSize <= 100000\n ) {\n ret.autoCompress.sizeFactorMinimumSize = ac.sizeFactorMinimumSize;\n }\n }\n if (tools.isObject(conf.throttleFS)) {\n const thr = conf.throttleFS;\n // Don't write more often than every second and write at least once every hour\n if (typeof thr.intervalMs === 'number' && thr.intervalMs >= 1000 && thr.intervalMs <= 3600000) {\n ret.throttleFS.intervalMs = thr.intervalMs;\n }\n // Don't keep too much in memory - 100k changes are more than enough\n if (\n typeof thr.maxBufferedCommands === 'number' &&\n thr.maxBufferedCommands >= 0 &&\n thr.maxBufferedCommands <= 100000\n ) {\n ret.throttleFS.maxBufferedCommands = thr.maxBufferedCommands;\n }\n }\n\n return ret;\n}\n\n/**\n * This class inherits InMemoryFileDB class and adds all relevant logic for objects\n * including the available methods for use by js-controller directly\n */\nexport class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {\n /**\n * @param settings Settings for the objects database\n */\n constructor(settings) {\n settings = settings || {};\n settings.fileDB = {\n fileName: 'objects.json',\n backupDirName: 'backup-objects',\n };\n\n const jsonlOptions = normalizeJsonlOptions(settings.connection.jsonlOptions);\n settings.jsonlDB = {\n fileName: 'objects.jsonl',\n };\n super(settings);\n\n this._db = new JsonlDB(path.join(this.dataDir, settings.jsonlDB.fileName), jsonlOptions);\n }\n\n /**\n * Open the JSONL database, migrating from the legacy file DB if necessary\n */\n async open() {\n if (!(await this._maybeMigrateFileDB())) {\n await this._db.open();\n }\n\n // Create an object-like wrapper around the internal Map\n this.dataset = new Proxy(this._db, {\n /**\n * @param target The proxied JsonlDB instance\n * @param prop The property key being read\n */\n get(target, prop) {\n return target.get(prop);\n },\n /**\n * @param target The proxied JsonlDB instance\n * @param prop The property key being checked\n */\n has(target, prop) {\n return target.has(prop);\n },\n /**\n * @param target The proxied JsonlDB instance\n * @param prop The property key being written\n * @param value The value to store\n */\n set(target, prop, value) {\n target.set(prop, value);\n return true;\n },\n /**\n * @param target The proxied JsonlDB instance\n * @param prop The property key being deleted\n */\n deleteProperty(target, prop) {\n return target.delete(prop);\n },\n ownKeys(target) {\n return [...target.keys()];\n },\n /**\n * @param target The proxied JsonlDB instance\n * @param prop The property key to describe\n */\n getOwnPropertyDescriptor(target, prop) {\n if (!target.has(prop)) {\n return undefined;\n }\n return {\n configurable: true,\n enumerable: true,\n writable: true,\n value: target.get(prop),\n };\n },\n });\n\n if (this.settings.backup && this.settings.backup.period && !this.settings.backup.disabled) {\n this._backupInterval = setInterval(() => {\n this.saveBackup();\n }, this.settings.backup.period);\n }\n }\n\n /**\n * Checks if an existing file DB should be migrated to JSONL\n *\n * @returns true if the file DB was migrated. false if not.\n * If this returns true, the jsonl DB was opened and doesn't need to be opened again.\n */\n async _maybeMigrateFileDB() {\n const jsonlFileName = path.join(this.dataDir, this.settings.jsonlDB.fileName);\n const jsonFileName = path.join(this.dataDir, this.settings.fileDB.fileName);\n const bakFileName = path.join(this.dataDir, `${this.settings.fileDB.fileName}.bak`);\n\n // Check the timestamps of each file, defaulting to 0 if they don't exist\n let jsonlTimeStamp = 0;\n let jsonTimeStamp = 0;\n let bakTimeStamp = 0;\n try {\n const stat = fs.statSync(jsonlFileName);\n if (stat.isFile()) {\n jsonlTimeStamp = stat.mtime;\n }\n } catch {\n // ignore\n }\n try {\n const stat = fs.statSync(jsonFileName);\n if (stat.isFile()) {\n jsonTimeStamp = stat.mtime;\n }\n } catch {\n // ignore\n }\n try {\n const stat = fs.statSync(bakFileName);\n if (stat.isFile()) {\n bakTimeStamp = stat.mtime;\n }\n } catch {\n // ignore\n }\n\n // Figure out which file needs to be imported\n let importFilename;\n if (jsonTimeStamp > 0 && jsonTimeStamp >= bakTimeStamp && jsonTimeStamp >= jsonlTimeStamp) {\n importFilename = jsonFileName;\n } else if (bakTimeStamp > 0 && bakTimeStamp >= jsonTimeStamp && bakTimeStamp >= jsonlTimeStamp) {\n importFilename = bakFileName;\n } else {\n // None of the File DB files are newer than the JSONL file\n // There is nothing to restore, we're done\n return false;\n }\n\n await this._db.open();\n this._db.clear();\n await this._db.importJson(importFilename);\n\n // And rename the existing files to avoid redoing the work next time\n if (fs.existsSync(jsonFileName)) {\n try {\n fs.renameSync(jsonFileName, `${jsonFileName}.migrated`);\n } catch {\n // ignore\n }\n }\n if (fs.existsSync(bakFileName)) {\n try {\n fs.renameSync(bakFileName, `${bakFileName}.migrated`);\n } catch {\n // ignore\n }\n }\n\n // Signal to the caller that the DB is already open\n return true;\n }\n\n /**\n * Persist the state. Nothing to do here as the JSONL DB saves behind the scenes.\n */\n async saveState() {\n // Nothing to do, the DB saves behind the scenes\n }\n\n /**\n * Regularly called to store a compressed backup of the DB\n */\n async saveBackup() {\n const now = Date.now();\n const tmpBackupFileName = path.join(os.tmpdir(), `${this.getTimeStr(now)}_${this.settings.jsonlDB.fileName}`);\n const backupFileName = path.join(\n this.backupDir,\n `${this.getTimeStr(now)}_${this.settings.jsonlDB.fileName}.gz`,\n );\n\n if (!this._db.isOpen) {\n this.log.warn(`${this.namespace} Cannot save backup ${backupFileName}: DB is closed`);\n return;\n }\n\n try {\n if (fs.existsSync(backupFileName)) {\n return;\n }\n\n // Create a DB dump\n await this._db.dump(tmpBackupFileName);\n // and zip it\n await tools.compressFileGZip(tmpBackupFileName, backupFileName, { deleteInput: true });\n // figure out if older files need to be deleted\n this.deleteOldBackupFiles(this.settings.jsonlDB.fileName);\n } catch (e) {\n this.log.error(`${this.namespace} Cannot save backup ${backupFileName}: ${e.message}`);\n }\n }\n\n /**\n * Stop the backup interval, close the DB and clean up\n */\n async destroy() {\n await super.destroy();\n\n if (this._backupInterval) {\n clearInterval(this._backupInterval);\n }\n if (this._db) {\n await this._db.close();\n }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AASA,6BAAsC;AACtC,sBAAwB;AACxB,uBAAiB;AACjB,qBAAe;AACf,qBAAe;AACf,qCAAsB;AAQtB,SAAS,sBAAsB,OAAO,CAAA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BAAuB,cAAc,gBAAgB;AACpF;IACJ;AAEA,QAAI;AACA,UAAI,eAAAC,QAAG,WAAW,cAAc,GAAG;AAC/B;MACJ;AAGA,YAAM,KAAK,IAAI,KAAK,iBAAiB;AAErC,YAAM,qCAAM,iBAAiB,mBAAmB,gBAAgB,EAAE,aAAa,KAAI,CAAE;AAErF,WAAK,qBAAqB,KAAK,SAAS,QAAQ,QAAQ;IAC5D,SAAS,GAAG;AACR,WAAK,IAAI,MAAM,GAAG,KAAK,SAAS,uBAAuB,cAAc,KAAK,EAAE,OAAO,EAAE;IACzF;EACJ;;;;EAKA,MAAM,UAAO;AACT,UAAM,MAAM,QAAO;AAEnB,QAAI,KAAK,iBAAiB;AACtB,oBAAc,KAAK,eAAe;IACtC;AACA,QAAI,KAAK,KAAK;AACV,YAAM,KAAK,IAAI,MAAK;IACxB;EACJ;;",
6
6
  "names": ["path", "fs", "os"]
7
7
  }
@@ -1,10 +1,27 @@
1
+ /**
2
+ * Objects database client that also starts an in-memory server speaking the Redis protocol
3
+ */
1
4
  export class ObjectsInMemoryServerClass extends ObjectsInRedisClient {
5
+ /**
6
+ * @param settings Settings for the objects client and the in-memory server
7
+ */
2
8
  constructor(settings: any);
3
9
  objectsServer: ObjectsInMemoryServer;
10
+ /**
11
+ * Synchronize the file directory of the in-memory server
12
+ *
13
+ * @param limitId Optional object ID to limit the synchronization to
14
+ */
4
15
  syncFileDirectory(limitId: any): {
5
16
  numberSuccess: number;
6
17
  notifications: any[];
7
18
  };
19
+ /**
20
+ * Check whether a directory exists in the in-memory server's file storage
21
+ *
22
+ * @param id The object ID owning the files
23
+ * @param name The directory path to check
24
+ */
8
25
  dirExists(id: any, name: any): boolean;
9
26
  }
10
27
  import { Client as ObjectsInRedisClient } from '@iobroker/db-objects-redis';
@@ -24,6 +24,9 @@ module.exports = __toCommonJS(objectsInMemServerClass_exports);
24
24
  var import_db_objects_redis = require("@iobroker/db-objects-redis");
25
25
  var import_objectsInMemServerRedis = require("./objectsInMemServerRedis.js");
26
26
  class ObjectsInMemoryServerClass extends import_db_objects_redis.Client {
27
+ /**
28
+ * @param settings Settings for the objects client and the in-memory server
29
+ */
27
30
  constructor(settings) {
28
31
  settings.autoConnect = false;
29
32
  super(settings);
@@ -38,16 +41,33 @@ class ObjectsInMemoryServerClass extends import_db_objects_redis.Client {
38
41
  };
39
42
  this.objectsServer = new import_objectsInMemServerRedis.ObjectsInMemoryServer(serverSettings);
40
43
  }
44
+ /**
45
+ * Destroy the client first and the in-memory server afterwards
46
+ */
41
47
  async destroy() {
42
48
  await super.destroy();
43
49
  await this.objectsServer.destroy();
44
50
  }
51
+ /**
52
+ * Get the status as reported by the in-memory server
53
+ */
45
54
  getStatus() {
46
55
  return this.objectsServer.getStatus();
47
56
  }
57
+ /**
58
+ * Synchronize the file directory of the in-memory server
59
+ *
60
+ * @param limitId Optional object ID to limit the synchronization to
61
+ */
48
62
  syncFileDirectory(limitId) {
49
63
  return this.objectsServer.syncFileDirectory(limitId);
50
64
  }
65
+ /**
66
+ * Check whether a directory exists in the in-memory server's file storage
67
+ *
68
+ * @param id The object ID owning the files
69
+ * @param name The directory path to check
70
+ */
51
71
  dirExists(id, name) {
52
72
  return this.objectsServer.dirExists(id, name);
53
73
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/objects/objectsInMemServerClass.js"],
4
- "sourcesContent": ["/**\n * States DB in memory - Server with Redis protocol\n *\n * Copyright 2013-2024 bluefox <dogafox@gmail.com>\n *\n * MIT License\n *\n */\n\nimport { Client as ObjectsInRedisClient } from '@iobroker/db-objects-redis';\nimport { ObjectsInMemoryServer } from './objectsInMemServerRedis.js';\n\nexport class ObjectsInMemoryServerClass extends ObjectsInRedisClient {\n constructor(settings) {\n settings.autoConnect = false; // delay Client connection to when we need it\n super(settings);\n\n const serverSettings = {\n namespace: settings.namespace ? `${settings.namespace}-Server` : 'Server',\n connection: settings.connection,\n logger: settings.logger,\n hostname: settings.hostname,\n connected: () => {\n this.connectDb(); // now that server is connected also connect client\n },\n };\n this.objectsServer = new ObjectsInMemoryServer(serverSettings);\n }\n\n async destroy() {\n await super.destroy(); // destroy client first\n await this.objectsServer.destroy(); // server afterwards too\n }\n\n getStatus() {\n return this.objectsServer.getStatus(); // return Status as Server\n }\n\n syncFileDirectory(limitId) {\n return this.objectsServer.syncFileDirectory(limitId);\n }\n\n dirExists(id, name) {\n return this.objectsServer.dirExists(id, name);\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;AASA,8BAA+C;AAC/C,qCAAsC;AAEhC,MAAO,mCAAmC,wBAAAA,OAAoB;EAChE,YAAY,UAAQ;AAChB,aAAS,cAAc;AACvB,UAAM,QAAQ;AAEd,UAAM,iBAAiB;MACnB,WAAW,SAAS,YAAY,GAAG,SAAS,SAAS,YAAY;MACjE,YAAY,SAAS;MACrB,QAAQ,SAAS;MACjB,UAAU,SAAS;MACnB,WAAW,MAAK;AACZ,aAAK,UAAS;MAClB;;AAEJ,SAAK,gBAAgB,IAAI,qDAAsB,cAAc;EACjE;EAEA,MAAM,UAAO;AACT,UAAM,MAAM,QAAO;AACnB,UAAM,KAAK,cAAc,QAAO;EACpC;EAEA,YAAS;AACL,WAAO,KAAK,cAAc,UAAS;EACvC;EAEA,kBAAkB,SAAO;AACrB,WAAO,KAAK,cAAc,kBAAkB,OAAO;EACvD;EAEA,UAAU,IAAI,MAAI;AACd,WAAO,KAAK,cAAc,UAAU,IAAI,IAAI;EAChD;;",
4
+ "sourcesContent": ["/**\n * States DB in memory - Server with Redis protocol\n *\n * Copyright 2013-2024 bluefox <dogafox@gmail.com>\n *\n * MIT License\n *\n */\n\nimport { Client as ObjectsInRedisClient } from '@iobroker/db-objects-redis';\nimport { ObjectsInMemoryServer } from './objectsInMemServerRedis.js';\n\n/**\n * Objects database client that also starts an in-memory server speaking the Redis protocol\n */\nexport class ObjectsInMemoryServerClass extends ObjectsInRedisClient {\n /**\n * @param settings Settings for the objects client and the in-memory server\n */\n constructor(settings) {\n settings.autoConnect = false; // delay Client connection to when we need it\n super(settings);\n\n const serverSettings = {\n namespace: settings.namespace ? `${settings.namespace}-Server` : 'Server',\n connection: settings.connection,\n logger: settings.logger,\n hostname: settings.hostname,\n connected: () => {\n this.connectDb(); // now that server is connected also connect client\n },\n };\n this.objectsServer = new ObjectsInMemoryServer(serverSettings);\n }\n\n /**\n * Destroy the client first and the in-memory server afterwards\n */\n async destroy() {\n await super.destroy(); // destroy client first\n await this.objectsServer.destroy(); // server afterwards too\n }\n\n /**\n * Get the status as reported by the in-memory server\n */\n getStatus() {\n return this.objectsServer.getStatus(); // return Status as Server\n }\n\n /**\n * Synchronize the file directory of the in-memory server\n *\n * @param limitId Optional object ID to limit the synchronization to\n */\n syncFileDirectory(limitId) {\n return this.objectsServer.syncFileDirectory(limitId);\n }\n\n /**\n * Check whether a directory exists in the in-memory server's file storage\n *\n * @param id The object ID owning the files\n * @param name The directory path to check\n */\n dirExists(id, name) {\n return this.objectsServer.dirExists(id, name);\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;AASA,8BAA+C;AAC/C,qCAAsC;AAKhC,MAAO,mCAAmC,wBAAAA,OAAoB;;;;EAIhE,YAAY,UAAQ;AAChB,aAAS,cAAc;AACvB,UAAM,QAAQ;AAEd,UAAM,iBAAiB;MACnB,WAAW,SAAS,YAAY,GAAG,SAAS,SAAS,YAAY;MACjE,YAAY,SAAS;MACrB,QAAQ,SAAS;MACjB,UAAU,SAAS;MACnB,WAAW,MAAK;AACZ,aAAK,UAAS;MAClB;;AAEJ,SAAK,gBAAgB,IAAI,qDAAsB,cAAc;EACjE;;;;EAKA,MAAM,UAAO;AACT,UAAM,MAAM,QAAO;AACnB,UAAM,KAAK,cAAc,QAAO;EACpC;;;;EAKA,YAAS;AACL,WAAO,KAAK,cAAc,UAAS;EACvC;;;;;;EAOA,kBAAkB,SAAO;AACrB,WAAO,KAAK,cAAc,kBAAkB,OAAO;EACvD;;;;;;;EAQA,UAAU,IAAI,MAAI;AACd,WAAO,KAAK,cAAc,UAAU,IAAI,IAAI;EAChD;;",
6
6
  "names": ["ObjectsInRedisClient"]
7
7
  }
@@ -3,12 +3,6 @@
3
3
  * to access the methods via redis protocol
4
4
  */
5
5
  export class ObjectsInMemoryServer extends ObjectsInMemoryJsonlDB {
6
- /**
7
- * Constructor
8
- *
9
- * @param settings State and InMem-DB settings
10
- */
11
- constructor(settings: any);
12
6
  serverConnections: {};
13
7
  namespaceObjects: string;
14
8
  namespaceFile: string;
@@ -63,7 +57,7 @@ export class ObjectsInMemoryServer extends ObjectsInMemoryJsonlDB {
63
57
  /**
64
58
  * Return connected RedisHandlers/Connections
65
59
  *
66
- * @returns
60
+ * @returns the currently connected RedisHandlers/Connections
67
61
  */
68
62
  getClients(): {};
69
63
  /**
@@ -85,7 +79,7 @@ export class ObjectsInMemoryServer extends ObjectsInMemoryJsonlDB {
85
79
  * Initialize Redis Server
86
80
  *
87
81
  * @param settings Settings object
88
- * @returns
82
+ * @returns a promise that resolves once the Redis server is listening
89
83
  */
90
84
  _initRedisServer(settings: any): Promise<any>;
91
85
  server: net.Server | undefined;
@@ -659,7 +659,7 @@ class ObjectsInMemoryServer extends import_objectsInMemJsonlDB.ObjectsInMemoryJs
659
659
  /**
660
660
  * Return connected RedisHandlers/Connections
661
661
  *
662
- * @returns
662
+ * @returns the currently connected RedisHandlers/Connections
663
663
  */
664
664
  getClients() {
665
665
  return this.serverConnections;
@@ -784,7 +784,7 @@ class ObjectsInMemoryServer extends import_objectsInMemJsonlDB.ObjectsInMemoryJs
784
784
  * Initialize Redis Server
785
785
  *
786
786
  * @param settings Settings object
787
- * @returns
787
+ * @returns a promise that resolves once the Redis server is listening
788
788
  */
789
789
  _initRedisServer(settings) {
790
790
  return new Promise((resolve, reject) => {
@@ -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';\n\nimport { RedisHandler } from '@iobroker/db-base';\nimport { ObjectsInMemoryJsonlDB } from './objectsInMemJsonlDB.js';\nimport { EXIT_CODES } from '@iobroker/js-controller-common-db';\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 statesInMemoryJsonlDB class and adds redis communication layer\n * to access the methods via redis protocol\n */\nexport class ObjectsInMemoryServer extends ObjectsInMemoryJsonlDB {\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\n if (namespace === this.namespaceFile || namespace === this.namespaceObjects) {\n if (isMeta !== undefined) {\n // such a request should never happen\n return handler.sendArray(responseId, isScan ? ['0', []] : []); // send out file or full db response\n }\n\n // Handle request to get meta data keys\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 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 JSONL-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';\n\nimport { RedisHandler } from '@iobroker/db-base';\nimport { ObjectsInMemoryJsonlDB } from './objectsInMemJsonlDB.js';\nimport { EXIT_CODES } from '@iobroker/js-controller-common-db';\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 statesInMemoryJsonlDB class and adds redis communication layer\n * to access the methods via redis protocol\n */\nexport class ObjectsInMemoryServer extends ObjectsInMemoryJsonlDB {\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\n if (namespace === this.namespaceFile || namespace === this.namespaceObjects) {\n if (isMeta !== undefined) {\n // such a request should never happen\n return handler.sendArray(responseId, isScan ? ['0', []] : []); // send out file or full db response\n }\n\n // Handle request to get meta data keys\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 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 JSONL-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;AAEhC,IAAAA,kBAA6B;AAC7B,iCAAuC;AACvC,qCAA2B;AA2BrB,MAAO,8BAA8B,kDAAsB;;;;;;EAM7D,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,S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