import { ERPObjType, ERPObject } from "../../types/erp-types.js"; export interface CacheServiceConfig { tableName: string; ttl?: number; } export interface CacheMetrics { /** * Count of records by type in the cache * Key is the ERPObjType string value */ recordCounts: { [type: string]: number; }; } export interface CacheService { /** * Checks if a record has changed since last seen * @param type The type of record * @param key The unique key for the record * @param record The record to check * @returns true if the record has changed or is new */ hasChanged( type: ERPObjType, key: string, record: ERPObject ): Promise; /** * Stores a record in the cache * @param type The type of record * @param key The unique key for the record * @param record The record to store */ store(type: ERPObjType, key: string, record: ERPObject): Promise; /** * Checks if a record has changed and stores it if it has * @param type The type of record * @param key The unique key for the record * @param record The record to check and store * @returns true if the record was changed or is new */ upsert(type: ERPObjType, key: string, record: ERPObject): Promise; /** * Checks a batch of objects against the cache and separates them into duplicates and non-duplicates * @param type The type of objects * @param objects Array of objects to check * @param idField The field to use as the unique identifier * @returns Object containing arrays of duplicate and non-duplicate objects */ checkBatch( type: ERPObjType, objects: ERPObject[], idField: string ): Promise<{ duplicates: ERPObject[]; nonDuplicates: ERPObject[] }>; /** * Stores a batch of objects in the cache * @param type The type of objects * @param objects Array of objects to store * @param idField The field to use as the unique identifier */ storeBatch( type: ERPObjType, objects: ERPObject[], idField: string ): Promise; /** * Gets all records of a specific type * @param type The type of records to get * @returns Array of records with their values */ getRecordsByType(type: ERPObjType): Promise; /** * Removes all records of a specific type * @param type The type of records to remove */ removeRecordsByType(type: ERPObjType): Promise; /** * Removes a specific record * @param type The type of record * @param key The unique key for the record */ removeRecord(type: ERPObjType, key: string): Promise; /** * Removes expired records based on TTL */ removeExpiredObjects(): Promise; /** * Clears all records from the cache */ clear(): Promise; /** * Gets the current cache metrics * @returns The current cache metrics */ getMetrics(): CacheMetrics; /** * Cleans up resources and marks the service as destroyed */ destroy(): Promise; }