@iobroker/db-objects-jsonl 4.0.21 → 4.1.0-alpha.0-20220819-74ceeddc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +4 -0
- package/{index.js → build/index.js} +2 -0
- package/build/lib/objects/objectsInMemJsonlDB.d.ts +21 -0
- package/build/lib/objects/objectsInMemJsonlDB.d.ts.map +1 -0
- package/{lib → build/lib}/objects/objectsInMemJsonlDB.js +75 -55
- package/build/lib/objects/objectsInMemJsonlDB.js.map +1 -0
- package/build/lib/objects/objectsInMemServerClass.d.ts +14 -0
- package/build/lib/objects/objectsInMemServerClass.d.ts.map +1 -0
- package/{lib → build/lib}/objects/objectsInMemServerClass.js +1 -9
- package/build/lib/objects/objectsInMemServerClass.js.map +1 -0
- package/build/lib/objects/objectsInMemServerRedis.d.ts +89 -0
- package/build/lib/objects/objectsInMemServerRedis.d.ts.map +1 -0
- package/{lib → build/lib}/objects/objectsInMemServerRedis.js +222 -286
- package/build/lib/objects/objectsInMemServerRedis.js.map +1 -0
- package/package.json +14 -10
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export = ObjectsInMemoryJsonlDB;
|
|
2
|
+
declare const ObjectsInMemoryJsonlDB_base: typeof import("@iobroker/db-objects-file/build/lib/objects/objectsInMemFileDB");
|
|
3
|
+
/**
|
|
4
|
+
* This class inherits InMemoryFileDB class and adds all relevant logic for objects
|
|
5
|
+
* including the available methods for use by js-controller directly
|
|
6
|
+
**/
|
|
7
|
+
declare class ObjectsInMemoryJsonlDB extends ObjectsInMemoryJsonlDB_base {
|
|
8
|
+
constructor(settings: any);
|
|
9
|
+
/** @type {JsonlDB<any>} */
|
|
10
|
+
_db: JsonlDB<any>;
|
|
11
|
+
_backupInterval: NodeJS.Timer | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if an existing file DB should be migrated to JSONL
|
|
14
|
+
* @returns {Promise<boolean>} true if the file DB was migrated. false if not.
|
|
15
|
+
* If this returns true, the jsonl DB was opened and doesn't need to be opened again.
|
|
16
|
+
*/
|
|
17
|
+
_maybeMigrateFileDB(): Promise<boolean>;
|
|
18
|
+
saveBackup(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
import { JsonlDB } from "@alcalzone/jsonl-db";
|
|
21
|
+
//# sourceMappingURL=objectsInMemJsonlDB.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectsInMemJsonlDB.d.ts","sourceRoot":"","sources":["../../../src/lib/objects/objectsInMemJsonlDB.js"],"names":[],"mappings":";;AAoFA;;;IAGI;AACJ;IACI,2BAeC;IAFG,2BAA2B;IAC3B,KADW,QAAQ,GAAG,CAAC,CACiE;IA6CpF,0CAE+B;IAIvC;;;;OAIG;IACH,uBAHa,QAAQ,OAAO,CAAC,CAwE5B;IAOD,4BA2BC;CAYJ"}
|
|
@@ -6,20 +6,72 @@
|
|
|
6
6
|
* MIT License
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
9
|
/* jshint -W097 */
|
|
11
10
|
/* jshint strict: false */
|
|
12
11
|
/* jslint node: true */
|
|
13
12
|
/* jshint -W061 */
|
|
14
13
|
'use strict';
|
|
15
|
-
|
|
16
|
-
const ObjectsInMemoryFileDB = require('@iobroker/db-objects-file').ObjectsInMemoryFileDB;
|
|
14
|
+
const { ObjectsInMemoryFileDB } = require('@iobroker/db-objects-file');
|
|
17
15
|
const { JsonlDB } = require('@alcalzone/jsonl-db');
|
|
18
16
|
const path = require('path');
|
|
19
17
|
const fs = require('fs');
|
|
20
18
|
const os = require('os');
|
|
21
19
|
const { tools } = require('@iobroker/js-controller-common');
|
|
22
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Normalizes options for the JsonlDB
|
|
22
|
+
* @param {Record<string, any> | undefined} conf The jsonlOptions options from iobroker.json
|
|
23
|
+
* @returns {import("@alcalzone/jsonl-db").JsonlDBOptions<any>}
|
|
24
|
+
*/
|
|
25
|
+
function normalizeJsonlOptions(conf = {}) {
|
|
26
|
+
/** @type {import("@alcalzone/jsonl-db").JsonlDBOptions<any>} */
|
|
27
|
+
const ret = {
|
|
28
|
+
autoCompress: {
|
|
29
|
+
sizeFactor: 2,
|
|
30
|
+
sizeFactorMinimumSize: 25000
|
|
31
|
+
},
|
|
32
|
+
ignoreReadErrors: true,
|
|
33
|
+
throttleFS: {
|
|
34
|
+
intervalMs: 60000,
|
|
35
|
+
maxBufferedCommands: 1000
|
|
36
|
+
},
|
|
37
|
+
lockfile: {
|
|
38
|
+
// 5 retries starting at 250ms add up to just above 2s,
|
|
39
|
+
// so the DB has 3 more seconds to load all data if it wants to stay within the 5s connectionTimeout
|
|
40
|
+
retries: 5,
|
|
41
|
+
retryMinTimeoutMs: 250,
|
|
42
|
+
// This makes sure the DB stays locked for maximum 2s even if the process crashes
|
|
43
|
+
staleMs: 2000
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
// Be really careful what we allow here. Incorrect settings may cause problems in production.
|
|
47
|
+
if (tools.isObject(conf.autoCompress)) {
|
|
48
|
+
const ac = conf.autoCompress;
|
|
49
|
+
// Letting the DB grow more than 100x is risky
|
|
50
|
+
if (typeof ac.sizeFactor === 'number' && ac.sizeFactor >= 2 && ac.sizeFactor <= 100) {
|
|
51
|
+
ret.autoCompress.sizeFactor = ac.sizeFactor;
|
|
52
|
+
}
|
|
53
|
+
// Also we should definitely compress once the DB has reached 100k lines or it might grow too big
|
|
54
|
+
if (typeof ac.sizeFactorMinimumSize === 'number' &&
|
|
55
|
+
ac.sizeFactorMinimumSize >= 0 &&
|
|
56
|
+
ac.sizeFactorMinimumSize <= 100000) {
|
|
57
|
+
ret.autoCompress.sizeFactorMinimumSize = ac.sizeFactorMinimumSize;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (tools.isObject(conf.throttleFS)) {
|
|
61
|
+
const thr = conf.throttleFS;
|
|
62
|
+
// Don't write more often than every second and write at least once every hour
|
|
63
|
+
if (typeof thr.intervalMs === 'number' && thr.intervalMs >= 1000 && thr.intervalMs <= 3600000) {
|
|
64
|
+
ret.throttleFS.intervalMs = thr.intervalMs;
|
|
65
|
+
}
|
|
66
|
+
// Don't keep too much in memory - 100k changes are more than enough
|
|
67
|
+
if (typeof thr.maxBufferedCommands === 'number' &&
|
|
68
|
+
thr.maxBufferedCommands >= 0 &&
|
|
69
|
+
thr.maxBufferedCommands <= 100000) {
|
|
70
|
+
ret.throttleFS.maxBufferedCommands = thr.maxBufferedCommands;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return ret;
|
|
74
|
+
}
|
|
23
75
|
/**
|
|
24
76
|
* This class inherits InMemoryFileDB class and adds all relevant logic for objects
|
|
25
77
|
* including the available methods for use by js-controller directly
|
|
@@ -31,41 +83,18 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
|
|
|
31
83
|
fileName: 'objects.json',
|
|
32
84
|
backupDirName: 'backup-objects'
|
|
33
85
|
};
|
|
34
|
-
|
|
35
|
-
/** @type {import("@alcalzone/jsonl-db").JsonlDBOptions<any>} */
|
|
36
|
-
const jsonlOptions = settings.connection.jsonlOptions || {
|
|
37
|
-
autoCompress: {
|
|
38
|
-
sizeFactor: 2,
|
|
39
|
-
sizeFactorMinimumSize: 25000
|
|
40
|
-
},
|
|
41
|
-
ignoreReadErrors: true,
|
|
42
|
-
throttleFS: {
|
|
43
|
-
intervalMs: 60000,
|
|
44
|
-
maxBufferedCommands: 1000
|
|
45
|
-
},
|
|
46
|
-
lockfile: {
|
|
47
|
-
// 5 retries starting at 250ms add up to just above 2s,
|
|
48
|
-
// so the DB has 3 more seconds to load all data if it wants to stay within the 5s connectionTimeout
|
|
49
|
-
retries: 5,
|
|
50
|
-
retryMinTimeoutMs: 250,
|
|
51
|
-
// This makes sure the DB stays locked for maximum 2s even if the process crashes
|
|
52
|
-
staleMs: 2000
|
|
53
|
-
}
|
|
54
|
-
};
|
|
86
|
+
const jsonlOptions = normalizeJsonlOptions(settings.connection.jsonlOptions);
|
|
55
87
|
settings.jsonlDB = {
|
|
56
88
|
fileName: 'objects.jsonl'
|
|
57
89
|
};
|
|
58
90
|
super(settings);
|
|
59
|
-
|
|
60
91
|
/** @type {JsonlDB<any>} */
|
|
61
92
|
this._db = new JsonlDB(path.join(this.dataDir, settings.jsonlDB.fileName), jsonlOptions);
|
|
62
93
|
}
|
|
63
|
-
|
|
64
94
|
async open() {
|
|
65
95
|
if (!(await this._maybeMigrateFileDB())) {
|
|
66
96
|
await this._db.open();
|
|
67
97
|
}
|
|
68
|
-
|
|
69
98
|
// Create an object-like wrapper around the internal Map
|
|
70
99
|
this.dataset = new Proxy(this._db, {
|
|
71
100
|
/** @param {any} prop */
|
|
@@ -101,14 +130,12 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
|
|
|
101
130
|
};
|
|
102
131
|
}
|
|
103
132
|
});
|
|
104
|
-
|
|
105
133
|
if (this.settings.backup && this.settings.backup.period && !this.settings.backup.disabled) {
|
|
106
134
|
this._backupInterval = setInterval(() => {
|
|
107
135
|
this.saveBackup();
|
|
108
136
|
}, this.settings.backup.period);
|
|
109
137
|
}
|
|
110
138
|
}
|
|
111
|
-
|
|
112
139
|
/**
|
|
113
140
|
* Checks if an existing file DB should be migrated to JSONL
|
|
114
141
|
* @returns {Promise<boolean>} true if the file DB was migrated. false if not.
|
|
@@ -118,7 +145,6 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
|
|
|
118
145
|
const jsonlFileName = path.join(this.dataDir, this.settings.jsonlDB.fileName);
|
|
119
146
|
const jsonFileName = path.join(this.dataDir, this.settings.fileDB.fileName);
|
|
120
147
|
const bakFileName = path.join(this.dataDir, this.settings.fileDB.fileName + '.bak');
|
|
121
|
-
|
|
122
148
|
// Check the timestamps of each file, defaulting to 0 if they don't exist
|
|
123
149
|
let jsonlTimeStamp = 0;
|
|
124
150
|
let jsonTimeStamp = 0;
|
|
@@ -128,7 +154,8 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
|
|
|
128
154
|
if (stat.isFile()) {
|
|
129
155
|
jsonlTimeStamp = stat.mtime;
|
|
130
156
|
}
|
|
131
|
-
}
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
132
159
|
// ignore
|
|
133
160
|
}
|
|
134
161
|
try {
|
|
@@ -136,7 +163,8 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
|
|
|
136
163
|
if (stat.isFile()) {
|
|
137
164
|
jsonTimeStamp = stat.mtime;
|
|
138
165
|
}
|
|
139
|
-
}
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
140
168
|
// ignore
|
|
141
169
|
}
|
|
142
170
|
try {
|
|
@@ -144,84 +172,76 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
|
|
|
144
172
|
if (stat.isFile()) {
|
|
145
173
|
bakTimeStamp = stat.mtime;
|
|
146
174
|
}
|
|
147
|
-
}
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
148
177
|
// ignore
|
|
149
178
|
}
|
|
150
|
-
|
|
151
179
|
// Figure out which file needs to be imported
|
|
152
180
|
/** @type {string} */
|
|
153
181
|
let importFilename;
|
|
154
182
|
if (jsonTimeStamp > 0 && jsonTimeStamp >= bakTimeStamp && jsonTimeStamp >= jsonlTimeStamp) {
|
|
155
183
|
importFilename = jsonFileName;
|
|
156
|
-
}
|
|
184
|
+
}
|
|
185
|
+
else if (bakTimeStamp > 0 && bakTimeStamp >= jsonTimeStamp && bakTimeStamp >= jsonlTimeStamp) {
|
|
157
186
|
importFilename = bakFileName;
|
|
158
|
-
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
159
189
|
// None of the File DB files are newer than the JSONL file
|
|
160
190
|
// There is nothing to restore, we're done
|
|
161
191
|
return false;
|
|
162
192
|
}
|
|
163
|
-
|
|
164
193
|
await this._db.open();
|
|
165
194
|
this._db.clear();
|
|
166
195
|
await this._db.importJson(importFilename);
|
|
167
|
-
|
|
168
196
|
// And rename the existing files to avoid redoing the work next time
|
|
169
197
|
if (fs.existsSync(jsonFileName)) {
|
|
170
198
|
try {
|
|
171
199
|
fs.renameSync(jsonFileName, `${jsonFileName}.migrated`);
|
|
172
|
-
}
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
173
202
|
// ignore
|
|
174
203
|
}
|
|
175
204
|
}
|
|
176
205
|
if (fs.existsSync(bakFileName)) {
|
|
177
206
|
try {
|
|
178
207
|
fs.renameSync(bakFileName, `${bakFileName}.migrated`);
|
|
179
|
-
}
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
180
210
|
// ignore
|
|
181
211
|
}
|
|
182
212
|
}
|
|
183
|
-
|
|
184
213
|
// Signal to the caller that the DB is already open
|
|
185
214
|
return true;
|
|
186
215
|
}
|
|
187
|
-
|
|
188
216
|
async saveState() {
|
|
189
217
|
// Nothing to do, the DB saves behind the scenes
|
|
190
218
|
}
|
|
191
|
-
|
|
192
219
|
// Is regularly called and stores a compressed backup of the DB
|
|
193
220
|
async saveBackup() {
|
|
194
221
|
const now = Date.now();
|
|
195
222
|
const tmpBackupFileName = path.join(os.tmpdir(), `${this.getTimeStr(now)}_${this.settings.jsonlDB.fileName}`);
|
|
196
|
-
const backupFileName = path.join(
|
|
197
|
-
this.backupDir,
|
|
198
|
-
`${this.getTimeStr(now)}_${this.settings.jsonlDB.fileName}.gz`
|
|
199
|
-
);
|
|
200
|
-
|
|
223
|
+
const backupFileName = path.join(this.backupDir, `${this.getTimeStr(now)}_${this.settings.jsonlDB.fileName}.gz`);
|
|
201
224
|
if (!this._db.isOpen) {
|
|
202
225
|
this.log.warn(`${this.namespace} Cannot save backup ${backupFileName}: DB is closed`);
|
|
203
226
|
return;
|
|
204
227
|
}
|
|
205
|
-
|
|
206
228
|
try {
|
|
207
229
|
if (fs.existsSync(backupFileName)) {
|
|
208
230
|
return;
|
|
209
231
|
}
|
|
210
|
-
|
|
211
232
|
// Create a DB dump
|
|
212
233
|
await this._db.dump(tmpBackupFileName);
|
|
213
234
|
// and zip it
|
|
214
235
|
await tools.compressFileGZip(tmpBackupFileName, backupFileName, { deleteInput: true });
|
|
215
236
|
// figure out if older files need to be deleted
|
|
216
237
|
this.deleteOldBackupFiles(this.settings.jsonlDB.fileName);
|
|
217
|
-
}
|
|
238
|
+
}
|
|
239
|
+
catch (e) {
|
|
218
240
|
this.log.error(`${this.namespace} Cannot save backup ${backupFileName}: ${e.message}`);
|
|
219
241
|
}
|
|
220
242
|
}
|
|
221
|
-
|
|
222
243
|
async destroy() {
|
|
223
244
|
await super.destroy();
|
|
224
|
-
|
|
225
245
|
if (this._backupInterval) {
|
|
226
246
|
clearInterval(this._backupInterval);
|
|
227
247
|
}
|
|
@@ -230,5 +250,5 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
|
|
|
230
250
|
}
|
|
231
251
|
}
|
|
232
252
|
}
|
|
233
|
-
|
|
234
253
|
module.exports = ObjectsInMemoryJsonlDB;
|
|
254
|
+
//# sourceMappingURL=objectsInMemJsonlDB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectsInMemJsonlDB.js","sourceRoot":"","sources":["../../../src/lib/objects/objectsInMemJsonlDB.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,kBAAkB;AAClB,0BAA0B;AAC1B,uBAAuB;AACvB,kBAAkB;AAClB,YAAY,CAAC;AAEb,MAAM,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACvE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AACnD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,MAAM,E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ACL,CAAC;CACJ;AAED,MAAM,CAAC,OAAO,GAAG,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export = ObjectsInMemoryServerClass;
|
|
2
|
+
declare class ObjectsInMemoryServerClass extends ObjectsInRedisClient {
|
|
3
|
+
constructor(settings: any);
|
|
4
|
+
objectsServer: ObjectsInMemServer;
|
|
5
|
+
syncFileDirectory(limitId: any): {
|
|
6
|
+
numberSuccess: number;
|
|
7
|
+
notifications: any[];
|
|
8
|
+
};
|
|
9
|
+
dirExists(id: any, name: any): boolean;
|
|
10
|
+
}
|
|
11
|
+
import ObjectsInRedisClient_1 = require("@iobroker/db-objects-redis/build/lib/objects/objectsInRedisClient");
|
|
12
|
+
import ObjectsInRedisClient = ObjectsInRedisClient_1.Client;
|
|
13
|
+
import ObjectsInMemServer = require("./objectsInMemServerRedis");
|
|
14
|
+
//# sourceMappingURL=objectsInMemServerClass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectsInMemServerClass.d.ts","sourceRoot":"","sources":["../../../src/lib/objects/objectsInMemServerClass.js"],"names":[],"mappings":";AAmBA;IACI,2BAcC;IADG,kCAA2D;IAY/D;;;MAEC;IAED,uCAEC;CACJ;;qDApCkE,MAAM"}
|
|
@@ -6,22 +6,17 @@
|
|
|
6
6
|
* MIT License
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
9
|
/** @module statesInMemory */
|
|
11
|
-
|
|
12
10
|
/* jshint -W097 */
|
|
13
11
|
/* jshint strict:false */
|
|
14
12
|
/* jslint node: true */
|
|
15
13
|
'use strict';
|
|
16
|
-
|
|
17
14
|
const ObjectsInRedisClient = require('@iobroker/db-objects-redis').Client;
|
|
18
15
|
const ObjectsInMemServer = require('./objectsInMemServerRedis');
|
|
19
|
-
|
|
20
16
|
class ObjectsInMemoryServerClass extends ObjectsInRedisClient {
|
|
21
17
|
constructor(settings) {
|
|
22
18
|
settings.autoConnect = false; // delay Client connection to when we need it
|
|
23
19
|
super(settings);
|
|
24
|
-
|
|
25
20
|
const serverSettings = {
|
|
26
21
|
namespace: settings.namespace ? `${settings.namespace}-Server` : 'Server',
|
|
27
22
|
connection: settings.connection,
|
|
@@ -33,22 +28,19 @@ class ObjectsInMemoryServerClass extends ObjectsInRedisClient {
|
|
|
33
28
|
};
|
|
34
29
|
this.objectsServer = new ObjectsInMemServer(serverSettings);
|
|
35
30
|
}
|
|
36
|
-
|
|
37
31
|
async destroy() {
|
|
38
32
|
await super.destroy(); // destroy client first
|
|
39
33
|
await this.objectsServer.destroy(); // server afterwards too
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
getStatus() {
|
|
43
36
|
return this.objectsServer.getStatus(); // return Status as Server
|
|
44
37
|
}
|
|
45
|
-
|
|
46
38
|
syncFileDirectory(limitId) {
|
|
47
39
|
return this.objectsServer.syncFileDirectory(limitId);
|
|
48
40
|
}
|
|
49
|
-
|
|
50
41
|
dirExists(id, name) {
|
|
51
42
|
return this.objectsServer.dirExists(id, name);
|
|
52
43
|
}
|
|
53
44
|
}
|
|
54
45
|
module.exports = ObjectsInMemoryServerClass;
|
|
46
|
+
//# sourceMappingURL=objectsInMemServerClass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectsInMemServerClass.js","sourceRoot":"","sources":["../../../src/lib/objects/objectsInMemServerClass.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,6BAA6B;AAE7B,kBAAkB;AAClB,yBAAyB;AACzB,uBAAuB;AACvB,YAAY,CAAC;AAEb,MAAM,oBAAoB,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC,MAAM,CAAC;AAC1E,MAAM,kBAAkB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAEhE,MAAM,0BAA2B,SAAQ,oBAAoB;IACzD,YAAY,QAAQ;QAChB,QAAQ,CAAC,WAAW,GAAG,KAAK,CAAC,CAAC,6CAA6C;QAC3E,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEhB,MAAM,cAAc,GAAG;YACnB,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,QAAQ;YACzE,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,SAAS,EAAE,GAAG,EAAE;gBACZ,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,mDAAmD;YACzE,CAAC;SACJ,CAAC;QACF,IAAI,CAAC,aAAa,GAAG,IAAI,kBAAkB,CAAC,cAAc,CAAC,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,OAAO;QACT,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,uBAAuB;QAC9C,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC,wBAAwB;IAChE,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC,CAAC,0BAA0B;IACrE,CAAC;IAED,iBAAiB,CAAC,OAAO;QACrB,OAAO,IAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC;IAED,SAAS,CAAC,EAAE,EAAE,IAAI;QACd,OAAO,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;CACJ;AACD,MAAM,CAAC,OAAO,GAAG,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export = ObjectsInMemoryServer;
|
|
3
|
+
/**
|
|
4
|
+
* This class inherits statesInMemoryJsonlDB class and adds redis communication layer
|
|
5
|
+
* to access the methods via redis protocol
|
|
6
|
+
**/
|
|
7
|
+
declare class ObjectsInMemoryServer extends ObjectsInMemoryJsonlDB {
|
|
8
|
+
/**
|
|
9
|
+
* Constructor
|
|
10
|
+
* @param settings State and InMem-DB settings
|
|
11
|
+
*/
|
|
12
|
+
constructor(settings: any);
|
|
13
|
+
serverConnections: {};
|
|
14
|
+
namespaceObjects: string;
|
|
15
|
+
namespaceFile: string;
|
|
16
|
+
namespaceObj: string;
|
|
17
|
+
namespaceSet: string;
|
|
18
|
+
namespaceSetLen: number;
|
|
19
|
+
namespaceFileLen: number;
|
|
20
|
+
namespaceObjLen: number;
|
|
21
|
+
namespaceMeta: string;
|
|
22
|
+
namespaceMetaLen: number;
|
|
23
|
+
knownScripts: {};
|
|
24
|
+
normalizeFileRegex1: RegExp;
|
|
25
|
+
normalizeFileRegex2: RegExp;
|
|
26
|
+
/**
|
|
27
|
+
* Separate Namespace from ID and return both
|
|
28
|
+
* @param idWithNamespace ID or Array of IDs containing a redis namespace and the real ID
|
|
29
|
+
* @returns {{namespace: (string); id: string; name?: string; isMeta?: boolean}} Object with namespace and the
|
|
30
|
+
* ID/Array of IDs without the namespace
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
private _normalizeId;
|
|
34
|
+
/**
|
|
35
|
+
* Publish a subscribed value to one of the redis connections in redis format
|
|
36
|
+
* @param client Instance of RedisHandler
|
|
37
|
+
* @param type Type of subscribed key
|
|
38
|
+
* @param id Subscribed ID
|
|
39
|
+
* @param obj Object to publish
|
|
40
|
+
* @returns {number} Publish counter 0 or 1 depending on if send out or not
|
|
41
|
+
*/
|
|
42
|
+
publishToClients(client: any, type: any, id: any, obj: any): number;
|
|
43
|
+
/**
|
|
44
|
+
* Generate ID for a File
|
|
45
|
+
* @param id ID of the File
|
|
46
|
+
* @param name Name of the file
|
|
47
|
+
* @param isMeta generate a META ID or a Data ID?
|
|
48
|
+
* @returns {string} File-ID
|
|
49
|
+
*/
|
|
50
|
+
getFileId(id: any, name: any, isMeta: any): string;
|
|
51
|
+
/**
|
|
52
|
+
* Register all event listeners for Handler and implement the relevant logic
|
|
53
|
+
* @param handler RedisHandler instance
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
private _socketEvents;
|
|
57
|
+
/**
|
|
58
|
+
* Return connected RedisHandlers/Connections
|
|
59
|
+
* @returns {{}|*}
|
|
60
|
+
*/
|
|
61
|
+
getClients(): {} | any;
|
|
62
|
+
/**
|
|
63
|
+
* Get keys matching pattern and send it to given responseId, for "SCAN" and "KEYS" - Objects and files supported
|
|
64
|
+
*
|
|
65
|
+
* @param handler RedisHandler instance
|
|
66
|
+
* @param {string} pattern - pattern without namespace prefix
|
|
67
|
+
* @param {number} responseId - Id where response will be sent to
|
|
68
|
+
* @param {boolean} isScan - if used by "SCAN" this flag should be true
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
private _handleScanOrKeys;
|
|
72
|
+
/**
|
|
73
|
+
* Initialize RedisHandler for a new network connection
|
|
74
|
+
* @param socket Network socket
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
private _initSocket;
|
|
78
|
+
/**
|
|
79
|
+
* Initialize Redis Server
|
|
80
|
+
* @param settings Settings object
|
|
81
|
+
* @private
|
|
82
|
+
* @return {Promise<void>}
|
|
83
|
+
*/
|
|
84
|
+
private _initRedisServer;
|
|
85
|
+
server: net.Server | undefined;
|
|
86
|
+
}
|
|
87
|
+
import ObjectsInMemoryJsonlDB = require("./objectsInMemJsonlDB");
|
|
88
|
+
import net = require("net");
|
|
89
|
+
//# sourceMappingURL=objectsInMemServerRedis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectsInMemServerRedis.d.ts","sourceRoot":"","sources":["../../../src/lib/objects/objectsInMemServerRedis.js"],"names":[],"mappings":";;AA8CA;;;IAGI;AACJ;IACI;;;OAGG;IACH,2BA8CC;IA3CG,sBAA2B;IAC3B,yBAEO;IACP,sBAAiD;IACjD,qBAAgD;IAChD,qBAAgD;IAChD,wBAA+C;IAG/C,yBAAiD;IACjD,wBAA+C;IAC/C,sBAAgE;IAChE,yBAAiD;IAEjD,iBAAsB;IAEtB,4BAA4E;IAC5E,4BAAiE;IA2BrE;;;;;;OAMG;IACH,qBAwDC;IAED;;;;;;;OAOG;IACH,6DAFa,MAAM,CAgClB;IAED;;;;;;OAMG;IACH,4CAFa,MAAM,CAclB;IAED;;;;OAIG;IACH,sBAsmBC;IAED;;;OAGG;IACH,cAFa,EAAE,MAAE,CAIhB;IA4BD;;;;;;;;OAQG;IACH,0BAkEC;IAED;;;;OAIG;IACH,oBAmBC;IAED;;;;;OAKG;IACH,yBAyBC;IAnBW,+BAAgC;CAoB/C"}
|