@syncbridge/common 0.6.14 → 0.7.1
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/classes/base-element.d.ts +3 -0
- package/classes/base-element.js +3 -0
- package/constants.d.ts +2 -3
- package/constants.js +3 -11
- package/decorators/component.decorator.d.ts +5 -7
- package/decorators/component.decorator.js +58 -10
- package/decorators/decorator-helpers.d.ts +6 -1
- package/decorators/decorator-helpers.js +45 -10
- package/decorators/processor-events.decorator.js +14 -8
- package/decorators/processor.decorator.d.ts +6 -8
- package/decorators/processor.decorator.js +49 -3
- package/decorators/use-component.decorator.d.ts +1 -1
- package/decorators/use-component.decorator.js +12 -14
- package/decorators/use-variables.decorator.js +5 -6
- package/models/metadata/component-metadata.js +1 -1
- package/models/metadata/element-component-metadata.d.ts +1 -2
- package/models/metadata/element-component-metadata.js +4 -13
- package/models/metadata/element-metadata.d.ts +2 -1
- package/models/metadata/element-metadata.js +12 -4
- package/models/profile/profile-component.d.ts +1 -1
- package/models/profile/profile-component.js +3 -3
- package/models/profile/profile.d.ts +1 -1
- package/models/profile/profile.js +3 -3
- package/package.json +2 -1
- package/processor-factory.d.ts +2 -1
- package/processor-factory.js +26 -8
- package/registry/extension-package.d.ts +23 -13
- package/registry/extension-package.js +28 -22
- package/registry/extension-registry.d.ts +22 -15
- package/registry/extension-registry.js +122 -88
- package/utils/decode-profile.js +1 -1
- package/utils/locate-package-json.d.ts +5 -0
- package/{registry → utils}/locate-package-json.js +9 -2
- package/utils/materialize-metadata.js +24 -41
- package/utils/normalize-metadata.js +4 -2
- package/decorators/finalize-element-metadata.d.ts +0 -4
- package/decorators/finalize-element-metadata.js +0 -30
- package/registry/locate-package-json.d.ts +0 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { clone, merge, omitUndefined } from '@jsopen/objects';
|
|
1
|
+
import { clone, merge, omit, omitUndefined } from '@jsopen/objects';
|
|
2
2
|
import { SbValidationError } from '../classes/sb-error.js';
|
|
3
3
|
import { StackExecutor } from '../classes/stack-executor.js';
|
|
4
4
|
import { VariableType, } from '../models/index.js';
|
|
@@ -29,9 +29,9 @@ export function materializeMetadata(profile) {
|
|
|
29
29
|
*/
|
|
30
30
|
export function materializeMetadataSilent(profile) {
|
|
31
31
|
const stackExecutor = new StackExecutor();
|
|
32
|
-
const processorRec = ExtensionRegistry.getProcessor(profile.
|
|
32
|
+
const processorRec = ExtensionRegistry.getProcessor(profile.processorUri);
|
|
33
33
|
const metadata = omitUndefined(clone({
|
|
34
|
-
|
|
34
|
+
uri: processorRec.metadata.uri,
|
|
35
35
|
displayName: processorRec.metadata.displayName,
|
|
36
36
|
description: processorRec.metadata.description,
|
|
37
37
|
iconUrl: processorRec.metadata.iconUrl,
|
|
@@ -41,10 +41,9 @@ export function materializeMetadataSilent(profile) {
|
|
|
41
41
|
components: processorRec.metadata.components,
|
|
42
42
|
...processorRec.metadata,
|
|
43
43
|
}, { deep: 'full' }));
|
|
44
|
-
|
|
45
|
-
if (processorRec.metadata.components) {
|
|
44
|
+
if (metadata.components) {
|
|
46
45
|
stackExecutor.execute('components', () => {
|
|
47
|
-
metadata.components = _materializeComponents(stackExecutor,
|
|
46
|
+
metadata.components = _materializeComponents(stackExecutor, metadata.components, profile);
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
49
|
if (stackExecutor.issues?.length)
|
|
@@ -55,18 +54,10 @@ export function materializeMetadataSilent(profile) {
|
|
|
55
54
|
*
|
|
56
55
|
* @private
|
|
57
56
|
*/
|
|
58
|
-
function _materializeComponents(stackExecutor,
|
|
57
|
+
function _materializeComponents(stackExecutor, srcMetadata, profile) {
|
|
59
58
|
const out = {};
|
|
60
|
-
for (const [componentName, metadataComponent,] of Object.entries(
|
|
59
|
+
for (const [componentName, metadataComponent,] of Object.entries(srcMetadata)) {
|
|
61
60
|
stackExecutor.execute(componentName, () => {
|
|
62
|
-
const materializedComponent = {
|
|
63
|
-
interfaces: metadataComponent.interfaces
|
|
64
|
-
? [...metadataComponent.interfaces]
|
|
65
|
-
: undefined,
|
|
66
|
-
required: metadataComponent.required,
|
|
67
|
-
...metadataComponent,
|
|
68
|
-
};
|
|
69
|
-
out[componentName] = materializedComponent;
|
|
70
61
|
/** Check if component defined in profile */
|
|
71
62
|
const profileComponent = profile?.components?.[componentName];
|
|
72
63
|
if (!profileComponent) {
|
|
@@ -75,34 +66,27 @@ function _materializeComponents(stackExecutor, metadata, profile) {
|
|
|
75
66
|
return;
|
|
76
67
|
}
|
|
77
68
|
/** istanbul ignore next */
|
|
78
|
-
if (!profileComponent.
|
|
79
|
-
throw new SbValidationError(`"
|
|
80
|
-
const reg = ExtensionRegistry.getComponent(profileComponent.
|
|
81
|
-
|
|
69
|
+
if (!profileComponent.uri)
|
|
70
|
+
throw new SbValidationError(`"uri" property required`);
|
|
71
|
+
const reg = ExtensionRegistry.getComponent(profileComponent.uri);
|
|
72
|
+
if (!(profileComponent.uri === metadataComponent.uri ||
|
|
73
|
+
reg.metadata.interfaces?.includes(metadataComponent.uri)))
|
|
74
|
+
throw new SbValidationError(`Selected component "${profileComponent.uri}" do not implement ${metadataComponent.uri}.`);
|
|
75
|
+
const materializedComponent = {
|
|
76
|
+
uri: profileComponent.uri,
|
|
77
|
+
...omit(metadataComponent, ['uri', 'variables']),
|
|
78
|
+
};
|
|
79
|
+
out[componentName] = materializedComponent;
|
|
82
80
|
materializedComponent.variables = merge({}, [reg.metadata.variables || {}, metadataComponent.variables || {}], { deep: 'full' });
|
|
83
81
|
materializedComponent.variables = sortVariables(materializedComponent.variables);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
const requiredInterfaces = metadataComponent.interfaces || [];
|
|
91
|
-
const implementations = reg.metadata.interfaces || [];
|
|
92
|
-
const filtered = requiredInterfaces.filter(x => !implementations.includes(x));
|
|
93
|
-
if (filtered.length) {
|
|
94
|
-
throw new SbValidationError(`Selected component "${profileComponent.className}" do not implements some of required interfaces (${filtered.join(',')}).`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (materializedComponent.variables) {
|
|
98
|
-
for (const [k, variable] of Object.entries(materializedComponent.variables)) {
|
|
99
|
-
if (variable.ignored)
|
|
100
|
-
delete materializedComponent.variables[k];
|
|
101
|
-
}
|
|
82
|
+
/** Remove ignored variables */
|
|
83
|
+
for (const [k, variable] of Object.entries(materializedComponent.variables)) {
|
|
84
|
+
if (variable.ignored)
|
|
85
|
+
delete materializedComponent.variables[k];
|
|
102
86
|
}
|
|
103
87
|
if (reg.metadata.components) {
|
|
104
88
|
stackExecutor.execute('components', () => {
|
|
105
|
-
materializedComponent.components = _materializeComponents(stackExecutor, reg.metadata, profileComponent);
|
|
89
|
+
materializedComponent.components = _materializeComponents(stackExecutor, reg.metadata.components, profileComponent);
|
|
106
90
|
});
|
|
107
91
|
}
|
|
108
92
|
});
|
|
@@ -113,7 +97,7 @@ function sortVariables(variables) {
|
|
|
113
97
|
if (!variables)
|
|
114
98
|
return;
|
|
115
99
|
const keys = Object.keys(variables);
|
|
116
|
-
|
|
100
|
+
return [...keys]
|
|
117
101
|
.sort((a, b) => {
|
|
118
102
|
const va = variables[a];
|
|
119
103
|
const vb = variables[b];
|
|
@@ -133,5 +117,4 @@ function sortVariables(variables) {
|
|
|
133
117
|
a[k] = variables[k];
|
|
134
118
|
return a;
|
|
135
119
|
}, {});
|
|
136
|
-
return sorted;
|
|
137
120
|
}
|
|
@@ -23,7 +23,8 @@ export async function normalizeProcessorMetadata(metadata) {
|
|
|
23
23
|
export async function normalizeProcessorMetadataSilent(metadata) {
|
|
24
24
|
const decoder = await getProcMetadataTypeDecoder();
|
|
25
25
|
let cloned = deepClone({
|
|
26
|
-
|
|
26
|
+
id: metadata.id,
|
|
27
|
+
uri: metadata.uri,
|
|
27
28
|
displayName: metadata.displayName,
|
|
28
29
|
description: metadata.description,
|
|
29
30
|
iconUrl: metadata.iconUrl,
|
|
@@ -67,7 +68,8 @@ export async function normalizeComponentMetadata(metadata) {
|
|
|
67
68
|
export async function normalizeComponentMetadataSilent(metadata) {
|
|
68
69
|
const decoder = await getCompMetadataTypeDecoder();
|
|
69
70
|
let cloned = deepClone({
|
|
70
|
-
|
|
71
|
+
id: metadata.id,
|
|
72
|
+
uri: metadata.uri,
|
|
71
73
|
displayName: metadata.displayName,
|
|
72
74
|
description: metadata.description,
|
|
73
75
|
iconUrl: metadata.iconUrl,
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { DeepPartial, Type } from 'ts-gems';
|
|
3
|
-
import { ElementMetadata } from '../models/index.js';
|
|
4
|
-
export declare function finalizeElementMetadata(target: Type, options: DeepPartial<ElementMetadata>, metadataKey: any, namePattern?: RegExp): void;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { merge } from '@jsopen/objects';
|
|
3
|
-
import { OWN_ELEMENT_METADATA } from '../constants.js';
|
|
4
|
-
export function finalizeElementMetadata(target, options, metadataKey, namePattern) {
|
|
5
|
-
/** Determine class name */
|
|
6
|
-
let className = options.className;
|
|
7
|
-
if (!className && namePattern) {
|
|
8
|
-
const m = namePattern.exec(target.name);
|
|
9
|
-
if (!m)
|
|
10
|
-
throw new TypeError('Class name must be PascalCase and should contains only letters and numbers. Example: MyProcessor ');
|
|
11
|
-
if (m)
|
|
12
|
-
className = m[1];
|
|
13
|
-
}
|
|
14
|
-
if (!className)
|
|
15
|
-
throw new TypeError('Class name is required');
|
|
16
|
-
const base = Object.getPrototypeOf(target);
|
|
17
|
-
const baseMetadata = Reflect.getMetadata(metadataKey, base) || {};
|
|
18
|
-
const ownMetadata = Reflect.getMetadata(OWN_ELEMENT_METADATA, target);
|
|
19
|
-
const finalMetadata = merge({}, [baseMetadata, options, ownMetadata], {
|
|
20
|
-
deep: 'full',
|
|
21
|
-
mergeArrays: 'unique',
|
|
22
|
-
ignoreNulls: false,
|
|
23
|
-
ignoreUndefined: false,
|
|
24
|
-
});
|
|
25
|
-
finalMetadata.abstract = !!options.abstract;
|
|
26
|
-
finalMetadata.className = className;
|
|
27
|
-
finalMetadata.displayName = finalMetadata.displayName || className;
|
|
28
|
-
Reflect.defineMetadata(metadataKey, finalMetadata, target);
|
|
29
|
-
target.className = finalMetadata.className;
|
|
30
|
-
}
|