@servlyadmin/runtime-core 0.1.0 → 0.1.2
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/dist/chunk-CIUQK4GA.js +182 -0
- package/dist/index.cjs +637 -149
- package/dist/index.d.cts +198 -5
- package/dist/index.d.ts +198 -5
- package/dist/index.js +441 -149
- package/dist/registry-GCCVK65D.js +16 -0
- package/package.json +2 -2
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// src/registry.ts
|
|
2
|
+
function createRegistry() {
|
|
3
|
+
const components = /* @__PURE__ */ new Map();
|
|
4
|
+
return {
|
|
5
|
+
get(id, version) {
|
|
6
|
+
if (version) {
|
|
7
|
+
const key = `${id}@${version}`;
|
|
8
|
+
if (components.has(key)) {
|
|
9
|
+
return components.get(key);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
for (const [key, component] of components) {
|
|
13
|
+
if (key.startsWith(`${id}@`)) {
|
|
14
|
+
return component;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return components.get(id);
|
|
18
|
+
},
|
|
19
|
+
has(id, version) {
|
|
20
|
+
if (version) {
|
|
21
|
+
return components.has(`${id}@${version}`);
|
|
22
|
+
}
|
|
23
|
+
for (const key of components.keys()) {
|
|
24
|
+
if (key.startsWith(`${id}@`) || key === id) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
},
|
|
30
|
+
set(id, version, component) {
|
|
31
|
+
components.set(`${id}@${version}`, component);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function buildRegistryFromBundle(data) {
|
|
36
|
+
const registry = createRegistry();
|
|
37
|
+
registry.set(data.id, data.version, {
|
|
38
|
+
layout: data.layout,
|
|
39
|
+
propsInterface: data.propsInterface
|
|
40
|
+
});
|
|
41
|
+
if (data.bundle) {
|
|
42
|
+
for (const [key, component] of Object.entries(data.bundle)) {
|
|
43
|
+
const [id, version] = key.split("@");
|
|
44
|
+
if (id && version) {
|
|
45
|
+
registry.set(id, version, component);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return registry;
|
|
50
|
+
}
|
|
51
|
+
function extractDependencies(elements) {
|
|
52
|
+
const dependencies = [];
|
|
53
|
+
for (const element of elements) {
|
|
54
|
+
const config = element.configuration;
|
|
55
|
+
if (!config) continue;
|
|
56
|
+
if (config.componentViewRef) {
|
|
57
|
+
dependencies.push({
|
|
58
|
+
id: config.componentViewRef,
|
|
59
|
+
version: config.componentViewVersion,
|
|
60
|
+
type: "viewRef",
|
|
61
|
+
elementId: element.i
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (config.blueprint) {
|
|
65
|
+
dependencies.push({
|
|
66
|
+
id: config.blueprint,
|
|
67
|
+
version: config.blueprintVersion,
|
|
68
|
+
type: "blueprint",
|
|
69
|
+
elementId: element.i
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return dependencies;
|
|
74
|
+
}
|
|
75
|
+
function extractDependenciesFromCode(code) {
|
|
76
|
+
const dependencies = [];
|
|
77
|
+
const pattern = /renderDynamicList\s*\(\s*\{[^}]*blueprint\s*:\s*["']([^"']+)["']/g;
|
|
78
|
+
let match;
|
|
79
|
+
while ((match = pattern.exec(code)) !== null) {
|
|
80
|
+
dependencies.push({
|
|
81
|
+
id: match[1],
|
|
82
|
+
type: "blueprint"
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return dependencies;
|
|
86
|
+
}
|
|
87
|
+
async function collectAllDependencies(rootId, rootVersion, fetchComponent, maxDepth = 10) {
|
|
88
|
+
const manifest = {};
|
|
89
|
+
const visited = /* @__PURE__ */ new Set();
|
|
90
|
+
async function collect(id, version, via, depth) {
|
|
91
|
+
if (depth > maxDepth) {
|
|
92
|
+
console.warn(`Max dependency depth (${maxDepth}) reached for ${id}`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const key = `${id}@${version || "latest"}`;
|
|
96
|
+
if (visited.has(key)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
visited.add(key);
|
|
100
|
+
try {
|
|
101
|
+
const component = await fetchComponent(id, version);
|
|
102
|
+
if (!component) {
|
|
103
|
+
console.warn(`Dependency not found: ${id}@${version || "latest"}`);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
manifest[id] = {
|
|
107
|
+
version: version || "latest",
|
|
108
|
+
resolved: component.version,
|
|
109
|
+
type: via ? "viewRef" : "viewRef",
|
|
110
|
+
// Will be set by caller
|
|
111
|
+
via
|
|
112
|
+
};
|
|
113
|
+
const nestedDeps = extractDependencies(component.layout);
|
|
114
|
+
for (const dep of nestedDeps) {
|
|
115
|
+
await collect(dep.id, dep.version, id, depth + 1);
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error(`Failed to fetch dependency ${id}:`, error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const rootComponent = await fetchComponent(rootId, rootVersion);
|
|
122
|
+
if (rootComponent) {
|
|
123
|
+
const rootDeps = extractDependencies(rootComponent.layout);
|
|
124
|
+
for (const dep of rootDeps) {
|
|
125
|
+
manifest[dep.id] = {
|
|
126
|
+
version: dep.version || "latest",
|
|
127
|
+
resolved: "",
|
|
128
|
+
// Will be filled when fetched
|
|
129
|
+
type: dep.type
|
|
130
|
+
};
|
|
131
|
+
await collect(dep.id, dep.version, void 0, 1);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return manifest;
|
|
135
|
+
}
|
|
136
|
+
function detectCircularDependencies(manifest) {
|
|
137
|
+
const graph = /* @__PURE__ */ new Map();
|
|
138
|
+
for (const [id, entry] of Object.entries(manifest)) {
|
|
139
|
+
if (entry.via) {
|
|
140
|
+
const deps = graph.get(entry.via) || [];
|
|
141
|
+
deps.push(id);
|
|
142
|
+
graph.set(entry.via, deps);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const visited = /* @__PURE__ */ new Set();
|
|
146
|
+
const stack = /* @__PURE__ */ new Set();
|
|
147
|
+
const path = [];
|
|
148
|
+
function dfs(node) {
|
|
149
|
+
if (stack.has(node)) {
|
|
150
|
+
const cycleStart = path.indexOf(node);
|
|
151
|
+
return [...path.slice(cycleStart), node];
|
|
152
|
+
}
|
|
153
|
+
if (visited.has(node)) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
visited.add(node);
|
|
157
|
+
stack.add(node);
|
|
158
|
+
path.push(node);
|
|
159
|
+
const neighbors = graph.get(node) || [];
|
|
160
|
+
for (const neighbor of neighbors) {
|
|
161
|
+
const cycle = dfs(neighbor);
|
|
162
|
+
if (cycle) return cycle;
|
|
163
|
+
}
|
|
164
|
+
stack.delete(node);
|
|
165
|
+
path.pop();
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
for (const node of graph.keys()) {
|
|
169
|
+
const cycle = dfs(node);
|
|
170
|
+
if (cycle) return cycle;
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export {
|
|
176
|
+
createRegistry,
|
|
177
|
+
buildRegistryFromBundle,
|
|
178
|
+
extractDependencies,
|
|
179
|
+
extractDependenciesFromCode,
|
|
180
|
+
collectAllDependencies,
|
|
181
|
+
detectCircularDependencies
|
|
182
|
+
};
|