class ReplyInboxObjectCore
Since 0.2.0

Delivers RPC replies to the caller waiting on them.

This class holds no state, for the same reason RealtimeBackplaneObjectCore holds none: sockets are accepted with state.acceptWebSocket, the hibernation API, so the runtime may evict the object and re-run this constructor before the reply arrives. A membership Set in a field would empty itself on the first hibernation while every test that never hibernates kept passing. state.getWebSockets() survives hibernation and is the only membership consulted here.

The reply body is forwarded verbatim and never parsed, so this object cannot corrupt an envelope and a future widening of the reply shape needs no redeploy of the class the application owns.

The application owns the class; this owns the behavior:

Examples

Example 1

import { DurableObject } from 'cloudflare:workers';
import { ReplyInboxObjectCore } from '@setu-ts/cloudflare-plugin';

export class ReplyInboxObject extends DurableObject {
  #core = new ReplyInboxObjectCore(this.ctx);

  override fetch(request: Request): Promise<Response> {
    return this.#core.fetch(request);
  }
  webSocketClose(ws: WebSocket, code: number, reason: string): void {
    this.#core.webSocketClose(ws, code, reason);
  }
}

Constructors

ReplyInboxObjectCore()

Builds the core the application's Durable Object class delegates to.

Parameters

The Durable Object's ctx

Optional seams; the defaults are the deployment path

Methods

Since 0.2.0
fetch(request: Request): Promise<Response>

Serves both halves of the inbox.

A WebSocket upgrade opens the caller's end; a POST delivers a reply from a responder. Anything else is refused with the method or upgrade the caller should have used.

Since 0.2.0
webSocketClose(
code: number,
reason: string
): void

Handles the caller disconnecting.

Nothing is tracked, so nothing needs removing — the runtime drops the socket from getWebSockets() itself. The handler exists so the application's class can forward it without a branch.

Since 0.2.0
webSocketError(socket: IDurableObjectWebSocket): void

Handles a socket error.

Usage

import { ReplyInboxObjectCore } from "cloudflare-plugin/src/index.ts";