import { type PortWebSocketClass, type WebSocketClassOptions, type WebSocketConnection } from "../ws/client.js"; import { type FetchHandler, type HandlerEndpointOptions } from "./handler-endpoint.js"; export interface ServeHttpInWorkerOptions extends Omit { /** Where the page's messages arrive. Default `globalThis` (the worker's scope). */ scope?: Pick; /** Options of the `WebSocket` class (`service.WebSocket`). */ webSocket?: WebSocketClassOptions; } /** What a worker serving HTTP can do besides serving. */ export interface WorkerHttpService { /** * Fetches through the ServiceWorker's router: a url under its scope reaches * the handler it routes to (another worker, a page), any other the network. * Needs no `fetch` event, so it works whether or not this worker is * controlled; a call that is in flight when the ServiceWorker dies fails * with `LinkLostError` rather than hanging, and the next waits for a link. */ fetch(input: RequestInfo | URL, init?: RequestInit): Promise; /** Opens the transport of a socket to the handler `url` routes to. */ connectWebSocket(url: string | URL, protocols?: string[]): Promise; /** A WHATWG `WebSocket` class over `connectWebSocket`. */ readonly WebSocket: PortWebSocketClass; /** Whether the worker has a live link. */ readonly linked: boolean; /** Stops serving; requests in flight fail. */ close(): Promise; } /** * Serves `handler` from a Dedicated Worker, on the links the page attaches * with `adapter.attachWorker(worker)`: * * ```ts * // worker.ts * const service = serveHttpInWorker(async (request) => new Response("hi")); * ``` * * The worker holds an owner lock while it lives, so the ServiceWorker notices * at once when it is terminated. It watches the ServiceWorker's router lock, * and asks its page to attach it again when its links died and a call waits. * While calls through the router are in flight it asks its page every 20 s to * keep the ServiceWorker awake — only a message to the ServiceWorker object * counts as an event, and a worker cannot post one. */ export declare function serveHttpInWorker(handler: FetchHandler, options?: ServeHttpInWorkerOptions): WorkerHttpService; //# sourceMappingURL=worker-service.d.ts.map