@syncbridge/common 0.9.4 → 0.9.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.
- package/constants.js +1 -1
- package/decorators/component.decorator.js +6 -9
- package/decorators/decorator-helpers.d.ts +1 -4
- package/decorators/decorator-helpers.js +7 -9
- package/decorators/processor-events.decorator.js +4 -10
- package/decorators/processor.decorator.js +5 -8
- package/package.json +1 -1
- package/utils/materialize-metadata.d.ts +2 -2
- package/utils/materialize-metadata.js +18 -9
package/constants.js
CHANGED
|
@@ -34,15 +34,12 @@ export function Component(options) {
|
|
|
34
34
|
const packageName = pkgjson.syncbridge?.name || pkgjson.name;
|
|
35
35
|
const uri = packageName + ':' + className;
|
|
36
36
|
const metadata = defineOwnMetadata(target, CLASS_METADATA, {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
author: parseNpmAuthor(pkgjson.author),
|
|
44
|
-
...omit(options, ['uri']),
|
|
45
|
-
},
|
|
37
|
+
uri,
|
|
38
|
+
displayName: className,
|
|
39
|
+
version: pkgjson.version,
|
|
40
|
+
abstract: !!options.abstract,
|
|
41
|
+
author: parseNpmAuthor(pkgjson.author),
|
|
42
|
+
...omit(options, ['uri']),
|
|
46
43
|
});
|
|
47
44
|
const base = Object.getPrototypeOf(target);
|
|
48
45
|
const baseMetadata = Reflect.getMetadata(CLASS_METADATA, base);
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { AuthorMetadata } from '../models/index.js';
|
|
3
|
-
export declare function defineOwnMetadata(target: any, metadataKey: string | symbol,
|
|
4
|
-
overwrite?: any;
|
|
5
|
-
mergeBase?: boolean;
|
|
6
|
-
}): any;
|
|
3
|
+
export declare function defineOwnMetadata(target: any, metadataKey: string | symbol, overwrite?: any): any;
|
|
7
4
|
export declare function parseNpmAuthor(value: any): AuthorMetadata | undefined;
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { merge } from '@jsopen/objects';
|
|
3
3
|
import { AuthorMetadata } from '../models/index.js';
|
|
4
|
-
export function defineOwnMetadata(target, metadataKey,
|
|
4
|
+
export function defineOwnMetadata(target, metadataKey, overwrite) {
|
|
5
5
|
let metadata = Reflect.getOwnMetadata(metadataKey, target);
|
|
6
6
|
const sources = [];
|
|
7
7
|
if (!metadata) {
|
|
8
8
|
metadata = {};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
sources.push(baseMetadata);
|
|
14
|
-
}
|
|
9
|
+
const base = Object.getPrototypeOf(target);
|
|
10
|
+
const baseMetadata = Reflect.getMetadata(metadataKey, base);
|
|
11
|
+
if (baseMetadata)
|
|
12
|
+
sources.push(baseMetadata);
|
|
15
13
|
}
|
|
16
|
-
if (
|
|
17
|
-
sources.push(
|
|
14
|
+
if (overwrite)
|
|
15
|
+
sources.push(overwrite);
|
|
18
16
|
if (sources.length)
|
|
19
17
|
merge(metadata, sources, {
|
|
20
18
|
deep: 'full',
|
|
@@ -4,11 +4,8 @@ import { defineOwnMetadata } from './decorator-helpers.js';
|
|
|
4
4
|
export function OnCreateProfile() {
|
|
5
5
|
return function (target, propertyKey) {
|
|
6
6
|
defineOwnMetadata(target, CLASS_METADATA, {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
staticEvents: {
|
|
10
|
-
onCreateProfile: propertyKey,
|
|
11
|
-
},
|
|
7
|
+
staticEvents: {
|
|
8
|
+
onCreateProfile: propertyKey,
|
|
12
9
|
},
|
|
13
10
|
});
|
|
14
11
|
};
|
|
@@ -16,11 +13,8 @@ export function OnCreateProfile() {
|
|
|
16
13
|
export function OnUpdateProfile() {
|
|
17
14
|
return function (target, propertyKey) {
|
|
18
15
|
defineOwnMetadata(target, CLASS_METADATA, {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
staticEvents: {
|
|
22
|
-
onUpdateProfile: propertyKey,
|
|
23
|
-
},
|
|
16
|
+
staticEvents: {
|
|
17
|
+
onUpdateProfile: propertyKey,
|
|
24
18
|
},
|
|
25
19
|
});
|
|
26
20
|
};
|
|
@@ -35,14 +35,11 @@ export function Processor(options) {
|
|
|
35
35
|
const packageName = pkgjson.syncbridge?.name || pkgjson.name;
|
|
36
36
|
const uri = packageName + ':' + className;
|
|
37
37
|
defineOwnMetadata(target, CLASS_METADATA, {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
abstract: !!options.abstract,
|
|
44
|
-
...omit(options, ['uri']),
|
|
45
|
-
},
|
|
38
|
+
uri,
|
|
39
|
+
displayName: className,
|
|
40
|
+
version: pkgjson.version,
|
|
41
|
+
abstract: !!options.abstract,
|
|
42
|
+
...omit(options, ['uri']),
|
|
46
43
|
});
|
|
47
44
|
target.uri = uri;
|
|
48
45
|
target.packageName = packageName;
|
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,7 +54,7 @@ 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, () => {
|
|
@@ -62,9 +62,18 @@ function _materializeComponents(stackExecutor, srcMetadata, profile) {
|
|
|
62
62
|
let materializedComponent;
|
|
63
63
|
const profileComponent = profile?.components?.[componentName];
|
|
64
64
|
if (!profileComponent) {
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
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;
|
|
68
77
|
}
|
|
69
78
|
else {
|
|
70
79
|
/** istanbul ignore next */
|
|
@@ -88,7 +97,7 @@ function _materializeComponents(stackExecutor, srcMetadata, profile) {
|
|
|
88
97
|
}
|
|
89
98
|
if (reg.metadata.components) {
|
|
90
99
|
stackExecutor.execute('components', () => {
|
|
91
|
-
materializedComponent.components = _materializeComponents(stackExecutor, reg.metadata.components, profileComponent);
|
|
100
|
+
materializedComponent.components = _materializeComponents(stackExecutor, reg.metadata.components, profileComponent, returnUndefinedComponentsAsAbstract);
|
|
92
101
|
});
|
|
93
102
|
}
|
|
94
103
|
}
|