@syncbridge/common 0.12.6 → 0.13.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/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const version = '0.12.6';
1
+ export const version = '0.13.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');
@@ -5,7 +5,7 @@ import { ComponentMetadata } from '../models/index.js';
5
5
  import { UseComponent as _UseComponent } from './use-component.decorator.js';
6
6
  export declare function Component<T extends ComponentBase>(options: Component.Options): (target: Type<T>) => void;
7
7
  export declare namespace Component {
8
- type Options = DeepPartial<StrictOmit<ComponentMetadata, 'uri' | 'components' | 'variables' | 'version'>> & {
8
+ type Options = DeepPartial<StrictOmit<ComponentMetadata, 'classType' | 'className' | 'components' | 'variables' | 'version'>> & {
9
9
  className?: string;
10
10
  };
11
11
  function UseVariables<T extends ComponentBase>(variablesClass?: Type): (target: T, propertyKey: "values") => void;
@@ -6,7 +6,7 @@ import { ComponentBase } from '../classes/component-base.js';
6
6
  import { CLASS_METADATA, CLASS_TYPE } from '../constants.js';
7
7
  import { ComponentMetadata } from '../models/index.js';
8
8
  import { resolvePackageJson } from '../utils/locate-package-json.js';
9
- import { defineOwnMetadata, parseNpmAuthor } from './decorator-helpers.js';
9
+ import { defineOwnMetadata } from './decorator-helpers.js';
10
10
  import { UseComponent as _UseComponent } from './use-component.decorator.js';
11
11
  import { UseVariables as _UseVariables } from './use-variables.decorator.js';
12
12
  const NAME_PATTERN = /^([A-Z][A-Za-z0-9_]*?)(Component)?$/;
@@ -36,12 +36,20 @@ export function Component(options) {
36
36
  const packageName = pkgjson.syncbridge?.name || pkgjson.name;
37
37
  const uri = packageName + ':' + className;
38
38
  const metadata = defineOwnMetadata(target, CLASS_METADATA, {
39
+ classType: 'component',
39
40
  uri,
41
+ className,
40
42
  displayName: className,
41
43
  version: pkgjson.version,
42
44
  abstract: !!options.abstract,
43
- author: parseNpmAuthor(pkgjson.author),
44
- ...omit(options, ['uri', 'components', 'variables', 'version']),
45
+ ...omit(options, [
46
+ 'uri',
47
+ 'classType',
48
+ 'className',
49
+ 'components',
50
+ 'variables',
51
+ 'version',
52
+ ]),
45
53
  });
46
54
  const base = Object.getPrototypeOf(target);
47
55
  const baseMetadata = Reflect.getMetadata(CLASS_METADATA, base);
@@ -1,4 +1,2 @@
1
1
  import 'reflect-metadata';
2
- import { AuthorMetadata } from '../models/index.js';
3
2
  export declare function defineOwnMetadata(target: any, metadataKey: string | symbol, overwrite?: any): any;
4
- export declare function parseNpmAuthor(value: any): AuthorMetadata | undefined;
@@ -1,6 +1,5 @@
1
1
  import 'reflect-metadata';
2
2
  import { merge } from '@jsopen/objects';
3
- import { AuthorMetadata } from '../models/index.js';
4
3
  export function defineOwnMetadata(target, metadataKey, overwrite) {
5
4
  let metadata = Reflect.getOwnMetadata(metadataKey, target);
6
5
  const sources = [];
@@ -23,24 +22,3 @@ export function defineOwnMetadata(target, metadataKey, overwrite) {
23
22
  Reflect.defineMetadata(metadataKey, metadata, target);
24
23
  return metadata;
25
24
  }
26
- const AUTHOR_PATTERN = /^\s*([^<(]+?)\s*(?:<([^>]+)>)?\s*(?:\(([^)]+)\))?\s*$/;
27
- export function parseNpmAuthor(value) {
28
- if (!value)
29
- return;
30
- if (typeof value === 'string') {
31
- const m = AUTHOR_PATTERN.exec(value);
32
- if (m)
33
- return new AuthorMetadata({
34
- name: m[1],
35
- email: m[2],
36
- url: m[3],
37
- });
38
- }
39
- else if (typeof value === 'object') {
40
- return new AuthorMetadata({
41
- name: value.name,
42
- email: value.email,
43
- url: value.url,
44
- });
45
- }
46
- }
@@ -23,7 +23,7 @@ export declare namespace Processor {
23
23
  function OnUpdateProfile<T extends ProcessorBase>(): (target: Type<T>, propertyKey: string | symbol) => void;
24
24
  }
25
25
  export declare namespace Processor {
26
- type Options = DeepPartial<StrictOmit<ProcessorMetadata, 'uri' | 'components' | 'variables' | 'version'>> & {
26
+ type Options = DeepPartial<StrictOmit<ProcessorMetadata, 'classType' | 'className' | 'components' | 'variables' | 'version'>> & {
27
27
  className?: string;
28
28
  };
29
29
  }
@@ -36,11 +36,20 @@ export function Processor(options) {
36
36
  const packageName = pkgjson.syncbridge?.name || pkgjson.name;
37
37
  const uri = packageName + ':' + className;
38
38
  defineOwnMetadata(target, CLASS_METADATA, {
39
+ classType: 'processor',
39
40
  uri,
41
+ className,
40
42
  displayName: className,
41
43
  version: pkgjson.version,
42
44
  abstract: !!options?.abstract,
43
- ...omit(options, ['uri', 'components', 'variables', 'version']),
45
+ ...omit(options, [
46
+ 'uri',
47
+ 'classType',
48
+ 'className',
49
+ 'components',
50
+ 'variables',
51
+ 'version',
52
+ ]),
44
53
  });
45
54
  target.uri = uri;
46
55
  target.packageName = packageName;
package/models/index.d.ts CHANGED
@@ -2,7 +2,6 @@ export * from './enums/log-level.js';
2
2
  export * from './enums/service-status.js';
3
3
  export * from './enums/variable-format.enum.js';
4
4
  export * from './enums/variable-type.enum.js';
5
- export * from './metadata/author-metadata.js';
6
5
  export * from './metadata/component-metadata.js';
7
6
  export * from './metadata/element-component-metadata.js';
8
7
  export * from './metadata/element-metadata.js';
package/models/index.js CHANGED
@@ -2,7 +2,6 @@ export * from './enums/log-level.js';
2
2
  export * from './enums/service-status.js';
3
3
  export * from './enums/variable-format.enum.js';
4
4
  export * from './enums/variable-type.enum.js';
5
- export * from './metadata/author-metadata.js';
6
5
  export * from './metadata/component-metadata.js';
7
6
  export * from './metadata/element-component-metadata.js';
8
7
  export * from './metadata/element-metadata.js';
@@ -4,5 +4,6 @@ import { ElementMetadata } from './element-metadata.js';
4
4
  */
5
5
  export declare class ComponentMetadata extends ElementMetadata {
6
6
  constructor(init?: Partial<ComponentMetadata>);
7
+ classType: 'component';
7
8
  interfaces: string[];
8
9
  }
@@ -9,6 +9,14 @@ let ComponentMetadata = class ComponentMetadata extends ElementMetadata {
9
9
  super(init);
10
10
  }
11
11
  };
12
+ __decorate([
13
+ ApiField({
14
+ label: 'Class Type',
15
+ description: 'Determines the type of the class',
16
+ fixed: 'component',
17
+ }),
18
+ __metadata("design:type", String)
19
+ ], ComponentMetadata.prototype, "classType", void 0);
12
20
  __decorate([
13
21
  ApiField({
14
22
  label: 'Interfaces',
@@ -1,4 +1,3 @@
1
- import { AuthorMetadata } from './author-metadata.js';
2
1
  import type { ElementComponentMetadataRecord } from './element-component-metadata.js';
3
2
  import { VariableMetadataRecord } from './variable-metadata.js';
4
3
  /**
@@ -7,12 +6,11 @@ import { VariableMetadataRecord } from './variable-metadata.js';
7
6
  export declare class ElementMetadata {
8
7
  constructor(init?: Partial<ElementMetadata>);
9
8
  abstract?: boolean;
10
- uri: string;
11
- version?: string;
9
+ className: string;
10
+ version: string;
12
11
  displayName: string;
13
12
  iconUrl?: string;
14
13
  description?: string;
15
- author: AuthorMetadata;
16
14
  variables?: VariableMetadataRecord;
17
15
  components?: ElementComponentMetadataRecord;
18
16
  tags: string[];
@@ -1,6 +1,5 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { ApiField, ArrayType, ComplexType } from '@opra/common';
3
- import { AuthorMetadata } from './author-metadata.js';
4
3
  import { VariableMetadataRecord } from './variable-metadata.js';
5
4
  /**
6
5
  *
@@ -14,17 +13,18 @@ let ElementMetadata = class ElementMetadata {
14
13
  };
15
14
  __decorate([
16
15
  ApiField({
17
- label: 'Class URI',
18
- description: 'URI of the class',
19
- examples: ['@syncbridge/net:TcpClient', '@syncbridge/sqb:SqbClient'],
16
+ label: 'Class Name',
17
+ description: 'Computer friendly class name',
18
+ required: true,
20
19
  }),
21
20
  __metadata("design:type", String)
22
- ], ElementMetadata.prototype, "uri", void 0);
21
+ ], ElementMetadata.prototype, "className", void 0);
23
22
  __decorate([
24
23
  ApiField({
25
24
  label: 'Version',
26
25
  description: 'Version of the class',
27
26
  examples: ['0.2.1', '2.1.5', '1.18.1-alpha.1'],
27
+ required: true,
28
28
  }),
29
29
  __metadata("design:type", String)
30
30
  ], ElementMetadata.prototype, "version", void 0);
@@ -50,13 +50,6 @@ __decorate([
50
50
  }),
51
51
  __metadata("design:type", String)
52
52
  ], ElementMetadata.prototype, "description", void 0);
53
- __decorate([
54
- ApiField({
55
- label: 'Author',
56
- description: 'Author',
57
- }),
58
- __metadata("design:type", AuthorMetadata)
59
- ], ElementMetadata.prototype, "author", void 0);
60
53
  __decorate([
61
54
  ApiField({
62
55
  label: 'Variables',
@@ -1,5 +1,6 @@
1
1
  import { ElementMetadata } from './element-metadata.js';
2
2
  export declare class ProcessorMetadata extends ElementMetadata {
3
3
  constructor(init?: Partial<ProcessorMetadata>);
4
+ classType: 'processor';
4
5
  staticEvents?: Record<string, string>;
5
6
  }
@@ -1,5 +1,5 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
- import { ComplexType } from '@opra/common';
2
+ import { ApiField, ComplexType } from '@opra/common';
3
3
  import { ElementMetadata } from './element-metadata.js';
4
4
  let ProcessorMetadata = class ProcessorMetadata extends ElementMetadata {
5
5
  constructor(init) {
@@ -7,6 +7,14 @@ let ProcessorMetadata = class ProcessorMetadata extends ElementMetadata {
7
7
  }
8
8
  staticEvents;
9
9
  };
10
+ __decorate([
11
+ ApiField({
12
+ label: 'Class Type',
13
+ description: 'Determines the type of the class',
14
+ fixed: 'processor',
15
+ }),
16
+ __metadata("design:type", String)
17
+ ], ProcessorMetadata.prototype, "classType", void 0);
10
18
  ProcessorMetadata = __decorate([
11
19
  ComplexType(),
12
20
  __metadata("design:paramtypes", [Object])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncbridge/common",
3
- "version": "0.12.6",
3
+ "version": "0.13.0",
4
4
  "description": "SyncBridge Common utilities",
5
5
  "author": "Panates Inc",
6
6
  "license": "MIT",
@@ -26,8 +26,6 @@ export declare abstract class ExtensionBase {
26
26
  readonly pkg: ExtensionPackage;
27
27
  readonly exportName: string;
28
28
  readonly metadata: ElementMetadata;
29
- readonly organization: string;
30
- readonly packageName: string;
31
29
  readonly className: string;
32
30
  protected constructor(pkg: ExtensionPackage, exportName: string, metadata: ElementMetadata, ctor?: Type<BaseElement>);
33
31
  get uri(): string;
@@ -21,22 +21,16 @@ export class ExtensionBase {
21
21
  pkg;
22
22
  exportName;
23
23
  metadata;
24
- organization;
25
- packageName;
26
24
  className;
27
25
  constructor(pkg, exportName, metadata, ctor) {
28
26
  this.pkg = pkg;
29
27
  this.exportName = exportName;
30
28
  this.metadata = metadata;
31
29
  this._ctor = ctor;
32
- const [pn, className] = metadata.uri.split(':');
33
- const [organization, packageName] = pn.split('/');
34
- this.className = className;
35
- this.organization = (organization || '').replace('@', '');
36
- this.packageName = packageName;
30
+ this.className = metadata.className;
37
31
  }
38
32
  get uri() {
39
- return this.metadata.uri;
33
+ return this.pkg.name + ':' + this.metadata.className;
40
34
  }
41
35
  get displayName() {
42
36
  return this.metadata.displayName;
@@ -31,12 +31,12 @@ export function materializeMetadataSilent(profile, options) {
31
31
  const stackExecutor = new StackExecutor();
32
32
  const processorRec = ExtensionRegistry.getProcessor(profile.processorUri);
33
33
  const metadata = omitUndefined(clone({
34
- uri: processorRec.metadata.uri,
34
+ classType: processorRec.metadata.classType,
35
+ className: processorRec.metadata.className,
35
36
  version: processorRec.version,
36
37
  displayName: processorRec.metadata.displayName,
37
38
  description: processorRec.metadata.description,
38
39
  iconUrl: processorRec.metadata.iconUrl,
39
- author: processorRec.metadata.author,
40
40
  tags: processorRec.metadata.tags,
41
41
  variables: processorRec.metadata.variables,
42
42
  components: processorRec.metadata.components,
@@ -24,11 +24,11 @@ export async function normalizeProcessorMetadata(metadata) {
24
24
  export async function normalizeProcessorMetadataSilent(metadata) {
25
25
  const decoder = await getProcMetadataTypeDecoder();
26
26
  let cloned = deepClone({
27
- uri: metadata.uri,
27
+ classType: 'processor',
28
+ className: metadata.className,
28
29
  displayName: metadata.displayName,
29
30
  description: metadata.description,
30
31
  iconUrl: metadata.iconUrl,
31
- author: metadata.author,
32
32
  tags: metadata.tags,
33
33
  abstract: metadata.abstract,
34
34
  variables: metadata.variables,
@@ -44,8 +44,10 @@ export async function normalizeProcessorMetadataSilent(metadata) {
44
44
  return {
45
45
  metadata: value || cloned,
46
46
  issues: errors?.map(x => ({
47
- ...x.issue,
47
+ message: x.message,
48
48
  severity: 'error',
49
+ location: x.location,
50
+ code: 'validation-error:' + x.rule,
49
51
  })),
50
52
  };
51
53
  }
@@ -69,11 +71,11 @@ export async function normalizeComponentMetadata(metadata) {
69
71
  export async function normalizeComponentMetadataSilent(metadata) {
70
72
  const decoder = await getCompMetadataTypeDecoder();
71
73
  let cloned = deepClone({
72
- uri: metadata.uri,
74
+ classType: 'component',
75
+ className: metadata.className,
73
76
  displayName: metadata.displayName,
74
77
  description: metadata.description,
75
78
  iconUrl: metadata.iconUrl,
76
- author: metadata.author,
77
79
  interfaces: metadata.interfaces,
78
80
  tags: metadata.tags,
79
81
  abstract: metadata.abstract,
@@ -90,8 +92,10 @@ export async function normalizeComponentMetadataSilent(metadata) {
90
92
  return {
91
93
  metadata: value || cloned,
92
94
  issues: errors?.map(x => ({
93
- ...x.issue,
95
+ message: x.message,
94
96
  severity: 'error',
97
+ location: x.location,
98
+ code: 'validation-error:' + x.rule,
95
99
  })),
96
100
  };
97
101
  }
@@ -1,8 +0,0 @@
1
- export declare class AuthorMetadata {
2
- constructor(init?: Partial<AuthorMetadata>);
3
- name?: string;
4
- email?: string;
5
- url?: string;
6
- logoUrl?: string;
7
- iconUrl?: string;
8
- }
@@ -1,48 +0,0 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import { ApiField, ComplexType } from '@opra/common';
3
- let AuthorMetadata = class AuthorMetadata {
4
- constructor(init) {
5
- if (init)
6
- Object.assign(this, init);
7
- }
8
- };
9
- __decorate([
10
- ApiField({
11
- label: 'Name',
12
- description: 'Name of the author. This is used to identify the author. ',
13
- }),
14
- __metadata("design:type", String)
15
- ], AuthorMetadata.prototype, "name", void 0);
16
- __decorate([
17
- ApiField({
18
- label: 'Email',
19
- description: 'Email of the author',
20
- }),
21
- __metadata("design:type", String)
22
- ], AuthorMetadata.prototype, "email", void 0);
23
- __decorate([
24
- ApiField({
25
- label: 'Url',
26
- description: 'Url of the author',
27
- }),
28
- __metadata("design:type", String)
29
- ], AuthorMetadata.prototype, "url", void 0);
30
- __decorate([
31
- ApiField({
32
- label: 'Logo Url',
33
- description: 'Url of the author logo. Dimensions should be 800x600, 400x300',
34
- }),
35
- __metadata("design:type", String)
36
- ], AuthorMetadata.prototype, "logoUrl", void 0);
37
- __decorate([
38
- ApiField({
39
- label: 'Logomark Url',
40
- description: 'Url of the author logomark. Dimensions should be square',
41
- }),
42
- __metadata("design:type", String)
43
- ], AuthorMetadata.prototype, "iconUrl", void 0);
44
- AuthorMetadata = __decorate([
45
- ComplexType(),
46
- __metadata("design:paramtypes", [Object])
47
- ], AuthorMetadata);
48
- export { AuthorMetadata };