|
7 | 7 | * during the migration phase. |
8 | 8 | */ |
9 | 9 |
|
| 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 | + |
10 | 83 | export class ObjectStackKernel { |
11 | 84 | public ql: unknown = null; |
| 85 | + public metadata: MockMetadataRegistry; |
| 86 | + public hooks: MockHookManager; |
| 87 | + public actions: MockActionManager; |
12 | 88 | private plugins: any[] = []; |
13 | 89 | private driver: any = null; // Will be set by the ObjectQL app |
14 | 90 |
|
15 | 91 | constructor(plugins: any[] = []) { |
16 | 92 | this.plugins = plugins; |
| 93 | + this.metadata = new MockMetadataRegistry(); |
| 94 | + this.hooks = new MockHookManager(); |
| 95 | + this.actions = new MockActionManager(); |
17 | 96 | } |
18 | 97 |
|
19 | 98 | // Method to set the driver for delegation during migration |
@@ -130,3 +209,15 @@ export interface RuntimePlugin { |
130 | 209 | install?: (ctx: RuntimeContext) => void | Promise<void>; |
131 | 210 | onStart?: (ctx: RuntimeContext) => void | Promise<void>; |
132 | 211 | } |
| 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