cloudflare-client
Version:
Universal HTTP client for Cloudflare API
119 lines (118 loc) • 3.52 kB
TypeScript
import { type Credentials } from "./fetch.js";
declare type Options = {
accountId: string;
} & Credentials;
declare type FindOptions = {
/**
* Page number of paginated results
* @minimum 1
* @default 1
*/
page?: number;
/**
* Maximum number of results per page
* @minimum 5
* @maximum 100
* @default 20
*/
per_page?: number;
/**
* Field to order results by
*/
order?: "id" | "title";
/**
* Direction to order namespaces
*/
direction?: "asc" | "desc";
};
export declare type Namespace = {
id: string;
title: string;
supports_url_encoding: boolean;
};
export declare type Key = {
name: string;
expiration: number;
metadata: Record<string, string | number>;
};
declare type KeysOptions = {
/**
* A string prefix used to filter down which keys will be returned. Exact
* matches and any key names that begin with the prefix will be returned.
*/
prefix?: string;
/**
* The number of keys to return. The cursor attribute may be used to iterate
* over the next batch of keys if there are more than the limit.
* @minimum 10
* @maximum 1000
* @example 1000
*/
first?: number;
/**
* Opaque token indicating the position from which to continue when requesting
* the next set of records if the amount of list results was limited by the
* limit parameter. A valid value for the cursor can be obtained from the
* cursors object in the result_info structure.
* @example "6Ck1la0VxJ0djhidm1MdX2FyDGxLKVeeHZZmORS_8XeSuhz9SjIJRaSa2lnsF01tQOHrfTGAP3R5X1Kv5iVUuMbNKhWNAXHOl6ePB0TUL8nw"
*/
after?: string;
};
declare type SetOptions = {
expires?: number;
expiresTtl?: number;
/**
* @default JSON.stringify
*/
encode?: ((value: any) => any) | false;
/**
* @default "text/plain; charset=utf-8"
*/
contentType?: string;
};
declare type GetOptions = {
/**
* @default JSON.parse
*/
decode?: ((value: ArrayBuffer) => any) | false;
};
/**
* Cloudflare KV Storage client
*/
export declare function kv(options: Options): {
/**
* List Namespaces
* @see https://api.cloudflare.com/#workers-kv-namespace-list-namespaces
*/
find: (params?: FindOptions | undefined) => import("./fetch.js").Query<Namespace>;
/**
* Create a Namespace
* @see https://api.cloudflare.com/#workers-kv-namespace-properties
*/
create: (name: string) => Promise<Namespace>;
/**
* Rename a Namespace
* @see https://api.cloudflare.com/#workers-kv-namespace-rename-a-namespace
*/
update: (id: string, title: string) => Promise<null>;
/**
* Remove a Namespace
* @see https://api.cloudflare.com/#workers-kv-namespace-remove-a-namespace
*/
delete: (id: string) => Promise<null>;
namespace(id: string): {
keys: (params?: KeysOptions | undefined) => import("./fetch.js").Query<Key>;
/**
* Read key-value pair
* @see https://api.cloudflare.com/#workers-kv-namespace-read-key-value-pair
*/
get: <T = any>(key: string, options?: GetOptions) => Promise<T>;
/**
* Write key-value pair
* @see https://api.cloudflare.com/#workers-kv-namespace-write-key-value-pair
*/
set: <T_1 = any>(key: string, value: T_1, options?: SetOptions) => Promise<undefined>;
delete: (id: string) => Promise<void>;
};
};
export {};