UNPKG

ttsc

Version:

General-purpose TypeScript-Go compiler, runtime, plugin host, and LSP host.

66 lines (65 loc) 2.82 kB
/** * The operation a request expects a reply for. The host answers a transform * request (`{"file":...}`) with `{"typescript":...,"found":...}` and an update * request (`{"update":...,"content":...}`) with `{"updated":...}`. The client * knows which it sent, so it validates the reply's shape against the operation * before handing it back — a well-formed JSON object of the wrong operation * shape is a protocol error, not a valid negative result. */ export type ResidentReplyKind = "transform" | "update"; /** Options for spawning the resident transform host. */ export interface ResidentTransformProcessOptions { args: readonly string[]; binary: string; cwd?: string; env?: NodeJS.ProcessEnv; } /** Per-request lifecycle controls for a resident transform host. */ export interface ResidentTransformRequestOptions { /** Abort this request. An in-flight abort retires the FIFO host. */ signal?: AbortSignal; } /** * Async client for the long-lived `utility-host serve` process. * * The host transforms the whole project once at startup, caches every file's * transformed TypeScript, then answers newline-delimited requests. This class * speaks that protocol: each {@link request} writes one JSON line and the host * replies with one line, matched FIFO. A transform request (`{"file":...}`) is * answered with `{"typescript":...,"found":...}`, and an update request * (`{"update":...,"content":...}`) with `{"updated":...}`. * * One resident process answers every request from one service instead of * spawning a fresh `transform` subprocess per call, so a single process pays * the project compile once (samchon/ttsc#255). */ export declare class ResidentTransformProcess { private readonly child; private readonly reader; private readonly pending; private stderr; private failure; constructor(options: ResidentTransformProcessOptions); /** * Send one request to the host and resolve with its validated JSON reply. The * host answers in FIFO order; `kind` tells the client which reply shape the * payload asks for, so the reply is validated as a well-formed `kind` reply * before it resolves. Rejects when the reply is not a valid `kind` reply, * when the host has already failed or exited, or if writing the request * fails. */ request(payload: Record<string, unknown>, kind: ResidentReplyKind, options?: ResidentTransformRequestOptions): Promise<Record<string, unknown>>; /** * Terminate the resident process and reject any in-flight requests. Safe to * call more than once. */ dispose(): void; private onLine; private onReaderClose; private fail; private rejectAll; private settlePending; private cancel; private terminate; private exitError; }