import { Mapping } from './Mapping' ; import { EntityInterface , ProxyInterface } from './EntityInterface' ; export class IdentityMap { type { WeakMap < Function , Object > } private map : WeakMap < Function , Object > = new WeakMap ; /**
     * Reset the map.
     */ public reset ( ) { this . map = new WeakMap ; } param { Function | EntityInterface } entity returns { Object } public getMapForEntity ( entity ) { const entityReference = ( typeof entity === 'function' ? entity : entity . constructor ) as Function ; const map = this . map . get ( entityReference ) ; if ( ! map ) { this . map . set ( entityReference , { } ) ; } return this . map . get ( entityReference ) ; } param { EntityInterface } entity param { ProxyInterface } proxy returns { IdentityMap } public register ( entity , proxy ) { this . getMapForEntity ( entity ) [ entity [ Mapping . forEntity ( entity ) . getPrimaryKey ( ) ] ] = proxy ; return this ; } param { EntityInterface | Function } entity param { * } primaryKey returns { EntityInterface | null } public fetch ( entity , primaryKey ) { return this . getMapForEntity ( entity ) [ primaryKey ] || null ; } }