@syncbridge/builtins 0.4.17 → 0.4.18

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.
@@ -8,6 +8,7 @@ export declare class TransmitLogger extends EventEmitter {
8
8
  received(content: Buffer | string, peer?: string): void;
9
9
  transmitted(content: Buffer | string, peer?: string): void;
10
10
  info(content: string, peer?: string): void;
11
+ close(): void;
11
12
  protected _write(direction: string, content: Buffer | string, peer?: string): void;
12
13
  protected _getHeader(direction: string, contentSize: number, peer?: string): string;
13
14
  }
@@ -38,6 +38,9 @@ export class TransmitLogger extends EventEmitter {
38
38
  info(content, peer) {
39
39
  this._write('I', content, peer);
40
40
  }
41
+ close() {
42
+ this._stream?.end('');
43
+ }
41
44
  _write(direction, content, peer) {
42
45
  if (!this._stream)
43
46
  return;
@@ -11,6 +11,7 @@ export declare class IoClientBaseComponent<TEvents extends IoClientBaseComponent
11
11
  values: IoClientComponentVariables;
12
12
  protected _init(): Promise<void>;
13
13
  write(data: string | Buffer): void;
14
+ protected _configureCommunicationLogs(): void;
14
15
  }
15
16
  /**
16
17
  * @namespace
@@ -12,10 +12,23 @@ let IoClientBaseComponent = class IoClientBaseComponent extends ComponentBase {
12
12
  transmitLogger;
13
13
  async _init() {
14
14
  await super._init();
15
- const { communicationLogs } = this.values;
16
- const { dataDirectory } = this.processor;
17
- if (communicationLogs) {
18
- const transmitLogger = (this.transmitLogger = new TransmitLogger({
15
+ this.on('data', (data, info) => {
16
+ this.transmitLogger?.received(data, info);
17
+ });
18
+ this.on('transmit', (data, info) => {
19
+ this.transmitLogger?.transmitted(data, info);
20
+ });
21
+ this._configureCommunicationLogs();
22
+ }
23
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
24
+ write(data) {
25
+ throw new Error(`"${this.constructor.name}" component do not support write operations.`);
26
+ }
27
+ _configureCommunicationLogs() {
28
+ const { communicationLogs, communicationLogs_enabled } = this.values;
29
+ if (communicationLogs_enabled) {
30
+ const { dataDirectory } = this.processor;
31
+ this.transmitLogger = new TransmitLogger({
19
32
  ...communicationLogs,
20
33
  logDirectory: dataDirectory
21
34
  ? path.join(dataDirectory, 'comm-logs')
@@ -23,18 +36,12 @@ let IoClientBaseComponent = class IoClientBaseComponent extends ComponentBase {
23
36
  name: this.path.replace(/\//g, '-'),
24
37
  maxFiles: communicationLogs?.maxFiles,
25
38
  maxFileSize: communicationLogs?.maxFileSize,
26
- }));
27
- this.on('data', (data, info) => {
28
- transmitLogger.received(data, info);
29
- });
30
- this.on('transmit', (data, info) => {
31
- transmitLogger.transmitted(data, info);
32
39
  });
33
40
  }
34
- }
35
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
36
- write(data) {
37
- throw new Error(`"${this.constructor.name}" component do not support write operations.`);
41
+ else {
42
+ this.transmitLogger?.close();
43
+ this.transmitLogger = undefined;
44
+ }
38
45
  }
39
46
  };
40
47
  __decorate([
@@ -9,6 +9,7 @@ export class IoClientComponentVariables {
9
9
  __decorate([
10
10
  DefineVariable({
11
11
  label: 'Communication Logs Enabled',
12
+ hotPlug: true,
12
13
  }),
13
14
  __metadata("design:type", Boolean)
14
15
  ], IoClientComponentVariables.prototype, "communicationLogs_enabled", void 0);
@@ -11,6 +11,7 @@ export declare class IoServerBaseComponent<TEvents extends IoServerBaseComponent
11
11
  values: IoServerComponentVariables;
12
12
  protected _init(): Promise<void>;
13
13
  write(data: string | Buffer): void;
14
+ protected _configureCommunicationLogs(): void;
14
15
  }
15
16
  /**
16
17
  * @namespace
@@ -12,10 +12,23 @@ let IoServerBaseComponent = class IoServerBaseComponent extends ComponentBase {
12
12
  transmitLogger;
13
13
  async _init() {
14
14
  await super._init();
15
- const { communicationLogs } = this.values;
16
- const { dataDirectory } = this.processor;
17
- if (communicationLogs) {
18
- const transmitLogger = (this.transmitLogger = new TransmitLogger({
15
+ this.on('data', (data, info) => {
16
+ this.transmitLogger?.received(data, info);
17
+ });
18
+ this.on('transmit', (data, info) => {
19
+ this.transmitLogger?.transmitted(data, info);
20
+ });
21
+ this._configureCommunicationLogs();
22
+ }
23
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
24
+ write(data) {
25
+ throw new Error(`"${this.constructor.name}" component do not support write operations.`);
26
+ }
27
+ _configureCommunicationLogs() {
28
+ const { communicationLogs, communicationLogs_enabled } = this.values;
29
+ if (communicationLogs_enabled) {
30
+ const { dataDirectory } = this.processor;
31
+ this.transmitLogger = new TransmitLogger({
19
32
  ...communicationLogs,
20
33
  logDirectory: dataDirectory
21
34
  ? path.join(dataDirectory, 'comm-logs')
@@ -23,18 +36,12 @@ let IoServerBaseComponent = class IoServerBaseComponent extends ComponentBase {
23
36
  name: this.path.replace(/\//g, '-'),
24
37
  maxFiles: communicationLogs?.maxFiles,
25
38
  maxFileSize: communicationLogs?.maxFileSize,
26
- }));
27
- this.on('data', (data, info) => {
28
- transmitLogger.received(data, info);
29
- });
30
- this.on('transmit', (data, info) => {
31
- transmitLogger.transmitted(data, info);
32
39
  });
33
40
  }
34
- }
35
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
36
- write(data) {
37
- throw new Error(`"${this.constructor.name}" component do not support write operations.`);
41
+ else {
42
+ this.transmitLogger?.close();
43
+ this.transmitLogger = undefined;
44
+ }
38
45
  }
39
46
  };
40
47
  __decorate([
@@ -9,6 +9,7 @@ export class IoServerComponentVariables {
9
9
  __decorate([
10
10
  DefineVariable({
11
11
  label: 'Communication Logs Enabled',
12
+ hotPlug: true,
12
13
  }),
13
14
  __metadata("design:type", Boolean)
14
15
  ], IoServerComponentVariables.prototype, "communicationLogs_enabled", void 0);
package/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const version = '0.4.17';
1
+ export const version = '0.4.18';
2
2
  export const noOp = () => undefined;
3
3
  export const panatesAuthor = {
4
4
  name: 'Panates Technology AS',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncbridge/builtins",
3
- "version": "0.4.17",
3
+ "version": "0.4.18",
4
4
  "description": "SyncBridge builtin extensions",
5
5
  "author": "Panates Inc",
6
6
  "license": "UNLICENSED",
@@ -26,7 +26,7 @@
26
26
  "serialport": "^13.0.0"
27
27
  },
28
28
  "peerDependencies": {
29
- "@syncbridge/common": "^0.5.11",
29
+ "@syncbridge/common": "^0.5.12",
30
30
  "@sqb/builder": ">=4.19.6 <5",
31
31
  "@sqb/connect": ">=4.19.6 <5"
32
32
  },