Key-value API

Types

// store any valid primitive JS type.
// Maintains type on retrieval.
type Value = string | number | boolean | object | Value[]

Methods

set

kv.set(key: string, value: Value)

Params: a key and corresponding value.

Returns: A promise resolving to true on success or false on failure.

Set a key-value pair in the store. Overwrites existing values.

await kv.set('complex', { foo: ['bar', 3, true] })

get

kv.get(key: string, allowCachedValue: boolean = true)

Params: A key to retrieve. If allowCachedValue is true, we will check the cache before querying Urbit.

Returns: A promise resolving to a Value or undefined if the key does not exist.

Get the value associated with a key in the store.

await kv.get('foo')

remove

kv.remove(key: string)

Params: a key to remove.

Returns: A promise resolving to true on success or false on failure.

Remove a key-value pair from the store. If the key does not exist, returns true.

await kv.remove('foo')

clear

kv.clear()

Returns: A promise resolving to true on success or false on failure.

Clear all key-value pairs from the store.

await kv.clear()

all

kv.all(useCache: boolean = false)

Params: If useCache is true, return the current cache instead of querying Urbit. Only relevant if preload was set to false.

Returns: A promise resolving to a Map<string, Value>>

Get all key-value pairs in the store.

await kv.all()

Last updated