diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/kv/01_db.ts | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/ext/kv/01_db.ts b/ext/kv/01_db.ts index ca37aa840..f8181cc2e 100644 --- a/ext/kv/01_db.ts +++ b/ext/kv/01_db.ts @@ -23,7 +23,7 @@ const encodeCursor: ( async function openKv(path: string) { const rid = await core.opAsync("op_kv_database_open", path); - return new Kv(rid); + return new Kv(rid, kvSymbol); } interface RawKvEntry { @@ -43,10 +43,17 @@ type RawValue = { value: bigint; }; +const kvSymbol = Symbol("KvRid"); + class Kv { #rid: number; - constructor(rid: number) { + constructor(rid: number = undefined, symbol: symbol = undefined) { + if (kvSymbol !== symbol) { + throw new TypeError( + "Deno.Kv can not be constructed, use Deno.openKv instead.", + ); + } this.#rid = rid; } |