Skip to content

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.

new FlareDurableObject(ctx, env)

new FlareDurableObject(ctx: DurableObjectState, env: Env): FlareDurableObject

ctx DurableObjectState

env Env

deps: readonly ServiceToken<FlareService>[]
state: readonly StateToken[]
config<T>(token: ConfigToken<T>): T

Resolves a config token.

token ConfigToken<T>

returns T

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<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(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(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(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

Last updated: