import { Result , ResultMeta } from '../../../result/types' ; import { CurationResult } from '../../types' ; /**
 * The `promoted` and `hidden` keys from the internal curations endpoints
 * currently return a document data structure that our Result component can't
 * correctly parse - we need to attempt to naively transform the data in order
 * to display it in a Result
 *
 * TODO: Ideally someday we can update our internal curations endpoint to return
 * the same Result-ready data structure that the `organic` endpoint uses, and
 * remove this file when that happens
 */ const mergeMetas = ( partialMeta , secondPartialMeta ) : ResultMeta => { return { ... ( partialMeta || { } ) , ... secondPartialMeta , } ; } ; export const convertToResultFormat = ( document ) : Result => { const result = { } as Result ; Object . entries ( document ) . forEach ( ( [ key , value ] ) => { if ( key === '_meta' ) { result [ key ] = value as ResultMeta ; } else { result [ key ] = { raw : value , snippet : null , } ; } } ) ; const convertedMetaObj = convertIdToMeta ( document . id ) ; result . _meta = mergeMetas ( result . _meta , convertedMetaObj ) ; return result ; } ; export const convertIdToMeta = ( id ) : Result [ '_meta' ] => { const splitId = id . split ( '|' ) ; const isMetaEngine = splitId . length > 1 ; return isMetaEngine ? { engine : splitId [ 0 ] , id : splitId [ 1 ] , } : ( { id } as Result [ '_meta' ] ) ; } ;