diff --git a/src/store/storage/kv/kv_driver_indexeddb.ts b/src/store/storage/kv/kv_driver_indexeddb.ts index dd6abad..0450890 100644 --- a/src/store/storage/kv/kv_driver_indexeddb.ts +++ b/src/store/storage/kv/kv_driver_indexeddb.ts @@ -9,6 +9,7 @@ import { pack, unpack } from "./key_codec/kv_key_codec.ts"; import { WillowError } from "../../../errors.ts"; import { FIFO } from "@korkje/fifo"; import { successorBytesFixedWidth } from "@earthstar/willow-utils"; +import { equals as equalsBytes } from "@std/bytes"; const KV_STORE = "kv"; const END_LIST = Symbol("end_list"); @@ -130,7 +131,7 @@ export class KvDriverIndexedDB implements KvDriver { return; } - const direction = opts?.reverse ? "prevunique" : "nextunique"; + const direction = opts?.reverse ? "prev" : "next"; const resultFifo = new FIFO< { packedKey: Uint8Array; value: Value } | typeof END_LIST @@ -226,7 +227,7 @@ type BatchOp = { value: unknown; } | { kind: "delete"; key: KvKey }; -class BatchIndexedDB implements KvBatch { +class BatchIndexedDB implements KvBatch { private db: Promise; private ops: BatchOp[] = []; @@ -320,7 +321,19 @@ function selectorToIdbBound({ start, end, prefix }: { } } - return IDBKeyRange.bound(actualPackedStart, actualPackedEnd, false, true); + if ( + actualPackedStart && actualPackedEnd && + equalsBytes(actualPackedStart, actualPackedEnd) + ) { + return "notMatchingAnything"; + } + + return IDBKeyRange.bound( + actualPackedStart, + actualPackedEnd, + false, + true, + ); } else { // The simple cases: no prefix to consider. if ( diff --git a/src/store/storage/kv/prefixed_driver.ts b/src/store/storage/kv/prefixed_driver.ts index 8dd796b..353e6f6 100644 --- a/src/store/storage/kv/prefixed_driver.ts +++ b/src/store/storage/kv/prefixed_driver.ts @@ -91,7 +91,9 @@ export class PrefixedDriver implements KvDriver { delete(key) { return batch.delete([...prefix, ...key]); }, - commit: batch.commit, + commit() { + return batch.commit(); + }, }; } }