Skip to content

Commit

Permalink
small refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 7, 2023
1 parent 6c3b4c2 commit 97c1aba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/drivers/indexeddb.ts → src/drivers/idb-keyval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"]
>;
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down

0 comments on commit 97c1aba

Please sign in to comment.