(msg: Record<string, unknown>)
| 134 | } |
| 135 | |
| 136 | private routeMessage(msg: Record<string, unknown>): void { |
| 137 | if (msg.type === "response" && typeof msg.id === "string") { |
| 138 | const pending = this.pendingRequests.get(msg.id); |
| 139 | if (pending) { |
| 140 | this.pendingRequests.delete(msg.id); |
| 141 | if (msg.success === false) { |
| 142 | pending.reject(new Error((msg.error as string) ?? "RPC error")); |
| 143 | } else { |
| 144 | pending.resolve((msg.data as Record<string, unknown>) ?? {}); |
| 145 | } |
| 146 | return; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | for (const listener of this.listeners) { |
| 151 | listener(msg); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | send(command: Record<string, unknown>): void { |
| 156 | if (!this.proc?.stdin || this.proc.stdin.destroyed) return; |
no test coverage detected