@syncbridge/common 0.7.1 → 0.7.2

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.7.1';
1
+ export const version = '0.7.2';
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,6 +4,7 @@ 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';
7
8
  import { defineOwnMetadata, parseNpmAuthor } from './decorator-helpers.js';
8
9
  import { UseComponent as _UseComponent } from './use-component.decorator.js';
9
10
  import { UseVariables as _UseVariables } from './use-variables.decorator.js';
@@ -33,11 +34,7 @@ export function Component(options) {
33
34
  Reflect.defineMetadata(CLASS_TYPE, 'component', target);
34
35
  const packageName = pkgjson.syncbridge?.name || pkgjson.name;
35
36
  const uri = packageName + ':' + className;
36
- const id = uri
37
- .replace('@', '')
38
- .replace(':', '__')
39
- .replace(/\W/g, '_')
40
- .toLowerCase();
37
+ const id = uriToId(uri);
41
38
  const metadata = defineOwnMetadata(target, CLASS_METADATA, {
42
39
  mergeBase: true,
43
40
  overwrite: {
@@ -4,6 +4,7 @@ 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';
7
8
  import { defineOwnMetadata } from './decorator-helpers.js';
8
9
  import { OnCreateProfile as _OnCreateProfile, OnUpdateProfile as _OnUpdateProfile, } from './processor-events.decorator.js';
9
10
  import { UseComponent as _UseComponent } from './use-component.decorator.js';
@@ -34,11 +35,7 @@ export function Processor(options) {
34
35
  Reflect.defineMetadata(CLASS_TYPE, 'processor', target);
35
36
  const packageName = pkgjson.syncbridge?.name || pkgjson.name;
36
37
  const uri = packageName + ':' + className;
37
- const id = uri
38
- .replace('@', '')
39
- .replace(':', '__')
40
- .replace(/\W/g, '_')
41
- .toLowerCase();
38
+ const id = uriToId(uri);
42
39
  defineOwnMetadata(target, CLASS_METADATA, {
43
40
  mergeBase: true,
44
41
  overwrite: {
package/index.d.ts CHANGED
@@ -20,3 +20,4 @@ export * from './utils/decode-profile.js';
20
20
  export * from './utils/materialize-metadata.js';
21
21
  export * from './utils/normalize-metadata.js';
22
22
  export * from './utils/type-guartds.js';
23
+ export * from './utils/uri-to-id.js';
package/index.js CHANGED
@@ -20,3 +20,4 @@ export * from './utils/decode-profile.js';
20
20
  export * from './utils/materialize-metadata.js';
21
21
  export * from './utils/normalize-metadata.js';
22
22
  export * from './utils/type-guartds.js';
23
+ export * from './utils/uri-to-id.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncbridge/common",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "SyncBridge Common utilities",
5
5
  "author": "Panates Inc",
6
6
  "license": "MIT",
@@ -3,6 +3,7 @@ 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';
6
7
  export async function normalizeProcessorMetadata(metadata) {
7
8
  const { metadata: out, issues } = await normalizeProcessorMetadataSilent(metadata);
8
9
  if (issues?.length) {
@@ -23,7 +24,7 @@ export async function normalizeProcessorMetadata(metadata) {
23
24
  export async function normalizeProcessorMetadataSilent(metadata) {
24
25
  const decoder = await getProcMetadataTypeDecoder();
25
26
  let cloned = deepClone({
26
- id: metadata.id,
27
+ id: metadata.id || uriToId(metadata.uri),
27
28
  uri: metadata.uri,
28
29
  displayName: metadata.displayName,
29
30
  description: metadata.description,
@@ -68,7 +69,7 @@ export async function normalizeComponentMetadata(metadata) {
68
69
  export async function normalizeComponentMetadataSilent(metadata) {
69
70
  const decoder = await getCompMetadataTypeDecoder();
70
71
  let cloned = deepClone({
71
- id: metadata.id,
72
+ id: metadata.id || uriToId(metadata.uri),
72
73
  uri: metadata.uri,
73
74
  displayName: metadata.displayName,
74
75
  description: metadata.description,
@@ -0,0 +1 @@
1
+ export declare function uriToId(uri: string): string;
@@ -0,0 +1,7 @@
1
+ export function uriToId(uri) {
2
+ return uri
3
+ .replace('@', '')
4
+ .replace(':', '__')
5
+ .replace(/\W/g, '_')
6
+ .toLowerCase();
7
+ }