import { CollectionBehavior } from '../Behavior' ; import { ListObjectsV2Request , ListObjectsV2Output } from 'aws-sdk/clients/s3' ; import { S3Metadata } from '../../s3' ; import { ReferenceList } from '../ReferenceList' ; export class FindBehavior < Of > extends CollectionBehavior < Of > { param prefix param pageSize param continuationToken public async find ( prefix , pageSize ? , continuationToken ? ) { try { const parameters = { Bucket : this . fullBucketName , Prefix : this . adjustId ( prefix ) , MaxKeys : pageSize || 100 , FetchOwner : false , ContinuationToken : continuationToken , } ; this . logger . debug ( { parameters } , 'find()' , `with prefix ${ prefix } -->` ) ; const response = await this . s3Client . s3 . listObjectsV2 ( parameters ) . promise ( ) ; this . logger . debug ( { response } , 'find()' , 'response from s3' ) ; const referenceList = new ReferenceList ( this , prefix , response . NextContinuationToken , response . IsTruncated , response . MaxKeys , response . KeyCount ) ; if ( response . Contents ) { response . Contents . forEach ( ( object ) => { const s3Metadata = object as S3Metadata ; referenceList . addReference ( s3Metadata ) ; } ) ; } this . logger . debug ( { referenceList } , 'find()' , 'referenceList' ) ; return referenceList ; } catch ( error ) { this . logger . error ( `error for prefix ${ prefix }` , error , 'find()' ) ; throw this . s3Client . handleError ( error , this . fullBucketName ) ; } } }