import { AdapterError } from "@/domain/spreadsheet-adapter/errors"; import { assertStorageKey } from "@/domain/spreadsheet-adapter/filenames"; export interface ObjectStorage { put(key: string, body: Buffer): Promise; get(key: string): Promise; delete(key: string): Promise; /** Listagem completa do prefixo. Implementações remotas devem paginar. */ list(prefix: string): Promise; /** Verdadeiro quando o bucket responde. Usado pelo health check. */ healthcheck(): Promise; } export class MemoryStorage implements ObjectStorage { private readonly objects = new Map(); async put(key: string, body: Buffer): Promise { assertStorageKey(key); this.objects.set(key, Buffer.from(body)); } async get(key: string): Promise { assertStorageKey(key); const value = this.objects.get(key); if (!value) throw new AdapterError("NOT_FOUND", "Arquivo não encontrado.", 404); return Buffer.from(value); } async delete(key: string): Promise { assertStorageKey(key); this.objects.delete(key); } async list(prefix: string): Promise { return [...this.objects.keys()].filter((key) => key.startsWith(prefix)); } async healthcheck(): Promise { return true; } }