@syncbridge/common 0.7.1 → 0.9.0
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 +0 -1
- package/classes/base-element.js +0 -1
- package/constants.js +1 -1
- package/decorators/component.decorator.js +0 -7
- package/decorators/processor.decorator.js +0 -7
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/models/metadata/element-metadata.d.ts +0 -1
- package/models/metadata/element-metadata.js +0 -8
- package/package.json +1 -1
- package/registry/extension-package.d.ts +0 -1
- package/registry/extension-package.js +0 -3
- package/registry/extension-registry.d.ts +0 -4
- package/registry/extension-registry.js +15 -18
- package/utils/normalize-metadata.js +0 -2
- package/utils/uri-to-id.d.ts +1 -0
- package/utils/uri-to-id.js +7 -0
|
@@ -3,7 +3,6 @@ import { ServiceStatus } from '../models/index.js';
|
|
|
3
3
|
import type { ComponentBase } from './component-base.js';
|
|
4
4
|
import { Runnable } from './runnable.js';
|
|
5
5
|
export declare abstract class BaseElement<TEvents extends BaseElement.Events = BaseElement.Events> extends Runnable<TEvents> {
|
|
6
|
-
static id: string;
|
|
7
6
|
static uri: string;
|
|
8
7
|
static packageName: string;
|
|
9
8
|
static className: string;
|
package/classes/base-element.js
CHANGED
package/constants.js
CHANGED
|
@@ -33,15 +33,9 @@ export function Component(options) {
|
|
|
33
33
|
Reflect.defineMetadata(CLASS_TYPE, 'component', target);
|
|
34
34
|
const packageName = pkgjson.syncbridge?.name || pkgjson.name;
|
|
35
35
|
const uri = packageName + ':' + className;
|
|
36
|
-
const id = uri
|
|
37
|
-
.replace('@', '')
|
|
38
|
-
.replace(':', '__')
|
|
39
|
-
.replace(/\W/g, '_')
|
|
40
|
-
.toLowerCase();
|
|
41
36
|
const metadata = defineOwnMetadata(target, CLASS_METADATA, {
|
|
42
37
|
mergeBase: true,
|
|
43
38
|
overwrite: {
|
|
44
|
-
id,
|
|
45
39
|
uri,
|
|
46
40
|
displayName: className,
|
|
47
41
|
version: pkgjson.version,
|
|
@@ -55,7 +49,6 @@ export function Component(options) {
|
|
|
55
49
|
if (baseMetadata) {
|
|
56
50
|
metadata.interfaces = Array.from(new Set([...(baseMetadata?.interfaces || []), base.uri]));
|
|
57
51
|
}
|
|
58
|
-
target.id = id;
|
|
59
52
|
target.uri = uri;
|
|
60
53
|
target.packageName = packageName;
|
|
61
54
|
target.className = className;
|
|
@@ -34,15 +34,9 @@ export function Processor(options) {
|
|
|
34
34
|
Reflect.defineMetadata(CLASS_TYPE, 'processor', target);
|
|
35
35
|
const packageName = pkgjson.syncbridge?.name || pkgjson.name;
|
|
36
36
|
const uri = packageName + ':' + className;
|
|
37
|
-
const id = uri
|
|
38
|
-
.replace('@', '')
|
|
39
|
-
.replace(':', '__')
|
|
40
|
-
.replace(/\W/g, '_')
|
|
41
|
-
.toLowerCase();
|
|
42
37
|
defineOwnMetadata(target, CLASS_METADATA, {
|
|
43
38
|
mergeBase: true,
|
|
44
39
|
overwrite: {
|
|
45
|
-
id,
|
|
46
40
|
uri,
|
|
47
41
|
displayName: className,
|
|
48
42
|
version: pkgjson.version,
|
|
@@ -50,7 +44,6 @@ export function Processor(options) {
|
|
|
50
44
|
...omit(options, ['uri']),
|
|
51
45
|
},
|
|
52
46
|
});
|
|
53
|
-
target.id = id;
|
|
54
47
|
target.uri = uri;
|
|
55
48
|
target.packageName = packageName;
|
|
56
49
|
target.className = className;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -12,14 +12,6 @@ let ElementMetadata = class ElementMetadata {
|
|
|
12
12
|
}
|
|
13
13
|
abstract;
|
|
14
14
|
};
|
|
15
|
-
__decorate([
|
|
16
|
-
ApiField({
|
|
17
|
-
label: 'Id',
|
|
18
|
-
description: 'Web friendly unique identifier',
|
|
19
|
-
examples: ['syncbridge_net__tcpclient', 'syncbridge_sqb__sqbclient'],
|
|
20
|
-
}),
|
|
21
|
-
__metadata("design:type", String)
|
|
22
|
-
], ElementMetadata.prototype, "id", void 0);
|
|
23
15
|
__decorate([
|
|
24
16
|
ApiField({
|
|
25
17
|
label: 'Class URI',
|
package/package.json
CHANGED
|
@@ -29,7 +29,6 @@ export declare abstract class ExtensionBase {
|
|
|
29
29
|
readonly name: string;
|
|
30
30
|
readonly packageName: string;
|
|
31
31
|
protected constructor(pkg: ExtensionPackage, exportName: string, metadata: ElementMetadata, ctor?: Type<BaseElement>);
|
|
32
|
-
get id(): string;
|
|
33
32
|
get uri(): string;
|
|
34
33
|
get displayName(): string;
|
|
35
34
|
get version(): string;
|
|
@@ -16,10 +16,8 @@ export declare class ExtensionRegistry {
|
|
|
16
16
|
protected static [instanceSymbol]: ExtensionRegistry;
|
|
17
17
|
static get packages(): ResponsiveMap<ExtensionPackage[]>;
|
|
18
18
|
static get components(): ResponsiveMap<ComponentExtension[]>;
|
|
19
|
-
static get componentsById(): ResponsiveMap<ComponentExtension[]>;
|
|
20
19
|
static get componentsByClassName(): ResponsiveMap<ComponentExtension[]>;
|
|
21
20
|
static get processors(): ResponsiveMap<ProcessorExtension[]>;
|
|
22
|
-
static get processorsById(): ResponsiveMap<ProcessorExtension[]>;
|
|
23
21
|
static get processorsByClassName(): ResponsiveMap<ProcessorExtension[]>;
|
|
24
22
|
static setResolver(fn: ExtensionRegistry.PackageResolver | undefined): void;
|
|
25
23
|
static findComponent(uri: string, version?: string): ComponentExtension | undefined;
|
|
@@ -33,10 +31,8 @@ export declare class ExtensionRegistry {
|
|
|
33
31
|
protected _resolver: ExtensionRegistry.PackageResolver;
|
|
34
32
|
readonly packages: ResponsiveMap<ExtensionPackage[]>;
|
|
35
33
|
readonly components: ResponsiveMap<ComponentExtension[]>;
|
|
36
|
-
readonly componentsById: ResponsiveMap<ComponentExtension[]>;
|
|
37
34
|
readonly componentsByClassName: ResponsiveMap<ComponentExtension[]>;
|
|
38
35
|
readonly processors: ResponsiveMap<ProcessorExtension[]>;
|
|
39
|
-
readonly processorsById: ResponsiveMap<ProcessorExtension[]>;
|
|
40
36
|
readonly processorsByClassName: ResponsiveMap<ProcessorExtension[]>;
|
|
41
37
|
/**
|
|
42
38
|
*
|
|
@@ -8,6 +8,7 @@ import { SbError } from '../classes/sb-error.js';
|
|
|
8
8
|
import { CLASS_METADATA, CLASS_TYPE } from '../constants.js';
|
|
9
9
|
import { locatePackageJson } from '../utils/locate-package-json.js';
|
|
10
10
|
import { normalizeComponentMetadata, normalizeProcessorMetadata, } from '../utils/normalize-metadata.js';
|
|
11
|
+
import { uriToId } from '../utils/uri-to-id.js';
|
|
11
12
|
import { ComponentExtension, ExtensionPackage, ProcessorExtension, } from './extension-package.js';
|
|
12
13
|
const instanceSymbol = Symbol.for('instance');
|
|
13
14
|
/**
|
|
@@ -26,18 +27,12 @@ export class ExtensionRegistry {
|
|
|
26
27
|
static get components() {
|
|
27
28
|
return this[instanceSymbol].components;
|
|
28
29
|
}
|
|
29
|
-
static get componentsById() {
|
|
30
|
-
return this[instanceSymbol].componentsById;
|
|
31
|
-
}
|
|
32
30
|
static get componentsByClassName() {
|
|
33
31
|
return this[instanceSymbol].componentsByClassName;
|
|
34
32
|
}
|
|
35
33
|
static get processors() {
|
|
36
34
|
return this[instanceSymbol].processors;
|
|
37
35
|
}
|
|
38
|
-
static get processorsById() {
|
|
39
|
-
return this[instanceSymbol].processorsById;
|
|
40
|
-
}
|
|
41
36
|
static get processorsByClassName() {
|
|
42
37
|
return this[instanceSymbol].processorsByClassName;
|
|
43
38
|
}
|
|
@@ -68,10 +63,8 @@ export class ExtensionRegistry {
|
|
|
68
63
|
_resolver = import.meta.resolve;
|
|
69
64
|
packages = new ResponsiveMap();
|
|
70
65
|
components = new ResponsiveMap();
|
|
71
|
-
componentsById = new ResponsiveMap();
|
|
72
66
|
componentsByClassName = new ResponsiveMap();
|
|
73
67
|
processors = new ResponsiveMap();
|
|
74
|
-
processorsById = new ResponsiveMap();
|
|
75
68
|
processorsByClassName = new ResponsiveMap();
|
|
76
69
|
/**
|
|
77
70
|
*
|
|
@@ -83,7 +76,9 @@ export class ExtensionRegistry {
|
|
|
83
76
|
*
|
|
84
77
|
*/
|
|
85
78
|
findComponent(uri, version = '*') {
|
|
86
|
-
return
|
|
79
|
+
return this.components
|
|
80
|
+
.get(uriToId(uri))
|
|
81
|
+
?.find(v => semver.satisfies(v.version, version || '*'));
|
|
87
82
|
}
|
|
88
83
|
/**
|
|
89
84
|
*
|
|
@@ -99,7 +94,9 @@ export class ExtensionRegistry {
|
|
|
99
94
|
*
|
|
100
95
|
*/
|
|
101
96
|
findProcessor(uri, version = '*') {
|
|
102
|
-
return
|
|
97
|
+
return this.processors
|
|
98
|
+
.get(uriToId(uri))
|
|
99
|
+
?.find(v => semver.satisfies(v.version, version || '*'));
|
|
103
100
|
}
|
|
104
101
|
/**
|
|
105
102
|
*
|
|
@@ -231,14 +228,14 @@ export class ExtensionRegistry {
|
|
|
231
228
|
pkgVersions.sort((a, b) => a.version.localeCompare(b.version));
|
|
232
229
|
if (pkg.components?.length) {
|
|
233
230
|
for (const cmp of pkg.components) {
|
|
234
|
-
if (this.
|
|
231
|
+
if (this.findProcessor(cmp.uri))
|
|
235
232
|
throw new SbError(`Component "${cmp.uri}" is already registered as a processor.`);
|
|
236
233
|
/** Store to components */
|
|
237
|
-
|
|
234
|
+
const id = uriToId(cmp.uri);
|
|
235
|
+
let items = this.components.get(id);
|
|
238
236
|
if (!items) {
|
|
239
237
|
items = [];
|
|
240
|
-
this.components.set(
|
|
241
|
-
this.componentsById.set(cmp.id, items);
|
|
238
|
+
this.components.set(id, items);
|
|
242
239
|
}
|
|
243
240
|
i = items.findIndex(v => v.version === cmp.version);
|
|
244
241
|
if (i >= 0)
|
|
@@ -260,14 +257,14 @@ export class ExtensionRegistry {
|
|
|
260
257
|
}
|
|
261
258
|
if (pkg.processors?.length) {
|
|
262
259
|
for (const prc of pkg.processors) {
|
|
263
|
-
if (this.
|
|
260
|
+
if (this.findComponent(prc.uri))
|
|
264
261
|
throw new SbError(`Processor "${prc.uri}" is already registered as a component.`);
|
|
265
262
|
/** Store to processors */
|
|
266
|
-
|
|
263
|
+
const id = uriToId(prc.uri);
|
|
264
|
+
let items = this.processors.get(id);
|
|
267
265
|
if (!items) {
|
|
268
266
|
items = [];
|
|
269
|
-
this.processors.set(
|
|
270
|
-
this.processorsById.set(prc.id, items);
|
|
267
|
+
this.processors.set(id, items);
|
|
271
268
|
}
|
|
272
269
|
i = items.findIndex(v => v.version === prc.version);
|
|
273
270
|
if (i >= 0)
|
|
@@ -23,7 +23,6 @@ export async function normalizeProcessorMetadata(metadata) {
|
|
|
23
23
|
export async function normalizeProcessorMetadataSilent(metadata) {
|
|
24
24
|
const decoder = await getProcMetadataTypeDecoder();
|
|
25
25
|
let cloned = deepClone({
|
|
26
|
-
id: metadata.id,
|
|
27
26
|
uri: metadata.uri,
|
|
28
27
|
displayName: metadata.displayName,
|
|
29
28
|
description: metadata.description,
|
|
@@ -68,7 +67,6 @@ export async function normalizeComponentMetadata(metadata) {
|
|
|
68
67
|
export async function normalizeComponentMetadataSilent(metadata) {
|
|
69
68
|
const decoder = await getCompMetadataTypeDecoder();
|
|
70
69
|
let cloned = deepClone({
|
|
71
|
-
id: metadata.id,
|
|
72
70
|
uri: metadata.uri,
|
|
73
71
|
displayName: metadata.displayName,
|
|
74
72
|
description: metadata.description,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function uriToId(uri: string): string;
|