We use cookies to improve your experience.

Cookie Policy
Logo of Lexmount
DocsTemplatesBlogHelp Center
GitHub
Logo of LexmountLexmount Browser

Get started

Lexmount Documentation
Console guide

Browser

Web Fetch

OverviewQuick Start
Common Errors

Web Search

OverviewQuick StartSearch API

Runtime

OverviewQuickstart
Overviewfetchlexmount:env
OverviewIndexedDBObjectStorageKVStorage
lexmount:browser
Examples

Help and billing

Capability FAQ
ChangelogContact support
API Referencelexmount:storage

KVStorage

Persist string values with expiration and prefix pagination.

KVStorage provides persistent string key/value data with expiration and prefix pagination, suitable for configuration, cached values, and JSON text.

Create and associate the resource first; see resources and associations in the module overview.

import { KVStorage } from 'lexmount:storage';

const kv = await KVStorage.open('cache');

KVStorage.storages()

Function: lists KV resources associated with this instance.

Parameters: none.

Return value: Promise<{ id: string; name: string }[]>.

KVStorage.open(name)

Function: opens an existing associated KV resource by name.

Parameters: required name: string; see resource naming.

Return value: Promise<Readonly<NamedKVStorage>>, with read-only name: string and the methods below. Handles bind to the selected resource ID.

kv.put(key, value, options?)

Function: stores a string, replacing the old value and expiration settings for that key.

ParameterTypeRequiredDescription
keystringYesNonempty valid Unicode without NUL; at most 1024 UTF-8 bytes
valuestringYesMay be empty; valid Unicode without NUL; at most 1 MiB UTF-8 text
options.expirationTtlnumberNoPositive safe-integer seconds, measured with the storage server's clock
options.expirationnumberNoFuture Unix timestamp in seconds; a safe integer

The expiration options are mutually exclusive. Omit both to retain indefinitely and clear any previous TTL. Every put replaces expiration settings.

Return value: Promise<void>, resolving after commit. Values are strings. Automatic non-string conversion follows String(value), without automatic JSON serialization. Use JSON.stringify() for JSON.

kv.get(key)

Function: reads an unexpired value.

Parameters: required key: string, following put's rules.

Return value: Promise<string | null>; null for missing or expired values. Empty strings are valid results. Parse JSON yourself and distinguish an empty string from absence.

kv.delete(key)

Function: deletes one key, without deleting the KV resource.

Parameters: required key: string, following put's rules.

Return value: Promise<void>; missing keys also succeed.

kv.list(options?)

Function: lists unexpired keys in UTF-8 byte order with pagination.

ParameterTypeDefault and description
options.prefixstringEmpty string; a literal prefix, with % and _ treated literally
options.cursorstringOptional cursor from the same resource and prefix
options.limitnumber1000; integer 1–1000

Return value: Promise<KVPage>, containing keys: { name: string; expiration?: number }[], truncated: boolean, and cursor: string | null. Expiration, when present, is a Unix timestamp in seconds. The last cursor is null.

Get and list immediately hide expired records. Concurrent changes mean pagination is not a snapshot. Operations commit independently; there are no multi-key transactions or compare-and-swap. See the KV example.

See StorageError for shared error handling and storage.d.ts for declarations.

ObjectStorage

Upload files, stream downloads, read metadata, and list objects.

Overview

Discover clients and choose file, HTTP, process, or TCP capabilities with the required permissions.

Table of Contents

KVStorage.storages()
KVStorage.open(name)
kv.put(key, value, options?)
kv.get(key)
kv.delete(key)
kv.list(options?)

Still need help?Ask on Discord