import type { DeadLetterMessage } from "./DeadLetterMessage"; import type IDeadLetterQueue from "./IDeadLetterQueue"; /** * In-memory implementation of the dead letter queue. * Suitable for development and testing purposes. */ export default class InMemoryDeadLetterQueue implements IDeadLetterQueue { private readonly messages: Map = new Map(); public async add(message: DeadLetterMessage): Promise { this.messages.set(message.id, message); } public async get(messageId: string): Promise { return this.messages.get(messageId); } public async getAll(): Promise { return Array.from(this.messages.values()); } public async remove(messageId: string): Promise { this.messages.delete(messageId); } public async update(message: DeadLetterMessage): Promise { if (!this.messages.has(message.id)) { throw new Error(`Message with id ${message.id} not found in dead letter queue`); } this.messages.set(message.id, message); } public async count(): Promise { return this.messages.size; } public async clear(): Promise { this.messages.clear(); } }