@syncbridge/common 0.5.8 → 0.5.10
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/component-base.js +2 -0
- package/classes/processor-base.js +2 -0
- package/classes/runnable.js +2 -0
- package/constants.js +1 -1
- package/decorators/use-variables.decorator.js +3 -4
- package/interfaces/logger.interface.d.ts +1 -1
- package/package.json +3 -3
- package/processor-factory.d.ts +6 -2
- package/processor-factory.js +6 -2
- package/registry/extension-package.d.ts +4 -4
- package/registry/extension-package.js +23 -48
- package/registry/extension-registry.d.ts +9 -9
- package/registry/extension-registry.js +6 -68
- package/registry/helpers.d.ts +3 -0
- package/registry/helpers.js +102 -0
- package/utils/type-guartds.d.ts +6 -0
- package/utils/type-guartds.js +15 -0
package/classes/runnable.js
CHANGED
package/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const version = '0.5.
|
|
1
|
+
export const version = '0.5.10';
|
|
2
2
|
export const OWN_ELEMENT_METADATA = Symbol.for('OWN_ELEMENT_METADATA');
|
|
3
3
|
export const COMPONENT_OPTIONS = Symbol.for('COMPONENT_OPTIONS');
|
|
4
4
|
export const PROCESSOR_OPTIONS = Symbol.for('PROCESSOR_OPTIONS');
|
|
@@ -8,11 +8,10 @@ export function UseVariables(variablesClass) {
|
|
|
8
8
|
throw new TypeError('Property key must be "values"');
|
|
9
9
|
variablesClass =
|
|
10
10
|
variablesClass || Reflect.getMetadata('design:type', target, propertyKey);
|
|
11
|
-
if (!(typeof variablesClass === 'function'
|
|
12
|
-
|
|
13
|
-
throw new TypeError('Variables class must be decorated with @DefineVariable');
|
|
11
|
+
if (!(typeof variablesClass === 'function')) {
|
|
12
|
+
throw new TypeError('type of "variables" must be a class');
|
|
14
13
|
}
|
|
15
|
-
const metadata = Reflect.getMetadata(VARIABLE_CONTAINER, variablesClass.prototype);
|
|
14
|
+
const metadata = Reflect.getMetadata(VARIABLE_CONTAINER, variablesClass.prototype) || {};
|
|
16
15
|
defineMergeMetadata(target.constructor, OWN_ELEMENT_METADATA, {
|
|
17
16
|
variables: metadata,
|
|
18
17
|
});
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncbridge/common",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.10",
|
|
4
4
|
"description": "SyncBridge Common utilities",
|
|
5
5
|
"author": "Panates Inc",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@jsopen/objects": "^2.
|
|
8
|
+
"@jsopen/objects": "^2.1.1",
|
|
9
9
|
"node-events-async": "^1.5.0",
|
|
10
10
|
"reflect-metadata": "^0.2.2",
|
|
11
|
-
"semver": "^7.7.
|
|
11
|
+
"semver": "^7.7.4",
|
|
12
12
|
"ts-gems": "^3.11.3",
|
|
13
13
|
"valgen": "^5.19.4"
|
|
14
14
|
},
|
package/processor-factory.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ProcessorBase } from './classes/processor-base.js';
|
|
2
|
+
import { StackExecutor } from './classes/stack-executor.js';
|
|
2
3
|
import { ILogger } from './interfaces/index.js';
|
|
3
4
|
import { Profile } from './models/index.js';
|
|
4
5
|
export declare namespace ProcessorFactory {
|
|
@@ -8,6 +9,9 @@ export declare namespace ProcessorFactory {
|
|
|
8
9
|
logger: ILogger;
|
|
9
10
|
dataDirectory?: string;
|
|
10
11
|
}
|
|
11
|
-
function createProcessor<T extends ProcessorBase>(profile: Profile, options?: ProcessorOptions): Promise<
|
|
12
|
-
|
|
12
|
+
function createProcessor<T extends ProcessorBase>(profile: Profile, options?: ProcessorOptions): Promise<{
|
|
13
|
+
processor: T;
|
|
14
|
+
issues: StackExecutor.Issue[];
|
|
15
|
+
}>;
|
|
16
|
+
function updateProcessor(processor: ProcessorBase, profile: Profile, options?: ProcessorOptions): Promise<StackExecutor.Issue[]>;
|
|
13
17
|
}
|
package/processor-factory.js
CHANGED
|
@@ -16,8 +16,11 @@ export var ProcessorFactory;
|
|
|
16
16
|
values: profile.values || {},
|
|
17
17
|
dataDirectory: options?.dataDirectory,
|
|
18
18
|
});
|
|
19
|
-
await _configureProcessor(processor, profile);
|
|
20
|
-
return
|
|
19
|
+
const issues = await _configureProcessor(processor, profile);
|
|
20
|
+
return {
|
|
21
|
+
processor: processor,
|
|
22
|
+
issues,
|
|
23
|
+
};
|
|
21
24
|
}
|
|
22
25
|
ProcessorFactory.createProcessor = createProcessor;
|
|
23
26
|
async function updateProcessor(processor, profile, options) {
|
|
@@ -88,5 +91,6 @@ export var ProcessorFactory;
|
|
|
88
91
|
await configureComponents(processor, '', processorMetadata, profile, processor[ProcessorFactory.METADATA_KEY], processor[ProcessorFactory.PROFILE_KEY]);
|
|
89
92
|
processor[ProcessorFactory.METADATA_KEY] = processorMetadata;
|
|
90
93
|
processor[ProcessorFactory.PROFILE_KEY] = profile;
|
|
94
|
+
return stackExecutor.issues;
|
|
91
95
|
}
|
|
92
96
|
})(ProcessorFactory || (ProcessorFactory = {}));
|
|
@@ -12,8 +12,8 @@ export declare class ExtensionPackage {
|
|
|
12
12
|
version: string;
|
|
13
13
|
description: string;
|
|
14
14
|
entryPoint: string;
|
|
15
|
-
components:
|
|
16
|
-
processors:
|
|
15
|
+
components: ComponentExtension[];
|
|
16
|
+
processors: ProcessorExtension[];
|
|
17
17
|
errors: Error[];
|
|
18
18
|
sortVersions(): void;
|
|
19
19
|
/**
|
|
@@ -27,7 +27,7 @@ export declare class ExtensionPackage {
|
|
|
27
27
|
/**
|
|
28
28
|
*
|
|
29
29
|
*/
|
|
30
|
-
export declare class
|
|
30
|
+
export declare class ComponentExtension {
|
|
31
31
|
readonly pkg: ExtensionPackage;
|
|
32
32
|
readonly exportName: string;
|
|
33
33
|
readonly metadata: ComponentMetadata;
|
|
@@ -41,7 +41,7 @@ export declare class ExtensionPackageComponent {
|
|
|
41
41
|
/**
|
|
42
42
|
*
|
|
43
43
|
*/
|
|
44
|
-
export declare class
|
|
44
|
+
export declare class ProcessorExtension {
|
|
45
45
|
readonly pkg: ExtensionPackage;
|
|
46
46
|
readonly exportName: string;
|
|
47
47
|
readonly metadata: ProcessorMetadata;
|
|
@@ -3,34 +3,10 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import process from 'node:process';
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
|
-
import {
|
|
7
|
-
import { ProcessorBase } from '../classes/processor-base.js';
|
|
6
|
+
import { updateErrorMessage } from '@jsopen/objects';
|
|
8
7
|
import { COMPONENT_OPTIONS, PROCESSOR_OPTIONS } from '../constants.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { resolvePromisesDeep } from '../utils/resolve-promises.js';
|
|
12
|
-
let _compMetadataTypeDecoder;
|
|
13
|
-
let _procMetadataTypeDecoder;
|
|
14
|
-
async function getCompMetadataTypeDecoder() {
|
|
15
|
-
if (!_compMetadataTypeDecoder) {
|
|
16
|
-
const apiDoc = await initializeModelsDocument();
|
|
17
|
-
const compMetadataType = apiDoc.node.getComplexType(ComponentMetadata);
|
|
18
|
-
_compMetadataTypeDecoder = compMetadataType.generateCodec('decode', {
|
|
19
|
-
coerce: true,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return _compMetadataTypeDecoder;
|
|
23
|
-
}
|
|
24
|
-
async function getProcMetadataTypeDecoder() {
|
|
25
|
-
if (!_procMetadataTypeDecoder) {
|
|
26
|
-
const apiDoc = await initializeModelsDocument();
|
|
27
|
-
const procMetadataType = apiDoc.node.getComplexType(ProcessorMetadata);
|
|
28
|
-
_procMetadataTypeDecoder = procMetadataType.generateCodec('decode', {
|
|
29
|
-
coerce: true,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return _procMetadataTypeDecoder;
|
|
33
|
-
}
|
|
8
|
+
import { isComponentBase, isProcessorBase } from '../utils/type-guartds.js';
|
|
9
|
+
import { normalizeComponentMetadata, normalizeProcessorMetadata, } from './helpers.js';
|
|
34
10
|
/**
|
|
35
11
|
*
|
|
36
12
|
*/
|
|
@@ -48,7 +24,6 @@ export class ExtensionPackage {
|
|
|
48
24
|
* @static
|
|
49
25
|
*/
|
|
50
26
|
static async fromDirectory(directory) {
|
|
51
|
-
const compMetadataTypeDecoder = await getCompMetadataTypeDecoder();
|
|
52
27
|
let filename = path.join(directory, 'package.json');
|
|
53
28
|
if (!fs.existsSync(filename))
|
|
54
29
|
throw new TypeError(`Directory "${directory}" does not contain package.json`);
|
|
@@ -76,16 +51,17 @@ export class ExtensionPackage {
|
|
|
76
51
|
continue;
|
|
77
52
|
}
|
|
78
53
|
try {
|
|
79
|
-
metadata =
|
|
54
|
+
metadata = await normalizeComponentMetadata(metadata);
|
|
80
55
|
}
|
|
81
56
|
catch (e) {
|
|
82
|
-
|
|
57
|
+
updateErrorMessage(e, `Component (${ctorName}) metadata validation error. ` + e.message);
|
|
58
|
+
out.errors.push(e);
|
|
83
59
|
continue;
|
|
84
60
|
}
|
|
85
61
|
if (metadata.abstract)
|
|
86
62
|
continue;
|
|
87
63
|
out.components = out.components || [];
|
|
88
|
-
out.components.push(new
|
|
64
|
+
out.components.push(new ComponentExtension(out, ctorName, metadata));
|
|
89
65
|
}
|
|
90
66
|
}
|
|
91
67
|
if (pkgJson.syncbridge.processors) {
|
|
@@ -103,24 +79,23 @@ export class ExtensionPackage {
|
|
|
103
79
|
continue;
|
|
104
80
|
}
|
|
105
81
|
try {
|
|
106
|
-
metadata =
|
|
82
|
+
metadata = await normalizeProcessorMetadata(metadata);
|
|
107
83
|
}
|
|
108
84
|
catch (e) {
|
|
109
|
-
|
|
85
|
+
updateErrorMessage(e, `Processor (${ctorName}) metadata validation error. ` + e.message);
|
|
86
|
+
out.errors.push(e);
|
|
110
87
|
continue;
|
|
111
88
|
}
|
|
112
89
|
if (metadata.abstract)
|
|
113
90
|
continue;
|
|
114
91
|
out.processors = out.processors || [];
|
|
115
|
-
out.processors.push(new
|
|
92
|
+
out.processors.push(new ProcessorExtension(out, ctorName, metadata));
|
|
116
93
|
}
|
|
117
94
|
}
|
|
118
95
|
out.sortVersions();
|
|
119
96
|
return out;
|
|
120
97
|
}
|
|
121
98
|
static async fromNodePackage(specifier, resolver) {
|
|
122
|
-
const compMetadataTypeDecoder = await getCompMetadataTypeDecoder();
|
|
123
|
-
const procMetadataTypeDecoder = await getProcMetadataTypeDecoder();
|
|
124
99
|
// const resolver = createRequire(parentPath || import.meta.url).resolve;
|
|
125
100
|
let entryPoint = (resolver || import.meta.resolve)(specifier);
|
|
126
101
|
const pkgJson = locatePkgJson(path.dirname(entryPoint));
|
|
@@ -141,33 +116,33 @@ export class ExtensionPackage {
|
|
|
141
116
|
continue;
|
|
142
117
|
let metadata = Reflect.getMetadata(COMPONENT_OPTIONS, v);
|
|
143
118
|
if (metadata) {
|
|
144
|
-
metadata = await resolvePromisesDeep(metadata);
|
|
145
119
|
try {
|
|
146
|
-
metadata =
|
|
120
|
+
metadata = await normalizeComponentMetadata(metadata);
|
|
147
121
|
}
|
|
148
122
|
catch (e) {
|
|
149
|
-
|
|
123
|
+
updateErrorMessage(e, `Component (${ctorName}) metadata validation error. ` + e.message);
|
|
124
|
+
out.errors.push(e);
|
|
150
125
|
continue;
|
|
151
126
|
}
|
|
152
127
|
if (metadata.abstract)
|
|
153
128
|
continue;
|
|
154
129
|
out.components = out.components || [];
|
|
155
|
-
out.components.push(new
|
|
130
|
+
out.components.push(new ComponentExtension(out, ctorName, metadata));
|
|
156
131
|
}
|
|
157
132
|
metadata = Reflect.getMetadata(PROCESSOR_OPTIONS, v);
|
|
158
133
|
if (metadata) {
|
|
159
|
-
metadata = await resolvePromisesDeep(metadata);
|
|
160
134
|
try {
|
|
161
|
-
metadata =
|
|
135
|
+
metadata = await normalizeProcessorMetadata(metadata);
|
|
162
136
|
}
|
|
163
137
|
catch (e) {
|
|
164
|
-
|
|
138
|
+
updateErrorMessage(e, `Processor (${ctorName}) metadata validation error. ` + e.message);
|
|
139
|
+
out.errors.push(e);
|
|
165
140
|
continue;
|
|
166
141
|
}
|
|
167
142
|
if (metadata.abstract)
|
|
168
143
|
continue;
|
|
169
144
|
out.processors = out.processors || [];
|
|
170
|
-
out.processors.push(new
|
|
145
|
+
out.processors.push(new ProcessorExtension(out, ctorName, metadata));
|
|
171
146
|
}
|
|
172
147
|
}
|
|
173
148
|
out.sortVersions();
|
|
@@ -177,7 +152,7 @@ export class ExtensionPackage {
|
|
|
177
152
|
/**
|
|
178
153
|
*
|
|
179
154
|
*/
|
|
180
|
-
export class
|
|
155
|
+
export class ComponentExtension {
|
|
181
156
|
pkg;
|
|
182
157
|
exportName;
|
|
183
158
|
metadata;
|
|
@@ -206,7 +181,7 @@ export class ExtensionPackageComponent {
|
|
|
206
181
|
throw new TypeError(`Exported component "${this.exportName}" not found in package "${this.pkg.name}"`);
|
|
207
182
|
if (typeof ctor !== 'function')
|
|
208
183
|
throw new TypeError(`Exported component "${this.exportName}" is not a class`);
|
|
209
|
-
if (!(ctor.prototype
|
|
184
|
+
if (!isComponentBase(ctor.prototype))
|
|
210
185
|
throw new TypeError(`Exported component "${this.exportName}" does not extends ComponentBase`);
|
|
211
186
|
this._ctor = ctor;
|
|
212
187
|
return this._ctor;
|
|
@@ -215,7 +190,7 @@ export class ExtensionPackageComponent {
|
|
|
215
190
|
/**
|
|
216
191
|
*
|
|
217
192
|
*/
|
|
218
|
-
export class
|
|
193
|
+
export class ProcessorExtension {
|
|
219
194
|
pkg;
|
|
220
195
|
exportName;
|
|
221
196
|
metadata;
|
|
@@ -244,7 +219,7 @@ export class ExtensionPackageProcessor {
|
|
|
244
219
|
throw new TypeError(`Exported processor "${this.exportName}" not found in package "${this.pkg.name}"`);
|
|
245
220
|
if (typeof ctor !== 'function')
|
|
246
221
|
throw new TypeError(`Exported processor "${this.exportName}" is not a class`);
|
|
247
|
-
if (!(ctor.prototype
|
|
222
|
+
if (!isProcessorBase(ctor.prototype))
|
|
248
223
|
throw new TypeError(`Exported processor "${this.exportName}" does not extends ProcessorBase`);
|
|
249
224
|
this._ctor = ctor;
|
|
250
225
|
return this._ctor;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { URL } from 'node:url';
|
|
2
2
|
import { Type } from 'ts-gems';
|
|
3
|
-
import {
|
|
3
|
+
import { ComponentExtension, ExtensionPackage, ProcessorExtension } from './extension-package.js';
|
|
4
4
|
export declare namespace ExtensionRegistry {
|
|
5
5
|
type Resolver = (specifier: string, parent?: string | URL) => string;
|
|
6
6
|
const packages: Map<string, ExtensionPackage[]>;
|
|
7
|
-
const components: Map<string,
|
|
8
|
-
const processors: Map<string,
|
|
7
|
+
const components: Map<string, ComponentExtension[]>;
|
|
8
|
+
const processors: Map<string, ProcessorExtension[]>;
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
|
-
function findComponent(className: string, version?: string):
|
|
12
|
+
function findComponent(className: string, version?: string): ComponentExtension | undefined;
|
|
13
13
|
/**
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
|
-
function getComponent(className: string, version?: string):
|
|
16
|
+
function getComponent(className: string, version?: string): ComponentExtension;
|
|
17
17
|
/**
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
-
function findProcessor(className: string, version?: string):
|
|
20
|
+
function findProcessor(className: string, version?: string): ProcessorExtension | undefined;
|
|
21
21
|
/**
|
|
22
22
|
*
|
|
23
23
|
*/
|
|
24
|
-
function getProcessor(className: string, version?: string):
|
|
24
|
+
function getProcessor(className: string, version?: string): ProcessorExtension;
|
|
25
25
|
/**
|
|
26
26
|
*
|
|
27
27
|
*/
|
|
@@ -34,6 +34,6 @@ export declare namespace ExtensionRegistry {
|
|
|
34
34
|
*
|
|
35
35
|
*/
|
|
36
36
|
function registerNodePackage(specifier: string): Promise<ExtensionPackage>;
|
|
37
|
-
function registerComponent(ctor: Type): Promise<
|
|
38
|
-
function registerProcessor(ctor: Type): Promise<
|
|
37
|
+
function registerComponent(ctor: Type): Promise<ComponentExtension | undefined>;
|
|
38
|
+
function registerProcessor(ctor: Type): Promise<ProcessorExtension | undefined>;
|
|
39
39
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { deepClone } from '@jsopen/objects';
|
|
2
1
|
import semver from 'semver';
|
|
3
2
|
import { COMPONENT_OPTIONS, PROCESSOR_OPTIONS } from '../constants.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { ComponentExtension, ExtensionPackage, ProcessorExtension, } from './extension-package.js';
|
|
4
|
+
import { normalizeComponentMetadata, normalizeProcessorMetadata, } from './helpers.js';
|
|
6
5
|
export var ExtensionRegistry;
|
|
7
6
|
(function (ExtensionRegistry) {
|
|
8
7
|
let _resolver;
|
|
@@ -79,38 +78,7 @@ export var ExtensionRegistry;
|
|
|
79
78
|
throw new TypeError(`Class "${ctor.name}" has no component metadata.`);
|
|
80
79
|
if (_metadata.abstract)
|
|
81
80
|
return;
|
|
82
|
-
|
|
83
|
-
metadata = deepClone({
|
|
84
|
-
className: metadata.className,
|
|
85
|
-
displayName: metadata.displayName,
|
|
86
|
-
description: metadata.description,
|
|
87
|
-
iconUrl: metadata.iconUrl,
|
|
88
|
-
author: metadata.author,
|
|
89
|
-
interfaces: metadata.interfaces,
|
|
90
|
-
tags: metadata.tags,
|
|
91
|
-
abstract: metadata.abstract,
|
|
92
|
-
variables: metadata.variables,
|
|
93
|
-
components: metadata.components,
|
|
94
|
-
...metadata,
|
|
95
|
-
});
|
|
96
|
-
if (metadata.variables) {
|
|
97
|
-
/** Convert object enumValues to arrays */
|
|
98
|
-
for (const v of Object.values(metadata.variables)) {
|
|
99
|
-
if (v.enumValues &&
|
|
100
|
-
typeof v.enumValues === 'object' &&
|
|
101
|
-
!Array.isArray(v.enumValues)) {
|
|
102
|
-
let values = v.enumValues;
|
|
103
|
-
const keys = Object.keys(values).filter(k => !/^\d+$/.test(k));
|
|
104
|
-
values = keys.reduce((a, k) => {
|
|
105
|
-
if (values[k] != null)
|
|
106
|
-
a.push(values[k]);
|
|
107
|
-
return a;
|
|
108
|
-
// v => !(typeof v === 'number' && !keys.includes(String(v))),
|
|
109
|
-
}, []);
|
|
110
|
-
v.enumValues = values;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
81
|
+
const metadata = await normalizeComponentMetadata(_metadata);
|
|
114
82
|
let versions = ExtensionRegistry.packages.get('internal');
|
|
115
83
|
if (!versions) {
|
|
116
84
|
versions = [];
|
|
@@ -123,7 +91,7 @@ export var ExtensionRegistry;
|
|
|
123
91
|
pkg.version = '0.0.0';
|
|
124
92
|
pkg.description = 'Internal extensions';
|
|
125
93
|
}
|
|
126
|
-
const cmp = new
|
|
94
|
+
const cmp = new ComponentExtension(pkg, ctor.name, metadata, ctor);
|
|
127
95
|
pkg.components.push(cmp);
|
|
128
96
|
storePackage(pkg);
|
|
129
97
|
return cmp;
|
|
@@ -135,37 +103,7 @@ export var ExtensionRegistry;
|
|
|
135
103
|
throw new TypeError(`Class "${ctor.name}" has no processor metadata.`);
|
|
136
104
|
if (_metadata.abstract)
|
|
137
105
|
return;
|
|
138
|
-
|
|
139
|
-
metadata = deepClone({
|
|
140
|
-
className: metadata.className,
|
|
141
|
-
displayName: metadata.displayName,
|
|
142
|
-
description: metadata.description,
|
|
143
|
-
iconUrl: metadata.iconUrl,
|
|
144
|
-
author: metadata.author,
|
|
145
|
-
tags: metadata.tags,
|
|
146
|
-
abstract: metadata.abstract,
|
|
147
|
-
variables: metadata.variables,
|
|
148
|
-
components: metadata.components,
|
|
149
|
-
...metadata,
|
|
150
|
-
});
|
|
151
|
-
if (metadata.variables) {
|
|
152
|
-
/** Convert object enumValues to arrays */
|
|
153
|
-
for (const v of Object.values(metadata.variables)) {
|
|
154
|
-
if (v.enumValues &&
|
|
155
|
-
typeof v.enumValues === 'object' &&
|
|
156
|
-
!Array.isArray(v.enumValues)) {
|
|
157
|
-
let values = v.enumValues;
|
|
158
|
-
const keys = Object.keys(values).filter(k => !/^\d+$/.test(k));
|
|
159
|
-
values = keys.reduce((a, k) => {
|
|
160
|
-
if (values[k] != null)
|
|
161
|
-
a.push(values[k]);
|
|
162
|
-
return a;
|
|
163
|
-
// v => !(typeof v === 'number' && !keys.includes(String(v))),
|
|
164
|
-
}, []);
|
|
165
|
-
v.enumValues = values;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
106
|
+
const metadata = await normalizeProcessorMetadata(_metadata);
|
|
169
107
|
let versions = ExtensionRegistry.packages.get('internal');
|
|
170
108
|
if (!versions) {
|
|
171
109
|
versions = [];
|
|
@@ -178,7 +116,7 @@ export var ExtensionRegistry;
|
|
|
178
116
|
pkg.version = '0.0.0';
|
|
179
117
|
pkg.description = 'Internal extensions';
|
|
180
118
|
}
|
|
181
|
-
const prc = new
|
|
119
|
+
const prc = new ProcessorExtension(pkg, ctor.name, metadata, ctor);
|
|
182
120
|
pkg.processors.push(prc);
|
|
183
121
|
storePackage(pkg);
|
|
184
122
|
return prc;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ComponentMetadata, ProcessorMetadata } from '../models/index.js';
|
|
2
|
+
export declare function normalizeProcessorMetadata(metadata: ProcessorMetadata): Promise<ProcessorMetadata>;
|
|
3
|
+
export declare function normalizeComponentMetadata(metadata: ComponentMetadata): Promise<ComponentMetadata>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { deepClone, merge } from '@jsopen/objects';
|
|
2
|
+
import { ComponentMetadata, ProcessorMetadata } from '../models/index.js';
|
|
3
|
+
import { initializeModelsDocument } from '../models-document.js';
|
|
4
|
+
import { resolvePromisesDeep } from '../utils/resolve-promises.js';
|
|
5
|
+
export async function normalizeProcessorMetadata(metadata) {
|
|
6
|
+
const decoder = await getProcMetadataTypeDecoder();
|
|
7
|
+
let out = await resolvePromisesDeep(metadata);
|
|
8
|
+
out = deepClone({
|
|
9
|
+
className: out.className,
|
|
10
|
+
displayName: out.displayName,
|
|
11
|
+
description: out.description,
|
|
12
|
+
iconUrl: out.iconUrl,
|
|
13
|
+
author: out.author,
|
|
14
|
+
tags: out.tags,
|
|
15
|
+
abstract: out.abstract,
|
|
16
|
+
variables: out.variables,
|
|
17
|
+
components: out.components,
|
|
18
|
+
...out,
|
|
19
|
+
});
|
|
20
|
+
if (out.variables) {
|
|
21
|
+
/** Convert object enumValues to arrays */
|
|
22
|
+
for (const v of Object.values(out.variables)) {
|
|
23
|
+
if (v.enumValues &&
|
|
24
|
+
typeof v.enumValues === 'object' &&
|
|
25
|
+
!Array.isArray(v.enumValues)) {
|
|
26
|
+
let values = v.enumValues;
|
|
27
|
+
const keys = Object.keys(values).filter(k => !/^\d+$/.test(k));
|
|
28
|
+
values = keys.reduce((a, k) => {
|
|
29
|
+
if (values[k] != null)
|
|
30
|
+
a.push(values[k]);
|
|
31
|
+
return a;
|
|
32
|
+
}, []);
|
|
33
|
+
v.enumValues = values;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
out = decoder(out);
|
|
38
|
+
merge(out, metadata, { keepExisting: true, deep: 'full' });
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
export async function normalizeComponentMetadata(metadata) {
|
|
42
|
+
const decoder = await getCompMetadataTypeDecoder();
|
|
43
|
+
let out = await resolvePromisesDeep(metadata);
|
|
44
|
+
out = deepClone({
|
|
45
|
+
className: out.className,
|
|
46
|
+
displayName: out.displayName,
|
|
47
|
+
description: out.description,
|
|
48
|
+
iconUrl: out.iconUrl,
|
|
49
|
+
author: out.author,
|
|
50
|
+
interfaces: out.interfaces,
|
|
51
|
+
tags: out.tags,
|
|
52
|
+
abstract: out.abstract,
|
|
53
|
+
variables: out.variables,
|
|
54
|
+
components: out.components,
|
|
55
|
+
...out,
|
|
56
|
+
});
|
|
57
|
+
if (out.variables) {
|
|
58
|
+
/** Convert object enumValues to arrays */
|
|
59
|
+
for (const v of Object.values(out.variables)) {
|
|
60
|
+
if (v.enumValues &&
|
|
61
|
+
typeof v.enumValues === 'object' &&
|
|
62
|
+
!Array.isArray(v.enumValues)) {
|
|
63
|
+
let values = v.enumValues;
|
|
64
|
+
const keys = Object.keys(values).filter(k => !/^\d+$/.test(k));
|
|
65
|
+
values = keys.reduce((a, k) => {
|
|
66
|
+
if (values[k] != null)
|
|
67
|
+
a.push(values[k]);
|
|
68
|
+
return a;
|
|
69
|
+
// v => !(typeof v === 'number' && !keys.includes(String(v))),
|
|
70
|
+
}, []);
|
|
71
|
+
v.enumValues = values;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
out = decoder(out);
|
|
76
|
+
merge(out, metadata, { keepExisting: true, deep: 'full' });
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
// ************************************************************************
|
|
80
|
+
// ************************************************************************
|
|
81
|
+
let _compMetadataTypeDecoder;
|
|
82
|
+
let _procMetadataTypeDecoder;
|
|
83
|
+
async function getCompMetadataTypeDecoder() {
|
|
84
|
+
if (!_compMetadataTypeDecoder) {
|
|
85
|
+
const apiDoc = await initializeModelsDocument();
|
|
86
|
+
const compMetadataType = apiDoc.node.getComplexType(ComponentMetadata);
|
|
87
|
+
_compMetadataTypeDecoder = compMetadataType.generateCodec('decode', {
|
|
88
|
+
coerce: true,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return _compMetadataTypeDecoder;
|
|
92
|
+
}
|
|
93
|
+
async function getProcMetadataTypeDecoder() {
|
|
94
|
+
if (!_procMetadataTypeDecoder) {
|
|
95
|
+
const apiDoc = await initializeModelsDocument();
|
|
96
|
+
const procMetadataType = apiDoc.node.getComplexType(ProcessorMetadata);
|
|
97
|
+
_procMetadataTypeDecoder = procMetadataType.generateCodec('decode', {
|
|
98
|
+
coerce: true,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return _procMetadataTypeDecoder;
|
|
102
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ComponentBase } from '../classes/component-base.js';
|
|
2
|
+
import { ProcessorBase } from '../classes/processor-base.js';
|
|
3
|
+
import { Runnable } from '../classes/runnable.js';
|
|
4
|
+
export declare function isRunnable(proto: any): proto is Runnable;
|
|
5
|
+
export declare function isProcessorBase(proto: any): proto is ProcessorBase;
|
|
6
|
+
export declare function isComponentBase(proto: any): proto is ComponentBase;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComponentBase } from '../classes/component-base.js';
|
|
2
|
+
import { ProcessorBase } from '../classes/processor-base.js';
|
|
3
|
+
import { Runnable } from '../classes/runnable.js';
|
|
4
|
+
const RUNNABLE_TOKEN = Symbol.for(Runnable.name);
|
|
5
|
+
const PROCESSOR_BASE_TOKEN = Symbol.for(ProcessorBase.name);
|
|
6
|
+
const COMPONENT_BASE_TOKEN = Symbol.for(ComponentBase.name);
|
|
7
|
+
export function isRunnable(proto) {
|
|
8
|
+
return !!proto[RUNNABLE_TOKEN];
|
|
9
|
+
}
|
|
10
|
+
export function isProcessorBase(proto) {
|
|
11
|
+
return !!proto[PROCESSOR_BASE_TOKEN];
|
|
12
|
+
}
|
|
13
|
+
export function isComponentBase(proto) {
|
|
14
|
+
return !!proto[COMPONENT_BASE_TOKEN];
|
|
15
|
+
}
|