Skip to content

Commit 8761077

Browse files
Copilothotlong
andcommitted
Fix platform-node tests - add MetadataRegistry and managers to runtime mock
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 761e431 commit 8761077

File tree

1 file changed

+91
-0
lines changed
  • packages/foundation/platform-node/test/__mocks__/@objectstack

1 file changed

+91
-0
lines changed

packages/foundation/platform-node/test/__mocks__/@objectstack/runtime.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,92 @@
77
* during the migration phase.
88
*/
99

10+
// Simple mock implementations of runtime managers
11+
class MockMetadataRegistry {
12+
private store = new Map<string, Map<string, any>>();
13+
14+
register(type: string, item: any): void {
15+
if (!this.store.has(type)) {
16+
this.store.set(type, new Map());
17+
}
18+
const typeMap = this.store.get(type)!;
19+
typeMap.set(item.id || item.name, item);
20+
}
21+
22+
get<T = any>(type: string, id: string): T | undefined {
23+
const typeMap = this.store.get(type);
24+
const item = typeMap?.get(id);
25+
return item?.content as T;
26+
}
27+
28+
list<T = any>(type: string): T[] {
29+
const typeMap = this.store.get(type);
30+
if (!typeMap) return [];
31+
return Array.from(typeMap.values()).map(item => item.content as T);
32+
}
33+
34+
unregister(type: string, id: string): boolean {
35+
const typeMap = this.store.get(type);
36+
if (!typeMap) return false;
37+
return typeMap.delete(id);
38+
}
39+
40+
getTypes(): string[] {
41+
return Array.from(this.store.keys());
42+
}
43+
44+
getEntry(type: string, id: string): any | undefined {
45+
const typeMap = this.store.get(type);
46+
return typeMap ? typeMap.get(id) : undefined;
47+
}
48+
49+
unregisterPackage(packageName: string): void {
50+
// Simple implementation - in real runtime this would filter by package
51+
for (const [type, typeMap] of this.store.entries()) {
52+
const toDelete: string[] = [];
53+
for (const [id, item] of typeMap.entries()) {
54+
if (item.packageName === packageName || item.package === packageName) {
55+
toDelete.push(id);
56+
}
57+
}
58+
toDelete.forEach(id => typeMap.delete(id));
59+
}
60+
}
61+
}
62+
63+
class MockHookManager {
64+
removePackage(packageName: string): void {
65+
// Mock implementation
66+
}
67+
68+
clear(): void {
69+
// Mock implementation
70+
}
71+
}
72+
73+
class MockActionManager {
74+
removePackage(packageName: string): void {
75+
// Mock implementation
76+
}
77+
78+
clear(): void {
79+
// Mock implementation
80+
}
81+
}
82+
1083
export class ObjectStackKernel {
1184
public ql: unknown = null;
85+
public metadata: MockMetadataRegistry;
86+
public hooks: MockHookManager;
87+
public actions: MockActionManager;
1288
private plugins: any[] = [];
1389
private driver: any = null; // Will be set by the ObjectQL app
1490

1591
constructor(plugins: any[] = []) {
1692
this.plugins = plugins;
93+
this.metadata = new MockMetadataRegistry();
94+
this.hooks = new MockHookManager();
95+
this.actions = new MockActionManager();
1796
}
1897

1998
// Method to set the driver for delegation during migration
@@ -130,3 +209,15 @@ export interface RuntimePlugin {
130209
install?: (ctx: RuntimeContext) => void | Promise<void>;
131210
onStart?: (ctx: RuntimeContext) => void | Promise<void>;
132211
}
212+
213+
// Export MetadataRegistry
214+
export { MockMetadataRegistry as MetadataRegistry };
215+
216+
export interface MetadataItem {
217+
type: string;
218+
id: string;
219+
content: unknown;
220+
packageName?: string;
221+
path?: string;
222+
package?: string;
223+
}

0 commit comments

Comments
 (0)