Skip to main content
Home
This release is 2 versions behind 0.29.2 — the latest version of @kitsonk/kv-toolbox. Jump to latest

Built and signed on GitHub Actions

Utilities for working with Deno KV. Encrypted values, batching atomic transactions, handling blobs, querying/filtering, and more.

This package works with Node.js, Deno, Bun, Browsers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 weeks ago (0.29.0)

KV Toolbox

jsr.io/@kitsonk/kv-toolbox jsr.io/@kitsonk/kv-toolbox score kv-toolbox ci

Provides a toolbox for interacting with a Deno KV store, including the ability to store values in an encrypted fashion. The main module exports a ToolboxKv class that augments the Deno KV store with additional functionality. It also exports a CryptoToolboxKv class that augments the Deno KV store with additional functionality for encrypting and decrypting blob values.

Typically though, you would use the openKvToolbox function to create an instance of the toolbox. If you pass in an encryption key, it will create an instance of the CryptoToolboxKv class, otherwise it will create an instance of the ToolboxKv class.

The generateKey function is exported and can be used to generate a random encryption key to use with the CryptoToolboxKv class.

Creating a toolbox

To create an instance, you can use the openKvToolbox function. It is similar to Deno.openKv but returns an instance of the ToolboxKv class:

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

const kv = await openKvToolbox();

Creating an encrypted toolbox

To create an instance of the CryptoToolboxKv class, you can pass in an encryption key:

import { openKvToolbox, generateKey } from "@kitsonk/kv-toolbox";

const kv = await openKvToolbox({ encryptWith: generateKey() });
Note

The encryption key should be kept secret and not shared with others. It also needs to be stored securely, as it is required to decrypt values. The above example generates a random encryption key, that will be lost when the script is run again.

Additional Modules

This is the default module for the entire toolbox, and the individual capabilities of the toolbox are provided by additional exports of the library:

  • batched_atomic - Provides a way to perform atomic operations in batches while working around the limitations of Deno KV.
  • blob - Provides a way to store arbitrarily large binary data in Deno KV.
  • crypto - Provides a way to encrypt and decrypt data in Deno KV.
  • keys - Provides convenience functions for working with keys in Deno KV.
  • query - Provides a way to query/filter values in Deno KV.

@deno/kv-utils

Parts of kv-toolbox were contributed to the @deno/kv-utils package, like specifically the JSON serialization, the ability to estimate the size of keys and values, and the ability to import and export to NDJSON.

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@kitsonk/kv-toolbox

Import symbol

import * as kv_toolbox from "@kitsonk/kv-toolbox";
or

Import directly with a jsr specifier

import * as kv_toolbox from "jsr:@kitsonk/kv-toolbox";

Add Package

pnpm i jsr:@kitsonk/kv-toolbox
or (using pnpm 10.8 or older)
pnpm dlx jsr add @kitsonk/kv-toolbox

Import symbol

import * as kv_toolbox from "@kitsonk/kv-toolbox";

Add Package

yarn add jsr:@kitsonk/kv-toolbox
or (using Yarn 4.8 or older)
yarn dlx jsr add @kitsonk/kv-toolbox

Import symbol

import * as kv_toolbox from "@kitsonk/kv-toolbox";

Add Package

vlt install jsr:@kitsonk/kv-toolbox

Import symbol

import * as kv_toolbox from "@kitsonk/kv-toolbox";

Add Package

npx jsr add @kitsonk/kv-toolbox

Import symbol

import * as kv_toolbox from "@kitsonk/kv-toolbox";

Add Package

bunx jsr add @kitsonk/kv-toolbox

Import symbol

import * as kv_toolbox from "@kitsonk/kv-toolbox";