cloudflare
Version:
The official TypeScript library for the Cloudflare API
209 lines • 8.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Namespaces = exports.BaseNamespaces = void 0;
const tslib_1 = require("../../../internal/tslib.js");
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
const resource_1 = require("../../../core/resource.js");
const KeysAPI = tslib_1.__importStar(require("./keys.js"));
const keys_1 = require("./keys.js");
const MetadataAPI = tslib_1.__importStar(require("./metadata.js"));
const metadata_1 = require("./metadata.js");
const ValuesAPI = tslib_1.__importStar(require("./values.js"));
const values_1 = require("./values.js");
const pagination_1 = require("../../../core/pagination.js");
const path_1 = require("../../../internal/utils/path.js");
var BaseNamespaces = /* @__PURE__ */ (() => {
class BaseNamespaces extends resource_1.APIResource {
/**
* Creates a Workers KV namespace in the specified account with the given title.
* Returns `400` if the account already owns a namespace with that title; an
* existing namespace must be explicitly deleted before it can be replaced. An
* optional jurisdiction restricts where data is durably stored and can only be set
* at creation time.
*
* @example
* ```ts
* const namespace = await client.kv.namespaces.create({
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* title: 'My Own Namespace',
* });
* ```
*/
create(params, options) {
const { account_id, ...body } = params;
return this._client.post((0, path_1.path) `/accounts/${account_id}/storage/kv/namespaces`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Changes the title of the specified Workers KV namespace and returns the updated
* namespace. The namespace ID and stored key-value pairs are unchanged.
*
* @example
* ```ts
* const namespace = await client.kv.namespaces.update(
* '0f2ac74b498b48028cb68387c421e279',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* title: 'My Own Namespace',
* },
* );
* ```
*/
update(namespaceID, params, options) {
const { account_id, ...body } = params;
return this._client.put((0, path_1.path) `/accounts/${account_id}/storage/kv/namespaces/${namespaceID}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Lists Workers KV namespaces owned by the specified account. Use `page` and
* `per_page` to select a page of results, and `order` and `direction` to control
* sorting.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const namespace of client.kv.namespaces.list({
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* })) {
* // ...
* }
* ```
*/
list(params, options) {
const { account_id, ...query } = params;
return this._client.getAPIList((0, path_1.path) `/accounts/${account_id}/storage/kv/namespaces`, (pagination_1.V4PagePaginationArray), { query, ...options });
}
/**
* Deletes the specified Workers KV namespace and its stored key-value pairs from
* the account.
*
* @example
* ```ts
* const namespace = await client.kv.namespaces.delete(
* '0f2ac74b498b48028cb68387c421e279',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(namespaceID, params, options) {
const { account_id } = params;
return this._client.delete((0, path_1.path) `/accounts/${account_id}/storage/kv/namespaces/${namespaceID}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* 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.
*
* @example
* ```ts
* const response = await client.kv.namespaces.bulkDelete(
* '0f2ac74b498b48028cb68387c421e279',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* body: ['My-Key'],
* },
* );
* ```
*/
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.
*
* @example
* ```ts
* const response = await client.kv.namespaces.bulkGet(
* '0f2ac74b498b48028cb68387c421e279',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* keys: ['My-Key'],
* },
* );
* ```
*/
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.
*
* @example
* ```ts
* const response = await client.kv.namespaces.bulkUpdate(
* '0f2ac74b498b48028cb68387c421e279',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* body: [{ key: 'My-Key', value: 'Some string' }],
* },
* );
* ```
*/
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);
}
/**
* Returns the Workers KV namespace for the specified account and namespace ID.
*
* @example
* ```ts
* const namespace = await client.kv.namespaces.get(
* '0f2ac74b498b48028cb68387c421e279',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
get(namespaceID, params, options) {
const { account_id } = params;
return this._client.get((0, path_1.path) `/accounts/${account_id}/storage/kv/namespaces/${namespaceID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseNamespaces._key = Object.freeze(['kv', 'namespaces']);
return BaseNamespaces;
})();
exports.BaseNamespaces = BaseNamespaces;
var Namespaces = /* @__PURE__ */ (() => {
class Namespaces extends BaseNamespaces {
constructor() {
super(...arguments);
this.keys = new KeysAPI.Keys(this._client);
this.metadata = new MetadataAPI.Metadata(this._client);
this.values = new ValuesAPI.Values(this._client);
}
}
Namespaces.Keys = keys_1.Keys;
Namespaces.BaseKeys = keys_1.BaseKeys;
Namespaces.Metadata = metadata_1.Metadata;
Namespaces.BaseMetadata = metadata_1.BaseMetadata;
Namespaces.Values = values_1.Values;
Namespaces.BaseValues = values_1.BaseValues;
return Namespaces;
})();
exports.Namespaces = Namespaces;
//# sourceMappingURL=namespaces.js.map