Actor Namespace
WorkerdActorNamespace is the Worker-side handle for a Cloudflare Durable Object actor.
The namespace is separate from the actor runtime. It binds a Cloudflare Durable Object namespace, validates upgrade requests, and exposes handles for upgrading clients or calling internal methods between Durable Object instances.
import { WorkerdActorNamespace } from "liminal/workerd"
import { TicTacToeActor } from "./TicTacToeActor.ts"
export class TicTacToeNamespace extends WorkerdActorNamespace.Service<TicTacToeNamespace>()("TicTacToeNamespace", {
binding: "TICTACTOE",
actor: TicTacToeActor,
internal: {},
}) {}Fields
binding: the Cloudflare Durable Object binding nameactor: the Liminal actor definitioninternal: methods callable through namespace handles from other Durable Object instances or Worker code
Bind an actor instance
Use Namespace.bind(name) to get a handle for one Durable Object instance.
const game = TicTacToeNamespace.bind(gameId)
yield * game.upgrade({ player: "X" })
yield * game.call("SomeInternalMethod", { value: 1 })upgrade(...) forwards the current request into the Durable Object as a WebSocket upgrade. call(...) invokes one of
the namespace's internal methods through Durable Object RPC.
Provide the namespace
Use TicTacToeNamespace.layer in the Worker runtime. The binding name comes from the namespace definition.
const WorkerLive = TicTacToeNamespace.layerDefine the runtime
The Durable Object class itself comes from WorkerdActorRuntime.make(...).
import { Effect, Layer } from "effect"
import { WorkerdActorRuntime } from "liminal/workerd"
import Move from "./handleMove.ts"
import hydrate from "./hydrate.ts"
import { KvLive } from "./KvLive.ts"
import { TicTacToeNamespace } from "./TicTacToeNamespace.ts"
export class TicTacToeRuntime extends WorkerdActorRuntime.make({
namespace: TicTacToeNamespace,
prelude: KvLive,
hydrate,
onDisconnect: Effect.void,
external: { Move },
internal: {},
layer: Layer.empty,
hibernation: "5 seconds",
}) {}Runtime fields:
namespace: the namespace definition this Durable Object implementsprelude: long-lived runtime dependencies for the Durable Object instancehydrate: returns initial client state during auditionexternal: handlers for client-callable methods fromClient.externalinternal: handlers for namespace-callable methods fromNamespace.internallayer: short-lived, invocation-scoped dependencies derived from actor contextonDisconnect: cleanup or notifications for closed socketshibernation: optional hibernatable WebSocket timeout (Duration.Input)
Read Prelude vs Layer for the dependency model.