mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
fix(ext/kv): throw on the Kv constructor (#18978)
Closes #18963 --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
632395da89
commit
d905f20cad
2 changed files with 15 additions and 2 deletions
|
@ -1256,6 +1256,12 @@ dbTest("keys must be arrays", async (db) => {
|
|||
);
|
||||
});
|
||||
|
||||
Deno.test("Deno.Kv constructor throws", () => {
|
||||
assertThrows(() => {
|
||||
new Deno.Kv();
|
||||
});
|
||||
});
|
||||
|
||||
// This function is never called, it is just used to check that all the types
|
||||
// are behaving as expected.
|
||||
async function _typeCheckingTests() {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue