@syncbridge/common 0.6.4 → 0.6.6

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.
@@ -25,8 +25,8 @@ export class BaseElement extends Runnable {
25
25
  }
26
26
  async _init() {
27
27
  for (const component of Object.values(this.components)) {
28
+ component.on('component-status-change', (...args) => this.emitAsyncSafe('component-status-change', ...args));
28
29
  component.on('status-change', (status, statusMessage) => {
29
- component.on('component-status-change', (...args) => this.emitAsyncSafe('component-status-change', ...args));
30
30
  /** Reset counters */
31
31
  this._context.statusIndicators = this._context.statusIndicators || {};
32
32
  Object.keys(ServiceStatus).forEach(key => {
@@ -42,9 +42,30 @@ export class BaseElement extends Runnable {
42
42
  counter.components.push(comp);
43
43
  counter.componentNames.push(comp.name);
44
44
  });
45
+ const oldStatus = this.status;
46
+ const oldStatusMessage = this.statusMessage;
47
+ this._context.calculatedStatus = undefined;
48
+ this._context.calculatedStatusMessage = undefined;
49
+ /** If there are one or more unhealthy components, set calculatedStatus to unhealthy */
50
+ if (this._context.status === ServiceStatus.started ||
51
+ this._context.status === ServiceStatus.starting) {
52
+ for (const _status of [
53
+ ServiceStatus.unhealthy,
54
+ ServiceStatus.starting,
55
+ ]) {
56
+ for (const cmp of Object.values(this.components)) {
57
+ if (cmp.status === _status) {
58
+ this._context.calculatedStatus = _status;
59
+ if (_status === ServiceStatus.unhealthy)
60
+ this._context.calculatedStatusMessage = cmp.statusMessage;
61
+ break;
62
+ }
63
+ }
64
+ }
65
+ }
45
66
  this.emitSafe('component-status-change', component, status, statusMessage);
46
- if (this._context.status !== this._context.calculatedStatus ||
47
- this._context.statusMessage !== this._context.statusMessage)
67
+ if (this.status !== oldStatus ||
68
+ this.statusMessage !== oldStatusMessage)
48
69
  this.onStatusChange();
49
70
  });
50
71
  }
@@ -62,20 +83,6 @@ export class BaseElement extends Runnable {
62
83
  .map(component => component.stop()));
63
84
  }
64
85
  onStatusChange() {
65
- this._context.calculatedStatus = this._context.status;
66
- this._context.calculatedStatusMessage = this._context.statusMessage;
67
- if (!(this.status === ServiceStatus.stopped ||
68
- this.status === ServiceStatus.stopping)) {
69
- /** If there are one or more unhealthy components, set calculatedStatus to unhealthy */
70
- for (const _status of [ServiceStatus.unhealthy, ServiceStatus.starting]) {
71
- const indicator = this._context.statusIndicators?.[_status];
72
- if (indicator?.count) {
73
- this._context.calculatedStatus = _status;
74
- this._context.calculatedStatusMessage = `${_status} components: ${indicator.componentNames}`;
75
- break;
76
- }
77
- }
78
- }
79
86
  super.onStatusChange();
80
87
  }
81
88
  }
@@ -112,6 +112,8 @@ export class Runnable extends AsyncEventEmitter {
112
112
  }).finally(() => (promiseSettled = true));
113
113
  }
114
114
  catch (e) {
115
+ if (this.status === ServiceStatus.stopping)
116
+ return;
115
117
  const err = e instanceof SbError ? e : new SbError(e);
116
118
  err.code = err.code || 'START_FAILED';
117
119
  this.onError(err);
package/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const version = '0.6.4';
1
+ export const version = '0.6.6';
2
2
  export const OWN_ELEMENT_METADATA = Symbol.for('OWN_ELEMENT_METADATA');
3
3
  export const COMPONENT_OPTIONS = Symbol.for('COMPONENT_OPTIONS');
4
4
  export const PROCESSOR_OPTIONS = Symbol.for('PROCESSOR_OPTIONS');
@@ -12,6 +12,7 @@ export declare class ElementComponentMetadata {
12
12
  propertyKey?: string;
13
13
  className?: string;
14
14
  description?: string;
15
+ disabled?: boolean;
15
16
  interfaces?: string[];
16
17
  required?: boolean;
17
18
  variables?: VariableMetadataRecord;
@@ -21,6 +21,7 @@ let ElementComponentMetadata = class ElementComponentMetadata {
21
21
  };
22
22
  __decorate([
23
23
  ApiField({
24
+ label: 'Class Name',
24
25
  description: 'Class name of the component',
25
26
  type: 'string',
26
27
  }),
@@ -28,6 +29,7 @@ __decorate([
28
29
  ], ElementComponentMetadata.prototype, "className", void 0);
29
30
  __decorate([
30
31
  ApiField({
32
+ label: 'Description',
31
33
  description: 'Description of the component',
32
34
  type: 'string',
33
35
  }),
@@ -35,6 +37,15 @@ __decorate([
35
37
  ], ElementComponentMetadata.prototype, "description", void 0);
36
38
  __decorate([
37
39
  ApiField({
40
+ label: 'Disabled',
41
+ description: 'Determine if the component is disabled or not',
42
+ type: 'string',
43
+ }),
44
+ __metadata("design:type", Boolean)
45
+ ], ElementComponentMetadata.prototype, "disabled", void 0);
46
+ __decorate([
47
+ ApiField({
48
+ label: 'Interfaces',
38
49
  description: 'Interfaces should be implemented by the component. This value is ignored if className is set',
39
50
  type: 'string',
40
51
  required: true,
@@ -44,6 +55,7 @@ __decorate([
44
55
  ], ElementComponentMetadata.prototype, "interfaces", void 0);
45
56
  __decorate([
46
57
  ApiField({
58
+ label: 'Required',
47
59
  description: 'Determine if the component is required or not',
48
60
  default: true,
49
61
  }),
@@ -51,6 +63,7 @@ __decorate([
51
63
  ], ElementComponentMetadata.prototype, "required", void 0);
52
64
  __decorate([
53
65
  ApiField({
66
+ label: 'Variables',
54
67
  description: 'Variables to be overridden',
55
68
  }),
56
69
  __metadata("design:type", VariableMetadataRecord)
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@syncbridge/common",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "SyncBridge Common utilities",
5
5
  "author": "Panates Inc",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "@jsopen/objects": "^2.1.1",
8
+ "@jsopen/objects": "^2.2.0",
9
9
  "fast-deep-equal": "^3.1.3",
10
10
  "node-events-async": "^1.5.0",
11
11
  "reflect-metadata": "^0.2.2",
@@ -121,7 +121,8 @@ export var ProcessorFactory;
121
121
  for (const [key, childMetadata] of Object.entries(newMetadata.components)) {
122
122
  // Stack: components/componentName
123
123
  await stackExecutor.executeAsync(key, async () => {
124
- await _configureComponent(ctx, key, childMetadata);
124
+ if (!childMetadata.disabled)
125
+ await _configureComponent(ctx, key, childMetadata);
125
126
  });
126
127
  }
127
128
  });
@@ -7,7 +7,7 @@ import { updateErrorMessage } from '@jsopen/objects';
7
7
  import { SbError } from '../classes/sb-error.js';
8
8
  import { COMPONENT_OPTIONS, PROCESSOR_OPTIONS } from '../constants.js';
9
9
  import { isComponentBase, isProcessorBase } from '../utils/type-guartds.js';
10
- import { normalizeComponentMetadata, normalizeProcessorMetadata, } from './helpers.js';
10
+ import { normalizeComponentMetadata, normalizeProcessorMetadata, } from './normalize-metadata.js';
11
11
  /**
12
12
  *
13
13
  */
@@ -2,7 +2,7 @@ import semver from 'semver';
2
2
  import { SbError } from '../classes/sb-error.js';
3
3
  import { COMPONENT_OPTIONS, PROCESSOR_OPTIONS } from '../constants.js';
4
4
  import { ComponentExtension, ExtensionPackage, ProcessorExtension, } from './extension-package.js';
5
- import { normalizeComponentMetadata, normalizeProcessorMetadata, } from './helpers.js';
5
+ import { normalizeComponentMetadata, normalizeProcessorMetadata, } from './normalize-metadata.js';
6
6
  export var ExtensionRegistry;
7
7
  (function (ExtensionRegistry) {
8
8
  let _resolver;
File without changes