import { v4 as uuidv4 } from 'uuid'; import { JsonManager } from './json_manager'; export class MemoryManager extends JsonManager { constructor(filePath: string) { super(filePath); // Call the parent constructor to ensure file initialization } // Generate a new unique GUID and ensure it doesn't already exist in the file private generateUniqueGuid(): Promise { const generate = async (): Promise => { const guid = uuidv4(); const value = await this.readValue(guid); if (value === null) { return guid; } return generate(); }; return generate(); } // Store meta information with a unique GUID as the key public async storeMetaInformation(metaInfo: any): Promise { const guid = await this.generateUniqueGuid(); const success = await this.writeValue(guid, metaInfo); if (success) { return guid; // Return the unique GUID for future reference } else { throw new Error('Failed to store meta information.'); } } // Retrieve meta information using the GUID public retrieveMetaInformation(guid: string): Promise { return this.readValue(guid); } // Update meta information by merging new data into existing data public async updateMetaInformation(guid: string, newMetaInfo: any): Promise { return await this.writeValue(guid, newMetaInfo); } // Remove meta information using the GUID public removeMetaInformation(guid: string): Promise { return this.removeValue(guid); } }