//#region src/server/http-server.types.d.ts /** One request a server received, as the language sees it. */ interface ServerRequest { method: string; /** The path with its query string, exactly as it arrived. */ url: string; headers: Record; body: string; } /** What a handler answers with. Every field has a sensible default. */ interface ServerReply { status?: number; headers?: Record; /** A string is sent as-is; anything else is sent as JSON. */ body?: unknown; } /** Called once per request. Returning nothing sends `204 No Content`. */ type RequestHandler = (request: ServerRequest) => ServerReply | undefined | Promise; /** A server that is listening, and how to stop it. */ interface RunningServer { /** The port it actually bound to. Asking for 0 gets one chosen for you. */ readonly port: number; close(): Promise; } /** * Accepting requests over HTTP. * * Two implementations: `createNodeServer` binds a real socket, and * `createMemoryServer` keeps the handler in memory so a test can deliver a * request without a network. The conformance suite is what says they agree. */ interface HttpServer { listen(args: { port: number; host?: string; handle: RequestHandler; }): Promise; } //#endregion //#region src/server/node-server.d.ts /** A node HttpServer, plus the way to hang up everything it still has open. */ interface NodeHttpServer extends HttpServer { /** * Close every server started here that is still listening. * * A process owns its sockets, so whoever owns the process (the CLI) needs one * call to give them all back on the way out. */ closeAll(): Promise; } /** * The real implementation: a bound socket, on the port the OS gave it. * * Only this file reaches for `node:http`, which is why it sits behind the * `@venn-lang/http/node` subpath. The rest of the package stays platform-neutral and * runs wherever the language runs, the editor's worker included. * * @throws VN7020 if the port is taken, VN7021 if the socket refuses to bind. */ declare function createNodeServer(): NodeHttpServer; //#endregion export { type NodeHttpServer, createNodeServer }; //# sourceMappingURL=node.d.mts.map