@@ -16,6 +16,7 @@ class BucketUtility {
1616 if ( unauthenticated ) {
1717 this . s3 = new S3Client ( {
1818 ...s3Config ,
19+ maxAttempts : 0 ,
1920 credentials : { accessKeyId : '' , secretAccessKey : '' } ,
2021 forcePathStyle : true ,
2122 signer : { sign : async request => request } ,
@@ -52,11 +53,7 @@ class BucketUtility {
5253 return this . s3 . send ( new CreateBucketCommand ( {
5354 Bucket : bucketName ,
5455 ObjectLockEnabledForBucket : true ,
55- } ) )
56- . then ( ( ) => bucketName )
57- . catch ( err => {
58- throw err ;
59- } ) ;
56+ } ) ) . then ( ( ) => bucketName ) ;
6057 }
6158
6259 createMany ( bucketNames ) {
@@ -78,10 +75,7 @@ class BucketUtility {
7875 }
7976
8077 deleteOne ( bucketName ) {
81- return this . s3 . send ( new DeleteBucketCommand ( { Bucket : bucketName } ) )
82- . catch ( err => {
83- throw err ;
84- } ) ;
78+ return this . s3 . send ( new DeleteBucketCommand ( { Bucket : bucketName } ) ) ;
8579 }
8680
8781 deleteMany ( bucketNames ) {
@@ -96,53 +90,57 @@ class BucketUtility {
9690 * @param bucketName
9791 * @returns {Promise.<T> }
9892 */
99-
100- async empty ( bucketName , BypassGovernanceRetention = false ) {
93+ empty ( bucketName , BypassGovernanceRetention = false ) {
10194 const param = {
10295 Bucket : bucketName ,
10396 } ;
10497
10598 return this . s3 . send ( new ListObjectVersionsCommand ( param ) )
10699 . then ( data => Promise . all (
107100 ( data . Versions || [ ] )
108- . filter ( object => ! object . Key . endsWith ( '/' ) )
101+ . filter ( object => ! object . Key . endsWith ( '/' ) )
102+ . map ( object =>
103+ this . s3 . send ( new DeleteObjectCommand ( {
104+ Bucket : bucketName ,
105+ Key : object . Key ,
106+ VersionId : object . VersionId ,
107+ ...( BypassGovernanceRetention && { BypassGovernanceRetention } ) ,
108+ } ) ) . then ( ( ) => object )
109+ )
110+ . concat ( ( data . Versions || [ ] )
111+ . filter ( object => object . Key . endsWith ( '/' ) )
109112 . map ( object =>
110113 this . s3 . send ( new DeleteObjectCommand ( {
111114 Bucket : bucketName ,
112115 Key : object . Key ,
113116 VersionId : object . VersionId ,
117+ ...( BypassGovernanceRetention && { BypassGovernanceRetention } ) ,
114118 } ) )
115- . then ( ( ) => object )
119+ . then ( ( ) => object )
116120 )
117- . concat ( ( data . Versions || [ ] )
118- . filter ( object => object . Key . endsWith ( '/' ) )
119- . map ( object =>
120- this . s3 . send ( new DeleteObjectCommand ( {
121- Bucket : bucketName ,
122- Key : object . Key ,
123- } ) )
124- . then ( ( ) => object )
125- )
121+ )
122+ . concat ( ( data . DeleteMarkers || [ ] )
123+ . map ( object =>
124+ this . s3 . send ( new DeleteObjectCommand ( {
125+ Bucket : bucketName ,
126+ Key : object . Key ,
127+ VersionId : object . VersionId ,
128+ ...( BypassGovernanceRetention && { BypassGovernanceRetention } ) ,
129+ } ) )
130+ . then ( ( ) => object )
126131 )
127- . concat ( ( data . DeleteMarkers || [ ] )
128- . map ( object =>
129- this . s3 . send ( new DeleteObjectCommand ( {
130- Bucket : bucketName ,
131- Key : object . Key ,
132- VersionId : object . VersionId ,
133- } ) )
134- . then ( ( ) => object )
135- ) )
136- ) ) ;
132+ )
133+ )
134+ ) ;
137135 }
138136
139137 emptyMany ( bucketNames ) {
140- const promises = bucketNames . map (
141- bucketName => this . empty ( bucketName )
138+ const promises = bucketNames . map (
139+ bucketName => this . empty ( bucketName )
142140 ) ;
143-
144141 return Promise . all ( promises ) ;
145142 }
143+
146144 emptyIfExists ( bucketName ) {
147145 return this . bucketExists ( bucketName ) . then ( exists => {
148146 if ( exists ) {
@@ -151,6 +149,7 @@ class BucketUtility {
151149 return undefined ;
152150 } ) ;
153151 }
152+
154153 emptyManyIfExists ( bucketNames ) {
155154 const promises = bucketNames . map ( bucketName =>
156155 this . emptyIfExists ( bucketName ) ,
0 commit comments