-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Update reference documentation for Worker accessible DO interfaces #17411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1003595
Add runtime API reference docs for Worker accessible interfaces
joshthoward 8cfdcb5
Update data location docs to account for docs for Worker accessible i…
joshthoward 0c41e9b
Update src/content/docs/durable-objects/api/namespace.mdx
Oxyjun b92f7c8
Update src/content/docs/durable-objects/api/id.mdx
Oxyjun f929620
Jun/PCX edits part 1
Oxyjun 279071d
Replacing relative paths to absolute paths.
Oxyjun ad4b2be
Fixing more invalid relative paths.
Oxyjun 1913630
Apply suggestions from code review
Oxyjun afb20a2
Adding suggestion.
Oxyjun 03863e5
Merge branch 'joshthoward/do-docs' of github.com:cloudflare/cloudflar…
Oxyjun 0f81545
Apply suggestions from code review
Oxyjun 9503ffe
Ensuring consistent wording for description of DurableObjectNamespace.
Oxyjun d21b9fb
Update src/content/docs/durable-objects/api/alarms.mdx
Oxyjun 84f382f
Update src/content/docs/durable-objects/api/alarms.mdx
Oxyjun 76f073c
Update src/content/docs/durable-objects/api/storage-api.mdx
Oxyjun a8cc386
"Two seconds" -> "2 seconds", "six seconds" -> "6 seconds"
Oxyjun 3010e95
Merge branch 'joshthoward/do-docs' of github.com:cloudflare/cloudflar…
Oxyjun c3ee93b
Adding link to best practices section.
Oxyjun 7ab17b2
Address remaining comments
joshthoward File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| --- | ||
| title: Durable Object ID | ||
Oxyjun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pcx_content_type: concept | ||
| sidebar: | ||
| order: 2 | ||
| --- | ||
|
|
||
| import { Tabs, TabItem } from "~/components"; | ||
|
|
||
| ## Description | ||
|
|
||
| The `DurableObjectId` interface refers to a new or existing Durable Object instance. This interface is most frequently used by [`DurableObjectNamespace::get`](/durable-objects/api/namespace/#get) to obtain a stub for submitting requests to a Durable Object instance. | ||
|
|
||
| Note that creating an ID for a Durable Object instance does not create the Durable Object. The Durable Object is created lazily after calling [`DurableObjectNamespace::get`](/durable-objects/api/namespace/#get) to create a [`DurableObjectStub`](/durable-objects/api/stub) from a `DurableObjectId`. This ensures that objects are not constructed until they are actually accessed. | ||
|
|
||
| :::note[`DurableObjectId`] | ||
|
|
||
| If you are experiencing an issue with a particular Durable Object instance, you may wish to log the `DurableObjectId` from your Worker and include it in your Cloudflare support request. | ||
|
|
||
| ::: | ||
|
|
||
| ## Methods | ||
|
|
||
| ### `toString` | ||
|
|
||
| #### Description | ||
|
|
||
| `toString` converts a `DurableObjectId` to a 64 digit hex string. This string is useful for logging purposes or storing the `DurableObjectId` elsewhere, for example, in a session cookie. This string can be used to reconstruct a `DurableObjectId` via `DurableObjectNamespace::idFromString`. | ||
|
|
||
| ```js | ||
| // Create a new unique ID | ||
| const id = env.MY_DURABLE_OBJECT.newUniqueId(); | ||
| // Save the unique ID elsewhere, e.g. a session cookie via id.toString() | ||
joshthoward marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ... | ||
| // Recreate the ID from the string | ||
| const id = env.MY_DURABLE_OBJECT.idFromString(session_id); | ||
| ``` | ||
|
|
||
| #### Parameters | ||
|
|
||
| None. | ||
|
|
||
| #### Return value | ||
|
|
||
| A 64 digit hex string. | ||
|
|
||
| ### `equals` | ||
|
|
||
| #### Description | ||
|
|
||
| `equals` is used to compare equality between two instances of `DurableObjectId`. | ||
|
|
||
| ```js | ||
| const id1 = env.MY_DURABLE_OBJECT.newUniqueId(); | ||
| const id2 = env.MY_DURABLE_OBJECT.newUniqueId(); | ||
| console.assert(!id1.equals(id2), "Different unique ids should never be equal."); | ||
| ``` | ||
|
|
||
| #### Parameters | ||
|
|
||
| A required `DurableObjectId` to compare against. | ||
|
|
||
| #### Return value | ||
|
|
||
| A boolean. True if equal and false otherwise. | ||
|
|
||
| ## Properties | ||
|
|
||
| ### `name` | ||
|
|
||
| #### Description | ||
|
|
||
| `name` is an optional property of a `DurableObjectId`, which returns the name that was used to create the `DurableObjectId` via [`DurableObjectNamespace::idFromName`](/durable-objects/api/namespace/#idfromname). This value is undefined if the `DurableObjectId` was constructed using [`DurableObjectNamespace::newUniqueId`](/durable-objects/api/namespace/#newuniqueid). | ||
|
|
||
| ```js | ||
| const uniqueId = env.MY_DURABLE_OBJECT.newUniqueId(); | ||
| const fromNameId = env.MY_DURABLE_OBJECT.idFromName("foo"); | ||
| console.assert(uniqueId.name === undefined, "unique ids have no name"); | ||
| console.assert(fromNameId.name === "foo", "name matches parameter to idFromName"); | ||
| ``` | ||
|
|
||
| ## Related resources | ||
|
|
||
| - [Durable Objects: Easy, Fast, Correct – Choose Three](https://blog.cloudflare.com/durable-objects-easy-fast-correct-choose-three/). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| --- | ||
| title: API | ||
| title: Runtime APIs | ||
| pcx_content_type: navigation | ||
| sidebar: | ||
| order: 4 | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.