(response: RpcMessage.FromServerEncoded | RpcMessage.FromClientEncoded)
| 361 | } |
| 362 | |
| 363 | function encodeJsonRpcMessage(response: RpcMessage.FromServerEncoded | RpcMessage.FromClientEncoded): JsonRpcMessage { |
| 364 | switch (response._tag) { |
| 365 | case "Request": |
| 366 | return { |
| 367 | jsonrpc: "2.0", |
| 368 | method: response.tag, |
| 369 | params: response.payload, |
| 370 | id: response.id && Number(response.id), |
| 371 | headers: response.headers, |
| 372 | traceId: response.traceId, |
| 373 | spanId: response.spanId, |
| 374 | sampled: response.sampled |
| 375 | } |
| 376 | case "Ping": |
| 377 | case "Pong": |
| 378 | case "Interrupt": |
| 379 | case "Ack": |
| 380 | case "Eof": |
| 381 | return { |
| 382 | jsonrpc: "2.0", |
| 383 | method: `@effect/rpc/${response._tag}`, |
| 384 | params: "requestId" in response ? { requestId: response.requestId } : undefined |
| 385 | } |
| 386 | case "Chunk": |
| 387 | return { |
| 388 | jsonrpc: "2.0", |
| 389 | chunk: true, |
| 390 | id: Number(response.requestId), |
| 391 | result: response.values |
| 392 | } |
| 393 | case "Exit": |
| 394 | return { |
| 395 | jsonrpc: "2.0", |
| 396 | id: response.requestId ? Number(response.requestId) : undefined, |
| 397 | result: response.exit._tag === "Success" ? response.exit.value : undefined, |
| 398 | error: response.exit._tag === "Failure" ? |
| 399 | { |
| 400 | _tag: "Cause", |
| 401 | code: response.exit.cause._tag === "Fail" && hasProperty(response.exit.cause.error, "code") |
| 402 | ? Number(response.exit.cause.error.code) |
| 403 | : 0, |
| 404 | message: response.exit.cause._tag === "Fail" && hasProperty(response.exit.cause.error, "message") |
| 405 | ? response.exit.cause.error.message |
| 406 | : JSON.stringify(response.exit.cause), |
| 407 | data: response.exit.cause |
| 408 | } : |
| 409 | undefined |
| 410 | } as any |
| 411 | case "Defect": |
| 412 | return { |
| 413 | jsonrpc: "2.0", |
| 414 | id: jsonRpcInternalError, |
| 415 | error: { |
| 416 | _tag: "Defect", |
| 417 | code: 1, |
| 418 | message: "A defect occurred", |
| 419 | data: response.defect |
| 420 | } |
no test coverage detected