@camera.ui/browser 0.0.1
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/CHANGELOG.md +8 -0
- package/LICENSE.md +22 -0
- package/README.md +1 -0
- package/dist/bundle.browser.js +1 -0
- package/dist/client/node/src/api.d.ts +5 -0
- package/dist/client/node/src/api.js +27 -0
- package/dist/client/node/src/api.js.map +1 -0
- package/dist/client/node/src/client.d.ts +20 -0
- package/dist/client/node/src/client.js +106 -0
- package/dist/client/node/src/client.js.map +1 -0
- package/dist/client/node/src/index.d.ts +2 -0
- package/dist/client/node/src/index.js +19 -0
- package/dist/client/node/src/index.js.map +1 -0
- package/dist/client/node/src/proxy/cameraDevice/cameraDevice.browser.d.ts +48 -0
- package/dist/client/node/src/proxy/cameraDevice/cameraDevice.browser.js +176 -0
- package/dist/client/node/src/proxy/cameraDevice/cameraDevice.browser.js.map +1 -0
- package/dist/client/node/src/proxy/cameraDevice/cameraDevice.mock.d.ts +1 -0
- package/dist/client/node/src/proxy/cameraDevice/cameraDevice.mock.js +3 -0
- package/dist/client/node/src/proxy/cameraDevice/cameraDevice.mock.js.map +1 -0
- package/dist/client/node/src/proxy/cameraDevice/cameraDevice.node.d.ts +11 -0
- package/dist/client/node/src/proxy/cameraDevice/cameraDevice.node.js +51 -0
- package/dist/client/node/src/proxy/cameraDevice/cameraDevice.node.js.map +1 -0
- package/dist/client/node/src/proxy/cameraDevice/index.d.ts +6 -0
- package/dist/client/node/src/proxy/cameraDevice/index.js +11 -0
- package/dist/client/node/src/proxy/cameraDevice/index.js.map +1 -0
- package/dist/client/node/src/proxy/deviceManager.d.ts +15 -0
- package/dist/client/node/src/proxy/deviceManager.js +67 -0
- package/dist/client/node/src/proxy/deviceManager.js.map +1 -0
- package/dist/client/node/src/proxy/index.d.ts +4 -0
- package/dist/client/node/src/proxy/index.js +21 -0
- package/dist/client/node/src/proxy/index.js.map +1 -0
- package/dist/client/node/src/proxy/pluginsManager.d.ts +9 -0
- package/dist/client/node/src/proxy/pluginsManager.js +25 -0
- package/dist/client/node/src/proxy/pluginsManager.js.map +1 -0
- package/dist/client/node/src/proxy/systemManager.d.ts +9 -0
- package/dist/client/node/src/proxy/systemManager.js +25 -0
- package/dist/client/node/src/proxy/systemManager.js.map +1 -0
- package/dist/client/node/src/socket.d.ts +9 -0
- package/dist/client/node/src/socket.js +45 -0
- package/dist/client/node/src/socket.js.map +1 -0
- package/dist/client/node/src/types.d.ts +22 -0
- package/dist/client/node/src/types.js +3 -0
- package/dist/client/node/src/types.js.map +1 -0
- package/dist/package.json +149 -0
- package/dist/shared/common/utils.d.ts +6 -0
- package/dist/shared/common/utils.js +66 -0
- package/dist/shared/common/utils.js.map +1 -0
- package/dist/shared/types/index.d.ts +8 -0
- package/dist/shared/types/index.js +23 -0
- package/dist/shared/types/index.js.map +1 -0
- package/dist/src/api/database/index.d.ts +25 -0
- package/dist/src/api/database/index.js +203 -0
- package/dist/src/api/database/index.js.map +1 -0
- package/dist/src/api/database/types.d.ts +153 -0
- package/dist/src/api/database/types.js +3 -0
- package/dist/src/api/database/types.js.map +1 -0
- package/dist/src/api/go2rtc/api/application.d.ts +8 -0
- package/dist/src/api/go2rtc/api/application.js +32 -0
- package/dist/src/api/go2rtc/api/application.js.map +1 -0
- package/dist/src/api/go2rtc/api/index.d.ts +3 -0
- package/dist/src/api/go2rtc/api/index.js +33 -0
- package/dist/src/api/go2rtc/api/index.js.map +1 -0
- package/dist/src/api/go2rtc/api/snapshot.d.ts +6 -0
- package/dist/src/api/go2rtc/api/snapshot.js +22 -0
- package/dist/src/api/go2rtc/api/snapshot.js.map +1 -0
- package/dist/src/api/go2rtc/api/streams.d.ts +10 -0
- package/dist/src/api/go2rtc/api/streams.js +32 -0
- package/dist/src/api/go2rtc/api/streams.js.map +1 -0
- package/dist/src/api/go2rtc/index.d.ts +3 -0
- package/dist/src/api/go2rtc/index.js +13 -0
- package/dist/src/api/go2rtc/index.js.map +1 -0
- package/dist/src/api/go2rtc/types.d.ts +43 -0
- package/dist/src/api/go2rtc/types.js +3 -0
- package/dist/src/api/go2rtc/types.js.map +1 -0
- package/dist/src/api/middlewares/socketAuth.middleware.d.ts +41 -0
- package/dist/src/api/middlewares/socketAuth.middleware.js +90 -0
- package/dist/src/api/middlewares/socketAuth.middleware.js.map +1 -0
- package/dist/src/api/schemas/backup.schema.d.ts +220 -0
- package/dist/src/api/schemas/backup.schema.js +94 -0
- package/dist/src/api/schemas/backup.schema.js.map +1 -0
- package/dist/src/api/schemas/cameras.schema.d.ts +316 -0
- package/dist/src/api/schemas/cameras.schema.js +124 -0
- package/dist/src/api/schemas/cameras.schema.js.map +1 -0
- package/dist/src/api/schemas/config.schema.d.ts +202 -0
- package/dist/src/api/schemas/config.schema.js +94 -0
- package/dist/src/api/schemas/config.schema.js.map +1 -0
- package/dist/src/api/schemas/go2rtc.schema.d.ts +604 -0
- package/dist/src/api/schemas/go2rtc.schema.js +204 -0
- package/dist/src/api/schemas/go2rtc.schema.js.map +1 -0
- package/dist/src/api/schemas/users.schema.d.ts +515 -0
- package/dist/src/api/schemas/users.schema.js +131 -0
- package/dist/src/api/schemas/users.schema.js.map +1 -0
- package/dist/src/api/services/auth.service.d.ts +20 -0
- package/dist/src/api/services/auth.service.js +104 -0
- package/dist/src/api/services/auth.service.js.map +1 -0
- package/dist/src/api/services/cameras.service.d.ts +40 -0
- package/dist/src/api/services/cameras.service.js +535 -0
- package/dist/src/api/services/cameras.service.js.map +1 -0
- package/dist/src/api/services/plugins.service.d.ts +23 -0
- package/dist/src/api/services/plugins.service.js +115 -0
- package/dist/src/api/services/plugins.service.js.map +1 -0
- package/dist/src/api/services/users.service.d.ts +13 -0
- package/dist/src/api/services/users.service.js +54 -0
- package/dist/src/api/services/users.service.js.map +1 -0
- package/dist/src/api/types/index.d.ts +522 -0
- package/dist/src/api/types/index.js +12 -0
- package/dist/src/api/types/index.js.map +1 -0
- package/dist/src/api/utils/cert.d.ts +17 -0
- package/dist/src/api/utils/cert.js +437 -0
- package/dist/src/api/utils/cert.js.map +1 -0
- package/dist/src/api/ws/index.d.ts +15 -0
- package/dist/src/api/ws/index.js +89 -0
- package/dist/src/api/ws/index.js.map +1 -0
- package/dist/src/api/ws/nsp/logs.d.ts +11 -0
- package/dist/src/api/ws/nsp/logs.js +121 -0
- package/dist/src/api/ws/nsp/logs.js.map +1 -0
- package/dist/src/api/ws/nsp/main.d.ts +9 -0
- package/dist/src/api/ws/nsp/main.js +49 -0
- package/dist/src/api/ws/nsp/main.js.map +1 -0
- package/dist/src/api/ws/nsp/metrics.d.ts +33 -0
- package/dist/src/api/ws/nsp/metrics.js +225 -0
- package/dist/src/api/ws/nsp/metrics.js.map +1 -0
- package/dist/src/api/ws/nsp/notifications.d.ts +11 -0
- package/dist/src/api/ws/nsp/notifications.js +39 -0
- package/dist/src/api/ws/nsp/notifications.js.map +1 -0
- package/dist/src/api/ws/nsp/plugins.d.ts +13 -0
- package/dist/src/api/ws/nsp/plugins.js +33 -0
- package/dist/src/api/ws/nsp/plugins.js.map +1 -0
- package/dist/src/api/ws/nsp/status.d.ts +12 -0
- package/dist/src/api/ws/nsp/status.js +41 -0
- package/dist/src/api/ws/nsp/status.js.map +1 -0
- package/dist/src/api/ws/nsp/streams.d.ts +30 -0
- package/dist/src/api/ws/nsp/streams.js +140 -0
- package/dist/src/api/ws/nsp/streams.js.map +1 -0
- package/dist/src/api/ws/types.d.ts +82 -0
- package/dist/src/api/ws/types.js +3 -0
- package/dist/src/api/ws/types.js.map +1 -0
- package/dist/src/api.d.ts +60 -0
- package/dist/src/api.js +66 -0
- package/dist/src/api.js.map +1 -0
- package/dist/src/camera/index.d.ts +54 -0
- package/dist/src/camera/index.js +210 -0
- package/dist/src/camera/index.js.map +1 -0
- package/dist/src/camera/streaming/peer-connection.d.ts +31 -0
- package/dist/src/camera/streaming/peer-connection.js +157 -0
- package/dist/src/camera/streaming/peer-connection.js.map +1 -0
- package/dist/src/camera/streaming/streaming-session.d.ts +32 -0
- package/dist/src/camera/streaming/streaming-session.js +172 -0
- package/dist/src/camera/streaming/streaming-session.js.map +1 -0
- package/dist/src/camera/streaming/webrtc-connection.d.ts +33 -0
- package/dist/src/camera/streaming/webrtc-connection.js +156 -0
- package/dist/src/camera/streaming/webrtc-connection.js.map +1 -0
- package/dist/src/camera/subscribed.d.ts +6 -0
- package/dist/src/camera/subscribed.js +14 -0
- package/dist/src/camera/subscribed.js.map +1 -0
- package/dist/src/camera/types.d.ts +130 -0
- package/dist/src/camera/types.js +3 -0
- package/dist/src/camera/types.js.map +1 -0
- package/dist/src/go2rtc/index.d.ts +24 -0
- package/dist/src/go2rtc/index.js +220 -0
- package/dist/src/go2rtc/index.js.map +1 -0
- package/dist/src/go2rtc/types.d.ts +14 -0
- package/dist/src/go2rtc/types.js +76 -0
- package/dist/src/go2rtc/types.js.map +1 -0
- package/dist/src/plugins/base.d.ts +19 -0
- package/dist/src/plugins/base.js +26 -0
- package/dist/src/plugins/base.js.map +1 -0
- package/dist/src/plugins/cameraStorage.d.ts +97 -0
- package/dist/src/plugins/cameraStorage.js +290 -0
- package/dist/src/plugins/cameraStorage.js.map +1 -0
- package/dist/src/plugins/child.d.ts +18 -0
- package/dist/src/plugins/child.js +140 -0
- package/dist/src/plugins/child.js.map +1 -0
- package/dist/src/plugins/config.d.ts +113 -0
- package/dist/src/plugins/config.js +234 -0
- package/dist/src/plugins/config.js.map +1 -0
- package/dist/src/plugins/index.d.ts +36 -0
- package/dist/src/plugins/index.js +328 -0
- package/dist/src/plugins/index.js.map +1 -0
- package/dist/src/plugins/plugin.d.ts +47 -0
- package/dist/src/plugins/plugin.js +215 -0
- package/dist/src/plugins/plugin.js.map +1 -0
- package/dist/src/plugins/schema.d.ts +268 -0
- package/dist/src/plugins/schema.js +717 -0
- package/dist/src/plugins/schema.js.map +1 -0
- package/dist/src/plugins/storage.d.ts +28 -0
- package/dist/src/plugins/storage.js +45 -0
- package/dist/src/plugins/storage.js.map +1 -0
- package/dist/src/plugins/types.d.ts +162 -0
- package/dist/src/plugins/types.js +21 -0
- package/dist/src/plugins/types.js.map +1 -0
- package/dist/src/plugins/worker.d.ts +27 -0
- package/dist/src/plugins/worker.js +236 -0
- package/dist/src/plugins/worker.js.map +1 -0
- package/dist/src/proxy/client/cameraDevice.d.ts +29 -0
- package/dist/src/proxy/client/cameraDevice.js +171 -0
- package/dist/src/proxy/client/cameraDevice.js.map +1 -0
- package/dist/src/proxy/client/deviceManager.d.ts +40 -0
- package/dist/src/proxy/client/deviceManager.js +239 -0
- package/dist/src/proxy/client/deviceManager.js.map +1 -0
- package/dist/src/proxy/client/index.d.ts +4 -0
- package/dist/src/proxy/client/index.js +21 -0
- package/dist/src/proxy/client/index.js.map +1 -0
- package/dist/src/proxy/client/pluginsManager.d.ts +35 -0
- package/dist/src/proxy/client/pluginsManager.js +237 -0
- package/dist/src/proxy/client/pluginsManager.js.map +1 -0
- package/dist/src/proxy/client/systemManager.d.ts +29 -0
- package/dist/src/proxy/client/systemManager.js +163 -0
- package/dist/src/proxy/client/systemManager.js.map +1 -0
- package/dist/src/proxy/index.d.ts +20 -0
- package/dist/src/proxy/index.js +98 -0
- package/dist/src/proxy/index.js.map +1 -0
- package/dist/src/proxy/proxies/camera.d.ts +26 -0
- package/dist/src/proxy/proxies/camera.js +72 -0
- package/dist/src/proxy/proxies/camera.js.map +1 -0
- package/dist/src/proxy/proxies/plugin.d.ts +30 -0
- package/dist/src/proxy/proxies/plugin.js +110 -0
- package/dist/src/proxy/proxies/plugin.js.map +1 -0
- package/dist/src/proxy/proxies/server.d.ts +34 -0
- package/dist/src/proxy/proxies/server.js +92 -0
- package/dist/src/proxy/proxies/server.js.map +1 -0
- package/dist/src/proxy/types.d.ts +189 -0
- package/dist/src/proxy/types.js +3 -0
- package/dist/src/proxy/types.js.map +1 -0
- package/dist/src/proxy/utils/generateKeys.d.ts +5 -0
- package/dist/src/proxy/utils/generateKeys.js +13 -0
- package/dist/src/proxy/utils/generateKeys.js.map +1 -0
- package/dist/src/proxy/ws/index.d.ts +21 -0
- package/dist/src/proxy/ws/index.js +75 -0
- package/dist/src/proxy/ws/index.js.map +1 -0
- package/dist/src/services/config/index.d.ts +60 -0
- package/dist/src/services/config/index.js +319 -0
- package/dist/src/services/config/index.js.map +1 -0
- package/dist/src/services/config/types.d.ts +153 -0
- package/dist/src/services/config/types.js +13 -0
- package/dist/src/services/config/types.js.map +1 -0
- package/dist/src/services/logger/index.d.ts +37 -0
- package/dist/src/services/logger/index.js +181 -0
- package/dist/src/services/logger/index.js.map +1 -0
- package/package.json +46 -0
- package/webpack.config.js +29 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CameraStorage = void 0;
|
|
7
|
+
const pouchdb_1 = __importDefault(require("pouchdb"));
|
|
8
|
+
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
9
|
+
const lodash_mergewith_1 = __importDefault(require("lodash.mergewith"));
|
|
10
|
+
const object_path_1 = __importDefault(require("object-path"));
|
|
11
|
+
const schema_1 = require("./schema");
|
|
12
|
+
class CameraStorage {
|
|
13
|
+
schema;
|
|
14
|
+
cameraId;
|
|
15
|
+
instance;
|
|
16
|
+
api;
|
|
17
|
+
db;
|
|
18
|
+
_values = {};
|
|
19
|
+
// get values(): Record<string, any> {
|
|
20
|
+
// return this._values;
|
|
21
|
+
// }
|
|
22
|
+
constructor(api, instance, cameraId, schema = {}) {
|
|
23
|
+
this.api = api;
|
|
24
|
+
this.instance = instance;
|
|
25
|
+
this.cameraId = cameraId;
|
|
26
|
+
this.schema = schema;
|
|
27
|
+
this.db = new pouchdb_1.default(`${this.api.storage().storagePath}/volume`, {
|
|
28
|
+
adapter: 'leveldb',
|
|
29
|
+
});
|
|
30
|
+
this.api.deviceManager.listen('cameraRemoved', async (cameraId) => {
|
|
31
|
+
if (cameraId === this.cameraId) {
|
|
32
|
+
const configDoc = await this.db.get('config');
|
|
33
|
+
delete configDoc.config[this.cameraId];
|
|
34
|
+
await this.db.put(configDoc, { force: true });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Initialize the storage.
|
|
40
|
+
* This will load the configuration from the database.
|
|
41
|
+
*/
|
|
42
|
+
async initializeStorage() {
|
|
43
|
+
const configDoc = await this.db.get('config');
|
|
44
|
+
const dbConfig = configDoc.config[this.cameraId] || {};
|
|
45
|
+
const schemaConfig = (0, schema_1.generateJsonFromRootSchema)({ schema: this.schema });
|
|
46
|
+
this._values = (0, lodash_mergewith_1.default)(schemaConfig, dbConfig);
|
|
47
|
+
await this.resolveOnGetFunctions(this.schema);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Set a new value for a given key/path in the configuration.
|
|
51
|
+
* If the schema of the value has an onSet function, and the value has changed, the onSet function will be called.
|
|
52
|
+
* If the schema of the value is declared as storable, the value will be saved to the database.
|
|
53
|
+
*
|
|
54
|
+
* @param path - The path to the configuration value.
|
|
55
|
+
* @param newValue - The new value to set.
|
|
56
|
+
*/
|
|
57
|
+
async setValue(path, newValue) {
|
|
58
|
+
const schemaPath = (0, schema_1.configPathToSchemaPath)(path);
|
|
59
|
+
const schema = object_path_1.default.get(this.schema, schemaPath);
|
|
60
|
+
if (schema) {
|
|
61
|
+
object_path_1.default.set(this._values, path, newValue);
|
|
62
|
+
const oldConfig = (0, lodash_clonedeep_1.default)(this._values);
|
|
63
|
+
await this.triggerOnSetForChanges(oldConfig, this._values);
|
|
64
|
+
if (this.containsStorableSchema(schema)) {
|
|
65
|
+
await this.saveDb();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get a value from the configuration by its key/path.
|
|
71
|
+
* If the schema has an onGet function, the onGet function will be called.
|
|
72
|
+
* If the onGet functions is undefined, the value from the configuration will be returned.
|
|
73
|
+
* If the schema has a default value, and the configuration value is undefined, the default value will be returned.
|
|
74
|
+
*
|
|
75
|
+
* @param path - The path to the configuration value.
|
|
76
|
+
* @returns The value from the configuration.
|
|
77
|
+
*/
|
|
78
|
+
getValue(path) {
|
|
79
|
+
const schemaPath = (0, schema_1.configPathToSchemaPath)(path);
|
|
80
|
+
const schema = object_path_1.default.get(this.schema, schemaPath);
|
|
81
|
+
const configValue = object_path_1.default.get(this._values, path);
|
|
82
|
+
return schema?.onGet?.call(this.instance) || configValue || schema?.defaultValue;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the root schema and configuration.
|
|
86
|
+
* This will also call the onGet functions for the schema.
|
|
87
|
+
*
|
|
88
|
+
* @returns The root schema and configuration.
|
|
89
|
+
*/
|
|
90
|
+
async getConfig() {
|
|
91
|
+
const filteredSchema = (0, schema_1.removeFunctionsFromSchemaForm)(this.schema);
|
|
92
|
+
const rootSchema = { schema: filteredSchema };
|
|
93
|
+
await this.resolveOnGetFunctions(this.schema);
|
|
94
|
+
return { rootSchema, config: this._values };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Set a new configuration.
|
|
98
|
+
* If the schema of a value which has been changed has an onSet function, the onSet function will be called.
|
|
99
|
+
*
|
|
100
|
+
* @param newConfig - The new configuration to set.
|
|
101
|
+
*/
|
|
102
|
+
async setConfig(newConfig) {
|
|
103
|
+
const oldConfig = (0, lodash_clonedeep_1.default)(this._values);
|
|
104
|
+
this._values = newConfig;
|
|
105
|
+
await this.saveDb();
|
|
106
|
+
await this.triggerOnSetForChanges(oldConfig, this._values);
|
|
107
|
+
}
|
|
108
|
+
async addSchema(schemaOrPath, schema) {
|
|
109
|
+
let shouldSave = false;
|
|
110
|
+
if (typeof schemaOrPath === 'string' && schema) {
|
|
111
|
+
const path = schemaOrPath;
|
|
112
|
+
const schemaPath = (0, schema_1.configPathToSchemaPath)(path);
|
|
113
|
+
const configValue = (0, schema_1.generateJsonFromSchema)(schema);
|
|
114
|
+
object_path_1.default.set(this.schema, schemaPath, schema);
|
|
115
|
+
object_path_1.default.set(this._values, path, configValue);
|
|
116
|
+
await this.resolveOnGetFunctions(schema, schemaPath);
|
|
117
|
+
if (this.containsStorableSchema(schema)) {
|
|
118
|
+
shouldSave = true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else if (typeof schemaOrPath === 'object' && !schema) {
|
|
122
|
+
const newSchema = schemaOrPath;
|
|
123
|
+
const schemaConfig = (0, schema_1.generateJsonFromRootSchema)({ schema: newSchema });
|
|
124
|
+
this.schema = (0, lodash_mergewith_1.default)(this.schema, newSchema);
|
|
125
|
+
this._values = (0, lodash_mergewith_1.default)(this._values, schemaConfig);
|
|
126
|
+
await this.resolveOnGetFunctions(newSchema);
|
|
127
|
+
if (this.containsStorableSchema(newSchema)) {
|
|
128
|
+
shouldSave = true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
throw new Error('Invalid arguments for addSchema');
|
|
133
|
+
}
|
|
134
|
+
if (shouldSave) {
|
|
135
|
+
await this.saveDb();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Remove a schema by its config path/key from the existing schema.
|
|
140
|
+
* It will also remove the value from the configuration.
|
|
141
|
+
* If the schema is declared as storable, the value will be removed from the database.
|
|
142
|
+
*
|
|
143
|
+
* @param path - The path to the schema to remove.
|
|
144
|
+
*/
|
|
145
|
+
async removeSchema(path) {
|
|
146
|
+
const schemaPath = (0, schema_1.configPathToSchemaPath)(path);
|
|
147
|
+
const schema = object_path_1.default.get(this.schema, schemaPath);
|
|
148
|
+
if (schema) {
|
|
149
|
+
object_path_1.default.del(this.schema, schemaPath);
|
|
150
|
+
object_path_1.default.del(this._values, path);
|
|
151
|
+
if (this.containsStorableSchema(schema)) {
|
|
152
|
+
await this.saveDb();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Change a schema by its config path/key from the existing schema.
|
|
158
|
+
* It will also change the value from the configuration.
|
|
159
|
+
* If the schema is declared as storable, the value will be saved to the database.
|
|
160
|
+
*
|
|
161
|
+
* @param path - The path to the schema to change.
|
|
162
|
+
* @param schema - The new schema to set.
|
|
163
|
+
*/
|
|
164
|
+
async changeSchema(path, newSchema) {
|
|
165
|
+
const schemaPath = (0, schema_1.configPathToSchemaPath)(path);
|
|
166
|
+
const schema = object_path_1.default.get(this.schema, schemaPath);
|
|
167
|
+
if (schema) {
|
|
168
|
+
const changedSchema = (0, lodash_mergewith_1.default)(schema, newSchema);
|
|
169
|
+
const changedSchemaConfigValue = (0, schema_1.generateJsonFromSchema)(changedSchema);
|
|
170
|
+
object_path_1.default.set(this.schema, schemaPath, changedSchema);
|
|
171
|
+
object_path_1.default.set(this._values, path, changedSchemaConfigValue);
|
|
172
|
+
await this.resolveOnGetFunctions(changedSchema, schemaPath);
|
|
173
|
+
if (this.containsStorableSchema(changedSchema)) {
|
|
174
|
+
await this.saveDb();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Check if a schema exists by its config path/key.
|
|
180
|
+
*
|
|
181
|
+
* @param path - The path to the schema to check.
|
|
182
|
+
* @returns True if the schema exists, false otherwise.
|
|
183
|
+
*/
|
|
184
|
+
hasSchema(path) {
|
|
185
|
+
const schemaPath = (0, schema_1.configPathToSchemaPath)(path);
|
|
186
|
+
const schema = object_path_1.default.get(this.schema, schemaPath);
|
|
187
|
+
return !!schema;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Check if a value exists by its config path/key.
|
|
191
|
+
*
|
|
192
|
+
* @param path - The path to the value to check.
|
|
193
|
+
* @returns True if the value exists, false otherwise.
|
|
194
|
+
*/
|
|
195
|
+
hasValue(path) {
|
|
196
|
+
const configValue = object_path_1.default.get(this._values, path);
|
|
197
|
+
return configValue !== undefined;
|
|
198
|
+
}
|
|
199
|
+
async resolveOnGetFunctions(schema, baseSchemaPath = '') {
|
|
200
|
+
if ((0, schema_1.isPrimitiveType)(schema)) {
|
|
201
|
+
await this.resolveOnGetFunctionsForSchema(baseSchemaPath);
|
|
202
|
+
}
|
|
203
|
+
else if ((0, schema_1.isObjectType)(schema)) {
|
|
204
|
+
if (schema.properties) {
|
|
205
|
+
await this.resolveOnGetFunctionsForObject(schema.properties, baseSchemaPath);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else if (typeof schema === 'object') {
|
|
209
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
210
|
+
const schemaPath = baseSchemaPath ? `${baseSchemaPath}.${key}` : key;
|
|
211
|
+
if ((0, schema_1.isObjectType)(value)) {
|
|
212
|
+
if (value.properties) {
|
|
213
|
+
await this.resolveOnGetFunctionsForObject(value.properties, schemaPath);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
await this.resolveOnGetFunctionsForSchema(schemaPath);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async resolveOnGetFunctionsForObject(schema, baseSchemaPath) {
|
|
223
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
224
|
+
const schemaPath = baseSchemaPath ? `${baseSchemaPath}.${key}` : key;
|
|
225
|
+
await this.resolveOnGetFunctionsForSchema(schemaPath);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async resolveOnGetFunctionsForSchema(schemaPath) {
|
|
229
|
+
const configPath = (0, schema_1.schemaPathToConfigPath)(schemaPath);
|
|
230
|
+
const schemaValue = await this.getValue(configPath);
|
|
231
|
+
if (schemaValue !== undefined && schemaValue !== null) {
|
|
232
|
+
object_path_1.default.set(this._values, configPath, schemaValue);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async triggerOnSetForChanges(oldConfig, newConfig, path = '') {
|
|
236
|
+
for (const key in newConfig) {
|
|
237
|
+
const newPath = path ? `${path}.${key}` : key;
|
|
238
|
+
const oldValue = (0, schema_1.getValueByPath)(oldConfig, newPath);
|
|
239
|
+
const newValue = newConfig[key];
|
|
240
|
+
// Check if the value has changed
|
|
241
|
+
if (JSON.stringify(oldValue) !== JSON.stringify(newValue)) {
|
|
242
|
+
const schemaItem = (0, schema_1.getValueByPath)(this.schema, newPath);
|
|
243
|
+
if (schemaItem && typeof schemaItem.onSet === 'function') {
|
|
244
|
+
await schemaItem.onSet.call(this.instance, newValue, oldValue);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {
|
|
248
|
+
await this.triggerOnSetForChanges(oldValue || {}, newValue, newPath);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
filterStorableValues(schema, baseSchemaPath = '', result = {}) {
|
|
253
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
254
|
+
if ((0, schema_1.isObjectType)(value)) {
|
|
255
|
+
if (value.properties) {
|
|
256
|
+
this.filterStorableValues(value.properties, baseSchemaPath ? `${baseSchemaPath}.${key}` : key, result);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
else if (value.store) {
|
|
260
|
+
const schemaPath = baseSchemaPath ? `${baseSchemaPath}.${key}` : key;
|
|
261
|
+
const configPath = (0, schema_1.schemaPathToConfigPath)(schemaPath);
|
|
262
|
+
const configValue = (0, schema_1.getValueByPath)(this._values, configPath);
|
|
263
|
+
object_path_1.default.set(result, configPath, configValue);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
containsStorableSchema(schema) {
|
|
269
|
+
if ((0, schema_1.isObjectType)(schema)) {
|
|
270
|
+
if (schema.store) {
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
if (schema.properties) {
|
|
274
|
+
return Object.values(schema.properties).some((subSchema) => this.containsStorableSchema(subSchema));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else if (typeof schema === 'object') {
|
|
278
|
+
return Object.values(schema).some((subSchema) => this.containsStorableSchema(subSchema));
|
|
279
|
+
}
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
async saveDb() {
|
|
283
|
+
const configDoc = await this.db.get('config');
|
|
284
|
+
const storableConfig = this.filterStorableValues(this.schema);
|
|
285
|
+
configDoc.config[this.cameraId] = storableConfig;
|
|
286
|
+
await this.db.put(configDoc, { force: true });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
exports.CameraStorage = CameraStorage;
|
|
290
|
+
//# sourceMappingURL=cameraStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cameraStorage.js","sourceRoot":"","sources":["../../../../../src/plugins/cameraStorage.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAC9B,wEAAyC;AACzC,wEAAyC;AACzC,8DAAqC;AAErC,qCASkB;AAWlB,MAAa,aAAa;IACjB,MAAM,CAAuB;IAE5B,QAAQ,CAAS;IACjB,QAAQ,CAAM;IACd,GAAG,CAAM;IACT,EAAE,CAAmB;IAErB,OAAO,GAAwB,EAAE,CAAC;IAE1C,sCAAsC;IACtC,yBAAyB;IACzB,IAAI;IAEJ,YAAY,GAAQ,EAAE,QAAa,EAAE,QAAgB,EAAE,SAA+B,EAAE;QACtF,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,EAAE,GAAG,IAAI,iBAAO,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,WAAW,SAAS,EAAE;YAChE,OAAO,EAAE,SAAS;SACnB,CAAC,CAAC;Q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CAAC,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAC;QAC3F,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,KAAK,CAAC,MAAM;QAClB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,GAAG,CAAkB,QAAQ,CAAC,CAAC;QAC/D,MAAM,cAAc,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE9D,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,cAAc,CAAC;QAEjD,MAAM,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;CACF;AAlVD,sCAkVC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { Plugin } from './plugin';
|
|
3
|
+
import { BasePlugin } from './base';
|
|
4
|
+
export declare class PluginChild {
|
|
5
|
+
private displayName;
|
|
6
|
+
plugin?: Plugin;
|
|
7
|
+
pluginConstructor?: BasePlugin;
|
|
8
|
+
private api?;
|
|
9
|
+
private storage?;
|
|
10
|
+
private pluginManager?;
|
|
11
|
+
private logger;
|
|
12
|
+
constructor();
|
|
13
|
+
private start;
|
|
14
|
+
private stop;
|
|
15
|
+
private sendMessage;
|
|
16
|
+
private processHandler;
|
|
17
|
+
private signalHander;
|
|
18
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PluginChild = void 0;
|
|
13
|
+
process.title = `camera.ui - ${process.argv[2]}`;
|
|
14
|
+
require("reflect-metadata");
|
|
15
|
+
const tsyringe_1 = require("tsyringe");
|
|
16
|
+
const _1 = require(".");
|
|
17
|
+
const api_1 = require("../api");
|
|
18
|
+
const logger_1 = require("../services/logger");
|
|
19
|
+
const storage_1 = require("./storage");
|
|
20
|
+
const client_1 = require("../proxy/client");
|
|
21
|
+
let PluginChild = class PluginChild {
|
|
22
|
+
displayName = process.argv[2];
|
|
23
|
+
plugin;
|
|
24
|
+
pluginConstructor;
|
|
25
|
+
api;
|
|
26
|
+
storage;
|
|
27
|
+
pluginManager;
|
|
28
|
+
logger;
|
|
29
|
+
constructor() {
|
|
30
|
+
this.logger = new logger_1.PluginLogger(this.displayName);
|
|
31
|
+
this.processHandler();
|
|
32
|
+
this.signalHander();
|
|
33
|
+
this.sendMessage({ type: "ready" /* PLUGIN_STATUS.READY */ });
|
|
34
|
+
tsyringe_1.container.register('plugin', { useValue: this });
|
|
35
|
+
}
|
|
36
|
+
async start(data) {
|
|
37
|
+
try {
|
|
38
|
+
this.api = new api_1.CameraUiAPI();
|
|
39
|
+
this.pluginManager = new _1.PluginManager();
|
|
40
|
+
this.plugin = await this.pluginManager.loadPlugin(data.storage.installPath, data.pluginId, data.storage.storagePath);
|
|
41
|
+
await this.plugin.load();
|
|
42
|
+
await this.pluginManager.initializePlugin(this.plugin, this.plugin.pluginName);
|
|
43
|
+
const pluginConstructor = this.plugin?.getPluginConstructor(this.plugin.pluginName);
|
|
44
|
+
if (pluginConstructor) {
|
|
45
|
+
this.api.deviceManager = new client_1.DeviceManager(this.logger, this.plugin.id, this.plugin.pluginName, data.zmqInfo.zmqReqAddress, data.zmqInfo.zmqPubAddress, data.zmqInfo.zmqPublicKey);
|
|
46
|
+
this.api.pluginsManager = new client_1.PluginsManager(this.logger, this.plugin.id, this.plugin.pluginName, data.zmqInfo.zmqReqAddress, data.zmqInfo.zmqPubAddress, data.zmqInfo.zmqRouterAddress, data.zmqInfo.zmqPublicKey);
|
|
47
|
+
this.api.systemManager = new client_1.SystemManager(this.logger, this.plugin.id, this.plugin.pluginName, data.zmqInfo.zmqReqAddress, data.zmqInfo.zmqPubAddress, data.zmqInfo.zmqPublicKey);
|
|
48
|
+
this.api.storage = () => ({ storagePath: this.plugin.storagePath, configFile: this.plugin.configFile });
|
|
49
|
+
const cameras = data.cameras.map((camera) => new client_1.CameraDeviceProxy(camera, this.logger, this.plugin.id, this.plugin.pluginName, data.zmqInfo.zmqReqAddress, data.zmqInfo.zmqPubAddress, data.zmqInfo.zmqPublicKey));
|
|
50
|
+
this.storage = new storage_1.Storage(this.api);
|
|
51
|
+
this.pluginConstructor = new pluginConstructor(this.plugin.id, this.logger, this.plugin.config, this.storage, this.api);
|
|
52
|
+
this.pluginConstructor.configureCameras(cameras);
|
|
53
|
+
this.sendMessage({ type: "started" /* PLUGIN_STATUS.STARTED */ });
|
|
54
|
+
this.api.emit("finishLaunching" /* API_EVENT.FINISH_LAUNCHING */);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw new Error(`Plugin Constructor for "${this.plugin.pluginName}" not found!`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
this.sendMessage({ type: "error" /* PLUGIN_STATUS.ERROR */, data: error.message });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async stop() {
|
|
65
|
+
this.api?.emit("shutdown" /* API_EVENT.SHUTDOWN */);
|
|
66
|
+
}
|
|
67
|
+
sendMessage(data) {
|
|
68
|
+
if (process.connected && process.send) {
|
|
69
|
+
process.send?.(data);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
processHandler() {
|
|
73
|
+
process.on('message', (message) => {
|
|
74
|
+
switch (message.type) {
|
|
75
|
+
case "start" /* PLUGIN_COMMAND.START */:
|
|
76
|
+
this.start(message.data);
|
|
77
|
+
break;
|
|
78
|
+
case "stop" /* PLUGIN_COMMAND.STOP */:
|
|
79
|
+
this.stop();
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
signalHander() {
|
|
85
|
+
let closePromise;
|
|
86
|
+
const gracefullyClose = async (signal, reason, error, promise) => {
|
|
87
|
+
if (closePromise) {
|
|
88
|
+
return closePromise;
|
|
89
|
+
}
|
|
90
|
+
if (error || (promise && reason)) {
|
|
91
|
+
this.logger.log(`${this.displayName} is ungracefully closing from signal="${signal}" reason="${reason || 'unknown'}"...`);
|
|
92
|
+
if (error) {
|
|
93
|
+
if (typeof error === 'string') {
|
|
94
|
+
this.logger.error(error);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.logger.error(`${signal}: ${error.message}`);
|
|
98
|
+
this.logger.log(error.stack);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.logger.error(`${signal}: Unhandled promise rejection`);
|
|
103
|
+
this.logger.log(promise);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
this.logger.log(`${this.displayName} is gracefully closing from signal="${signal}" reason="${reason || 'unknown'}"...`);
|
|
108
|
+
}
|
|
109
|
+
setTimeout(() => {
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}, 5000);
|
|
112
|
+
closePromise = this.stop();
|
|
113
|
+
await closePromise;
|
|
114
|
+
process.exit(0);
|
|
115
|
+
};
|
|
116
|
+
process.on('uncaughtException', (error) => gracefullyClose('uncaughtException', undefined, error));
|
|
117
|
+
process.on('unhandledRejection', (reason, promise) => gracefullyClose('unhandledRejection', reason, undefined, promise));
|
|
118
|
+
process.on('SIGTERM', gracefullyClose);
|
|
119
|
+
process.on('SIGINT', gracefullyClose);
|
|
120
|
+
process.on('SIGUSR2', gracefullyClose);
|
|
121
|
+
/**
|
|
122
|
+
* Ensure orphaned processes are cleaned up
|
|
123
|
+
*/
|
|
124
|
+
// setInterval(() => {
|
|
125
|
+
// if (!process.connected && !closePromise) {
|
|
126
|
+
// this.logger.warn('Parent process not connected, terminating process...', process.argv[2]);
|
|
127
|
+
// setTimeout(() => process.kill(process.pid, 'SIGTERM'), 2000);
|
|
128
|
+
// }
|
|
129
|
+
// }, 5000);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
exports.PluginChild = PluginChild;
|
|
133
|
+
exports.PluginChild = PluginChild = __decorate([
|
|
134
|
+
(0, tsyringe_1.scoped)(tsyringe_1.Lifecycle.ContainerScoped),
|
|
135
|
+
__metadata("design:paramtypes", [])
|
|
136
|
+
], PluginChild);
|
|
137
|
+
if (require.main === module) {
|
|
138
|
+
new PluginChild();
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=child.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"child.js","sourceRoot":"","sources":["../../../../../src/plugins/child.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,CAAC,KAAK,GAAG,eAAe,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;AAEjD,4BAA0B;AAC1B,uCAAwD;AAExD,wBAAkC;AAClC,gCAAgD;AAChD,+CAAkD;AAGlD,uCAAoC;AAEpC,4CAAkG;AAM3F,IAAM,WAAW,GAAjB,MAAM,WAAW;IACd,WAAW,GAAW,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEvC,MAAM,CAAU;IAChB,iBAAiB,CAAc;IAE9B,GAAG,CAAe;IAClB,OAAO,CAAW;IA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AAC;YAET,YAAY,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAC3B,MAAM,YAAY,CAAC;YAEnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC;QAEF,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,mBAAmB,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;QACnG,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAc,EAAE,OAAY,EAAE,EAAE,CAAC,eAAe,CAAC,oBAAoB,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;QACtI,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QACvC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QACtC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QAEvC;;WAEG;QACH,sBAAsB;QACtB,+CAA+C;QAC/C,iGAAiG;QACjG,oEAAoE;QACpE,MAAM;QACN,YAAY;IACd,CAAC;CACF,CAAA;AAvKY,kCAAW;sBAAX,WAAW;IADvB,IAAA,iBAAM,EAAC,oBAAS,CAAC,eAAe,CAAC;;GACrB,WAAW,CAuKvB;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,IAAI,WAAW,EAAE,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { type Path } from 'object-path';
|
|
2
|
+
import type { JSONValue, PluginConfig } from './types';
|
|
3
|
+
export declare class PluginConfigService {
|
|
4
|
+
private config;
|
|
5
|
+
private configFile;
|
|
6
|
+
constructor(configFile: string);
|
|
7
|
+
/**
|
|
8
|
+
* Get key (Path) from config.json
|
|
9
|
+
*
|
|
10
|
+
* @param key - Key to lookup for
|
|
11
|
+
* @param defaultValue - Default value if `key` not exist
|
|
12
|
+
* @param validate - Validate the value of the `key` and replace with `defaultValue` if it is not valid
|
|
13
|
+
* @param refresh - Re-Read config.json before lookup for the `key`
|
|
14
|
+
* @param writeIfNotValid - Optional parameter, if true, the changes will be written to the file, if the value of the `key` is not valid and is replaced by the `defaultValue`
|
|
15
|
+
*
|
|
16
|
+
* @returns `value` for the given `key` or `defaultValue`
|
|
17
|
+
*/
|
|
18
|
+
get(key: Path, defaultValue: JSONValue, validate: Function, refresh?: boolean, writeIfNotValid?: boolean): any;
|
|
19
|
+
get(key: Path, defaultValue?: unknown, validate?: Function, refresh?: boolean, writeIfNotValid?: boolean): any;
|
|
20
|
+
/**
|
|
21
|
+
* Test key (Path) existence
|
|
22
|
+
*
|
|
23
|
+
* @param key - Key to lookup for
|
|
24
|
+
* @param refresh - Re-Read config.json before lookup for the `key`
|
|
25
|
+
*/
|
|
26
|
+
has(key: Path, refresh?: boolean): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Set a value if it doesn't exist, do nothing if it does
|
|
29
|
+
*
|
|
30
|
+
* @param key - Key whose existence is to be checked
|
|
31
|
+
* @param defaultValue - Default value if `key` not exist
|
|
32
|
+
* @param write - Optional parameter, if true, the changes will be written to the file.
|
|
33
|
+
*/
|
|
34
|
+
ensureExists(key: Path, defaultValue: JSONValue, write?: boolean): void;
|
|
35
|
+
/**
|
|
36
|
+
* Set a key (Path) to a value
|
|
37
|
+
*
|
|
38
|
+
* @param key - Key
|
|
39
|
+
* @param value - Value to set for they given `key`
|
|
40
|
+
* @param write - Optional parameter, if true, the changes will be written to the file.
|
|
41
|
+
*/
|
|
42
|
+
set(key: Path, value: any, write?: boolean): void;
|
|
43
|
+
/**
|
|
44
|
+
* Insert an item in an array path
|
|
45
|
+
*
|
|
46
|
+
* @param key - Key to the array
|
|
47
|
+
* @param value - Value to insert in the array
|
|
48
|
+
* @param at - Index
|
|
49
|
+
* @param write - Optional parameter, if true, the changes will be written to the file.
|
|
50
|
+
*/
|
|
51
|
+
insert(key: Path, value: any, at?: number, write?: boolean): void;
|
|
52
|
+
/**
|
|
53
|
+
* Create (if path isn't an array) and push the value to it. Can push unlimited number of values
|
|
54
|
+
*
|
|
55
|
+
* @param key - Key to the array
|
|
56
|
+
* @param write - Optional parameter, if true, the changes will be written to the file.
|
|
57
|
+
* @param items - Values to push in to the array
|
|
58
|
+
*/
|
|
59
|
+
push(key: Path, write?: boolean, ...items: any[]): void;
|
|
60
|
+
/**
|
|
61
|
+
* Deletes a member from object or array
|
|
62
|
+
*
|
|
63
|
+
* @param key - Key to lookup for
|
|
64
|
+
* @param write - Optional parameter, if true, the changes will be written to the file.
|
|
65
|
+
*/
|
|
66
|
+
delete(key: Path, write?: boolean): void;
|
|
67
|
+
/**
|
|
68
|
+
* @param refresh - Re-Read config.json
|
|
69
|
+
*
|
|
70
|
+
* @returns config.json
|
|
71
|
+
*/
|
|
72
|
+
all(refresh?: boolean): PluginConfig;
|
|
73
|
+
/**
|
|
74
|
+
* @param config - New config.json
|
|
75
|
+
* @param write - Optional parameter, if true, the changes will be written to the file.
|
|
76
|
+
*/
|
|
77
|
+
replace(config: PluginConfig, write?: boolean): void;
|
|
78
|
+
/**
|
|
79
|
+
* Updates a specific value in a nested object structure by a given path and key.
|
|
80
|
+
*
|
|
81
|
+
* @param path - The path to the nested object.
|
|
82
|
+
* @param searchKey - The key to search for.
|
|
83
|
+
* @param searchValue - The value to match the searchKey.
|
|
84
|
+
* @param targetKey - The key of the value to be updated.
|
|
85
|
+
* @param newValue - The new value to be set.
|
|
86
|
+
* @param write - Optional parameter, if true, the changes will be written to the file.
|
|
87
|
+
*/
|
|
88
|
+
updateValue(path: string, searchKey: string, searchValue: any, targetKey: string, newValue: any, write?: boolean): void;
|
|
89
|
+
/**
|
|
90
|
+
* Replaces a specific item in a nested object structure by a given path and key.
|
|
91
|
+
* If the item does not exist, it will be added.
|
|
92
|
+
* If the path does not exist, it will be created.
|
|
93
|
+
*
|
|
94
|
+
* @param path - The path to the nested object.
|
|
95
|
+
* @param searchKey - The key to search for.
|
|
96
|
+
* @param searchValue - The value to match the searchKey.
|
|
97
|
+
* @param newItem - The new item to replace the old one. If the item does not exist, it will be added.
|
|
98
|
+
* @param write - Optional parameter, if true, the changes will be written to the file.
|
|
99
|
+
*/
|
|
100
|
+
replaceOrAddItem(path: string, searchKey: string, searchValue: any, newItem: any, write?: boolean): void;
|
|
101
|
+
/**
|
|
102
|
+
* Initialize config.json
|
|
103
|
+
*/
|
|
104
|
+
private init;
|
|
105
|
+
/**
|
|
106
|
+
* Read config.json
|
|
107
|
+
*/
|
|
108
|
+
private read;
|
|
109
|
+
/**
|
|
110
|
+
* Write config.json
|
|
111
|
+
*/
|
|
112
|
+
private write;
|
|
113
|
+
}
|