diff options
author | Luca Casonato <hello@lcas.dev> | 2023-05-03 23:08:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-03 23:08:42 +0200 |
commit | d905f20cadfd95b927027a3c597d578db606984e (patch) | |
tree | 70664b2187e1864cb713092c5e918bf044454cf5 /ext/kv/01_db.ts | |
parent | 632395da89c767913cb88edfb437d02772fe84b9 (diff) |
fix(ext/kv): throw on the Kv constructor (#18978)
Closes #18963
---------
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'ext/kv/01_db.ts')
-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; } |