import type { AnyEntity , EntityData , EntityMetadata , EntityProperty , IHydrator } from '../typings' ; import type { EntityFactory } from '../entity' ; import type { Platform } from '../platforms/Platform' ; import type { MetadataStorage } from '../metadata/MetadataStorage' ; import type { Configuration } from '../utils/Configuration' ; export abstract class Hydrator implements IHydrator { constructor ( protected readonly metadata , protected readonly platform , protected readonly config ) { } inheritDoc hydrate < T extends AnyEntity < T > > ( entity , meta , data , factory , type , newEntity = false , convertCustomTypes = false ) { const props = this . getProperties ( meta , type ) ; for ( const prop of props ) { this . hydrateProperty ( entity , prop , data , factory , newEntity , convertCustomTypes ) ; } } inheritDoc hydrateReference < T extends AnyEntity < T > > ( entity , meta , data , factory , convertCustomTypes ? ) { meta . primaryKeys . forEach ( pk => { this . hydrateProperty < T > ( entity , meta . properties [ pk ] , data , factory , false , convertCustomTypes ) ; } ) ; } protected getProperties < T extends AnyEntity < T > > ( meta , type ) { if ( type === 'reference' ) { return meta . primaryKeys . map ( pk => meta . properties [ pk ] ) ; } if ( type === 'returning' ) { return meta . hydrateProps . filter ( prop => prop . primary || prop . defaultRaw ) ; } return meta . hydrateProps ; } protected hydrateProperty < T extends AnyEntity < T > > ( entity , prop , data , factory , newEntity ? , convertCustomTypes ? ) { entity [ prop . name ] = data [ prop . name ] ; } }