export namespace KV { type Metadata = Record; type Value = string | ReadableStream | ArrayBuffer; type GetFormat = 'text' | 'json' | 'arrayBuffer' | 'stream'; type GetMetadata = { value: T | null; metadata: M | null; } interface KeyInfo { name: string; expiration?: number; metadata?: M; } interface KeyList { keys: KeyInfo[]; list_complete: boolean; cursor?: string; } namespace Options { type List = { prefix?: string; cursor?: string; limit?: number; } type Get = { type: T; cacheTtl?: number; } type Put = { expiration?: number; expirationTtl?: number; metadata?: M; } } interface Namespace { get(key: string, options: 'json' | Options.Get<'json'>): Promise; get(key: string, options: 'stream' | Options.Get<'stream'>): Promise; get(key: string, options: 'arrayBuffer' | Options.Get<'arrayBuffer'>): Promise; get(key: string, options?: 'text' | Options.Get<'text'>): Promise; getWithMetadata(key: string, options: 'json' | Options.Get<'json'>): Promise>; getWithMetadata(key: string, options: 'stream' | Options.Get<'stream'>): Promise>; getWithMetadata(key: string, options: 'arrayBuffer' | Options.Get<'arrayBuffer'>): Promise>; getWithMetadata(key: string, options?: 'text' | Options.Get<'text'>): Promise>; put(key: string, value: Value, options?: Options.Put): Promise; list(options?: Options.List): Promise>; delete(key: string): Promise; } } export declare class Database = { [P in keyof Models]: string}> { constructor(binding: KV.Namespace); get(type: K, uid: Identifiers[K], options: Options.Read & { metadata: true }): Promise>; get(type: K, uid: Identifiers[K], options?: KV.GetFormat | (Options.Read & { metadata?: false })): Promise; put(type: K, uid: Identifiers[K], value: Models[K], options?: Options.Write): Promise; del(type: K, uid: Identifiers[K]): Promise; } // Custom method options export namespace Options { type Read = KV.Options.Get & { metadata?: boolean }; type Write = KV.Options.Put & { toJSON?: boolean }; type List = KV.Options.List & { metadata?: boolean }; type Paginate = { page?: number; limit?: number; prefix?: string; metadata?: boolean; } } // Get item value with metadata export function read(binding: KV.Namespace, key: string, options: Options.Read<'arrayBuffer'> & { metadata: true }): Promise>; export function read(binding: KV.Namespace, key: string, options: Options.Read<'stream'> & { metadata: true }): Promise>; export function read(binding: KV.Namespace, key: string, options: Options.Read<'text'> & { metadata: true }): Promise>; export function read(binding: KV.Namespace, key: string, options: Options.Read<'json'> & { metadata: true }): Promise>; // Get raw item value (no metadata) export function read(binding: KV.Namespace, key: string, options: 'arrayBuffer' | Options.Read<'arrayBuffer'>): Promise; export function read(binding: KV.Namespace, key: string, options: 'stream' | Options.Read<'stream'>): Promise; export function read(binding: KV.Namespace, key: string, options: 'text' | Options.Read<'text'>): Promise; export function read(binding: KV.Namespace, key: string, options?: 'json' | Options.Read<'json'>): Promise; export function write(binding: KV.Namespace, key: string, value: T, options?: Options.Write): Promise; export function remove(binding: KV.Namespace, key: string): Promise; export function list(binding: KV.Namespace, options?: Options.List & { metadata: true }): AsyncGenerator<{ done: boolean; keys: KV.KeyInfo[] }>; export function list(binding: KV.Namespace, options?: Options.List): AsyncGenerator<{ done: boolean; keys: string[] }>; export function paginate(binding: KV.Namespace, options?: Options.Paginate & { metadata: true }): Promise[]>; export function paginate(binding: KV.Namespace, options?: Options.Paginate & { metadata?: false }): Promise; export function until( toMake: () => X, toSearch: (val: X) => Promise ): Promise;