import { getKeyValueStore } from "../data/index.js";
import { ok } from "../is.js";
import { v4 } from "uuid";
import { Chance } from "chance";
import { builder } from "../data/storage/hook.js";
import sinon from "sinon";
const chance = new Chance();
{
    const store = builder()
        .use("set", (key, value) => {
        return undefined;
    })
        .use("get", (key, value) => {
    }, { stage: "after" })
        .use("has", (key, value) => {
    }, { stage: "after" })
        .build("storeName");
}
{
    const base = getKeyValueStore("storeName");
    const expectedValue = {
        value: v4()
    };
    const before = sinon.spy(async function (key, value) {
        ok(value.value === expectedValue.value);
        const found = await base.get(key);
        ok(found?.value !== expectedValue.value);
    });
    const after = sinon.spy(async function (key, value) {
        ok(value.value === expectedValue.value);
        const found = await base.get(key);
        ok(found.value === expectedValue.value);
    });
    const hooked = builder()
        .use({
        on: "set",
        stage: "before",
        handler: before,
    })
        .use({
        on: "set",
        stage: "after",
        handler: after,
    })
        .build(base);
    ok(!before.called);
    ok(!after.called);
    await hooked.set("key", expectedValue);
    ok(before.called);
    ok(before.calledWith("key", expectedValue));
    ok(after.called);
    ok(after.calledWith("key", expectedValue));
    ok(before.calledBefore(after));
}
//# sourceMappingURL=storage.js.map