cf-workers-kv
Version:
Cloudflare workers KV with customizable backing store for testing.
62 lines (61 loc) • 2.46 kB
TypeScript
/// <reference types="@cloudflare/workers-types" />
import { AsyncMapLike } from 'async-map-like';
declare type ListKey = {
name: string;
expiration?: number | undefined;
metadata?: unknown;
};
declare type PutOptions = {
expiration?: string | number | undefined;
expirationTtl?: string | number | undefined;
metadata?: any;
};
declare type ListOptions = {
prefix?: string | undefined;
limit?: number | undefined;
cursor?: string | undefined;
};
export declare type ValueAndMeta = {
value: string;
metadata: any | null;
};
export declare class KV implements KVNamespace {
private readonly data;
constructor(backend: Map<string, ValueAndMeta> | AsyncMapLike<string, ValueAndMeta>);
get(key: string, options?: {
cacheTtl?: number;
}): KVValue<string>;
get(key: string, type: 'text'): KVValue<string>;
get<ExpectedValue = unknown>(key: string, type: 'json'): KVValue<ExpectedValue>;
get(key: string, type: 'arrayBuffer'): KVValue<ArrayBuffer>;
get(key: string, type: 'stream'): KVValue<ReadableStream>;
get(key: string, options?: {
type: 'text';
cacheTtl?: number;
}): KVValue<string>;
get<ExpectedValue = unknown>(key: string, options?: {
type: 'json';
cacheTtl?: number;
}): KVValue<ExpectedValue>;
get(key: string, options?: {
type: 'arrayBuffer';
cacheTtl?: number;
}): KVValue<ArrayBuffer>;
get(key: string, options?: {
type: 'stream';
cacheTtl?: number;
}): KVValue<ReadableStream>;
getWithMetadata<Metadata = unknown>(key: string): KVValueWithMetadata<string, Metadata>;
getWithMetadata<Metadata = unknown>(key: string, type: 'text'): KVValueWithMetadata<string, Metadata>;
getWithMetadata<ExpectedValue = unknown, Metadata = unknown>(key: string, type: 'json'): KVValueWithMetadata<ExpectedValue, Metadata>;
getWithMetadata<Metadata = unknown>(key: string, type: 'arrayBuffer'): KVValueWithMetadata<ArrayBuffer, Metadata>;
getWithMetadata<Metadata = unknown>(key: string, type: 'stream'): KVValueWithMetadata<ReadableStream, Metadata>;
put(key: string, value: string | ArrayBuffer | ReadableStream | FormData, options?: PutOptions): Promise<void>;
delete(key: string): Promise<void>;
list(options?: ListOptions): Promise<{
keys: ListKey[];
list_complete: boolean;
cursor?: string | undefined;
}>;
}
export {};