(raw: unknown)
| 50 | |
| 51 | /** Parse an incoming WebSocket payload into a typed frame, or null if invalid. */ |
| 52 | export function parseFrame<T extends { type: string }>(raw: unknown): T | null { |
| 53 | if (typeof raw !== 'string') return null |
| 54 | try { |
| 55 | const obj = JSON.parse(raw) |
| 56 | if (obj && typeof obj === 'object' && typeof obj.type === 'string') { |
| 57 | return obj as T |
| 58 | } |
| 59 | } catch { |
| 60 | /* malformed JSON — ignore */ |
| 61 | } |
| 62 | return null |
| 63 | } |
no outgoing calls
no test coverage detected