@@ -110,9 +110,7 @@ export class Transaction {
110110
111111 const itemKey = this . getItemKey ( item , args ?. TableName ) ;
112112
113- const actions : UpdateAction [ ] = [
114- { _type : "set" , values : { updatedAt : this . updatedAt } } ,
115- ] ;
113+ const actions : UpdateAction [ ] = [ ] ;
116114
117115 const existingOperation = this . operations [ itemKey ] ;
118116 if ( existingOperation && existingOperation . _type === "update" ) {
@@ -195,11 +193,17 @@ export class Transaction {
195193 ExpressionAttributeNames
196194 ) ;
197195
196+ let hasSetUpdatedAt = false ;
197+
198198 actions . forEach ( ( action ) => {
199199 switch ( action . _type ) {
200200 case "set" :
201201 attr . appendBoth ( action . values ) ;
202202
203+ if ( "updatedAt" in action . values ) {
204+ hasSetUpdatedAt = true ;
205+ }
206+
203207 expressions . set . push (
204208 Object . keys ( action . values )
205209 . map ( ( key ) => `${ attr . getName ( key ) } = ${ attr . getValue ( key ) } ` )
@@ -209,13 +213,21 @@ export class Transaction {
209213 case "remove" :
210214 attr . appendNames ( action . attributes ) ;
211215
216+ if ( action . attributes . includes ( "updatedAt" ) ) {
217+ hasSetUpdatedAt = true ;
218+ }
219+
212220 expressions . remove . push (
213221 action . attributes . map ( ( key ) => attr . getName ( key ) ) . join ( ", " )
214222 ) ;
215223 break ;
216224 case "add" :
217225 attr . appendBoth ( action . values ) ;
218226
227+ if ( "updatedAt" in action . values ) {
228+ hasSetUpdatedAt = true ;
229+ }
230+
219231 expressions . add . push (
220232 Object . keys ( action . values )
221233 . map ( ( key ) => `${ attr . getName ( key ) } ${ attr . getValue ( key ) } ` )
@@ -225,6 +237,10 @@ export class Transaction {
225237 case "delete" :
226238 attr . appendBoth ( action . values ) ;
227239
240+ if ( "updatedAt" in action . values ) {
241+ hasSetUpdatedAt = true ;
242+ }
243+
228244 expressions . delete . push (
229245 Object . keys ( action . values )
230246 . map ( ( key ) => `${ attr . getName ( key ) } ${ attr . getValue ( key ) } ` )
@@ -234,6 +250,14 @@ export class Transaction {
234250 }
235251 } ) ;
236252
253+ if ( ! hasSetUpdatedAt ) {
254+ attr . appendBoth ( { updatedAt : this . updatedAt } ) ;
255+
256+ expressions . set . push (
257+ `${ attr . getName ( "updatedAt" ) } = ${ attr . getValue ( "updatedAt" ) } `
258+ ) ;
259+ }
260+
237261 const joinedExpressions = Object . entries ( expressions )
238262 . filter ( ( [ , value ] ) => value ?. length )
239263 . reduce (
0 commit comments