Skip to main content
Version: 0.9

Class: KeyValueStorage

Simplified wrapper around KVStore which stores all data as serialized JSON objects

Table of contents

Constructors

Methods

Constructors

constructor

new KeyValueStorage(storage?)

Parameters

NameType
storageKVStore

Methods

delete

delete(key, metadata?): Promise<void>

Deletes a key from the store if present

Parameters

NameType
keystring
metadata?Metadata

Returns

Promise<void>


get

get<T>(key, metadata?, defaultValue?): Promise<undefined | T>

Retrieves a value from the store at the given key or defaultValue if not found or falsy

to-do: remove defaultValue and use builtin nullish coalescing at call sites. to-do: change falsy comparison to an undefined check since undefineds are stripped by JSON parsing. This will allow KV to represent sets with any values and be less surprising.

Type parameters

NameType
Textends JSONValue

Parameters

NameType
keystring
metadata?Metadata
defaultValue?T

Returns

Promise<undefined | T>


list

list(metadata?): Promise<string[]>

Returns a list of keys in the store

Parameters

NameType
metadata?Metadata

Returns

Promise<string[]>


put

put(key, value, metadata?): Promise<void>

Assigns a value to a key in the store

Parameters

NameType
keystring
valueJSONValue
metadata?Metadata

Returns

Promise<void>