module import { Metadata } from '../../../decorator/metadata/metadata' ; import { NESTED_ATTR_PATH_CAPTURED_REGEX , NESTED_ATTR_PATH_REGEX } from './attribute-names.const' ; hidden export function resolveAttributeNames ( attributePath , metadata ? ) { let placeholder ; const attributeNames = { } ; if ( new RegExp ( NESTED_ATTR_PATH_REGEX ) . test ( attributePath ) ) { const regex = new RegExp ( NESTED_ATTR_PATH_CAPTURED_REGEX ) ; const currentPath = [ ] ; let regExpResult ; const namePlaceholders = [ ] ; while ( ( regExpResult = regex . exec ( attributePath ) ) !== null ) { const pathPart = regExpResult [ 1 ] ; currentPath . push ( regExpResult [ 1 ] ) ; const collectionIndex = regExpResult [ 2 ] ; const propertyMetadata = metadata && metadata . forProperty ( currentPath . join ( '.' ) ) ; attributeNames [ `#${ pathPart }` ] = propertyMetadata ? propertyMetadata . nameDb : pathPart ; if ( collectionIndex !== undefined ) { namePlaceholders . push ( `#${ pathPart }[${ collectionIndex }]` ) ; } else { namePlaceholders . push ( `#${ pathPart }` ) ; } } placeholder = namePlaceholders . join ( '.' ) ; } else { const propertyMetadata = metadata && metadata . forProperty ( attributePath ) ; attributeNames [ `#${ attributePath }` ] = propertyMetadata ? propertyMetadata . nameDb : attributePath ; placeholder = `#${ attributePath }` ; } return { placeholder , attributeNames , } ; }