vrack2-core 1.0.4 → 1.0.5

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 CHANGED
@@ -9,6 +9,14 @@ VRack2 Core
9
9
 
10
10
  --------
11
11
 
12
+ ### Последнее обновление 1.0.5
13
+ - В Container добавлена ошибка `CTR_IGNORE_SERVICE_AUTORELOAD` её можно использовать, когда не хочется что бы после завершения работы сервиса - сервис автоматически перезапускался
14
+ - В класс `Device` добавлены
15
+ - Свойство `works: boolean = true` - если `false` - устройство перестает принимать и отправлять данные через порты
16
+ - Метод `beforeTerminate(){ return }` - может вызываться перед завершением сервиса (зависит от реализации)
17
+ - Теперь бинд входящего порта осуществляется по другому. Теперь вместо замены `DevicePort.push` ссылка на хендлер складывается в `DevicePort.bind` и уже после этого происходит вызов `DevicePort.bind()` внутри `DevicePort.push`
18
+
19
+
12
20
  ### Последнее обновление 1.0.4
13
21
 
14
22
  - `BasicType` (класс `Rule`) `require()` deprecated - используем `required()`
@@ -17,11 +25,6 @@ VRack2 Core
17
25
  - isCode(error: any, code: string) - Проверяет является ли ошибка VRack2 Error и соответсвует ли код переданной ошибке (проверяет vShort и vCode)
18
26
  - isError(error: any) - Проверяет - пренадлежит ли объект ошибки CoreError
19
27
 
20
- ### Обновление 1.0.3
21
-
22
- - Теперь порты `DevicePort` имеют ссылки на устройство своего владельца `Device`
23
- - Добавлено свойство meta внутри контейнера для хранения дополнительной информации
24
-
25
28
  **Использовать эту документацию имеет смысл только для более глубокого изучения устройства VRack2 или для создания сервиса независимого от VRack2**
26
29
 
27
30
  -------
package/lib/Container.js CHANGED
@@ -85,6 +85,7 @@ ErrorManager_1.default.register('Container', 'XR1K10R0OOUC', 'CTR_INCOMPATIBLE_P
85
85
  });
86
86
  ErrorManager_1.default.register('Container', 'MmVoDOQwaYkx', 'CTR_INCORRECT_BOOSTRAP', 'The required DeviceManager class is not specified correctly', {});
87
87
  ErrorManager_1.default.register('Container', 'e090R0MLyb7y', 'CTR_CONF_EXTENDS_PROBLEM', 'Problem with extending service configuration.', {});
88
+ ErrorManager_1.default.register('Container', 'LYC0VA1AWYKU', 'CTR_IGNORE_SERVICE_AUTORELOAD', 'Error that ignores service restart flag', {});
88
89
  /**
89
90
  * Service Load Class. It loads all devices in the list,
90
91
  * establishes connections between them, and performs device startup.
@@ -373,8 +374,9 @@ class Container extends events_1.default {
373
374
  // add structure device input ports
374
375
  this.structure[dconf.id].inputs[subkey] = [];
375
376
  this.structure[dconf.id].ports.push(Object.assign({ port: subkey, direct: 'input' }, pList[subkey]));
377
+ // биндимся а не заменяем push для контроля внутри push
376
378
  if (handler in dev)
377
- ndp.push = dev[handler].bind(dev);
379
+ ndp.bind = dev[handler].bind(dev);
378
380
  }
379
381
  }
380
382
  // make output ports
@@ -40,6 +40,12 @@ export default class Device {
40
40
  * @example 'vrack.KeyManager'
41
41
  */
42
42
  type: string;
43
+ /**
44
+ * Флаг общей работы
45
+ * Если флаг === false = все порты перестают принимать или отправлять данные/события
46
+ *
47
+ */
48
+ works: boolean;
43
49
  /**
44
50
  * Allows access to port management.
45
51
  */
@@ -136,6 +142,11 @@ export default class Device {
136
142
  * @param data data for action
137
143
  */
138
144
  beforeAction(action: string, data: any): boolean;
145
+ /**
146
+ * Должен вызываться перед завершением сервиса
147
+ * Но может не вызываться (зависит от реализации)
148
+ */
149
+ beforeTerminate(): void;
139
150
  /**
140
151
  * Prepare options
141
152
  *
@@ -58,6 +58,7 @@ class Device {
58
58
  this.id = id;
59
59
  this.type = type;
60
60
  this.Container = Container;
61
+ this.works = true;
61
62
  this.ports = {
62
63
  input: {},
63
64
  output: {}
@@ -118,6 +119,11 @@ class Device {
118
119
  * @param data data for action
119
120
  */
120
121
  beforeAction(action, data) { return true; }
122
+ /**
123
+ * Должен вызываться перед завершением сервиса
124
+ * Но может не вызываться (зависит от реализации)
125
+ */
126
+ beforeTerminate() { return; }
121
127
  /**
122
128
  * Prepare options
123
129
  *
@@ -268,7 +274,8 @@ class Device {
268
274
  */
269
275
  addInputHandler(name, action) {
270
276
  name = ImportManager_1.default.camelize('input.' + name);
271
- this[name] = action;
277
+ const a = this;
278
+ a[name] = action;
272
279
  }
273
280
  /**
274
281
  * Adding a handle for the action
@@ -278,7 +285,8 @@ class Device {
278
285
  */
279
286
  addActionHandler(name, action) {
280
287
  name = ImportManager_1.default.camelize('action.' + name);
281
- this[name] = action;
288
+ const a = this;
289
+ a[name] = action;
282
290
  }
283
291
  /**
284
292
  * Informs the rack that the unit cannot continue to operate.
@@ -18,6 +18,7 @@ export default class DevicePort {
18
18
  required: boolean;
19
19
  /** Ссылка на устройсто владельца */
20
20
  Device: Device;
21
+ bind: ((data: any) => {}) | null;
21
22
  /**
22
23
  * Список слушателей порта
23
24
  * Используется для захвата порта. Если какие либо данные будут проброшены
@@ -18,6 +18,7 @@ class DevicePort {
18
18
  this.connected = false;
19
19
  /** Port connection list. One port can have multiple connections */
20
20
  this.connections = [];
21
+ this.bind = null;
21
22
  /**
22
23
  * Список слушателей порта
23
24
  * Используется для захвата порта. Если какие либо данные будут проброшены
@@ -40,6 +41,10 @@ class DevicePort {
40
41
  * Calling the incoming port when calling a connection
41
42
  */
42
43
  push(data) {
44
+ if (!this.Device.works)
45
+ return;
46
+ if (this.bind !== null)
47
+ return this.bind(data);
43
48
  // Если у нас есть слушатели порта
44
49
  // Передаем им данные и пересоздаем Map
45
50
  if (this.listens.size) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vrack2-core",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Фреймворк для создания событийно-ориентированных сервисов на JavaScript/TypeScript",
5
5
  "main": "./lib/index",
6
6
  "scripts": {},
package/src/Container.ts CHANGED
@@ -107,6 +107,9 @@ ErrorManager.register('Container', 'XR1K10R0OOUC', 'CTR_INCOMPATIBLE_PORTS', 'In
107
107
  ErrorManager.register('Container', 'MmVoDOQwaYkx', 'CTR_INCORRECT_BOOSTRAP', 'The required DeviceManager class is not specified correctly', {})
108
108
  ErrorManager.register('Container', 'e090R0MLyb7y', 'CTR_CONF_EXTENDS_PROBLEM', 'Problem with extending service configuration.', {})
109
109
 
110
+ ErrorManager.register('Container', 'LYC0VA1AWYKU', 'CTR_IGNORE_SERVICE_AUTORELOAD', 'Error that ignores service restart flag', {})
111
+
112
+
110
113
 
111
114
  /**
112
115
  * Contains the structure of the service
@@ -474,7 +477,9 @@ export default class Container extends EventEmitter {
474
477
  this.structure[dconf.id].ports.push(
475
478
  Object.assign({ port: subkey, direct: 'input' }, pList[subkey])
476
479
  )
477
- if (handler in dev) ndp.push = dev[handler].bind(dev)
480
+
481
+ // биндимся а не заменяем push для контроля внутри push
482
+ if (handler in dev) ndp.bind = dev[handler].bind(dev)
478
483
  }
479
484
  }
480
485
 
@@ -54,6 +54,13 @@ export default class Device {
54
54
  */
55
55
  type: string;
56
56
 
57
+ /**
58
+ * Флаг общей работы
59
+ * Если флаг === false = все порты перестают принимать или отправлять данные/события
60
+ *
61
+ */
62
+ works: boolean
63
+
57
64
  /**
58
65
  * Allows access to port management.
59
66
  */
@@ -83,6 +90,7 @@ export default class Device {
83
90
  this.id = id
84
91
  this.type = type
85
92
  this.Container = Container
93
+ this.works = true
86
94
  this.ports = {
87
95
  input: {},
88
96
  output: {}
@@ -165,6 +173,12 @@ export default class Device {
165
173
  * @param data data for action
166
174
  */
167
175
  beforeAction(action: string, data: any) { return true }
176
+
177
+ /**
178
+ * Должен вызываться перед завершением сервиса
179
+ * Но может не вызываться (зависит от реализации)
180
+ */
181
+ beforeTerminate(){ return }
168
182
 
169
183
  /**
170
184
  * Prepare options
@@ -330,7 +344,8 @@ export default class Device {
330
344
  */
331
345
  addInputHandler(name: string, action: (data: any) => any) {
332
346
  name = ImportManager.camelize('input.' + name)
333
- this[name as keyof Device] = action
347
+ const a = this as any
348
+ a[name] = action
334
349
  }
335
350
 
336
351
  /**
@@ -341,7 +356,8 @@ export default class Device {
341
356
  */
342
357
  addActionHandler(name: string, action: (data: any) => any) {
343
358
  name = ImportManager.camelize('action.' + name)
344
- this[name as keyof Device] = action
359
+ const a = this as any
360
+ a[name] = action
345
361
  }
346
362
 
347
363
  /**
@@ -353,4 +369,5 @@ export default class Device {
353
369
  terminate(error: Error, action: string) {
354
370
  return this.makeEvent('device.terminate', action, error, [])
355
371
  }
372
+
356
373
  }
@@ -30,6 +30,8 @@ export default class DevicePort {
30
30
  /** Ссылка на устройсто владельца */
31
31
  Device: Device
32
32
 
33
+ bind: ((data: any) => {}) | null = null;
34
+
33
35
  /**
34
36
  * Список слушателей порта
35
37
  * Используется для захвата порта. Если какие либо данные будут проброшены
@@ -56,6 +58,9 @@ export default class DevicePort {
56
58
  * Calling the incoming port when calling a connection
57
59
  */
58
60
  push(data: any): any {
61
+ if (!this.Device.works) return
62
+ if (this.bind !== null) return this.bind(data)
63
+
59
64
  // Если у нас есть слушатели порта
60
65
  // Передаем им данные и пересоздаем Map
61
66
  if (this.listens.size) {