@kitsonk/kv-toolbox@0.29.0Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Utilities for working with Deno KV. Encrypted values, batching atomic transactions, handling blobs, querying/filtering, and more.
KV Toolbox
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() });
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.
Add Package
deno add jsr:@kitsonk/kv-toolbox
Import symbol
import * as kv_toolbox from "@kitsonk/kv-toolbox";
Import directly with a jsr specifier
import * as kv_toolbox from "jsr:@kitsonk/kv-toolbox";
Add Package
pnpm i jsr:@kitsonk/kv-toolbox
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
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";