(raw: string)
| 224 | } |
| 225 | |
| 226 | private handleMessage(raw: string): void { |
| 227 | let message: unknown |
| 228 | try { |
| 229 | message = JSON.parse(raw) |
| 230 | } catch { |
| 231 | return |
| 232 | } |
| 233 | |
| 234 | const response = validateRuntimeResponse(message) |
| 235 | if (response.ok) { |
| 236 | const pending = this.pending.get(response.value.id) |
| 237 | if (!pending) return |
| 238 | this.pending.delete(response.value.id) |
| 239 | if (response.value.error) { |
| 240 | pending.reject(new RuntimeClientError(response.value.error.code, response.value.error.message, response.value.error.data)) |
| 241 | } else { |
| 242 | pending.resolve(response.value.result) |
| 243 | } |
| 244 | return |
| 245 | } |
| 246 | |
| 247 | if (isRuntimeNotification(message)) { |
| 248 | if (typeof message.cursor === "string") this.lastCursor = message.cursor |
| 249 | for (const listener of this.listeners) { |
| 250 | listener(message) |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | export class RuntimeLocalClient { |
no test coverage detected