summaryrefslogtreecommitdiff
path: root/ext/kv/01_db.ts
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2023-04-11 16:36:01 +0200
committerGitHub <noreply@github.com>2023-04-11 14:36:01 +0000
commite0bf8e6faf58c8120738215a1aa05adbd79289c3 (patch)
treee26d0dd8767c21cbda83f96ed8e8183bc3e6f6f4 /ext/kv/01_db.ts
parent015eb4ef9c99526486e372489dcc50feb7b39ea6 (diff)
fix(ext/kv): keys must be arrays (#18655)
There was some leftover code from previous iterations, where keys could be single parts instead of arrays also. This didn't match the types.
Diffstat (limited to 'ext/kv/01_db.ts')
-rw-r--r--ext/kv/01_db.ts21
1 files changed, 4 insertions, 17 deletions
diff --git a/ext/kv/01_db.ts b/ext/kv/01_db.ts
index 05e9a66d8..38dcb4ae0 100644
--- a/ext/kv/01_db.ts
+++ b/ext/kv/01_db.ts
@@ -48,7 +48,6 @@ class Kv {
}
async get(key: Deno.KvKey, opts?: { consistency?: Deno.KvConsistencyLevel }) {
- key = convertKey(key);
const [entries]: [RawKvEntry[]] = await core.opAsync(
"op_kv_snapshot_read",
this.#rid,
@@ -76,7 +75,6 @@ class Kv {
keys: Deno.KvKey[],
opts?: { consistency?: Deno.KvConsistencyLevel },
): Promise<Deno.KvEntry<unknown>[]> {
- keys = keys.map(convertKey);
const ranges: RawKvEntry[][] = await core.opAsync(
"op_kv_snapshot_read",
this.#rid,
@@ -103,7 +101,6 @@ class Kv {
}
async set(key: Deno.KvKey, value: unknown) {
- key = convertKey(key);
value = serializeValue(value);
const checks: Deno.AtomicCheck[] = [];
@@ -123,8 +120,6 @@ class Kv {
}
async delete(key: Deno.KvKey) {
- key = convertKey(key);
-
const checks: Deno.AtomicCheck[] = [];
const mutations = [
[key, "delete", null],
@@ -211,14 +206,14 @@ class AtomicOperation {
check(...checks: Deno.AtomicCheck[]): this {
for (const check of checks) {
- this.#checks.push([convertKey(check.key), check.versionstamp]);
+ this.#checks.push([check.key, check.versionstamp]);
}
return this;
}
mutate(...mutations: Deno.KvMutation[]): this {
for (const mutation of mutations) {
- const key = convertKey(mutation.key);
+ const key = mutation.key;
let type: string;
let value: RawValue | null;
switch (mutation.type) {
@@ -247,12 +242,12 @@ class AtomicOperation {
}
set(key: Deno.KvKey, value: unknown): this {
- this.#mutations.push([convertKey(key), "set", serializeValue(value)]);
+ this.#mutations.push([key, "set", serializeValue(value)]);
return this;
}
delete(key: Deno.KvKey): this {
- this.#mutations.push([convertKey(key), "delete", null]);
+ this.#mutations.push([key, "delete", null]);
return this;
}
@@ -296,14 +291,6 @@ class KvU64 {
}
}
-function convertKey(key: Deno.KvKey | Deno.KvKeyPart): Deno.KvKey {
- if (Array.isArray(key)) {
- return key;
- } else {
- return [key as Deno.KvKeyPart];
- }
-}
-
function deserializeValue(entry: RawKvEntry): Deno.KvEntry<unknown> {
const { kind, value } = entry.value;
switch (kind) {