(result: QueryResult)
| 333 | |
| 334 | // Parses the hits array from an Elasticsearch _search QueryResult's "hits" column. |
| 335 | const parseESHitsArray = (result: QueryResult): unknown[] | undefined => { |
| 336 | const hitsColIdx = result.columnNames.indexOf("hits"); |
| 337 | if (hitsColIdx === -1 || result.rows.length === 0) return undefined; |
| 338 | |
| 339 | const hitsCell = result.rows[0]?.values[hitsColIdx]; |
| 340 | if (hitsCell?.kind.case !== "stringValue") return undefined; |
| 341 | |
| 342 | let hitsObj: Record<string, unknown>; |
| 343 | try { |
| 344 | hitsObj = JSON.parse(hitsCell.kind.value); |
| 345 | } catch { |
| 346 | return undefined; |
| 347 | } |
| 348 | |
| 349 | const hitsArray = hitsObj?.hits; |
| 350 | if (!Array.isArray(hitsArray) || hitsArray.length === 0) return undefined; |
| 351 | return hitsArray; |
| 352 | }; |
| 353 | |
| 354 | // Discovers columns from ES hits: _id, _score, then sorted _source field keys. |
| 355 | const discoverESColumns = (hitsArray: unknown[]) => { |
no outgoing calls
no test coverage detected