// JSON envelopes for Redis replies. Integer replies carry decimal digits until the wire writes them; // converting them to a Number here would round values outside JavaScript's safe integer range. import { RedisInteger } from './engine.ts'; /** Serialize a JSON reply envelope, including nested exact Redis integer numeric tokens. */ export function jsonReply(value: unknown): string { if (value instanceof RedisInteger) return value.integer; if (Array.isArray(value)) return `[${value.map((item) => jsonReply(item)).join(',')}]`; if (value !== null && typeof value === 'object') { return `{${Object.entries(value).filter(([, item]) => item !== undefined).map(([key, item]) => `${JSON.stringify(key)}:${jsonReply(item)}`).join(',')}}`; } return JSON.stringify(value) ?? 'null'; }