UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

85 lines • 3.96 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../core/resource.mjs"; import { CursorLimitPagination, } from "../../../core/pagination.mjs"; import { path } from "../../../internal/utils/path.mjs"; export var BaseKeys = /* @__PURE__ */ (() => { class BaseKeys extends APIResource { /** * Lists key names in the specified Workers KV namespace, with expiration times and * metadata when present. Use `prefix` to filter names and `cursor` to request the * next page. Values are not included. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const key of client.kv.namespaces.keys.list( * '0f2ac74b498b48028cb68387c421e279', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * )) { * // ... * } * ``` */ list(namespaceID, params, options) { const { account_id, ...query } = params; return this._client.getAPIList(path `/accounts/${account_id}/storage/kv/namespaces/${namespaceID}/keys`, (CursorLimitPagination), { query, ...options }); } /** * Deletes up to 10,000 key-value pairs from the specified Workers KV namespace. * Send a JSON array of the key names to delete. The result reports the number of * successful deletions and any keys that failed and should be retried. * * @deprecated Please use kv.namespaces.bulk_delete instead */ bulkDelete(namespaceID, params, options) { const { account_id, body } = params; return this._client.post(path `/accounts/${account_id}/storage/kv/namespaces/${namespaceID}/bulk/delete`, { body: body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Retrieves the text-based values of up to 100 keys from the specified Workers KV * namespace. The result maps each requested key to its value. Set `type` to `json` * to parse JSON values instead of returning strings, and set `withMetadata` to * `true` to include metadata with each value. Binary values are not supported by * this operation. * * @deprecated Please use kv.namespaces.bulk_get instead */ bulkGet(namespaceID, params, options) { const { account_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/storage/kv/namespaces/${namespaceID}/bulk/get`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Writes up to 10,000 key-value pairs to the specified Workers KV namespace from a * JSON array, with optional metadata and expiration settings for each pair. * Existing values and expirations are overwritten. If neither `expiration` nor * `expiration_ttl` is specified, the key-value pair will not expire. If both are * set, `expiration_ttl` takes precedence. The entire request must be 100 megabytes * or less. The result reports the number of successful writes and any keys that * failed and should be retried. * * @deprecated Please use kv.namespaces.bulk_update instead */ bulkUpdate(namespaceID, params, options) { const { account_id, body } = params; return this._client.put(path `/accounts/${account_id}/storage/kv/namespaces/${namespaceID}/bulk`, { body: body, ...options, })._thenUnwrap((obj) => obj.result); } } BaseKeys._key = Object.freeze([ 'kv', 'namespaces', 'keys', ]); return BaseKeys; })(); export class Keys extends BaseKeys { } //# sourceMappingURL=keys.mjs.map