(raw: string)
| 132 | }); |
| 133 | |
| 134 | const parseRecord = (raw: string): DaemonRecord | null => { |
| 135 | let parsed: unknown; |
| 136 | try { |
| 137 | parsed = JSON.parse(raw); |
| 138 | } catch { |
| 139 | return null; |
| 140 | } |
| 141 | |
| 142 | if ( |
| 143 | typeof parsed !== "object" || |
| 144 | parsed === null || |
| 145 | !("version" in parsed) || |
| 146 | (parsed as { version?: unknown }).version !== 1 |
| 147 | ) { |
| 148 | return null; |
| 149 | } |
| 150 | |
| 151 | const r = parsed as Record<string, unknown>; |
| 152 | if ( |
| 153 | typeof r.hostname !== "string" || |
| 154 | typeof r.port !== "number" || |
| 155 | typeof r.pid !== "number" || |
| 156 | typeof r.startedAt !== "string" || |
| 157 | !(typeof r.scopeDir === "string" || r.scopeDir === null) |
| 158 | ) { |
| 159 | return null; |
| 160 | } |
| 161 | |
| 162 | return { |
| 163 | version: 1, |
| 164 | hostname: canonicalDaemonHost(r.hostname), |
| 165 | port: r.port, |
| 166 | pid: r.pid, |
| 167 | startedAt: r.startedAt, |
| 168 | scopeDir: r.scopeDir, |
| 169 | }; |
| 170 | }; |
| 171 | |
| 172 | const parsePointer = (raw: string): DaemonPointer | null => { |
| 173 | let parsed: unknown; |
no test coverage detected