Skip to main content

@rtorcato/cf-common

Interfaces

KvPutOptions

Defined in: index.ts:3

Properties

ttl?

optional ttl?: number

Defined in: index.ts:5

Seconds until the key expires (maps to KV expirationTtl).

expiration?

optional expiration?: number

Defined in: index.ts:7

Absolute expiry as a unix timestamp in seconds (maps to KV expiration).

metadata?

optional metadata?: Record<string, unknown>

Defined in: index.ts:9

Arbitrary metadata stored alongside the value.


KvStore

Defined in: index.ts:16

A typed, JSON-(de)serializing view over a single KVNamespace binding. Values are stored as JSON; get returns null for a missing key.

Type Parameters

T

T

Methods

get()

get(key): Promise<T | null>

Defined in: index.ts:17

Parameters
key

string

Returns

Promise<T | null>

put()

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

Defined in: index.ts:18

Parameters
key

string

value

T

options?

KvPutOptions

Returns

Promise<void>

delete()

delete(key): Promise<void>

Defined in: index.ts:19

Parameters
key

string

Returns

Promise<void>

list()

list(options?): Promise<KVNamespaceListResult<unknown, string>>

Defined in: index.ts:20

Parameters
options?

KVNamespaceListOptions

Returns

Promise<KVNamespaceListResult<unknown, string>>

Functions

createKvStore()

createKvStore<T>(namespace): KvStore<T>

Defined in: index.ts:31

Wrap a KVNamespace binding as a typed JSON store.

Type Parameters

T

T = unknown

Parameters

namespace

KVNamespace

Returns

KvStore<T>

Example

const users = createKvStore<User>(env.USERS)
await users.put(id, user, { ttl: 3600 })
const user = await users.get(id) // User | null