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.
Files changed (148) hide show
  1. package/README.md +33 -4
  2. package/docs/Bootstrap.md +77 -0
  3. package/docs/Container.md +124 -0
  4. package/docs/Device.md +272 -0
  5. package/docs/FastStart.md +111 -0
  6. package/docs/Structure.md +148 -0
  7. package/lib/Bootstrap.d.ts +79 -0
  8. package/lib/Bootstrap.js +103 -0
  9. package/lib/Container.d.ts +202 -6
  10. package/lib/Container.js +295 -27
  11. package/lib/IServiceStructure.d.ts +8 -0
  12. package/lib/IStructureDevice.d.ts +5 -0
  13. package/lib/ImportManager.d.ts +85 -3
  14. package/lib/ImportManager.js +122 -16
  15. package/lib/MainProcess.d.ts +30 -3
  16. package/lib/MainProcess.js +28 -6
  17. package/lib/Utility.d.ts +15 -21
  18. package/lib/Utility.js +40 -40
  19. package/lib/actions/Action.d.ts +10 -0
  20. package/lib/actions/Action.js +10 -0
  21. package/lib/actions/BasicAction.d.ts +60 -0
  22. package/lib/actions/BasicAction.js +62 -0
  23. package/lib/actions/GlobalAction.d.ts +5 -0
  24. package/lib/actions/GlobalAction.js +5 -0
  25. package/lib/actions/IAction.d.ts +7 -0
  26. package/lib/actions/ILocalAction.d.ts +7 -0
  27. package/lib/boot/BootClass.d.ts +93 -0
  28. package/lib/boot/BootClass.js +101 -0
  29. package/lib/boot/DeviceFileStorage.d.ts +38 -0
  30. package/lib/boot/DeviceFileStorage.js +112 -0
  31. package/lib/boot/DeviceManager.d.ts +190 -0
  32. package/lib/boot/DeviceManager.js +311 -0
  33. package/lib/boot/DeviceMetrics.d.ts +82 -0
  34. package/lib/boot/DeviceMetrics.js +128 -0
  35. package/lib/boot/StructureStorage.d.ts +59 -0
  36. package/lib/boot/StructureStorage.js +125 -0
  37. package/lib/errors/CoreError.d.ts +42 -25
  38. package/lib/errors/CoreError.js +44 -24
  39. package/lib/errors/ErrorManager.d.ts +18 -20
  40. package/lib/errors/ErrorManager.js +23 -22
  41. package/lib/index.d.ts +20 -4
  42. package/lib/index.js +28 -4
  43. package/lib/metrics/BasicMetric.d.ts +49 -0
  44. package/lib/metrics/BasicMetric.js +79 -0
  45. package/lib/metrics/IMetricSettings.d.ts +32 -0
  46. package/lib/metrics/IMetricSettings.js +2 -0
  47. package/lib/metrics/IvMs.d.ts +9 -0
  48. package/lib/metrics/IvMs.js +22 -0
  49. package/lib/metrics/IvS.d.ts +9 -0
  50. package/lib/metrics/IvS.js +22 -0
  51. package/lib/metrics/IvUs.d.ts +9 -0
  52. package/lib/metrics/IvUs.js +22 -0
  53. package/lib/metrics/Metric.d.ts +17 -0
  54. package/lib/metrics/Metric.js +27 -0
  55. package/lib/ports/BasicPort.d.ts +39 -0
  56. package/lib/ports/BasicPort.js +39 -0
  57. package/lib/ports/ILocalPort.d.ts +7 -0
  58. package/lib/ports/IPort.d.ts +7 -0
  59. package/lib/ports/Port.d.ts +10 -0
  60. package/lib/ports/Port.js +10 -0
  61. package/lib/ports/ReturnPort.d.ts +5 -0
  62. package/lib/ports/ReturnPort.js +5 -0
  63. package/lib/service/Device.d.ts +213 -78
  64. package/lib/service/Device.js +185 -83
  65. package/lib/service/DeviceConnect.d.ts +4 -8
  66. package/lib/service/DeviceConnect.js +4 -8
  67. package/lib/service/DevicePort.d.ts +15 -6
  68. package/lib/service/DevicePort.js +29 -12
  69. package/lib/service/IDeviceEvent.d.ts +4 -1
  70. package/lib/validator/IValidationProblem.d.ts +7 -0
  71. package/lib/validator/IValidationRule.d.ts +12 -0
  72. package/lib/validator/IValidationSubrule.d.ts +2 -0
  73. package/lib/validator/Rule.d.ts +6 -2
  74. package/lib/validator/Rule.js +12 -2
  75. package/lib/validator/Validator.d.ts +48 -3
  76. package/lib/validator/Validator.js +70 -18
  77. package/lib/validator/types/AnyType.d.ts +17 -0
  78. package/lib/validator/types/AnyType.js +34 -0
  79. package/lib/validator/types/ArrayType.d.ts +37 -4
  80. package/lib/validator/types/ArrayType.js +42 -6
  81. package/lib/validator/types/BasicType.d.ts +67 -7
  82. package/lib/validator/types/BasicType.js +74 -8
  83. package/lib/validator/types/BooleanType.d.ts +23 -0
  84. package/lib/validator/types/BooleanType.js +47 -0
  85. package/lib/validator/types/FunctionType.d.ts +17 -0
  86. package/lib/validator/types/FunctionType.js +38 -0
  87. package/lib/validator/types/NumberType.d.ts +40 -5
  88. package/lib/validator/types/NumberType.js +53 -14
  89. package/lib/validator/types/ObjectType.d.ts +32 -5
  90. package/lib/validator/types/ObjectType.js +42 -8
  91. package/lib/validator/types/StringType.d.ts +30 -5
  92. package/lib/validator/types/StringType.js +33 -7
  93. package/package.json +15 -14
  94. package/src/Bootstrap.ts +122 -0
  95. package/src/Container.ts +411 -43
  96. package/src/IServiceStructure.ts +9 -0
  97. package/src/IStructureDevice.ts +5 -0
  98. package/src/ImportManager.ts +119 -11
  99. package/src/MainProcess.ts +53 -8
  100. package/src/Utility.ts +35 -36
  101. package/src/actions/Action.ts +12 -0
  102. package/src/actions/BasicAction.ts +63 -0
  103. package/src/actions/GlobalAction.ts +5 -0
  104. package/src/actions/IAction.ts +7 -0
  105. package/src/actions/ILocalAction.ts +7 -0
  106. package/src/boot/BootClass.ts +117 -0
  107. package/src/boot/DeviceFileStorage.ts +96 -0
  108. package/src/boot/DeviceManager.ts +346 -0
  109. package/src/boot/DeviceMetrics.ts +129 -0
  110. package/src/boot/StructureStorage.ts +108 -0
  111. package/src/errors/CoreError.ts +52 -26
  112. package/src/errors/ErrorManager.ts +46 -33
  113. package/src/index.ts +30 -6
  114. package/src/metrics/BasicMetric.ts +84 -0
  115. package/src/metrics/IMetricSettings.ts +38 -0
  116. package/src/metrics/IvMs.ts +18 -0
  117. package/src/metrics/IvS.ts +18 -0
  118. package/src/metrics/IvUs.ts +17 -0
  119. package/src/metrics/Metric.ts +25 -0
  120. package/src/ports/BasicPort.ts +39 -0
  121. package/src/ports/ILocalPort.ts +7 -0
  122. package/src/ports/IPort.ts +7 -0
  123. package/src/ports/Port.ts +11 -1
  124. package/src/ports/ReturnPort.ts +5 -0
  125. package/src/service/Device.ts +234 -103
  126. package/src/service/DeviceConnect.ts +4 -8
  127. package/src/service/DevicePort.ts +30 -11
  128. package/src/service/IDeviceEvent.ts +4 -1
  129. package/src/validator/IValidationProblem.ts +7 -0
  130. package/src/validator/IValidationRule.ts +12 -0
  131. package/src/validator/IValidationSubrule.ts +3 -0
  132. package/src/validator/Rule.ts +16 -2
  133. package/src/validator/Validator.ts +74 -23
  134. package/src/validator/types/AnyType.ts +32 -0
  135. package/src/validator/types/ArrayType.ts +43 -7
  136. package/src/validator/types/BasicType.ts +78 -9
  137. package/src/validator/types/BooleanType.ts +49 -0
  138. package/src/validator/types/FunctionType.ts +39 -0
  139. package/src/validator/types/NumberType.ts +53 -15
  140. package/src/validator/types/ObjectType.ts +52 -14
  141. package/src/validator/types/StringType.ts +34 -10
  142. package/docs/RU-README.md +0 -6
  143. package/lib/DeviceManager.d.ts +0 -32
  144. package/lib/DeviceManager.js +0 -143
  145. package/lib/test.d.ts +0 -1
  146. package/lib/test.js +0 -58
  147. package/src/DeviceManager.ts +0 -124
  148. 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
- static validate(obj: {[key:string]: any}, key: string, rule: IValidationRule){
39
- BasicType.validate(obj, key, rule)
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
- StringType.checkMaxLength(obj, key, subrule)
62
+ this.checkMaxLength(obj, key, subrule)
45
63
  break
46
64
  case 'minLength':
47
- StringType.checkMinLength(obj, key, subrule)
65
+ this.checkMinLength(obj, key, subrule)
48
66
  break
49
67
  }
50
68
  }
51
69
  return true
52
70
  }
53
71
 
54
- protected static checkMaxLength(obj: {[key:string]: any}, key: string, sub: IValidationSubrule){
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
- protected static checkMinLength(obj: {[key:string]: any}, key: string, sub: IValidationSubrule){
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
@@ -1,6 +0,0 @@
1
- VRack2 core
2
- -----------
3
-
4
- Основной набор компонентов для работы vrack2. На данный момент находится в начальном состоянии и дорабатывает по мере необходимости.
5
-
6
- На данный момент непригодно для публичного использования.
@@ -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 {};
@@ -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);
@@ -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
-