From 97c1abae77d4b337a0e8a8a7b9d7b6930acbdcbf Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 7 Aug 2023 22:31:22 +0200 Subject: [PATCH] small refactors --- src/drivers/{indexeddb.ts => idb-keyval.ts} | 10 +++++----- src/index.ts | 2 ++ test/drivers/{indexeddb.test.ts => idb-keyval.test.ts} | 3 +-- 3 files changed, 8 insertions(+), 7 deletions(-) rename src/drivers/{indexeddb.ts => idb-keyval.ts} (97%) rename test/drivers/{indexeddb.test.ts => idb-keyval.test.ts} (91%) diff --git a/src/drivers/indexeddb.ts b/src/drivers/idb-keyval.ts similarity index 97% rename from src/drivers/indexeddb.ts rename to src/drivers/idb-keyval.ts index 69925fcc..86ae971f 100644 --- a/src/drivers/indexeddb.ts +++ b/src/drivers/idb-keyval.ts @@ -10,21 +10,21 @@ import { } from "idb-keyval"; export interface IDBKeyvalOptions { + base?: string; dbName?: string; storeName?: string; - base?: string; } -const DRIVER_NAME = "indexeddb"; +const DRIVER_NAME = "idb-keyval"; export default defineDriver((opts: IDBKeyvalOptions = {}) => { - let customStore: UseStore | undefined; + const base = opts.base && opts.base.length > 0 ? `${opts.base}:` : ""; + const makeKey = (key: string) => base + key; + let customStore: UseStore | undefined; if (opts.dbName && opts.storeName) { customStore = createStore(opts.dbName, opts.storeName); } - const base = opts.base && opts.base.length > 0 ? `${opts.base}:` : ""; - const makeKey = (key: string) => base + key; return { name: DRIVER_NAME, diff --git a/src/index.ts b/src/index.ts index bec1d6ce..1b4463f5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,6 +15,7 @@ export const builtinDrivers = { fs: "unstorage/drivers/fs", github: "unstorage/drivers/github", http: "unstorage/drivers/http", + idbKeyval: "unstorage/drivers/idb-keyval", localStorage: "unstorage/drivers/localstorage", lruCache: "unstorage/drivers/lru-cache", memory: "unstorage/drivers/memory", @@ -61,6 +62,7 @@ export type BuiltinDriverOptions = { fs: ExtractOpts<(typeof import("./drivers/fs"))["default"]>; github: ExtractOpts<(typeof import("./drivers/github"))["default"]>; http: ExtractOpts<(typeof import("./drivers/http"))["default"]>; + idbKeyval: ExtractOpts<(typeof import("./drivers/idb-keyval"))["default"]>; localStorage: ExtractOpts< (typeof import("./drivers/localstorage"))["default"] >; diff --git a/test/drivers/indexeddb.test.ts b/test/drivers/idb-keyval.test.ts similarity index 91% rename from test/drivers/indexeddb.test.ts rename to test/drivers/idb-keyval.test.ts index f0dbc7d4..e033bf2d 100644 --- a/test/drivers/indexeddb.test.ts +++ b/test/drivers/idb-keyval.test.ts @@ -1,6 +1,5 @@ -import { del } from "idb-keyval"; import { describe, expect, it } from "vitest"; -import driver from "../../src/drivers/indexeddb"; +import driver from "../../src/drivers/idb-keyval"; import { testDriver } from "./utils"; import "fake-indexeddb/auto"; import { createStorage } from "../../src";