Skip to main content

Module websocket

Module websocket 

Source
Expand description

v0.104 (real-time track slice 3b): shared analysis of a from websocket on open handler for the Workers wire path.

On Workers the upgrade is authenticated at the edge, then forwarded to the Durable Object that hosts the connection — the agent the on open transfers it to. For that routing to be static, the handler must transfer the connection to exactly one agent, by a key derivable from the request (D2). This module finds that single transfer; both the checker (to diagnose a bad shape) and the emitter (to route the upgrade) use it.

Lives in bynk-check (moved here in the compiler-pipeline-review’s Wave 5, batch 5.1) rather than bynk-emit: it depends only on bynk-syntax’s AST and is conceptually checker-side analysis, misfiled under the emitter.

Structs§

WsOpenTarget
The single connection-transfer target a from websocket on open resolves to: the agent that will host the connection, and the key expression addressing the instance (Room(roomId) → agent Room, key roomId).

Enums§

WsOpenKey
#2959: how the key of the single connection transfer addresses its Durable Object. On Workers the edge (compose.ts) resolves the hosting instance before the on open body runs, so the key has to be something it can evaluate there on its own: a route parameter (validated from the upgrade URL), a const of the context (a pure static initialiser, handlers.Name()) or of a commons it uses (imported into compose.ts, #2967), or a literal. Anything else — a let-bound local, a field access, a call — is WsOpenKey::Other and rejected on Workers (bynk.ws.open_transfer_key).
WsOpenShape
The shape of an on open body’s connection handling (D2).

Constants§

CONNECTION_BINDING
The synthetic name of the held connection an on open handler receives.

Functions§

analyse_open_shape
Analyse a from websocket on open body: find the top-level agent transfers of the connection binding (a let _ <- Agent(key).m(…, connection) statement). A transfer nested in a conditional is deliberately not counted — the host DO must be statically resolvable.
classify_open_key
Classify key, the key of open’s connection transfer. is_const answers whether a name is a constant visible in the context (crate::consts::visible_consts). A parameter shadows a constant of the same name, and a name any top-level let of the body binds is a local, not the constant (or parameter) it may shadow; so is one a par block binds, since its bindings land in the enclosing scope.