import { ClassMapping } from "./classMapping" ; import { EntityMapping } from "./entityMapping" ; import { Constructor } from "../index" ; import { MappingModel } from "./mappingModel" ; import { PersistenceError } from "../persistenceError" ; hidden export class MappingRegistry { private _mappings : Map < Function , ClassMapping > = new Map ( ) ; addMappings ( mappings ) { mappings . forEach ( x => this . addMapping ( x ) ) ; } addMapping ( mapping ) { if ( ! mapping . classConstructor ) { throw new PersistenceError ( "Class mapping is missing classConstructor." ) ; } if ( this . _mappings . has ( mapping . classConstructor ) ) { throw new PersistenceError ( "Mapping '" + mapping . classConstructor . name + "' has already been registered." ) ; } this . _mappings . set ( mapping . classConstructor , mapping ) ; } getEntityMappings ( ) { var entities = [ ] ; this . _mappings . forEach ( ( mapping ) => { if ( ( mapping . flags & MappingModel . MappingFlags . Entity ) != 0 ) { entities . push ( < EntityMapping > mapping ) ; } } ) ; return entities ; } getMappingForObject ( obj ) { return this . getMappingForConstructor ( obj . constructor ) ; } getMappingForConstructor ( ctr ) { if ( ctr ) { return this . _mappings . get ( < any > ctr ) ; } } }