import { type MountSpec, type MountTable } from "./mount-table.js"; /** What the registry keeps per service key. */ export interface RegisteredClient { clientId: string; /** Where the service is mounted. Absent means `/~/`, as before mounts. */ path?: string; } /** * One stored registry entry, whatever shape it is on disk. * * BEFORE MOUNTS THE VALUE WAS A BARE CLIENT ID. A browser that ran the earlier * worker still holds that shape, and reading it as an object would drop the id * and quietly unregister every service the visitor had. */ export declare function readStoredEntry(value: unknown): RegisteredClient | undefined; /** * Which service, if any, should answer `url`. * * `undefined` means NOT THE RELAY'S, and the caller must not call * `respondWith`: the request then goes to the network, which is how a host * keeps serving its own files from its own origin. Answering 404 here instead * would make a root mount fatal. */ export declare function resolveServiceKey(url: URL, table: MountTable, selfOrigin: string): string | undefined; /** * Waits for the mount table to be restored from the registry before routing * `url` — but a restore failure must never wedge every fetch. `restored` * rejecting (blocked storage, quota, private-mode edge cases) would otherwise * propagate straight to `respondWith` on every request, including ones that * should reach the network, which breaks the one rule this file exists to * uphold. So: log the failure and route with whatever the in-memory table * already holds — possibly empty, never fatal. */ export declare function resolveAfterRestore(restored: Promise, url: URL, table: MountTable, selfOrigin: string): Promise; /** * What REGISTER does to the mount table: set it when `path` is given, or * remove any earlier mount when it is not. A path-less re-registration * reverts a service to `/~/` addressing, and a stale prefix left behind * would keep routing requests to a mount that no longer exists. * * A REGISTRATION ONLY TOUCHES WHAT A REGISTRATION MADE. `hostKeys` names the * mounts the host declared itself, in `options.mounts`. Those are the host's * build-time decision and a page may not undo it: the documented static flow * -- host declares `{ key: "app", path: "/" }`, page calls `initHttpService(h, * { key: "app", port })` with no path -- would otherwise have its very first * registration delete the host's own mount and leave the origin unmounted. A * path-ful REGISTER naming a host key is ignored for the same reason (it would * replace a `match` predicate with a prefix of the page's choosing). */ export declare function applyRegisteredMount(table: MountTable, key: string, path: string | undefined, hostKeys?: ReadonlySet): void; /** * What UNREGISTER does to the mount table: drop the mount a registration * made. A host-declared mount stays, for the reason `applyRegisteredMount` * gives -- a page tearing down its service must not take the host's table * with it. */ export declare function removeRegisteredMount(table: MountTable, key: string, hostKeys?: ReadonlySet): void; export interface RelayServiceWorkerOptions { /** A fixed table, for a host that knows its services at build time. */ mounts?: Array<{ key: string; } & MountSpec>; /** Paths the relay never claims. Checked before the table. */ exclude?: (url: URL) => boolean; /** * Refuse a registration from the wrong client. Default: everyone may. * * `path` is where the registrant asks to be mounted (`undefined` for the * `/~/` addressing), so a host can vet where a key lands, not only who * takes it: on an origin whose name is not a secret, a page could otherwise * mount an allowed key at `/index.html` and outrank `/` on longest-prefix. * Also consulted for `UNREGISTER`, with the path the key is mounted at. */ canRegister?: (client: Client, key: string, path?: string) => boolean | Promise; /** Per-stream inactivity timeout of the links to services, in ms. Default none. */ streamTimeout?: number; /** Default `"last-wins"`, the behaviour before this option existed. */ takeover?: "first-wins" | "last-wins"; /** Stamp headers on responses the relay makes. Not applied to network fetches. */ decorateResponse?: (response: Response, request: Request) => Response; } /** * May `candidateId` take the key? * * `last-wins` is what the relay has always done and stays the default. With * `first-wins`, a LIVE holder keeps its key: on an origin whose name is * guessable, a second page proves nothing by existing. A holder that reloaded * is no longer live, so a host's own re-registration is never blocked. */ export declare function mayRegister(args: { current?: RegisteredClient; candidateId: string; isCurrentLive: boolean; takeover: "first-wins" | "last-wins"; }): boolean; /** * Boots the relay ServiceWorker: routes fetches shaped `/~/…` to * the client that registered `key`, and exposes REGISTER/UNREGISTER/CONNECT * channel calls used by the page-side relay client. */ export declare function startRelayServiceWorker(self: ServiceWorkerGlobalScope, options?: RelayServiceWorkerOptions): () => void; //# sourceMappingURL=index-sw.d.ts.map