@@ -98,6 +98,46 @@ export default class LifecycleUtils {
98
98
} ) ;
99
99
}
100
100
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
+
101
141
// TODO
102
142
/**
103
143
* Filter out all rules based on `Status` and `Filter` (Prefix and Tags)
@@ -239,14 +279,31 @@ export default class LifecycleUtils {
239
279
currentDate,
240
280
} ) ;
241
281
}
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
+
243
294
return store ;
244
295
} , { } ) ;
245
296
// Do not transition to a location where the object is already stored.
246
297
if ( applicableRules . Transition
247
298
&& applicableRules . Transition . StorageClass === metadata . StorageClass ) {
248
299
applicableRules . Transition = undefined ;
249
300
}
301
+
302
+ if ( applicableRules . NoncurrentVersionTransition
303
+ && applicableRules . NoncurrentVersionTransition . StorageClass === metadata . StorageClass ) {
304
+ applicableRules . NoncurrentVersionTransition = undefined ;
305
+ }
306
+
250
307
return applicableRules ;
251
308
/* eslint-enable no-param-reassign */
252
309
}
0 commit comments