import { MappingModel } from "./mappingModel" ; import { Reference } from "../reference" ; import { InternalSession } from "../session" ; import { ResultCallback } from "../core/callback" ; import { ResolveContext } from "./resolveContext" ; import { ReadContext } from "./readContext" ; import { Observer } from "../observer" ; import { InternalMapping } from "./internalMapping" ; import { WriteContext } from "./writeContext" ; import { PersistenceError } from "../persistenceError" ; var nextMappingId = 1 ; hidden export abstract class MappingBase implements InternalMapping { id : number ; private _resolveCache : Map < string , ResolveContext > ; constructor ( public flags ) { this . id = nextMappingId ++ ; } abstract read ( context , value ) ; abstract write ( context , value ) ; hasFlags ( flags ) { return this . flags != undefined && ( ( this . flags & flags ) === flags ) ; } watch ( value , observer , visited ) { } walk ( session , value , flags , entities , embedded , references ) { } areEqual ( documentValue1 , documentValue2 ) { if ( documentValue1 === documentValue2 ) return true ; if ( documentValue1 == null || documentValue2 == null ) return false ; if ( documentValue1 !== documentValue1 && documentValue2 !== documentValue2 ) return true ; return false ; } fetch ( session , parentEntity , value , path , depth , callback ) { if ( depth == path . length ) { process . nextTick ( ( ) => callback ( null , value ) ) ; return ; } callback ( new PersistenceError ( "Undefined property '" + path [ depth ] + "' in path '" + path . join ( "." ) + "'." ) ) ; } fetchInverse ( session , parentEntity , propertyName , path , depth , callback ) { callback ( new PersistenceError ( "Mapping does not support inverse relationships." ) ) ; } resolve ( pathOrContext ) { var context , path ; if ( typeof pathOrContext === "string" ) { path = pathOrContext ; if ( ! this . _resolveCache ) { this . _resolveCache = new Map ( ) ; } else { var context = this . _resolveCache . get ( path ) ; if ( context ) { return context ; } } context = new ResolveContext ( path ) ; } else { context = pathOrContext ; } this . resolveCore ( context ) ; if ( path ) { this . _resolveCache . set ( path , context ) ; } return context ; } protected resolveCore ( context ) { if ( ! context . isEop ) { context . setError ( "Undefined property." ) ; } } }