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
@@ -1,34 +1,37 @@
1
1
  /*
2
- * Copyright © 2022 Boris Bobylev. All rights reserved.
2
+ * Copyright © 2024 Boris Bobylev. All rights reserved.
3
3
  * Licensed under the Apache License, Version 2.0
4
4
  */
5
5
 
6
6
  /**
7
- * Базовый класс для реализаиции ошибок с возможностью
8
- * импортирования и экспортирования классов ошибок для
9
- * клиент-серверных операций.
7
+ * Base class for error realization with the ability to
8
+ * import and export error classes for client-server operations.
10
9
  *
11
- * В VRack очень много передается по сети в виде JSON. Поскольку
12
- * в чистом виде ошибки не преобрзауются в JSON, были сделаны методы
13
- * для экспортирования и импортирования с сохранения основных важных свойств.
10
+ * In VRack, a lot of things are transmitted over the network as JSON.
11
+ * Since pure errors are not converted to JSON, methods were made to export and
12
+ * import them while preserving the main important properties.
14
13
  *
15
- * Если импортируемая ошибка имеет свойства которых нет в базовом классе, буду добавлены.
16
- * Для получения неизвестных свойств можно воспользоватся функцией (для typescript) getUnknownProperty
17
- *
18
- * Для работы с ошибками VRack рекомендуется использовать ErrorManager
14
+ * If the imported error has properties that are not in the base class,
15
+ * they will be added. To get unknown properties you can use the function
16
+ * (for typescript) getUnknownProperty.
19
17
  *
20
18
  */
21
19
  class CoreError extends Error{
22
- /** Флаг того что ошибка пренадлежит VRack */
20
+
21
+ /** Flag that the error belongs to VRack */
23
22
  vError = true
24
- /** Код ошибки VRack */
23
+
24
+ /** Error code */
25
25
  vCode = ""
26
- /** Кородкий код VRack */
26
+
27
+ /** Short code */
27
28
  vShort = ""
28
- /** Список дополнительных параметров */
29
+
30
+ /** List of additional parameters */
29
31
  vAdd: Array<string> = []
30
- /** */
31
- vAddErrors: Array<CoreError> = []
32
+
33
+ /** Nested errors */
34
+ vAddErrors: Array<Error> = []
32
35
 
33
36
  constructor(name: string, message: string, code: string, short: string) {
34
37
  super(message)
@@ -38,8 +41,24 @@ class CoreError extends Error{
38
41
  }
39
42
 
40
43
  /**
41
- * Импортирует ошибку пришедшую по сети в виде JSON объекта
42
- * На всякий случай использует objectify для приходящего объекта
44
+ * Sets the stacktrace of the error above
45
+ * It is necessary for the stacktrace to refer to the
46
+ * required file and not to ErrorManager
47
+ *
48
+ * @param err Error
49
+ * @example Example of assigning a more correct path to the file where the error occurred
50
+ * ```
51
+ * ErrorManager.make('EM_CODE_NOT_FOUND').setTrace(new Error())
52
+ * ```
53
+ */
54
+ setTrace (err: Error){
55
+ this.stack = err.stack
56
+ return this
57
+ }
58
+
59
+ /**
60
+ * Imports an error that came over the network as a JSON object
61
+ * Uses objectify for the incoming object just in case
43
62
  *
44
63
  * @returns {CoreError} this после модификации
45
64
  */
@@ -50,22 +69,29 @@ class CoreError extends Error{
50
69
  }
51
70
 
52
71
  /**
53
- * Возвращает объект для передачи его по сети с предварительным
54
- * преобразованием в JSON
72
+ * Returns an object to be transmitted over the network
73
+ * with preliminary conversion to JSON
74
+ *
75
+ * @see objectify
55
76
  */
56
77
  export() : any {
57
78
  return CoreError.objectify(this)
58
79
  }
59
80
 
60
81
 
61
- add(err: CoreError) {
82
+ /**
83
+ * Add nested error
84
+ *
85
+ * @param err Nested error
86
+ */
87
+ add(err: Error) {
62
88
  this.vAddErrors.push(CoreError.objectify(err))
63
89
  return this
64
90
  }
65
91
 
66
92
  /**
67
- * Для Typescript используется для получения неизвестного
68
- * свойства экземпляра после импорта пришедшей ошибки
93
+ * For Typescript it is used to retrieve an unknown
94
+ * instance property after importing an incoming error
69
95
  */
70
96
  getUnknownProperty(field:string): any | undefined {
71
97
  const dynamicKey = field as keyof CoreError;
@@ -73,9 +99,9 @@ class CoreError extends Error{
73
99
  }
74
100
 
75
101
  /**
76
- * Возвращает объект для передачи его по сети
102
+ * Returns an object to be transmitted over the network
77
103
  *
78
- * @param {any} error Ошибка для преобразования в объект
104
+ * @param {any} error Error for conversion to an object
79
105
  * */
80
106
  static objectify(error: any) : any {
81
107
  const result: any = {}
@@ -6,65 +6,80 @@
6
6
  import BasicType from "../validator/types/BasicType"
7
7
  import CoreError from "./CoreError"
8
8
 
9
+
9
10
  interface RegisteredError {
11
+ /** Property for error grouping */
10
12
  name: string,
13
+ /** Unique random string code ID like a random string */
11
14
  code: string,
15
+ /** Readable unique identifier like a VS_ERROR_DATABASE_NF */
12
16
  short: string,
17
+ /** Error string (description) */
13
18
  description: string,
14
- rules: {[key:string]: BasicType}
19
+ /**
20
+ * You can specify additional data when creating an error.
21
+ * If these data are standardized - you can specify rules for them.
22
+ * These rules do not validate the additional data.
23
+ * But they can make it easier to understand these properties.
24
+ * */
25
+ rules: { [key: string]: BasicType }
15
26
  }
16
27
 
17
28
 
18
29
  /**
19
- * Класс является точкой входа для инициализации исключений
20
- *
21
- * Было принято решение вместо кучи мелких однотипных файлов сделать один класс
22
- * со стандартным функционалом
30
+ * A simple class for creating errors.
31
+ * This centralized class is useful because you can find out t
32
+ * he list of all registered errors and which group/component they belong to.
23
33
  */
24
34
  class ErrorManager {
25
35
 
36
+ /**
37
+ * List of registered errors
38
+ */
26
39
  private registeredList: Array<RegisteredError> = []
27
40
 
28
41
  /**
29
- * Регистрирует тип ошибки компонента
30
- *
31
- * Перед тем как менеджер ошибок может создать ошибки, необходимо зарегистрировать ее тип.
32
- *
33
- * @param {string} name Название компонента
34
- * @param {string} code Код ошибки
35
- * @param {string} short Короткий код ошибки
36
- * @param {string} description Описание ошибки
42
+ * Error registration. An error must be registered before creating it
37
43
  *
44
+ * @param name Property for error grouping
45
+ * @param code Unique random string code ID
46
+ * @param short Readable unique identifier
47
+ * @param description Error string (description)
38
48
  */
39
- register(name: string, code: string, short: string, description: string, rules: {[key:string]: BasicType} = {}) {
49
+ register(name: string, code: string, short: string, description: string, rules: { [key: string]: BasicType } = {}) {
40
50
  const reg1 = this.getRegistered(code)
41
51
  const reg2 = this.getRegistered(short)
42
- if (reg1 !== null || reg2 !== null) throw this.make('EM_CODE_EXISTS', {code, short})
43
- const nr = { name, code, short, description, rules}
52
+ if (reg1 !== null || reg2 !== null) throw this.make('EM_CODE_EXISTS', { code, short })
53
+ const nr = { name, code, short, description, rules }
44
54
  this.registeredList.push(nr)
45
55
  }
46
56
 
47
57
  /**
48
- * Создание ошибки
58
+ * Creating an instance of an error
49
59
  *
50
- *
51
- *
52
- * @param {string} short
60
+ * @param short
61
+ * @param additional
53
62
  */
54
63
  make(short: string, additional = {}) {
55
64
  const reg = this.getRegistered(short)
56
65
  if (reg === null) throw this.make('EM_CODE_NOT_FOUND')
57
- const ne = new CoreError(reg.name, reg.description,reg.code, reg.short)
66
+ const ne = new CoreError(reg.name, reg.description, reg.code, reg.short)
67
+
68
+ // Убираем из стека вызовы ErrorManager.make()
69
+ if (typeof Error.captureStackTrace === 'function') {
70
+ Error.captureStackTrace(ne, this.make);
71
+ }
72
+
58
73
  ne.vAdd = Object.keys(additional)
59
74
  return Object.assign(ne, additional)
60
75
  }
61
76
 
62
77
  /**
63
- * Преобразует обычную ошибку в ошибку VRack
78
+ * Converts a normal error to a VRack error
64
79
  *
65
- * @param {Error} error Ошибка для преобразования
80
+ * @param error Ошибка для преобразования
66
81
  */
67
- convert(error: any){
82
+ convert(error: any) {
68
83
  if (error.vError) return error
69
84
  const ne = this.make('EM_ERROR_CONVERT')
70
85
  ne.import(error)
@@ -72,14 +87,12 @@ class ErrorManager {
72
87
  }
73
88
 
74
89
  /**
75
- * Возвращает тип ошибки или null
90
+ * Searches for an error by code or short
76
91
  *
77
- * @param {string} short Короткий код ошибки или код ошибки поиска
92
+ * @param short Short error code or search error code
78
93
  */
79
- private getRegistered(short: string) : RegisteredError | null {
80
- for (const registered of this.registeredList){
81
- if (registered.code === short || registered.short === short) return registered
82
- }
94
+ private getRegistered(short: string): RegisteredError | null {
95
+ for (const registered of this.registeredList) if (registered.code === short || registered.short === short) return registered
83
96
  return null
84
97
  }
85
98
  }
@@ -87,7 +100,7 @@ class ErrorManager {
87
100
 
88
101
 
89
102
  const GlobalErrorManager = new ErrorManager()
90
- GlobalErrorManager.register('ErrorManager','NcZIb9QvQRcq', 'EM_CODE_EXISTS', 'This code already exists')
91
- GlobalErrorManager.register('ErrorManager','uLYv4mE1Yo50', 'EM_CODE_NOT_FOUND', 'No such error found')
92
- GlobalErrorManager.register('ErrorManager','RIl3BUrxWOzP', 'EM_ERROR_CONVERT', 'Converted error')
103
+ GlobalErrorManager.register('ErrorManager', 'NcZIb9QvQRcq', 'EM_CODE_EXISTS', 'This code already exists')
104
+ GlobalErrorManager.register('ErrorManager', 'uLYv4mE1Yo50', 'EM_CODE_NOT_FOUND', 'No such error found')
105
+ GlobalErrorManager.register('ErrorManager', 'RIl3BUrxWOzP', 'EM_ERROR_CONVERT', 'Converted error')
93
106
  export default GlobalErrorManager
package/src/index.ts CHANGED
@@ -1,29 +1,53 @@
1
1
  /*
2
- * Copyright © 2022 Boris Bobylev. All rights reserved.
2
+ * Copyright © 2024 Boris Bobylev. All rights reserved.
3
3
  * Licensed under the Apache License, Version 2.0
4
4
  */
5
5
 
6
-
7
6
  /* ---------------- VALIDATOR EXPORT ------------------- */
8
7
  export { default as ErrorManager } from './errors/ErrorManager'
9
8
  export { default as CoreError } from './errors/CoreError'
10
9
  export { default as Rule } from './validator/Rule'
11
10
  export { default as Validator } from './validator/Validator'
12
- export { default as IValidationProblem} from './validator/IValidationProblem'
13
- export { default as IValidationRule} from './validator/IValidationRule'
14
- export { default as IValidationSubrule} from './validator/IValidationSubrule'
15
11
 
16
12
  /* ---------------- BASE OF VRACK ------------------- */
17
13
  export { default as ImportManager } from './ImportManager';
18
- export { default as DeviceManager } from './DeviceManager';
19
14
  export { default as Container } from './Container';
20
15
  export { default as MainProcess } from './MainProcess';
21
16
 
17
+ /* ---------------- BOOTSTRAP ------------------- */
18
+
19
+ export { default as Bootstrap } from './Bootstrap'
20
+ export { default as BootClass } from './boot/BootClass'
21
+ export { default as DeviceFileStorage } from './boot/DeviceFileStorage'
22
+ export { default as DeviceManager } from './boot/DeviceManager';
23
+ export { default as StructureStorage } from './boot/StructureStorage';
24
+ export { default as DeviceMetrics } from './boot/DeviceMetrics';
25
+
26
+ /* ---------------- INTERNAL SERVICE ------------------- */
27
+
22
28
  export { default as Action } from './actions/Action'
23
29
  export { default as Device } from './service/Device'
24
30
  export { default as DeviceConnect } from './service/DeviceConnect'
25
31
  export { default as DevicePort } from './service/DevicePort'
26
32
  export { default as Port } from './ports/Port'
33
+ export { default as Metric } from './metrics/Metric'
34
+
35
+ export { default as BasicPort } from './ports/BasicPort'
36
+ export { default as BasicType } from './validator/types/BasicType'
37
+ export { default as BasicMetric } from './metrics/BasicMetric'
38
+ export { default as BasicAction } from './actions/BasicAction'
39
+
40
+ /* ---------------- INTERFACES ------------------- */
41
+ export { default as IMetricSettings } from './metrics/IMetricSettings'
42
+ export { default as IPort } from './ports/IPort'
43
+ export { default as IDeviceEvent } from './service/IDeviceEvent'
44
+ export { default as IValidationProblem} from './validator/IValidationProblem'
45
+ export { default as IValidationRule} from './validator/IValidationRule'
46
+ export { default as IValidationSubrule} from './validator/IValidationSubrule'
47
+ export { default as IServiceStructure} from './IServiceStructure'
48
+ export { default as IStructureDevice} from './IStructureDevice'
49
+
50
+ export { StorageTypes } from 'vrack-db';
27
51
 
28
52
  export * from './service/Device'
29
53
  export * from './service/DeviceConnect'
@@ -0,0 +1,84 @@
1
+ /*
2
+ * Copyright © 2025 Boris Bobylev. All rights reserved.
3
+ * Licensed under the Apache License, Version 2.0
4
+ */
5
+
6
+
7
+ import { StorageTypes, SingleDB } from "vrack-db"
8
+ import IMetricSettings from "./IMetricSettings"
9
+
10
+ /**
11
+ * Metric base class. Used internally to define device metrics.
12
+ */
13
+ export default class BasicMetric {
14
+ /**
15
+ * Default metric setting
16
+ */
17
+ protected metric: IMetricSettings = {
18
+ retentions: '5s:10m, 1m:2h, 15m:1d, 1h:1w, 6h:1mon, 1d:1y',
19
+ interval: 's',
20
+ vType: StorageTypes.Float,
21
+ tType: StorageTypes.Uint64
22
+ }
23
+
24
+ /**
25
+ * Defines the type of time storage
26
+ *
27
+ * @param type StorageTypes type like a StorageTypes.Uint64 (default)
28
+ */
29
+ timeStorage(type: StorageTypes){
30
+ this.metric.tType = type
31
+ return this
32
+ }
33
+
34
+ /**
35
+ * Defines the type of value storage
36
+ *
37
+ * @param type StorageTypes type like a StorageTypes.Uint64 (default)
38
+ */
39
+ valueStorage(type: StorageTypes){
40
+ this.metric.vType = type
41
+ return this
42
+ }
43
+
44
+ /**
45
+ * Specifies the accuracy and storage period size of Graphite-style metrics
46
+ *
47
+ *
48
+ * @see SingleDB.metric
49
+ * @param req retentions Graphite-style `5s:10m, 1m:2h, 15m:1d, 1h:1w, 6h:1mon, 1d:1y`
50
+ */
51
+ retentions(req: string){
52
+ this.metric.retentions = req
53
+ return this
54
+ }
55
+
56
+ /**
57
+ * Metric Description
58
+ *
59
+ * @param des Short text description of the metric
60
+ */
61
+ description(des: string){
62
+ this.metric.description = des
63
+ return this
64
+ }
65
+
66
+ /**
67
+ * To add additional data to the metric, you can specify
68
+ * any object describing the metric in this method.
69
+ *
70
+ * @param add Additional information for the metric
71
+ */
72
+ additional(add: any){
73
+ this.metric.additional = add
74
+ return this
75
+ }
76
+
77
+ /**
78
+ * Returns the internal metric settings object. Used inside Container
79
+ * @private
80
+ */
81
+ export(){
82
+ return this.metric
83
+ }
84
+ }
@@ -0,0 +1,38 @@
1
+ import { StorageTypes } from "vrack-db";
2
+
3
+
4
+ export default interface IMetricSettings {
5
+ /**
6
+ * Specifies the accuracy and storage period size of Graphite-style metrics
7
+ * @see SingleDB.metric
8
+ */
9
+ retentions: string;
10
+ /**
11
+ * Interval that defines the minimal time unit
12
+ *
13
+ * s - second
14
+ * ms - millisecond
15
+ * us - microsecond
16
+ */
17
+ interval: 's' | 'ms' | 'us';
18
+
19
+ /**
20
+ * Defines the type of value storage
21
+ * StorageTypes type like a StorageTypes.Uint64 (default)
22
+ */
23
+ vType: StorageTypes;
24
+
25
+ /**
26
+ * Defines the type of time storage
27
+ * StorageTypes type like a StorageTypes.Uint64 (default)
28
+ */
29
+ tType: StorageTypes;
30
+
31
+ /** Metric Description */
32
+ description?: string;
33
+
34
+ /**
35
+ * Additional information for the metric
36
+ */
37
+ additional?: any;
38
+ }
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright © 2025 Boris Bobylev. All rights reserved.
3
+ * Licensed under the Apache License, Version 2.0
4
+ */
5
+
6
+ import BasicMetric from "./BasicMetric";
7
+
8
+ /**
9
+ * Creating a new metric with minimum time unit in milliseconds
10
+ *
11
+ * @see BasicMetric
12
+ */
13
+ export default class IvMS extends BasicMetric {
14
+ constructor (){
15
+ super()
16
+ this.metric.interval = 'ms'
17
+ }
18
+ }
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright © 2025 Boris Bobylev. All rights reserved.
3
+ * Licensed under the Apache License, Version 2.0
4
+ */
5
+
6
+ import BasicInterval from "./BasicMetric";
7
+
8
+ /**
9
+ * Creating a new metric with minimum time unit in Seconds
10
+ *
11
+ * @see BasicMetric
12
+ */
13
+ export default class IvS extends BasicInterval {
14
+ constructor (){
15
+ super()
16
+ this.metric.interval = 's'
17
+ }
18
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright © 2025 Boris Bobylev. All rights reserved.
3
+ * Licensed under the Apache License, Version 2.0
4
+ */
5
+
6
+ import BasicInterval from "./BasicMetric";
7
+ /**
8
+ * Creating a new metric with minimum time unit in Microseconds
9
+ *
10
+ * @see BasicMetric
11
+ */
12
+ export default class IvUs extends BasicInterval {
13
+ constructor (){
14
+ super()
15
+ this.metric.interval = 'us'
16
+ }
17
+ }
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright © 2025 Boris Bobylev. All rights reserved.
3
+ * Licensed under the Apache License, Version 2.0
4
+ */
5
+
6
+ import IvMS from "./IvMs";
7
+ import IvS from "./IvS";
8
+ import IvUs from "./IvUs";
9
+
10
+ export default class Metric {
11
+ /**
12
+ * Creating a new metric with minimum time unit in Seconds
13
+ */
14
+ static inS(){ return new IvS() }
15
+
16
+ /**
17
+ * Creating a new metric with minimum time unit in Milliseconds
18
+ */
19
+ static inMs(){ return new IvMS() }
20
+
21
+ /**
22
+ * Creating a new metric with minimum time unit in Microsecond
23
+ */
24
+ static inUs(){ return new IvUs() }
25
+ }
@@ -7,6 +7,9 @@ import BasicType from "../validator/types/BasicType";
7
7
  import ILocalPort from "./ILocalPort";
8
8
  import IPort from "./IPort";
9
9
 
10
+ /**
11
+ * Port basic class. Used internally to define device ports.
12
+ */
10
13
  export default class BasicPort {
11
14
  protected port: ILocalPort
12
15
 
@@ -20,22 +23,58 @@ export default class BasicPort {
20
23
  }
21
24
  }
22
25
 
26
+ /**
27
+ * Sets this port to dynamic
28
+ *
29
+ * If you specify a port to be dynamic, you must specify the number of those ports.
30
+ * Also if you specify a port as dynamic, you must specify `%d` in the name,
31
+ * which will be replaced by the port number.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * {
36
+ * 'command%d': Port.return().dynamic(this.options.inputs)
37
+ * }
38
+ * ```
39
+ *
40
+ * @param count Count of ports
41
+ */
23
42
  dynamic(count: number){
24
43
  this.port.count = count
25
44
  this.port.dynamic = true
26
45
  return this
27
46
  }
28
47
 
48
+ /**
49
+ * Specifies a recommendation to the data passing through the port.
50
+ * This data is not actually validated by these rules,
51
+ * but these rules can be used in the documentation to clarify perception.
52
+ *
53
+ * @param req BasicType type
54
+ */
29
55
  requirement(req: BasicType ){
30
56
  this.port.requirement = req
31
57
  return this
32
58
  }
33
59
 
60
+ /**
61
+ * Port descriptions
62
+ */
34
63
  description(des: string){
35
64
  this.port.description = des
36
65
  return this
37
66
  }
38
67
 
68
+ /**
69
+ * Exports the port data.
70
+ * Collects all data into an IPort object.
71
+ * Internal types of type BasicType are also exported to the corresponding properties
72
+ *
73
+ * @see IPort
74
+ *
75
+ * !hide for external users
76
+ * @private
77
+ */
39
78
  export(): IPort{
40
79
  const nPort: IPort = {
41
80
  type: this.port.type,
@@ -2,11 +2,18 @@ import BasicType from "../validator/types/BasicType";
2
2
 
3
3
 
4
4
  export default interface ILocalPort {
5
+ /** Port Type - Returned or Standard */
5
6
  type: string;
7
+ /** Specifies a recommendation to the data passing through the port. */
6
8
  requirement?: BasicType;
9
+ /** Specifies a recommendation for the data returned by the port */
7
10
  return?: BasicType;
11
+ /** Port description */
8
12
  description: string;
13
+ /** Is the connection of this port mandatory */
9
14
  required: boolean;
15
+ /** Whether the port is dynamic */
10
16
  dynamic: boolean;
17
+ /** Count of dynamic ports */
11
18
  count: number;
12
19
  }
@@ -2,11 +2,18 @@ import IValidationRule from "../validator/IValidationRule";
2
2
 
3
3
 
4
4
  export default interface IPort {
5
+ /** Port Type - Returned or Standard */
5
6
  type: string;
7
+ /** Specifies a recommendation to the data passing through the port. */
6
8
  requirement?: IValidationRule;
9
+ /** Specifies a recommendation for the data returned by the port */
7
10
  return?: IValidationRule;
11
+ /** Port description */
8
12
  description: string;
13
+ /** Is the connection of this port mandatory */
9
14
  required: boolean;
15
+ /** Whether the port is dynamic */
10
16
  dynamic: boolean;
17
+ /** Count of dynamic ports */
11
18
  count: number;
12
19
  }
package/src/ports/Port.ts CHANGED
@@ -5,12 +5,22 @@
5
5
 
6
6
  import ReturnPort from "./ReturnPort";
7
7
  import StandartPort from "./StandartPort";
8
-
8
+ /**
9
+ * Creating a new port. Used internally to create a port
10
+ */
9
11
  export default class Port {
12
+
13
+ /**
14
+ * Standard Port.
15
+ * Used to cast a value to another port or to signal a value to another port
16
+ */
10
17
  static standart() {
11
18
  return new StandartPort()
12
19
  }
13
20
 
21
+ /**
22
+ * Return Port. Used to get the value over connections
23
+ */
14
24
  static return() {
15
25
  return new ReturnPort()
16
26
  }
@@ -12,6 +12,11 @@ export default class ReturnPort extends BasicPort {
12
12
  this.port.type = 'return'
13
13
  }
14
14
 
15
+ /**
16
+ * Specifies a recommendation to the data return from the port.
17
+ *
18
+ * @param req BasicType type
19
+ */
15
20
  return(req: BasicType ){
16
21
  this.port.return = req
17
22
  return this