@memberjunction/react-runtime 2.70.0
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/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +3 -0
- package/README.md +224 -0
- package/dist/compiler/babel-config.d.ts +40 -0
- package/dist/compiler/babel-config.d.ts.map +1 -0
- package/dist/compiler/babel-config.js +52 -0
- package/dist/compiler/component-compiler.d.ts +22 -0
- package/dist/compiler/component-compiler.d.ts.map +1 -0
- package/dist/compiler/component-compiler.js +188 -0
- package/dist/compiler/index.d.ts +3 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +13 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +95 -0
- package/dist/registry/component-registry.d.ts +32 -0
- package/dist/registry/component-registry.d.ts.map +1 -0
- package/dist/registry/component-registry.js +197 -0
- package/dist/registry/component-resolver.d.ts +29 -0
- package/dist/registry/component-resolver.d.ts.map +1 -0
- package/dist/registry/component-resolver.js +112 -0
- package/dist/registry/index.d.ts +3 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +7 -0
- package/dist/runtime/component-hierarchy.d.ts +44 -0
- package/dist/runtime/component-hierarchy.d.ts.map +1 -0
- package/dist/runtime/component-hierarchy.js +162 -0
- package/dist/runtime/component-wrapper.d.ts +18 -0
- package/dist/runtime/component-wrapper.d.ts.map +1 -0
- package/dist/runtime/component-wrapper.js +108 -0
- package/dist/runtime/error-boundary.d.ts +6 -0
- package/dist/runtime/error-boundary.d.ts.map +1 -0
- package/dist/runtime/error-boundary.js +139 -0
- package/dist/runtime/index.d.ts +5 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +31 -0
- package/dist/runtime/prop-builder.d.ts +16 -0
- package/dist/runtime/prop-builder.d.ts.map +1 -0
- package/dist/runtime/prop-builder.js +161 -0
- package/dist/types/index.d.ts +98 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/package.json +36 -0
- package/src/compiler/babel-config.ts +97 -0
- package/src/compiler/component-compiler.ts +366 -0
- package/src/compiler/index.ts +15 -0
- package/src/index.ts +125 -0
- package/src/registry/component-registry.ts +379 -0
- package/src/registry/component-resolver.ts +275 -0
- package/src/registry/index.ts +7 -0
- package/src/runtime/component-hierarchy.ts +346 -0
- package/src/runtime/component-wrapper.ts +249 -0
- package/src/runtime/error-boundary.ts +242 -0
- package/src/runtime/index.ts +45 -0
- package/src/runtime/prop-builder.ts +290 -0
- package/src/types/index.ts +226 -0
- package/tsconfig.json +37 -0
- package/tsconfig.tsbuildinfo +1 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createReactRuntime = exports.DEFAULT_CONFIGS = exports.VERSION = exports.countComponentsInHierarchy = exports.flattenComponentHierarchy = exports.validateComponentSpec = exports.registerComponentHierarchy = exports.ComponentHierarchyRegistrar = exports.extractPropPaths = exports.wrapCallbacksWithLogging = exports.createPropsTransformer = exports.mergeProps = exports.validateComponentProps = exports.normalizeStyles = exports.normalizeCallbacks = exports.buildComponentProps = exports.portalComponent = exports.withErrorHandler = exports.conditionalComponent = exports.injectProps = exports.lazyComponent = exports.memoizeComponent = exports.wrapComponent = exports.createErrorLogger = exports.formatComponentError = exports.withErrorBoundary = exports.createErrorBoundary = exports.ComponentResolver = exports.ComponentRegistry = exports.getJSXConfig = exports.validateBabelPresets = exports.getBabelConfig = exports.DEVELOPMENT_CONFIG = exports.PRODUCTION_CONFIG = exports.DEFAULT_PLUGINS = exports.DEFAULT_PRESETS = exports.ComponentCompiler = void 0;
|
|
18
|
+
const compiler_1 = require("./compiler");
|
|
19
|
+
const registry_1 = require("./registry");
|
|
20
|
+
const registry_2 = require("./registry");
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
var compiler_2 = require("./compiler");
|
|
23
|
+
Object.defineProperty(exports, "ComponentCompiler", { enumerable: true, get: function () { return compiler_2.ComponentCompiler; } });
|
|
24
|
+
var compiler_3 = require("./compiler");
|
|
25
|
+
Object.defineProperty(exports, "DEFAULT_PRESETS", { enumerable: true, get: function () { return compiler_3.DEFAULT_PRESETS; } });
|
|
26
|
+
Object.defineProperty(exports, "DEFAULT_PLUGINS", { enumerable: true, get: function () { return compiler_3.DEFAULT_PLUGINS; } });
|
|
27
|
+
Object.defineProperty(exports, "PRODUCTION_CONFIG", { enumerable: true, get: function () { return compiler_3.PRODUCTION_CONFIG; } });
|
|
28
|
+
Object.defineProperty(exports, "DEVELOPMENT_CONFIG", { enumerable: true, get: function () { return compiler_3.DEVELOPMENT_CONFIG; } });
|
|
29
|
+
Object.defineProperty(exports, "getBabelConfig", { enumerable: true, get: function () { return compiler_3.getBabelConfig; } });
|
|
30
|
+
Object.defineProperty(exports, "validateBabelPresets", { enumerable: true, get: function () { return compiler_3.validateBabelPresets; } });
|
|
31
|
+
Object.defineProperty(exports, "getJSXConfig", { enumerable: true, get: function () { return compiler_3.getJSXConfig; } });
|
|
32
|
+
var registry_3 = require("./registry");
|
|
33
|
+
Object.defineProperty(exports, "ComponentRegistry", { enumerable: true, get: function () { return registry_3.ComponentRegistry; } });
|
|
34
|
+
var registry_4 = require("./registry");
|
|
35
|
+
Object.defineProperty(exports, "ComponentResolver", { enumerable: true, get: function () { return registry_4.ComponentResolver; } });
|
|
36
|
+
var runtime_1 = require("./runtime");
|
|
37
|
+
Object.defineProperty(exports, "createErrorBoundary", { enumerable: true, get: function () { return runtime_1.createErrorBoundary; } });
|
|
38
|
+
Object.defineProperty(exports, "withErrorBoundary", { enumerable: true, get: function () { return runtime_1.withErrorBoundary; } });
|
|
39
|
+
Object.defineProperty(exports, "formatComponentError", { enumerable: true, get: function () { return runtime_1.formatComponentError; } });
|
|
40
|
+
Object.defineProperty(exports, "createErrorLogger", { enumerable: true, get: function () { return runtime_1.createErrorLogger; } });
|
|
41
|
+
var runtime_2 = require("./runtime");
|
|
42
|
+
Object.defineProperty(exports, "wrapComponent", { enumerable: true, get: function () { return runtime_2.wrapComponent; } });
|
|
43
|
+
Object.defineProperty(exports, "memoizeComponent", { enumerable: true, get: function () { return runtime_2.memoizeComponent; } });
|
|
44
|
+
Object.defineProperty(exports, "lazyComponent", { enumerable: true, get: function () { return runtime_2.lazyComponent; } });
|
|
45
|
+
Object.defineProperty(exports, "injectProps", { enumerable: true, get: function () { return runtime_2.injectProps; } });
|
|
46
|
+
Object.defineProperty(exports, "conditionalComponent", { enumerable: true, get: function () { return runtime_2.conditionalComponent; } });
|
|
47
|
+
Object.defineProperty(exports, "withErrorHandler", { enumerable: true, get: function () { return runtime_2.withErrorHandler; } });
|
|
48
|
+
Object.defineProperty(exports, "portalComponent", { enumerable: true, get: function () { return runtime_2.portalComponent; } });
|
|
49
|
+
var runtime_3 = require("./runtime");
|
|
50
|
+
Object.defineProperty(exports, "buildComponentProps", { enumerable: true, get: function () { return runtime_3.buildComponentProps; } });
|
|
51
|
+
Object.defineProperty(exports, "normalizeCallbacks", { enumerable: true, get: function () { return runtime_3.normalizeCallbacks; } });
|
|
52
|
+
Object.defineProperty(exports, "normalizeStyles", { enumerable: true, get: function () { return runtime_3.normalizeStyles; } });
|
|
53
|
+
Object.defineProperty(exports, "validateComponentProps", { enumerable: true, get: function () { return runtime_3.validateComponentProps; } });
|
|
54
|
+
Object.defineProperty(exports, "mergeProps", { enumerable: true, get: function () { return runtime_3.mergeProps; } });
|
|
55
|
+
Object.defineProperty(exports, "createPropsTransformer", { enumerable: true, get: function () { return runtime_3.createPropsTransformer; } });
|
|
56
|
+
Object.defineProperty(exports, "wrapCallbacksWithLogging", { enumerable: true, get: function () { return runtime_3.wrapCallbacksWithLogging; } });
|
|
57
|
+
Object.defineProperty(exports, "extractPropPaths", { enumerable: true, get: function () { return runtime_3.extractPropPaths; } });
|
|
58
|
+
var runtime_4 = require("./runtime");
|
|
59
|
+
Object.defineProperty(exports, "ComponentHierarchyRegistrar", { enumerable: true, get: function () { return runtime_4.ComponentHierarchyRegistrar; } });
|
|
60
|
+
Object.defineProperty(exports, "registerComponentHierarchy", { enumerable: true, get: function () { return runtime_4.registerComponentHierarchy; } });
|
|
61
|
+
Object.defineProperty(exports, "validateComponentSpec", { enumerable: true, get: function () { return runtime_4.validateComponentSpec; } });
|
|
62
|
+
Object.defineProperty(exports, "flattenComponentHierarchy", { enumerable: true, get: function () { return runtime_4.flattenComponentHierarchy; } });
|
|
63
|
+
Object.defineProperty(exports, "countComponentsInHierarchy", { enumerable: true, get: function () { return runtime_4.countComponentsInHierarchy; } });
|
|
64
|
+
exports.VERSION = '2.69.1';
|
|
65
|
+
exports.DEFAULT_CONFIGS = {
|
|
66
|
+
compiler: {
|
|
67
|
+
babel: {
|
|
68
|
+
presets: ['react'],
|
|
69
|
+
plugins: []
|
|
70
|
+
},
|
|
71
|
+
minify: false,
|
|
72
|
+
sourceMaps: false,
|
|
73
|
+
cache: true,
|
|
74
|
+
maxCacheSize: 100
|
|
75
|
+
},
|
|
76
|
+
registry: {
|
|
77
|
+
maxComponents: 1000,
|
|
78
|
+
cleanupInterval: 60000,
|
|
79
|
+
useLRU: true,
|
|
80
|
+
enableNamespaces: true
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
function createReactRuntime(babelInstance, config) {
|
|
84
|
+
const compiler = new compiler_1.ComponentCompiler(config?.compiler);
|
|
85
|
+
compiler.setBabelInstance(babelInstance);
|
|
86
|
+
const registry = new registry_1.ComponentRegistry(config?.registry);
|
|
87
|
+
const resolver = new registry_2.ComponentResolver(registry);
|
|
88
|
+
return {
|
|
89
|
+
compiler,
|
|
90
|
+
registry,
|
|
91
|
+
resolver,
|
|
92
|
+
version: exports.VERSION
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
exports.createReactRuntime = createReactRuntime;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ComponentMetadata, RegistryConfig } from '../types';
|
|
2
|
+
export declare class ComponentRegistry {
|
|
3
|
+
private registry;
|
|
4
|
+
private config;
|
|
5
|
+
private cleanupTimer?;
|
|
6
|
+
constructor(config?: Partial<RegistryConfig>);
|
|
7
|
+
register(name: string, component: any, namespace?: string, version?: string, tags?: string[]): ComponentMetadata;
|
|
8
|
+
get(name: string, namespace?: string, version?: string): any;
|
|
9
|
+
has(name: string, namespace?: string, version?: string): boolean;
|
|
10
|
+
unregister(name: string, namespace?: string, version?: string): boolean;
|
|
11
|
+
getNamespace(namespace: string): ComponentMetadata[];
|
|
12
|
+
getNamespaces(): string[];
|
|
13
|
+
getByTags(tags: string[]): ComponentMetadata[];
|
|
14
|
+
release(name: string, namespace?: string, version?: string): void;
|
|
15
|
+
clear(): void;
|
|
16
|
+
size(): number;
|
|
17
|
+
cleanup(force?: boolean): number;
|
|
18
|
+
getStats(): {
|
|
19
|
+
totalComponents: number;
|
|
20
|
+
namespaces: number;
|
|
21
|
+
totalRefCount: number;
|
|
22
|
+
oldestComponent?: Date;
|
|
23
|
+
newestComponent?: Date;
|
|
24
|
+
};
|
|
25
|
+
destroy(): void;
|
|
26
|
+
private generateRegistryKey;
|
|
27
|
+
private findLatestVersion;
|
|
28
|
+
private evictLRU;
|
|
29
|
+
private startCleanupTimer;
|
|
30
|
+
private stopCleanupTimer;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=component-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-registry.d.ts","sourceRoot":"","sources":["../../src/registry/component-registry.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,iBAAiB,EACjB,cAAc,EACf,MAAM,UAAU,CAAC;AAgBlB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,YAAY,CAAC,CAA0B;gBAMnC,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;IAmB5C,QAAQ,CACN,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,GAAG,EACd,SAAS,GAAE,MAAiB,EAC5B,OAAO,GAAE,MAAa,EACtB,IAAI,CAAC,EAAE,MAAM,EAAE,GACd,iBAAiB;IAuCpB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAAiB,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,GAAG;IAyBtE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAAiB,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO;IAe1E,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAAiB,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO;IAejF,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,EAAE;IAgBpD,aAAa,IAAI,MAAM,EAAE;IAezB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,iBAAiB,EAAE;IAkB9C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAAiB,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAgB3E,KAAK,IAAI,IAAI;IAQb,IAAI,IAAI,MAAM;IASd,OAAO,CAAC,KAAK,GAAE,OAAe,GAAG,MAAM;IAyBvC,QAAQ,IAAI;QACV,eAAe,EAAE,MAAM,CAAC;QACxB,UAAU,EAAE,MAAM,CAAC;QACnB,aAAa,EAAE,MAAM,CAAC;QACtB,eAAe,CAAC,EAAE,IAAI,CAAC;QACvB,eAAe,CAAC,EAAE,IAAI,CAAC;KACxB;IA6BD,OAAO,IAAI,IAAI;IAYf,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,iBAAiB;IAoBzB,OAAO,CAAC,QAAQ;IAsBhB,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,gBAAgB;CAMzB"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentRegistry = void 0;
|
|
4
|
+
const DEFAULT_REGISTRY_CONFIG = {
|
|
5
|
+
maxComponents: 1000,
|
|
6
|
+
cleanupInterval: 60000,
|
|
7
|
+
useLRU: true,
|
|
8
|
+
enableNamespaces: true
|
|
9
|
+
};
|
|
10
|
+
class ComponentRegistry {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = { ...DEFAULT_REGISTRY_CONFIG, ...config };
|
|
13
|
+
this.registry = new Map();
|
|
14
|
+
if (this.config.cleanupInterval > 0) {
|
|
15
|
+
this.startCleanupTimer();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
register(name, component, namespace = 'Global', version = 'v1', tags) {
|
|
19
|
+
const id = this.generateRegistryKey(name, namespace, version);
|
|
20
|
+
const metadata = {
|
|
21
|
+
id,
|
|
22
|
+
name,
|
|
23
|
+
version,
|
|
24
|
+
namespace,
|
|
25
|
+
registeredAt: new Date(),
|
|
26
|
+
tags
|
|
27
|
+
};
|
|
28
|
+
const entry = {
|
|
29
|
+
component,
|
|
30
|
+
metadata,
|
|
31
|
+
lastAccessed: new Date(),
|
|
32
|
+
refCount: 0
|
|
33
|
+
};
|
|
34
|
+
if (this.registry.size >= this.config.maxComponents && this.config.useLRU) {
|
|
35
|
+
this.evictLRU();
|
|
36
|
+
}
|
|
37
|
+
this.registry.set(id, entry);
|
|
38
|
+
return metadata;
|
|
39
|
+
}
|
|
40
|
+
get(name, namespace = 'Global', version) {
|
|
41
|
+
const id = version
|
|
42
|
+
? this.generateRegistryKey(name, namespace, version)
|
|
43
|
+
: this.findLatestVersion(name, namespace);
|
|
44
|
+
if (!id)
|
|
45
|
+
return undefined;
|
|
46
|
+
const entry = this.registry.get(id);
|
|
47
|
+
if (entry) {
|
|
48
|
+
entry.lastAccessed = new Date();
|
|
49
|
+
entry.refCount++;
|
|
50
|
+
return entry.component;
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
has(name, namespace = 'Global', version) {
|
|
55
|
+
const id = version
|
|
56
|
+
? this.generateRegistryKey(name, namespace, version)
|
|
57
|
+
: this.findLatestVersion(name, namespace);
|
|
58
|
+
return id ? this.registry.has(id) : false;
|
|
59
|
+
}
|
|
60
|
+
unregister(name, namespace = 'Global', version) {
|
|
61
|
+
const id = version
|
|
62
|
+
? this.generateRegistryKey(name, namespace, version)
|
|
63
|
+
: this.findLatestVersion(name, namespace);
|
|
64
|
+
if (!id)
|
|
65
|
+
return false;
|
|
66
|
+
return this.registry.delete(id);
|
|
67
|
+
}
|
|
68
|
+
getNamespace(namespace) {
|
|
69
|
+
const components = [];
|
|
70
|
+
for (const entry of this.registry.values()) {
|
|
71
|
+
if (entry.metadata.namespace === namespace) {
|
|
72
|
+
components.push(entry.metadata);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return components;
|
|
76
|
+
}
|
|
77
|
+
getNamespaces() {
|
|
78
|
+
const namespaces = new Set();
|
|
79
|
+
for (const entry of this.registry.values()) {
|
|
80
|
+
namespaces.add(entry.metadata.namespace);
|
|
81
|
+
}
|
|
82
|
+
return Array.from(namespaces);
|
|
83
|
+
}
|
|
84
|
+
getByTags(tags) {
|
|
85
|
+
const components = [];
|
|
86
|
+
for (const entry of this.registry.values()) {
|
|
87
|
+
if (entry.metadata.tags?.some(tag => tags.includes(tag))) {
|
|
88
|
+
components.push(entry.metadata);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return components;
|
|
92
|
+
}
|
|
93
|
+
release(name, namespace = 'Global', version) {
|
|
94
|
+
const id = version
|
|
95
|
+
? this.generateRegistryKey(name, namespace, version)
|
|
96
|
+
: this.findLatestVersion(name, namespace);
|
|
97
|
+
if (!id)
|
|
98
|
+
return;
|
|
99
|
+
const entry = this.registry.get(id);
|
|
100
|
+
if (entry && entry.refCount > 0) {
|
|
101
|
+
entry.refCount--;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
clear() {
|
|
105
|
+
this.registry.clear();
|
|
106
|
+
}
|
|
107
|
+
size() {
|
|
108
|
+
return this.registry.size;
|
|
109
|
+
}
|
|
110
|
+
cleanup(force = false) {
|
|
111
|
+
const toRemove = [];
|
|
112
|
+
const now = Date.now();
|
|
113
|
+
for (const [id, entry] of this.registry) {
|
|
114
|
+
const timeSinceAccess = now - entry.lastAccessed.getTime();
|
|
115
|
+
const isUnused = entry.refCount === 0 && timeSinceAccess > this.config.cleanupInterval;
|
|
116
|
+
if (force || isUnused) {
|
|
117
|
+
toRemove.push(id);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
for (const id of toRemove) {
|
|
121
|
+
this.registry.delete(id);
|
|
122
|
+
}
|
|
123
|
+
return toRemove.length;
|
|
124
|
+
}
|
|
125
|
+
getStats() {
|
|
126
|
+
let totalRefCount = 0;
|
|
127
|
+
let oldest;
|
|
128
|
+
let newest;
|
|
129
|
+
for (const entry of this.registry.values()) {
|
|
130
|
+
totalRefCount += entry.refCount;
|
|
131
|
+
if (!oldest || entry.metadata.registeredAt < oldest) {
|
|
132
|
+
oldest = entry.metadata.registeredAt;
|
|
133
|
+
}
|
|
134
|
+
if (!newest || entry.metadata.registeredAt > newest) {
|
|
135
|
+
newest = entry.metadata.registeredAt;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
totalComponents: this.registry.size,
|
|
140
|
+
namespaces: this.getNamespaces().length,
|
|
141
|
+
totalRefCount,
|
|
142
|
+
oldestComponent: oldest,
|
|
143
|
+
newestComponent: newest
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
destroy() {
|
|
147
|
+
this.stopCleanupTimer();
|
|
148
|
+
this.clear();
|
|
149
|
+
}
|
|
150
|
+
generateRegistryKey(name, namespace, version) {
|
|
151
|
+
if (this.config.enableNamespaces) {
|
|
152
|
+
return `${namespace}::${name}@${version}`;
|
|
153
|
+
}
|
|
154
|
+
return `${name}@${version}`;
|
|
155
|
+
}
|
|
156
|
+
findLatestVersion(name, namespace) {
|
|
157
|
+
let latestKey;
|
|
158
|
+
let latestDate;
|
|
159
|
+
for (const [key, entry] of this.registry) {
|
|
160
|
+
if (entry.metadata.name === name &&
|
|
161
|
+
entry.metadata.namespace === namespace) {
|
|
162
|
+
if (!latestDate || entry.metadata.registeredAt > latestDate) {
|
|
163
|
+
latestDate = entry.metadata.registeredAt;
|
|
164
|
+
latestKey = key;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return latestKey;
|
|
169
|
+
}
|
|
170
|
+
evictLRU() {
|
|
171
|
+
let lruKey;
|
|
172
|
+
let lruTime;
|
|
173
|
+
for (const [key, entry] of this.registry) {
|
|
174
|
+
if (entry.refCount > 0)
|
|
175
|
+
continue;
|
|
176
|
+
if (!lruTime || entry.lastAccessed < lruTime) {
|
|
177
|
+
lruTime = entry.lastAccessed;
|
|
178
|
+
lruKey = key;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (lruKey) {
|
|
182
|
+
this.registry.delete(lruKey);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
startCleanupTimer() {
|
|
186
|
+
this.cleanupTimer = setInterval(() => {
|
|
187
|
+
this.cleanup();
|
|
188
|
+
}, this.config.cleanupInterval);
|
|
189
|
+
}
|
|
190
|
+
stopCleanupTimer() {
|
|
191
|
+
if (this.cleanupTimer) {
|
|
192
|
+
clearInterval(this.cleanupTimer);
|
|
193
|
+
this.cleanupTimer = undefined;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
exports.ComponentRegistry = ComponentRegistry;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ComponentRegistry } from './component-registry';
|
|
2
|
+
export interface ComponentSpec {
|
|
3
|
+
componentName: string;
|
|
4
|
+
componentCode?: string;
|
|
5
|
+
childComponents?: ComponentSpec[];
|
|
6
|
+
components?: ComponentSpec[];
|
|
7
|
+
}
|
|
8
|
+
export interface ResolvedComponents {
|
|
9
|
+
[componentName: string]: any;
|
|
10
|
+
}
|
|
11
|
+
export declare class ComponentResolver {
|
|
12
|
+
private registry;
|
|
13
|
+
constructor(registry: ComponentRegistry);
|
|
14
|
+
resolveComponents(spec: ComponentSpec, namespace?: string): ResolvedComponents;
|
|
15
|
+
private resolveComponentHierarchy;
|
|
16
|
+
validateDependencies(spec: ComponentSpec, namespace?: string): string[];
|
|
17
|
+
private checkDependencies;
|
|
18
|
+
getDependencyGraph(spec: ComponentSpec): Map<string, string[]>;
|
|
19
|
+
private buildDependencyGraph;
|
|
20
|
+
getLoadOrder(spec: ComponentSpec): string[];
|
|
21
|
+
private topologicalSortDFS;
|
|
22
|
+
resolveInOrder(spec: ComponentSpec, namespace?: string): Array<{
|
|
23
|
+
name: string;
|
|
24
|
+
component: any;
|
|
25
|
+
}>;
|
|
26
|
+
flattenComponentSpecs(spec: ComponentSpec): ComponentSpec[];
|
|
27
|
+
private collectComponentSpecs;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=component-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-resolver.d.ts","sourceRoot":"","sources":["../../src/registry/component-resolver.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAKzD,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,aAAa,EAAE,CAAC;IAClC,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;CAC9B;AAKD,MAAM,WAAW,kBAAkB;IACjC,CAAC,aAAa,EAAE,MAAM,GAAG,GAAG,CAAC;CAC9B;AAMD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAoB;gBAMxB,QAAQ,EAAE,iBAAiB;IAUvC,iBAAiB,CAAC,IAAI,EAAE,aAAa,EAAE,SAAS,GAAE,MAAiB,GAAG,kBAAkB;IAgBxF,OAAO,CAAC,yBAAyB;IAgCjC,oBAAoB,CAAC,IAAI,EAAE,aAAa,EAAE,SAAS,GAAE,MAAiB,GAAG,MAAM,EAAE;IAgBjF,OAAO,CAAC,iBAAiB;IA0BzB,kBAAkB,CAAC,IAAI,EAAE,aAAa,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAe9D,OAAO,CAAC,oBAAoB;IAwB5B,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,EAAE;IAuB3C,OAAO,CAAC,kBAAkB;IAwB1B,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,SAAS,GAAE,MAAiB,GAAG,KAAK,CAAC;QACvE,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,GAAG,CAAC;KAChB,CAAC;IAmBF,qBAAqB,CAAC,IAAI,EAAE,aAAa,GAAG,aAAa,EAAE;IAe3D,OAAO,CAAC,qBAAqB;CAe9B"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentResolver = void 0;
|
|
4
|
+
class ComponentResolver {
|
|
5
|
+
constructor(registry) {
|
|
6
|
+
this.registry = registry;
|
|
7
|
+
}
|
|
8
|
+
resolveComponents(spec, namespace = 'Global') {
|
|
9
|
+
const resolved = {};
|
|
10
|
+
this.resolveComponentHierarchy(spec, resolved, namespace);
|
|
11
|
+
return resolved;
|
|
12
|
+
}
|
|
13
|
+
resolveComponentHierarchy(spec, resolved, namespace, visited = new Set()) {
|
|
14
|
+
if (visited.has(spec.componentName)) {
|
|
15
|
+
console.warn(`Circular dependency detected for component: ${spec.componentName}`);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
visited.add(spec.componentName);
|
|
19
|
+
const component = this.registry.get(spec.componentName, namespace);
|
|
20
|
+
if (component) {
|
|
21
|
+
resolved[spec.componentName] = component;
|
|
22
|
+
}
|
|
23
|
+
const children = spec.childComponents || spec.components || [];
|
|
24
|
+
for (const child of children) {
|
|
25
|
+
this.resolveComponentHierarchy(child, resolved, namespace, visited);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
validateDependencies(spec, namespace = 'Global') {
|
|
29
|
+
const missing = [];
|
|
30
|
+
const checked = new Set();
|
|
31
|
+
this.checkDependencies(spec, namespace, missing, checked);
|
|
32
|
+
return missing;
|
|
33
|
+
}
|
|
34
|
+
checkDependencies(spec, namespace, missing, checked) {
|
|
35
|
+
if (checked.has(spec.componentName))
|
|
36
|
+
return;
|
|
37
|
+
checked.add(spec.componentName);
|
|
38
|
+
if (!this.registry.has(spec.componentName, namespace)) {
|
|
39
|
+
missing.push(spec.componentName);
|
|
40
|
+
}
|
|
41
|
+
const children = spec.childComponents || spec.components || [];
|
|
42
|
+
for (const child of children) {
|
|
43
|
+
this.checkDependencies(child, namespace, missing, checked);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
getDependencyGraph(spec) {
|
|
47
|
+
const graph = new Map();
|
|
48
|
+
const visited = new Set();
|
|
49
|
+
this.buildDependencyGraph(spec, graph, visited);
|
|
50
|
+
return graph;
|
|
51
|
+
}
|
|
52
|
+
buildDependencyGraph(spec, graph, visited) {
|
|
53
|
+
if (visited.has(spec.componentName))
|
|
54
|
+
return;
|
|
55
|
+
visited.add(spec.componentName);
|
|
56
|
+
const children = spec.childComponents || spec.components || [];
|
|
57
|
+
const dependencies = children.map(child => child.componentName);
|
|
58
|
+
graph.set(spec.componentName, dependencies);
|
|
59
|
+
for (const child of children) {
|
|
60
|
+
this.buildDependencyGraph(child, graph, visited);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
getLoadOrder(spec) {
|
|
64
|
+
const graph = this.getDependencyGraph(spec);
|
|
65
|
+
const visited = new Set();
|
|
66
|
+
const stack = [];
|
|
67
|
+
for (const node of graph.keys()) {
|
|
68
|
+
if (!visited.has(node)) {
|
|
69
|
+
this.topologicalSortDFS(node, graph, visited, stack);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return stack.reverse();
|
|
73
|
+
}
|
|
74
|
+
topologicalSortDFS(node, graph, visited, stack) {
|
|
75
|
+
visited.add(node);
|
|
76
|
+
const dependencies = graph.get(node) || [];
|
|
77
|
+
for (const dep of dependencies) {
|
|
78
|
+
if (!visited.has(dep)) {
|
|
79
|
+
this.topologicalSortDFS(dep, graph, visited, stack);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
stack.push(node);
|
|
83
|
+
}
|
|
84
|
+
resolveInOrder(spec, namespace = 'Global') {
|
|
85
|
+
const loadOrder = this.getLoadOrder(spec);
|
|
86
|
+
const resolved = [];
|
|
87
|
+
for (const name of loadOrder) {
|
|
88
|
+
const component = this.registry.get(name, namespace);
|
|
89
|
+
if (component) {
|
|
90
|
+
resolved.push({ name, component });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return resolved;
|
|
94
|
+
}
|
|
95
|
+
flattenComponentSpecs(spec) {
|
|
96
|
+
const flattened = [];
|
|
97
|
+
const visited = new Set();
|
|
98
|
+
this.collectComponentSpecs(spec, flattened, visited);
|
|
99
|
+
return flattened;
|
|
100
|
+
}
|
|
101
|
+
collectComponentSpecs(spec, collected, visited) {
|
|
102
|
+
if (visited.has(spec.componentName))
|
|
103
|
+
return;
|
|
104
|
+
visited.add(spec.componentName);
|
|
105
|
+
collected.push(spec);
|
|
106
|
+
const children = spec.childComponents || spec.components || [];
|
|
107
|
+
for (const child of children) {
|
|
108
|
+
this.collectComponentSpecs(child, collected, visited);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.ComponentResolver = ComponentResolver;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentResolver = exports.ComponentRegistry = void 0;
|
|
4
|
+
var component_registry_1 = require("./component-registry");
|
|
5
|
+
Object.defineProperty(exports, "ComponentRegistry", { enumerable: true, get: function () { return component_registry_1.ComponentRegistry; } });
|
|
6
|
+
var component_resolver_1 = require("./component-resolver");
|
|
7
|
+
Object.defineProperty(exports, "ComponentResolver", { enumerable: true, get: function () { return component_resolver_1.ComponentResolver; } });
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ComponentStyles, RuntimeContext } from '../types';
|
|
2
|
+
import { ComponentCompiler } from '../compiler';
|
|
3
|
+
import { ComponentRegistry } from '../registry';
|
|
4
|
+
import { ComponentSpec } from '../registry/component-resolver';
|
|
5
|
+
export interface HierarchyRegistrationResult {
|
|
6
|
+
success: boolean;
|
|
7
|
+
registeredComponents: string[];
|
|
8
|
+
errors: ComponentRegistrationError[];
|
|
9
|
+
warnings: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface ComponentRegistrationError {
|
|
12
|
+
componentName: string;
|
|
13
|
+
error: string;
|
|
14
|
+
phase: 'compilation' | 'registration' | 'validation';
|
|
15
|
+
}
|
|
16
|
+
export interface HierarchyRegistrationOptions {
|
|
17
|
+
styles?: ComponentStyles;
|
|
18
|
+
namespace?: string;
|
|
19
|
+
version?: string;
|
|
20
|
+
continueOnError?: boolean;
|
|
21
|
+
allowOverride?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare class ComponentHierarchyRegistrar {
|
|
24
|
+
private compiler;
|
|
25
|
+
private registry;
|
|
26
|
+
private runtimeContext;
|
|
27
|
+
constructor(compiler: ComponentCompiler, registry: ComponentRegistry, runtimeContext: RuntimeContext);
|
|
28
|
+
registerHierarchy(rootSpec: ComponentSpec, options?: HierarchyRegistrationOptions): Promise<HierarchyRegistrationResult>;
|
|
29
|
+
registerSingleComponent(spec: ComponentSpec, options: {
|
|
30
|
+
styles?: ComponentStyles;
|
|
31
|
+
namespace?: string;
|
|
32
|
+
version?: string;
|
|
33
|
+
allowOverride?: boolean;
|
|
34
|
+
}): Promise<{
|
|
35
|
+
success: boolean;
|
|
36
|
+
error?: ComponentRegistrationError;
|
|
37
|
+
}>;
|
|
38
|
+
private registerChildComponents;
|
|
39
|
+
}
|
|
40
|
+
export declare function registerComponentHierarchy(rootSpec: ComponentSpec, compiler: ComponentCompiler, registry: ComponentRegistry, runtimeContext: RuntimeContext, options?: HierarchyRegistrationOptions): Promise<HierarchyRegistrationResult>;
|
|
41
|
+
export declare function validateComponentSpec(spec: ComponentSpec): string[];
|
|
42
|
+
export declare function flattenComponentHierarchy(rootSpec: ComponentSpec): ComponentSpec[];
|
|
43
|
+
export declare function countComponentsInHierarchy(rootSpec: ComponentSpec, includeEmpty?: boolean): number;
|
|
44
|
+
//# sourceMappingURL=component-hierarchy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-hierarchy.d.ts","sourceRoot":"","sources":["../../src/runtime/component-hierarchy.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,eAAe,EACf,cAAc,EACf,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAK/D,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,OAAO,CAAC;IACjB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,MAAM,EAAE,0BAA0B,EAAE,CAAC;IACrC,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAKD,MAAM,WAAW,0BAA0B;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,aAAa,GAAG,cAAc,GAAG,YAAY,CAAC;CACtD;AAKD,MAAM,WAAW,4BAA4B;IAE3C,MAAM,CAAC,EAAE,eAAe,CAAC;IAEzB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAKD,qBAAa,2BAA2B;IAEpC,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,cAAc;gBAFd,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,iBAAiB,EAC3B,cAAc,EAAE,cAAc;IASlC,iBAAiB,CACrB,QAAQ,EAAE,aAAa,EACvB,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,2BAA2B,CAAC;IAsDjC,uBAAuB,CAC3B,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE;QACP,MAAM,CAAC,EAAE,eAAe,CAAC;QACzB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,GACA,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,0BAA0B,CAAA;KAAE,CAAC;YA8EtD,uBAAuB;CAwCtC;AAWD,wBAAsB,0BAA0B,CAC9C,QAAQ,EAAE,aAAa,EACvB,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,iBAAiB,EAC3B,cAAc,EAAE,cAAc,EAC9B,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,2BAA2B,CAAC,CAGtC;AAOD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,EAAE,CA2BnE;AAOD,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,aAAa,GAAG,aAAa,EAAE,CASlF;AAQD,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,aAAa,EACvB,YAAY,GAAE,OAAe,GAC5B,MAAM,CAaR"}
|