From 8f17499c3fd24f3ac79f3446a73306a8c024a5e5 Mon Sep 17 00:00:00 2001 From: Avinder Bahra Date: Tue, 6 Aug 2024 07:05:08 +0100 Subject: [PATCH 1/3] minor improvements to API --- .../scala/zio/dynamodb/DynamoDBExecutor.scala | 8 +-- .../zio/dynamodb/TestDynamoDBExecutor.scala | 19 ++----- .../dynamodb/TestDynamoDBExecutorImpl.scala | 52 +++++++++---------- .../src/main/scala/zio/dynamodb/package.scala | 2 +- .../scala/zio/dynamodb/BatchingDSLSpec.scala | 23 +++++--- .../scala/zio/dynamodb/GetAndPutSpec.scala | 2 +- .../examples/SimpleDecodedExample.scala | 4 +- ...ypeSafeRoundTripSerialisationExample.scala | 8 +-- 8 files changed, 59 insertions(+), 59 deletions(-) diff --git a/dynamodb/src/main/scala/zio/dynamodb/DynamoDBExecutor.scala b/dynamodb/src/main/scala/zio/dynamodb/DynamoDBExecutor.scala index 97448c13..4516a394 100644 --- a/dynamodb/src/main/scala/zio/dynamodb/DynamoDBExecutor.scala +++ b/dynamodb/src/main/scala/zio/dynamodb/DynamoDBExecutor.scala @@ -18,8 +18,8 @@ object DynamoDBExecutor { val effect = for { ref <- Ref.make(List.empty[DynamoDBQuery[_, _]]) test <- (for { - tableMap <- TMap.empty[String, TMap[PrimaryKey, Item]] - tablePkNameMap <- TMap.empty[String, String] + tableMap <- TMap.empty[TableName, TMap[PrimaryKey, Item]] + tablePkNameMap <- TMap.empty[TableName, String] } yield TestDynamoDBExecutorImpl(ref, tableMap, tablePkNameMap)).commit } yield test ZLayer.fromZIO(effect) @@ -29,8 +29,8 @@ object DynamoDBExecutor { val effect = for { ref <- Ref.make(List.empty[DynamoDBQuery[_, _]]) test <- (for { - tableMap <- TMap.empty[String, TMap[PrimaryKey, Item]] - tablePkNameMap <- TMap.empty[String, String] + tableMap <- TMap.empty[TableName, TMap[PrimaryKey, Item]] + tablePkNameMap <- TMap.empty[TableName, String] _ <- STM.foreach(tableDefs) { case (tableName, pkFieldName) => for { diff --git a/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutor.scala b/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutor.scala index 129c777a..133ea4aa 100644 --- a/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutor.scala +++ b/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutor.scala @@ -1,7 +1,6 @@ package zio.dynamodb import zio.{ UIO, ZIO } -import zio.dynamodb.DynamoDBQuery.{ BatchGetItem, BatchWriteItem } /** * A Fake implementation of `DynamoDBExecutor.Service` that currently has the very modest aspiration of providing bare minimum @@ -34,7 +33,7 @@ import zio.dynamodb.DynamoDBQuery.{ BatchGetItem, BatchWriteItem } trait TestDynamoDBExecutor { def addTable(tableName: String, pkFieldName: String, pkAndItems: PkAndItem*): UIO[Unit] def addItems(tableName: String, pkAndItems: PkAndItem*): ZIO[Any, DynamoDBError, Unit] - def queries: UIO[List[DynamoDBQuery[_, _]]] + def recordedQueries: UIO[List[DynamoDBQuery[_, _]]] } object TestDynamoDBExecutor { @@ -49,19 +48,7 @@ object TestDynamoDBExecutor { def addItems(tableName: String, pkAndItems: PkAndItem*): ZIO[TestDynamoDBExecutor, DynamoDBError, Unit] = ZIO.serviceWithZIO[TestDynamoDBExecutor](_.addItems(tableName, pkAndItems: _*)) - def queries: ZIO[TestDynamoDBExecutor, Nothing, List[DynamoDBQuery[_, _]]] = - ZIO.serviceWithZIO[TestDynamoDBExecutor](_.queries) - - def isEmptyBatchWrite(q: DynamoDBQuery[_, _]) = - q match { - case BatchWriteItem(items, _, _, _, _) => items.isEmpty - case _ => false - } - - def isEmptyBatchGet(q: DynamoDBQuery[_, _]) = - q match { - case BatchGetItem(items, _, _, _) => items.isEmpty - case _ => false - } + def recordedQueries: ZIO[TestDynamoDBExecutor, Nothing, List[DynamoDBQuery[_, _]]] = + ZIO.serviceWithZIO[TestDynamoDBExecutor](_.recordedQueries) } diff --git a/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutorImpl.scala b/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutorImpl.scala index 00193f09..04e0c761 100644 --- a/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutorImpl.scala +++ b/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutorImpl.scala @@ -9,9 +9,9 @@ import scala.annotation.nowarn @nowarn private[dynamodb] final case class TestDynamoDBExecutorImpl private[dynamodb] ( - recordedQueries: Ref[List[DynamoDBQuery[_, _]]], - tableMap: TMap[String, TMap[PrimaryKey, Item]], - tablePkNameMap: TMap[String, String] + queries: Ref[List[DynamoDBQuery[_, _]]], + tableMap: TMap[TableName, TMap[PrimaryKey, Item]], + tablePkNameMap: TMap[TableName, String] ) extends DynamoDBExecutor with TestDynamoDBExecutor { self => @@ -26,7 +26,7 @@ private[dynamodb] final case class TestDynamoDBExecutorImpl private[dynamodb] ( .foreach(requestItems) { case (tableName, tableGet) => ZIO.foreach(tableGet.keysSet) { key => - fakeGetItem(tableName.value, key).map((tableName, _)) + fakeGetItem(tableName, key).map((tableName, _)) } } .map(_.flatten) @@ -47,9 +47,9 @@ private[dynamodb] final case class TestDynamoDBExecutorImpl private[dynamodb] ( ZIO.foreachDiscard(setOfWrite) { write => write match { case BatchWriteItem.Put(item) => - fakePut(tableName.value, item) + fakePut(tableName, item) case BatchWriteItem.Delete(pk) => - fakeDelete(tableName.value, pk) + fakeDelete(tableName, pk) } } @@ -57,27 +57,27 @@ private[dynamodb] final case class TestDynamoDBExecutorImpl private[dynamodb] ( results.map(_ => BatchWriteItem.Response(None)) case GetItem(tableName, key, _, _, _, _) => - fakeGetItem(tableName.value, key) + fakeGetItem(tableName, key) case PutItem(tableName, item, _, _, _, _, _) => - fakePut(tableName.value, item) + fakePut(tableName, item) // TODO Note UpdateItem is not currently supported as it uses an UpdateExpression case DeleteItem(tableName, key, _, _, _, _, _) => - fakeDelete(tableName.value, key) + fakeDelete(tableName, key) case ScanSome(tableName, limit, _, _, exclusiveStartKey, _, _, _, _) => - fakeScanSome(tableName.value, exclusiveStartKey, Some(limit)) + fakeScanSome(tableName, exclusiveStartKey, Some(limit)) case ScanAll(tableName, _, maybeLimit, _, _, _, _, _, _, _) => - fakeScanAll(tableName.value, maybeLimit) + fakeScanAll(tableName, maybeLimit) case QuerySome(tableName, limit, _, _, exclusiveStartKey, _, _, _, _, _, _) => - fakeScanSome(tableName.value, exclusiveStartKey, Some(limit)) + fakeScanSome(tableName, exclusiveStartKey, Some(limit)) case QueryAll(tableName, _, maybeLimit, _, _, _, _, _, _, _, _) => - fakeScanAll(tableName.value, maybeLimit) + fakeScanAll(tableName, maybeLimit) // TODO: implement CreateTable @@ -85,13 +85,13 @@ private[dynamodb] final case class TestDynamoDBExecutorImpl private[dynamodb] ( ZIO.die(new Exception(s"Constructor $unknown not implemented yet")) } - recordedQueries.update(_ :+ query) *> result + queries.update(_ :+ query) *> result } - private def tableError(tableName: String): DynamoDBError = + private def tableError(tableName: TableName): DynamoDBError = DynamoDBError.ItemError.ValueNotFound(s"table $tableName does not exist") - private def tableMapAndPkName(tableName: String): ZSTM[Any, DynamoDBError, (TMap[PrimaryKey, Item], String)] = + private def tableMapAndPkName(tableName: TableName): ZSTM[Any, DynamoDBError, (TMap[PrimaryKey, Item], String)] = for { tableMap <- for { maybeTableMap <- self.tableMap.get(tableName) @@ -106,30 +106,30 @@ private[dynamodb] final case class TestDynamoDBExecutorImpl private[dynamodb] ( .flatMap(_.fold[STM[DynamoDBError, String]](STM.fail(tableError(tableName)))(STM.succeed(_))) } yield (tableMap, pkName) - private def pkForItem(item: Item, pkName: String): PrimaryKey = + private def pkForItem(item: Item, pkName: String): PrimaryKey = Item(item.map.filter { case (key, _) => key == pkName }) - private def fakeGetItem(tableName: String, pk: PrimaryKey): IO[DynamoDBError, Option[Item]] = + private def fakeGetItem(tableName: TableName, pk: PrimaryKey): IO[DynamoDBError, Option[Item]] = (for { (tableMap, _) <- tableMapAndPkName(tableName) maybeItem <- tableMap.get(pk) } yield maybeItem).commit - private def fakePut(tableName: String, item: Item): IO[DynamoDBError, Option[Item]] = + private def fakePut(tableName: TableName, item: Item): IO[DynamoDBError, Option[Item]] = (for { (tableMap, pkName) <- tableMapAndPkName(tableName) pk = pkForItem(item, pkName) _ <- tableMap.put(pk, item) } yield None).commit - private def fakeDelete(tableName: String, pk: PrimaryKey): IO[DynamoDBError, Option[Item]] = + private def fakeDelete(tableName: TableName, pk: PrimaryKey): IO[DynamoDBError, Option[Item]] = (for { (tableMap, _) <- tableMapAndPkName(tableName) _ <- tableMap.delete(pk) } yield None).commit private def fakeScanSome( - tableName: String, + tableName: TableName, exclusiveStartKey: LastEvaluatedKey, maybeLimit: Option[Int] ): IO[DynamoDBError, (Chunk[Item], LastEvaluatedKey)] = @@ -139,7 +139,7 @@ private[dynamodb] final case class TestDynamoDBExecutorImpl private[dynamodb] ( result <- STM.succeed(slice(sort(xs, pkName), exclusiveStartKey, maybeLimit)) } yield result).commit - private def fakeScanAll[R](tableName: String, maybeLimit: Option[Int]): UIO[Stream[DynamoDBError, Item]] = { + private def fakeScanAll[R](tableName: TableName, maybeLimit: Option[Int]): UIO[Stream[DynamoDBError, Item]] = { val start: LastEvaluatedKey = None ZIO.succeed( ZStream @@ -217,21 +217,21 @@ private[dynamodb] final case class TestDynamoDBExecutorImpl private[dynamodb] ( override def addTable(tableName: String, pkFieldName: String, pkAndItems: PkAndItem*): UIO[Unit] = (for { - _ <- tablePkNameMap.put(tableName, pkFieldName) + _ <- tablePkNameMap.put(TableName(tableName), pkFieldName) tmap <- TMap.empty[PrimaryKey, Item] _ <- STM.foreach(pkAndItems) { case (pk, item) => tmap.put(pk, item) } - _ <- tableMap.put(tableName, tmap) + _ <- tableMap.put(TableName(tableName), tmap) } yield ()).commit override def addItems(tableName: String, pkAndItems: (PrimaryKey, Item)*): ZIO[Any, DynamoDBError, Unit] = (for { - (tableMap, _) <- tableMapAndPkName(tableName) + (tableMap, _) <- tableMapAndPkName(TableName(tableName)) _ <- STM.foreach(pkAndItems) { case (pk, item) => tableMap.put(pk, item) } } yield ()).commit - override def queries: UIO[List[DynamoDBQuery[_, _]]] = self.recordedQueries.get + override def recordedQueries: UIO[List[DynamoDBQuery[_, _]]] = self.queries.get } diff --git a/dynamodb/src/main/scala/zio/dynamodb/package.scala b/dynamodb/src/main/scala/zio/dynamodb/package.scala index d8f19827..e98ffb7d 100644 --- a/dynamodb/src/main/scala/zio/dynamodb/package.scala +++ b/dynamodb/src/main/scala/zio/dynamodb/package.scala @@ -14,7 +14,7 @@ package object dynamodb { val Item = AttrMap type PkAndItem = (PrimaryKey, Item) - type TableNameAndPK = (String, String) + type TableNameAndPK = (TableName, String) type Encoder[A] = A => AttributeValue type Decoder[+A] = AttributeValue => Either[ItemError, A] diff --git a/dynamodb/src/test/scala/zio/dynamodb/BatchingDSLSpec.scala b/dynamodb/src/test/scala/zio/dynamodb/BatchingDSLSpec.scala index 776fa25c..b4172243 100644 --- a/dynamodb/src/test/scala/zio/dynamodb/BatchingDSLSpec.scala +++ b/dynamodb/src/test/scala/zio/dynamodb/BatchingDSLSpec.scala @@ -23,26 +23,26 @@ object BatchingDSLSpec extends ZIOSpecDefault with DynamoDBFixtures { DynamoDBExecutor.test ) - private val singleQueryDoesNotBatchSuite = suite("single query does not batch CRUD suite")( + private val singleQueryDoesNotBatchSuite = suite("single query does not auto-batch CRUD suite")( test("a single getItem does not get auto-batched") { for { _ <- TestDynamoDBExecutor.addTable(tableName1.value, "k1", primaryKeyT1 -> itemT1, primaryKeyT1_2 -> itemT1_2) result <- getItemT1.execute - queries <- TestDynamoDBExecutor.queries + queries <- TestDynamoDBExecutor.recordedQueries } yield assert(result)(equalTo(Some(itemT1))) && assertQueryNotBatched(queries) }, test("a single putItem does not get auto-batched") { for { _ <- TestDynamoDBExecutor.addTable(tableName1.value, "k1", primaryKeyT1 -> itemT1, primaryKeyT1_2 -> itemT1_2) result <- putItemT1.execute - queries <- TestDynamoDBExecutor.queries + queries <- TestDynamoDBExecutor.recordedQueries } yield assert(result)(equalTo(None)) && assertQueryNotBatched(queries) }, test("a single deleteItem does not get auto-batched") { for { _ <- TestDynamoDBExecutor.addTable(tableName1.value, "k1", primaryKeyT1 -> itemT1, primaryKeyT1_2 -> itemT1_2) result <- deleteItemT1.execute - queries <- TestDynamoDBExecutor.queries + queries <- TestDynamoDBExecutor.recordedQueries } yield assert(result)(equalTo(None)) && assertQueryNotBatched(queries) } ) @@ -198,9 +198,20 @@ object BatchingDSLSpec extends ZIOSpecDefault with DynamoDBFixtures { private def assertQueryNotBatched(queries: List[DynamoDBQuery[_, _]]) = assertTrue(queries.size == 3) && assertTrue( - queries.find(TestDynamoDBExecutor.isEmptyBatchWrite).isDefined + queries.find(isEmptyBatchWrite).isDefined ) && assertTrue( - queries.find(TestDynamoDBExecutor.isEmptyBatchGet).isDefined + queries.find(isEmptyBatchGet).isDefined ) + private def isEmptyBatchWrite(q: DynamoDBQuery[_, _]): Boolean = + q match { + case BatchWriteItem(items, _, _, _, _) => items.isEmpty + case _ => false + } + + private def isEmptyBatchGet(q: DynamoDBQuery[_, _]): Boolean = + q match { + case BatchGetItem(items, _, _, _) => items.isEmpty + case _ => false + } } diff --git a/dynamodb/src/test/scala/zio/dynamodb/GetAndPutSpec.scala b/dynamodb/src/test/scala/zio/dynamodb/GetAndPutSpec.scala index d3b5827f..640470fe 100644 --- a/dynamodb/src/test/scala/zio/dynamodb/GetAndPutSpec.scala +++ b/dynamodb/src/test/scala/zio/dynamodb/GetAndPutSpec.scala @@ -24,7 +24,7 @@ object GetAndPutSpec extends ZIOSpecDefault { private val primaryKey2 = PrimaryKey("id" -> 2) override def spec: Spec[Environment, Any] = - suite("get and put suite")(getSuite, putSuite).provideLayer(DynamoDBExecutor.test("table1" -> "id")) + suite("get and put suite")(getSuite, putSuite).provideLayer(DynamoDBExecutor.test(TableName("table1") -> "id")) private val getSuite = suite("get item as SimpleCaseClass2")( test("that exists") { diff --git a/examples/src/main/scala/zio/dynamodb/examples/SimpleDecodedExample.scala b/examples/src/main/scala/zio/dynamodb/examples/SimpleDecodedExample.scala index d1923144..9123c2a5 100644 --- a/examples/src/main/scala/zio/dynamodb/examples/SimpleDecodedExample.scala +++ b/examples/src/main/scala/zio/dynamodb/examples/SimpleDecodedExample.scala @@ -1,7 +1,7 @@ package zio.dynamodb.examples import zio.dynamodb.DynamoDBQuery._ -import zio.dynamodb.{ DynamoDBExecutor, Item } +import zio.dynamodb.{ DynamoDBExecutor, Item, TableName } import zio.schema.{ DeriveSchema, Schema } import zio.ZIOAppDefault import zio.Console.printLine @@ -42,5 +42,5 @@ object SimpleDecodedExample extends ZIOAppDefault { } yield () override def run: ZIO[Any, Throwable, Unit] = - program.provideLayer(DynamoDBExecutor.test("table1" -> "id")) + program.provideLayer(DynamoDBExecutor.test(TableName("table1") -> "id")) } diff --git a/examples/src/main/scala/zio/dynamodb/examples/TypeSafeRoundTripSerialisationExample.scala b/examples/src/main/scala/zio/dynamodb/examples/TypeSafeRoundTripSerialisationExample.scala index d8b115f8..ef760717 100644 --- a/examples/src/main/scala/zio/dynamodb/examples/TypeSafeRoundTripSerialisationExample.scala +++ b/examples/src/main/scala/zio/dynamodb/examples/TypeSafeRoundTripSerialisationExample.scala @@ -14,10 +14,12 @@ import zio.dynamodb.{ DynamoDBExecutor, DynamoDBQuery, PrimaryKey } import zio.schema.annotation.{ caseName, discriminatorName } import zio.schema.{ DeriveSchema, Schema } -import java.time.Instant import zio.dynamodb.ProjectionExpression -import zio.ZIO import zio.dynamodb.DynamoDBError.ItemError +import zio.dynamodb.TableName +import zio.ZIO +import java.time.Instant + object TypeSafeRoundTripSerialisationExample extends ZIOAppDefault { @discriminatorName("invoiceType") @@ -121,5 +123,5 @@ object TypeSafeRoundTripSerialisationExample extends ZIOAppDefault { } yield () override def run: ZIO[Any, Throwable, Unit] = - program.provideLayer(DynamoDBExecutor.test("table1" -> "id")) + program.provideLayer(DynamoDBExecutor.test(TableName("table1") -> "id")) } From 624569f27d36199bd162a6e2fe60aa782bbc6404 Mon Sep 17 00:00:00 2001 From: Avinder Bahra Date: Wed, 7 Aug 2024 07:11:07 +0100 Subject: [PATCH 2/3] minor improvements to TestDynamoDBExecutor --- .../src/main/scala/zio/dynamodb/DynamoDBExecutor.scala | 8 ++++---- .../main/scala/zio/dynamodb/TestDynamoDBExecutor.scala | 2 ++ .../scala/zio/dynamodb/TestDynamoDBExecutorImpl.scala | 1 + dynamodb/src/main/scala/zio/dynamodb/package.scala | 3 --- .../src/test/scala/zio/dynamodb/DynamoDBFixtures.scala | 2 +- dynamodb/src/test/scala/zio/dynamodb/GetAndPutSpec.scala | 2 +- .../zio/dynamodb/examples/SimpleDecodedExample.scala | 4 ++-- .../examples/TypeSafeRoundTripSerialisationExample.scala | 3 +-- 8 files changed, 12 insertions(+), 13 deletions(-) diff --git a/dynamodb/src/main/scala/zio/dynamodb/DynamoDBExecutor.scala b/dynamodb/src/main/scala/zio/dynamodb/DynamoDBExecutor.scala index 4516a394..e64d7d86 100644 --- a/dynamodb/src/main/scala/zio/dynamodb/DynamoDBExecutor.scala +++ b/dynamodb/src/main/scala/zio/dynamodb/DynamoDBExecutor.scala @@ -25,18 +25,18 @@ object DynamoDBExecutor { ZLayer.fromZIO(effect) } - def test(tableDefs: TableNameAndPK*): ULayer[DynamoDBExecutor with TestDynamoDBExecutor] = { + def test(tableAndPKNames: (String, String)*): ULayer[DynamoDBExecutor with TestDynamoDBExecutor] = { val effect = for { ref <- Ref.make(List.empty[DynamoDBQuery[_, _]]) test <- (for { tableMap <- TMap.empty[TableName, TMap[PrimaryKey, Item]] tablePkNameMap <- TMap.empty[TableName, String] - _ <- STM.foreach(tableDefs) { + _ <- STM.foreach(tableAndPKNames) { case (tableName, pkFieldName) => for { - _ <- tablePkNameMap.put(tableName, pkFieldName) + _ <- tablePkNameMap.put(TableName(tableName), pkFieldName) pkToItemMap <- TMap.empty[PrimaryKey, Item] - _ <- tableMap.put(tableName, pkToItemMap) + _ <- tableMap.put(TableName(tableName), pkToItemMap) } yield () } } yield TestDynamoDBExecutorImpl(ref, tableMap, tablePkNameMap)).commit diff --git a/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutor.scala b/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutor.scala index 133ea4aa..8ea508e1 100644 --- a/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutor.scala +++ b/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutor.scala @@ -1,5 +1,6 @@ package zio.dynamodb +import zio.dynamodb.TestDynamoDBExecutor.PkAndItem import zio.{ UIO, ZIO } /** @@ -37,6 +38,7 @@ trait TestDynamoDBExecutor { } object TestDynamoDBExecutor { + type PkAndItem = (PrimaryKey, Item) def addTable( tableName: String, diff --git a/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutorImpl.scala b/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutorImpl.scala index 04e0c761..74d5afa9 100644 --- a/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutorImpl.scala +++ b/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutorImpl.scala @@ -2,6 +2,7 @@ package zio.dynamodb import zio.dynamodb.DynamoDBQuery.BatchGetItem.TableGet import zio.dynamodb.DynamoDBQuery._ +import zio.dynamodb.TestDynamoDBExecutor.PkAndItem import zio.stm.{ STM, TMap, ZSTM } import zio.stream.{ Stream, ZStream } import zio.{ Chunk, IO, Ref, UIO, ZIO } diff --git a/dynamodb/src/main/scala/zio/dynamodb/package.scala b/dynamodb/src/main/scala/zio/dynamodb/package.scala index e98ffb7d..c521ecaa 100644 --- a/dynamodb/src/main/scala/zio/dynamodb/package.scala +++ b/dynamodb/src/main/scala/zio/dynamodb/package.scala @@ -13,9 +13,6 @@ package object dynamodb { type Item = AttrMap val Item = AttrMap - type PkAndItem = (PrimaryKey, Item) - type TableNameAndPK = (TableName, String) - type Encoder[A] = A => AttributeValue type Decoder[+A] = AttributeValue => Either[ItemError, A] diff --git a/dynamodb/src/test/scala/zio/dynamodb/DynamoDBFixtures.scala b/dynamodb/src/test/scala/zio/dynamodb/DynamoDBFixtures.scala index e80c907c..dc4c6ce1 100644 --- a/dynamodb/src/test/scala/zio/dynamodb/DynamoDBFixtures.scala +++ b/dynamodb/src/test/scala/zio/dynamodb/DynamoDBFixtures.scala @@ -34,7 +34,7 @@ trait DynamoDBFixtures { val deleteItemT1: DeleteItem = DeleteItem(tableName = tableName1, key = primaryKeyT1) val deleteItemT3: DeleteItem = DeleteItem(tableName = tableName3, key = primaryKeyT3) - def chunkOfPrimaryKeyAndItem(r: Range, pkFieldName: String): Chunk[PkAndItem] = + def chunkOfPrimaryKeyAndItem(r: Range, pkFieldName: String): Chunk[(PrimaryKey, Item)] = Chunk.fromIterable(r.map(i => (PrimaryKey(pkFieldName -> i), Item(pkFieldName -> i, "k2" -> (i + 1)))).toList) def resultItems(range: Range): Chunk[Item] = chunkOfPrimaryKeyAndItem(range, "k1").map { case (_, v) => v } diff --git a/dynamodb/src/test/scala/zio/dynamodb/GetAndPutSpec.scala b/dynamodb/src/test/scala/zio/dynamodb/GetAndPutSpec.scala index 640470fe..d3b5827f 100644 --- a/dynamodb/src/test/scala/zio/dynamodb/GetAndPutSpec.scala +++ b/dynamodb/src/test/scala/zio/dynamodb/GetAndPutSpec.scala @@ -24,7 +24,7 @@ object GetAndPutSpec extends ZIOSpecDefault { private val primaryKey2 = PrimaryKey("id" -> 2) override def spec: Spec[Environment, Any] = - suite("get and put suite")(getSuite, putSuite).provideLayer(DynamoDBExecutor.test(TableName("table1") -> "id")) + suite("get and put suite")(getSuite, putSuite).provideLayer(DynamoDBExecutor.test("table1" -> "id")) private val getSuite = suite("get item as SimpleCaseClass2")( test("that exists") { diff --git a/examples/src/main/scala/zio/dynamodb/examples/SimpleDecodedExample.scala b/examples/src/main/scala/zio/dynamodb/examples/SimpleDecodedExample.scala index 9123c2a5..d1923144 100644 --- a/examples/src/main/scala/zio/dynamodb/examples/SimpleDecodedExample.scala +++ b/examples/src/main/scala/zio/dynamodb/examples/SimpleDecodedExample.scala @@ -1,7 +1,7 @@ package zio.dynamodb.examples import zio.dynamodb.DynamoDBQuery._ -import zio.dynamodb.{ DynamoDBExecutor, Item, TableName } +import zio.dynamodb.{ DynamoDBExecutor, Item } import zio.schema.{ DeriveSchema, Schema } import zio.ZIOAppDefault import zio.Console.printLine @@ -42,5 +42,5 @@ object SimpleDecodedExample extends ZIOAppDefault { } yield () override def run: ZIO[Any, Throwable, Unit] = - program.provideLayer(DynamoDBExecutor.test(TableName("table1") -> "id")) + program.provideLayer(DynamoDBExecutor.test("table1" -> "id")) } diff --git a/examples/src/main/scala/zio/dynamodb/examples/TypeSafeRoundTripSerialisationExample.scala b/examples/src/main/scala/zio/dynamodb/examples/TypeSafeRoundTripSerialisationExample.scala index ef760717..15ee7114 100644 --- a/examples/src/main/scala/zio/dynamodb/examples/TypeSafeRoundTripSerialisationExample.scala +++ b/examples/src/main/scala/zio/dynamodb/examples/TypeSafeRoundTripSerialisationExample.scala @@ -16,7 +16,6 @@ import zio.schema.{ DeriveSchema, Schema } import zio.dynamodb.ProjectionExpression import zio.dynamodb.DynamoDBError.ItemError -import zio.dynamodb.TableName import zio.ZIO import java.time.Instant @@ -123,5 +122,5 @@ object TypeSafeRoundTripSerialisationExample extends ZIOAppDefault { } yield () override def run: ZIO[Any, Throwable, Unit] = - program.provideLayer(DynamoDBExecutor.test(TableName("table1") -> "id")) + program.provideLayer(DynamoDBExecutor.test("table1" -> "id")) } From 9b4e085137a90b1b54fd492d2ed3b6ff650c5941 Mon Sep 17 00:00:00 2001 From: Avinder Bahra Date: Wed, 7 Aug 2024 07:16:27 +0100 Subject: [PATCH 3/3] scalafmt --- dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutor.scala | 2 +- dynamodb/src/test/scala/zio/dynamodb/DynamoDBFixtures.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutor.scala b/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutor.scala index 8ea508e1..3e0677bd 100644 --- a/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutor.scala +++ b/dynamodb/src/main/scala/zio/dynamodb/TestDynamoDBExecutor.scala @@ -38,7 +38,7 @@ trait TestDynamoDBExecutor { } object TestDynamoDBExecutor { - type PkAndItem = (PrimaryKey, Item) + type PkAndItem = (PrimaryKey, Item) def addTable( tableName: String, diff --git a/dynamodb/src/test/scala/zio/dynamodb/DynamoDBFixtures.scala b/dynamodb/src/test/scala/zio/dynamodb/DynamoDBFixtures.scala index dc4c6ce1..37cbd76b 100644 --- a/dynamodb/src/test/scala/zio/dynamodb/DynamoDBFixtures.scala +++ b/dynamodb/src/test/scala/zio/dynamodb/DynamoDBFixtures.scala @@ -37,6 +37,6 @@ trait DynamoDBFixtures { def chunkOfPrimaryKeyAndItem(r: Range, pkFieldName: String): Chunk[(PrimaryKey, Item)] = Chunk.fromIterable(r.map(i => (PrimaryKey(pkFieldName -> i), Item(pkFieldName -> i, "k2" -> (i + 1)))).toList) - def resultItems(range: Range): Chunk[Item] = chunkOfPrimaryKeyAndItem(range, "k1").map { case (_, v) => v } + def resultItems(range: Range): Chunk[Item] = chunkOfPrimaryKeyAndItem(range, "k1").map { case (_, v) => v } }