( record: Record<string, unknown>, label: string, keys: readonly string[], )
| 32 | } |
| 33 | |
| 34 | export function assertExactKeys( |
| 35 | record: Record<string, unknown>, |
| 36 | label: string, |
| 37 | keys: readonly string[], |
| 38 | ): void { |
| 39 | const allowed = new Set(keys); |
| 40 | if (Object.keys(record).some((key) => !allowed.has(key))) { |
| 41 | throw invalidProtocolFrame(`Unknown ${label} field`); |
| 42 | } |
| 43 | if ( |
| 44 | Object.keys(record).length !== keys.length || |
| 45 | keys.some((key) => !Object.hasOwn(record, key)) |
| 46 | ) { |
| 47 | throw invalidProtocolFrame(`Invalid ${label} fields`); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | export function requireString(value: unknown, label: string, maxLength: number): string { |
| 52 | if (typeof value !== 'string' || value.length === 0 || value.length > maxLength) { |
no test coverage detected