ciallo-config

    Layered configuration (Defaults -> TOML/JSON -> Env -> Workers Binding), SchemaNode Fail-Fast validation, and Secret[T] redaction for unmbt/ciallo

    config
    toml
    secret
    schema
    ciallo
    Download zip
    Author
    Version
    0.1.1
    License
    MIT
    Last updated
    13 hours ago
    Downloads
    10

    #unmbt/ciallo-config

    Layered configuration loader (Defaults -> TOML -> JSON -> Env -> Workers Binding) with SchemaNode Fail-Fast startup validation and Secret[T] leak protection across all 4 MoonBit targets.

    ConfigError

    pub(all) suberror ConfigError {
    ParseError(source~ : String, message~ : String)
    ValidationFailed(issues~ : Array[
    ValidationIssue
    ])
    DecodeFailed(String)
    } derive(Eq,
    Debug
    )

    ConfigLoader

    pub struct ConfigLoader {
    layers : Array[
    Json
    ]
    }

    Layered configuration loader: Defaults -> TOML -> JSON -> Env -> Workers Binding.

    ConfigLoader::ConfigLoader

    fn ConfigLoader::ConfigLoader() -> ConfigLoader

    ConfigLoader::load_as

    Fail-Fast loads, validates against T::schema_node, and decodes typed config T.

    ConfigLoader::load_json

    Coerces environment strings according to schema and Fail-Fast validates.

    ConfigLoader::merged_raw

    ConfigLoader::with_binding_json

    fn ConfigLoader::with_binding_json(self : ConfigLoader, binding :
    Json
    ) -> ConfigLoader

    Adds Cloudflare Workers / runtime binding JSON as the highest-precedence layer.

    ConfigLoader::with_defaults

    ConfigLoader::with_env_lookup

    fn ConfigLoader::with_env_lookup(self : ConfigLoader, keys : Array[String], lookup : (StringView) -> String?, prefix? : String) -> ConfigLoader

    Reads selected keys via any lookup function (e.g. k => env.get_var(k)).

    ConfigLoader::with_env_vars

    fn ConfigLoader::with_env_vars(self : ConfigLoader, vars : Map[String, String], prefix? : String) -> ConfigLoader

    Adds environment variables as a layer. Keys matching prefix (e.g. "APP_") are stripped, lowercased, and split on "__" into nested objects (e.g. APP_DB__PORT=5432 -> { "db": { "port": "5432" } }).

    ConfigLoader::with_json

    fn ConfigLoader::with_json(self : ConfigLoader, json_text : StringView) -> ConfigLoader raise ConfigError

    ConfigLoader::with_toml

    fn ConfigLoader::with_toml(self : ConfigLoader, toml_text : StringView) -> ConfigLoader raise ConfigError

    Secret

    pub struct Secret[T] {
    value : T
    }

    Opaque secret wrapper that ALWAYS redacts itself in Show, Debug, and ToJson. Call .expose() explicitly at the point of use.
    impl Eq for Secret[String]
    impl Show for Secret[T]
    impl Debug for Secret[T]
    impl ToJson for Secret[T]
    impl Schema for Secret[T]

    Secret::Secret

    fn[T] Secret::Secret(value : T) -> Secret[T]

    Secret::expose

    fn[T] Secret::expose(self : Secret[T]) -> T

    Secret::to_json

    fn[T] Secret::to_json(_self : Secret[T]) ->
    Json

    Secret::to_string

    fn[T] Secret::to_string(_self : Secret[T]) -> String

    parse_toml

    fn parse_toml(input : StringView) ->
    Json
    raise ConfigError

    Pure MoonBit TOML subset parser (tables, dotted keys, strings, numbers, bools, arrays).

    redact_config_json

    fn redact_config_json(json :
    Json
    , extra_sensitive_keys? : Array[String]) ->
    Json

    Produces a redacted JSON config snapshot safe for /_debug/config diagnostics.