@syncbridge/common 0.5.7 → 0.5.9
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/package.json +3 -3
- package/processor-factory.d.ts +6 -2
- package/processor-factory.js +6 -2
- package/registry/extension-package.d.ts +6 -5
- package/registry/extension-package.js +26 -52
- package/registry/extension-registry.d.ts +12 -10
- package/registry/extension-registry.js +11 -73
- 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.9';
|
|
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');
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncbridge/common",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
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 = {}));
|
|
@@ -3,6 +3,7 @@ import { Type } from 'ts-gems';
|
|
|
3
3
|
import { ComponentBase } from '../classes/component-base.js';
|
|
4
4
|
import { ProcessorBase } from '../classes/processor-base.js';
|
|
5
5
|
import { ComponentMetadata, ProcessorMetadata } from '../models/index.js';
|
|
6
|
+
import type { ExtensionRegistry } from './extension-registry.js';
|
|
6
7
|
/**
|
|
7
8
|
*
|
|
8
9
|
*/
|
|
@@ -11,8 +12,8 @@ export declare class ExtensionPackage {
|
|
|
11
12
|
version: string;
|
|
12
13
|
description: string;
|
|
13
14
|
entryPoint: string;
|
|
14
|
-
components:
|
|
15
|
-
processors:
|
|
15
|
+
components: ComponentExtension[];
|
|
16
|
+
processors: ProcessorExtension[];
|
|
16
17
|
errors: Error[];
|
|
17
18
|
sortVersions(): void;
|
|
18
19
|
/**
|
|
@@ -21,12 +22,12 @@ export declare class ExtensionPackage {
|
|
|
21
22
|
* @static
|
|
22
23
|
*/
|
|
23
24
|
static fromDirectory(directory: string): Promise<ExtensionPackage>;
|
|
24
|
-
static fromNodePackage(specifier: string,
|
|
25
|
+
static fromNodePackage(specifier: string, resolver: ExtensionRegistry.Resolver | undefined): Promise<ExtensionPackage>;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
*
|
|
28
29
|
*/
|
|
29
|
-
export declare class
|
|
30
|
+
export declare class ComponentExtension {
|
|
30
31
|
readonly pkg: ExtensionPackage;
|
|
31
32
|
readonly exportName: string;
|
|
32
33
|
readonly metadata: ComponentMetadata;
|
|
@@ -40,7 +41,7 @@ export declare class ExtensionPackageComponent {
|
|
|
40
41
|
/**
|
|
41
42
|
*
|
|
42
43
|
*/
|
|
43
|
-
export declare class
|
|
44
|
+
export declare class ProcessorExtension {
|
|
44
45
|
readonly pkg: ExtensionPackage;
|
|
45
46
|
readonly exportName: string;
|
|
46
47
|
readonly metadata: ProcessorMetadata;
|
|
@@ -1,37 +1,12 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
-
import { createRequire } from 'node:module';
|
|
4
3
|
import path from 'node:path';
|
|
5
4
|
import process from 'node:process';
|
|
6
5
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
|
-
import {
|
|
8
|
-
import { ProcessorBase } from '../classes/processor-base.js';
|
|
6
|
+
import { updateErrorMessage } from '@jsopen/objects';
|
|
9
7
|
import { COMPONENT_OPTIONS, PROCESSOR_OPTIONS } from '../constants.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { resolvePromisesDeep } from '../utils/resolve-promises.js';
|
|
13
|
-
let _compMetadataTypeDecoder;
|
|
14
|
-
let _procMetadataTypeDecoder;
|
|
15
|
-
async function getCompMetadataTypeDecoder() {
|
|
16
|
-
if (!_compMetadataTypeDecoder) {
|
|
17
|
-
const apiDoc = await initializeModelsDocument();
|
|
18
|
-
const compMetadataType = apiDoc.node.getComplexType(ComponentMetadata);
|
|
19
|
-
_compMetadataTypeDecoder = compMetadataType.generateCodec('decode', {
|
|
20
|
-
coerce: true,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return _compMetadataTypeDecoder;
|
|
24
|
-
}
|
|
25
|
-
async function getProcMetadataTypeDecoder() {
|
|
26
|
-
if (!_procMetadataTypeDecoder) {
|
|
27
|
-
const apiDoc = await initializeModelsDocument();
|
|
28
|
-
const procMetadataType = apiDoc.node.getComplexType(ProcessorMetadata);
|
|
29
|
-
_procMetadataTypeDecoder = procMetadataType.generateCodec('decode', {
|
|
30
|
-
coerce: true,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return _procMetadataTypeDecoder;
|
|
34
|
-
}
|
|
8
|
+
import { isComponentBase, isProcessorBase } from '../utils/type-guartds.js';
|
|
9
|
+
import { normalizeComponentMetadata, normalizeProcessorMetadata, } from './helpers.js';
|
|
35
10
|
/**
|
|
36
11
|
*
|
|
37
12
|
*/
|
|
@@ -49,7 +24,6 @@ export class ExtensionPackage {
|
|
|
49
24
|
* @static
|
|
50
25
|
*/
|
|
51
26
|
static async fromDirectory(directory) {
|
|
52
|
-
const compMetadataTypeDecoder = await getCompMetadataTypeDecoder();
|
|
53
27
|
let filename = path.join(directory, 'package.json');
|
|
54
28
|
if (!fs.existsSync(filename))
|
|
55
29
|
throw new TypeError(`Directory "${directory}" does not contain package.json`);
|
|
@@ -77,16 +51,17 @@ export class ExtensionPackage {
|
|
|
77
51
|
continue;
|
|
78
52
|
}
|
|
79
53
|
try {
|
|
80
|
-
metadata =
|
|
54
|
+
metadata = await normalizeComponentMetadata(metadata);
|
|
81
55
|
}
|
|
82
56
|
catch (e) {
|
|
83
|
-
|
|
57
|
+
updateErrorMessage(e, `Component (${ctorName}) metadata validation error. ` + e.message);
|
|
58
|
+
out.errors.push(e);
|
|
84
59
|
continue;
|
|
85
60
|
}
|
|
86
61
|
if (metadata.abstract)
|
|
87
62
|
continue;
|
|
88
63
|
out.components = out.components || [];
|
|
89
|
-
out.components.push(new
|
|
64
|
+
out.components.push(new ComponentExtension(out, ctorName, metadata));
|
|
90
65
|
}
|
|
91
66
|
}
|
|
92
67
|
if (pkgJson.syncbridge.processors) {
|
|
@@ -104,26 +79,25 @@ export class ExtensionPackage {
|
|
|
104
79
|
continue;
|
|
105
80
|
}
|
|
106
81
|
try {
|
|
107
|
-
metadata =
|
|
82
|
+
metadata = await normalizeProcessorMetadata(metadata);
|
|
108
83
|
}
|
|
109
84
|
catch (e) {
|
|
110
|
-
|
|
85
|
+
updateErrorMessage(e, `Processor (${ctorName}) metadata validation error. ` + e.message);
|
|
86
|
+
out.errors.push(e);
|
|
111
87
|
continue;
|
|
112
88
|
}
|
|
113
89
|
if (metadata.abstract)
|
|
114
90
|
continue;
|
|
115
91
|
out.processors = out.processors || [];
|
|
116
|
-
out.processors.push(new
|
|
92
|
+
out.processors.push(new ProcessorExtension(out, ctorName, metadata));
|
|
117
93
|
}
|
|
118
94
|
}
|
|
119
95
|
out.sortVersions();
|
|
120
96
|
return out;
|
|
121
97
|
}
|
|
122
|
-
static async fromNodePackage(specifier,
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
const resolver = createRequire(parentPath || import.meta.url).resolve;
|
|
126
|
-
let entryPoint = resolver(specifier);
|
|
98
|
+
static async fromNodePackage(specifier, resolver) {
|
|
99
|
+
// const resolver = createRequire(parentPath || import.meta.url).resolve;
|
|
100
|
+
let entryPoint = (resolver || import.meta.resolve)(specifier);
|
|
127
101
|
const pkgJson = locatePkgJson(path.dirname(entryPoint));
|
|
128
102
|
if (!pkgJson) {
|
|
129
103
|
throw new TypeError(`Can't locate package.json file for "${specifier}"`);
|
|
@@ -142,33 +116,33 @@ export class ExtensionPackage {
|
|
|
142
116
|
continue;
|
|
143
117
|
let metadata = Reflect.getMetadata(COMPONENT_OPTIONS, v);
|
|
144
118
|
if (metadata) {
|
|
145
|
-
metadata = await resolvePromisesDeep(metadata);
|
|
146
119
|
try {
|
|
147
|
-
metadata =
|
|
120
|
+
metadata = await normalizeComponentMetadata(metadata);
|
|
148
121
|
}
|
|
149
122
|
catch (e) {
|
|
150
|
-
|
|
123
|
+
updateErrorMessage(e, `Component (${ctorName}) metadata validation error. ` + e.message);
|
|
124
|
+
out.errors.push(e);
|
|
151
125
|
continue;
|
|
152
126
|
}
|
|
153
127
|
if (metadata.abstract)
|
|
154
128
|
continue;
|
|
155
129
|
out.components = out.components || [];
|
|
156
|
-
out.components.push(new
|
|
130
|
+
out.components.push(new ComponentExtension(out, ctorName, metadata));
|
|
157
131
|
}
|
|
158
132
|
metadata = Reflect.getMetadata(PROCESSOR_OPTIONS, v);
|
|
159
133
|
if (metadata) {
|
|
160
|
-
metadata = await resolvePromisesDeep(metadata);
|
|
161
134
|
try {
|
|
162
|
-
metadata =
|
|
135
|
+
metadata = await normalizeProcessorMetadata(metadata);
|
|
163
136
|
}
|
|
164
137
|
catch (e) {
|
|
165
|
-
|
|
138
|
+
updateErrorMessage(e, `Processor (${ctorName}) metadata validation error. ` + e.message);
|
|
139
|
+
out.errors.push(e);
|
|
166
140
|
continue;
|
|
167
141
|
}
|
|
168
142
|
if (metadata.abstract)
|
|
169
143
|
continue;
|
|
170
144
|
out.processors = out.processors || [];
|
|
171
|
-
out.processors.push(new
|
|
145
|
+
out.processors.push(new ProcessorExtension(out, ctorName, metadata));
|
|
172
146
|
}
|
|
173
147
|
}
|
|
174
148
|
out.sortVersions();
|
|
@@ -178,7 +152,7 @@ export class ExtensionPackage {
|
|
|
178
152
|
/**
|
|
179
153
|
*
|
|
180
154
|
*/
|
|
181
|
-
export class
|
|
155
|
+
export class ComponentExtension {
|
|
182
156
|
pkg;
|
|
183
157
|
exportName;
|
|
184
158
|
metadata;
|
|
@@ -207,7 +181,7 @@ export class ExtensionPackageComponent {
|
|
|
207
181
|
throw new TypeError(`Exported component "${this.exportName}" not found in package "${this.pkg.name}"`);
|
|
208
182
|
if (typeof ctor !== 'function')
|
|
209
183
|
throw new TypeError(`Exported component "${this.exportName}" is not a class`);
|
|
210
|
-
if (!(ctor.prototype
|
|
184
|
+
if (!isComponentBase(ctor.prototype))
|
|
211
185
|
throw new TypeError(`Exported component "${this.exportName}" does not extends ComponentBase`);
|
|
212
186
|
this._ctor = ctor;
|
|
213
187
|
return this._ctor;
|
|
@@ -216,7 +190,7 @@ export class ExtensionPackageComponent {
|
|
|
216
190
|
/**
|
|
217
191
|
*
|
|
218
192
|
*/
|
|
219
|
-
export class
|
|
193
|
+
export class ProcessorExtension {
|
|
220
194
|
pkg;
|
|
221
195
|
exportName;
|
|
222
196
|
metadata;
|
|
@@ -245,7 +219,7 @@ export class ExtensionPackageProcessor {
|
|
|
245
219
|
throw new TypeError(`Exported processor "${this.exportName}" not found in package "${this.pkg.name}"`);
|
|
246
220
|
if (typeof ctor !== 'function')
|
|
247
221
|
throw new TypeError(`Exported processor "${this.exportName}" is not a class`);
|
|
248
|
-
if (!(ctor.prototype
|
|
222
|
+
if (!isProcessorBase(ctor.prototype))
|
|
249
223
|
throw new TypeError(`Exported processor "${this.exportName}" does not extends ProcessorBase`);
|
|
250
224
|
this._ctor = ctor;
|
|
251
225
|
return this._ctor;
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
+
import { URL } from 'node:url';
|
|
1
2
|
import { Type } from 'ts-gems';
|
|
2
|
-
import {
|
|
3
|
+
import { ComponentExtension, ExtensionPackage, ProcessorExtension } from './extension-package.js';
|
|
3
4
|
export declare namespace ExtensionRegistry {
|
|
5
|
+
type Resolver = (specifier: string, parent?: string | URL) => string;
|
|
4
6
|
const packages: Map<string, ExtensionPackage[]>;
|
|
5
|
-
const components: Map<string,
|
|
6
|
-
const processors: Map<string,
|
|
7
|
+
const components: Map<string, ComponentExtension[]>;
|
|
8
|
+
const processors: Map<string, ProcessorExtension[]>;
|
|
7
9
|
/**
|
|
8
10
|
*
|
|
9
11
|
*/
|
|
10
|
-
function findComponent(className: string, version?: string):
|
|
12
|
+
function findComponent(className: string, version?: string): ComponentExtension | undefined;
|
|
11
13
|
/**
|
|
12
14
|
*
|
|
13
15
|
*/
|
|
14
|
-
function getComponent(className: string, version?: string):
|
|
16
|
+
function getComponent(className: string, version?: string): ComponentExtension;
|
|
15
17
|
/**
|
|
16
18
|
*
|
|
17
19
|
*/
|
|
18
|
-
function findProcessor(className: string, version?: string):
|
|
20
|
+
function findProcessor(className: string, version?: string): ProcessorExtension | undefined;
|
|
19
21
|
/**
|
|
20
22
|
*
|
|
21
23
|
*/
|
|
22
|
-
function getProcessor(className: string, version?: string):
|
|
24
|
+
function getProcessor(className: string, version?: string): ProcessorExtension;
|
|
23
25
|
/**
|
|
24
26
|
*
|
|
25
27
|
*/
|
|
26
|
-
function
|
|
28
|
+
function setResolver(fn: Resolver | undefined): void;
|
|
27
29
|
/**
|
|
28
30
|
*
|
|
29
31
|
*/
|
|
@@ -32,6 +34,6 @@ export declare namespace ExtensionRegistry {
|
|
|
32
34
|
*
|
|
33
35
|
*/
|
|
34
36
|
function registerNodePackage(specifier: string): Promise<ExtensionPackage>;
|
|
35
|
-
function registerComponent(ctor: Type): Promise<
|
|
36
|
-
function registerProcessor(ctor: Type): Promise<
|
|
37
|
+
function registerComponent(ctor: Type): Promise<ComponentExtension | undefined>;
|
|
38
|
+
function registerProcessor(ctor: Type): Promise<ProcessorExtension | undefined>;
|
|
37
39
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
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
|
-
let
|
|
7
|
+
let _resolver;
|
|
9
8
|
ExtensionRegistry.packages = new Map();
|
|
10
9
|
ExtensionRegistry.components = new Map();
|
|
11
10
|
ExtensionRegistry.processors = new Map();
|
|
@@ -51,10 +50,10 @@ export var ExtensionRegistry;
|
|
|
51
50
|
/**
|
|
52
51
|
*
|
|
53
52
|
*/
|
|
54
|
-
function
|
|
55
|
-
|
|
53
|
+
function setResolver(fn) {
|
|
54
|
+
_resolver = fn;
|
|
56
55
|
}
|
|
57
|
-
ExtensionRegistry.
|
|
56
|
+
ExtensionRegistry.setResolver = setResolver;
|
|
58
57
|
/**
|
|
59
58
|
*
|
|
60
59
|
*/
|
|
@@ -68,7 +67,7 @@ export var ExtensionRegistry;
|
|
|
68
67
|
*
|
|
69
68
|
*/
|
|
70
69
|
async function registerNodePackage(specifier) {
|
|
71
|
-
const pkg = await ExtensionPackage.fromNodePackage(specifier,
|
|
70
|
+
const pkg = await ExtensionPackage.fromNodePackage(specifier, _resolver);
|
|
72
71
|
storePackage(pkg);
|
|
73
72
|
return pkg;
|
|
74
73
|
}
|
|
@@ -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
|
+
}
|