UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

90 lines • 4.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Keys = exports.BaseKeys = void 0; // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../../core/resource.js"); const pagination_1 = require("../../../core/pagination.js"); const path_1 = require("../../../internal/utils/path.js"); var BaseKeys = /* @__PURE__ */ (() => { class BaseKeys extends resource_1.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((0, path_1.path) `/accounts/${account_id}/storage/kv/namespaces/${namespaceID}/keys`, (pagination_1.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((0, path_1.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((0, path_1.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((0, path_1.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; })(); exports.BaseKeys = BaseKeys; class Keys extends BaseKeys { } exports.Keys = Keys; //# sourceMappingURL=keys.js.map