import type { Key, Value } from '../interfaces/common.js'; import type { AztecAsyncMultiMap, AztecMultiMap } from '../interfaces/multi_map.js'; import { LmdbAztecMap } from './map.js'; /** * A map backed by LMDB. */ export class LmdbAztecMultiMap extends LmdbAztecMap implements AztecMultiMap, AztecAsyncMultiMap { *getValues(key: K): IterableIterator { const transaction = this.db.useReadTransaction(); try { const values = this.db.getValues(this.slot(key), { transaction, }); for (const value of values) { yield value?.[1]; } } finally { transaction.done(); } } async *getValuesAsync(key: K): AsyncIterableIterator { for (const value of this.getValues(key)) { yield value; } } getValueCountAsync(key: K): Promise { const transaction = this.db.useReadTransaction(); try { const values = this.db.getValues(this.slot(key), { transaction, }); let count = 0; for (const _ of values) { count++; } return Promise.resolve(count); } finally { transaction.done(); } } async deleteValue(key: K, val: V): Promise { await this.db.remove(this.slot(key), [key, val]); } }