(output: unknown)
| 59 | * `stdout` keys is not mistaken for another envelope. |
| 60 | */ |
| 61 | export function extractTabularData(output: unknown): Record<string, unknown>[] | null { |
| 62 | if (!output || typeof output !== 'object') return null |
| 63 | |
| 64 | if (Array.isArray(output)) { |
| 65 | if (output.length > 0 && typeof output[0] === 'object' && output[0] !== null) { |
| 66 | return output as Record<string, unknown>[] |
| 67 | } |
| 68 | return null |
| 69 | } |
| 70 | |
| 71 | const obj = output as Record<string, unknown> |
| 72 | |
| 73 | // user_table query_rows shape: { data: { rows: [{ data: {...} }], totalCount } } |
| 74 | if (obj.data && typeof obj.data === 'object' && !Array.isArray(obj.data)) { |
| 75 | const data = obj.data as Record<string, unknown> |
| 76 | if (Array.isArray(data.rows) && data.rows.length > 0) { |
| 77 | const rows = data.rows as Record<string, unknown>[] |
| 78 | if (typeof rows[0].data === 'object' && rows[0].data !== null) { |
| 79 | return rows.map((r) => r.data as Record<string, unknown>) |
| 80 | } |
| 81 | return rows |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | return null |
| 86 | } |
| 87 | |
| 88 | export function escapeCsvValue(value: unknown): string { |
| 89 | if (value === null || value === undefined) return '' |
no outgoing calls
no test coverage detected