import Queue from '../helpers/queue.js' import { Base, Item } from '../types/types.js' import { Cache } from './interfaces.js' import { MemoryDatabaseOptions } from './options.js' export class MemoryDatabase implements Cache { #items: Record constructor(options?: MemoryDatabaseOptions) { this.#items = options?.items || {} } getItem(params: { id: string }): Promise { const item = this.#items[params.id] if (item) { return Promise.resolve({ baseId: params.id, base: item }) } return Promise.resolve(undefined) } processItems(params: { ids: string[] foundItems: Queue notFoundItems: Queue }): Promise { const { ids, foundItems, notFoundItems } = params for (const id of ids) { const item = this.#items[id] if (item) { foundItems.add({ baseId: id, base: item }) } else { notFoundItems.add(id) } } return Promise.resolve() } add(item: Item): Promise { this.#items[item.baseId] = item.base return Promise.resolve() } disposeAsync(): Promise { return Promise.resolve() } }