cloudflare
Version:
The official TypeScript library for the Cloudflare API
144 lines • 5.19 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../../core/resource.mjs";
import * as VersionsAPI from "./versions.mjs";
import { BaseVersions, Versions, } from "./versions.mjs";
import { V4PagePaginationArray, } from "../../../../core/pagination.mjs";
import { path } from "../../../../internal/utils/path.mjs";
export var BaseWorkers = /* @__PURE__ */ (() => {
class BaseWorkers extends APIResource {
/**
* Create a new Worker.
*
* @example
* ```ts
* const worker = await client.workers.beta.workers.create({
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* name: 'my-worker',
* });
* ```
*/
create(params, options) {
const { account_id, ...body } = params;
return this._client.post(path `/accounts/${account_id}/workers/workers`, { body, ...options })._thenUnwrap((obj) => obj.result);
}
/**
* Perform a complete replacement of a Worker, where omitted properties are set to
* their default values. This is the exact same as the Create Worker endpoint, but
* operates on an existing Worker. To perform a partial update instead, use the
* Edit Worker endpoint.
*
* @example
* ```ts
* const worker = await client.workers.beta.workers.update(
* 'worker_id',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* name: 'my-worker',
* },
* );
* ```
*/
update(workerID, params, options) {
const { account_id, ...body } = params;
return this._client.put(path `/accounts/${account_id}/workers/workers/${workerID}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* List all Workers for an account.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const worker of client.workers.beta.workers.list(
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* )) {
* // ...
* }
* ```
*/
list(params, options) {
const { account_id, ...query } = params;
return this._client.getAPIList(path `/accounts/${account_id}/workers/workers`, (V4PagePaginationArray), { query, ...options });
}
/**
* Delete a Worker and all its associated resources (versions, deployments, etc.).
*
* @example
* ```ts
* const worker = await client.workers.beta.workers.delete(
* 'worker_id',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(workerID, params, options) {
const { account_id, force } = params;
return this._client.delete(path `/accounts/${account_id}/workers/workers/${workerID}`, {
query: { force },
...options,
});
}
/**
* Perform a partial update on a Worker, where omitted properties are left
* unchanged from their current values.
*
* @example
* ```ts
* const worker = await client.workers.beta.workers.edit(
* 'worker_id',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* logpush: true,
* name: 'my-worker',
* observability: {},
* subdomain: {},
* tags: ['my-team', 'my-public-api'],
* tail_consumers: [{ name: 'my-tail-consumer' }],
* },
* );
* ```
*/
edit(workerID, params, options) {
const { account_id, ...body } = params;
return this._client.patch(path `/accounts/${account_id}/workers/workers/${workerID}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Get details about a specific Worker.
*
* @example
* ```ts
* const worker = await client.workers.beta.workers.get(
* 'worker_id',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
get(workerID, params, options) {
const { account_id } = params;
return this._client.get(path `/accounts/${account_id}/workers/workers/${workerID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseWorkers._key = Object.freeze([
'workers',
'beta',
'workers',
]);
return BaseWorkers;
})();
export var Workers = /* @__PURE__ */ (() => {
class Workers extends BaseWorkers {
constructor() {
super(...arguments);
this.versions = new VersionsAPI.Versions(this._client);
}
}
Workers.Versions = Versions;
Workers.BaseVersions = BaseVersions;
return Workers;
})();
//# sourceMappingURL=workers.mjs.map