@syncbridge/common 0.7.2 → 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.
@@ -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;
@@ -1,7 +1,6 @@
1
1
  import { ServiceStatus } from '../models/index.js';
2
2
  import { Runnable } from './runnable.js';
3
3
  export class BaseElement extends Runnable {
4
- static id;
5
4
  static uri;
6
5
  static packageName;
7
6
  static className;
package/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const version = '0.7.2';
1
+ export const version = '0.9.0';
2
2
  export const CLASS_METADATA = Symbol.for('CLASS_METADATA');
3
3
  export const CLASS_TYPE = Symbol.for('CLASS_TYPE');
4
4
  export const VARIABLE_CONTAINER = Symbol.for('VARIABLE_CONTAINER');
@@ -4,7 +4,6 @@ import { omit } from '@jsopen/objects';
4
4
  import callerCallsite from 'caller-callsite';
5
5
  import { CLASS_METADATA, CLASS_TYPE } from '../constants.js';
6
6
  import { resolvePackageJson } from '../utils/locate-package-json.js';
7
- import { uriToId } from '../utils/uri-to-id.js';
8
7
  import { defineOwnMetadata, parseNpmAuthor } from './decorator-helpers.js';
9
8
  import { UseComponent as _UseComponent } from './use-component.decorator.js';
10
9
  import { UseVariables as _UseVariables } from './use-variables.decorator.js';
@@ -34,11 +33,9 @@ export function Component(options) {
34
33
  Reflect.defineMetadata(CLASS_TYPE, 'component', target);
35
34
  const packageName = pkgjson.syncbridge?.name || pkgjson.name;
36
35
  const uri = packageName + ':' + className;
37
- const id = uriToId(uri);
38
36
  const metadata = defineOwnMetadata(target, CLASS_METADATA, {
39
37
  mergeBase: true,
40
38
  overwrite: {
41
- id,
42
39
  uri,
43
40
  displayName: className,
44
41
  version: pkgjson.version,
@@ -52,7 +49,6 @@ export function Component(options) {
52
49
  if (baseMetadata) {
53
50
  metadata.interfaces = Array.from(new Set([...(baseMetadata?.interfaces || []), base.uri]));
54
51
  }
55
- target.id = id;
56
52
  target.uri = uri;
57
53
  target.packageName = packageName;
58
54
  target.className = className;
@@ -4,7 +4,6 @@ import { omit } from '@jsopen/objects';
4
4
  import callerCallsite from 'caller-callsite';
5
5
  import { CLASS_METADATA, CLASS_TYPE } from '../constants.js';
6
6
  import { resolvePackageJson } from '../utils/locate-package-json.js';
7
- import { uriToId } from '../utils/uri-to-id.js';
8
7
  import { defineOwnMetadata } from './decorator-helpers.js';
9
8
  import { OnCreateProfile as _OnCreateProfile, OnUpdateProfile as _OnUpdateProfile, } from './processor-events.decorator.js';
10
9
  import { UseComponent as _UseComponent } from './use-component.decorator.js';
@@ -35,11 +34,9 @@ export function Processor(options) {
35
34
  Reflect.defineMetadata(CLASS_TYPE, 'processor', target);
36
35
  const packageName = pkgjson.syncbridge?.name || pkgjson.name;
37
36
  const uri = packageName + ':' + className;
38
- const id = uriToId(uri);
39
37
  defineOwnMetadata(target, CLASS_METADATA, {
40
38
  mergeBase: true,
41
39
  overwrite: {
42
- id,
43
40
  uri,
44
41
  displayName: className,
45
42
  version: pkgjson.version,
@@ -47,7 +44,6 @@ export function Processor(options) {
47
44
  ...omit(options, ['uri']),
48
45
  },
49
46
  });
50
- target.id = id;
51
47
  target.uri = uri;
52
48
  target.packageName = packageName;
53
49
  target.className = className;
@@ -7,7 +7,6 @@ import { VariableMetadataRecord } from './variable-metadata.js';
7
7
  export declare class ElementMetadata {
8
8
  constructor(init?: Partial<ElementMetadata>);
9
9
  abstract?: boolean;
10
- id: string;
11
10
  uri: string;
12
11
  displayName: string;
13
12
  iconUrl?: string;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncbridge/common",
3
- "version": "0.7.2",
3
+ "version": "0.9.0",
4
4
  "description": "SyncBridge Common utilities",
5
5
  "author": "Panates Inc",
6
6
  "license": "MIT",
@@ -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;
@@ -28,9 +28,6 @@ export class ExtensionBase {
28
28
  this.name = name;
29
29
  this.packageName = packageName;
30
30
  }
31
- get id() {
32
- return this.metadata.id;
33
- }
34
31
  get uri() {
35
32
  return this.metadata.uri;
36
33
  }
@@ -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 (this.components.get(uri) || this.componentsById.get(uri))?.find(v => semver.satisfies(v.version, version || '*'));
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 (this.processors.get(uri) || this.processorsById.get(uri))?.find(v => semver.satisfies(v.version, version || '*'));
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.processors.get(cmp.uri))
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
- let items = this.components.get(cmp.uri);
234
+ const id = uriToId(cmp.uri);
235
+ let items = this.components.get(id);
238
236
  if (!items) {
239
237
  items = [];
240
- this.components.set(cmp.uri, items);
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.components.get(prc.uri))
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
- let items = this.processors.get(prc.uri);
263
+ const id = uriToId(prc.uri);
264
+ let items = this.processors.get(id);
267
265
  if (!items) {
268
266
  items = [];
269
- this.processors.set(prc.uri, items);
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)
@@ -3,7 +3,6 @@ import { SbValidationError } from '../classes/sb-error.js';
3
3
  import { ComponentMetadata, ProcessorMetadata, } from '../models/index.js';
4
4
  import { initializeModelsDocument } from '../models-document.js';
5
5
  import { resolvePromisesDeep } from './resolve-promises.js';
6
- import { uriToId } from './uri-to-id.js';
7
6
  export async function normalizeProcessorMetadata(metadata) {
8
7
  const { metadata: out, issues } = await normalizeProcessorMetadataSilent(metadata);
9
8
  if (issues?.length) {
@@ -24,7 +23,6 @@ export async function normalizeProcessorMetadata(metadata) {
24
23
  export async function normalizeProcessorMetadataSilent(metadata) {
25
24
  const decoder = await getProcMetadataTypeDecoder();
26
25
  let cloned = deepClone({
27
- id: metadata.id || uriToId(metadata.uri),
28
26
  uri: metadata.uri,
29
27
  displayName: metadata.displayName,
30
28
  description: metadata.description,
@@ -69,7 +67,6 @@ export async function normalizeComponentMetadata(metadata) {
69
67
  export async function normalizeComponentMetadataSilent(metadata) {
70
68
  const decoder = await getCompMetadataTypeDecoder();
71
69
  let cloned = deepClone({
72
- id: metadata.id || uriToId(metadata.uri),
73
70
  uri: metadata.uri,
74
71
  displayName: metadata.displayName,
75
72
  description: metadata.description,