@iobroker/db-base 1.2.2 → 4.0.0-alpha.10-20211116-cb8ad50a
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/lib/inMemFileDB.js +11 -8
- package/lib/tools.js +3 -47
- package/package.json +11 -6
package/lib/inMemFileDB.js
CHANGED
|
@@ -286,15 +286,17 @@ class InMemoryFileDB {
|
|
|
286
286
|
* Handle saving the dataset incl. backups
|
|
287
287
|
*/
|
|
288
288
|
async saveState() {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
this.stateTimer = null;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const jsonString = await this.saveDataset();
|
|
289
|
+
try {
|
|
290
|
+
const jsonString = await this.saveDataset();
|
|
295
291
|
|
|
296
|
-
|
|
297
|
-
|
|
292
|
+
if (!this.settings.backup.disabled && jsonString) {
|
|
293
|
+
this.saveBackup(jsonString);
|
|
294
|
+
}
|
|
295
|
+
} finally {
|
|
296
|
+
if (this.stateTimer) {
|
|
297
|
+
clearTimeout(this.stateTimer);
|
|
298
|
+
this.stateTimer = null;
|
|
299
|
+
}
|
|
298
300
|
}
|
|
299
301
|
}
|
|
300
302
|
|
|
@@ -432,6 +434,7 @@ class InMemoryFileDB {
|
|
|
432
434
|
// Destructor of the class. Called by shutting down.
|
|
433
435
|
async destroy() {
|
|
434
436
|
if (this.stateTimer) {
|
|
437
|
+
clearTimeout(this.stateTimer);
|
|
435
438
|
await this.saveState();
|
|
436
439
|
}
|
|
437
440
|
}
|
package/lib/tools.js
CHANGED
|
@@ -1,51 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
const fs = require('fs');
|
|
1
|
+
const { tools } = require('@iobroker/js-controller-common');
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
for (const pkg of possibilities) {
|
|
7
|
-
try {
|
|
8
|
-
// package.json is guaranteed to be in the module root folder
|
|
9
|
-
// so once that is resolved, take the dirname and we're done
|
|
10
|
-
const possiblePath = require.resolve(`${pkg}/package.json`);
|
|
11
|
-
if (fs.existsSync(possiblePath)) {
|
|
12
|
-
return path.dirname(possiblePath);
|
|
13
|
-
}
|
|
14
|
-
} catch {
|
|
15
|
-
/* not found */
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Apparently, checking vs null/undefined may miss the odd case of controllerPath being ""
|
|
20
|
-
// Thus we check for falsyness, which includes failing on an empty path
|
|
21
|
-
let checkPath = path.join(__dirname, '../..');
|
|
22
|
-
// Also check in the current check dir (along with iobroker.js-controller subdirs)
|
|
23
|
-
possibilities.unshift('');
|
|
24
|
-
while (true) {
|
|
25
|
-
for (const pkg of possibilities) {
|
|
26
|
-
try {
|
|
27
|
-
const possiblePath = path.join(checkPath, pkg);
|
|
28
|
-
if (fs.existsSync(path.join(possiblePath, 'lib/tools.js'))) {
|
|
29
|
-
return possiblePath;
|
|
30
|
-
}
|
|
31
|
-
} catch {
|
|
32
|
-
// not found, continue with next possiblity
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Controller not found here - go to the parent dir
|
|
37
|
-
const newPath = path.dirname(checkPath);
|
|
38
|
-
if (newPath === checkPath) {
|
|
39
|
-
// We already reached the root dir, abort
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
checkPath = newPath;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const controllerDir = getControllerDir() || __dirname;
|
|
47
|
-
|
|
48
|
-
module.exports = require(path.join(controllerDir , 'lib/tools.js'));
|
|
3
|
+
module.exports = tools;
|
|
4
|
+
const controllerDir = tools.getControllerDir() || __dirname;
|
|
49
5
|
module.exports.getControllerDir = () => controllerDir;
|
|
50
6
|
|
|
51
7
|
/**
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iobroker/db-base",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.10-20211116-cb8ad50a",
|
|
4
4
|
"engines": {
|
|
5
|
-
"node": ">=
|
|
5
|
+
"node": ">=12.0.0"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"@iobroker/js-controller-common": "4.0.0-alpha.10-20211116-cb8ad50a",
|
|
8
9
|
"deep-clone": "^3.0.3",
|
|
9
|
-
"fs-extra": "^
|
|
10
|
+
"fs-extra": "^10.0.0",
|
|
10
11
|
"node.extend": "^2.0.2",
|
|
11
12
|
"respjs": "^4.2.0"
|
|
12
13
|
},
|
|
@@ -19,11 +20,11 @@
|
|
|
19
20
|
"contributors": [
|
|
20
21
|
"bluefox <dogafox@gmail.com>",
|
|
21
22
|
"Apollon77 <iobroker@fischer-ka.de>",
|
|
22
|
-
"foxriver76"
|
|
23
|
+
"foxriver76 <moritz.heusinger@gmail.com>"
|
|
23
24
|
],
|
|
24
25
|
"repository": {
|
|
25
26
|
"type": "git",
|
|
26
|
-
"url": "https://github.com/ioBroker/ioBroker.
|
|
27
|
+
"url": "https://github.com/ioBroker/ioBroker.js-controller/packages/db-base"
|
|
27
28
|
},
|
|
28
29
|
"scripts": {},
|
|
29
30
|
"main": "index.js",
|
|
@@ -31,5 +32,9 @@
|
|
|
31
32
|
"publishConfig": {
|
|
32
33
|
"access": "public"
|
|
33
34
|
},
|
|
34
|
-
"
|
|
35
|
+
"files": [
|
|
36
|
+
"lib/",
|
|
37
|
+
"index.js"
|
|
38
|
+
],
|
|
39
|
+
"gitHead": "7e4b1475d5d59e3540a6111f69f8a3bc9536f751"
|
|
35
40
|
}
|