Functions

f
connect(
socketPath: string,
timeoutMs: number
): Promise<net.Socket | null>

Attempts a connection to the given path (POSIX socket or Windows named pipe). Resolves the connected socket on success, null on any failure (peer absent, ECONNREFUSED, ENOENT, timeout). Lets net.createConnection produce the error directly — a pre-emptive existsSync check would not work for Windows named pipes (they live in \\.\pipe\..., not on the regular filesystem).

f
readMessages<T>(
socket: net.Socket,
onLine: (line: T) => void
): void

Reads NDJSON from socket, dispatching each parsed object via onLine. Tolerates packet splits across line boundaries; silently drops malformed lines. Used by both the daemon server (parsing client requests) and the client (parsing server responses).

Usage

import * as mod from "lib/commands/daemon/socket.ts";