| 123 | } |
| 124 | |
| 125 | export function readTraceAnswer(raw: unknown): TraceAnswer { |
| 126 | const record = isRecord(raw) ? raw : {}; |
| 127 | const path = Array.isArray(record['path']) ? record['path'].map(readNode) : []; |
| 128 | const answer: TraceAnswer = { |
| 129 | mode: text(record['mode']), |
| 130 | reachable: record['reachable'] === true, |
| 131 | path, |
| 132 | }; |
| 133 | const maxDepth = num(record['max_depth']); |
| 134 | if (maxDepth !== undefined) { |
| 135 | answer.maxDepth = maxDepth; |
| 136 | } |
| 137 | const explored = num(record['explored']); |
| 138 | if (explored !== undefined) { |
| 139 | answer.explored = explored; |
| 140 | } |
| 141 | const hops = num(record['hops']); |
| 142 | if (hops !== undefined) { |
| 143 | answer.hops = hops; |
| 144 | } |
| 145 | const error = text(record['error']); |
| 146 | if (error.length > 0) { |
| 147 | answer.error = error; |
| 148 | } |
| 149 | return answer; |
| 150 | } |
| 151 | |
| 152 | export function readFlowSummaries(raw: unknown): FlowSummary[] { |
| 153 | const record = isRecord(raw) ? raw : {}; |