module import { Attribute } from '../../../mapper/type/attribute.type' ; import { ModelConstructor } from '../../../model/model-constructor' ; import { PropertyMetadata , TypeInfo } from '../../metadata/property-metadata.model' ; import { getMetadataType } from '../../util' ; import { KEY_PROPERTY } from './key-property.const' ; hidden export function initOrUpdateProperty ( propertyMetadata = { } , target , propertyKey ) { let property ; let properties = Reflect . getMetadata ( KEY_PROPERTY , target . constructor ) || [ ] ; const existingProperty = properties . find ( ( p ) => p . name === propertyKey ) ; if ( existingProperty ) { property = { ... existingProperty , ... propertyMetadata } ; properties = properties . filter ( ( p ) => p !== existingProperty ) ; } else { property = createNewProperty ( propertyMetadata , target , propertyKey ) ; } Reflect . defineMetadata ( KEY_PROPERTY , [ ... properties , property ] , target . constructor ) ; } hidden function createNewProperty ( propertyOptions = { } , target , propertyKey ) { const propertyType = getMetadataType ( target , propertyKey ) ; if ( propertyType === undefined ) { throw new Error ( 'make sure you have enabled the typescript compiler options which enable us to work with decorators (see doc)' ) ; } const typeInfo = { type : propertyType } ; propertyOptions = { name : propertyKey , nameDb : propertyKey , typeInfo , ... propertyOptions , } ; return < PropertyMetadata < any > > propertyOptions ; }