hocon

    HOCON 配置迁移差异检查与 MoonBit 解析

    Download zip
    Author
    Version
    0.24.1
    License
    MIT
    Last updated
    5 hours ago
    Downloads
    4

    #可执行 API 示例

    增加必需字段的 String/Int/Bool 类型读取和类型错误。这些例子调用公开 API,并随 moon test 执行。

    ///|
    test "typed configuration access reports missing and invalid values" {
    let v = @hocon.parse("port=8080\nenabled=true\nhost=localhost")
    assert_eq(@hocon.get_int(v, "port"), 8080)
    assert_true(@hocon.get_bool(v, "enabled"))
    assert_eq(@hocon.get_string(v, "host"), "localhost")
    assert_true(
    try {
    ignore(@hocon.get_int(v, "host"))
    false
    } catch {
    _ => true
    },
    )
    assert_true(
    try {
    ignore(@hocon.get_bool(v, "missing"))
    false
    } catch {
    _ => true
    },
    )
    }

    0.6 已增加 Node HTTP(S)/异步读取、对象根约束与 JSON 严格成员检查;八种类型化列表和 config/config-list 保持可用。历史自引用、来源加载、回退/环境和单位访问器保持可用。尚未完整兼容 Lightbend Config,差距见 FEATURES.md。

    ParseError

    pub suberror ParseError {
    Invalid(String)
    Located(String, SourcePosition)
    } derive(
    Debug
    )

    ValidationError

    pub suberror ValidationError {
    ValidationFailed(Array[ValidationProblem])
    } derive(
    Debug
    )

    ConfigChange

    pub(all) struct ConfigChange {
    path : Array[String]
    kind : String
    before_type : String?
    after_type : String?
    } derive(Eq, ToJson,
    Debug
    )

    A value-free description of a change between two resolved configurations. path contains literal object keys, so a key containing a period is not confused with a nested path. Lists are compared as one value.

    ConfigChange::equal

    ConfigChange::not_equal

    fn ConfigChange::not_equal(x : ConfigChange, y : ConfigChange) -> Bool

    ConfigChange::to_json

    ConfigNumber

    pub(all) enum ConfigNumber {
    Integer(Int)
    Long(Int64)
    Floating(Double)
    } derive(Eq,
    Debug
    )

    Preserve the Number subtype returned by the pinned reference implementation.

    ConfigNumber::equal

    ConfigNumber::not_equal

    fn ConfigNumber::not_equal(x : ConfigNumber, y : ConfigNumber) -> Bool

    ConfigNumber::to_json

    fn ConfigNumber::to_json(self : ConfigNumber) -> Json

    ConfigPeriod

    pub(all) struct ConfigPeriod {
    years : Int
    months : Int
    days : Int
    } derive(Eq, ToJson,
    Debug
    )

    ConfigPeriod::equal

    ConfigPeriod::not_equal

    fn ConfigPeriod::not_equal(x : ConfigPeriod, y : ConfigPeriod) -> Bool

    ConfigPeriod::to_json

    DurationUnit

    pub(all) enum DurationUnit {
    Nanoseconds
    Microseconds
    Milliseconds
    Seconds
    Minutes
    Hours
    Days
    } derive(Eq,
    Debug
    )

    DurationUnit::equal

    DurationUnit::not_equal

    fn DurationUnit::not_equal(x : DurationUnit, y : DurationUnit) -> Bool

    IncludeRequest

    pub(all) struct IncludeRequest {
    name : String
    kind : String
    from : String
    required : Bool
    } derive(Eq, ToJson,
    Debug
    )

    IncludeRequest::equal

    IncludeRequest::not_equal

    fn IncludeRequest::not_equal(x : IncludeRequest, y : IncludeRequest) -> Bool

    IncludeRequest::to_json

    IncludeSource

    pub(all) struct IncludeSource {
    name : String
    content : String
    format : String
    } derive(Eq,
    Debug
    )

    IncludeSource::equal

    IncludeSource::not_equal

    fn IncludeSource::not_equal(x : IncludeSource, y : IncludeSource) -> Bool

    SourcePosition

    pub(all) struct SourcePosition {
    source : String
    offset : Int
    line : Int
    column : Int
    } derive(Eq, ToJson,
    Debug
    )

    SourcePosition::equal

    SourcePosition::not_equal

    fn SourcePosition::not_equal(x : SourcePosition, y : SourcePosition) -> Bool

    SourcePosition::to_json

    TemporalAmount

    pub(all) enum TemporalAmount {
    Duration(Int64)
    Period(ConfigPeriod)
    } derive(Eq,
    Debug
    )

    TemporalAmount::equal

    TemporalAmount::not_equal

    fn TemporalAmount::not_equal(x : TemporalAmount, y : TemporalAmount) -> Bool

    TemporalAmount::to_json

    fn TemporalAmount::to_json(self : TemporalAmount) -> Json

    ValidationProblem

    pub(all) struct ValidationProblem {
    path : String
    kind : String
    expected : String
    actual : String
    } derive(Eq, ToJson,
    Debug
    )

    ValidationProblem::equal

    ValidationProblem::not_equal

    fn ValidationProblem::not_equal(x : ValidationProblem, y : ValidationProblem) -> Bool

    ValidationProblem::to_json

    Value

    pub(all) enum Value {
    Text(String)
    Bare(String)
    Number(String)
    Boolean(Bool)
    Null
    List(Array[Value])
    Reference(String)
    PathReference(Array[String], Bool)
    Object(Map[String, Value])
    SealedObject(Map[String, Value])
    Concat(Array[(String, Value)])
    DelayedMerge(Value, Value)
    Bound(Array[String], Int, Value)
    Substitution(Array[Array[String]], Bool, Bool, Int)
    } derive(Eq,
    Debug
    )

    Value::equal

    fn Value::equal(Value, Value) -> Bool

    Value::not_equal

    fn Value::not_equal(x : Value, y : Value) -> Bool

    Value::to_json_string

    fn Value::to_json_string(self : Value) -> String raise ParseError

    Stable JSON rendering of a resolved value; number spelling is retained.

    Value::to_repr

    at_key

    fn at_key(value : Value, key : String) -> Value raise ParseError

    at_path

    fn at_path(value : Value, path : String) -> Value raise ParseError

    check_valid

    fn check_valid(config : Value, reference : Value, paths? : Array[String]) -> Unit raise

    copy_value

    fn copy_value(value : Value) -> Value raise ParseError

    Return a detached tree; mutable maps/arrays are not shared with the input.

    diff_resolved_configs

    fn diff_resolved_configs(before : Value, after : Value) -> Array[ConfigChange] raise ParseError

    Compare two already resolved HOCON object roots without disclosing values. Additions and removals are reported at their nearest object key; lists are atomic. The caller decides whether each change is allowed for its migration. Rejects unresolved values and bounds work, nesting, paths and report size.

    entry_set

    fn entry_set(config : Value) -> Map[String, Value] raise ParseError

    Flatten non-object, non-null leaves. Lists remain leaf values.

    get

    fn get(config : Value, key : String) -> Value?

    get_any_ref

    fn get_any_ref(config : Value, key : String) -> Value raise ParseError

    get_any_ref_list

    fn get_any_ref_list(config : Value, key : String) -> Array[Value] raise ParseError

    get_as_bool

    fn get_as_bool(config : Value, key : String) -> Bool raise ParseError

    get_as_int

    fn get_as_int(config : Value, key : String) -> Int raise ParseError

    get_as_list

    fn get_as_list(config : Value, key : String) -> Array[Value] raise ParseError

    get_as_string

    fn get_as_string(config : Value, key : String) -> String raise ParseError

    HOCON's recommended conversions, separate from the original strict getters.

    get_bool

    fn get_bool(config : Value, key : String) -> Bool raise ParseError

    get_bool_list

    fn get_bool_list(config : Value, key : String) -> Array[Bool] raise ParseError

    get_bytes

    fn get_bytes(config : Value, key : String) -> Int64 raise ParseError

    get_bytes_list

    fn get_bytes_list(config : Value, key : String) -> Array[Int64] raise ParseError

    get_config

    fn get_config(config : Value, key : String) -> Value raise ParseError

    get_config_list

    fn get_config_list(config : Value, key : String) -> Array[Value] raise ParseError

    get_double

    fn get_double(config : Value, key : String) -> Double raise ParseError

    get_double_list

    fn get_double_list(config : Value, key : String) -> Array[Double] raise ParseError

    get_duration

    fn get_duration(config : Value, key : String) -> Int64 raise ParseError

    Duration in nanoseconds; unitless values use milliseconds.

    get_duration_in

    fn get_duration_in(config : Value, key : String, unit : DurationUnit) -> Int64 raise ParseError

    get_duration_list

    fn get_duration_list(config : Value, key : String) -> Array[Int64] raise ParseError

    get_duration_list_in

    fn get_duration_list_in(config : Value, key : String, unit : DurationUnit) -> Array[Int64] raise ParseError

    get_enum

    fn[T] get_enum(config : Value, key : String, choices : Map[String, T]) -> T raise ParseError

    Match exact case-sensitive enum names; values may be a caller-defined enum.

    get_enum_list

    fn[T] get_enum_list(config : Value, key : String, choices : Map[String, T]) -> Array[T] raise ParseError

    get_int

    fn get_int(config : Value, key : String) -> Int raise ParseError

    get_int_list

    fn get_int_list(config : Value, key : String) -> Array[Int] raise ParseError

    get_is_null

    fn get_is_null(config : Value, key : String) -> Bool raise ParseError

    get_list

    fn get_list(config : Value, key : String) -> Array[Value] raise ParseError

    get_long

    fn get_long(config : Value, key : String) -> Int64 raise ParseError

    get_long_list

    fn get_long_list(config : Value, key : String) -> Array[Int64] raise ParseError

    get_memory_size

    fn get_memory_size(config : Value, key : String) -> String raise ParseError

    Exact nonnegative byte count, including units larger than int64.

    get_memory_size_list

    fn get_memory_size_list(config : Value, key : String) -> Array[String] raise ParseError

    get_milliseconds

    fn get_milliseconds(config : Value, key : String) -> Int64 raise ParseError

    get_milliseconds_list

    fn get_milliseconds_list(config : Value, key : String) -> Array[Int64] raise ParseError

    get_nanoseconds

    fn get_nanoseconds(config : Value, key : String) -> Int64 raise ParseError

    get_nanoseconds_list

    fn get_nanoseconds_list(config : Value, key : String) -> Array[Int64] raise ParseError

    get_number

    fn get_number(config : Value, key : String) -> ConfigNumber raise ParseError

    get_number_list

    fn get_number_list(config : Value, key : String) -> Array[ConfigNumber] raise ParseError

    get_object

    fn get_object(config : Value, key : String) -> Map[String, Value] raise ParseError

    get_object_list

    fn get_object_list(config : Value, key : String) -> Array[Map[String, Value]] raise ParseError

    get_path

    fn get_path(config : Value, keys : Array[String]) -> Value?

    get_period

    fn get_period(config : Value, key : String) -> ConfigPeriod raise ParseError

    Calendar period; unitless values are days and months remain unnormalized.

    get_string

    fn get_string(config : Value, key : String) -> String raise ParseError

    Required typed lookup. Text values remain text; numeric-looking strings are not coerced.

    get_string_list

    fn get_string_list(config : Value, key : String) -> Array[String] raise ParseError

    get_temporal

    fn get_temporal(config : Value, key : String) -> TemporalAmount raise ParseError

    Duration takes precedence: unitless values are milliseconds and m is minutes.

    get_value

    fn get_value(config : Value, path : String) -> Value raise ParseError

    has_path

    fn has_path(config : Value, key : String, include_null? : Bool) -> Bool

    has_path_or_null

    fn has_path_or_null(config : Value, path : String) -> Bool raise ParseError

    is_empty

    fn is_empty(config : Value) -> Bool raise ParseError

    is_resolved

    fn is_resolved(config : Value) -> Bool raise ParseError

    join_path

    fn join_path(parts : Array[String]) -> String raise ParseError

    Canonical path expression. A literal key can always be expressed by quoting it.

    list_get

    fn list_get(value : Value, index : Int) -> Value raise ParseError

    list_index_of

    fn list_index_of(value : Value, needle : Value, last? : Bool) -> Int raise ParseError

    Read-only search; equality is needle.equals(element), including error order.

    object_contains_value

    fn object_contains_value(value : Value, needle : Value) -> Bool raise ParseError

    object_get

    fn object_get(value : Value, key : String) -> Value? raise ParseError

    Literal map lookup; None means missing, Some(Null) is a present null value.

    object_keys

    fn object_keys(value : Value) -> Array[String] raise ParseError

    parse

    fn parse(source : String, includes? : Map[String, String], loader? : (IncludeRequest) -> Result[Array[IncludeSource], String]?, source_name? : String, fallbacks? : Array[String], environment? : Map[String, String]) -> Value raise ParseError

    parse_sources

    fn parse_sources(source : IncludeSource, includes? : Map[String, String], loader? : (IncludeRequest) -> Result[Array[IncludeSource], String]?, fallbacks? : Array[IncludeSource], environment? : Map[String, String], object_only? : Bool) -> Value raise ParseError

    Load ordered sources with explicit origins and a synchronous include host.

    parse_sources_unresolved

    fn parse_sources_unresolved(source : IncludeSource, includes? : Map[String, String], loader? : (IncludeRequest) -> Result[Array[IncludeSource], String]?, fallbacks? : Array[IncludeSource], object_only? : Bool) -> Value raise ParseError

    Parse and merge sources without resolving substitutions.

    parse_unresolved

    fn parse_unresolved(source : String, includes? : Map[String, String], loader? : (IncludeRequest) -> Result[Array[IncludeSource], String]?, source_name? : String, fallbacks? : Array[String]) -> Value raise ParseError

    render_value

    fn render_value(value : Value, json? : Bool, formatted? : Bool) -> String raise ParseError

    Render resolved or unresolved values with comments and origin annotations omitted. JSON mode can contain substitutions or repeated unresolved fields; it is valid JSON only for resolved finite values.

    resolve

    fn resolve(config : Value, environment? : Map[String, String], allow_unresolved? : Bool) -> Value raise ParseError

    Resolve a detached document; missing mandatory references may remain deferred.

    resolve_with

    fn resolve_with(config : Value, source : Value, environment? : Map[String, String], allow_unresolved? : Bool) -> Value raise ParseError

    Only the supplied source is searched for substitutions; source fields are not merged.

    split_path

    fn split_path(text : String) -> Array[String] raise ParseError

    Parse HOCON path expressions, including quoted periods and empty components.

    validation_problems

    fn validation_problems(config : Value, reference : Value, paths? : Array[String]) -> Array[ValidationProblem] raise ParseError

    Collect all missing/type problems, retaining duplicate restricted paths. Like checkValid, this is a structural check, not application-level validation.

    value_equals

    fn value_equals(a : Value, b : Value) -> Bool raise ParseError

    value_hash

    fn value_hash(value : Value) -> Int raise ParseError

    value_size

    fn value_size(value : Value) -> Int raise ParseError

    value_type

    fn value_type(value : Value) -> String raise ParseError

    The type is known for a delayed object even when its members are unresolved.

    value_unwrapped

    fn value_unwrapped(value : Value) -> Value raise ParseError

    Return detached data, rejecting unresolved children at any depth.

    value_with_fallback

    fn value_with_fallback(value : Value, fallback : Value) -> Value raise ParseError

    Merge arbitrary values, preserving scalar fallback barriers and raw history. Both inputs and the result own independent mutable maps and arrays.

    with_fallback

    fn with_fallback(config : Value, fallback : Value) -> Value raise ParseError

    with_key_value

    fn with_key_value(config : Value, key : String, value : Value) -> Value raise ParseError

    with_only_key

    fn with_only_key(config : Value, key : String) -> Value raise ParseError

    with_only_path

    fn with_only_path(config : Value, path : String) -> Value raise ParseError

    with_value

    fn with_value(config : Value, path : String, value : Value) -> Value raise ParseError

    without_key

    fn without_key(config : Value, key : String) -> Value raise ParseError

    without_path

    fn without_path(config : Value, path : String) -> Value raise ParseError