@iobroker/js-controller-common-db 4.0.0-alpha.8-20210909-001a711c → 4.0.3
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/LICENSE +1 -1
- package/README.md +1 -1
- package/build/index.d.ts +4 -0
- package/build/index.js +28 -0
- package/build/lib/common/objects.d.ts +2 -0
- package/build/lib/common/objects.d.ts.map +1 -0
- package/build/lib/common/objects.js +41 -0
- package/build/lib/common/objects.js.map +1 -0
- package/build/lib/common/states.d.ts +2 -0
- package/build/lib/common/states.d.ts.map +1 -0
- package/build/lib/common/states.js +41 -0
- package/build/lib/common/states.js.map +1 -0
- package/build/lib/common/tools.d.ts +29 -0
- package/build/lib/common/tools.d.ts.map +1 -0
- package/build/lib/common/tools.js +74 -0
- package/build/lib/common/tools.js.map +1 -0
- package/package.json +18 -13
- package/index.js +0 -1
- package/lib/common/tools.js +0 -76
package/LICENSE
CHANGED
package/README.md
CHANGED
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.getObjectsConstructor = exports.getStatesConstructor = exports.tools = void 0;
|
|
23
|
+
exports.tools = __importStar(require("./lib/common/tools"));
|
|
24
|
+
var states_1 = require("./lib/common/states");
|
|
25
|
+
Object.defineProperty(exports, "getStatesConstructor", { enumerable: true, get: function () { return states_1.getStatesConstructor; } });
|
|
26
|
+
var objects_1 = require("./lib/common/objects");
|
|
27
|
+
Object.defineProperty(exports, "getObjectsConstructor", { enumerable: true, get: function () { return objects_1.getObjectsConstructor; } });
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objects.d.ts","sourceRoot":"","sources":["../../../src/lib/common/objects.ts"],"names":[],"mappings":"AAMA,wBAAgB,qBAAqB,IAAI,GAAG,CAa3C"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.getObjectsConstructor = void 0;
|
|
23
|
+
const fs = __importStar(require("fs-extra"));
|
|
24
|
+
// @ts-expect-error no typings yet
|
|
25
|
+
const js_controller_common_1 = require("@iobroker/js-controller-common");
|
|
26
|
+
function getObjectsConstructor() {
|
|
27
|
+
const config = fs.readJSONSync(js_controller_common_1.tools.getConfigFileName());
|
|
28
|
+
if (!config.objects) {
|
|
29
|
+
config.objects = { type: 'file' };
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
33
|
+
return require(`@iobroker/db-objects-${config.objects.type}`).Client;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
console.error(`Installation broken or unknown objects type: ${config.objects.type} configured.`);
|
|
37
|
+
process.exit(101);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.getObjectsConstructor = getObjectsConstructor;
|
|
41
|
+
//# sourceMappingURL=objects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objects.js","sourceRoot":"","sources":["../../../src/lib/common/objects.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;AAEb,6CAA+B;AAC/B,kCAAkC;AAClC,yEAAuD;AAEvD,SAAgB,qBAAqB;IACjC,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,4BAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC1D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;QACjB,MAAM,CAAC,OAAO,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;KACrC;IAED,IAAI;QACA,8DAA8D;QAC9D,OAAO,OAAO,CAAC,wBAAwB,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;KACxE;IAAC,MAAM;QACJ,OAAO,CAAC,KAAK,CAAC,gDAAgD,MAAM,CAAC,OAAO,CAAC,IAAI,cAAc,CAAC,CAAC;QACjG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACrB;AACL,CAAC;AAbD,sDAaC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"states.d.ts","sourceRoot":"","sources":["../../../src/lib/common/states.ts"],"names":[],"mappings":"AAMA,wBAAgB,oBAAoB,IAAI,GAAG,CAa1C"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.getStatesConstructor = void 0;
|
|
23
|
+
const fs = __importStar(require("fs-extra"));
|
|
24
|
+
// @ts-expect-error no typings yet
|
|
25
|
+
const js_controller_common_1 = require("@iobroker/js-controller-common");
|
|
26
|
+
function getStatesConstructor() {
|
|
27
|
+
const config = fs.readJSONSync(js_controller_common_1.tools.getConfigFileName());
|
|
28
|
+
if (!config.states) {
|
|
29
|
+
config.states = { type: 'file' };
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
33
|
+
return require(`@iobroker/db-states-${config.states.type}`).Client;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
console.error(`Installation broken or unknown states type: ${config.states.type} configured.`);
|
|
37
|
+
process.exit(101);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.getStatesConstructor = getStatesConstructor;
|
|
41
|
+
//# sourceMappingURL=states.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"states.js","sourceRoot":"","sources":["../../../src/lib/common/states.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;AAEb,6CAA+B;AAC/B,kCAAkC;AAClC,yEAAuD;AAEvD,SAAgB,oBAAoB;IAChC,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,4BAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC1D,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;QAChB,MAAM,CAAC,MAAM,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;KACpC;IAED,IAAI;QACA,8DAA8D;QAC9D,OAAO,OAAO,CAAC,uBAAuB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;KACtE;IAAC,MAAM;QACJ,OAAO,CAAC,KAAK,CAAC,+CAA+C,MAAM,CAAC,MAAM,CAAC,IAAI,cAAc,CAAC,CAAC;QAC/F,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACrB;AACL,CAAC;AAbD,oDAaC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allows to find out if a given states dbType offers a server or not
|
|
3
|
+
* @param dbType database type
|
|
4
|
+
* @returns true if a server class is available
|
|
5
|
+
*/
|
|
6
|
+
export declare function statesDbHasServer(dbType: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Allows to find out if a given objects dbType offers a server which runs on this host and listens (locally or globally/by IP)
|
|
9
|
+
* @param dbType database type
|
|
10
|
+
* @param host configured db host
|
|
11
|
+
* @param checkIfLocalOnly if true the method checks if the server listens to local connections only; else also external connection options are checked
|
|
12
|
+
* @returns true if a server listens on this host (locally or globally/by IP)
|
|
13
|
+
*/
|
|
14
|
+
export declare function isLocalObjectsDbServer(dbType: string, host: string, checkIfLocalOnly?: boolean): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Allows to find out if a given states dbType offers a server which runs on this host and listens (locally or globally/by IP)
|
|
17
|
+
* @param dbType database type
|
|
18
|
+
* @param host configured db host
|
|
19
|
+
* @param checkIfLocalOnly if true the method checks if the server listens to local connections only; else also external connection options are checked
|
|
20
|
+
* @returns true if a server listens on this host (locally or globally/by IP)
|
|
21
|
+
*/
|
|
22
|
+
export declare function isLocalStatesDbServer(dbType: string, host: string, checkIfLocalOnly?: boolean): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Allows to find out if a given objects dbType offers a server or not
|
|
25
|
+
* @param dbType database type
|
|
26
|
+
* @returns true if a server class is available
|
|
27
|
+
*/
|
|
28
|
+
export declare function objectsDbHasServer(dbType: string): boolean;
|
|
29
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/lib/common/tools.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAOzD;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,GAAE,OAAe,GAAG,OAAO,CAU/G;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,UAAQ,GAAG,OAAO,CAUrG;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAO1D"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objectsDbHasServer = exports.isLocalStatesDbServer = exports.isLocalObjectsDbServer = exports.statesDbHasServer = void 0;
|
|
4
|
+
// @ts-expect-error no typings yet
|
|
5
|
+
const js_controller_common_1 = require("@iobroker/js-controller-common");
|
|
6
|
+
/**
|
|
7
|
+
* Allows to find out if a given states dbType offers a server or not
|
|
8
|
+
* @param dbType database type
|
|
9
|
+
* @returns true if a server class is available
|
|
10
|
+
*/
|
|
11
|
+
function statesDbHasServer(dbType) {
|
|
12
|
+
try {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
14
|
+
return !!require(`@iobroker/db-states-${dbType}`).Server;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
throw new Error(`Installation error or unknown states database type: ${dbType}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.statesDbHasServer = statesDbHasServer;
|
|
21
|
+
/**
|
|
22
|
+
* Allows to find out if a given objects dbType offers a server which runs on this host and listens (locally or globally/by IP)
|
|
23
|
+
* @param dbType database type
|
|
24
|
+
* @param host configured db host
|
|
25
|
+
* @param checkIfLocalOnly if true the method checks if the server listens to local connections only; else also external connection options are checked
|
|
26
|
+
* @returns true if a server listens on this host (locally or globally/by IP)
|
|
27
|
+
*/
|
|
28
|
+
function isLocalObjectsDbServer(dbType, host, checkIfLocalOnly = false) {
|
|
29
|
+
if (!objectsDbHasServer(dbType)) {
|
|
30
|
+
return false; // if no server it can not be a local server
|
|
31
|
+
}
|
|
32
|
+
let result = host === 'localhost' || host === '127.0.0.1'; // reachable locally only
|
|
33
|
+
if (!checkIfLocalOnly) {
|
|
34
|
+
const ownIps = js_controller_common_1.tools.findIPs();
|
|
35
|
+
result = result || host === '0.0.0.0' || ownIps.includes(host);
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
exports.isLocalObjectsDbServer = isLocalObjectsDbServer;
|
|
40
|
+
/**
|
|
41
|
+
* Allows to find out if a given states dbType offers a server which runs on this host and listens (locally or globally/by IP)
|
|
42
|
+
* @param dbType database type
|
|
43
|
+
* @param host configured db host
|
|
44
|
+
* @param checkIfLocalOnly if true the method checks if the server listens to local connections only; else also external connection options are checked
|
|
45
|
+
* @returns true if a server listens on this host (locally or globally/by IP)
|
|
46
|
+
*/
|
|
47
|
+
function isLocalStatesDbServer(dbType, host, checkIfLocalOnly = false) {
|
|
48
|
+
if (!statesDbHasServer(dbType)) {
|
|
49
|
+
return false; // if no server it can not be a local server
|
|
50
|
+
}
|
|
51
|
+
let result = host === 'localhost' || host === '127.0.0.1'; // reachable locally only
|
|
52
|
+
if (!checkIfLocalOnly) {
|
|
53
|
+
const ownIps = js_controller_common_1.tools.findIPs();
|
|
54
|
+
result = result || host === '0.0.0.0' || ownIps.includes(host);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
exports.isLocalStatesDbServer = isLocalStatesDbServer;
|
|
59
|
+
/**
|
|
60
|
+
* Allows to find out if a given objects dbType offers a server or not
|
|
61
|
+
* @param dbType database type
|
|
62
|
+
* @returns true if a server class is available
|
|
63
|
+
*/
|
|
64
|
+
function objectsDbHasServer(dbType) {
|
|
65
|
+
try {
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
67
|
+
return !!require(`@iobroker/db-objects-${dbType}`).Server;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
throw new Error(`Installation error or unknown objects database type: ${dbType}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.objectsDbHasServer = objectsDbHasServer;
|
|
74
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/lib/common/tools.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AACb,kCAAkC;AAClC,yEAAuD;AAEvD;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,MAAc;IAC5C,IAAI;QACA,8DAA8D;QAC9D,OAAO,CAAC,CAAC,OAAO,CAAC,uBAAuB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;KAC5D;IAAC,MAAM;QACJ,MAAM,IAAI,KAAK,CAAC,uDAAuD,MAAM,EAAE,CAAC,CAAC;KACpF;AACL,CAAC;AAPD,8CAOC;AAED;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAAC,MAAc,EAAE,IAAY,EAAE,mBAA4B,KAAK;IAClG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE;QAC7B,OAAO,KAAK,CAAC,CAAC,4CAA4C;KAC7D;IACD,IAAI,MAAM,GAAG,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,WAAW,CAAC,CAAC,yBAAyB;IACpF,IAAI,CAAC,gBAAgB,EAAE;QACnB,MAAM,MAAM,GAAG,4BAAK,CAAC,OAAO,EAAE,CAAC;QAC/B,MAAM,GAAG,MAAM,IAAI,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;KAClE;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAVD,wDAUC;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB,CAAC,MAAc,EAAE,IAAY,EAAE,gBAAgB,GAAG,KAAK;IACxF,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE;QAC5B,OAAO,KAAK,CAAC,CAAC,4CAA4C;KAC7D;IACD,IAAI,MAAM,GAAG,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,WAAW,CAAC,CAAC,yBAAyB;IACpF,IAAI,CAAC,gBAAgB,EAAE;QACnB,MAAM,MAAM,GAAG,4BAAK,CAAC,OAAO,EAAE,CAAC;QAC/B,MAAM,GAAG,MAAM,IAAI,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;KAClE;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAVD,sDAUC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,MAAc;IAC7C,IAAI;QACA,8DAA8D;QAC9D,OAAO,CAAC,CAAC,OAAO,CAAC,wBAAwB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;KAC7D;IAAC,MAAM;QACJ,MAAM,IAAI,KAAK,CAAC,wDAAwD,MAAM,EAAE,CAAC,CAAC;KACrF;AACL,CAAC;AAPD,gDAOC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iobroker/js-controller-common-db",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=12.0.0"
|
|
6
6
|
},
|
|
@@ -9,13 +9,14 @@
|
|
|
9
9
|
"winston-syslog": "^2.4.4"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@iobroker/db-objects-file": "4.0.
|
|
13
|
-
"@iobroker/db-objects-jsonl": "4.0.
|
|
14
|
-
"@iobroker/db-objects-redis": "4.0.
|
|
15
|
-
"@iobroker/db-states-file": "4.0.
|
|
16
|
-
"@iobroker/db-states-jsonl": "4.0.
|
|
17
|
-
"@iobroker/db-states-redis": "4.0.
|
|
18
|
-
"@iobroker/js-controller-common": "4.0.
|
|
12
|
+
"@iobroker/db-objects-file": "4.0.3",
|
|
13
|
+
"@iobroker/db-objects-jsonl": "4.0.3",
|
|
14
|
+
"@iobroker/db-objects-redis": "4.0.3",
|
|
15
|
+
"@iobroker/db-states-file": "4.0.3",
|
|
16
|
+
"@iobroker/db-states-jsonl": "4.0.3",
|
|
17
|
+
"@iobroker/db-states-redis": "4.0.3",
|
|
18
|
+
"@iobroker/js-controller-common": "4.0.3",
|
|
19
|
+
"fs-extra": "^10.0.0"
|
|
19
20
|
},
|
|
20
21
|
"keywords": [
|
|
21
22
|
"ioBroker"
|
|
@@ -30,15 +31,19 @@
|
|
|
30
31
|
"type": "git",
|
|
31
32
|
"url": "https://github.com/ioBroker/ioBroker.js-controller/packages/common"
|
|
32
33
|
},
|
|
33
|
-
"scripts": {
|
|
34
|
-
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc -b tsconfig.build.json"
|
|
36
|
+
},
|
|
37
|
+
"main": "build/index.js",
|
|
38
|
+
"types": "build/index.d.ts",
|
|
35
39
|
"license": "MIT",
|
|
36
40
|
"publishConfig": {
|
|
37
41
|
"access": "public"
|
|
38
42
|
},
|
|
39
43
|
"files": [
|
|
40
|
-
"lib/",
|
|
41
|
-
"index.js"
|
|
44
|
+
"build/lib/",
|
|
45
|
+
"build/index.js",
|
|
46
|
+
"build/index.d.ts"
|
|
42
47
|
],
|
|
43
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "79a76a082db91399d0e432ef02bf2981a6739107"
|
|
44
49
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./lib/common/tools');
|
package/lib/common/tools.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { tools } = require('@iobroker/js-controller-common');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Allows to find out if a given states dbType offers a server or not
|
|
7
|
-
* @param dbType {string} database type
|
|
8
|
-
* @returns {boolean} true if a server class is available
|
|
9
|
-
*/
|
|
10
|
-
function statesDbHasServer(dbType) {
|
|
11
|
-
try {
|
|
12
|
-
const path = require.resolve(`@iobroker/db-states-${dbType}`);
|
|
13
|
-
return !!require(path).Server;
|
|
14
|
-
} catch {
|
|
15
|
-
throw new Error(`Installation error or unknown states database type: ${dbType}`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Allows to find out if a given objects dbType offers a server which runs on this host and listens (locally or globally/by IP)
|
|
21
|
-
* @param dbType {string} database type
|
|
22
|
-
* @param host {string} configured db host
|
|
23
|
-
* @param [checkIfLocalOnly=false] {boolean} optional if try the method checks if the server listens to local connections only; else also external connection options are checked
|
|
24
|
-
* @returns {boolean} true if a server listens on this host (locally or globally/by IP)
|
|
25
|
-
*/
|
|
26
|
-
function isLocalObjectsDbServer(dbType, host, checkIfLocalOnly) {
|
|
27
|
-
const ownIps = tools.findIPs();
|
|
28
|
-
if (!objectsDbHasServer(dbType)) {
|
|
29
|
-
return false; // if no server it can not be a local server
|
|
30
|
-
}
|
|
31
|
-
let result = host === 'localhost' || host === '127.0.0.1'; // reachable locally only
|
|
32
|
-
if (!checkIfLocalOnly) {
|
|
33
|
-
result = result || host === '0.0.0.0' || ownIps.includes(host);
|
|
34
|
-
}
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Allows to find out if a given states dbType offers a server which runs on this host and listens (locally or globally/by IP)
|
|
40
|
-
* @param dbType {string} database type
|
|
41
|
-
* @param host {string} configured db host
|
|
42
|
-
* @param [checkIfLocalOnly=false] {boolean} if try the method checks if the server listens to local connections only; else also external connection options are checked
|
|
43
|
-
* @returns {boolean} true if a server listens on this host (locally or globally/by IP)
|
|
44
|
-
*/
|
|
45
|
-
function isLocalStatesDbServer(dbType, host, checkIfLocalOnly) {
|
|
46
|
-
const ownIps = tools.findIPs();
|
|
47
|
-
if (!statesDbHasServer(dbType)) {
|
|
48
|
-
return false; // if no server it can not be a local server
|
|
49
|
-
}
|
|
50
|
-
let result = host === 'localhost' || host === '127.0.0.1'; // reachable locally only
|
|
51
|
-
if (!checkIfLocalOnly) {
|
|
52
|
-
result = result || host === '0.0.0.0' || ownIps.includes(host);
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Allows to find out if a given objects dbType offers a server or not
|
|
59
|
-
* @param dbType {string} database type
|
|
60
|
-
* @returns {boolean} true if a server class is available
|
|
61
|
-
*/
|
|
62
|
-
function objectsDbHasServer(dbType) {
|
|
63
|
-
try {
|
|
64
|
-
const path = require.resolve(`@iobroker/db-objects-${dbType}`);
|
|
65
|
-
return !!require(path).Server;
|
|
66
|
-
} catch {
|
|
67
|
-
throw new Error(`Installation error or unknown objects database type: ${dbType}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
module.exports = {
|
|
72
|
-
objectsDbHasServer,
|
|
73
|
-
isLocalObjectsDbServer,
|
|
74
|
-
isLocalStatesDbServer,
|
|
75
|
-
statesDbHasServer
|
|
76
|
-
};
|