@syncbridge/common 0.5.4 → 0.5.6
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 +1 -1
- package/package.json +1 -1
- package/registry/extension-package.d.ts +1 -1
- package/registry/extension-package.js +4 -2
- package/registry/extension-registry.d.ts +12 -18
- package/registry/extension-registry.js +5 -6
- package/registry/registry.d.ts +0 -0
- package/registry/registry.js +0 -273
package/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const version = '0.5.
|
|
1
|
+
export const version = '0.5.6';
|
|
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
|
@@ -21,7 +21,7 @@ export declare class ExtensionPackage {
|
|
|
21
21
|
* @static
|
|
22
22
|
*/
|
|
23
23
|
static fromDirectory(directory: string): Promise<ExtensionPackage>;
|
|
24
|
-
static fromNodePackage(specifier: string,
|
|
24
|
+
static fromNodePackage(specifier: string, parentPath?: string | URL): Promise<ExtensionPackage>;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import process from 'node:process';
|
|
5
6
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
@@ -118,10 +119,11 @@ export class ExtensionPackage {
|
|
|
118
119
|
out.sortVersions();
|
|
119
120
|
return out;
|
|
120
121
|
}
|
|
121
|
-
static async fromNodePackage(specifier,
|
|
122
|
+
static async fromNodePackage(specifier, parentPath) {
|
|
122
123
|
const compMetadataTypeDecoder = await getCompMetadataTypeDecoder();
|
|
123
124
|
const procMetadataTypeDecoder = await getProcMetadataTypeDecoder();
|
|
124
|
-
|
|
125
|
+
const resolver = createRequire(parentPath || import.meta.url).resolve;
|
|
126
|
+
let entryPoint = resolver(specifier);
|
|
125
127
|
const pkgJson = locatePkgJson(path.dirname(entryPoint));
|
|
126
128
|
if (!pkgJson) {
|
|
127
129
|
throw new TypeError(`Can't locate package.json file for "${specifier}"`);
|
|
@@ -1,43 +1,37 @@
|
|
|
1
1
|
import { Type } from 'ts-gems';
|
|
2
2
|
import { ExtensionPackage, ExtensionPackageComponent, ExtensionPackageProcessor } from './extension-package.js';
|
|
3
3
|
export declare namespace ExtensionRegistry {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export const packages: Map<string, ExtensionPackage[]>;
|
|
9
|
-
export const components: Map<string, ExtensionPackageComponent[]>;
|
|
10
|
-
export const processors: Map<string, ExtensionPackageProcessor[]>;
|
|
4
|
+
const packages: Map<string, ExtensionPackage[]>;
|
|
5
|
+
const components: Map<string, ExtensionPackageComponent[]>;
|
|
6
|
+
const processors: Map<string, ExtensionPackageProcessor[]>;
|
|
11
7
|
/**
|
|
12
8
|
*
|
|
13
9
|
*/
|
|
14
|
-
|
|
10
|
+
function findComponent(className: string, version?: string): ExtensionPackageComponent | undefined;
|
|
15
11
|
/**
|
|
16
12
|
*
|
|
17
13
|
*/
|
|
18
|
-
|
|
14
|
+
function getComponent(className: string, version?: string): ExtensionPackageComponent;
|
|
19
15
|
/**
|
|
20
16
|
*
|
|
21
17
|
*/
|
|
22
|
-
|
|
18
|
+
function findProcessor(className: string, version?: string): ExtensionPackageProcessor | undefined;
|
|
23
19
|
/**
|
|
24
20
|
*
|
|
25
21
|
*/
|
|
26
|
-
|
|
22
|
+
function getProcessor(className: string, version?: string): ExtensionPackageProcessor;
|
|
27
23
|
/**
|
|
28
24
|
*
|
|
29
|
-
* @param resolver
|
|
30
25
|
*/
|
|
31
|
-
|
|
26
|
+
function setParentPath(value: string | URL): void;
|
|
32
27
|
/**
|
|
33
28
|
*
|
|
34
29
|
*/
|
|
35
|
-
|
|
30
|
+
function registerExtensionPackage(directory: string): Promise<ExtensionPackage>;
|
|
36
31
|
/**
|
|
37
32
|
*
|
|
38
33
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export {};
|
|
34
|
+
function registerNodePackage(specifier: string): Promise<ExtensionPackage>;
|
|
35
|
+
function registerComponent(ctor: Type): Promise<ExtensionPackageComponent | undefined>;
|
|
36
|
+
function registerProcessor(ctor: Type): Promise<ExtensionPackageProcessor | undefined>;
|
|
43
37
|
}
|
|
@@ -5,7 +5,7 @@ import { resolvePromisesDeep } from '../utils/resolve-promises.js';
|
|
|
5
5
|
import { ExtensionPackage, ExtensionPackageComponent, ExtensionPackageProcessor, } from './extension-package.js';
|
|
6
6
|
export var ExtensionRegistry;
|
|
7
7
|
(function (ExtensionRegistry) {
|
|
8
|
-
let
|
|
8
|
+
let _parentPath = import.meta.url;
|
|
9
9
|
ExtensionRegistry.packages = new Map();
|
|
10
10
|
ExtensionRegistry.components = new Map();
|
|
11
11
|
ExtensionRegistry.processors = new Map();
|
|
@@ -50,12 +50,11 @@ export var ExtensionRegistry;
|
|
|
50
50
|
ExtensionRegistry.getProcessor = getProcessor;
|
|
51
51
|
/**
|
|
52
52
|
*
|
|
53
|
-
* @param resolver
|
|
54
53
|
*/
|
|
55
|
-
function
|
|
56
|
-
|
|
54
|
+
function setParentPath(value) {
|
|
55
|
+
_parentPath = value;
|
|
57
56
|
}
|
|
58
|
-
ExtensionRegistry.
|
|
57
|
+
ExtensionRegistry.setParentPath = setParentPath;
|
|
59
58
|
/**
|
|
60
59
|
*
|
|
61
60
|
*/
|
|
@@ -69,7 +68,7 @@ export var ExtensionRegistry;
|
|
|
69
68
|
*
|
|
70
69
|
*/
|
|
71
70
|
async function registerNodePackage(specifier) {
|
|
72
|
-
const pkg = await ExtensionPackage.fromNodePackage(specifier,
|
|
71
|
+
const pkg = await ExtensionPackage.fromNodePackage(specifier, _parentPath);
|
|
73
72
|
storePackage(pkg);
|
|
74
73
|
return pkg;
|
|
75
74
|
}
|
package/registry/registry.d.ts
DELETED
|
File without changes
|
package/registry/registry.js
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import * as fs from 'node:fs';
|
|
3
|
-
// import path from 'node:path';
|
|
4
|
-
// import process from 'node:process';
|
|
5
|
-
// import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
|
-
// import { deepClone, isPlainObject } from '@jsopen/objects';
|
|
7
|
-
// import { Type } from 'ts-gems';
|
|
8
|
-
// import type { ComponentBase } from '../classes/component-base.js';
|
|
9
|
-
// import type { ProcessorBase } from '../classes/processor-base.js';
|
|
10
|
-
// import { COMPONENT_OPTIONS, PROCESSOR_OPTIONS } from '../constants.js';
|
|
11
|
-
// import { ComponentMetadata, ProcessorMetadata } from '../models/index.js';
|
|
12
|
-
// import { isExtensionPackage } from '../utils/make-extension-package.js';
|
|
13
|
-
//
|
|
14
|
-
// export namespace ExtensionRegistry {
|
|
15
|
-
// let _resolver = import.meta.resolve;
|
|
16
|
-
//
|
|
17
|
-
// export const packages = new Map<
|
|
18
|
-
// string,
|
|
19
|
-
// ExtensionRegistry.ExtensionPackageRecord
|
|
20
|
-
// >();
|
|
21
|
-
// export const components = new Map<
|
|
22
|
-
// string,
|
|
23
|
-
// ExtensionRegistry.ComponentRecord
|
|
24
|
-
// >();
|
|
25
|
-
// export const processors = new Map<
|
|
26
|
-
// string,
|
|
27
|
-
// ExtensionRegistry.ProcessorRecord
|
|
28
|
-
// >();
|
|
29
|
-
//
|
|
30
|
-
// export function setResolver(resolver: (name: string) => string) {
|
|
31
|
-
// _resolver = resolver;
|
|
32
|
-
// }
|
|
33
|
-
//
|
|
34
|
-
// export function getProcessor(
|
|
35
|
-
// className: string,
|
|
36
|
-
// ): ExtensionRegistry.ProcessorRecord {
|
|
37
|
-
// const rec = ExtensionRegistry.processors.get(className);
|
|
38
|
-
// if (!rec) {
|
|
39
|
-
// throw new Error(`Processor "${className}" not found in registry`);
|
|
40
|
-
// }
|
|
41
|
-
// return rec;
|
|
42
|
-
// }
|
|
43
|
-
//
|
|
44
|
-
// export function getComponent(
|
|
45
|
-
// className: string,
|
|
46
|
-
// ): ExtensionRegistry.ComponentRecord {
|
|
47
|
-
// const rec = ExtensionRegistry.components.get(className);
|
|
48
|
-
// if (!rec) {
|
|
49
|
-
// throw new Error(`Component "${className}" not found in registry`);
|
|
50
|
-
// }
|
|
51
|
-
// return rec;
|
|
52
|
-
// }
|
|
53
|
-
//
|
|
54
|
-
// export async function registerPackage(
|
|
55
|
-
// ...specifiers: string[]
|
|
56
|
-
// ): Promise<void> {
|
|
57
|
-
// const errors: string[] = [];
|
|
58
|
-
// await Promise.all(
|
|
59
|
-
// specifiers.map(specifier =>
|
|
60
|
-
// _registerPackage(specifier).catch(err => {
|
|
61
|
-
// errors.push(`\n ${specifier}: ${err.message}`);
|
|
62
|
-
// }),
|
|
63
|
-
// ),
|
|
64
|
-
// );
|
|
65
|
-
// if (errors.length) {
|
|
66
|
-
// console.error(`Failed to register extensions:${errors}`);
|
|
67
|
-
// }
|
|
68
|
-
// }
|
|
69
|
-
//
|
|
70
|
-
// async function _registerPackage(
|
|
71
|
-
// specifier: string,
|
|
72
|
-
// options?: {
|
|
73
|
-
// ignoreInvalid?: boolean;
|
|
74
|
-
// },
|
|
75
|
-
// ): Promise<void> {
|
|
76
|
-
// let packagePath = fileURLToPath(_resolver(specifier));
|
|
77
|
-
// const json = locatePkgJson(path.dirname(packagePath));
|
|
78
|
-
// if (!json) {
|
|
79
|
-
// if (options?.ignoreInvalid) return;
|
|
80
|
-
// throw new TypeError(`Can't locate package.json file for "${specifier}"`);
|
|
81
|
-
// }
|
|
82
|
-
//
|
|
83
|
-
// if (path.isAbsolute(packagePath) && process.platform === 'win32') {
|
|
84
|
-
// packagePath = pathToFileURL(packagePath).href;
|
|
85
|
-
// }
|
|
86
|
-
//
|
|
87
|
-
// const pkg = (await import(packagePath)).default;
|
|
88
|
-
// if (!isExtensionPackage(pkg)) {
|
|
89
|
-
// if (options?.ignoreInvalid) return;
|
|
90
|
-
// throw new TypeError(
|
|
91
|
-
// `"${specifier}" do not export ExtensionPackage interface`,
|
|
92
|
-
// );
|
|
93
|
-
// }
|
|
94
|
-
// // ignore if already registered
|
|
95
|
-
// if (packages.get(json.name)) return;
|
|
96
|
-
//
|
|
97
|
-
// // Register dependencies
|
|
98
|
-
// if (pkg.dependencies) {
|
|
99
|
-
// for (const dep of pkg.dependencies)
|
|
100
|
-
// await _registerPackage(dep, { ignoreInvalid: true });
|
|
101
|
-
// }
|
|
102
|
-
//
|
|
103
|
-
// const packageRec: ExtensionRegistry.ExtensionPackageRecord = Object.freeze({
|
|
104
|
-
// name: json.name,
|
|
105
|
-
// version: json.version,
|
|
106
|
-
// description: json.description,
|
|
107
|
-
// });
|
|
108
|
-
// packages.set(packageRec.name, packageRec);
|
|
109
|
-
//
|
|
110
|
-
// if (Array.isArray(pkg.components)) {
|
|
111
|
-
// for (const ctor of pkg.components) {
|
|
112
|
-
// await registerComponent(ctor, packageRec.name);
|
|
113
|
-
// }
|
|
114
|
-
// }
|
|
115
|
-
//
|
|
116
|
-
// if (Array.isArray(pkg.processors)) {
|
|
117
|
-
// for (const ctor of pkg.processors) {
|
|
118
|
-
// await registerProcessor(ctor, packageRec.name);
|
|
119
|
-
// }
|
|
120
|
-
// }
|
|
121
|
-
// }
|
|
122
|
-
//
|
|
123
|
-
// export async function registerComponent(ctor: Type, packageName: string) {
|
|
124
|
-
// const _metadata: ComponentMetadata = Reflect.getMetadata(
|
|
125
|
-
// COMPONENT_OPTIONS,
|
|
126
|
-
// ctor,
|
|
127
|
-
// );
|
|
128
|
-
// if (!_metadata)
|
|
129
|
-
// throw new TypeError(`Class "${ctor.name}" has no component metadata.`);
|
|
130
|
-
// if (_metadata.abstract) return;
|
|
131
|
-
// let componentRec = components.get(_metadata.className);
|
|
132
|
-
// if (componentRec)
|
|
133
|
-
// throw new TypeError(
|
|
134
|
-
// `Component "${_metadata.className}" already registered by "${componentRec.package}" package`,
|
|
135
|
-
// );
|
|
136
|
-
//
|
|
137
|
-
// let metadata: ComponentMetadata = await resolvePromisesDeep(_metadata);
|
|
138
|
-
// metadata = deepClone({
|
|
139
|
-
// className: metadata.className,
|
|
140
|
-
// displayName: metadata.displayName,
|
|
141
|
-
// description: metadata.description,
|
|
142
|
-
// iconUrl: metadata.iconUrl,
|
|
143
|
-
// author: metadata.author,
|
|
144
|
-
// interfaces: metadata.interfaces,
|
|
145
|
-
// tags: metadata.tags,
|
|
146
|
-
// abstract: metadata.abstract,
|
|
147
|
-
// variables: metadata.variables,
|
|
148
|
-
// components: metadata.components,
|
|
149
|
-
// ...(metadata as any),
|
|
150
|
-
// });
|
|
151
|
-
// if (metadata.variables) {
|
|
152
|
-
// /** Convert object enumValues to arrays */
|
|
153
|
-
// for (const v of Object.values(metadata.variables)) {
|
|
154
|
-
// if (
|
|
155
|
-
// v.enumValues &&
|
|
156
|
-
// typeof v.enumValues === 'object' &&
|
|
157
|
-
// !Array.isArray(v.enumValues)
|
|
158
|
-
// ) {
|
|
159
|
-
// let values: any = v.enumValues;
|
|
160
|
-
// const keys = Object.keys(values).filter(k => !/^\d+$/.test(k));
|
|
161
|
-
// values = keys.reduce((a, k) => {
|
|
162
|
-
// if (values[k] != null) a.push(values[k]);
|
|
163
|
-
// return a;
|
|
164
|
-
// // v => !(typeof v === 'number' && !keys.includes(String(v))),
|
|
165
|
-
// }, [] as any[]);
|
|
166
|
-
// v.enumValues = values;
|
|
167
|
-
// }
|
|
168
|
-
// }
|
|
169
|
-
// }
|
|
170
|
-
//
|
|
171
|
-
// componentRec = {
|
|
172
|
-
// package: packageName,
|
|
173
|
-
// ctor,
|
|
174
|
-
// metadata,
|
|
175
|
-
// };
|
|
176
|
-
// components.set(metadata.className, componentRec);
|
|
177
|
-
// }
|
|
178
|
-
//
|
|
179
|
-
// export async function registerProcessor(ctor: Type, packageName: string) {
|
|
180
|
-
// const _metadata: ProcessorMetadata = Reflect.getMetadata(
|
|
181
|
-
// PROCESSOR_OPTIONS,
|
|
182
|
-
// ctor,
|
|
183
|
-
// );
|
|
184
|
-
// if (!_metadata)
|
|
185
|
-
// throw new TypeError(`Class "${ctor.name}" has no processor metadata.`);
|
|
186
|
-
// if (_metadata.abstract) return;
|
|
187
|
-
// let processorRec = processors.get(_metadata.className);
|
|
188
|
-
// if (processorRec)
|
|
189
|
-
// throw new TypeError(
|
|
190
|
-
// `Processor "${_metadata.className}" already registered by "${processorRec.package}" package`,
|
|
191
|
-
// );
|
|
192
|
-
// let metadata: ComponentMetadata = await resolvePromisesDeep(_metadata);
|
|
193
|
-
// metadata = deepClone({
|
|
194
|
-
// className: metadata.className,
|
|
195
|
-
// displayName: metadata.displayName,
|
|
196
|
-
// description: metadata.description,
|
|
197
|
-
// iconUrl: metadata.iconUrl,
|
|
198
|
-
// author: metadata.author,
|
|
199
|
-
// tags: metadata.tags,
|
|
200
|
-
// abstract: metadata.abstract,
|
|
201
|
-
// variables: metadata.variables,
|
|
202
|
-
// components: metadata.components,
|
|
203
|
-
// ...(metadata as any),
|
|
204
|
-
// });
|
|
205
|
-
// if (metadata.variables) {
|
|
206
|
-
// /** Convert object enumValues to arrays */
|
|
207
|
-
// for (const v of Object.values(metadata.variables)) {
|
|
208
|
-
// if (
|
|
209
|
-
// v.enumValues &&
|
|
210
|
-
// typeof v.enumValues === 'object' &&
|
|
211
|
-
// !Array.isArray(v.enumValues)
|
|
212
|
-
// ) {
|
|
213
|
-
// let values: any = v.enumValues;
|
|
214
|
-
// const keys = Object.keys(values).filter(k => !/^\d+$/.test(k));
|
|
215
|
-
// values = keys.reduce((a, k) => {
|
|
216
|
-
// if (values[k] != null) a.push(values[k]);
|
|
217
|
-
// return a;
|
|
218
|
-
// // v => !(typeof v === 'number' && !keys.includes(String(v))),
|
|
219
|
-
// }, [] as any[]);
|
|
220
|
-
// v.enumValues = values;
|
|
221
|
-
// }
|
|
222
|
-
// }
|
|
223
|
-
// }
|
|
224
|
-
// processorRec = {
|
|
225
|
-
// package: packageName,
|
|
226
|
-
// ctor,
|
|
227
|
-
// metadata,
|
|
228
|
-
// };
|
|
229
|
-
// processors.set(metadata.className, processorRec);
|
|
230
|
-
// }
|
|
231
|
-
// }
|
|
232
|
-
//
|
|
233
|
-
// function locatePkgJson(directory: string): Record<string, any> | undefined {
|
|
234
|
-
// if (directory.startsWith('file:')) directory = fileURLToPath(directory);
|
|
235
|
-
// for (let i = 0; i < 3; i++) {
|
|
236
|
-
// const f = path.resolve(directory, 'package.json');
|
|
237
|
-
// if (fs.existsSync(f)) {
|
|
238
|
-
// const json = JSON.parse(fs.readFileSync(f, 'utf8'));
|
|
239
|
-
// if (json.name && json.version) return json;
|
|
240
|
-
// }
|
|
241
|
-
// directory = path.dirname(directory);
|
|
242
|
-
// }
|
|
243
|
-
// }
|
|
244
|
-
//
|
|
245
|
-
// async function resolvePromisesDeep(obj: any) {
|
|
246
|
-
// obj = await obj;
|
|
247
|
-
// if (obj && isPlainObject(obj)) {
|
|
248
|
-
// for (const k of Object.keys(obj)) {
|
|
249
|
-
// obj[k] = await resolvePromisesDeep(obj[k]);
|
|
250
|
-
// }
|
|
251
|
-
// }
|
|
252
|
-
// return obj;
|
|
253
|
-
// }
|
|
254
|
-
//
|
|
255
|
-
// export namespace ExtensionRegistry {
|
|
256
|
-
// export interface ExtensionPackageRecord {
|
|
257
|
-
// name: string;
|
|
258
|
-
// description?: string;
|
|
259
|
-
// version: string;
|
|
260
|
-
// }
|
|
261
|
-
//
|
|
262
|
-
// export interface ComponentRecord {
|
|
263
|
-
// package: string;
|
|
264
|
-
// ctor: Type<ComponentBase>;
|
|
265
|
-
// metadata: ComponentMetadata;
|
|
266
|
-
// }
|
|
267
|
-
//
|
|
268
|
-
// export interface ProcessorRecord {
|
|
269
|
-
// package: string;
|
|
270
|
-
// ctor: Type<ProcessorBase>;
|
|
271
|
-
// metadata: ProcessorMetadata;
|
|
272
|
-
// }
|
|
273
|
-
// }
|