Skip to content

Commit 91ad4d9

Browse files
Oxyjunsdnts
authored andcommitted
[DO] Recommending restricting DurableObjectNamespace to jurisdiction, rather than DurableObjectID (cloudflare#22494)
* Not recommending newUniqueId(jurisdiction) approach * Iterating over the docs for clarity and better information segregation * Iterating on feedback * Turning code blocks into in-line code, restructure * Cleaning up footnote lines
1 parent 24d9bca commit 91ad4d9

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

src/content/docs/durable-objects/reference/data-location.mdx

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,39 @@ A [`DurableObjectId`](/durable-objects/api/id) will be logged outside of the spe
1919

2020
:::
2121

22-
Durable Objects can be restricted to a specific jurisdiction either by creating a [`DurableObjectNamespace`](/durable-objects/api/namespace/) restricted to a jurisdiction, or by creating an individual [`DurableObjectId`](/durable-objects/api/id) restricted to a jurisdiction:
22+
Durable Objects can be restricted to a specific jurisdiction by creating a [`DurableObjectNamespace`](/durable-objects/api/namespace/) restricted to a jurisdiction. All [Durable Object ID methods](/durable-objects/api/id/) are valid on IDs within a namespace restricted to a jurisdiction.
2323

2424
```js
2525
const euSubnamespace = env.MY_DURABLE_OBJECT.jurisdiction("eu");
2626
const euId = euSubnamespace.newUniqueId();
27-
// or
28-
const euId = env.MY_DURABLE_OBJECT.newUniqueId({ jurisdiction: "eu" });
2927
```
3028

31-
Methods on a [`DurableObjectNamespace`](/durable-objects/api/namespace/) that take a [`DurableObjectId`](/durable-objects/api/id) as a parameter will throw an exception if the parameter is associated with a different jurisdiction. To achieve this, a [`DurableObjectId`](/durable-objects/api/id) encodes its jurisdiction. As a consequence, it is possible to have the same name represent different IDs in different jurisdictions.
29+
- It is possible to have the same name represent different IDs in different jurisdictions.
3230

33-
```js
34-
const euId1 = env.MY_DURABLE_OBJECT.idFromName("my-name");
35-
const euId2 = env.MY_DURABLE_OBJECT.jurisdiction("eu").idFromName("my-name");
36-
console.assert(!euId1.equal(euId2), "This should always be true");
37-
```
31+
```js
32+
const euId1 = env.MY_DURABLE_OBJECT.idFromName("my-name");
33+
const euId2 = env.MY_DURABLE_OBJECT.jurisdiction("eu").idFromName("my-name");
34+
console.assert(!euId1.equal(euId2), "This should always be true");
35+
```
3836

39-
Methods on a [`DurableObjectNamespace`](/durable-objects/api/namespace/) that take a [`DurableObjectId`](/durable-objects/api/id) as a parameter will throw an exception if the parameter is associated with a different jurisdiction. However, these methods will not throw an exception if the [`DurableObjectNamespace`](/durable-objects/api/namespace/) is not associated with a jurisdiction. The common case is that any valid [`DurableObjectId`](/durable-objects/api/id) can be used in the top-level namespace's methods.
37+
- You will run into an error if the jurisdiction on your [`DurableObjectNamespace`](/durable-objects/api/namespace/) and the jurisdiction on [`DurableObjectId`](/durable-objects/api/id) are different.
38+
- You will not run into an error if the [`DurableObjectNamespace`](/durable-objects/api/namespace/) is not associated with a jurisdiction.
39+
- All [Durable Object ID methods](/durable-objects/api/id/) are valid on IDs within a namespace restricted to a jurisdiction.
4040

41-
```js
42-
const euSubnamespace = env.MY_DURABLE_OBJECT.jurisdiction("eu");
43-
const euId = euSubnamespace.idFromName(name);
44-
const stub = env.MY_DURABLE_OBJECT.get(euId);
45-
```
41+
```js
42+
const euSubnamespace = env.MY_DURABLE_OBJECT.jurisdiction("eu");
43+
const euId = euSubnamespace.idFromName(name);
44+
const stub = env.MY_DURABLE_OBJECT.get(euId);
45+
```
46+
47+
:::caution[Use `DurableObjectNamespace.jurisdiction`]
48+
49+
When specifying a jurisdiction, Cloudflare recommends you first create a namespace restricted to a jurisdiction, using `const euSubnamespace = env.MY_DURABLE_OBJECT.jurisdiction("eu")`.
50+
51+
Note that it is also possible to specify a jurisdiction by creating an individual [`DurableObjectId`](/durable-objects/api/id) restricted to a jurisdiction, using `const euId = env.MY_DURABLE_OBJECT.newUniqueId({ jurisdiction: "eu" })`.
52+
53+
**However, Cloudflare does not recommend this approach.**
54+
:::
4655

4756
### Supported locations
4857

@@ -90,13 +99,9 @@ Hints are a best effort and not a guarantee. Unlike with jurisdictions, Durable
9099
| afr | Africa <sup>2</sup> |
91100
| me | Middle East <sup>2</sup> |
92101

93-
<sup>1</sup> Dynamic relocation of existing Durable Objects is planned for the
94-
future.
102+
<sup>1</sup> Dynamic relocation of existing Durable Objects is planned for the future.
95103

96-
<sup>2</sup> Durable Objects currently do not spawn in this location. Instead,
97-
the Durable Object will spawn in a nearby location which does support Durable
98-
Objects. For example, Durable Objects hinted to South America spawn in Eastern
99-
North America instead.
104+
<sup>2</sup> Durable Objects currently do not spawn in this location. Instead, the Durable Object will spawn in a nearby location which does support Durable Objects. For example, Durable Objects hinted to South America spawn in Eastern North America instead.
100105

101106
## Additional resources
102107

0 commit comments

Comments
 (0)