|
| 1 | +/** |
| 2 | + * Mock for @objectstack/objectql |
| 3 | + * Provides minimal mock implementations for ObjectQL and SchemaRegistry |
| 4 | + */ |
| 5 | + |
| 6 | +export class ObjectQL { |
| 7 | + constructor() {} |
| 8 | +} |
| 9 | + |
| 10 | +export class SchemaRegistry { |
| 11 | + // Named 'metadata' to match what app.ts expects in unregisterPackage |
| 12 | + private static metadata = new Map<string, Map<string, any>>(); |
| 13 | + |
| 14 | + constructor() {} |
| 15 | + |
| 16 | + static registerItem(type: string, item: any, idField: string = 'id'): void { |
| 17 | + if (!SchemaRegistry.metadata.has(type)) { |
| 18 | + SchemaRegistry.metadata.set(type, new Map()); |
| 19 | + } |
| 20 | + const typeMap = SchemaRegistry.metadata.get(type)!; |
| 21 | + const id = item[idField]; |
| 22 | + typeMap.set(id, item); |
| 23 | + } |
| 24 | + |
| 25 | + static getItem(type: string, id: string): any { |
| 26 | + const typeMap = SchemaRegistry.metadata.get(type); |
| 27 | + return typeMap ? typeMap.get(id) : undefined; |
| 28 | + } |
| 29 | + |
| 30 | + static listItems(type: string): any[] { |
| 31 | + const typeMap = SchemaRegistry.metadata.get(type); |
| 32 | + return typeMap ? Array.from(typeMap.values()) : []; |
| 33 | + } |
| 34 | + |
| 35 | + static unregisterPackage(packageName: string): void { |
| 36 | + for (const typeMap of SchemaRegistry.metadata.values()) { |
| 37 | + const toDelete: string[] = []; |
| 38 | + for (const [id, item] of typeMap.entries()) { |
| 39 | + if (item.package === packageName || item.packageName === packageName) { |
| 40 | + toDelete.push(id); |
| 41 | + } |
| 42 | + } |
| 43 | + toDelete.forEach(id => typeMap.delete(id)); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + static clear(): void { |
| 48 | + SchemaRegistry.metadata.clear(); |
| 49 | + } |
| 50 | + |
| 51 | + register(schema: any): void {} |
| 52 | + get(name: string): any { return null; } |
| 53 | + list(): any[] { return []; } |
| 54 | +} |
| 55 | + |
| 56 | +export interface ObjectStackProtocolImplementation { |
| 57 | + name: string; |
| 58 | + handle(request: any): Promise<any>; |
| 59 | +} |
0 commit comments