1- import { AttributeMap , AttributeValue } from 'aws-sdk/clients/dynamodb'
21import { curryRight , forEach , isPlainObject } from 'lodash'
32import { Metadata } from '../../decorator/metadata/metadata'
43import { PropertyMetadata } from '../../decorator/metadata/property-metadata.model'
54import { Mapper } from '../../mapper/mapper'
5+ import { Attribute , Attributes } from '../../mapper/type/attribute.type'
66import { Util } from '../../mapper/util'
77import { resolveAttributeNames } from './functions/attribute-names.function'
88import { isFunctionOperator } from './functions/is-function-operator.function'
@@ -151,17 +151,15 @@ export class ConditionExpressionBuilder {
151151 existingValueNames : string [ ] | undefined ,
152152 propertyMetadata : PropertyMetadata < any > | undefined
153153 ) : Expression {
154- const attributeValues : AttributeMap = ( < any [ ] > values [ 0 ] )
155- . map ( value => Mapper . toDbOne ( value , propertyMetadata ) )
156- . reduce (
157- ( result , mappedValue : AttributeValue | null , index : number ) => {
158- if ( mappedValue !== null ) {
159- result [ `${ valuePlaceholder } _${ index } ` ] = mappedValue
160- }
161- return result
162- } ,
163- < AttributeMap > { }
164- )
154+ const attributeValues : Attributes = ( < any [ ] > values [ 0 ] ) . map ( value => Mapper . toDbOne ( value , propertyMetadata ) ) . reduce (
155+ ( result , mappedValue : Attribute | null , index : number ) => {
156+ if ( mappedValue !== null ) {
157+ result [ `${ valuePlaceholder } _${ index } ` ] = mappedValue
158+ }
159+ return result
160+ } ,
161+ < Attributes > { }
162+ )
165163
166164 const inStatement = ( < any [ ] > values [ 0 ] ) . map ( ( value : any , index : number ) => `${ valuePlaceholder } _${ index } ` ) . join ( ', ' )
167165
@@ -181,7 +179,7 @@ export class ConditionExpressionBuilder {
181179 existingValueNames : string [ ] | undefined ,
182180 propertyMetadata : PropertyMetadata < any > | undefined
183181 ) : Expression {
184- const attributeValues : AttributeMap = { }
182+ const attributes : Attributes = { }
185183 const mappedValue1 = Mapper . toDbOne ( values [ 0 ] , propertyMetadata )
186184 const mappedValue2 = Mapper . toDbOne ( values [ 1 ] , propertyMetadata )
187185
@@ -192,13 +190,13 @@ export class ConditionExpressionBuilder {
192190 const value2Placeholder = uniqAttributeValueName ( attributePath , [ valuePlaceholder ] . concat ( existingValueNames || [ ] ) )
193191
194192 const statement = `${ namePlaceholder } BETWEEN ${ valuePlaceholder } AND ${ value2Placeholder } `
195- attributeValues [ valuePlaceholder ] = mappedValue1
196- attributeValues [ value2Placeholder ] = mappedValue2
193+ attributes [ valuePlaceholder ] = mappedValue1
194+ attributes [ value2Placeholder ] = mappedValue2
197195
198196 return {
199197 statement,
200198 attributeNames,
201- attributeValues,
199+ attributeValues : attributes ,
202200 }
203201 }
204202
@@ -225,28 +223,28 @@ export class ConditionExpressionBuilder {
225223 statement = [ namePlaceholder , operator , valuePlaceholder ] . join ( ' ' )
226224 }
227225
228- const attributeValues : AttributeMap = { }
226+ const attributes : Attributes = { }
229227 if ( hasValue ) {
230- let value : AttributeValue | null
228+ let attribute : Attribute | null
231229 switch ( operator ) {
232230 case 'contains' :
233231 // TODO think about validation
234232 // ConditionExpressionBuilder.validateValueForContains(values[0], propertyMetadata)
235- value = Mapper . toDbOne ( values [ 0 ] , propertyMetadata )
233+ attribute = Mapper . toDbOne ( values [ 0 ] , propertyMetadata )
236234 break
237235 default :
238- value = Mapper . toDbOne ( values [ 0 ] , propertyMetadata )
236+ attribute = Mapper . toDbOne ( values [ 0 ] , propertyMetadata )
239237 }
240238
241- if ( value ) {
242- attributeValues [ valuePlaceholder ] = value
239+ if ( attribute ) {
240+ attributes [ valuePlaceholder ] = attribute
243241 }
244242 }
245243
246244 return {
247245 statement,
248246 attributeNames,
249- attributeValues,
247+ attributeValues : attributes ,
250248 }
251249 }
252250
0 commit comments