(value: unknown)
| 94 | // ── runtime validators (used only by the server for client→server msgs) ───── |
| 95 | |
| 96 | export function isClientControlMessage(value: unknown): value is ClientControlMessage { |
| 97 | if (typeof value !== 'object' || value === null) return false; |
| 98 | const v = value as Record<string, unknown>; |
| 99 | if (v['type'] === 'attach') { |
| 100 | return ( |
| 101 | isNonEmptyString(v['wsId']) && |
| 102 | isPositiveInt(v['cols']) && |
| 103 | isPositiveInt(v['rows']) && |
| 104 | (v['since'] === undefined || isNonNegativeInt(v['since'])) |
| 105 | ); |
| 106 | } |
| 107 | if (v['type'] === 'resize') { |
| 108 | return isPositiveInt(v['cols']) && isPositiveInt(v['rows']); |
| 109 | } |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | function isNonEmptyString(x: unknown): x is string { |
| 114 | return typeof x === 'string' && x.length > 0; |
no test coverage detected