Package-level declarations

Loading, results, errors, sources and the global holder.

Types

Link copied to clipboard
sealed class ConfigError

Why a key failed to load. The subclasses are plain classes rather than data classes, so fields can be added later without breaking callers; they still compare by value.

Link copied to clipboard

Thrown by ConfigResult.getOrThrow and the generated Konstant.init<Spec> functions. The message lists every error, one per line:

Link copied to clipboard

Reads config values from a list of sources. The KSP processor adds a load<Spec>() extension for each @ConfigSpec class, which returns a ConfigResult:

Link copied to clipboard
Link copied to clipboard
class ConfigReport<out T>(val result: ConfigResult<T>, val entries: List<ConfigReport.Entry>)

The outcome of ConfigLoader.explain: the load result plus, for each field in load order, its key, the value used and where it came from. toString renders a table.

Link copied to clipboard
sealed class ConfigResult<out T>

The outcome of loading a config: Success with the value, or Failure with every error found. Loading does not stop at the first bad key, so all problems are reported at once.

Link copied to clipboard
interface ConfigSource

A place config values are read from, such as environment variables or a file. For each field, ConfigLoader builds the key in keyFormat, then in each of fallbackKeyFormats, and asks get for each until one returns a value, before moving on to the next source.

Link copied to clipboard
object Converters

String-to-value converters used by generated loaders. Every converter throws IllegalArgumentException (or a subclass) on invalid input, which the loader turns into ConfigError.ConversionFailed.

Link copied to clipboard
class FieldDescriptor<T>(val propertyName: String, val typeName: String, val secret: Boolean, val default: T?, val hasDefault: Boolean, val customKey: String? = null, val convert: (String) -> T, val convertChildren: (Map<String, String>) -> T? = null, val validate: (T) -> String?? = null)

Describes one config field for ConfigLoader.resolve. Built by generated code.

Link copied to clipboard
@RequiresOptIn(message = "This is used by Konstant's generated code and may change without notice.", level = RequiresOptIn.Level.ERROR)
annotation class InternalKonstantApi

Marks declarations that exist for code generated by the Konstant KSP processor. They may change in any release without notice, so do not use them directly. Generated files opt in.

Link copied to clipboard

How a field's property name becomes a lookup key in a ConfigSource. The examples are for the field maxPoolSize inside a nested spec held in a property named database.

Link copied to clipboard
object KeyUtils

Builds lookup keys from property names for ConfigLoader.resolve and generated code.

Link copied to clipboard
object Konstant

Global access to the loaded config. Load it once at startup with the generated init<Spec> function, then read any spec, root or nested, from anywhere:

Link copied to clipboard
abstract class MapBackedSource(entries: Map<String, String>, origin: String? = null) : ConfigSource

Base ConfigSource backed by an in-memory map with case-insensitive fallback lookup. origin, such as a file path, is added to name so reports tell sources of one type apart: TomlSource(config/app.dev.toml).

Link copied to clipboard
sealed class ResolveResult<out T>

The outcome of resolving one field. Used by generated code.

Link copied to clipboard

Collects sources inside ConfigLoaderBuilder.sources, in the order they are added.

Link copied to clipboard
object Validators

Checks used by generated loaders for the validation annotations. Each returns an error message, or null when the value is valid.

Link copied to clipboard
fun interface ValueConverter<out T>

Custom conversion for a field annotated with @Convert(MyConverter::class). Implement it as an object. Throw IllegalArgumentException for invalid input; the message becomes the error's cause.

Functions

Link copied to clipboard
inline fun <T : Any, V> configField(noinline selector: (T) -> V): ReadOnlyProperty<Any?, V>

Property delegate that lazily extracts a field from a registered config.

fun <T : Any, V> configField(type: KClass<T>, selector: (T) -> V): ReadOnlyProperty<Any?, V>

configField for when the config type is only known as a KClass.

Link copied to clipboard
fun <T, V> T.field(selector: (T) -> V): ReadOnlyProperty<Any?, V>

Property delegate backed by a specific config instance (not the global registry).