diff --git a/connectors/s3-connector/src/main/scala/zio/connect/s3/LiveS3Connector.scala b/connectors/s3-connector/src/main/scala/zio/connect/s3/LiveS3Connector.scala index e7270401..824fcb4a 100644 --- a/connectors/s3-connector/src/main/scala/zio/connect/s3/LiveS3Connector.scala +++ b/connectors/s3-connector/src/main/scala/zio/connect/s3/LiveS3Connector.scala @@ -28,8 +28,8 @@ final case class LiveS3Connector(s3: S3) extends S3Connector { .foreach[Any, AwsError, CopyObject] { m => s3.copyObject( CopyObjectRequest( - destinationBucket = AwsBucketName(m.targetBucketName.toString), - destinationKey = AwsObjectKey(m.objectKey.toString), + destinationBucket = AwsBucketName(m.targetBucketName), + destinationKey = AwsObjectKey(m.objectKey), copySource = CopySource(URLEncoder.encode(s"${m.sourceBucketName}/${m.objectKey}", StandardCharsets.UTF_8.toString)) ) @@ -40,14 +40,14 @@ final case class LiveS3Connector(s3: S3) extends S3Connector { override def createBucket(implicit trace: Trace): ZSink[Any, S3Exception, BucketName, BucketName, Unit] = ZSink .foreach[Any, AwsError, BucketName] { name => - s3.createBucket(CreateBucketRequest(bucket = AwsBucketName(name.toString))) + s3.createBucket(CreateBucketRequest(bucket = AwsBucketName(name))) } .mapError(a => S3Exception(a.toThrowable)) override def deleteEmptyBucket(implicit trace: Trace): ZSink[Any, S3Exception, BucketName, BucketName, Unit] = ZSink .foreach[Any, AwsError, BucketName] { name => - s3.deleteBucket(DeleteBucketRequest(bucket = AwsBucketName(name.toString))) + s3.deleteBucket(DeleteBucketRequest(bucket = AwsBucketName(name))) } .mapError(a => S3Exception(a.toThrowable)) @@ -58,8 +58,8 @@ final case class LiveS3Connector(s3: S3) extends S3Connector { .foreachChunk[Any, AwsError, ObjectKey] { objectKeys => s3.deleteObjects( DeleteObjectsRequest( - bucket = AwsBucketName(bucketName.toString), - delete = Delete(objects = objectKeys.map(a => ObjectIdentifier(AwsObjectKey(a.toString)))) + bucket = AwsBucketName(bucketName), + delete = Delete(objects = objectKeys.map(a => ObjectIdentifier(AwsObjectKey(a)))) ) ) } @@ -70,7 +70,7 @@ final case class LiveS3Connector(s3: S3) extends S3Connector { ): ZStream[Any, S3Exception, Byte] = ZStream .unwrap( - s3.getObject(GetObjectRequest(bucket = AwsBucketName(bucketName.toString), key = AwsObjectKey(key.toString))) + s3.getObject(GetObjectRequest(bucket = AwsBucketName(bucketName), key = AwsObjectKey(key))) .map(a => a.output) ) .mapError(a => S3Exception(a.toThrowable)) @@ -89,7 +89,7 @@ final case class LiveS3Connector(s3: S3) extends S3Connector { ): ZStream[Any, S3Exception, ObjectKey] = ZStream .fromIterableZIO( - s3.listObjects(ListObjectsRequest(bucket = AwsBucketName(bucketName.toString))) + s3.listObjects(ListObjectsRequest(bucket = AwsBucketName(bucketName))) .map(_.contents.map(_.flatMap(_.key.toChunk.map(ObjectKey(_)))).getOrElse(Chunk.empty[ObjectKey])) ) .mapError(a => S3Exception(a.toThrowable)) @@ -101,15 +101,14 @@ final case class LiveS3Connector(s3: S3) extends S3Connector { .foreach[Any, AwsError, S3Connector.MoveObject] { m => s3.copyObject( CopyObjectRequest( - destinationBucket = AwsBucketName(m.targetBucketName.toString), - destinationKey = AwsObjectKey(m.targetObjectKey.toString), - copySource = - CopySource(URLEncoder.encode(s"${m.bucketName}/${m.objectKey}", StandardCharsets.UTF_8.toString)) + destinationBucket = AwsBucketName(m.targetBucketName), + destinationKey = AwsObjectKey(m.targetObjectKey), + copySource = CopySource(URLEncoder.encode(s"${m.bucketName}/${m.objectKey}", StandardCharsets.UTF_8)) ) ) *> s3.deleteObject( DeleteObjectRequest( - bucket = AwsBucketName(m.bucketName.toString), - key = AwsObjectKey(m.objectKey.toString) + bucket = AwsBucketName(m.bucketName), + key = AwsObjectKey(m.objectKey) ) ) } @@ -122,8 +121,8 @@ final case class LiveS3Connector(s3: S3) extends S3Connector { .foreachChunk[Any, AwsError, Byte] { content => s3.putObject( request = PutObjectRequest( - bucket = AwsBucketName(bucketName.toString), - key = AwsObjectKey(key.toString), + bucket = AwsBucketName(bucketName), + key = AwsObjectKey(key), contentLength = Some(ContentLength(content.length.toLong)) ), body = ZStream.fromChunk(content).rechunk(1024) diff --git a/connectors/s3-connector/src/main/scala/zio/connect/s3/S3Connector.scala b/connectors/s3-connector/src/main/scala/zio/connect/s3/S3Connector.scala index adb2c111..c6b02bc9 100644 --- a/connectors/s3-connector/src/main/scala/zio/connect/s3/S3Connector.scala +++ b/connectors/s3-connector/src/main/scala/zio/connect/s3/S3Connector.scala @@ -1,7 +1,7 @@ package zio.connect.s3 -import zio.connect.s3.S3Connector.{BucketName, CopyObject, MoveObject, ObjectKey, S3Exception} -import zio.prelude.Newtype +import zio.connect.s3.S3Connector._ +import zio.prelude.Subtype import zio.stream.{ZSink, ZStream} import zio.{Trace, ZIO} @@ -61,10 +61,10 @@ trait S3Connector { object S3Connector { - object BucketName extends Newtype[String] + object BucketName extends Subtype[String] type BucketName = BucketName.Type - object ObjectKey extends Newtype[String] + object ObjectKey extends Subtype[String] type ObjectKey = ObjectKey.Type case class S3Exception(reason: Throwable) diff --git a/connectors/s3-connector/src/main/scala/zio/connect/s3/TestS3Connector.scala b/connectors/s3-connector/src/main/scala/zio/connect/s3/TestS3Connector.scala index 7cd1ed5f..c0f05bbe 100644 --- a/connectors/s3-connector/src/main/scala/zio/connect/s3/TestS3Connector.scala +++ b/connectors/s3-connector/src/main/scala/zio/connect/s3/TestS3Connector.scala @@ -1,6 +1,6 @@ package zio.connect.s3 -import zio.connect.s3.S3Connector.{BucketName, CopyObject, MoveObject, ObjectKey, S3Exception} +import zio.connect.s3.S3Connector._ import zio.connect.s3.TestS3Connector.S3Node.{S3Bucket, S3Obj} import zio.connect.s3.TestS3Connector.TestS3 import zio.stm.{STM, TRef, ZSTM} diff --git a/connectors/s3-connector/src/main/scala/zio/connect/s3/package.scala b/connectors/s3-connector/src/main/scala/zio/connect/s3/package.scala index c9e813c4..c970ea77 100644 --- a/connectors/s3-connector/src/main/scala/zio/connect/s3/package.scala +++ b/connectors/s3-connector/src/main/scala/zio/connect/s3/package.scala @@ -1,8 +1,9 @@ package zio.connect -import zio.Trace +import zio.aws.s3.S3 import zio.connect.s3.S3Connector.{BucketName, CopyObject, ObjectKey, S3Exception} import zio.stream.{ZSink, ZStream} +import zio.{Trace, ZLayer} package object s3 { @@ -44,8 +45,8 @@ package object s3 { ): ZSink[S3Connector, S3Exception, S3Connector.MoveObject, S3Connector.MoveObject, Unit] = ZSink.serviceWithSink(_.moveObject) - val s3ConnectorLiveLayer = LiveS3Connector.layer - val s3ConnectorTestLayer = TestS3Connector.layer + val s3ConnectorLiveLayer: ZLayer[S3, Nothing, LiveS3Connector] = LiveS3Connector.layer + val s3ConnectorTestLayer: ZLayer[Any, Nothing, TestS3Connector] = TestS3Connector.layer def putObject(bucketName: => BucketName, key: ObjectKey)(implicit trace: Trace diff --git a/connectors/s3-connector/src/test/scala/zio/connect/s3/LiveS3ConnectorSpec.scala b/connectors/s3-connector/src/test/scala/zio/connect/s3/LiveS3ConnectorSpec.scala index 12d41c9a..3e0552d5 100644 --- a/connectors/s3-connector/src/test/scala/zio/connect/s3/LiveS3ConnectorSpec.scala +++ b/connectors/s3-connector/src/test/scala/zio/connect/s3/LiveS3ConnectorSpec.scala @@ -5,6 +5,7 @@ import org.testcontainers.utility.DockerImageName import software.amazon.awssdk.auth.credentials.{AwsBasicCredentials, StaticCredentialsProvider} import software.amazon.awssdk.regions.Region import zio.aws.core.config.AwsConfig +import zio.aws.core.httpclient.HttpClient import zio.aws.netty.NettyHttpClient import zio.aws.s3.S3 import zio.{Scope, ZIO, ZLayer} @@ -19,8 +20,8 @@ object LiveS3ConnectorSpec extends S3ConnectorSpec { zio.connect.s3.s3ConnectorLiveLayer ) - lazy val httpClient = NettyHttpClient.default - lazy val awsConfig: ZLayer[Any, Throwable, AwsConfig] = httpClient >>> AwsConfig.default + lazy val httpClient: ZLayer[Any, Throwable, HttpClient] = NettyHttpClient.default + lazy val awsConfig: ZLayer[Any, Throwable, AwsConfig] = httpClient >>> AwsConfig.default lazy val localStackContainer: ZLayer[Scope, Throwable, LocalStackContainer] = ZLayer.fromZIO( diff --git a/connectors/s3-connector/src/test/scala/zio/connect/s3/S3ConnectorSpec.scala b/connectors/s3-connector/src/test/scala/zio/connect/s3/S3ConnectorSpec.scala index ac9357cb..a412c3f0 100644 --- a/connectors/s3-connector/src/test/scala/zio/connect/s3/S3ConnectorSpec.scala +++ b/connectors/s3-connector/src/test/scala/zio/connect/s3/S3ConnectorSpec.scala @@ -27,7 +27,7 @@ trait S3ConnectorSpec extends ZIOSpecDefault { _ <- ZStream.fromChunk(content2) >>> putObject(bucket2, key) _ <- ZStream(S3Connector.CopyObject(bucket1, key, bucket2)) >>> copyObject copiedContent <- getObject(bucket2, key).runCollect - } yield assert(copiedContent)(equalTo(content1)) + } yield assertTrue(copiedContent == content1) }, test("succeeds") { val bucket1 = BucketName(UUID.randomUUID().toString) @@ -66,7 +66,7 @@ trait S3ConnectorSpec extends ZIOSpecDefault { objectsBefore <- listObjects(bucketName).runCollect _ <- ZStream(bucketName) >>> createBucket objectsAfter <- listObjects(bucketName).runCollect - } yield assert(objectsBefore)(equalTo(objectsAfter)) + } yield assertTrue(objectsBefore == objectsAfter) }, test("succeeds") { val bucketName = BucketName(UUID.randomUUID().toString) @@ -170,7 +170,7 @@ trait S3ConnectorSpec extends ZIOSpecDefault { actual <- listObjects(bucketName).runCollect _ <- ZStream.fromChunk(Chunk(obj1, obj2)) >>> deleteObjects(bucketName) afterObjectDeletion <- listObjects(bucketName).runCollect - } yield assert(actual.sortBy(_.toString))(equalTo(Chunk(obj1, obj2).sortBy(_.toString))) && assertTrue( + } yield assertTrue(actual.sortBy(_.toString) == Chunk(obj1, obj2).sortBy(_.toString)) && assertTrue( afterObjectDeletion.isEmpty ) } @@ -190,7 +190,7 @@ trait S3ConnectorSpec extends ZIOSpecDefault { _ <- ZStream.fromChunk(content2) >>> putObject(bucket2, key) _ <- ZStream(S3Connector.MoveObject(bucket1, key, bucket2, key)) >>> moveObject copiedContent <- getObject(bucket2, key).runCollect - } yield assert(copiedContent)(equalTo(content1)) + } yield assertTrue(copiedContent == content1) }, test("succeeds") { @@ -217,10 +217,10 @@ trait S3ConnectorSpec extends ZIOSpecDefault { b1Objects <- listObjects(bucket1).runCollect b2Objects <- listObjects(bucket2).runCollect - } yield assert(initialB1Objects.sortBy(_.toString))(equalTo(Chunk(key1, key2, key3).sortBy(_.toString))) && + } yield assertTrue(initialB1Objects.sortBy(_.toString) == Chunk(key1, key2, key3).sortBy(_.toString)) && assertTrue(initialB2Objects.isEmpty) && - assert(b1Objects)(equalTo(Chunk(key1))) && - assert(b2Objects.sortBy(_.toString))(equalTo(Chunk(key1, key2, key4).sortBy(_.toString))) + assertTrue(b1Objects == Chunk(key1)) && + assertTrue(b2Objects.sortBy(_.toString) == Chunk(key1, key2, key4).sortBy(_.toString)) } ) @@ -235,7 +235,7 @@ trait S3ConnectorSpec extends ZIOSpecDefault { testData <- Random.nextBytes(5) _ <- ZStream.fromChunk(testData) >>> putObject(bucketName, objectKey) actual <- getObject(bucketName, objectKey).runCollect - } yield assert(actual)(equalTo(testData)) + } yield assertTrue(actual == testData) } )