Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Utilities for working with Deno KV
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.
Converting to a maybe entry to JSON
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
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();
Serialize a Deno.KvEntryMaybe
to JSON.
Serialize a Deno.KvEntry
to JSON.
Serialize a Deno.KvKeyPart
to JSON.
Serialize a Deno.KvKey
to JSON.
Deserialize a KvEntryJSON
to a Deno.KvEntry
.
Deserialize a KvEntryMaybeJSON
to a
Deno.KvEntryMaybe
.
Deserialize KvKeyJSON
to a Deno.KvKey
.
Deserialize KvBigIntJSON
to a bigint.
Deserialize KvArrayBufferJSON
to an ArrayBuffer
which
can be stored in a Deno KV store.
Serialize an array that can be stored in Deno KV to JSON.
Error instances which are cloneable and therefore can be stored in a Deno KV store.
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:
A representation of an Array
Deno KV value. The value is the
JSON serialized version of the elements of the array.
A JSON representation of a bigint
Deno KV key part. The value
is a string representation of the integer, for example 100n
would be:
A JSON representation of a boolean
Deno KV key part. The value
is the boolean value, for example true
would be:
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:
A representation of a Date
Deno KV value. The value is the
ISO string representation
of the date.
A representation of a Deno.KvEntry
where the key and value are
encoded in a JSON serializable format.
A representation of Error
s 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
.
A representation of a Deno.KvU64
value. The value is the string
representation of the unsigned integer.
A JSON representation of a number
Deno KV key part. The value
is the number value, for example 100
would be:
A representation of a object
Deno KV value. The value is a JSON
serialized version of the value.
A representation of a RegExp
Deno KV value. The value is a string
representation of the regular expression value.
A JSON representation of a string
Deno KV key part. The value is
the string value, for example "value"
would be:
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.
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:
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:
The keys of CloneableErrors
which is used for type inference
when deserializing from JSON.
A representation of a Deno.KvEntryMaybe
where the key and value
are encoded in a JSON serializable format.
A JSON representation of a Deno.KvKey
, which is an array of
KvKeyPartJSON
items.
JSON representations of Deno.KvKeyPart
. This represents each key
part type that is supported by Deno KV.
JSON representations of Deno.Kv
values, where the value types are
exhaustive of what Deno KV supports and are allowed via
structured cloning.
Add Package
deno add jsr:@deno/kv-utils
Import symbol
import * as mod from "@deno/kv-utils/json";
Import directly with a jsr specifier
import * as mod from "jsr:@deno/kv-utils/json";
Add Package
pnpm i jsr:@deno/kv-utils
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
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";