import { DocDetail , UpdatableDocDetails } from './DocDetail' ; import { isPresent } from 'polar-shared/src/Preconditions' ; import { Logger } from 'polar-shared/src/logger/Logger' ; import { IDocInfo } from "polar-shared/src/metadata/IDocInfo" ; const log = Logger . create ( ) ; export class DocDetails { public static merge ( docInfo , docDetail ? ) { if ( docDetail !== undefined ) { log . debug ( "Merging docDetail: " , docDetail ) ; const targetDocDetails = docInfo ; const typedKeys = [ 'title' , 'subtitle' , 'description' , 'url' , 'filename' ] ; const sourceDocDetails = docDetail ; typedKeys . forEach ( typedKey => { if ( ! isPresent ( targetDocDetails [ typedKey ] ) && isPresent ( sourceDocDetails [ typedKey ] ) ) { const newValue = sourceDocDetails [ typedKey ] ; log . debug ( `Setting ${ typedKey } to ${ newValue }` ) ; ( < any > targetDocDetails ) [ typedKey ] = newValue ; } } ) ; return targetDocDetails ; } else { log . warn ( "No docDetail to merge" ) ; } return undefined ; } }