module import { Metadata } from '../../../decorator/metadata/metadata' ; import { Attribute } from '../../../mapper/type/attribute.type' ; import { uniqueAttributeValueName } from '../functions/unique-attribute-value-name.function' ; import { ConditionExpressionDefinitionFunction } from '../type/condition-expression-definition-function' ; import { Expression } from '../type/expression.type' ; hidden export function mergeConditions ( operator , conditionDefinitionFns ) { return ( expressionAttributeValues , metadata ) : Expression => { const mergedCondition = { statement : '' , attributeNames : { } , attributeValues : { } , } ; const statements = [ ] ; conditionDefinitionFns . forEach ( ( conditionDefinitionFn ) => { const condition = conditionDefinitionFn ( expressionAttributeValues , metadata ) ; mergedCondition . attributeNames = { ... mergedCondition . attributeNames , ... condition . attributeNames } ; const attributeValues = { } ; Object . keys ( condition . attributeValues ) . forEach ( ( key ) => { const unique = uniqueAttributeValueName ( key . replace ( ':' , '' ) , Object . keys ( mergedCondition . attributeValues ) ) ; if ( key !== unique ) { condition . statement = condition . statement . replace ( key , unique ) ; } attributeValues [ unique ] = condition . attributeValues [ key ] ; } ) ; mergedCondition . attributeValues = { ... mergedCondition . attributeValues , ... attributeValues } ; statements . push ( condition . statement ) ; } ) ; mergedCondition . statement = statements . length === 1 ? statements [ 0 ] : `(${ statements . join ( ' ' + operator + ' ' ) })` ; return mergedCondition ; } ; }