A toolbox for Deno KV

Serializing entries and values to JSON, importing and exporting with NDJSON, working with blobs, utilities for working with keys, batched atomic transactions and more.

A comprehensive toolbox

openKvToolbox() allow access to most of the features of the library in an enriched that builds on top of Deno.Kv.

See the docs
import { openKvToolbox } from "@kitsonk/kv-toolbox";

const file = await Deno.readFile("hello.jpeg");
const kv = await openKvToolbox();
await kv.setBlob(["hello.jpeg"], file);
kv.close();
import {
  generateKey,
  openCryptoKv,
} from "@kitsonk/kv-toolbox/crypto";

const kv = await openCryptoKv(generateKey());
const res = await kv.setBlob(
  ["hello"],
  window.crypto.getRandomValues(new Uint8Array(65_536)),
);
if (res.ok) {
  const maybeValue = await kv.getBlob(["hello"]);
  await kv.deleteBlob(["hello"]);
}
kv.close();

Store encrypted values

Encrypt and decrypt Deno KV values, ensuring that data at rest is secure.

See the docs

Represent Deno KV data as JSON

Safely serialize and deserialize Deno KV entries, keys and values. Making it possible to work on KV data in browsers or other runtimes.

See the docs
import {
  entryToJSON,
  entryMaybeToJSON,
  keyPartToJSON,
  keyToJSON,
  valueToJSON,
  toEntry,
  toEntryMaybe,
  toKeyPart,
  toKey,
  toValue,
} from "@kitsonk/kv-toolbox/json";
import {
  exportEntries,
  exportToResponse,
  importEntries,
  LineTransformStream,
} from "@kitsonk/kv-toolbox/ndjson";

Handle streaming Deno KV data

New line delimitated JSON (NDJSON) is the most straight forward way of handling Deno KV data in a serialized format.

See the docs

Work with blobs

Working with arbitrarily size blobs like Uint8Arrays, byte ReadableStreams, Blobs and Files, stream blob values to a browser, and manage Deno KV's 64k per entry value limit.

See the docs
import {
  get,
  getAsBlob,
  getAsJSON,
  getAsResponse,
  getAsStream,
  getMeta,
  remove,
  set,
  toJSON,
  toValue,
} from "@kitsonk/kv-toolbox/blob";
import {
  equals,
  keys,
  partEquals,
  startsWith,
  tree,
  unique,
  uniqueCount,
} from "@kitsonk/kv-toolbox/keys";

Unlock Deno KV keys

Make working with Deno KV keys easier, especially when using a sub-key pattern.

See the docs

Batched atomics

Create atomic transactions without having to worry about Deno KV's limitations per transaction as well as provide atomic transactions for blobs via .checkBlob() and .setBlob().

See the docs
import {
  batchedAtomic,
} from "@kitsonk/kv-toolbox/batched_atomic";

const kv = await Deno.openKv();
await batchedAtomic(kv)
  .check({ key: ["hello"], versionstamp: null })
  .checkBlob({ key: ["video"], versionstamp: null })
  .set(["hello"], "deno kv")
  .setBlob(
    ["video"],
    new Blob([], { type: "video/mp4" }),
  )
  .commit();

await kv.close();