Skip to content

Commit fc3a7b5

Browse files
committed
fixup! Move reference documentation out of Durable Objects best practices
1 parent 4c2f919 commit fc3a7b5

File tree

5 files changed

+11
-21
lines changed

5 files changed

+11
-21
lines changed

src/content/docs/durable-objects/api/namespace.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default {
7171

7272
### `idFromName`
7373

74-
`idFromName` creates a [`DurableObjectId`](/durable-objects/api/id) which refers to an individual instance of the Durable Object class from a particular name.
74+
`idFromName` creates a unique [`DurableObjectId`](/durable-objects/api/id) which refers to an individual instance of the Durable Object class. Named Durable Object instances are the most common method of referring to Durable Object instances.
7575

7676
```js
7777
const fooId = env.MY_DURABLE_OBJECT.idFromName("foo");
@@ -88,7 +88,7 @@ const barId = env.MY_DURABLE_OBJECT.idFromName("bar");
8888

8989
### `newUniqueId`
9090

91-
`newUniqueId` creates a `DurableObjectId` which refers to an individual instance of the Durable Object class. When using `newUniqueId`, you need to store the ID as a string in order to refer to the same Durable Object again in the future. For example, the ID can be stored in Workers KV, another Durable Object instance, or in a cookie in the user's browser.
91+
`newUniqueId` creates a randomly generated and unique [`DurableObjectId`](/durable-objects/api/id) which refers to an individual instance of the Durable Object class. IDs created using `newUniqueId`, will need to be stored as a string in order to refer to the same Durable Object again in the future. For example, the ID can be stored in Workers KV, another Durable Object instance, or in a cookie in the user's browser.
9292

9393
```js
9494
const id = env.MY_DURABLE_OBJECT.newUniqueId();
@@ -165,4 +165,3 @@ const euId = subnamespace.idFromName("foo");
165165
## Related resources
166166

167167
- [Durable Objects: Easy, Fast, Correct – Choose Three](https://blog.cloudflare.com/durable-objects-easy-fast-correct-choose-three/).
168-
- [Durable Objects best practices](/durable-objects/best-practices/access-durable-objects-from-a-worker/).

src/content/docs/durable-objects/get-started/tutorial-with-sql-api.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export default {
185185
In the code above, you have:
186186

187187
1. Exported your Worker's main event handlers, such as the `fetch()` handler for receiving HTTP requests.
188-
2. Passed `env` into the `fetch()` handler. Bindings are delivered as a property of the environment object passed as the second parameter when an event handler or class constructor is invoked. By calling the `idFromName()` function on the binding, you use a string-derived object ID. You can also ask the system to [generate random unique IDs](/durable-objects/best-practices/access-durable-objects-from-a-worker/#generate-ids-randomly). System-generated unique IDs have better performance characteristics, but require you to store the ID somewhere to access the Object again later.
188+
2. Passed `env` into the `fetch()` handler. Bindings are delivered as a property of the environment object passed as the second parameter when an event handler or class constructor is invoked. By calling the `idFromName()` function on the binding, you use a string-derived object ID. You can also ask the system to [generate random unique IDs](/durable-objects/api/namespace/#newuniqueid). System-generated unique IDs have better performance characteristics, but require you to store the ID somewhere to access the Object again later.
189189
3. Derived an object ID from the URL path. `MY_DURABLE_OBJECT.idFromName()` always returns the same ID when given the same string as input (and called on the same class), but never the same ID for two different strings (or for different classes). In this case, you are creating a new object for each unique path.
190190
4. Constructed the stub for the Durable Object using the ID. A stub is a client object used to send messages to the Durable Object.
191191
5. Called a Durable Object by invoking a RPC method, `sayHello()`, on the Durable Object, which returns a `Hello, World!` string greeting.
@@ -258,7 +258,6 @@ By finishing this tutorial, you have successfully created, tested and deployed a
258258

259259
### Related resources
260260

261-
- [Access a Durable Object from a Worker](/durable-objects/best-practices/access-durable-objects-from-a-worker/)
262261
- [Create Durable Object stubs](/durable-objects/best-practices/create-durable-object-stubs-and-send-requests/)
263262
- [Access Durable Objects Storage](/durable-objects/best-practices/access-durable-objects-storage/)
264263
- [Miniflare](https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare) - Helpful tools for mocking and testing your Durable Objects.

src/content/docs/durable-objects/get-started/walkthrough.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,5 @@ By finishing this tutorial, you have successfully created, tested and deployed a
258258

259259
### Related resources
260260

261-
- [Access a Durable Object from a Worker](/durable-objects/best-practices/access-durable-objects-from-a-worker/)
262-
- [Create Durable Object stubs](/durable-objects/best-practices/create-durable-object-stubs-and-send-requests/)
261+
- [Send requests to Durable Objects](/durable-objects/best-practices/create-durable-object-stubs-and-send-requests/)
263262
- [Miniflare](https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare) - Helpful tools for mocking and testing your Durable Objects.

src/content/docs/durable-objects/reference/websockets.mdx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pcx_content_type: concept
33
title: Durable Objects with WebSockets
44
sidebar:
55
order: 3
6-
76
---
87

98
[WebSockets](/durable-objects/api/websockets/) allow real time communication between a client and server. Both Cloudflare Durable Objects and Workers can act as WebSocket endpoints – either as a client or as a server.
@@ -14,16 +13,14 @@ Durable Objects provide a single-point-of-coordination for [Cloudflare Workers](
1413

1514
While there are other use cases for using Workers exclusively with WebSockets, WebSockets are most useful when combined with Durable Objects.
1615

17-
When a client connects to your application using a WebSocket, you need a way for server-generated messages to be sent using the existing socket connection. Multiple clients can establish a WebSocket connection with a specific Durable Object addressed by its [unique ID](/durable-objects/best-practices/access-durable-objects-from-a-worker/#1-create-durable-object-ids). The Durable Object can then send messages to each client over the WebSocket connection.
16+
When a client connects to your application using a WebSocket, you need a way for server-generated messages to be sent using the existing socket connection. Multiple clients can establish a WebSocket connection with a specific Durable Object addressed by its unique ID. The Durable Object can then send messages to each client over the WebSocket connection.
1817

1918
Durable Objects can use the web standard APIs described in [WebSockets API](/durable-objects/api/websockets/). Refer to [Cloudflare Edge Chat Demo](https://github.com/cloudflare/workers-chat-demo) for an example of using Durable Objects with WebSockets.
2019

2120
:::caution[WebSockets disconnection]
2221

23-
2422
Code updates will disconnect all WebSockets. If you deploy a new version of a Worker, every Durable Object is restarted. Any connections to old Durable Objects will be disconnected.
2523

26-
2724
:::
2825

2926
## WebSocket Hibernation
@@ -32,19 +29,17 @@ The WebSocket Hibernation API allows a Durable Object that is not currently runn
3229

3330
:::note
3431

35-
3632
Hibernation is only supported when a Durable Object acts as a WebSocket server. Outgoing WebSockets cannot be hibernated as of now.
3733

38-
3934
:::
4035

4136
A Durable Object with WebSockets created via the Hibernation API will not incur billable [Duration (GB-s) charges](/durable-objects/platform/pricing/) during periods of inactivity, unlike Durable Objects using the [regular WebSockets API](/workers/runtime-apis/websockets/).
4237

4338
The WebSocket Hibernation API includes:
4439

45-
* Cloudflare-specific extensions to the web standard WebSocket API.
46-
* Related methods on the [`state`](/durable-objects/api/websockets/#state-methods) of the Durable Object.
47-
* [Handler methods](/durable-objects/api/websockets/#handler-methods) that a Durable Object can implement for processing WebSocket events.
40+
- Cloudflare-specific extensions to the web standard WebSocket API.
41+
- Related methods on the [`state`](/durable-objects/api/websockets/#state-methods) of the Durable Object.
42+
- [Handler methods](/durable-objects/api/websockets/#handler-methods) that a Durable Object can implement for processing WebSocket events.
4843

4944
The WebSocket Hibernation API enables you to terminate (not proxy) WebSocket connections within a Durable Object, and push messages to all connected clients based on state stored within the [Storage API](/durable-objects/api/storage-api/), HTTP fetches to external services, and/or data stored in [R2](/r2/) and [Workers KV](/kv/api/).
5045

@@ -54,16 +49,14 @@ If an event occurs for a hibernated Durable Object's corresponding handler metho
5449

5550
:::caution[Support for local development]
5651

57-
5852
Prior to `[email protected]` and Miniflare `v3.20231016.0`, WebSockets did not hibernate when using local development environments such as `wrangler dev` or Miniflare.
5953

6054
If you are using older versions, note that while hibernatable WebSocket events such as [`webSocketMessage()`](/durable-objects/api/websockets/#websocketmessage) will still be delivered, the Durable Object will never be evicted from memory.
6155

62-
6356
:::
6457

65-
***
58+
---
6659

6760
## Related resources
6861

69-
* Refer to [Build a WebSocket server with WebSocket Hibernation](/durable-objects/examples/websocket-hibernation-server/) to learn more about building a WebSocket server using WebSocket Hibernation on Durable Objects and Workers.
62+
- Refer to [Build a WebSocket server with WebSocket Hibernation](/durable-objects/examples/websocket-hibernation-server/) to learn more about building a WebSocket server using WebSocket Hibernation on Durable Objects and Workers.

src/content/docs/workers/configuration/versions-and-deployments/gradual-deployments.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ When you create a new gradual deployment for a Durable Object Worker, each Durab
205205

206206
### Example
207207

208-
This example assumes that you have previously created 3 Durable Objects and [derived their IDs from the names](/durable-objects/best-practices/access-durable-objects-from-a-worker/#derive-ids-from-names) "foo", "bar" and "baz".
208+
This example assumes that you have previously created 3 Durable Objects and [derived their IDs from the names](/durable-objects/api/namespace/#idfromname) "foo", "bar" and "baz".
209209

210210
Your Worker is currently on a version that we will call version "A" and you want to gradually deploy a new version "B" of your Worker.
211211

0 commit comments

Comments
 (0)