Package

zio

config

Permalink

package config

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. config
  2. ImplicitTupleConversion
  3. ConfigStringModule
  4. ConfigModule
  5. ReadModule
  6. ConfigDocsModule
  7. WriteModule
  8. ConfigDescriptorModule
  9. ConfigSourceModule
  10. KeyValueModule
  11. KeyConversionFunctions
  12. AnyRef
  13. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. type CachedReaders = Map[config.ReadModule.ConfigSource, ManagedReader]

    Permalink
    Definition Classes
    ReadModule
  2. sealed trait ConfigDescriptor[A] extends AnyRef

    Permalink
    Definition Classes
    ConfigDescriptorModule
  3. trait ConfigDescriptorFunctions extends AnyRef

    Permalink
    Definition Classes
    ConfigDescriptorModule
  4. trait ConfigDescriptorModule extends ConfigSourceModule

    Permalink
    Annotations
    @silent( "Unused import" )
  5. sealed trait ConfigDocs extends AnyRef

    Permalink

    ConfigDocs holds the descriptions and details of a ConfigDescriptor which can be used to produce documentation.

    ConfigDocs holds the descriptions and details of a ConfigDescriptor which can be used to produce documentation.

    Definition Classes
    ConfigDocsModule
  6. trait ConfigDocsModule extends WriteModule

    Permalink
  7. trait ConfigModule extends ConfigDescriptorModule with ConfigSourceModule with ConfigDocsModule with ReadModule with WriteModule

    Permalink
  8. sealed trait ConfigSource extends AnyRef

    Permalink

    Every ConfigSource at the core is just a Reader, which is essentially a function that goes from PropertyTreePath to an actual PropertyTree.

    Every ConfigSource at the core is just a Reader, which is essentially a function that goes from PropertyTreePath to an actual PropertyTree. i.e, f: PropertyTreePath[String] => IO[ReadError[String], PropertyTree[String, String] Later on for each key represented as PropertyTreePath[String] internally, f is used to applied to get the value as a PropertyTree itself.

    Internal details:

    This function f can be retrieved under an ZManaged effect. This implies it may involve an IO with managing resources to even form this function. Example: In order to retrieve a property-tree corresponding to a key (PropertyTreePath), it requires a database connection in the very first instance.

    // pseudo-logic, doesn't compile

    val source: ConfigSource = ConfigSource.Reader( ZManaged(getDatabaseConnection) .flatMap(connection => (key: PropertyTreePath[String] => IO.effect(connection.getStatement.executeQuery(s"get key from table"))) )

    Note that ConfigSource has a generalised memoize function that allows you to memoize the effect required to form the function. In the context of the above example, with source.memoize we acquire only a single connection to retrieve the values for all the keys in your product/coproduct for an instance of read.

    Definition Classes
    ConfigSourceModule
  9. trait ConfigSourceModule extends KeyValueModule

    Permalink
  10. trait ConfigStringModule extends ConfigModule with ConfigSourceModule

    Permalink
  11. trait ImplicitTupleConversion extends AnyRef

    Permalink
  12. implicit final class Interpolator extends AnyVal

    Permalink
  13. trait InvariantZip[A, B] extends AnyRef

    Permalink
  14. trait InvariantZipLowPriority0 extends InvariantZipLowPriority1

    Permalink
  15. trait InvariantZipLowPriority1 extends AnyRef

    Permalink
  16. abstract type K

    Permalink
    Definition Classes
    KeyValueModule
  17. trait KeyValueModule extends AnyRef

    Permalink
  18. implicit class MapOps[A] extends AnyRef

    Permalink
  19. sealed trait PropertyTree[+K, +V] extends AnyRef

    Permalink
    Annotations
    @silent( "Unused import" )
  20. final case class PropertyTreePath[K](path: Vector[Step[K]]) extends Product with Serializable

    Permalink
  21. trait PropertyType[V, A] extends AnyRef

    Permalink
  22. trait PropertyTypePlatformSpecific extends AnyRef

    Permalink
  23. sealed trait ReadError[+A] extends Exception with NoStackTrace

    Permalink
  24. sealed case class Table(rows: List[TableRow]) extends Product with Serializable

    Permalink

    A Table is a recursive structure that is more easier to be interpreted as Json or Markdown than trying to convert ConfigDocs to a readable format.

    A Table is a recursive structure that is more easier to be interpreted as Json or Markdown than trying to convert ConfigDocs to a readable format.

    Definition Classes
    ConfigDocsModule
  25. trait TupleConversion[A, B] extends AnyRef

    Permalink
  26. abstract type V

    Permalink
    Definition Classes
    KeyValueModule

Value Members

  1. object BuildInfo extends Product with Serializable

    Permalink

    This object was generated by sbt-buildinfo.

  2. object ConfigDescriptor extends ConfigDescriptorFunctions

    Permalink
    Definition Classes
    ConfigStringModule
  3. object ConfigSource

    Permalink
    Definition Classes
    ConfigSourceModule
  4. object InvariantZip extends InvariantZipLowPriority0

    Permalink
  5. object PropertyTree

    Permalink
  6. object PropertyTreePath extends Serializable

    Permalink
    Annotations
    @silent( "Unused import" )
  7. object PropertyType extends PropertyTypePlatformSpecific

    Permalink
  8. object ReadError extends Serializable

    Permalink
  9. object Table extends Serializable

    Permalink
    Definition Classes
    ConfigDocsModule
  10. object TupleConversion

    Permalink
  11. object ZConfig

    Permalink

    Use functions in this Config object when you need to retrieve your instance of config in terms of zio.Layer.

    Use functions in this Config object when you need to retrieve your instance of config in terms of zio.Layer.

    For example:

    final case class MyConfig(dburl: String, port: Int)
    
    val myConfigDesc: ConfigDescriptor[MyConfig]             = (string("dburl") |@| int("port"))(MyConfig.apply, MyConfig.unapply)
    val myConfig: Layer[ReadError[String], Config[MyConfig]] = Config.fromSystemEnv(myConfigDesc)

    By using Config.fromSystemEnv(myConfigDesc), it internally extends your description which is myConfigDesc to include the ConfigSource. In the above example, it is the ConfigSource corresponding to sys.env. It then calls zio.config.read with this new description that includes the source information.

    Extending an existing config description to include a ConfigSource is as simple as

    myConfigDesc from configSource

    Also, note that Config[MyConfig] in the above example is a simple type alias to Has[MyConfig].

    If you want to retrieve your config as scala.Either instead of zio.Layer, then you will have to extend your description to include the information on ConfigSource manually.

    For example:

    import zio.config._, ConfigDescriptor._
    final case class MyConfig(dburl: String, port: Int)
    
    val myConfig: ConfigDescriptor[MyConfig]         = (string("dburl") |@| int("port"))(MyConfig.apply, MyConfig.unapply)
    val constantSource: ConfigSource                 = ConfigSource.fromMap(Map("dburl" -> "xyz", "port" -> "8080"))
    val result: Either[ReadError[String], MyConfig]  = read(myConfig from constantSource)

    Note: With the above approach, we got a simple scala.Either instead of retrieving them in terms of ZIO. Instead of the above approach, if we use Config.fromMap(constantMap, myConfig), then we will get a Layer[ReadError[String], MyConfig]

    The above approach is especially useful when we have a custom ConfigSource. For instance, we can form a custom ConfigSource by composing a few existing ConfigSources.

    For example:

    import zio.config._, ConfigDescriptor._
    
    final case class MyConfig(dburl: String, port: Int)
    
    val myConfig: ConfigDescriptor[MyConfig]     = (string("dburl") |@| int("port"))(MyConfig.apply, MyConfig.unapply)
    val sysEnvSource: UIO[MyConfig]              = ConfigSource.fromSystemEnv
    val constantSource: ConfigSource             = ConfigSource.fromMap(Map("dburl" -> "xyz", "port" -> "8080"))
    val result: IO[ReadError[String], MyConfig]  = configSource.flatMap(source => read(myConfig from sysEnvSource.orElse(constantSource))

    In the above example, the results returned an UIO because of the existence of ConfigSource corresponding to sys.env.

    Definition Classes
    ConfigStringModule
  12. def addPostFixToKey(string: String): (String) ⇒ String

    Permalink

    Add a post fix to an existing key

    Add a post fix to an existing key

    Definition Classes
    KeyConversionFunctions
  13. def addPrefixToKey(prefix: String): (String) ⇒ String

    Permalink

    Add a prefix to an existing key

    Add a prefix to an existing key

    Definition Classes
    KeyConversionFunctions
  14. implicit macro def autoTupleConversion[P <: Product, T]: TupleConversion[P, T]

    Permalink
    Definition Classes
    ImplicitTupleConversion
  15. def autoTupleConversion1[P, A](implicit ev: TupleConversion[P, (A)]): TupleConversion[P, A]

    Permalink
    Definition Classes
    ImplicitTupleConversion
  16. def camelToDelimiter(input: String, delimiter: String): String

    Permalink

    Convert camelCase to any delimited string.

    Convert camelCase to any delimited string. Example:

    camelToDelimiter("abcDef", "-") === abc-def
    Definition Classes
    KeyConversionFunctions
  17. final def configLayer[A](config: config.ConfigModule.ConfigDescriptor[A])(implicit tag: Tag[A]): ZLayer[config.ConfigModule.ConfigSource, ReadError[config.ConfigModule.K], A]

    Permalink

    Convert a ConfigDescriptor to a Layer, which further requires a ConfigSource as input.

    Convert a ConfigDescriptor to a Layer, which further requires a ConfigSource as input. Note: Use configLayer_ instead of configLayer if ConfigSource information is already embedded in the descriptor.

    Example usage:

    final case class MyConfig(age: Int)
    
    val appConfigLayer  =
       ConfigSource.fromMap(Map("age" -> "20")).toLayer >>> configLayer(int("age").to[MyConfig])
    
    val app: ZIO[MyConfig with zio.console.Console,java.io.IOException, Unit] =
      getConfig[MyConfig].flatMap(Console.printLine)
    
    app.provideSomeLayer[Console](appConfigLayer)
    // ZIO[zio.console.Console, Exception, Unit]

    This can also be simplified to

    val appConfigLayer  =
     configLayer_(int("age").to[MyConfig] from  ConfigSource.fromMap(Map("age" -> "20")))
    
    app.provideSomeLayer[Console](appConfigLayer)

    The preference depends on how you want to design the entry point to managing config of your app.

    Definition Classes
    ConfigModule
  18. final def configLayer_[A](config: config.ConfigModule.ConfigDescriptor[A])(implicit tag: Tag[A]): ZLayer[Any, ReadError[config.ConfigModule.K], A]

    Permalink

    Convert a ConfigDescriptor to a Layer.

    Convert a ConfigDescriptor to a Layer.

    Example usage:

    final case class MyConfig(age: Int, name: String)
    
    object MyConfig {
      val config =
        (int("age") zip string("name")).to[MyConfig] from ConfigSource.fromMap(Map("age" -> "20", "name" -> "afsal"))
    }
    
    val app: ZIO[Has[MyConfig] with zio.console.Console, java.io.IOException, Unit] =
      getConfig[MyConfig].flatMap(putStrLn)
    
    val io: ZIO[zio.console.Console, Exception, Unit] =
      app.provideSomeLayer[Console](configLayer_(MyConfig.config))
    
    println(zio.Runtime.default.unsafeRun(io))
    Definition Classes
    ConfigModule
  19. final def generateDocs[A](config: config.ConfigDocsModule.ConfigDescriptor[A]): ConfigDocs

    Permalink

    Generate documentation based on the ConfigDescriptor, where a ConfigDescriptor is a structure representing the logic to fetch the application config from various sources.

    Generate documentation based on the ConfigDescriptor, where a ConfigDescriptor is a structure representing the logic to fetch the application config from various sources.

    Once we generate the docs, this can be converted to a light weight Table structure which is much more easier to be converted to markdown or json formats.

    Example :

    val configDescriptor: ConfigDescriptor[MyAppConfig] = ???
    
    generatedDocs(configDescriptor).toTable.toGithubFlavouredMarkdown
    Definition Classes
    ConfigDocsModule
  20. def generateReport[A](config: config.ConfigDocsModule.ConfigDescriptor[A], value: A): Either[String, ConfigDocs]

    Permalink

    Generate a report based on the ConfigDescriptor and an A, where a ConfigDescriptor represents the logic to fetch the application config from various sources, and A represents the actual config value that was retrieved.

    Generate a report based on the ConfigDescriptor and an A, where a ConfigDescriptor represents the logic to fetch the application config from various sources, and A represents the actual config value that was retrieved.

    Definition Classes
    ConfigDocsModule
  21. final def getConfig[A](implicit tag: Tag[A]): ZIO[A, Nothing, A]

    Permalink

    Example usage:

    Example usage:

    A helper method allowing you to forget passing configs as arguments to all over the place in your app. Whereever, you need to access the config, simply call getConfig[MyConfig].flatMap(config => ???).

    PS: if you are familiar with Kleisli, this is similar to using Kleisi[IO, Config, A], except for the fact that it is Has[Config] instead of Config allowing you to mixin with other dependencies keeping your Monad the same

    import zio.console._
    
    final case class MyConfig(username: String, port: Int)
    
    val app: ZIO[Has[MyConfig] with Console, java.io.IOException, Unit] =
      for {
         config <- getConfig[MyConfig]
         _      <- putStrLn(config.toString)
      } yield ()
    
    val configDesc =
      (string("USERNAME") |@| int("PORT")).to[MyConfig] from ConfigSource.fromMap(Map())
    
    val main: ZIO[zio.console.Console, Exception, Unit] =
      app.provideSomeLayer[Console](configLayer_(configDesc))
    Definition Classes
    ConfigModule
  22. final def read[A](configuration: config.ReadModule.ConfigDescriptor[A]): IO[ReadError[config.ReadModule.K], A]

    Permalink
    Definition Classes
    ReadModule
  23. final def requiredZipAndOrFields[A](config: config.ReadModule.ConfigDescriptor[A]): Int

    Permalink
    Definition Classes
    ReadModule
  24. def sizeOfZipAndOrErrors(error: ReadError[config.ReadModule.K]): Int

    Permalink
    Definition Classes
    ReadModule
  25. package syntax

    Permalink
  26. val toKebabCase: (String) ⇒ String

    Permalink

    Convert a camelCase key to kebab-case val s = abcDef toKebabCase(s) === abc-def

    Convert a camelCase key to kebab-case val s = abcDef toKebabCase(s) === abc-def

    Definition Classes
    KeyConversionFunctions
  27. val toSnakeCase: (String) ⇒ String

    Permalink

    Convert a camelCase key to snake_case

    Convert a camelCase key to snake_case

    Definition Classes
    KeyConversionFunctions
  28. final def write[A](config: config.WriteModule.ConfigDescriptor[A], a: A): Either[String, PropertyTree[config.WriteModule.K, config.WriteModule.V]]

    Permalink
    Definition Classes
    WriteModule

Inherited from ImplicitTupleConversion

Inherited from ConfigStringModule

Inherited from ConfigModule

Inherited from ReadModule

Inherited from ConfigDocsModule

Inherited from WriteModule

Inherited from ConfigDescriptorModule

Inherited from ConfigSourceModule

Inherited from KeyValueModule

Inherited from KeyConversionFunctions

Inherited from AnyRef

Inherited from Any

Ungrouped