partyserver@0.5.3
Patch Changes
-
#386
8a3bc02Thanks @threepointone! - Document and test the supported pattern for using PartyServer with Durable Object Facets. No runtime behavior change.Background. Facets spawned via
ctx.facets.get(name, factory)without an explicitidinFacetStartupOptionsinherit the parent DO'sctx.id— includingctx.id.name. PartyServer'snamegetter readsctx.id.namestraight through, so on an implicit-id facetthis.namereturns the parent's name rather than the facet's logical name. This is a faithful reflection of the workerd contract, but it's almost never what framework authors expect.The fix is at the call site, not in PartyServer: pass
id: someBoundDONamespace.idFromName(facetName)toctx.facets.get(...). The facet then gets its own nativectx.id.name === facetNameand PartyServer'snamegetter does the right thing automatically. NosetName()is required, no__ps_namestorage record is written, and cold-wake recovery happens for free because the factory re-runs andidFromNameis deterministic.This release adds:
- A "Using PartyServer with Durable Object Facets" section in the README that walks through the recommended pattern with a code example, calls out the implicit-id footgun explicitly, and documents that plain-string
idvalues are not a substitute foridFromName(facetName)(workerd treats string ids asidFromString-like, so the resulting facet has noctx.id.name). setName()docstring updated to clarify that facets are NOT asetName()use case — point to the explicit-idpattern instead. The originalsetName()ctx.id.namemismatch throw is preserved as a typo guard for theidFromNamehappy path.- End-to-end facet test coverage against the real workerd
ctx.facets.get(...)API. AFacetParent/FacetChildfixture exercises both the implicit-id path (pinning the runtime contract thatthis.namereturns the parent's name in that flow — i.e., behavior-as-documentation so framework authors are unsurprised) and the explicit-id path (recommended; verifies that all reasonable id-construction strategies work and that cold wake recovers without any storage record). Plain-stringidis also tested; the test asserts it does NOT carry a name, pinning the contract so callers don't get tempted by the type signature.
The runtime behavior of
Server(thenamegetter,setName(), the legacy__ps_namehydrate inside#ensureInitialized()) is unchanged from 0.5.2. - A "Using PartyServer with Durable Object Facets" section in the README that walks through the recommended pattern with a code example, calls out the implicit-id footgun explicitly, and documents that plain-string