Programmatic configuration·续5
<dt><code>containers?: ConfigInput<ContainerConfig>[]</code></dt> <dd>Container applications defined by this configuration.</dd></dl></details>
</details>
<details>
<summary>worker: { (worker reference)</summary>
<code>worker</code>Optional<a href="#config-rename-delete-cloudflareconfig-worker">Link to worker</a>
<code>worker?: ConfigInput<WorkerConfig></code>
The Worker defined by this configuration.
</details>
<details>
<summary>name: "counter-worker", (name reference)</summary>
<code>name</code>Required<a href="#config-rename-delete-workerconfig-name">Link to name</a>
<code>name: string</code>
The name of your Worker.
</details>
<details>
<summary>entrypoint, (entrypoint reference)</summary>
<code>entrypoint</code>Optional<a href="#config-rename-delete-workerconfig-entrypoint">Link to entrypoint</a>
<code>entrypoint?: string | WorkerModule</code>
The entrypoint module that will be executed. May be either a path string (e.g. <code>"./src/index.ts"</code>) or a module namespace imported with the <code>cf-worker</code> import attribute.
</details>
<details>
<summary>compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)</summary>
<code>compatibilityDate</code>Required<a href="#config-rename-delete-workerconfig-compatibilitydate">Link to compatibilityDate</a>
<code>compatibilityDate: string</code>
A date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at <a href="https://developers.cloudflare.com/workers/configuration/compatibility-dates">https://developers.cloudflare.com/workers/configuration/compatibility-dates</a>
</details>
<details>
<summary>exports: { (exports reference)</summary>
<code>exports</code>Optional<a href="#config-rename-delete-workerconfig-exports">Link to exports</a>
<code>exports?: Record<string, Export></code>
Configuration for named exports declared by the Worker. Each entry's key is the exported class name; the value configures the export. - Construct entries with <code>exports.durableObject(...)</code>. - Declares Durable Object classes exported from this Worker. For more information about Durable Objects, see the documentation at <a href="https://developers.cloudflare.com/workers/learning/using-durable-objects">https://developers.cloudflare.com/workers/learning/using-durable-objects</a>. For reference, see <a href="https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects">https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects</a>. - Construct entries with <code>exports.workflow(...)</code>. - Declares Workflows defined by this Worker. For more information about Workflows, see the documentation at <a href="https://developers.cloudflare.com/workflows/">https://developers.cloudflare.com/workflows/</a>.
</details>
<details>
<summary>Counter: exports.durableObject({ storage: "sqlite" }), (durableObject, storage reference)</summary>
<code>durableObject</code>Builder<a href="#config-rename-delete-exports-durableobject-created">Link to durableObject</a>
<code>durableObject<TContainer extends ContainerDefinition | undefined = undefined>(options: DurableObjectCreatedExportOptions<TContainer>): DurableObjectCreatedExport<TContainer>;</code>
Declares a Durable Object class defined by this Worker. For more information about Durable Objects, see the documentation at <a href="https://developers.cloudflare.com/workers/learning/using-durable-objects">https://developers.cloudflare.com/workers/learning/using-durable-objects</a> For reference, see <a href="https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects">https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects</a>
<details>
<summary>Options (4)</summary>
<dl>
<dt><code>state?: "created"</code></dt> <dd></dd>
<dt><code>storage: "sqlite"</code></dt> <dd>Selects the SQLite-backed storage engine (recommended for new classes).</dd>
<dt><code>container?: TContainer</code></dt> <dd>Attach a Container application to this Durable Object by config reference.</dd>
<dt><code>storage: "legacy-kv"</code></dt> <dd>Selects the legacy key-value storage engine.</dd></dl></details>
<code>storage</code>Required<a href="#config-rename-delete-exports-durableobject-created">Link to storage</a>
<code>storage: "sqlite" | "legacy-kv"</code>
Selects the SQLite-backed storage engine (recommended for new classes). Selects the legacy key-value storage engine.
</details>
<details>
<summary>OldCounter: exports.durableObject({ (durableObject reference)</summary>
<code>durableObject</code>Builder<a href="#config-rename-delete-exports-durableobject-renamed">Link to durableObject</a>
<code>durableObject(options: DurableObjectRenamedExportOptions): DurableObjectRenamedExport;</code>
Rename a provisioned Durable Object namespace's class.
<details>
<summary>Options (2)</summary>
<dl>
<dt><code>state: "renamed"</code></dt> <dd></dd>
<dt><code>renamedTo: string</code></dt> <dd>The destination class name. Must be a valid JavaScript identifier and must appear as a live (<code>state: "created"</code>) <code>durableObject</code> entry in the same <code>exports</code> map.</dd></dl></details>
</details>
<details>
<summary>state: "renamed", (state reference)</summary>
<code>state</code>Required<a href="#config-rename-delete-exports-durableobject-renamed-state">Link to state</a>
<code>state: "renamed"</code>
The type definition does not include a description.
</details>
<details>
<summary>renamedTo: "Counter", (renamedTo reference)</summary>
<code>renamedTo</code>Required<a href="#config-rename-delete-exports-durableobject-renamed-renamedto">Link to renamedTo</a>
<code>renamedTo: string</code>
The destination class name. Must be a valid JavaScript identifier and must appear as a live (<code>state: "created"</code>) <code>durableObject</code> entry in the same <code>exports</code> map.
</details>
}),
<details>
<summary>UnusedCounter: exports.durableObject({ state: "deleted" }), (durableObject, state reference)</summary>
<code>durableObject</code>Builder<a href="#config-rename-delete-exports-durableobject-deleted">Link to durableObject</a>
<code>durableObject(options: DurableObjectDeletedExportOptions): DurableObjectDeletedExport;</code>
Retire a provisioned Durable Object namespace whose class has been removed from code.
<details>
<summary>Options (1)</summary>
<dl>
<dt><code>state: "deleted"</code></dt> <dd></dd>
</dl></details>
<code>state</code>Required<a href="#config-rename-delete-exports-durableobject-deleted">Link to state</a>
<code>state: "deleted"</code>
The type definition does not include a description.
</details>
},
},
});
Before you delete a namespace, remove every binding to that class. The uploaded Worker must not export a class marked as deleted.
Deployment responses identify stale tombstones that are safe to remove. Keep each tombstone until it appears in that response, then remove it from the map. You do not need to retain the complete migration history.
Transfer a class between Workers
A namespace transfer uses two deployments. Both Workers must use the same Cloudflare account.
First, deploy the destination Worker with an incoming live entry:
Select a highlighted line to show its type and description below it.
destination/cloudflare.config.ts
Expand allCopy
import { defineConfig, exports } from "cf/config";
import * as entrypoint from "./src/index.ts" with { type: "cf-worker" };
<details>
<summary>export default defineConfig({ (defineConfig reference)</summary>
<code>defineConfig</code>Function<a href="#config-transfer-destination-defineconfig">Link to defineConfig</a>
<code>defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;</code>
Defines the default export of <code>cloudflare.config.ts</code>. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (<code>isPreview</code> and <code>mode</code>) and returns either.
<details>
<summary>Options (4)</summary>
<dl>
<dt><code>accountId?: string</code></dt> <dd>This is the ID of the account associated with your zone. It can also be specified through the <code>CLOUDFLARE_ACCOUNT_ID</code> environment variable.</dd>
<dt><code>complianceRegion?: "public" | "fedramp-high"</code></dt> <dd>The compliance boundary in which commands should operate. When omitted, this can be supplied through <code>CLOUDFLARE_COMPLIANCE_REGION</code>.</dd>
<dt><code>worker?: ConfigInput<WorkerConfig></code></dt> <dd>The Worker defined by this configuration.</dd>
<dt><code>containers?: ConfigInput<ContainerConfig>[]</code></dt> <dd>Container applications defined by this configuration.</dd></dl></details>
</details>
<details>
<summary>worker: { (worker reference)</summary>
<code>worker</code>Optional<a href="#config-transfer-destination-cloudflareconfig-worker">Link to worker</a>
<code>worker?: ConfigInput<WorkerConfig></code>
The Worker defined by this configuration.
</details>
<details>
<summary>name: "destination-worker", (name reference)</summary>
<code>name</code>Required<a href="#config-transfer-destination-workerconfig-name">Link to name</a>
<code>name: string</code>
The name of your Worker.
</details>
<details>
<summary>entrypoint, (entrypoint reference)</summary>
<code>entrypoint</code>Optional<a href="#config-transfer-destination-workerconfig-entrypoint">Link to entrypoint</a>
<code>entrypoint?: string | WorkerModule</code>
The entrypoint module that will be executed. May be either a path string (e.g. <code>"./src/index.ts"</code>) or a module namespace imported with the <code>cf-worker</code> import attribute.
</details>
<details>
<summary>compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)</summary>
<code>compatibilityDate</code>Required<a href="#config-transfer-destination-workerconfig-compatibilitydate">Link to compatibilityDate</a>
<code>compatibilityDate: string</code>
A date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at <a href="https://developers.cloudflare.com/workers/configuration/compatibility-dates">https://developers.cloudflare.com/workers/configuration/compatibility-dates</a>
</details>
<details>
<summary>exports: { (exports reference)</summary>
<code>exports</code>Optional<a href="#config-transfer-destination-workerconfig-exports">Link to exports</a>
<code>exports?: Record<string, Export></code>
Configuration for named exports declared by the Worker. Each entry's key is the exported class name; the value configures the export. - Construct entries with <code>exports.durableObject(...)</code>. - Declares Durable Object classes exported from this Worker. For more information about Durable Objects, see the documentation at <a href="https://developers.cloudflare.com/workers/learning/using-durable-objects">https://developers.cloudflare.com/workers/learning/using-durable-objects</a>. For reference, see <a href="https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects">https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects</a>. - Construct entries with <code>exports.workflow(...)</code>. - Declares Workflows defined by this Worker. For more information about Workflows, see the documentation at <a href="https://developers.cloudflare.com/workflows/">https://developers.cloudflare.com/workflows/</a>.
</details>
<details>
<summary>Counter: exports.durableObject({ (durableObject reference)</summary>
<code>durableObject</code>Builder<a href="#config-transfer-destination-exports-durableobject-expecting-transfer">Link to durableObject</a>
<code>durableObject<TContainer extends ContainerDefinition | undefined = undefined>(options: DurableObjectExpectingTransferExportOptions<TContainer>): DurableObjectExpectingTransferExport<TContainer>;</code>
Prepare to receive cross-Worker Durable Object transfer. The source Worker must follow up with a deployment containing a <code>transferred</code> export to commit the transfer.
<details>
<summary>Options (5)</summary>
<dl>
<dt><code>state: "expecting-transfer"</code></dt> <dd></dd>
<dt><code>transferFrom: string</code></dt> <dd>The source Worker for the two-phase cross-Worker transfer.</dd>
<dt><code>storage: "sqlite"</code></dt> <dd>Selects the SQLite-backed storage engine (recommended for new classes).</dd>
<dt><code>container?: TContainer</code></dt> <dd>Attach a Container application to this Durable Object by config reference.</dd>
<dt><code>storage: "legacy-kv"</code></dt> <dd>Selects the legacy key-value storage engine.</dd></dl></details>
</details>
<details>
<summary>state: "expecting-transfer", (state reference)</summary>
<code>state</code>Required<a href="#config-transfer-destination-exports-durableobject-expecting-transfer-state">Link to state</a>
<code>state: "expecting-transfer"</code>
The type definition does not include a description.
</details>
<details>
<summary>storage: "sqlite", (storage reference)</summary>
<code>storage</code>Required<a href="#config-transfer-destination-exports-durableobject-expecting-transfer-storage">Link to storage</a>
<code>storage: "sqlite" | "legacy-kv"</code>
Selects the SQLite-backed storage engine (recommended for new classes). Selects the legacy key-value storage engine.
</details>
<details>
<summary>transferFrom: "source-worker", (transferFrom reference)</summary>
<code>transferFrom</code>Required<a href="#config-transfer-destination-exports-durableobject-expecting-transfer-transferfrom">Link to transferFrom</a>
<code>transferFrom: string</code>
The source Worker for the two-phase cross-Worker transfer.
</details>
}),
},
},
});
Then deploy the source Worker with a transfer tombstone:
Select a highlighted line to show its type and description below it.
source/cloudflare.config.ts
Expand allCopy
import { defineConfig, exports } from "cf/config";
import * as entrypoint from "./src/index.ts" with { type: "cf-worker" };
<details>
<summary>export default defineConfig({ (defineConfig reference)</summary>
<code>defineConfig</code>Function<a href="#config-transfer-source-defineconfig">Link to defineConfig</a>
<code>defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;</code>
Defines the default export of <code>cloudflare.config.ts</code>. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (<code>isPreview</code> and <code>mode</code>) and returns either.
<details>
<summary>Options (4)</summary>
<dl>
<dt><code>accountId?: string</code></dt> <dd>This is the ID of the account associated with your zone. It can also be specified through the <code>CLOUDFLARE_ACCOUNT_ID</code> environment variable.</dd>
<dt><code>complianceRegion?: "public" | "fedramp-high"</code></dt> <dd>The compliance boundary in which commands should operate. When omitted, this can be supplied through <code>CLOUDFLARE_COMPLIANCE_REGION</code>.</dd>
<dt><code>worker?: ConfigInput<WorkerConfig></code></dt> <dd>The Worker defined by this configuration.</dd>
<dt><code>containers?: ConfigInput<ContainerConfig>[]</code></dt> <dd>Container applications defined by this configuration.</dd></dl></details>
</details>
<details>
<summary>worker: { (worker reference)</summary>
<code>worker</code>Optional<a href="#config-transfer-source-cloudflareconfig-worker">Link to worker</a>
<code>worker?: ConfigInput<WorkerConfig></code>
The Worker defined by this configuration.
</details>
<details>
<summary>name: "source-worker", (name reference)</summary>
<code>name</code>Required<a href="#config-transfer-source-workerconfig-name">Link to name</a>
<code>name: string</code>
The name of your Worker.
</details>
<details>
<summary>entrypoint, (entrypoint reference)</summary>
<code>entrypoint</code>Optional<a href="#config-transfer-source-workerconfig-entrypoint">Link to entrypoint</a>
<code>entrypoint?: string | WorkerModule</code>
The entrypoint module that will be executed. May be either a path string (e.g. <code>"./src/index.ts"</code>) or a module namespace imported with the <code>cf-worker</code> import attribute.
</details>
<details>
<summary>compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)</summary>
<code>compatibilityDate</code>Required<a href="#config-transfer-source-workerconfig-compatibilitydate">Link to compatibilityDate</a>
<code>compatibilityDate: string</code>
A date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at <a href="https://developers.cloudflare.com/workers/configuration/compatibility-dates">https://developers.cloudflare.com/workers/configuration/compatibility-dates</a>
</details>
<details>
<summary>exports: { (exports reference)</summary>
<code>exports</code>Optional<a href="#config-transfer-source-workerconfig-exports">Link to exports</a>
<code>exports?: Record<string, Export></code>
