@@ -98,6 +98,46 @@ export default class LifecycleUtils {
9898 } ) ;
9999 }
100100
101+ /**
102+ * Find the most relevant trantition rule for the given transitions array
103+ * and any previously stored transition from another rule.
104+ * @param params.noncurrentTransitions - Array of lifecycle rule noncurrent
105+ * transitions
106+ * @param params.lastModified - The object's last modified
107+ * @param params.currentDate - current date
108+ * @param params.store - object containing applicable rules
109+ * date
110+ * @return The most applicable transition rule
111+ */
112+ getApplicableNoncurrentVersionTransition ( params : {
113+ store : any ;
114+ currentDate : Date ;
115+ noncurrentTransitions : any [ ] ;
116+ lastModified : string ;
117+ } ) {
118+ const { noncurrentTransitions, store, lastModified, currentDate } = params ;
119+ const ncvt = noncurrentTransitions . reduce ( ( result , ncvt ) => {
120+ const isApplicable = // Is the transition time in the past?
121+ this . _datetime . getTimestamp ( currentDate ) >=
122+ this . _datetime . getTransitionTimestamp ( ncvt , lastModified ) ! ;
123+ if ( ! isApplicable ) {
124+ return result ;
125+ }
126+ return this . compareTransitions ( {
127+ transition1 : ncvt ,
128+ transition2 : result ,
129+ lastModified,
130+ } ) ;
131+ } , undefined ) ;
132+
133+
134+ return this . compareTransitions ( {
135+ transition1 : ncvt ,
136+ transition2 : store . NoncurrentVersionTransition ,
137+ lastModified,
138+ } ) ;
139+ }
140+
101141 // TODO
102142 /**
103143 * Filter out all rules based on `Status` and `Filter` (Prefix and Tags)
@@ -239,14 +279,31 @@ export default class LifecycleUtils {
239279 currentDate,
240280 } ) ;
241281 }
242- // TODO: Add support for NoncurrentVersionTransitions.
282+
283+ const ncvt = 'NoncurrentVersionTransitions' ;
284+ const hasNoncurrentTransitions = Array . isArray ( rule [ ncvt ] ) && rule [ ncvt ] . length > 0 ;
285+ if ( hasNoncurrentTransitions && this . _supportedRules . includes ( 'noncurrentVersionTransitions' ) ) {
286+ store . NoncurrentVersionTransition = this . getApplicableNoncurrentVersionTransition ( {
287+ noncurrentTransitions : rule . NoncurrentVersionTransitions ,
288+ lastModified : metadata . LastModified ,
289+ store,
290+ currentDate,
291+ } ) ;
292+ }
293+
243294 return store ;
244295 } , { } ) ;
245296 // Do not transition to a location where the object is already stored.
246297 if ( applicableRules . Transition
247298 && applicableRules . Transition . StorageClass === metadata . StorageClass ) {
248299 applicableRules . Transition = undefined ;
249300 }
301+
302+ if ( applicableRules . NoncurrentVersionTransition
303+ && applicableRules . NoncurrentVersionTransition . StorageClass === metadata . StorageClass ) {
304+ applicableRules . NoncurrentVersionTransition = undefined ;
305+ }
306+
250307 return applicableRules ;
251308 /* eslint-enable no-param-reassign */
252309 }
0 commit comments