|
| 1 | +/** |
| 2 | + * Compile-time regression: each entry of the HELLO reply's modules field is a |
| 3 | + * structured entry (name, ver), not a plain string. The declared reply type |
| 4 | + * used to label it Array<BlobStringReply>, so consumers had no type-safe |
| 5 | + * access to the module fields. path and args exist only on Redis 7.0+ and are |
| 6 | + * intentionally left out of the declared shape, mirroring MODULE LIST. |
| 7 | + * |
| 8 | + * Lives outside `lib/` so it is not picked up by the production build / |
| 9 | + * typedoc. Checked with `npm run test:types -w @redis/client`. |
| 10 | + */ |
| 11 | +import { createClient } from '../index'; |
| 12 | + |
| 13 | +type Client = ReturnType<typeof createClient>; |
| 14 | +type HelloReply = Awaited<ReturnType<Client['hello']>>; |
| 15 | +type ModuleEntry = HelloReply['modules'][number]; |
| 16 | + |
| 17 | +export function helloModulesAreStructured(entry: ModuleEntry): void { |
| 18 | + // Mapped (RESP3-style) entries must expose the server's fields. |
| 19 | + if (!Array.isArray(entry)) { |
| 20 | + const name: string = entry.name; |
| 21 | + const ver: number = entry.ver; |
| 22 | + |
| 23 | + // A module version is a number, not a string. |
| 24 | + // @ts-expect-error module versions are numbers |
| 25 | + const notAString: string = entry.ver; |
| 26 | + |
| 27 | + if (process.env.NODE_ENV !== 'production') { |
| 28 | + console.log(name, ver, notAString); |
| 29 | + } |
| 30 | + |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | + // Flat (RESP2-style) entries stay arrays. |
| 35 | + if (entry.length < 0) { |
| 36 | + console.log(entry); |
| 37 | + } |
| 38 | +} |
0 commit comments