azu / kvs

Lightweight key-value storage library for Browser, Node.js, and In-Memory.
MIT License
182 stars 6 forks source link

Introduce `Schema` type #2

Closed azu closed 4 years ago

azu commented 4 years ago

Useful interface.

import assert from "assert";
import { kvsStorage } from "@kvs/storage";
(async () => {
    type StorageSchema = {
        a1: string;
        b2: number;
        c3: boolean;
    };
    const storage = await kvsStorage<StorageSchema>({
        name: "test",
        version: 1,
        storage: localStorage
    });
    await storage.set("a1", "string");
    await storage.set("b2", 42);
    await storage.set("c3", false);
    const a1 = await storage.get("a1");
    const b2 = await storage.get("b2");
    const c3 = await storage.get("c3");
    assert.strictEqual(a1, "string");
    assert.strictEqual(b2, 42);
    assert.strictEqual(c3, false);
})();

fix #1