import { collectIteratorValueToArray } from "../../../core/collection/collectIteratorValueToArray.js";
import { noop } from "../../../core/function/noop.js";
import Storage from "../Storage.js";

export class InMemoryStorage extends Storage {
    #data = new Map();

    store(key, value, resolve=noop, reject, progress) {
        this.#data.set(key, value);

        resolve();
    }

    load(key, resolve, reject, progress) {
        resolve(this.#data.get(key));
    }

    remove(key, resolve=noop, reject) {
        this.#data.delete(key);

        resolve();
    }

    contains(key, resolve, reject) {
        resolve(this.#data.has(key));
    }

    list(resolve, reject) {
        const result = [];

        collectIteratorValueToArray(result, this.#data.keys());

        resolve(result);
    }
}
