Skip to content

Commit

Permalink
add missing DeriveConfig instances (#1309)
Browse files Browse the repository at this point in the history
  • Loading branch information
mberndt123 authored Oct 29, 2023
1 parent cd1f9d4 commit 7523fb9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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._
import scala.compiletime.{erasedValue, summonInline, constValue, summonFrom, constValueTuple}
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._

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit 7523fb9

Please sign in to comment.