import type { KVNamespace } from "@cloudflare/workers-types"; import type { Jsonifiable } from "type-fest"; /** * Add a global, low-latency key-value data storage to your Edge-first * application. */ export declare class KV { protected kv: KVNamespace; constructor(kv: KVNamespace); get binding(): KVNamespace; /** * Retrieves all keys from the KV storage. * @param prefix The prefix to filter keys by. * @param options The options to use when fetching keys. */ keys(prefix: KV.Keys.Prefix, options?: KV.Keys.Options): Promise>; keys(options?: KV.Keys.Options): Promise>; keys(): Promise>; /** * Retrieves an item from the Key-Value storage. * @param key The key to retrieve. * @returns The value and metadata of the key. */ get(key: KV.Get.Key): Promise>; /** * Puts an item in the storage. * @param key The key to set. * @param value The value to store, it must be serializable to JSON. * @param options The options to use when setting the key. */ set(key: KV.Set.Key, value: Value, options?: KV.Set.Options): Promise; /** * Checks if an item exists in the storage. * @param key The key to check. * @returns Whether the key exists or not. */ has(key: KV.Has.Key): Promise; /** * Delete an item from the storage. * @param key The key to delete. */ remove(key: KV.Remove.Key): Promise; } export declare namespace KV { interface Key { /** The name of the key. */ name: string; /** The metadata stored along the key. */ meta: Meta | undefined; /** The time-to-live of the key. */ ttl?: number; } namespace Keys { type Prefix = string; interface Options { /** The maximum number of keys to return. */ limit?: number; /** The cursor to use when fetching more pages of keys. */ cursor?: string; } type Result = { keys: Key[]; cursor: null; done: true; } | { keys: Key[]; cursor: string; done: false; }; } namespace Get { type Key = string; type Value = Jsonifiable; type Meta = Record; interface Output { /** * The value stored along the key. * It will be null if the key was not found. */ data: T | null; /** * The metadata stored along the key. */ meta: M | null; } } namespace Set { type Key = string; type Value = Jsonifiable; type Meta = Record; interface Options { /** * The time-to-live of the key. */ ttl?: number; /** * Extra metadata to store along the key. */ metadata?: T; } } namespace Has { type Key = string; type Output = boolean; } namespace Remove { type Key = string; } }