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
|
@@ -1,19 +1,54 @@
|
|
|
1
1
|
import BasicType from "./BasicType";
|
|
2
|
-
import IValidationRule from "../IValidationRule";
|
|
3
2
|
import IValidationSubrule from "../IValidationSubrule";
|
|
4
3
|
export default class NumberType extends BasicType {
|
|
5
4
|
constructor();
|
|
5
|
+
/**
|
|
6
|
+
* Example of a valid value for this rule
|
|
7
|
+
*
|
|
8
|
+
* @param ex Example valid value
|
|
9
|
+
*/
|
|
10
|
+
example(ex: number): this;
|
|
11
|
+
/**
|
|
12
|
+
* Setting the default value
|
|
13
|
+
*/
|
|
6
14
|
default(def: number): this;
|
|
15
|
+
/**
|
|
16
|
+
* Adds an integer check
|
|
17
|
+
*/
|
|
7
18
|
integer(): this;
|
|
19
|
+
/**
|
|
20
|
+
* Defines the maximum value for the rule
|
|
21
|
+
*/
|
|
8
22
|
max(max: number): this;
|
|
23
|
+
/**
|
|
24
|
+
* Defines the minimal value for the rule
|
|
25
|
+
*/
|
|
9
26
|
min(min: number): this;
|
|
10
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Method of validation of this type
|
|
29
|
+
*
|
|
30
|
+
* @param obj Validation object
|
|
31
|
+
* @param key Key for getting value from object
|
|
32
|
+
*/
|
|
33
|
+
validate(obj: {
|
|
11
34
|
[key: string]: any;
|
|
12
|
-
}, key: string
|
|
13
|
-
|
|
35
|
+
}, key: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Checking the maximum value
|
|
38
|
+
*/
|
|
39
|
+
protected checkMax(obj: {
|
|
14
40
|
[key: string]: any;
|
|
15
41
|
}, key: string, sub: IValidationSubrule): void;
|
|
16
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Checking the minimal value
|
|
44
|
+
*/
|
|
45
|
+
protected checkMin(obj: {
|
|
17
46
|
[key: string]: any;
|
|
18
47
|
}, key: string, sub: IValidationSubrule): void;
|
|
48
|
+
/**
|
|
49
|
+
* Integer check
|
|
50
|
+
*/
|
|
51
|
+
protected checkInteger(obj: {
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
}, key: string): void;
|
|
19
54
|
}
|
|
@@ -14,50 +14,89 @@ class NumberType extends BasicType_1.default {
|
|
|
14
14
|
super();
|
|
15
15
|
this.rule.type = 'number';
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Example of a valid value for this rule
|
|
19
|
+
*
|
|
20
|
+
* @param ex Example valid value
|
|
21
|
+
*/
|
|
22
|
+
example(ex) {
|
|
23
|
+
this.rule.example = ex;
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Setting the default value
|
|
28
|
+
*/
|
|
17
29
|
default(def) {
|
|
18
30
|
this.rule.default = def;
|
|
19
31
|
return this;
|
|
20
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Adds an integer check
|
|
35
|
+
*/
|
|
21
36
|
integer() {
|
|
22
37
|
this.rule.rules.push({ name: 'integer', args: {} });
|
|
23
38
|
return this;
|
|
24
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Defines the maximum value for the rule
|
|
42
|
+
*/
|
|
25
43
|
max(max) {
|
|
26
44
|
this.rule.rules.push({ name: 'max', args: max });
|
|
27
45
|
return this;
|
|
28
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Defines the minimal value for the rule
|
|
49
|
+
*/
|
|
29
50
|
min(min) {
|
|
30
|
-
this.rule.rules.push({ name: '
|
|
51
|
+
this.rule.rules.push({ name: 'min', args: min });
|
|
31
52
|
return this;
|
|
32
53
|
}
|
|
33
|
-
|
|
34
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Method of validation of this type
|
|
56
|
+
*
|
|
57
|
+
* @param obj Validation object
|
|
58
|
+
* @param key Key for getting value from object
|
|
59
|
+
*/
|
|
60
|
+
validate(obj, key) {
|
|
61
|
+
this.basicValidate(obj, key);
|
|
35
62
|
if (typeof obj[key] !== 'number')
|
|
36
63
|
throw ErrorManager_1.default.make('VR_IS_NOT_NUMBER', { key });
|
|
37
|
-
|
|
38
|
-
throw ErrorManager_1.default.make('VR_NUMBER_INTEGER', {});
|
|
39
|
-
for (const subrule of rule.rules) {
|
|
64
|
+
for (const subrule of this.rule.rules) {
|
|
40
65
|
switch (subrule.name) {
|
|
66
|
+
case 'integer':
|
|
67
|
+
this.checkInteger(obj, key);
|
|
68
|
+
break;
|
|
41
69
|
case 'max':
|
|
42
|
-
|
|
70
|
+
this.checkMax(obj, key, subrule);
|
|
43
71
|
break;
|
|
44
72
|
case 'min':
|
|
45
|
-
|
|
73
|
+
this.checkMin(obj, key, subrule);
|
|
46
74
|
break;
|
|
47
75
|
}
|
|
48
76
|
}
|
|
49
77
|
return true;
|
|
50
78
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Checking the maximum value
|
|
81
|
+
*/
|
|
82
|
+
checkMax(obj, key, sub) {
|
|
83
|
+
if (obj[key] > sub.args)
|
|
54
84
|
throw ErrorManager_1.default.make('VR_NUMBER_MAX', { limit: sub.args });
|
|
55
85
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Checking the minimal value
|
|
88
|
+
*/
|
|
89
|
+
checkMin(obj, key, sub) {
|
|
90
|
+
if (obj[key] < sub.args)
|
|
59
91
|
throw ErrorManager_1.default.make('VR_NUMBER_MIN', { limit: sub.args });
|
|
60
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Integer check
|
|
95
|
+
*/
|
|
96
|
+
checkInteger(obj, key) {
|
|
97
|
+
if (!Number.isInteger(obj[key]))
|
|
98
|
+
throw ErrorManager_1.default.make('VR_NUMBER_INTEGER', {});
|
|
99
|
+
}
|
|
61
100
|
}
|
|
62
101
|
exports.default = NumberType;
|
|
63
102
|
ErrorManager_1.default.register('Validator', 'pn7B9po1UGRp', 'VR_IS_NOT_NUMBER', 'Value must be a number', {});
|
|
@@ -1,18 +1,45 @@
|
|
|
1
1
|
import BasicType from "./BasicType";
|
|
2
|
-
import IValidationRule from "../IValidationRule";
|
|
3
2
|
import IValidationSubrule from "../IValidationSubrule";
|
|
4
3
|
export default class ObjectType extends BasicType {
|
|
5
4
|
constructor();
|
|
5
|
+
/**
|
|
6
|
+
* Example of a valid value for this rule
|
|
7
|
+
*
|
|
8
|
+
* @param ex Example valid value
|
|
9
|
+
*/
|
|
10
|
+
example(ex: any): this;
|
|
11
|
+
/**
|
|
12
|
+
* Setting the default value
|
|
13
|
+
*/
|
|
14
|
+
default(def: object): this;
|
|
15
|
+
/**
|
|
16
|
+
* Rule object for defining properties
|
|
17
|
+
*
|
|
18
|
+
* Allows you to describe the fields of the required object
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* obj: Rule.object().fields({
|
|
23
|
+
* bool: Rule.boolean().require().default(true).description('Boolean checkbox')
|
|
24
|
+
* }).description('TEst ibject description'),
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
6
27
|
fields(obj: {
|
|
7
28
|
[key: string]: BasicType;
|
|
8
|
-
}):
|
|
9
|
-
|
|
29
|
+
}): this;
|
|
30
|
+
/**
|
|
31
|
+
* Method of validation of this type
|
|
32
|
+
*
|
|
33
|
+
* @param obj Validation object
|
|
34
|
+
* @param key Key for getting value from object
|
|
35
|
+
*/
|
|
36
|
+
validate(obj: {
|
|
10
37
|
[key: string]: any;
|
|
11
|
-
}, key: string
|
|
38
|
+
}, key: string): boolean;
|
|
12
39
|
/**
|
|
13
40
|
* Validate object fields
|
|
14
41
|
*/
|
|
15
|
-
protected
|
|
42
|
+
protected subValidate(obj: {
|
|
16
43
|
[key: string]: any;
|
|
17
44
|
}, key: string, sub: IValidationSubrule): void;
|
|
18
45
|
}
|
|
@@ -10,23 +10,57 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
const BasicType_1 = __importDefault(require("./BasicType"));
|
|
11
11
|
const ErrorManager_1 = __importDefault(require("../../errors/ErrorManager"));
|
|
12
12
|
const Validator_1 = __importDefault(require("../Validator"));
|
|
13
|
-
const CoreError_1 = __importDefault(require("../../errors/CoreError"));
|
|
14
13
|
class ObjectType extends BasicType_1.default {
|
|
15
14
|
constructor() {
|
|
16
15
|
super();
|
|
17
16
|
this.rule.type = 'object';
|
|
18
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Example of a valid value for this rule
|
|
20
|
+
*
|
|
21
|
+
* @param ex Example valid value
|
|
22
|
+
*/
|
|
23
|
+
example(ex) {
|
|
24
|
+
this.rule.example = ex;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Setting the default value
|
|
29
|
+
*/
|
|
30
|
+
default(def) {
|
|
31
|
+
this.rule.default = def;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Rule object for defining properties
|
|
36
|
+
*
|
|
37
|
+
* Allows you to describe the fields of the required object
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* obj: Rule.object().fields({
|
|
42
|
+
* bool: Rule.boolean().require().default(true).description('Boolean checkbox')
|
|
43
|
+
* }).description('TEst ibject description'),
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
19
46
|
fields(obj) {
|
|
20
|
-
|
|
47
|
+
this.rule.rules.push({ name: 'fields', args: obj });
|
|
48
|
+
return this;
|
|
21
49
|
}
|
|
22
|
-
|
|
23
|
-
|
|
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) {
|
|
57
|
+
this.basicValidate(obj, key);
|
|
24
58
|
if (typeof obj[key] !== 'object')
|
|
25
59
|
throw ErrorManager_1.default.make('VR_IS_NOT_OBJECT', {});
|
|
26
|
-
for (const subrule of rule.rules) {
|
|
60
|
+
for (const subrule of this.rule.rules) {
|
|
27
61
|
switch (subrule.name) {
|
|
28
62
|
case 'fields':
|
|
29
|
-
|
|
63
|
+
this.subValidate(obj, key, subrule);
|
|
30
64
|
break;
|
|
31
65
|
}
|
|
32
66
|
}
|
|
@@ -35,12 +69,12 @@ class ObjectType extends BasicType_1.default {
|
|
|
35
69
|
/**
|
|
36
70
|
* Validate object fields
|
|
37
71
|
*/
|
|
38
|
-
|
|
72
|
+
subValidate(obj, key, sub) {
|
|
39
73
|
try {
|
|
40
74
|
Validator_1.default.validate(sub.args, obj[key]);
|
|
41
75
|
}
|
|
42
76
|
catch (error) {
|
|
43
|
-
if (error instanceof
|
|
77
|
+
if (error instanceof Error) {
|
|
44
78
|
throw ErrorManager_1.default.make('VR_ERROR_OBJECT_FIELDS', { key }).add(error);
|
|
45
79
|
}
|
|
46
80
|
}
|
|
@@ -1,19 +1,44 @@
|
|
|
1
1
|
import BasicType from "./BasicType";
|
|
2
|
-
import IValidationRule from "../IValidationRule";
|
|
3
2
|
import IValidationSubrule from "../IValidationSubrule";
|
|
4
3
|
export default class StringType extends BasicType {
|
|
5
4
|
constructor();
|
|
5
|
+
/**
|
|
6
|
+
* Example of a valid value for this rule
|
|
7
|
+
*
|
|
8
|
+
* @param ex Example valid value
|
|
9
|
+
*/
|
|
6
10
|
example(ex: string): this;
|
|
11
|
+
/**
|
|
12
|
+
* Setting the default value
|
|
13
|
+
*/
|
|
7
14
|
default(def: string): this;
|
|
15
|
+
/**
|
|
16
|
+
* Sets the maximum length of the string
|
|
17
|
+
*/
|
|
8
18
|
maxLength(max: number): this;
|
|
19
|
+
/**
|
|
20
|
+
* Sets the minimum length of the string
|
|
21
|
+
*/
|
|
9
22
|
minLength(min: number): this;
|
|
10
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Method of validation of this type
|
|
25
|
+
*
|
|
26
|
+
* @param obj Validation object
|
|
27
|
+
* @param key Key for getting value from object
|
|
28
|
+
*/
|
|
29
|
+
validate(obj: {
|
|
11
30
|
[key: string]: any;
|
|
12
|
-
}, key: string
|
|
13
|
-
|
|
31
|
+
}, key: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Checking the maximum string length
|
|
34
|
+
*/
|
|
35
|
+
protected checkMaxLength(obj: {
|
|
14
36
|
[key: string]: any;
|
|
15
37
|
}, key: string, sub: IValidationSubrule): void;
|
|
16
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Checking the minimum string length
|
|
40
|
+
*/
|
|
41
|
+
protected checkMinLength(obj: {
|
|
17
42
|
[key: string]: any;
|
|
18
43
|
}, key: string, sub: IValidationSubrule): void;
|
|
19
44
|
}
|
|
@@ -14,44 +14,70 @@ class StringType extends BasicType_1.default {
|
|
|
14
14
|
super();
|
|
15
15
|
this.rule.type = 'string';
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Example of a valid value for this rule
|
|
19
|
+
*
|
|
20
|
+
* @param ex Example valid value
|
|
21
|
+
*/
|
|
17
22
|
example(ex) {
|
|
18
23
|
this.rule.example = ex;
|
|
19
24
|
return this;
|
|
20
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Setting the default value
|
|
28
|
+
*/
|
|
21
29
|
default(def) {
|
|
22
30
|
this.rule.default = def;
|
|
23
31
|
return this;
|
|
24
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Sets the maximum length of the string
|
|
35
|
+
*/
|
|
25
36
|
maxLength(max) {
|
|
26
37
|
this.rule.rules.push({ name: 'maxLength', args: max });
|
|
27
38
|
return this;
|
|
28
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Sets the minimum length of the string
|
|
42
|
+
*/
|
|
29
43
|
minLength(min) {
|
|
30
44
|
this.rule.rules.push({ name: 'minLength', args: min });
|
|
31
45
|
return this;
|
|
32
46
|
}
|
|
33
|
-
|
|
34
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Method of validation of this type
|
|
49
|
+
*
|
|
50
|
+
* @param obj Validation object
|
|
51
|
+
* @param key Key for getting value from object
|
|
52
|
+
*/
|
|
53
|
+
validate(obj, key) {
|
|
54
|
+
this.basicValidate(obj, key);
|
|
35
55
|
if (typeof obj[key] !== 'string')
|
|
36
56
|
throw ErrorManager_1.default.make('VR_IS_NOT_STRING', { key });
|
|
37
|
-
for (const subrule of rule.rules) {
|
|
57
|
+
for (const subrule of this.rule.rules) {
|
|
38
58
|
switch (subrule.name) {
|
|
39
59
|
case 'maxLength':
|
|
40
|
-
|
|
60
|
+
this.checkMaxLength(obj, key, subrule);
|
|
41
61
|
break;
|
|
42
62
|
case 'minLength':
|
|
43
|
-
|
|
63
|
+
this.checkMinLength(obj, key, subrule);
|
|
44
64
|
break;
|
|
45
65
|
}
|
|
46
66
|
}
|
|
47
67
|
return true;
|
|
48
68
|
}
|
|
49
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Checking the maximum string length
|
|
71
|
+
*/
|
|
72
|
+
checkMaxLength(obj, key, sub) {
|
|
50
73
|
const val = obj[key];
|
|
51
74
|
if (val.length >= sub.args)
|
|
52
75
|
throw ErrorManager_1.default.make('VR_STRING_MAX_LENGTH', { limit: sub.args, key });
|
|
53
76
|
}
|
|
54
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Checking the minimum string length
|
|
79
|
+
*/
|
|
80
|
+
checkMinLength(obj, key, sub) {
|
|
55
81
|
const val = obj[key];
|
|
56
82
|
if (val.length <= sub.args)
|
|
57
83
|
throw ErrorManager_1.default.make('VR_STRING_MIN_LENGTH', { limit: sub.args, key });
|
package/package.json
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vrack2-core",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Фреймворк для создания событийно-ориентированных сервисов на JavaScript/TypeScript",
|
|
5
5
|
"main": "./lib/index",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "node ./lib/test.js"
|
|
8
|
-
},
|
|
6
|
+
"scripts": {},
|
|
9
7
|
"repository": {
|
|
10
8
|
"type": "git",
|
|
11
|
-
"url": "git+https://
|
|
9
|
+
"url": "git+https://github.com/VRack2/vrack2-core.git"
|
|
12
10
|
},
|
|
13
11
|
"author": "Boris Bobylev",
|
|
14
|
-
"license": "
|
|
12
|
+
"license": "Apache-2.0",
|
|
15
13
|
"bugs": {
|
|
16
|
-
"url": "https://
|
|
14
|
+
"url": "https://github.com/VRack2/vrack2-core/issues"
|
|
17
15
|
},
|
|
18
|
-
"homepage": "https://
|
|
16
|
+
"homepage": "https://github.com/VRack2/vrack2-core#readme",
|
|
19
17
|
"devDependencies": {
|
|
20
18
|
"@types/node": "^18.11.17",
|
|
21
19
|
"@typescript-eslint/eslint-plugin": "^5.45.0",
|
|
22
20
|
"@typescript-eslint/parser": "^5.45.0",
|
|
23
21
|
"eslint": "^8.29.0",
|
|
24
22
|
"typescript": "^4.9.3"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"vrack-db": "^3.0.1"
|
|
25
26
|
}
|
|
26
27
|
}
|
package/src/Bootstrap.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2024 Boris Bobylev. All rights reserved.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ErrorManager, Rule } from '.';
|
|
7
|
+
import BootClass from './boot/BootClass';
|
|
8
|
+
import Container from './Container';
|
|
9
|
+
import ImportManager from './ImportManager';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Defines a list of bootstrap classes to load
|
|
14
|
+
*
|
|
15
|
+
* {
|
|
16
|
+
* 'ClassID': {
|
|
17
|
+
* path: 'importclass.path',
|
|
18
|
+
* options: {}
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export interface IBootListConfig {
|
|
23
|
+
[key: string]: {
|
|
24
|
+
/** VRack-style bootclass path */
|
|
25
|
+
path: string,
|
|
26
|
+
/** Options for this bootclass */
|
|
27
|
+
options: { [key: string]: any },
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
ErrorManager.register('Bootstrap', 'yNHeX5fwDH5P', 'BTSP_CLASS_ID_NOT_FOUND',
|
|
32
|
+
'Bootstrap class id not found', {
|
|
33
|
+
id: Rule.string().description('Class identify')
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
ErrorManager.register('Bootstrap', 'ack6kwHSBtcf', 'BTSP_INSTANCE_OF_INCORRECT',
|
|
37
|
+
'Bootstrap class id is not a class defined by check', {
|
|
38
|
+
id: Rule.string().description('Class identify')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
ErrorManager.register('Bootstrap', 'DMloqbZG9J36', 'BTSP_MUST_BE_BOOTCLASS',
|
|
42
|
+
'The class must be inherited from BootClass', {
|
|
43
|
+
path: Rule.string().description('Class path')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Bootstrap is a class for running bootclasses,
|
|
48
|
+
* which should work above Container and is required
|
|
49
|
+
* for Container to work.
|
|
50
|
+
*
|
|
51
|
+
* For example DeviceManager class - it is
|
|
52
|
+
* necessary for Container to work but it must be
|
|
53
|
+
* replaceable and customizable.
|
|
54
|
+
*
|
|
55
|
+
* Bootstrap handles the loading of DeviceManager and
|
|
56
|
+
* provides the ability to work with it from Container.
|
|
57
|
+
* Bootclasses are a forced exception.
|
|
58
|
+
*
|
|
59
|
+
* This is the minimum code that is needed to do everything
|
|
60
|
+
* else in the style of VRack service.
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
export default class Bootstrap {
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Loaded class list
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* { UniqueID: Classinstance }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
protected loaded: { [key: string]: BootClass } = {}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* List of downloadable classes and their settings
|
|
76
|
+
*
|
|
77
|
+
* @see IBootListConfig
|
|
78
|
+
*/
|
|
79
|
+
protected config: IBootListConfig
|
|
80
|
+
|
|
81
|
+
constructor(config: IBootListConfig){
|
|
82
|
+
this.config = config
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Load bootclasses
|
|
87
|
+
*
|
|
88
|
+
* Bootclass has some analogy to devices within VRack services.
|
|
89
|
+
* They also have options, process, processPromise methods similar to devices
|
|
90
|
+
*
|
|
91
|
+
* @param Container Container for which loading is performed
|
|
92
|
+
*/
|
|
93
|
+
async loadBootList(Container: Container) {
|
|
94
|
+
for (const cn in this.config) {
|
|
95
|
+
const conf = this.config[cn]
|
|
96
|
+
const ExClass = await ImportManager.importClass(conf.path)
|
|
97
|
+
this.loaded[cn] = new ExClass(cn, ImportManager.importClassName(conf.path), Container, conf.options)
|
|
98
|
+
if (!(this.loaded[cn] instanceof BootClass)) {
|
|
99
|
+
throw ErrorManager.make('BTSP_INSTANCE_OF_INCORRECT', { path: conf.path })
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
for (const bc in this.loaded) this.loaded[bc].process()
|
|
103
|
+
for (const bc in this.loaded) await this.loaded[bc].processPromise()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Getting an initialized class
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* this.Container.Bootstrap.getBootClass('DeviceMetrics', DeviceMetrics) as DeviceMetrics
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @param id class identifier that was specified in the list
|
|
115
|
+
* @param cs Class to be compared with when receiving
|
|
116
|
+
*/
|
|
117
|
+
getBootClass (id: string, cs: any ) {
|
|
118
|
+
if (!this.loaded[id]) throw ErrorManager.make('BTSP_CLASS_ID_NOT_FOUND', { id })
|
|
119
|
+
if (!(this.loaded[id] instanceof cs)) throw ErrorManager.make('BTSP_INSTANCE_OF_INCORRECT', { id })
|
|
120
|
+
return this.loaded[id] as typeof cs
|
|
121
|
+
}
|
|
122
|
+
}
|