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.
Files changed (148) hide show
  1. package/README.md +25 -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 +306 -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 +10 -9
  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 +339 -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
@@ -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
- return __awaiter(this, void 0, void 0, function* () {
101
- if (!path_1.default.isAbsolute(filePath)) {
102
- filePath = path_1.default.join(ImportManager.systemPath(), filePath);
103
- }
104
- if ((0, fs_1.existsSync)(filePath)) {
105
- const jdata = (0, fs_1.readFileSync)(filePath).toString('utf-8');
106
- return ImportManager.tryJsonParse(jdata);
107
- }
108
- throw ErrorManager_1.default.make('IM_FILE_NOT_FOUND', { filePath });
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
- static getSub(imp, get) {
129
- return imp[get];
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 {
@@ -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
- DeviceManager: DeviceManager;
7
- constructor(ContainerClass: typeof Container, DeviceManagerClass: typeof DeviceManager, service: IServiceStructure);
30
+ options: IMainProcessInternalOptions;
31
+ Bootstrap: Bootstrap;
32
+ constructor(config: IMainProcessOptions);
8
33
  run(): Promise<void>;
34
+ check(): Promise<void>;
9
35
  }
36
+ export {};
@@ -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 ImportManager_1 = __importDefault(require("./ImportManager"));
15
+ const Bootstrap_1 = __importDefault(require("./Bootstrap"));
16
+ const Container_1 = __importDefault(require("./Container"));
16
17
  class MainProcess {
17
- constructor(ContainerClass, DeviceManagerClass, service) {
18
- this.DeviceManager = new DeviceManagerClass(ImportManager_1.default.systemPath(), './devices');
19
- this.DeviceManager.updateList();
20
- this.Container = new ContainerClass(service, this.DeviceManager);
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.Container.run();
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
- * Преобразует строку типа `aaa.bbb.ccc` в строку типа `aaaBbbCcc`
3
- * Обратите внимание на то, что первый символ первого актета не преобразуется,
4
- * если есть такая необходимость, можно добавить точку в самое начало строки `.aaa.bbb.ccc`
5
- * результат выполнения будет `AaaBbbCcc`
6
- */
7
- declare function camelize(text: string): string;
8
- /**
9
- * Проверяет, является ли JSON строка валидным JSON
10
- * Обычно используется, когда неважно в чем конретно проблема в JSON
11
- * и нужно просто узнать валидный он или нет
12
- *
13
- */
14
- declare function validJSON(text: string): any;
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 © 2022 Boris Bobylev. All rights reserved.
3
+ * Copyright © 2025 Boris Bobylev. All rights reserved.
4
4
  * Licensed under the Apache License, Version 2.0
5
5
  */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.toPath = exports.validJSON = exports.camelize = void 0;
8
- /**
9
- * Преобразует строку типа `aaa.bbb.ccc` в строку типа `aaaBbbCcc`
10
- * Обратите внимание на то, что первый символ первого актета не преобразуется,
11
- * если есть такая необходимость, можно добавить точку в самое начало строки `.aaa.bbb.ccc`
12
- * результат выполнения будет `AaaBbbCcc`
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
- exports.camelize = camelize;
22
- /**
23
- * Проверяет, является ли JSON строка валидным JSON
24
- * Обычно используется, когда неважно в чем конретно проблема в JSON
25
- * и нужно просто узнать валидный он или нет
26
- *
27
- */
28
- function validJSON(text) {
29
- try {
30
- const cfg = JSON.parse(text);
31
- if (!(cfg && typeof cfg === 'object'))
32
- return false;
33
- return cfg;
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
- catch (e) {
36
- return false;
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.validJSON = validJSON;
40
- /**
41
- * Преобразует строку в локальный путь VRack, на данный момент
42
- * это просто приведение строки в lowerCase
43
- *
44
- */
45
- function toPath(text) {
46
- return text.toLowerCase();
47
- }
48
- exports.toPath = toPath;
48
+ exports.default = Utility;
@@ -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
  }
@@ -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,
@@ -1,4 +1,9 @@
1
1
  import BasicAction from "./BasicAction";
2
+ /**
3
+ * Standart action class
4
+ *
5
+ * @see BasicAction
6
+ */
2
7
  export default class GlobalAction extends BasicAction {
3
8
  constructor();
4
9
  }
@@ -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();
@@ -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
  }