FlareDurableObject
class FlareDurableObject extends DurableObject<Cloudflare.Env>Base class for Flare Durable Objects. Extend it, declare static deps, register with
host.durableObject(Class) before host.build().
Each instance composes its own per-instance lazy container seeded with DurableState and
Bindings. User scoped services registered via host.scoped() resolve lazily per instance.
How you get one
Section titled “How you get one”new FlareDurableObject(ctx, env)
Constructor
Section titled “Constructor”new FlareDurableObject(ctx: DurableObjectState, env: Env): FlareDurableObjectctx DurableObjectState
env Env
Properties
Section titled “Properties”deps: readonly ServiceToken<FlareService>[]state: readonly StateToken[]Methods
Section titled “Methods”config()
Section titled “config()”config<T>(token: ConfigToken<T>): TResolves a config token.
token ConfigToken<T>
returns T
fetch()
Section titled “fetch()”fetch(request: Request): Promise<Response>Serves this DO’s requests. A WebSocket upgrade to a hibernating route (the default) is accepted natively
here - ctx.acceptWebSocket so the runtime owns the socket and this DO may be evicted while idle -
running open once and serializing the connection into the socket attachment. Everything else (HTTP, and
hibernate: false resident WebSocket routes) delegates to the handler. Override to customize; call
super.fetch to delegate.
request Request
returns Promise<Response>
inject()
Section titled “inject()”inject<T extends FlareService>(token: ServiceToken<T>): Injected<T>Resolves a service declared in this class’s static deps from the per-instance graph.
token ServiceToken<T>
returns Injected<T>
webSocketClose()
Section titled “webSocketClose()”webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): void | Promise<void>Dispatches a terminal close on a hibernated socket.
ws WebSocket
code number
reason string
wasClean boolean
returns void | Promise<void>
webSocketError()
Section titled “webSocketError()”webSocketError(ws: WebSocket, error: unknown): void | Promise<void>Dispatches a transport/protocol error on a hibernated socket; a close still follows.
ws WebSocket
error unknown
returns void | Promise<void>
webSocketMessage()
Section titled “webSocketMessage()”webSocketMessage(ws: WebSocket, message: string | ArrayBuffer): void | Promise<void>Reconstructs the connection from its socket attachment and dispatches an inbound message on a hibernated socket.
ws WebSocket
message string | ArrayBuffer
returns void | Promise<void>
Learn: Overview