MCPcopy Create free account
hub / github.com/bytebase/bytebase / parseESHitsArray

Function parseESHitsArray

frontend/src/utils/sqlResult.ts:335–352  ·  view source on GitHub ↗
(result: QueryResult)

Source from the content-addressed store, hash-verified

333
334// Parses the hits array from an Elasticsearch _search QueryResult's "hits" column.
335const 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.
355const discoverESColumns = (hitsArray: unknown[]) => {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected