@syncbridge/common 0.12.1 → 0.12.3

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.1';
1
+ export const version = '0.12.3';
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');
@@ -16,7 +16,6 @@ __decorate([
16
16
  ApiField({
17
17
  label: 'Level',
18
18
  description: 'Determines the log level',
19
- default: LogLevel.info,
20
19
  }),
21
20
  __metadata("design:type", String)
22
21
  ], LogOptions.prototype, "level", void 0);
@@ -45,7 +44,6 @@ __decorate([
45
44
  ApiField({
46
45
  label: 'Pipe To Main',
47
46
  description: 'Determines if logs will be piped to application terminal',
48
- default: true,
49
47
  }),
50
48
  __metadata("design:type", Boolean)
51
49
  ], ProfileLogOptions.prototype, "pipeToMain", void 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncbridge/common",
3
- "version": "0.12.1",
3
+ "version": "0.12.3",
4
4
  "description": "SyncBridge Common utilities",
5
5
  "author": "Panates Inc",
6
6
  "license": "MIT",
@@ -12,7 +12,7 @@
12
12
  "reflect-metadata": "^0.2.2",
13
13
  "semver": "^7.8.0",
14
14
  "ts-gems": "^3.12.0",
15
- "valgen": "^6.1.0"
15
+ "valgen": "^6.2.0"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "@opra/common": ">=1.17.1 <2"
@@ -7,8 +7,7 @@ import { StackExecutor } from './classes/stack-executor.js';
7
7
  import { ElementComponentMetadataRecord, ProcessorMetadata, Profile, ProfileComponentRecord, VariableMetadataRecord, } from './models/index.js';
8
8
  import { initializeModelsDocument } from './models-document.js';
9
9
  import { ExtensionRegistry } from './registry/extension-registry.js';
10
- import { decodeProfile } from './utils/decode-profile.js';
11
- import { materializeMetadataSilent } from './utils/materialize-metadata.js';
10
+ import { decodeProfileSilent } from './utils/decode-profile.js';
12
11
  export var ProcessorFactory;
13
12
  (function (ProcessorFactory) {
14
13
  ProcessorFactory.METADATA_KEY = Symbol('METADATA');
@@ -122,32 +121,31 @@ export var ProcessorFactory;
122
121
  }
123
122
  ProcessorFactory.updateProcessorSilent = updateProcessorSilent;
124
123
  async function _configureProcessor(ctx) {
125
- const r1 = materializeMetadataSilent(ctx.profile);
124
+ /* Decode profile */
125
+ const r1 = decodeProfileSilent(ctx.profile);
126
126
  if (!r1.result) {
127
127
  ctx.stackExecutor.issues.push(...r1.issues);
128
128
  return false;
129
129
  }
130
- /* Decode profile */
131
- const profile = decodeProfile(r1.metadata, ctx.profile);
132
- ctx.profile = profile;
130
+ ctx.profile = r1.profile;
133
131
  const oldMetadata = ctx.processor?.[ProcessorFactory.METADATA_KEY];
134
132
  const oldProfile = ctx.processor?.[ProcessorFactory.PROFILE_KEY];
135
133
  if (!ctx.processor) {
136
134
  /* Create new processor instance */
137
- const reg = ExtensionRegistry.getProcessor(profile.processorUri, profile.processorVersion);
135
+ const reg = ExtensionRegistry.getProcessor(r1.profile.processorUri, r1.profile.processorVersion);
138
136
  const processorClass = await reg.getClass();
139
137
  /* Create processor instance */
140
138
  ctx.processor = new processorClass({
141
- name: profile.displayName,
139
+ name: r1.profile.displayName,
142
140
  logger: ctx.options?.logger,
143
- values: profile.values ? clone(profile.values) : {},
141
+ values: r1.profile.values ? clone(r1.profile.values) : {},
144
142
  dataDirectory: ctx.options?.dataDirectory,
145
143
  });
146
144
  }
147
145
  else {
148
146
  /* Update values */
149
147
  if (!ctx.stackExecutor.execute('values', () => {
150
- _patchValues(ctx, ctx.processor, ctx.processor.values, '', profile.values, r1.metadata.variables || {}, oldProfile?.values, oldMetadata.variables);
148
+ _patchValues(ctx, ctx.processor, ctx.processor.values, '', r1.profile.values, r1.metadata.variables || {}, oldProfile?.values, oldMetadata.variables);
151
149
  })) {
152
150
  return false;
153
151
  }
@@ -157,7 +155,7 @@ export var ProcessorFactory;
157
155
  owner: ctx.processor,
158
156
  curPath: '',
159
157
  newMetadataComponents: r1.metadata.components,
160
- newProfileComponents: profile.components,
158
+ newProfileComponents: r1.profile.components,
161
159
  oldMetadataComponents: oldMetadata?.components,
162
160
  oldProfileComponents: oldProfile?.components,
163
161
  };
@@ -165,7 +163,7 @@ export var ProcessorFactory;
165
163
  return false;
166
164
  }
167
165
  ctx.processor[ProcessorFactory.METADATA_KEY] = r1.metadata;
168
- ctx.processor[ProcessorFactory.PROFILE_KEY] = profile;
166
+ ctx.processor[ProcessorFactory.PROFILE_KEY] = r1.profile;
169
167
  return true;
170
168
  }
171
169
  function _validateComponents(ctx) {
@@ -7,19 +7,28 @@ export interface CodecOptions {
7
7
  /**
8
8
  * Decodes profile
9
9
  */
10
- export declare function decodeProfile(materializedMetadata: ProcessorMetadata, rawProfile: Profile, options?: CodecOptions): Profile;
11
- export declare function decodeProfileSilent(materializedMetadata: ProcessorMetadata, rawProfile: Profile, options?: CodecOptions): {
10
+ export declare function decodeProfile(profile: Profile, options?: CodecOptions): Profile;
11
+ export declare function decodeProfileSilent(profile: Profile, options?: CodecOptions): {
12
+ result: true;
12
13
  profile: Profile;
14
+ metadata: ProcessorMetadata;
13
15
  issues?: StackExecutor.Issue[];
16
+ } | {
17
+ result: false;
18
+ issues: StackExecutor.Issue[];
14
19
  };
15
20
  /**
16
21
  * Encodes profile
17
22
  */
18
- export declare function encodeProfile(materializedMetadata: ProcessorMetadata, rawProfile: Profile, options?: CodecOptions): Profile;
23
+ export declare function encodeProfile(rawProfile: Profile, options?: CodecOptions): Profile;
19
24
  /**
20
25
  * Encodes profile
21
26
  */
22
- export declare function encodeProfileSilent(metadata: ProcessorMetadata, rawProfile: Profile, options?: CodecOptions): {
27
+ export declare function encodeProfileSilent(profile: Profile, options?: CodecOptions): {
28
+ result: true;
23
29
  profile: Profile;
24
30
  issues?: StackExecutor.Issue[];
31
+ } | {
32
+ result: false;
33
+ issues: StackExecutor.Issue[];
25
34
  };
@@ -4,82 +4,102 @@ import { StackExecutor } from '../classes/stack-executor.js';
4
4
  import { ElementComponentMetadata, ProcessorMetadata, Profile, ProfileComponent, VariableMetadataRecord, VariableType, } from '../models/index.js';
5
5
  import { getModelsDocument } from '../models-document.js';
6
6
  import { secretDecryptor, secretEncryptor } from './encrypt-helpers.js';
7
+ import { materializeMetadataSilent } from './materialize-metadata.js';
7
8
  /**
8
9
  * Decodes profile
9
10
  */
10
- export function decodeProfile(materializedMetadata, rawProfile, options) {
11
- const { profile: out, issues } = decodeProfileSilent(materializedMetadata, rawProfile, options);
12
- if (issues?.length) {
11
+ export function decodeProfile(profile, options) {
12
+ const r1 = decodeProfileSilent(profile, options);
13
+ if (!r1.result) {
13
14
  const msg = 'Worker profile decoding error.\n ' +
14
- issues
15
+ r1.issues
15
16
  .map(issue => `- ${issue.message}. Location: /${issue.location}`)
16
17
  .join('\n ');
17
- issues.forEach(issue => {
18
+ r1.issues.forEach(issue => {
18
19
  if (issue instanceof SbValidationError)
19
20
  delete issue.stack;
20
21
  });
21
22
  throw new SbValidationError(msg, {
22
- workerId: rawProfile.id,
23
- issues,
23
+ workerId: profile.id,
24
+ issues: r1.issues,
24
25
  });
25
26
  }
26
- return out;
27
+ return r1.profile;
27
28
  }
28
- export function decodeProfileSilent(materializedMetadata, rawProfile, options) {
29
+ export function decodeProfileSilent(profile, options) {
29
30
  const modelsDocument = getModelsDocument();
31
+ const r1 = materializeMetadataSilent(profile);
32
+ if (!r1.result) {
33
+ return { result: false, issues: r1.issues };
34
+ }
30
35
  const t = modelsDocument.node.getComplexType(Profile);
31
36
  const fn = t.generateCodec('decode');
32
- const out = fn(rawProfile);
37
+ const out = fn(profile);
33
38
  const stackExecutor = new StackExecutor();
34
- _codecProcessElement(stackExecutor, 'decode', materializedMetadata, out, options);
35
- return { profile: out, issues: stackExecutor.issues };
39
+ _codecProcessElement(stackExecutor, 'decode', r1.metadata, out, options);
40
+ if (stackExecutor.issues.find(i => !(i.severity === 'warning' || i.severity === 'info'))) {
41
+ return { result: false, issues: stackExecutor.issues };
42
+ }
43
+ return {
44
+ result: true,
45
+ profile: out,
46
+ metadata: r1.metadata,
47
+ issues: stackExecutor.issues,
48
+ };
36
49
  }
37
50
  /**
38
51
  * Encodes profile
39
52
  */
40
- export function encodeProfile(materializedMetadata, rawProfile, options) {
41
- const { profile: out, issues } = encodeProfileSilent(materializedMetadata, rawProfile, options);
42
- if (issues?.length) {
53
+ export function encodeProfile(rawProfile, options) {
54
+ const r1 = encodeProfileSilent(rawProfile, options);
55
+ if (!r1.result) {
43
56
  const msg = 'Worker profile encoding error.\n ' +
44
- issues
57
+ r1.issues
45
58
  .map(issue => `- ${issue.message}. Location: /${issue.location}`)
46
59
  .join('\n ');
47
- issues.forEach(issue => {
60
+ r1.issues.forEach(issue => {
48
61
  if (issue instanceof SbValidationError)
49
62
  delete issue.stack;
50
63
  });
51
64
  throw new SbValidationError(msg, {
52
65
  workerId: rawProfile.id,
53
- issues,
66
+ issues: r1.issues,
54
67
  });
55
68
  }
56
- return out;
69
+ return r1.profile;
57
70
  }
58
71
  /**
59
72
  * Encodes profile
60
73
  */
61
- export function encodeProfileSilent(metadata, rawProfile, options) {
74
+ export function encodeProfileSilent(profile, options) {
62
75
  const modelsDocument = getModelsDocument();
76
+ const r1 = materializeMetadataSilent(profile);
77
+ if (!r1.result) {
78
+ return { result: false, issues: r1.issues };
79
+ }
63
80
  const t = modelsDocument.node.getComplexType(Profile);
64
81
  const fn = t.generateCodec('encode', { coerce: true });
65
82
  const out = fn({
66
- id: rawProfile.id,
67
- processorUri: rawProfile.processorUri,
68
- displayName: rawProfile.displayName,
69
- group: rawProfile.group,
70
- description: rawProfile.description,
71
- iconUrl: rawProfile.iconUrl,
83
+ id: profile.id,
84
+ processorUri: profile.processorUri,
85
+ displayName: profile.displayName,
86
+ group: profile.group,
87
+ description: profile.description,
88
+ iconUrl: profile.iconUrl,
72
89
  settings: {
73
- autostart: rawProfile.settings?.autostart ?? false,
74
- logs: rawProfile.settings?.logs ?? {},
75
- ...rawProfile.settings,
90
+ autostart: profile.settings?.autostart ?? false,
91
+ logs: profile.settings?.logs ?? {},
92
+ ...profile.settings,
76
93
  },
77
- values: rawProfile.values,
78
- ...rawProfile,
94
+ values: profile.values,
95
+ ...profile,
79
96
  });
80
97
  const stackExecutor = new StackExecutor();
81
- _codecProcessElement(stackExecutor, 'encode', metadata, out, options);
82
- return { profile: out, issues: stackExecutor.issues };
98
+ _codecProcessElement(stackExecutor, 'encode', r1.metadata, out, options);
99
+ if (stackExecutor.issues.find(i => !(i.severity === 'warning' || i.severity === 'info'))) {
100
+ return { result: false, issues: stackExecutor.issues };
101
+ }
102
+ return { result: true, profile: out, issues: stackExecutor.issues };
83
103
  }
84
104
  /**
85
105
  *
@@ -130,6 +150,11 @@ function _decodeVariables(stackExecutor, codec, metadata, profile, options) {
130
150
  if (defVariable == null)
131
151
  return;
132
152
  const fns = [];
153
+ if (defVariable.ignored) {
154
+ if (defVariable.default === undefined)
155
+ return;
156
+ fns.push(vg.fixed(defVariable.default));
157
+ }
133
158
  switch (defVariable.type) {
134
159
  case VariableType.String: {
135
160
  switch (defVariable.format) {
@@ -3,11 +3,17 @@ import { ProcessorMetadata, Profile } from '../models/index.js';
3
3
  /**
4
4
  * Materializes metadata from profile.
5
5
  */
6
- export declare function materializeMetadata(profile: Profile, returnUndefinedComponentsAsAbstract?: boolean): ProcessorMetadata;
6
+ export declare function materializeMetadata(profile: Profile, options?: {
7
+ returnUndefinedComponentsAsAbstract?: boolean;
8
+ removeIgnoredVariables?: boolean;
9
+ }): ProcessorMetadata;
7
10
  /**
8
11
  *
9
12
  */
10
- export declare function materializeMetadataSilent(profile: Profile, returnUndefinedComponentsAsAbstract?: boolean): {
13
+ export declare function materializeMetadataSilent(profile: Profile, options?: {
14
+ returnUndefinedComponentsAsAbstract?: boolean;
15
+ removeIgnoredVariables?: boolean;
16
+ }): {
11
17
  result: true;
12
18
  metadata: ProcessorMetadata;
13
19
  issues: StackExecutor.Issue[];
@@ -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, returnUndefinedComponentsAsAbstract) {
10
- const r = materializeMetadataSilent(profile, returnUndefinedComponentsAsAbstract);
9
+ export function materializeMetadata(profile, options) {
10
+ const r = materializeMetadataSilent(profile, options);
11
11
  if (!r.result) {
12
12
  const msg = 'Worker profile validation error.\n ' +
13
13
  r.issues
@@ -27,7 +27,7 @@ export function materializeMetadata(profile, returnUndefinedComponentsAsAbstract
27
27
  /**
28
28
  *
29
29
  */
30
- export function materializeMetadataSilent(profile, returnUndefinedComponentsAsAbstract) {
30
+ 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({
@@ -42,9 +42,15 @@ export function materializeMetadataSilent(profile, returnUndefinedComponentsAsAb
42
42
  components: processorRec.metadata.components,
43
43
  ...processorRec.metadata,
44
44
  }, { deep: 'full' }));
45
+ /* Remove ignored variables */
46
+ for (const [k, variable] of Object.entries(metadata.variables)) {
47
+ if (variable.ignored && options?.removeIgnoredVariables)
48
+ delete metadata.variables[k];
49
+ }
50
+ /* Materialize components */
45
51
  if (metadata.components) {
46
52
  stackExecutor.execute('components', () => {
47
- metadata.components = _materializeComponents(stackExecutor, metadata.components, profile, returnUndefinedComponentsAsAbstract);
53
+ metadata.components = _materializeComponents(stackExecutor, metadata.components, profile, options);
48
54
  });
49
55
  }
50
56
  if (stackExecutor.issues?.length)
@@ -55,7 +61,7 @@ export function materializeMetadataSilent(profile, returnUndefinedComponentsAsAb
55
61
  *
56
62
  * @private
57
63
  */
58
- function _materializeComponents(stackExecutor, srcMetadata, profile, returnUndefinedComponentsAsAbstract) {
64
+ function _materializeComponents(stackExecutor, srcMetadata, profile, options) {
59
65
  const out = {};
60
66
  for (const [componentName, metadataComponent,] of Object.entries(srcMetadata)) {
61
67
  stackExecutor.execute(componentName, () => {
@@ -63,7 +69,7 @@ function _materializeComponents(stackExecutor, srcMetadata, profile, returnUndef
63
69
  let materializedComponent;
64
70
  const profileComponent = profile?.components?.[componentName];
65
71
  if (!profileComponent) {
66
- if (!returnUndefinedComponentsAsAbstract) {
72
+ if (!options?.returnUndefinedComponentsAsAbstract) {
67
73
  if (metadataComponent.required)
68
74
  throw new SbValidationError(`Component "${componentName}" should be configured`);
69
75
  return;
@@ -96,12 +102,12 @@ function _materializeComponents(stackExecutor, srcMetadata, profile, returnUndef
96
102
  out[componentName] = materializedComponent;
97
103
  /** Remove ignored variables */
98
104
  for (const [k, variable] of Object.entries(materializedComponent.variables)) {
99
- if (variable.ignored)
105
+ if (variable.ignored && options?.removeIgnoredVariables)
100
106
  delete materializedComponent.variables[k];
101
107
  }
102
108
  if (reg.metadata.components) {
103
109
  stackExecutor.execute('components', () => {
104
- materializedComponent.components = _materializeComponents(stackExecutor, reg.metadata.components, profileComponent, returnUndefinedComponentsAsAbstract);
110
+ materializedComponent.components = _materializeComponents(stackExecutor, reg.metadata.components, profileComponent, options);
105
111
  });
106
112
  }
107
113
  }