Skip to main content
Home

Built and signed on GitHub Actions

Utilities for working with Deno KV

This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
100%
Published
a month ago (0.1.4)

Utilities for handling Deno KV entries, keys, and values as structures which can be serialized and deserialized to JSON.

This is useful when communicating entries and values outside of the runtime environment.

Examples

Converting to a maybe entry to JSON

import { entryMaybeToJSON } from "@deno/kv-utils/json";

const db = await Deno.openKv();
const entryMaybe = await db.get(["a"]);

// `json` is now an object which can be safely converted to a JSON string
const json = entryMaybeToJSON(entryMaybe);
db.close();

Converting a JSON value to a Deno KV value

import { toValue } from "@deno/kv-utils/json";

// `json` represents a `Uint8Array` with the bytes of [1, 2, 3]
const json = { type: "Uint8Array", value: "AQID", byteLength: 3 } as const;

const db = await Deno.openKv();
await db.set(["a"], toValue(json));
db.close();

Functions

f
entryMaybeToJSON

Serialize a Deno.KvEntryMaybe to JSON.

f
entryToJSON

Serialize a Deno.KvEntry to JSON.

f
keyPartToJSON

Serialize a Deno.KvKeyPart to JSON.

f
keyToJSON

Serialize a Deno.KvKey to JSON.

f
toEntry

Deserialize a KvEntryJSON to a Deno.KvEntry.

f
toKey

Deserialize KvKeyJSON to a Deno.KvKey.

f
toKeyPart

Deserialize KvBigIntJSON to a bigint.

f
toValue

Deserialize KvArrayBufferJSON to an ArrayBuffer which can be stored in a Deno KV store.

f
valueToJSON

Serialize an array that can be stored in Deno KV to JSON.

Interfaces

I
CloneableErrors

Error instances which are cloneable and therefore can be stored in a Deno KV store.

I
KvArrayBufferJSON

A representation of an ArrayBuffer Deno KV value. The value is the bytes of the array buffer encoded as a URL safe base64 string, for example an array buffer with the byte values of [ 1, 2, 3 ] would be:

I
KvArrayJSON

A representation of an Array Deno KV value. The value is the JSON serialized version of the elements of the array.

I
KvBigIntJSON

A JSON representation of a bigint Deno KV key part. The value is a string representation of the integer, for example 100n would be:

I
KvBooleanJSON

A JSON representation of a boolean Deno KV key part. The value is the boolean value, for example true would be:

I
KvDataViewJSON

A representation of an DataView Deno KV value. The value is the bytes of the buffer encoded as a URL safe base64 string, for example a data view with the byte values of [ 1, 2, 3 ] would be:

I
KvDateJSON

A representation of a Date Deno KV value. The value is the ISO string representation of the date.

I
KvEntryJSON

A representation of a Deno.KvEntry where the key and value are encoded in a JSON serializable format.

I
KvErrorJSON

A representation of Errors that can be stored as Deno KV values. The value is set to a serialized version of the value. Instances that are not one of the specified types, but inherit from Error will be serialized as Error.

I
KvKvU64JSON

A representation of a Deno.KvU64 value. The value is the string representation of the unsigned integer.

I
KvMapJSON

A representation of a Map Deno KV value. The value is an array of map entries where is map entry is a tuple of a JSON serialized key and value.

I
KvNullJSON

A representation of a null Deno KV value. The value is null.

I
KvNumberJSON

A JSON representation of a number Deno KV key part. The value is the number value, for example 100 would be:

I
KvObjectJSON

A representation of a object Deno KV value. The value is a JSON serialized version of the value.

I
KvRegExpJSON

A representation of a RegExp Deno KV value. The value is a string representation of the regular expression value.

I
KvSetJSON

A representation of a Set Deno KV value. The value is an array of the JSON serialized values of the set.

I
KvStringJSON

A JSON representation of a string Deno KV key part. The value is the string value, for example "value" would be:

I
KvTypedArrayJSON

A representation of a typed array Deno KV value. The value is a URL safe base64 encoded string which represents the individual bytes of the array.

I
KvUint8ArrayJSON

A JSON representation of a Uint8Array Deno KV key part. The value is a URL safe base64 encoded value, for example an array with the values of [ 1, 2, 3 ] would be:

I
KvUndefinedJSON

A representation of a undefined Deno KV value. The value is undefined, and therefore elided when serialized. Therefore there is only one form of this entity:

Type Aliases

T
CloneableErrorTypes

The keys of CloneableErrors which is used for type inference when deserializing from JSON.

T
KvEntryMaybeJSON

A representation of a Deno.KvEntryMaybe where the key and value are encoded in a JSON serializable format.

T
KvKeyJSON

A JSON representation of a Deno.KvKey, which is an array of KvKeyPartJSON items.

T
KvKeyPartJSON

JSON representations of Deno.KvKeyPart. This represents each key part type that is supported by Deno KV.

T
KvValueJSON

JSON representations of Deno.Kv values, where the value types are exhaustive of what Deno KV supports and are allowed via structured cloning.

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:@deno/kv-utils

Import symbol

import * as mod from "@deno/kv-utils/json";
or

Import directly with a jsr specifier

import * as mod from "jsr:@deno/kv-utils/json";

Add Package

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

Import symbol

import * as mod from "@deno/kv-utils/json";

Add Package

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

Import symbol

import * as mod from "@deno/kv-utils/json";

Add Package

vlt install jsr:@deno/kv-utils

Import symbol

import * as mod from "@deno/kv-utils/json";

Add Package

npx jsr add @deno/kv-utils

Import symbol

import * as mod from "@deno/kv-utils/json";

Add Package

bunx jsr add @deno/kv-utils

Import symbol

import * as mod from "@deno/kv-utils/json";