Skip to main content
Module

x/tpy/mod.ts>TpyKV

🔑 A strongly typed Pylon API client.
Latest
class TpyKV
import { TpyKV } from "https://deno.land/x/tpy@v1.0.0-RC/mod.ts";

A KVNamespace interface that (almost) matches the Pylon KVNamespace SDK class.

Constructors

new
TpyKV(
tpyInstance: Tpy,
deploymentID: string,
kvnamespace: string,
)

Properties

private
deploymentID: string
private
tpyc: Tpy
readonly
kvnamespace: string

The KV namespace title.

Methods

cas(
key: string,
compare: Json,
set: Json,
ttl?: Date | number,
): Promise<void>

Compare and set a key's value.

cas(
key: string,
compare: undefined,
set: Json,
ttl?: Date | number,
): Promise<void>

Compare and set a key's value, setting the value only if the key does not already exist.

cas(
key: string,
compare: Json,
set: undefined,
ttl?: Date | number,
): Promise<void>

Compare and delete a key's value. This is functionally equivalent to delete, if the prevValue option is provided.

Clears the namespace. Returning the number of keys deleted.

This operation will delete all the data in the namespace. The data is irrecoverably deleted.

Use with caution!

Returns the number of keys present in this namespace.

delete(key: string, options?: KV.OperationOptions.Delete)

Deletes a given key from the namespace. Throwing if the key does not exist, or if options.prevValue is set the previous value is not equal to the value provided.

get<T extends Json = Json>(key: string): Promise<T | undefined>

Gets a key's value - returning the value or undefined.

getArrayBuffer(key: string): Promise<ArrayBuffer | undefined>

Gets a key's value - returning the value or undefined.

items<T>(options?: KV.OperationOptions.Items): Promise<KV.GET.ItemsFlattened<T>>

Lists the keys and values in a namespace, including their expiration date if applicable.

The maximum limit is 100, however.

list(options?: KV.OperationOptions.List)

Lists the keys that are set within the namespace.

put(
key: string,
value: Json,
options?: KV.OperationOptions.Put,
)

Sets the value of a given key within the key-value store.

putArrayBuffer(
key: string,
value: ArrayBuffer,
options?: KV.OperationOptions.Put,
)

Sets the value of a given key within the key-value store.

transact<T extends Json>(key: string, transaction: (prev: T | undefined) => T | undefined): Promise<T | undefined>

A higher level alternative to cas. Updates a key, using the specified transaction function.