From 7523fb9f0b479ba4ba1646d0331a3b4e54af7c11 Mon Sep 17 00:00:00 2001 From: Matthias Berndt Date: Sun, 29 Oct 2023 08:09:24 +0100 Subject: [PATCH] add missing DeriveConfig instances (#1309) --- .../zio/config/magnolia/DeriveConfig.scala | 45 +++++++++++-------- .../zio/config/magnolia/DeriveConfig.scala | 16 ++++++- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/magnolia/shared/src/main/scala-2.12-2.13/zio/config/magnolia/DeriveConfig.scala b/magnolia/shared/src/main/scala-2.12-2.13/zio/config/magnolia/DeriveConfig.scala index 84771ae03..c8cf4b824 100644 --- a/magnolia/shared/src/main/scala-2.12-2.13/zio/config/magnolia/DeriveConfig.scala +++ b/magnolia/shared/src/main/scala-2.12-2.13/zio/config/magnolia/DeriveConfig.scala @@ -1,11 +1,11 @@ package zio.config.magnolia import magnolia._ -import zio.Config +import zio.{Config, LogLevel, Chunk} import zio.config._ import java.net.URI -import java.time.{LocalDate, LocalDateTime, LocalTime} +import java.time.{LocalDate, LocalDateTime, LocalTime, OffsetDateTime} import java.util.UUID import scala.collection.immutable @@ -34,22 +34,25 @@ object DeriveConfig { import Config._ - implicit val implicitStringDesc: DeriveConfig[String] = DeriveConfig(string) - implicit val implicitBooleanDesc: DeriveConfig[Boolean] = DeriveConfig(boolean) - implicit val implicitIntDesc: DeriveConfig[Int] = DeriveConfig(int) - implicit val implicitBigIntDesc: DeriveConfig[BigInt] = DeriveConfig(bigInt) - implicit val implicitFloatDesc: DeriveConfig[Float] = DeriveConfig(float) - implicit val implicitDoubleDesc: DeriveConfig[Double] = DeriveConfig(double) - implicit val implicitBigDecimalDesc: DeriveConfig[BigDecimal] = DeriveConfig(bigDecimal) - implicit val implicitUriDesc: DeriveConfig[URI] = DeriveConfig(uri) - implicit val implicitDurationDesc: DeriveConfig[zio.Duration] = DeriveConfig(duration) - implicit val implicitLocalDateDesc: DeriveConfig[LocalDate] = DeriveConfig(localDate) - implicit val implicitLocalTimeDesc: DeriveConfig[LocalTime] = DeriveConfig(localTime) - implicit val implicitLocalDateTimeDesc: DeriveConfig[LocalDateTime] = DeriveConfig(localDateTime) - implicit val implicitByteDesc: DeriveConfig[Byte] = DeriveConfig(Config.byte) - implicit val implicitShortDesc: DeriveConfig[Short] = DeriveConfig(Config.short) - implicit val implicitUUIDDesc: DeriveConfig[UUID] = DeriveConfig(Config.uuid) - implicit val implicitLongDesc: DeriveConfig[Long] = DeriveConfig(Config.long) + implicit val implicitSecretDesc: DeriveConfig[Secret] = DeriveConfig(secret) + implicit val implicitOffsetDateTimeDesc: DeriveConfig[OffsetDateTime] = DeriveConfig(offsetDateTime) + implicit val implicitLogLevelDesc: DeriveConfig[LogLevel] = DeriveConfig(logLevel) + implicit val implicitStringDesc: DeriveConfig[String] = DeriveConfig(string) + implicit val implicitBooleanDesc: DeriveConfig[Boolean] = DeriveConfig(boolean) + implicit val implicitIntDesc: DeriveConfig[Int] = DeriveConfig(int) + implicit val implicitBigIntDesc: DeriveConfig[BigInt] = DeriveConfig(bigInt) + implicit val implicitFloatDesc: DeriveConfig[Float] = DeriveConfig(float) + implicit val implicitDoubleDesc: DeriveConfig[Double] = DeriveConfig(double) + implicit val implicitBigDecimalDesc: DeriveConfig[BigDecimal] = DeriveConfig(bigDecimal) + implicit val implicitUriDesc: DeriveConfig[URI] = DeriveConfig(uri) + implicit val implicitDurationDesc: DeriveConfig[zio.Duration] = DeriveConfig(duration) + implicit val implicitLocalDateDesc: DeriveConfig[LocalDate] = DeriveConfig(localDate) + implicit val implicitLocalTimeDesc: DeriveConfig[LocalTime] = DeriveConfig(localTime) + implicit val implicitLocalDateTimeDesc: DeriveConfig[LocalDateTime] = DeriveConfig(localDateTime) + implicit val implicitByteDesc: DeriveConfig[Byte] = DeriveConfig(Config.byte) + implicit val implicitShortDesc: DeriveConfig[Short] = DeriveConfig(Config.short) + implicit val implicitUUIDDesc: DeriveConfig[UUID] = DeriveConfig(Config.uuid) + implicit val implicitLongDesc: DeriveConfig[Long] = DeriveConfig(Config.long) implicit def implicitOptionDesc[A: DeriveConfig]: DeriveConfig[Option[A]] = DeriveConfig(DeriveConfig[A].desc.optional) @@ -66,6 +69,12 @@ object DeriveConfig { implicit def implicitSetDesc[A: DeriveConfig]: DeriveConfig[Set[A]] = DeriveConfig(Config.setOf(implicitly[DeriveConfig[A]].desc)) + implicit def implicitVectorDesc[A: DeriveConfig]: DeriveConfig[Vector[A]] = + DeriveConfig(Config.vectorOf(DeriveConfig[A].desc)) + + implicit def implicitChunkDesc[A: DeriveConfig]: DeriveConfig[Chunk[A]] = + DeriveConfig(Config.chunkOf(DeriveConfig[A].desc)) + implicit def implicitMapDesc[A: DeriveConfig]: DeriveConfig[Map[String, A]] = DeriveConfig(Config.table(implicitly[DeriveConfig[A]].desc)) diff --git a/magnolia/shared/src/main/scala-dotty/zio/config/magnolia/DeriveConfig.scala b/magnolia/shared/src/main/scala-dotty/zio/config/magnolia/DeriveConfig.scala index 6cedd5067..d54a467ac 100644 --- a/magnolia/shared/src/main/scala-dotty/zio/config/magnolia/DeriveConfig.scala +++ b/magnolia/shared/src/main/scala-dotty/zio/config/magnolia/DeriveConfig.scala @@ -5,7 +5,7 @@ import zio.NonEmptyChunk import java.io.File import java.net.{URI, URL} -import java.time.{Duration, Instant, LocalDate, LocalDateTime, LocalTime} +import java.time.{Duration, Instant, LocalDate, LocalDateTime, LocalTime, OffsetDateTime} import java.util.UUID import scala.concurrent.duration.{Duration => ScalaDuration} import scala.deriving._ @@ -13,7 +13,7 @@ import scala.compiletime.{erasedValue, summonInline, constValue, summonFrom, con import scala.quoted import scala.util.Try import DeriveConfig._ -import zio.{Config, ConfigProvider}, Config._ +import zio.{Config, ConfigProvider, LogLevel, Chunk}, Config._ import zio.config.syntax._ import zio.config.derivation._ @@ -66,6 +66,9 @@ object DeriveConfig { final case class ProductName(originalName: String, alternativeNames: List[String], descriptions: List[String]) final case class CoproductName(originalName: String, alternativeNames: List[String], descriptions: List[String], typeDiscriminator: Option[String]) + lazy given DeriveConfig[Secret] = DeriveConfig.from(secret) + lazy given DeriveConfig[OffsetDateTime] = DeriveConfig.from(offsetDateTime) + lazy given DeriveConfig[LogLevel] = DeriveConfig.from(logLevel) lazy given DeriveConfig[String] = DeriveConfig.from(string) lazy given DeriveConfig[Boolean] = DeriveConfig.from(boolean) lazy given DeriveConfig[Int] = DeriveConfig.from(int) @@ -95,6 +98,15 @@ object DeriveConfig { given seqDesc[A](using ev: DeriveConfig[A]): DeriveConfig[Seq[A]] = DeriveConfig.from(listOf(ev.desc).map(_.toSeq)) + given setDesc[A](using ev: DeriveConfig[A]): DeriveConfig[Set[A]] = + DeriveConfig.from(setOf(ev.desc)) + + given vectorDesc[A](using ev: DeriveConfig[A]): DeriveConfig[Vector[A]] = + DeriveConfig.from(vectorOf(ev.desc)) + + given chunkDesc[A](using ev: DeriveConfig[A]): DeriveConfig[Chunk[A]] = + DeriveConfig.from(chunkOf(ev.desc)) + given mapDesc[A](using ev: DeriveConfig[A]): DeriveConfig[Map[String, A]] = DeriveConfig.from(table(ev.desc))