import { InternalMapping } from "./internalMapping" ; import { PersistenceError } from "../persistenceError" ; hidden export class ResolveContext { resolvedPath : string ; resolvedMapping : InternalMapping ; error : Error ; private _path : string [ ] ; private _resolvePath : string [ ] ; private _depth : number ; constructor ( public path ) { if ( typeof path !== "string" ) { throw new PersistenceError ( "Expected argument 'path' to be a string." ) ; } this . _path = path . split ( "." ) ; this . _resolvePath = new Array ( this . _path . length ) ; this . _depth = 0 ; } get currentProperty ( ) : string { return this . _path [ this . _depth ] ; } get isEop ( ) : boolean { return this . path === undefined ; } get isFirst ( ) : boolean { return this . _depth === 0 ; } setError ( message ) { if ( this . _path . length == 1 ) { this . error = new PersistenceError ( "Invalid path '" + this . path + "': " + message ) ; } else { this . error = new PersistenceError ( "Invalid path '" + this . path + "' at property '" + this . currentProperty + "': " + message ) ; } this . _finished ( ) ; } resolveProperty ( mapping , resolvedProperty ) { this . _resolvePath [ this . _depth ] = resolvedProperty ; this . _depth ++ ; if ( this . _depth === this . _path . length ) { this . resolvedMapping = mapping ; this . resolvedPath = this . _resolvePath . join ( "." ) ; this . _finished ( ) ; return true ; } return false ; } private _finished ( ) { this . _depth = undefined ; this . _path = undefined ; this . _resolvePath = undefined ; } }