import type { KeyValueStorage } from './KeyValueStorage'; /** * A {@link KeyValueStorage} which uses a JavaScript Map for internal storage. * Warning: Uses a Map object, which internally uses `Object.is` for key equality, * so object keys have to be the same objects. */ export class MemoryMapStorage implements KeyValueStorage { private readonly data: Map; public constructor() { this.data = new Map(); } public async get(key: TKey): Promise { return this.data.get(key); } public async has(key: TKey): Promise { return this.data.has(key); } public async set(key: TKey, value: TValue): Promise { this.data.set(key, value); return this; } public async delete(key: TKey): Promise { return this.data.delete(key); } public async* entries(): AsyncIterableIterator<[TKey, TValue]> { for (const entry of this.data.entries()) { yield entry; } } }