vrack2-core 0.0.1 → 1.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/README.md +33 -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 +311 -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 +15 -14
- 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 +346 -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
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import BasicType from "./BasicType"
|
|
7
|
-
import IValidationRule from "../IValidationRule"
|
|
8
7
|
import ErrorManager from "../../errors/ErrorManager"
|
|
9
|
-
import Rule from "../Rule"
|
|
10
8
|
import IValidationSubrule from "../IValidationSubrule"
|
|
11
9
|
|
|
12
10
|
export default class StringType extends BasicType {
|
|
@@ -15,48 +13,74 @@ export default class StringType extends BasicType {
|
|
|
15
13
|
this.rule.type = 'string'
|
|
16
14
|
}
|
|
17
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Example of a valid value for this rule
|
|
18
|
+
*
|
|
19
|
+
* @param ex Example valid value
|
|
20
|
+
*/
|
|
18
21
|
example(ex: string): this {
|
|
19
22
|
this.rule.example = ex
|
|
20
23
|
return this
|
|
21
24
|
}
|
|
22
|
-
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Setting the default value
|
|
28
|
+
*/
|
|
23
29
|
default(def: string) {
|
|
24
30
|
this.rule.default = def
|
|
25
31
|
return this
|
|
26
32
|
}
|
|
27
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Sets the maximum length of the string
|
|
36
|
+
*/
|
|
28
37
|
maxLength(max: number) {
|
|
29
38
|
this.rule.rules.push({ name: 'maxLength', args: max })
|
|
30
39
|
return this
|
|
31
40
|
}
|
|
32
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Sets the minimum length of the string
|
|
44
|
+
*/
|
|
33
45
|
minLength(min: number) {
|
|
34
46
|
this.rule.rules.push({ name: 'minLength', args: min })
|
|
35
47
|
return this
|
|
36
48
|
}
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Method of validation of this type
|
|
52
|
+
*
|
|
53
|
+
* @param obj Validation object
|
|
54
|
+
* @param key Key for getting value from object
|
|
55
|
+
*/
|
|
56
|
+
validate(obj: {[key:string]: any}, key: string){
|
|
57
|
+
this.basicValidate(obj, key)
|
|
40
58
|
if (typeof obj[key] !== 'string') throw ErrorManager.make('VR_IS_NOT_STRING', { key })
|
|
41
|
-
for (const subrule of rule.rules){
|
|
59
|
+
for (const subrule of this.rule.rules){
|
|
42
60
|
switch (subrule.name){
|
|
43
61
|
case 'maxLength':
|
|
44
|
-
|
|
62
|
+
this.checkMaxLength(obj, key, subrule)
|
|
45
63
|
break
|
|
46
64
|
case 'minLength':
|
|
47
|
-
|
|
65
|
+
this.checkMinLength(obj, key, subrule)
|
|
48
66
|
break
|
|
49
67
|
}
|
|
50
68
|
}
|
|
51
69
|
return true
|
|
52
70
|
}
|
|
53
71
|
|
|
54
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Checking the maximum string length
|
|
74
|
+
*/
|
|
75
|
+
protected checkMaxLength(obj: {[key:string]: any}, key: string, sub: IValidationSubrule){
|
|
55
76
|
const val = obj[key]
|
|
56
77
|
if (val.length >= sub.args) throw ErrorManager.make('VR_STRING_MAX_LENGTH', { limit: sub.args, key })
|
|
57
78
|
}
|
|
58
79
|
|
|
59
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Checking the minimum string length
|
|
82
|
+
*/
|
|
83
|
+
protected checkMinLength(obj: {[key:string]: any}, key: string, sub: IValidationSubrule){
|
|
60
84
|
const val = obj[key]
|
|
61
85
|
if (val.length <= sub.args) throw ErrorManager.make('VR_STRING_MIN_LENGTH', { limit: sub.args, key })
|
|
62
86
|
}
|
package/docs/RU-README.md
DELETED
package/lib/DeviceManager.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
interface IDeviceGroup {
|
|
2
|
-
name: string;
|
|
3
|
-
dir: string;
|
|
4
|
-
devices: Array<any>;
|
|
5
|
-
deviceList: Array<string>;
|
|
6
|
-
errors: Array<string>;
|
|
7
|
-
description: string;
|
|
8
|
-
}
|
|
9
|
-
export default class DeviceManager {
|
|
10
|
-
dir: string;
|
|
11
|
-
systemDir: string;
|
|
12
|
-
devices: Map<string, string>;
|
|
13
|
-
deviceList: Array<IDeviceGroup>;
|
|
14
|
-
constructor(systemDir: string, dir: string);
|
|
15
|
-
updateList(): IDeviceGroup[];
|
|
16
|
-
devicesList(): IDeviceGroup[];
|
|
17
|
-
/**
|
|
18
|
-
* Return class of device
|
|
19
|
-
*
|
|
20
|
-
* Requires special device string of path
|
|
21
|
-
* example "vrack.System" where "vrack" is vendor and "System" is device class
|
|
22
|
-
* @param {string} device Device path string
|
|
23
|
-
*/
|
|
24
|
-
get(device: string): Promise<any>;
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
private getOnlyDirs;
|
|
31
|
-
}
|
|
32
|
-
export {};
|
package/lib/DeviceManager.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
const path_1 = __importDefault(require("path"));
|
|
39
|
-
const fs_1 = __importDefault(require("fs"));
|
|
40
|
-
const ErrorManager_1 = __importDefault(require("./errors/ErrorManager"));
|
|
41
|
-
const Rule_1 = __importDefault(require("./validator/Rule"));
|
|
42
|
-
ErrorManager_1.default.register('DeviceManager', 'S5dBTBKTnVbF', 'DM_DEVICE_NOT_FOUND', 'Device not found', {
|
|
43
|
-
device: Rule_1.default.string().require().description('Device request name')
|
|
44
|
-
});
|
|
45
|
-
class DeviceManager {
|
|
46
|
-
constructor(systemDir, dir) {
|
|
47
|
-
this.dir = './devices';
|
|
48
|
-
this.devices = new Map();
|
|
49
|
-
this.deviceList = [];
|
|
50
|
-
this.systemDir = systemDir;
|
|
51
|
-
this.dir = dir;
|
|
52
|
-
}
|
|
53
|
-
updateList() {
|
|
54
|
-
this.deviceList = this.devicesList();
|
|
55
|
-
for (const dgroup of this.deviceList) {
|
|
56
|
-
dgroup.devices = [];
|
|
57
|
-
for (const device of dgroup.deviceList) {
|
|
58
|
-
const ndevice = { name: device, errors: [] };
|
|
59
|
-
dgroup.devices.push(ndevice);
|
|
60
|
-
const devicePath = path_1.default.join(this.systemDir, this.dir, dgroup.name, device + '.js');
|
|
61
|
-
if (!fs_1.default.existsSync(devicePath)) {
|
|
62
|
-
ndevice.errors.push('File of device not found');
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return this.deviceList;
|
|
68
|
-
}
|
|
69
|
-
devicesList() {
|
|
70
|
-
const result = [];
|
|
71
|
-
const files = fs_1.default.readdirSync(path_1.default.join(this.systemDir, this.dir));
|
|
72
|
-
const dirs = this.getOnlyDirs(files);
|
|
73
|
-
dirs.sort();
|
|
74
|
-
for (const ddir of dirs) {
|
|
75
|
-
const group = {
|
|
76
|
-
name: ddir,
|
|
77
|
-
dir: this.dir,
|
|
78
|
-
devices: [],
|
|
79
|
-
deviceList: [],
|
|
80
|
-
errors: [],
|
|
81
|
-
description: ''
|
|
82
|
-
};
|
|
83
|
-
result.push(group);
|
|
84
|
-
const listPath = path_1.default.join(this.systemDir, this.dir, ddir, 'list.json');
|
|
85
|
-
if (!fs_1.default.existsSync(listPath)) {
|
|
86
|
-
group.errors.push(listPath + ' ignored - list.json not found');
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
// @todo Исправить на SAFE
|
|
90
|
-
const list = JSON.parse(fs_1.default.readFileSync(listPath).toString('utf-8'));
|
|
91
|
-
if (!list || !Array.isArray(list)) {
|
|
92
|
-
group.errors.push(listPath + ' ignored - list.json incorrect');
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
for (const listKey in list) {
|
|
96
|
-
const reqPath = path_1.default.join(this.systemDir, this.dir, ddir, list[listKey]);
|
|
97
|
-
const devicePath = reqPath + '.js';
|
|
98
|
-
if (fs_1.default.existsSync(devicePath)) {
|
|
99
|
-
if (!this.devices.has(ddir + '.' + list[listKey]))
|
|
100
|
-
this.devices.set(ddir + '.' + list[listKey], reqPath);
|
|
101
|
-
else
|
|
102
|
-
console.log(devicePath + ' ignored - device not found');
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
list.sort();
|
|
106
|
-
group.deviceList = list;
|
|
107
|
-
}
|
|
108
|
-
return result;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Return class of device
|
|
112
|
-
*
|
|
113
|
-
* Requires special device string of path
|
|
114
|
-
* example "vrack.System" where "vrack" is vendor and "System" is device class
|
|
115
|
-
* @param {string} device Device path string
|
|
116
|
-
*/
|
|
117
|
-
get(device) {
|
|
118
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
-
const p = this.devices.get(device);
|
|
120
|
-
if (typeof p === 'string') {
|
|
121
|
-
const deviceClass = yield Promise.resolve(`${p}`).then(s => __importStar(require(s)));
|
|
122
|
-
if (deviceClass.default)
|
|
123
|
-
return deviceClass.default;
|
|
124
|
-
}
|
|
125
|
-
throw ErrorManager_1.default.make('DM_DEVICE_NOT_FOUND', { device });
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*/
|
|
133
|
-
getOnlyDirs(files) {
|
|
134
|
-
const result = [];
|
|
135
|
-
for (const i in files) {
|
|
136
|
-
if (fs_1.default.statSync(path_1.default.join(this.systemDir, this.dir, files[i])).isDirectory())
|
|
137
|
-
result.push(files[i]);
|
|
138
|
-
}
|
|
139
|
-
result.sort();
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
exports.default = DeviceManager;
|
package/lib/test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/test.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import Action from "./rack/Action";
|
|
3
|
-
// import Port from "./rack/Port";
|
|
4
|
-
// import Rule from "./validator/Rule";
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const Rule_1 = __importDefault(require("./validator/Rule"));
|
|
10
|
-
const Validator_1 = __importDefault(require("./validator/Validator"));
|
|
11
|
-
Rule_1.default.array().require();
|
|
12
|
-
// class Device {
|
|
13
|
-
// options (){
|
|
14
|
-
// return {
|
|
15
|
-
// test: Rule.string().default('Default string').description('Test string'),
|
|
16
|
-
// list: Rule.Array().objects({
|
|
17
|
-
// name: Rule.string(),
|
|
18
|
-
// value: Rule.number()
|
|
19
|
-
// })
|
|
20
|
-
// }
|
|
21
|
-
// }
|
|
22
|
-
// outputs(){
|
|
23
|
-
// return {
|
|
24
|
-
// 'test.output%d': Port.standart().dynamic(5),
|
|
25
|
-
// }
|
|
26
|
-
// }
|
|
27
|
-
// inputs(){
|
|
28
|
-
// return {
|
|
29
|
-
// 'test.output%d': Port.return().dynamic(5),
|
|
30
|
-
// }
|
|
31
|
-
// }
|
|
32
|
-
// actions(){
|
|
33
|
-
// return {
|
|
34
|
-
// 'test.action': Action.global().rules({
|
|
35
|
-
// test: Rule.string().default('Default string').description('Test string'),
|
|
36
|
-
// }).description('Test action for call global')
|
|
37
|
-
// }
|
|
38
|
-
// }
|
|
39
|
-
// init(){
|
|
40
|
-
// }
|
|
41
|
-
// process(){
|
|
42
|
-
// }
|
|
43
|
-
// async processPromise(){
|
|
44
|
-
// }
|
|
45
|
-
// }
|
|
46
|
-
const rules = {
|
|
47
|
-
obj: Rule_1.default.object().require().description('Test validation object'),
|
|
48
|
-
str: Rule_1.default.string().require().minLength(5),
|
|
49
|
-
arr: Rule_1.default.array().require(),
|
|
50
|
-
num: Rule_1.default.number().require().integer().description('integer test')
|
|
51
|
-
};
|
|
52
|
-
const data = {
|
|
53
|
-
obj: {},
|
|
54
|
-
str: 'qwe4',
|
|
55
|
-
arr: [],
|
|
56
|
-
num: 1.23
|
|
57
|
-
};
|
|
58
|
-
Validator_1.default.validate(rules, data);
|
package/src/DeviceManager.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import fs from 'fs'
|
|
3
|
-
import ErrorManager from './errors/ErrorManager'
|
|
4
|
-
import Rule from './validator/Rule'
|
|
5
|
-
|
|
6
|
-
interface IDeviceGroup {
|
|
7
|
-
name: string,
|
|
8
|
-
dir: string,
|
|
9
|
-
devices: Array<any>,
|
|
10
|
-
deviceList: Array<string>,
|
|
11
|
-
errors: Array<string>,
|
|
12
|
-
description: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface IDeviceInGroup{
|
|
16
|
-
name: string,
|
|
17
|
-
errors: Array<string>
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
ErrorManager.register('DeviceManager', 'S5dBTBKTnVbF', 'DM_DEVICE_NOT_FOUND','Device not found', {
|
|
21
|
-
device: Rule.string().require().description('Device request name')
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
export default class DeviceManager {
|
|
25
|
-
|
|
26
|
-
dir = './devices'
|
|
27
|
-
systemDir: string
|
|
28
|
-
|
|
29
|
-
devices = new Map<string, string>()
|
|
30
|
-
deviceList: Array<IDeviceGroup> = []
|
|
31
|
-
constructor(systemDir: string, dir: string) {
|
|
32
|
-
this.systemDir = systemDir
|
|
33
|
-
this.dir = dir
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
updateList() {
|
|
38
|
-
this.deviceList = this.devicesList()
|
|
39
|
-
for (const dgroup of this.deviceList) {
|
|
40
|
-
dgroup.devices = []
|
|
41
|
-
for (const device of dgroup.deviceList) {
|
|
42
|
-
const ndevice : IDeviceInGroup = { name: device, errors: [] }
|
|
43
|
-
dgroup.devices.push(ndevice)
|
|
44
|
-
const devicePath = path.join(this.systemDir, this.dir, dgroup.name, device + '.js')
|
|
45
|
-
if (!fs.existsSync(devicePath)) { ndevice.errors.push('File of device not found'); continue }
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return this.deviceList
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
devicesList() {
|
|
52
|
-
const result: Array<IDeviceGroup> = []
|
|
53
|
-
const files = fs.readdirSync(path.join(this.systemDir, this.dir))
|
|
54
|
-
const dirs = this.getOnlyDirs(files)
|
|
55
|
-
dirs.sort()
|
|
56
|
-
for (const ddir of dirs) {
|
|
57
|
-
const group: IDeviceGroup = {
|
|
58
|
-
name: ddir,
|
|
59
|
-
dir: this.dir,
|
|
60
|
-
devices: [],
|
|
61
|
-
deviceList: [],
|
|
62
|
-
errors: [],
|
|
63
|
-
description: ''
|
|
64
|
-
}
|
|
65
|
-
result.push(group)
|
|
66
|
-
const listPath = path.join(this.systemDir, this.dir, ddir, 'list.json')
|
|
67
|
-
|
|
68
|
-
if (!fs.existsSync(listPath)) {
|
|
69
|
-
group.errors.push(listPath + ' ignored - list.json not found');
|
|
70
|
-
continue
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// @todo Исправить на SAFE
|
|
74
|
-
const list: Array<string> = JSON.parse(fs.readFileSync(listPath).toString('utf-8'))
|
|
75
|
-
if (!list || !Array.isArray(list)) {
|
|
76
|
-
group.errors.push(listPath + ' ignored - list.json incorrect');
|
|
77
|
-
continue
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
for (const listKey in list) {
|
|
81
|
-
const reqPath = path.join(this.systemDir, this.dir, ddir, list[listKey])
|
|
82
|
-
const devicePath = reqPath + '.js'
|
|
83
|
-
if (fs.existsSync(devicePath)) {
|
|
84
|
-
if (!this.devices.has(ddir + '.' + list[listKey])) this.devices.set(ddir + '.' + list[listKey], reqPath)
|
|
85
|
-
else console.log(devicePath + ' ignored - device not found')
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
list.sort()
|
|
89
|
-
|
|
90
|
-
group.deviceList = list
|
|
91
|
-
}
|
|
92
|
-
return result
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Return class of device
|
|
97
|
-
*
|
|
98
|
-
* Requires special device string of path
|
|
99
|
-
* example "vrack.System" where "vrack" is vendor and "System" is device class
|
|
100
|
-
* @param {string} device Device path string
|
|
101
|
-
*/
|
|
102
|
-
async get(device:string){
|
|
103
|
-
const p: string | undefined = this.devices.get(device)
|
|
104
|
-
if (typeof p ==='string') {
|
|
105
|
-
const deviceClass = await import(p)
|
|
106
|
-
if (deviceClass.default) return deviceClass.default
|
|
107
|
-
}
|
|
108
|
-
throw ErrorManager.make('DM_DEVICE_NOT_FOUND', { device })
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*/
|
|
116
|
-
private getOnlyDirs(files: Array<string>) {
|
|
117
|
-
const result: Array<string> = []
|
|
118
|
-
for (const i in files) {
|
|
119
|
-
if (fs.statSync(path.join(this.systemDir, this.dir, files[i])).isDirectory()) result.push(files[i])
|
|
120
|
-
}
|
|
121
|
-
result.sort()
|
|
122
|
-
return result
|
|
123
|
-
}
|
|
124
|
-
}
|
package/src/test.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// import Action from "./rack/Action";
|
|
2
|
-
// import Port from "./rack/Port";
|
|
3
|
-
// import Rule from "./validator/Rule";
|
|
4
|
-
|
|
5
|
-
import Rule from "./validator/Rule";
|
|
6
|
-
import Validator from "./validator/Validator";
|
|
7
|
-
|
|
8
|
-
Rule.array().require()
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// class Device {
|
|
12
|
-
|
|
13
|
-
// options (){
|
|
14
|
-
// return {
|
|
15
|
-
// test: Rule.string().default('Default string').description('Test string'),
|
|
16
|
-
// list: Rule.Array().objects({
|
|
17
|
-
// name: Rule.string(),
|
|
18
|
-
// value: Rule.number()
|
|
19
|
-
// })
|
|
20
|
-
// }
|
|
21
|
-
// }
|
|
22
|
-
|
|
23
|
-
// outputs(){
|
|
24
|
-
// return {
|
|
25
|
-
// 'test.output%d': Port.standart().dynamic(5),
|
|
26
|
-
// }
|
|
27
|
-
// }
|
|
28
|
-
|
|
29
|
-
// inputs(){
|
|
30
|
-
// return {
|
|
31
|
-
// 'test.output%d': Port.return().dynamic(5),
|
|
32
|
-
// }
|
|
33
|
-
// }
|
|
34
|
-
|
|
35
|
-
// actions(){
|
|
36
|
-
// return {
|
|
37
|
-
// 'test.action': Action.global().rules({
|
|
38
|
-
// test: Rule.string().default('Default string').description('Test string'),
|
|
39
|
-
// }).description('Test action for call global')
|
|
40
|
-
// }
|
|
41
|
-
// }
|
|
42
|
-
|
|
43
|
-
// init(){
|
|
44
|
-
|
|
45
|
-
// }
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// process(){
|
|
49
|
-
|
|
50
|
-
// }
|
|
51
|
-
|
|
52
|
-
// async processPromise(){
|
|
53
|
-
|
|
54
|
-
// }
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// }
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const rules = {
|
|
65
|
-
obj: Rule.object().require().description('Test validation object'),
|
|
66
|
-
str: Rule.string().require().minLength(5),
|
|
67
|
-
arr: Rule.array().require(),
|
|
68
|
-
num: Rule.number().require().integer().description('integer test')
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const data = {
|
|
73
|
-
obj: {},
|
|
74
|
-
str: 'qwe4',
|
|
75
|
-
arr: [],
|
|
76
|
-
num: 1.23
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
Validator.validate(rules,data)
|
|
81
|
-
|
|
82
|
-
|