import { MappingBase } from "./mappingBase" ; import { MappingModel } from "./mappingModel" ; import { ReadContext } from "./readContext" ; import { PropertyConverter } from "../config/configuration" ; import { WriteContext } from "./writeContext" ; hidden export class ConverterMapping extends MappingBase { constructor ( public converter ) { super ( MappingModel . MappingFlags . Converter ) ; } read ( context , value ) { if ( value == null ) return null ; var result = this . converter . convertToObjectProperty ( value ) ; if ( result === undefined ) { context . addError ( "Unable to convert '" + value + "' to object property." ) ; } return result ; } write ( context , value ) { if ( value == null ) return null ; var result = this . converter . convertToDocumentField ( value ) ; if ( result === undefined ) { context . addError ( "Unable to convert '" + value + "' to document field." ) ; } return result ; } areEqual ( documentValue1 , documentValue2 ) { if ( documentValue1 === documentValue2 ) return true ; if ( documentValue1 === null || documentValue2 === null ) return false ; if ( documentValue1 !== documentValue1 && documentValue2 !== documentValue2 ) return true ; return this . converter . areEqual ( documentValue1 , documentValue2 ) ; } }