@syncbridge/common 0.9.0 → 0.9.2
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/constants.js
CHANGED
|
@@ -19,6 +19,14 @@ export { ElementComponentMetadataRecord };
|
|
|
19
19
|
let ElementComponentMetadata = class ElementComponentMetadata {
|
|
20
20
|
propertyKey;
|
|
21
21
|
};
|
|
22
|
+
__decorate([
|
|
23
|
+
ApiField({
|
|
24
|
+
label: 'Abstract',
|
|
25
|
+
description: 'Determines if the component uri is set in profile or it not. If set true an explicit uri is required.',
|
|
26
|
+
examples: ['@syncbridge/net:TcpClient', '@syncbridge/sqb:SqbClient'],
|
|
27
|
+
}),
|
|
28
|
+
__metadata("design:type", Boolean)
|
|
29
|
+
], ElementComponentMetadata.prototype, "abstract", void 0);
|
|
22
30
|
__decorate([
|
|
23
31
|
ApiField({
|
|
24
32
|
label: 'Class URI',
|
package/package.json
CHANGED
|
@@ -3,11 +3,11 @@ import { ProcessorMetadata, Profile } from '../models/index.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Materializes metadata from profile.
|
|
5
5
|
*/
|
|
6
|
-
export declare function materializeMetadata(profile: Profile): ProcessorMetadata;
|
|
6
|
+
export declare function materializeMetadata(profile: Profile, returnUndefinedComponentsAsAbstract?: boolean): ProcessorMetadata;
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
9
9
|
*/
|
|
10
|
-
export declare function materializeMetadataSilent(profile: Profile): {
|
|
10
|
+
export declare function materializeMetadataSilent(profile: Profile, returnUndefinedComponentsAsAbstract?: boolean): {
|
|
11
11
|
metadata: ProcessorMetadata;
|
|
12
12
|
issues?: StackExecutor.Issue[];
|
|
13
13
|
};
|
|
@@ -6,8 +6,8 @@ import { ExtensionRegistry } from '../registry/extension-registry.js';
|
|
|
6
6
|
/**
|
|
7
7
|
* Materializes metadata from profile.
|
|
8
8
|
*/
|
|
9
|
-
export function materializeMetadata(profile) {
|
|
10
|
-
const { metadata, issues } = materializeMetadataSilent(profile);
|
|
9
|
+
export function materializeMetadata(profile, returnUndefinedComponentsAsAbstract) {
|
|
10
|
+
const { metadata, issues } = materializeMetadataSilent(profile, returnUndefinedComponentsAsAbstract);
|
|
11
11
|
if (issues?.length) {
|
|
12
12
|
const msg = 'Worker profile validation error.\n ' +
|
|
13
13
|
issues
|
|
@@ -27,7 +27,7 @@ export function materializeMetadata(profile) {
|
|
|
27
27
|
/**
|
|
28
28
|
*
|
|
29
29
|
*/
|
|
30
|
-
export function materializeMetadataSilent(profile) {
|
|
30
|
+
export function materializeMetadataSilent(profile, returnUndefinedComponentsAsAbstract) {
|
|
31
31
|
const stackExecutor = new StackExecutor();
|
|
32
32
|
const processorRec = ExtensionRegistry.getProcessor(profile.processorUri);
|
|
33
33
|
const metadata = omitUndefined(clone({
|
|
@@ -43,7 +43,7 @@ export function materializeMetadataSilent(profile) {
|
|
|
43
43
|
}, { deep: 'full' }));
|
|
44
44
|
if (metadata.components) {
|
|
45
45
|
stackExecutor.execute('components', () => {
|
|
46
|
-
metadata.components = _materializeComponents(stackExecutor, metadata.components, profile);
|
|
46
|
+
metadata.components = _materializeComponents(stackExecutor, metadata.components, profile, returnUndefinedComponentsAsAbstract);
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
if (stackExecutor.issues?.length)
|
|
@@ -54,40 +54,52 @@ export function materializeMetadataSilent(profile) {
|
|
|
54
54
|
*
|
|
55
55
|
* @private
|
|
56
56
|
*/
|
|
57
|
-
function _materializeComponents(stackExecutor, srcMetadata, profile) {
|
|
57
|
+
function _materializeComponents(stackExecutor, srcMetadata, profile, returnUndefinedComponentsAsAbstract) {
|
|
58
58
|
const out = {};
|
|
59
59
|
for (const [componentName, metadataComponent,] of Object.entries(srcMetadata)) {
|
|
60
60
|
stackExecutor.execute(componentName, () => {
|
|
61
61
|
/** Check if component defined in profile */
|
|
62
|
+
let materializedComponent;
|
|
62
63
|
const profileComponent = profile?.components?.[componentName];
|
|
63
64
|
if (!profileComponent) {
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
if (!returnUndefinedComponentsAsAbstract) {
|
|
66
|
+
if (metadataComponent.required)
|
|
67
|
+
throw new SbValidationError(`Component "${componentName}" should be configured`);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
materializedComponent = {
|
|
71
|
+
abstract: true,
|
|
72
|
+
uri: metadataComponent.uri,
|
|
73
|
+
description: metadataComponent.description,
|
|
74
|
+
required: metadataComponent.required,
|
|
75
|
+
};
|
|
76
|
+
out[componentName] = materializedComponent;
|
|
67
77
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
else {
|
|
79
|
+
/** istanbul ignore next */
|
|
80
|
+
if (!profileComponent.uri)
|
|
81
|
+
throw new SbValidationError(`"uri" property required`);
|
|
82
|
+
const reg = ExtensionRegistry.getComponent(profileComponent.uri);
|
|
83
|
+
if (!(profileComponent.uri === metadataComponent.uri ||
|
|
84
|
+
reg.metadata.interfaces?.includes(metadataComponent.uri)))
|
|
85
|
+
throw new SbValidationError(`Selected component "${profileComponent.uri}" do not implement ${metadataComponent.uri}.`);
|
|
86
|
+
materializedComponent = {
|
|
87
|
+
uri: profileComponent.uri,
|
|
88
|
+
...omit(metadataComponent, ['uri', 'variables']),
|
|
89
|
+
};
|
|
90
|
+
materializedComponent.variables = merge({}, [reg.metadata.variables || {}, metadataComponent.variables || {}], { deep: 'full' });
|
|
91
|
+
materializedComponent.variables = sortVariables(materializedComponent.variables);
|
|
92
|
+
out[componentName] = materializedComponent;
|
|
93
|
+
/** Remove ignored variables */
|
|
94
|
+
for (const [k, variable] of Object.entries(materializedComponent.variables)) {
|
|
95
|
+
if (variable.ignored)
|
|
96
|
+
delete materializedComponent.variables[k];
|
|
97
|
+
}
|
|
98
|
+
if (reg.metadata.components) {
|
|
99
|
+
stackExecutor.execute('components', () => {
|
|
100
|
+
materializedComponent.components = _materializeComponents(stackExecutor, reg.metadata.components, profileComponent, returnUndefinedComponentsAsAbstract);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
91
103
|
}
|
|
92
104
|
});
|
|
93
105
|
}
|