(raw: string)
| 170 | }; |
| 171 | |
| 172 | const parsePointer = (raw: string): DaemonPointer | null => { |
| 173 | let parsed: unknown; |
| 174 | try { |
| 175 | parsed = JSON.parse(raw); |
| 176 | } catch { |
| 177 | return null; |
| 178 | } |
| 179 | |
| 180 | if ( |
| 181 | typeof parsed !== "object" || |
| 182 | parsed === null || |
| 183 | !("version" in parsed) || |
| 184 | (parsed as { version?: unknown }).version !== 1 |
| 185 | ) { |
| 186 | return null; |
| 187 | } |
| 188 | |
| 189 | const r = parsed as Record<string, unknown>; |
| 190 | if ( |
| 191 | typeof r.hostname !== "string" || |
| 192 | typeof r.port !== "number" || |
| 193 | typeof r.pid !== "number" || |
| 194 | typeof r.startedAt !== "string" || |
| 195 | typeof r.scopeId !== "string" || |
| 196 | !(typeof r.scopeDir === "string" || r.scopeDir === null) || |
| 197 | typeof r.token !== "string" |
| 198 | ) { |
| 199 | return null; |
| 200 | } |
| 201 | |
| 202 | return { |
| 203 | version: 1, |
| 204 | hostname: canonicalDaemonHost(r.hostname), |
| 205 | port: r.port, |
| 206 | pid: r.pid, |
| 207 | startedAt: r.startedAt, |
| 208 | scopeId: r.scopeId, |
| 209 | scopeDir: r.scopeDir, |
| 210 | token: r.token, |
| 211 | }; |
| 212 | }; |
| 213 | |
| 214 | export const readDaemonRecord = (input: { |
| 215 | hostname: string; |
no test coverage detected