Skip to content

Commit

Permalink
Merge branch 'series/2.x' into update/zio-aws-dynamodb-7.21.15.13
Browse files Browse the repository at this point in the history
  • Loading branch information
googley42 authored Jun 18, 2024
2 parents 5618f44 + 87597f8 commit 06817a8
Show file tree
Hide file tree
Showing 48 changed files with 136 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fail-fast: false
matrix:
java: ["adopt@1.11", "openjdk@1.17"]
scala: ["3.3.0", "2.13.8", "2.12.18"]
scala: ["3.3.0", "2.13.12", "2.12.19"]
env:
AWS_ACCESS_KEY_ID: dummykey
AWS_SECRET_ACCESS_KEY: dummykey
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck"

val zioVersion = "2.1.1"
val zioAwsVersion = "7.21.15.13"
val zioSchemaVersion = "0.4.17"
val zioSchemaVersion = "1.2.1"
val zioPreludeVersion = "1.0.0-RC25"
val zioInteropCats3Version = "23.1.0.2"
val catsEffect3Version = "3.5.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import zio.test.ZIOSpecDefault
import zio.test.assertTrue
import zio.schema.{ DeriveSchema, Schema }
import zio.schema.annotation.discriminatorName
import zio.test.Spec

object SyntaxSpec extends ZIOSpecDefault {
@discriminatorName("invoiceType")
Expand Down Expand Up @@ -43,5 +44,5 @@ object SyntaxSpec extends ZIOSpecDefault {
}
)

val spec = suite("DynamodbJsonCodecSpec")(sumTypeSuite)
val spec: Spec[Environment, Any] = suite("DynamodbJsonCodecSpec")(sumTypeSuite)
}
2 changes: 1 addition & 1 deletion dynamodb/src/it/scala/zio/dynamodb/LiveSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ object LiveSpec extends DynamoDBLocalSpec {
ConditionExpression.Operand.ValueOperand(AttributeValue(id))
)

override def spec = mainSuite
override def spec: Spec[Environment with Scope, Any] = mainSuite

final case class ExpressionAttrNames(id: String, num: Int, ttl: Option[Long]) // Note "ttl" is a reserved keyword
object ExpressionAttrNames {
Expand Down
3 changes: 2 additions & 1 deletion dynamodb/src/it/scala/zio/dynamodb/TypeSafeApiCrudSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedExce
import zio.stream.ZStream
import zio.ZIO
import software.amazon.awssdk.services.dynamodb.model.TransactionCanceledException
import zio.Scope

object TypeSafeApiCrudSpec extends DynamoDBLocalSpec {

Expand Down Expand Up @@ -40,7 +41,7 @@ object TypeSafeApiCrudSpec extends DynamoDBLocalSpec {
val (id, surname, addressList, addressMap, addressSet) = ProjectionExpression.accessors[PersonWithCollections]
}

override def spec =
override def spec: Spec[Environment with Scope, Any] =
suite("TypeSafeApiCrudSpec")(
putSuite,
updateSuite,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import zio.schema.Schema
import zio.schema.DeriveSchema
import zio.test.TestAspect
import zio.Chunk
import zio.test.Spec
import zio.Scope

object TypeSafeStreamingUtilsSpec extends DynamoDBLocalSpec {

Expand All @@ -22,7 +24,7 @@ object TypeSafeStreamingUtilsSpec extends DynamoDBLocalSpec {
val (id, forename) = ProjectionExpression.accessors[PersonLegacy]
}

override def spec =
override def spec: Spec[Environment with Scope, Any] =
suite("TypeSafeStreamingUtilsSpec")(
test("migrates legacy data using batchReadFromStream and batchWriteFromStream") {
withTwoSingleIdKeyTables { (personTable, personLegacyTable) =>
Expand Down
2 changes: 2 additions & 0 deletions dynamodb/src/main/scala/zio/dynamodb/AliasMap.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package zio.dynamodb

import scala.annotation.tailrec
import scala.annotation.nowarn

@nowarn
private[dynamodb] final case class AliasMap private[dynamodb] (map: Map[AliasMap.Key, String], index: Int) { self =>

private def +(entry: AttributeValue): (AliasMap, String) = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package zio.dynamodb

import scala.annotation.nowarn

@nowarn
final case class AttributeDefinition private (
name: String,
attributeType: PrimitiveValueType
Expand Down
10 changes: 9 additions & 1 deletion dynamodb/src/main/scala/zio/dynamodb/Codec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private[dynamodb] object Codec {
case StandardType.DoubleType => (a: A) => AttributeValue.Number(BigDecimal(a.toString))
case StandardType.BigDecimalType => (a: A) => AttributeValue.Number(BigDecimal(a.toString))
case StandardType.BigIntegerType => (a: A) => AttributeValue.Number(BigDecimal(a.toString))
case StandardType.UUIDType => (a: A) => AttributeValue.String(a.toString)
case StandardType.CurrencyType => (a: A) => AttributeValue.String(a.toString)
case StandardType.DayOfWeekType => (a: A) => AttributeValue.String(a.toString)
case StandardType.DurationType => (a: A) => AttributeValue.String(a.toString)
case StandardType.InstantType => (a: A) => AttributeValue.String(a.toString)
Expand All @@ -226,6 +226,7 @@ private[dynamodb] object Codec {
case StandardType.OffsetDateTimeType => (a: A) => AttributeValue.String(a.toString)
case StandardType.OffsetTimeType => (a: A) => AttributeValue.String(a.toString)
case StandardType.PeriodType => (a: A) => AttributeValue.String(a.toString)
case StandardType.UUIDType => (a: A) => AttributeValue.String(a.toString)
case StandardType.YearType => yearEncoder
case StandardType.YearMonthType => (a: A) => AttributeValue.String(a.toString)
case StandardType.ZonedDateTimeType => (a: A) => AttributeValue.String(a.toString)
Expand Down Expand Up @@ -611,6 +612,13 @@ private[dynamodb] object Codec {
FromAttributeValue.stringFromAttributeValue.fromAttributeValue(av).flatMap { s =>
Try(UUID.fromString(s)).toEither.left.map(iae => DecodingError(s"Invalid UUID: ${iae.getMessage}"))
}
case StandardType.CurrencyType =>
(av: AttributeValue) =>
FromAttributeValue.stringFromAttributeValue.fromAttributeValue(av).flatMap { s =>
Try(java.util.Currency.getInstance(s)).toEither.left.map(e =>
DecodingError(s"Invalid Currency: ${e.getMessage}")
)
}
case StandardType.DayOfWeekType =>
(av: AttributeValue) => javaTimeStringParser(av)(DayOfWeek.valueOf(_))
case StandardType.DurationType =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ import zio.{ Chunk, NonEmptyChunk, ZIO }

import scala.collection.immutable.{ Map => ScalaMap }
import software.amazon.awssdk.services.dynamodb.model.{ DynamoDbException => AwsSdkDynamoDbException }
import scala.annotation.nowarn

@nowarn
private[dynamodb] final case class DynamoDBExecutorImpl private[dynamodb] (dynamoDb: DynamoDb)
extends DynamoDBExecutor {
import DynamoDBExecutorImpl._
Expand Down
2 changes: 2 additions & 0 deletions dynamodb/src/main/scala/zio/dynamodb/DynamoDBQuery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import zio.prelude.ForEachOps
import zio.schema.Schema
import zio.stream.Stream
import zio.{ Chunk, Schedule, ZIO, Zippable => _, _ }
import scala.annotation.nowarn

sealed trait DynamoDBQuery[-In, +Out] { self =>

Expand Down Expand Up @@ -1046,6 +1047,7 @@ object DynamoDBQuery {
(indexedNonBatched, indexedBatchGetItem, indexedBatchWrite)
}

@nowarn
private[dynamodb] def parallelize[In, A](
query: DynamoDBQuery[In, A]
): (Chunk[Constructor[In, Any]], Chunk[Any] => A) =
Expand Down
3 changes: 3 additions & 0 deletions dynamodb/src/main/scala/zio/dynamodb/KeySchema.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package zio.dynamodb

import scala.annotation.nowarn

@nowarn
final case class KeySchema private (hashKey: String, sortKey: Option[String])
object KeySchema {
def apply(hashKey: String): KeySchema = KeySchema(hashKey, sortKey = None)
Expand Down
2 changes: 2 additions & 0 deletions dynamodb/src/main/scala/zio/dynamodb/MapOfSet.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package zio.dynamodb

import scala.collection.immutable.{ Map => ScalaMap }
import scala.annotation.nowarn

@nowarn
private[dynamodb] final case class MapOfSet[K, V] private (private val map: ScalaMap[K, Set[V]])
extends Iterable[(K, Set[V])] { self =>

Expand Down
3 changes: 3 additions & 0 deletions dynamodb/src/main/scala/zio/dynamodb/NonEmptySet.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package zio.dynamodb

import scala.annotation.nowarn

@nowarn
private[dynamodb] final case class NonEmptySet[A] private (private val set: Set[A]) extends Iterable[A] {
self =>
def +(a: A): NonEmptySet[A] = new NonEmptySet(set + a)
Expand Down
3 changes: 3 additions & 0 deletions dynamodb/src/main/scala/zio/dynamodb/ProjectionType.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package zio.dynamodb

import scala.annotation.nowarn

sealed trait ProjectionType
object ProjectionType {

case object KeysOnly extends ProjectionType
// count must not exceed 20
@nowarn
final case class Include private (nonKeyAttributes: NonEmptySet[String]) extends ProjectionType
object Include {
def apply(nonKeyAttribute: String, nonKeyAttributes: String*): Include =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import zio.dynamodb.DynamoDBQuery._
import zio.stm.{ STM, TMap, ZSTM }
import zio.stream.{ Stream, ZStream }
import zio.{ Chunk, IO, UIO, ZIO }
import scala.annotation.nowarn

@nowarn
private[dynamodb] final case class TestDynamoDBExecutorImpl private[dynamodb] (
tableMap: TMap[String, TMap[PrimaryKey, Item]],
tablePkNameMap: TMap[String, String]
Expand Down
4 changes: 2 additions & 2 deletions dynamodb/src/test/scala/zio/dynamodb/AliasMapRenderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ object AliasMapRenderSpec extends ZIOSpecDefault {
val setOperandValueTwo = UpdateExpression.SetOperand.ValueOperand[Any](two)
val setOperandValueThree = UpdateExpression.SetOperand.ValueOperand[Any](three)

override def spec: Spec[_root_.zio.test.TestEnvironment, Any] = main
override def spec: Spec[TestEnvironment, Any] = main

val main: Spec[_root_.zio.test.TestEnvironment, Any] =
val main: Spec[TestEnvironment, Any] =
suite("AliasMapRender")(
suite("ConditionExpression")(
suite("basic renders")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object AttributeValueRoundTripSerialisationSpec extends ZIOSpecDefault {
}
})

override def spec = serialisationSuite
override def spec: Spec[Environment, Any] = serialisationSuite

trait Serializable {
def genA: Gen[Sized, Element]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import zio.test.Assertion
import zio.Chunk

import zio.schema.DeriveSchema
import zio.test.Spec

object AutoBatchedFailureSpec extends ZIOSpecDefault with DynamoDBFixtures {

override def spec =
override def spec: Spec[Environment, Any] =
suite("Executor spec")(
batchRetries
)
Expand Down
4 changes: 3 additions & 1 deletion dynamodb/src/test/scala/zio/dynamodb/BatchingDSLSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import zio.Chunk
import zio.dynamodb.DynamoDBQuery._
import zio.test.Assertion._
import zio.test.{ assert, TestAspect, ZIOSpecDefault }
import zio.test.Spec

object BatchingDSLSpec extends ZIOSpecDefault with DynamoDBFixtures {

Expand All @@ -17,7 +18,8 @@ object BatchingDSLSpec extends ZIOSpecDefault with DynamoDBFixtures {
TestDynamoDBExecutor.addTable(tableName3.value, "k3", primaryKeyT3 -> itemT3)
)

override def spec = suite("Batching")(crudSuite, scanAndQuerySuite, batchingSuite).provideLayer(DynamoDBExecutor.test)
override def spec: Spec[Environment, Any] =
suite("Batching")(crudSuite, scanAndQuerySuite, batchingSuite).provideLayer(DynamoDBExecutor.test)

private val crudSuite = suite("single Item CRUD suite")(
test("getItem") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import zio.test.ZIOSpecDefault

object BatchingModelSpec extends ZIOSpecDefault with DynamoDBFixtures {

override def spec = suite("Batch Model")(batchGetItemSuite, batchWriteItemSuite)
override def spec: Spec[Environment, Any] = suite("Batch Model")(batchGetItemSuite, batchWriteItemSuite)

private val batchGetItemSuite = suite("BatchGetItem")(
test("should aggregate GetItems using +") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import zio.test.ZIOSpecDefault
import zio.test.assertTrue
import zio.schema.DeriveSchema
import zio.schema.Schema
import zio.test.Spec

object ComplexAliasMapRenderSpec extends ZIOSpecDefault {

Expand Down Expand Up @@ -36,7 +37,7 @@ object ComplexAliasMapRenderSpec extends ZIOSpecDefault {
val (green, red, amber) = ProjectionExpression.accessors[TrafficLight]
}

override def spec =
override def spec: Spec[Environment, Any] =
suite("ComplexAliasMapRenderSpec")(
test("aliasMap should contain all names and values that appear in the rendered expression") {

Expand Down
3 changes: 2 additions & 1 deletion dynamodb/src/test/scala/zio/dynamodb/ExecutorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import zio.test.{ assert, ZIOSpecDefault }
import zio.{ Schedule, ULayer }

import scala.collection.immutable.{ Map => ScalaMap }
import zio.test.Spec

object ExecutorSpec extends ZIOSpecDefault with DynamoDBFixtures {

override def spec =
override def spec: Spec[Environment, Any] =
suite("Executor spec")(
batchRetries
)
Expand Down
5 changes: 3 additions & 2 deletions dynamodb/src/test/scala/zio/dynamodb/GetAndPutSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import zio.dynamodb.codec.Invoice
import zio.dynamodb.codec.Invoice.PreBilled
import zio.schema.{ DeriveSchema, Schema }
import zio.test.{ assertTrue, ZIOSpecDefault }
import zio.test.Spec

object GetAndPutSpec extends ZIOSpecDefault {
final case class SimpleCaseClass2(id: Int, name: String)
Expand All @@ -22,10 +23,10 @@ object GetAndPutSpec extends ZIOSpecDefault {
private val primaryKey1 = PrimaryKey("id" -> 1)
private val primaryKey2 = PrimaryKey("id" -> 2)

override def spec =
override def spec: Spec[Environment, Any] =
suite("get and put suite")(getSuite, putSuite).provideLayer(DynamoDBExecutor.test("table1" -> "id"))

private val getSuite = suite("get item as SimpleCaseClass2")(
private val getSuite = suite("get item as SimpleCaseClass2")(
test("that exists") {
for {
_ <- TestDynamoDBExecutor.addItems("table1", primaryKey1 -> Item("id" -> 1, "name" -> "Avi"))
Expand Down
2 changes: 1 addition & 1 deletion dynamodb/src/test/scala/zio/dynamodb/MapOfSetSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import zio.test.ZIOSpecDefault

object MapOfSetSpec extends ZIOSpecDefault {

override def spec =
override def spec: Spec[Environment, Any] =
suite("MapOfSet")(
test("addAll(1 -> 1, 1 -> 2)") {
val actual = MapOfSet.empty.addAll(1 -> 1, 1 -> 2)
Expand Down
2 changes: 1 addition & 1 deletion dynamodb/src/test/scala/zio/dynamodb/NonEmptySetSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import zio.test.ZIOSpecDefault

object NonEmptySetSpec extends ZIOSpecDefault {

override def spec =
override def spec: Spec[Environment, Any] =
suite("NonEmptySet")(
test("construction single param") {
val actual = NonEmptySet(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import zio.schema.annotation.{ caseName, discriminatorName, fieldName }
import zio.schema.{ DeriveSchema, Schema }
import zio.test.Assertion.equalTo
import zio.test.{ assert, ZIOSpecDefault }
import zio.test.Spec

object OpticsShouldRespectAnnotationsSpec extends ZIOSpecDefault {

Expand Down Expand Up @@ -104,7 +105,7 @@ object OpticsShouldRespectAnnotationsSpec extends ZIOSpecDefault {

}

override def spec =
override def spec: Spec[Environment, Any] =
suite("OpticsShouldRespectAnnotationsSpec")(nonDiscriminatedSuite, discriminatedSuite)

val discriminatedSuite = {
Expand Down
3 changes: 2 additions & 1 deletion dynamodb/src/test/scala/zio/dynamodb/ParallelizeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import zio.dynamodb.DynamoDBQuery._
import zio.test.Assertion.equalTo
import zio.test.assert
import zio.test.ZIOSpecDefault
import zio.test.Spec

object ParallelizeSpec extends ZIOSpecDefault with DynamoDBFixtures {
override def spec = suite("Executor")(parallelizeSuite)
override def spec: Spec[Environment, Any] = suite("Executor")(parallelizeSuite)

private val parallelizeSuite =
suite(label = "parallelize")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object ProjectionExpressionParserSpec extends ZIOSpecDefault {

}

override def spec = suite("main")(mainSuite)
override def spec: Spec[Environment, Any] = suite("main")(mainSuite)

private val mainSuite: Spec[Sized with TestConfig, Nothing] =
suite("ProjectionExpression Parser")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import zio.dynamodb.ProjectionExpression.{ $, mapElement, MapElement, Root }
import zio.schema.{ DeriveSchema, Schema }
import zio.test.Assertion._
import zio.test.{ assert, assertTrue, ZIOSpecDefault }
import zio.test.Spec

object ProjectionExpressionSpec extends ZIOSpecDefault {

Expand Down Expand Up @@ -49,7 +50,7 @@ object ProjectionExpressionSpec extends ZIOSpecDefault {

private val address1 = Address("Addr1")

override def spec =
override def spec: Spec[Environment, Any] =
suite("ProjectionExpressionSpec")(
TypeSafeSuite.typeSafeSuite,
DollarFunctionSuite.typeUnsafeSuite,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import zio.test.ZIOSpecDefault
object ToAttributeValueSpec extends ZIOSpecDefault {
private val ScalaMap = scala.collection.immutable.Map

override def spec = suite("AttrMap suite")(simpleAttrMapSuite)
override def spec: Spec[Environment, Any] = suite("AttrMap suite")(simpleAttrMapSuite)

val simpleAttrMapSuite = suite("Simple AttrMap suite")(
test("AttrMap.empty.map equals empty map") {
Expand Down
Loading

0 comments on commit 06817a8

Please sign in to comment.