import ConditionExpression from './condition' ; import Expression from './expression' ; import MatchExpression from './match' ; import NotExpression from './not' ; export interface ResolvedExpression { resolvedExpression : string ; expressionAttributeNames : { [ key ] : string ; } ; expressionAttributeValues : { [ key ] : { [ key ] : string | number ; } ; } ; } export function resolveExpression ( expressionStack ) { return expressionStack . reduce ( ( acc , expression ) => { switch ( ( expression as any ) . kind ) { case 'condition' : { acc . resolvedExpression += '(' + resolveExpression ( ( expression as any ) . conditionStack ) + ')' ; return acc ; } case 'not' : { acc . resolvedExpression += 'NOT (' + resolveExpression ( ( expression as any ) . notStack ) + ')' ; return acc ; } case 'and' : { acc . resolvedExpression += ' and ' ; return acc ; } case 'or' : { acc . resolvedExpression += ' or ' ; return acc ; } case 'match' : { acc . resolvedExpression += ( expression as any ) . matchValue ; acc . expressionAttributeValues = Object . assign ( { } , acc . expressionAttributeValues , ( expression as any ) . expressionAttributeValues ) ; acc . expressionAttributeNames = Object . assign ( { } , acc . expressionAttributeNames , ( expression as any ) . expressionAttributeNames ) ; return acc ; } } return acc ; } , { resolvedExpression : '' , expressionAttributeValues : { } , expressionAttributeNames : { } , } ) ; }