vrack2-core 0.0.1 → 1.0.0
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/README.md +25 -4
- package/docs/Bootstrap.md +77 -0
- package/docs/Container.md +124 -0
- package/docs/Device.md +272 -0
- package/docs/FastStart.md +111 -0
- package/docs/Structure.md +148 -0
- package/lib/Bootstrap.d.ts +79 -0
- package/lib/Bootstrap.js +103 -0
- package/lib/Container.d.ts +202 -6
- package/lib/Container.js +295 -27
- package/lib/IServiceStructure.d.ts +8 -0
- package/lib/IStructureDevice.d.ts +5 -0
- package/lib/ImportManager.d.ts +85 -3
- package/lib/ImportManager.js +122 -16
- package/lib/MainProcess.d.ts +30 -3
- package/lib/MainProcess.js +28 -6
- package/lib/Utility.d.ts +15 -21
- package/lib/Utility.js +40 -40
- package/lib/actions/Action.d.ts +10 -0
- package/lib/actions/Action.js +10 -0
- package/lib/actions/BasicAction.d.ts +60 -0
- package/lib/actions/BasicAction.js +62 -0
- package/lib/actions/GlobalAction.d.ts +5 -0
- package/lib/actions/GlobalAction.js +5 -0
- package/lib/actions/IAction.d.ts +7 -0
- package/lib/actions/ILocalAction.d.ts +7 -0
- package/lib/boot/BootClass.d.ts +93 -0
- package/lib/boot/BootClass.js +101 -0
- package/lib/boot/DeviceFileStorage.d.ts +38 -0
- package/lib/boot/DeviceFileStorage.js +112 -0
- package/lib/boot/DeviceManager.d.ts +190 -0
- package/lib/boot/DeviceManager.js +306 -0
- package/lib/boot/DeviceMetrics.d.ts +82 -0
- package/lib/boot/DeviceMetrics.js +128 -0
- package/lib/boot/StructureStorage.d.ts +59 -0
- package/lib/boot/StructureStorage.js +125 -0
- package/lib/errors/CoreError.d.ts +42 -25
- package/lib/errors/CoreError.js +44 -24
- package/lib/errors/ErrorManager.d.ts +18 -20
- package/lib/errors/ErrorManager.js +23 -22
- package/lib/index.d.ts +20 -4
- package/lib/index.js +28 -4
- package/lib/metrics/BasicMetric.d.ts +49 -0
- package/lib/metrics/BasicMetric.js +79 -0
- package/lib/metrics/IMetricSettings.d.ts +32 -0
- package/lib/metrics/IMetricSettings.js +2 -0
- package/lib/metrics/IvMs.d.ts +9 -0
- package/lib/metrics/IvMs.js +22 -0
- package/lib/metrics/IvS.d.ts +9 -0
- package/lib/metrics/IvS.js +22 -0
- package/lib/metrics/IvUs.d.ts +9 -0
- package/lib/metrics/IvUs.js +22 -0
- package/lib/metrics/Metric.d.ts +17 -0
- package/lib/metrics/Metric.js +27 -0
- package/lib/ports/BasicPort.d.ts +39 -0
- package/lib/ports/BasicPort.js +39 -0
- package/lib/ports/ILocalPort.d.ts +7 -0
- package/lib/ports/IPort.d.ts +7 -0
- package/lib/ports/Port.d.ts +10 -0
- package/lib/ports/Port.js +10 -0
- package/lib/ports/ReturnPort.d.ts +5 -0
- package/lib/ports/ReturnPort.js +5 -0
- package/lib/service/Device.d.ts +213 -78
- package/lib/service/Device.js +185 -83
- package/lib/service/DeviceConnect.d.ts +4 -8
- package/lib/service/DeviceConnect.js +4 -8
- package/lib/service/DevicePort.d.ts +15 -6
- package/lib/service/DevicePort.js +29 -12
- package/lib/service/IDeviceEvent.d.ts +4 -1
- package/lib/validator/IValidationProblem.d.ts +7 -0
- package/lib/validator/IValidationRule.d.ts +12 -0
- package/lib/validator/IValidationSubrule.d.ts +2 -0
- package/lib/validator/Rule.d.ts +6 -2
- package/lib/validator/Rule.js +12 -2
- package/lib/validator/Validator.d.ts +48 -3
- package/lib/validator/Validator.js +70 -18
- package/lib/validator/types/AnyType.d.ts +17 -0
- package/lib/validator/types/AnyType.js +34 -0
- package/lib/validator/types/ArrayType.d.ts +37 -4
- package/lib/validator/types/ArrayType.js +42 -6
- package/lib/validator/types/BasicType.d.ts +67 -7
- package/lib/validator/types/BasicType.js +74 -8
- package/lib/validator/types/BooleanType.d.ts +23 -0
- package/lib/validator/types/BooleanType.js +47 -0
- package/lib/validator/types/FunctionType.d.ts +17 -0
- package/lib/validator/types/FunctionType.js +38 -0
- package/lib/validator/types/NumberType.d.ts +40 -5
- package/lib/validator/types/NumberType.js +53 -14
- package/lib/validator/types/ObjectType.d.ts +32 -5
- package/lib/validator/types/ObjectType.js +42 -8
- package/lib/validator/types/StringType.d.ts +30 -5
- package/lib/validator/types/StringType.js +33 -7
- package/package.json +10 -9
- package/src/Bootstrap.ts +122 -0
- package/src/Container.ts +411 -43
- package/src/IServiceStructure.ts +9 -0
- package/src/IStructureDevice.ts +5 -0
- package/src/ImportManager.ts +119 -11
- package/src/MainProcess.ts +53 -8
- package/src/Utility.ts +35 -36
- package/src/actions/Action.ts +12 -0
- package/src/actions/BasicAction.ts +63 -0
- package/src/actions/GlobalAction.ts +5 -0
- package/src/actions/IAction.ts +7 -0
- package/src/actions/ILocalAction.ts +7 -0
- package/src/boot/BootClass.ts +117 -0
- package/src/boot/DeviceFileStorage.ts +96 -0
- package/src/boot/DeviceManager.ts +339 -0
- package/src/boot/DeviceMetrics.ts +129 -0
- package/src/boot/StructureStorage.ts +108 -0
- package/src/errors/CoreError.ts +52 -26
- package/src/errors/ErrorManager.ts +46 -33
- package/src/index.ts +30 -6
- package/src/metrics/BasicMetric.ts +84 -0
- package/src/metrics/IMetricSettings.ts +38 -0
- package/src/metrics/IvMs.ts +18 -0
- package/src/metrics/IvS.ts +18 -0
- package/src/metrics/IvUs.ts +17 -0
- package/src/metrics/Metric.ts +25 -0
- package/src/ports/BasicPort.ts +39 -0
- package/src/ports/ILocalPort.ts +7 -0
- package/src/ports/IPort.ts +7 -0
- package/src/ports/Port.ts +11 -1
- package/src/ports/ReturnPort.ts +5 -0
- package/src/service/Device.ts +234 -103
- package/src/service/DeviceConnect.ts +4 -8
- package/src/service/DevicePort.ts +30 -11
- package/src/service/IDeviceEvent.ts +4 -1
- package/src/validator/IValidationProblem.ts +7 -0
- package/src/validator/IValidationRule.ts +12 -0
- package/src/validator/IValidationSubrule.ts +3 -0
- package/src/validator/Rule.ts +16 -2
- package/src/validator/Validator.ts +74 -23
- package/src/validator/types/AnyType.ts +32 -0
- package/src/validator/types/ArrayType.ts +43 -7
- package/src/validator/types/BasicType.ts +78 -9
- package/src/validator/types/BooleanType.ts +49 -0
- package/src/validator/types/FunctionType.ts +39 -0
- package/src/validator/types/NumberType.ts +53 -15
- package/src/validator/types/ObjectType.ts +52 -14
- package/src/validator/types/StringType.ts +34 -10
- package/docs/RU-README.md +0 -6
- package/lib/DeviceManager.d.ts +0 -32
- package/lib/DeviceManager.js +0 -143
- package/lib/test.d.ts +0 -1
- package/lib/test.js +0 -58
- package/src/DeviceManager.ts +0 -124
- package/src/test.ts +0 -82
package/lib/ImportManager.js
CHANGED
|
@@ -79,6 +79,14 @@ class ImportManager {
|
|
|
79
79
|
return ti;
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Import class like a vrack2 device style
|
|
84
|
+
*
|
|
85
|
+
* Разделяюет переданную строку пути на 2 части.
|
|
86
|
+
* Первая честь является названием модуля, а вторая часть классом внутри него
|
|
87
|
+
*
|
|
88
|
+
* @example ImportManager.importClass('vrack2-core.Container')
|
|
89
|
+
*/
|
|
82
90
|
static importClass(cs) {
|
|
83
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
92
|
const acts = cs.split('.');
|
|
@@ -96,18 +104,100 @@ class ImportManager {
|
|
|
96
104
|
return ret;
|
|
97
105
|
});
|
|
98
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Attempts to open a file and use its contents as json
|
|
109
|
+
*
|
|
110
|
+
* Returns the result of parsing json
|
|
111
|
+
*
|
|
112
|
+
* @returns {any} json parsing result
|
|
113
|
+
*/
|
|
99
114
|
static importJSON(filePath) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
if (!path_1.default.isAbsolute(filePath)) {
|
|
116
|
+
filePath = path_1.default.join(ImportManager.systemPath(), filePath);
|
|
117
|
+
}
|
|
118
|
+
if ((0, fs_1.existsSync)(filePath)) {
|
|
119
|
+
const jdata = (0, fs_1.readFileSync)(filePath).toString('utf-8');
|
|
120
|
+
return ImportManager.tryJsonParse(jdata);
|
|
121
|
+
}
|
|
122
|
+
throw ErrorManager_1.default.make('IM_FILE_NOT_FOUND', { filePath });
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns the class name in the style of import vrack
|
|
126
|
+
*
|
|
127
|
+
* return `Container` from 'vrack2-core.Container' string
|
|
128
|
+
*
|
|
129
|
+
* @param cs Import class string
|
|
130
|
+
*
|
|
131
|
+
*/
|
|
132
|
+
static importClassName(cs) {
|
|
133
|
+
const acts = cs.split('.');
|
|
134
|
+
return acts.pop();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns the vendor name in the style of import vrack
|
|
138
|
+
*
|
|
139
|
+
* return `vrack2-core` from 'vrack2-core.Container' string
|
|
140
|
+
*
|
|
141
|
+
* @param cs Import class string
|
|
142
|
+
*/
|
|
143
|
+
static importVendorName(cs) {
|
|
144
|
+
const acts = cs.split('.');
|
|
145
|
+
return acts.shift();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Returns a list of directories in the specified directory.
|
|
149
|
+
*
|
|
150
|
+
* @param dir path to directory
|
|
151
|
+
*/
|
|
152
|
+
static dirList(dir) {
|
|
153
|
+
const files = (0, fs_1.readdirSync)(dir);
|
|
154
|
+
const result = [];
|
|
155
|
+
for (const i in files)
|
|
156
|
+
if ((0, fs_1.statSync)(path_1.default.join(dir, files[i])).isDirectory())
|
|
157
|
+
result.push(files[i]);
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Returns a list of files in the specified directory.
|
|
162
|
+
*
|
|
163
|
+
* @param dir path to directory
|
|
164
|
+
*/
|
|
165
|
+
static fileList(dir) {
|
|
166
|
+
const files = (0, fs_1.readdirSync)(dir);
|
|
167
|
+
const result = [];
|
|
168
|
+
for (const i in files)
|
|
169
|
+
if (!(0, fs_1.statSync)(path_1.default.join(dir, files[i])).isDirectory())
|
|
170
|
+
result.push(files[i]);
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Checks if a path is a directory
|
|
175
|
+
*
|
|
176
|
+
* @param dir path to directory
|
|
177
|
+
*/
|
|
178
|
+
static isDir(dir) {
|
|
179
|
+
if ((0, fs_1.existsSync)(dir) && (0, fs_1.lstatSync)(dir).isDirectory())
|
|
180
|
+
return true;
|
|
181
|
+
return false;
|
|
110
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Checks if a path is a directory
|
|
185
|
+
*
|
|
186
|
+
* @param f path to file
|
|
187
|
+
*/
|
|
188
|
+
static isFile(f) {
|
|
189
|
+
if ((0, fs_1.existsSync)(f) && (0, fs_1.lstatSync)(f).isFile())
|
|
190
|
+
return true;
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Try JSON parse
|
|
195
|
+
*
|
|
196
|
+
* Returns an CoreError[IM_JSON_INCORRECT] if there is a parsing error.
|
|
197
|
+
*
|
|
198
|
+
* @param jsonRaw JSON raw string
|
|
199
|
+
*
|
|
200
|
+
*/
|
|
111
201
|
static tryJsonParse(jsonRaw) {
|
|
112
202
|
try {
|
|
113
203
|
return JSON.parse(jsonRaw);
|
|
@@ -118,6 +208,25 @@ class ImportManager {
|
|
|
118
208
|
});
|
|
119
209
|
}
|
|
120
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Return directory where VRack was launched from
|
|
213
|
+
*/
|
|
214
|
+
static systemPath() {
|
|
215
|
+
return process.cwd();
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Camelize string for input & action handlers
|
|
219
|
+
*
|
|
220
|
+
* Splits a string with a dot and returns the string
|
|
221
|
+
* with capital letters starting from the second word
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* ImportManager.camelize('input.device.port') // return inputDevicePort
|
|
226
|
+
* ```
|
|
227
|
+
*
|
|
228
|
+
* @param text Like a `input.device.port` string
|
|
229
|
+
*/
|
|
121
230
|
static camelize(text) {
|
|
122
231
|
return text.replace(/^([A-Z])|[.]+(\w)/g, function (match, p1, p2, offset) {
|
|
123
232
|
if (p2)
|
|
@@ -125,12 +234,9 @@ class ImportManager {
|
|
|
125
234
|
return p1.toLowerCase();
|
|
126
235
|
});
|
|
127
236
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
static systemPath() {
|
|
132
|
-
return process.cwd();
|
|
133
|
-
}
|
|
237
|
+
/**
|
|
238
|
+
* Try import method
|
|
239
|
+
*/
|
|
134
240
|
static tryImport(p) {
|
|
135
241
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
242
|
try {
|
package/lib/MainProcess.d.ts
CHANGED
|
@@ -1,9 +1,36 @@
|
|
|
1
|
+
import Bootstrap, { IBootListConfig } from "./Bootstrap";
|
|
1
2
|
import Container from "./Container";
|
|
2
|
-
import DeviceManager from "./DeviceManager";
|
|
3
3
|
import IServiceStructure from "./IServiceStructure";
|
|
4
|
+
interface IMainProcessInternalOptions {
|
|
5
|
+
/** Container ID */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Service structure */
|
|
8
|
+
service: IServiceStructure;
|
|
9
|
+
/** Path to extends conf file */
|
|
10
|
+
confFile?: string;
|
|
11
|
+
/** Container class */
|
|
12
|
+
ContainerClass: typeof Container;
|
|
13
|
+
/** Bootstrap list config */
|
|
14
|
+
bootstrap: IBootListConfig;
|
|
15
|
+
}
|
|
16
|
+
export interface IMainProcessOptions {
|
|
17
|
+
/** Container ID */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Service structure */
|
|
20
|
+
service: IServiceStructure;
|
|
21
|
+
/** Path to extends conf file */
|
|
22
|
+
confFile?: string;
|
|
23
|
+
/** Container class */
|
|
24
|
+
ContainerClass?: typeof Container;
|
|
25
|
+
/** Bootstrap list config */
|
|
26
|
+
bootstrap?: IBootListConfig;
|
|
27
|
+
}
|
|
4
28
|
export default class MainProcess {
|
|
5
29
|
Container: Container;
|
|
6
|
-
|
|
7
|
-
|
|
30
|
+
options: IMainProcessInternalOptions;
|
|
31
|
+
Bootstrap: Bootstrap;
|
|
32
|
+
constructor(config: IMainProcessOptions);
|
|
8
33
|
run(): Promise<void>;
|
|
34
|
+
check(): Promise<void>;
|
|
9
35
|
}
|
|
36
|
+
export {};
|
package/lib/MainProcess.js
CHANGED
|
@@ -12,16 +12,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const
|
|
15
|
+
const Bootstrap_1 = __importDefault(require("./Bootstrap"));
|
|
16
|
+
const Container_1 = __importDefault(require("./Container"));
|
|
16
17
|
class MainProcess {
|
|
17
|
-
constructor(
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.options = {
|
|
20
|
+
id: 'vrack2',
|
|
21
|
+
service: {
|
|
22
|
+
devices: [],
|
|
23
|
+
connections: [],
|
|
24
|
+
},
|
|
25
|
+
ContainerClass: Container_1.default,
|
|
26
|
+
bootstrap: {
|
|
27
|
+
DeviceManager: { path: 'vrack2-core.DeviceManager', options: { storageDir: './storage' } },
|
|
28
|
+
DeviceStorage: { path: 'vrack2-core.DeviceFileStorage', options: {} },
|
|
29
|
+
StructureStorage: { path: 'vrack2-core.StructureStorage', options: {} },
|
|
30
|
+
DeviceMetrics: { path: 'vrack2-core.DeviceMetrics', options: {} }
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
Object.assign(this.options, config);
|
|
34
|
+
this.Bootstrap = new Bootstrap_1.default(this.options.bootstrap);
|
|
35
|
+
this.Container = new this.options.ContainerClass(this.options.id, this.options.service, this.Bootstrap, this.options.confFile);
|
|
21
36
|
}
|
|
22
37
|
run() {
|
|
23
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
yield this.
|
|
39
|
+
yield this.check();
|
|
40
|
+
yield this.Container.runProcess();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
check() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
yield this.Bootstrap.loadBootList(this.Container);
|
|
46
|
+
yield this.Container.init();
|
|
25
47
|
});
|
|
26
48
|
}
|
|
27
49
|
}
|
package/lib/Utility.d.ts
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* Преобразует строку в локальный путь VRack, на данный момент
|
|
17
|
-
* это просто приведение строки в lowerCase
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
declare function toPath(text: string): string;
|
|
21
|
-
export { camelize, validJSON, toPath };
|
|
1
|
+
export default class Utility {
|
|
2
|
+
/**
|
|
3
|
+
* Check device name (device ID)
|
|
4
|
+
* */
|
|
5
|
+
static isDeviceName(name: string): Promise<boolean>;
|
|
6
|
+
/**
|
|
7
|
+
* Форматирует любое значение в красивую строку (с отступами, подсветкой и т. д.).
|
|
8
|
+
* Поддерживает: объекты, массивы, примитивы, Error, Map, Set, Buffer и др.
|
|
9
|
+
*
|
|
10
|
+
* @param {any} value - Значение для форматирования
|
|
11
|
+
* @param {object} [options] - Дополнительные опции (как в `util.inspect()`)
|
|
12
|
+
* @returns {string} Отформатированная строка
|
|
13
|
+
*/
|
|
14
|
+
static prettyFormat(value: any, options?: {}): string | undefined;
|
|
15
|
+
}
|
package/lib/Utility.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright ©
|
|
3
|
+
* Copyright © 2025 Boris Bobylev. All rights reserved.
|
|
4
4
|
* Licensed under the Apache License, Version 2.0
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
function camelize(text) {
|
|
15
|
-
return text.replace(/^([A-Z])|[.]+(\w)/g, function (match, p1, p2, offset) {
|
|
16
|
-
if (p2)
|
|
17
|
-
return p2.toUpperCase();
|
|
18
|
-
return p1.toLowerCase();
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
13
|
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return
|
|
33
|
-
|
|
14
|
+
};
|
|
15
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
const util_1 = __importDefault(require("util"));
|
|
20
|
+
class Utility {
|
|
21
|
+
/**
|
|
22
|
+
* Check device name (device ID)
|
|
23
|
+
* */
|
|
24
|
+
static isDeviceName(name) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return /^[a-zA-Z0-9_*-:]+$/.test(name);
|
|
27
|
+
});
|
|
34
28
|
}
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Форматирует любое значение в красивую строку (с отступами, подсветкой и т. д.).
|
|
31
|
+
* Поддерживает: объекты, массивы, примитивы, Error, Map, Set, Buffer и др.
|
|
32
|
+
*
|
|
33
|
+
* @param {any} value - Значение для форматирования
|
|
34
|
+
* @param {object} [options] - Дополнительные опции (как в `util.inspect()`)
|
|
35
|
+
* @returns {string} Отформатированная строка
|
|
36
|
+
*/
|
|
37
|
+
static prettyFormat(value, options = {}) {
|
|
38
|
+
const defaultOptions = Object.assign({ depth: null, colors: true, compact: false, breakLength: 80, sorted: false, showHidden: false }, options // Переопределение дефолтных опций
|
|
39
|
+
);
|
|
40
|
+
// Особые случаи (если нужно обработать их по-особому)
|
|
41
|
+
if (value instanceof Error) {
|
|
42
|
+
return value.stack; // Стек ошибки
|
|
43
|
+
}
|
|
44
|
+
// Всё остальное форматируем через util.inspect()
|
|
45
|
+
return util_1.default.inspect(value, defaultOptions);
|
|
37
46
|
}
|
|
38
47
|
}
|
|
39
|
-
exports.
|
|
40
|
-
/**
|
|
41
|
-
* Преобразует строку в локальный путь VRack, на данный момент
|
|
42
|
-
* это просто приведение строки в lowerCase
|
|
43
|
-
*
|
|
44
|
-
*/
|
|
45
|
-
function toPath(text) {
|
|
46
|
-
return text.toLowerCase();
|
|
47
|
-
}
|
|
48
|
-
exports.toPath = toPath;
|
|
48
|
+
exports.default = Utility;
|
package/lib/actions/Action.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import GlobalAction from "./GlobalAction";
|
|
2
|
+
/**
|
|
3
|
+
* A class for defining new actions.
|
|
4
|
+
* It is not necessary to use `new Action`.
|
|
5
|
+
* You must use the static method `Action.global` to define a new action
|
|
6
|
+
*/
|
|
2
7
|
export default class Action {
|
|
8
|
+
/**
|
|
9
|
+
* The only type of action game at the moment. Does not have any special properties.
|
|
10
|
+
*
|
|
11
|
+
* @see BasicAction
|
|
12
|
+
*/
|
|
3
13
|
static global(): GlobalAction;
|
|
4
14
|
}
|
package/lib/actions/Action.js
CHANGED
|
@@ -8,7 +8,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
const GlobalAction_1 = __importDefault(require("./GlobalAction"));
|
|
11
|
+
/**
|
|
12
|
+
* A class for defining new actions.
|
|
13
|
+
* It is not necessary to use `new Action`.
|
|
14
|
+
* You must use the static method `Action.global` to define a new action
|
|
15
|
+
*/
|
|
11
16
|
class Action {
|
|
17
|
+
/**
|
|
18
|
+
* The only type of action game at the moment. Does not have any special properties.
|
|
19
|
+
*
|
|
20
|
+
* @see BasicAction
|
|
21
|
+
*/
|
|
12
22
|
static global() {
|
|
13
23
|
return new GlobalAction_1.default();
|
|
14
24
|
}
|
|
@@ -1,15 +1,75 @@
|
|
|
1
1
|
import BasicType from "../validator/types/BasicType";
|
|
2
2
|
import IAction from "./IAction";
|
|
3
3
|
import ILocalAction from "./ILocalAction";
|
|
4
|
+
/**
|
|
5
|
+
* Action base class.
|
|
6
|
+
* Forms settings for a new action in `fluent interface` style
|
|
7
|
+
*/
|
|
4
8
|
export default class BasicAction {
|
|
5
9
|
protected action: ILocalAction;
|
|
6
10
|
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Sets the requirements for incoming `Action` parameters
|
|
13
|
+
* These rules will be applied every time the user invokes this action
|
|
14
|
+
*
|
|
15
|
+
* The method necessarily accepts an object.
|
|
16
|
+
* An action method cannot accept anything other than an object
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* Action.global().requirements({
|
|
22
|
+
* id: Rule.number().require().default(0).description('Unique ID'),
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
* @param req Object of BasicType rules
|
|
26
|
+
*/
|
|
7
27
|
requirements(req: {
|
|
8
28
|
[key: string]: BasicType;
|
|
9
29
|
}): this;
|
|
30
|
+
/**
|
|
31
|
+
* Sets the requirements for the return value.
|
|
32
|
+
* This method does not guarantee that this action will return this particular data type.
|
|
33
|
+
* In fact, the return value is not validated.
|
|
34
|
+
* It may help to read the documentation for the device
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* Action.global().returns({
|
|
40
|
+
* id: Rule.number().require().default(0).description('Unique ID'),
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @param ret Object of BasicType rules
|
|
45
|
+
*/
|
|
10
46
|
returns(ret: {
|
|
11
47
|
[key: string]: BasicType;
|
|
12
48
|
}): this;
|
|
49
|
+
/**
|
|
50
|
+
* Set description of Action
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* Action.global().description('Short action description')
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
13
57
|
description(des: string): this;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the internal Action object.
|
|
60
|
+
* This method is used inside VRack2 when processing an Action inside Container
|
|
61
|
+
*
|
|
62
|
+
* **Do not use this method if it is not necessary**
|
|
63
|
+
*/
|
|
64
|
+
exportRaw(): ILocalAction;
|
|
65
|
+
/**
|
|
66
|
+
* Forms a new IAction object
|
|
67
|
+
* This method is used inside VRack2 when processing an Action inside Container
|
|
68
|
+
*
|
|
69
|
+
* **Do not use this method if it is not necessary**
|
|
70
|
+
*
|
|
71
|
+
* !hide for external users
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
14
74
|
export(): IAction;
|
|
15
75
|
}
|
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
* Licensed under the Apache License, Version 2.0
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
/**
|
|
8
|
+
* Action base class.
|
|
9
|
+
* Forms settings for a new action in `fluent interface` style
|
|
10
|
+
*/
|
|
7
11
|
class BasicAction {
|
|
8
12
|
constructor() {
|
|
9
13
|
this.action = {
|
|
@@ -13,18 +17,76 @@ class BasicAction {
|
|
|
13
17
|
description: ''
|
|
14
18
|
};
|
|
15
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Sets the requirements for incoming `Action` parameters
|
|
22
|
+
* These rules will be applied every time the user invokes this action
|
|
23
|
+
*
|
|
24
|
+
* The method necessarily accepts an object.
|
|
25
|
+
* An action method cannot accept anything other than an object
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* Action.global().requirements({
|
|
31
|
+
* id: Rule.number().require().default(0).description('Unique ID'),
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
* @param req Object of BasicType rules
|
|
35
|
+
*/
|
|
16
36
|
requirements(req) {
|
|
17
37
|
this.action.requirements = req;
|
|
18
38
|
return this;
|
|
19
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Sets the requirements for the return value.
|
|
42
|
+
* This method does not guarantee that this action will return this particular data type.
|
|
43
|
+
* In fact, the return value is not validated.
|
|
44
|
+
* It may help to read the documentation for the device
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* Action.global().returns({
|
|
50
|
+
* id: Rule.number().require().default(0).description('Unique ID'),
|
|
51
|
+
* })
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @param ret Object of BasicType rules
|
|
55
|
+
*/
|
|
20
56
|
returns(ret) {
|
|
21
57
|
this.action.returns = ret;
|
|
22
58
|
return this;
|
|
23
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Set description of Action
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* Action.global().description('Short action description')
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
24
68
|
description(des) {
|
|
25
69
|
this.action.description = des;
|
|
26
70
|
return this;
|
|
27
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns the internal Action object.
|
|
74
|
+
* This method is used inside VRack2 when processing an Action inside Container
|
|
75
|
+
*
|
|
76
|
+
* **Do not use this method if it is not necessary**
|
|
77
|
+
*/
|
|
78
|
+
exportRaw() {
|
|
79
|
+
return this.action;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Forms a new IAction object
|
|
83
|
+
* This method is used inside VRack2 when processing an Action inside Container
|
|
84
|
+
*
|
|
85
|
+
* **Do not use this method if it is not necessary**
|
|
86
|
+
*
|
|
87
|
+
* !hide for external users
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
28
90
|
export() {
|
|
29
91
|
const nAction = {
|
|
30
92
|
type: this.action.type,
|
|
@@ -8,6 +8,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
const BasicAction_1 = __importDefault(require("./BasicAction"));
|
|
11
|
+
/**
|
|
12
|
+
* Standart action class
|
|
13
|
+
*
|
|
14
|
+
* @see BasicAction
|
|
15
|
+
*/
|
|
11
16
|
class GlobalAction extends BasicAction_1.default {
|
|
12
17
|
constructor() {
|
|
13
18
|
super();
|
package/lib/actions/IAction.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import IValidationRule from "../validator/IValidationRule";
|
|
2
|
+
/**
|
|
3
|
+
* Internal (exported) Action interface
|
|
4
|
+
*/
|
|
2
5
|
export default interface IAction {
|
|
6
|
+
/** Type of action ('global' as default) */
|
|
3
7
|
type: string;
|
|
8
|
+
/** Requirements for incoming data */
|
|
4
9
|
requirements: {
|
|
5
10
|
[key: string]: IValidationRule;
|
|
6
11
|
};
|
|
12
|
+
/** Requirements to returned data */
|
|
7
13
|
returns: {
|
|
8
14
|
[key: string]: IValidationRule;
|
|
9
15
|
};
|
|
16
|
+
/** A short text description of the action */
|
|
10
17
|
description: string;
|
|
11
18
|
}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import BasicType from "../validator/types/BasicType";
|
|
2
|
+
/**
|
|
3
|
+
* Internal (raw exported) Action interface
|
|
4
|
+
*/
|
|
2
5
|
export default interface ILocalAction {
|
|
6
|
+
/** Type of action ('global' as default) */
|
|
3
7
|
type: string;
|
|
8
|
+
/** Requirements for incoming data */
|
|
4
9
|
requirements: {
|
|
5
10
|
[key: string]: BasicType;
|
|
6
11
|
};
|
|
12
|
+
/** Requirements to returned data */
|
|
7
13
|
returns: {
|
|
8
14
|
[key: string]: BasicType;
|
|
9
15
|
};
|
|
16
|
+
/** A short text description of the action */
|
|
10
17
|
description: string;
|
|
11
18
|
}
|