moonrockz/moon-lander/config
Types
BindFailure
pub(all) struct BindFailure {
at : Array[Located]
detail : String
} derive(Eq, @moonbitlang/core/debug.Debug)A binding failure: the decoder or validation detail and the paths that it
names. at holds one or more paths and is never empty.
BindFailure::equal
fn BindFailure::equal(BindFailure, BindFailure) -> BoolBindFailure::not_equal
fn BindFailure::not_equal(x : BindFailure, y : BindFailure) -> BoolBindFailure::to_repr
fn BindFailure::to_repr(BindFailure) -> @moonbitlang/core/debug.ReprBlame
pub(all) enum Blame {
Set(Array[Origin])
Table(Array[Origin])
Default
Unset
} derive(Eq, @moonbitlang/core/debug.Debug)The sources to blame for a value that failed to decode.
Blame::equal
fn Blame::equal(Blame, Blame) -> BoolBlame::not_equal
fn Blame::not_equal(x : Blame, y : Blame) -> BoolBlame::to_repr
fn Blame::to_repr(Blame) -> @moonbitlang/core/debug.ReprConfig
pub struct Config {
// private fields
}A merged configuration with the reports of its sources. Its root is always a struct.
Config::bind
fn[T : @moonbitlang/core/json.FromJson] Config::bind(self : Config, key : String) -> T raise ConfigErrorDecode the section at key into a T, as bind does.
Config::bind_or
fn[T : @moonbitlang/core/json.FromJson + ToJson] Config::bind_or(self : Config, key : String, default : T, unknown? : UnknownKeys) -> T raise ConfigErrorDecode the section at key merged over default, as bind_or does.
Config::get
fn Config::get(self : Config, key : KeyPath) -> ConfigValue?The value at key, or None when no value is there.
Config::origins
fn Config::origins(self : Config, key : KeyPath) -> Array[Origin]The origins of the leaf at key: one origin for a replaced leaf or list.
A struct has no origin of its own, so a struct or a missing key gives an
empty array.
Config::provenance
fn Config::provenance(self : Config) -> Array[(KeyPath, Array[Origin])]The origins of every leaf, in tree order. Each array is not empty.
Config::reports
fn Config::reports(self : Config) -> Array[SourceReport]The source reports in merge order.
Config::secret
fn[R : SecretResolver] Config::secret(self : Config, key : String, resolver : R) -> Secret raise SecretErrorResolve the secret at key. A plain string is a literal secret and does not
call the resolver. A secret reference calls resolver with the leaf origin.
Config::value
fn Config::value(self : Config) -> ConfigValueThe merged value tree.
Config::warnings
fn Config::warnings(self : Config) -> Array[ConfigWarning]The warnings of the load: the warnings of the source providers, then the warnings of each source report in merge order.
ConfigBuilder
pub struct ConfigBuilder {
// private fields
}An immutable list of sources and source providers in merge order, the registered formats, and the explicit inputs of one run: the variable set, the working directory, and the platform. Each function returns a new builder.
ConfigBuilder::formats
fn ConfigBuilder::formats(self : ConfigBuilder) -> Array[Format]The registered formats in registration order.
ConfigBuilder::given_env_vars
fn ConfigBuilder::given_env_vars(self : ConfigBuilder) -> Map[String, String]?The variable set that the builder holds, or None when nobody gave one. A
host reads the process variables only when this is None.
ConfigBuilder::given_platform
fn ConfigBuilder::given_platform(self : ConfigBuilder) -> Platform?The platform that the builder holds, or None when nobody gave one.
ConfigBuilder::given_working_dir
fn ConfigBuilder::given_working_dir(self : ConfigBuilder) -> String?The working directory that the builder holds, or None when nobody gave one.
ConfigNode
pub struct ConfigNode {
// private fields
}One value of the configuration tree for exact decoding: its decode path, the value or its absence, and the sources to blame. A node in a list has a decode path with an index suffix and the blame of the list.
ConfigNode::blame
fn ConfigNode::blame(self : ConfigNode) -> BlameThe sources to blame for the value of the node.
ConfigNode::child
fn ConfigNode::child(self : ConfigNode, name : String) -> ConfigNodeThe node of the field name. The node has no value when this node is not a
table or has no such field.
ConfigNode::children
fn ConfigNode::children(self : ConfigNode) -> Array[(String, ConfigNode)]The fields of a table, with their nodes, in configuration order. A node that is not a table has no fields.
ConfigNode::fail
fn[T] ConfigNode::fail(self : ConfigNode, detail : String) -> T raise ConfigErrorRaise Decode at the node with detail and the blame of the node. Use it
for a rule that a FromConfig implementation checks while it decodes.
ConfigNode::get
fn[T : FromConfig] ConfigNode::get(self : ConfigNode, name : String) -> T raise ConfigErrorDecode the field name exactly.
ConfigNode::items
fn ConfigNode::items(self : ConfigNode) -> Array[ConfigNode]The items of a list, in order. Each item node has the index in its decode path and the blame of the list. A node that is not a list has no items.
ConfigNode::json
fn[T : @moonbitlang/core/json.FromJson] ConfigNode::json(self : ConfigNode) -> T raise ConfigErrorDecode the node with FromJson, with the same error translation as bind:
a failure names the full decode path from the bound section. A node with no
value decodes as null. A secret reference in the node raises Decode.
ConfigNode::path
fn ConfigNode::path(self : ConfigNode) -> DecodePathThe decode path of the node.
ConfigNode::value
fn ConfigNode::value(self : ConfigNode) -> ConfigValue?The value of the node, or None when no source sets it.
ConfigSource
pub struct ConfigSource {
// private fields
}An immutable configuration source: a kind, a display name, an optional display priority, the list merge policy, key-path policies, the input, and the key paths to exclude.
ConfigSource::candidates
fn ConfigSource::candidates(paths : Array[String], display~ : String, role? : FileRole, name? : String, priority? : Int) -> ConfigSourceA file source over an explicit list of candidate files at one location.
No existing candidate gives the status NotFound, one loads it, and more
than one raises Ambiguous with display. A candidate exists when the
listing of its directory holds its exact name as a file. The name is
display when no name is given.
ConfigSource::defaults
fn ConfigSource::defaults(json : Json, name? : String, priority? : Int) -> ConfigSource raise ConfigErrorA defaults source from a JSON value, for example Defaults::default().to_json().
The root must be an object.
ConfigSource::defaults_value
fn ConfigSource::defaults_value(value : ConfigValue, name? : String, priority? : Int) -> ConfigSource raise ConfigErrorA defaults source from a value tree. The root must be a struct.
ConfigSource::env
fn ConfigSource::env(prefix~ : String, reserved? : Array[String], selection? : SourceSelection[Map[String, String]], name? : String, priority? : Int) -> ConfigSourceAn environment variable source. A variable counts when its name, in upper
case, starts with prefix and _ and is not in reserved (compared in
upper case). After the prefix, leading _ characters go, __ separates
names, and each name is written in lower case: ACME_SERVER__PORT sets
server.port. An empty name raises InvalidEnvKey.
Discover reads the variable set of the builder, and reports NotFound
when the builder holds none. Explicit(vars) reads only vars. Skip
loads nothing. Each value gets a type: true or false in any case is a
Boolean, an optional sign and digits that fit Int64 are an integer, JSON
text that starts with [ or { is a list or a struct, and other text is a
string. The origin of each value names its variable.
ConfigSource::exclude
fn ConfigSource::exclude(self : ConfigSource, paths : Array[KeyPath], warn~ : Bool) -> ConfigSourceA new source that removes the subtrees at paths after the parse and
before the merge. When warn is true, each removed key that the source held
adds a KeyRemoved warning to its report.
ConfigSource::file
fn ConfigSource::file(path : String, role? : FileRole, name? : String, priority? : Int) -> ConfigSourceA file source at an explicit path. A relative path joins the working
directory of the builder. The extension selects the registered format. The
load raises FileNotFound when the file does not exist. The name is the
path when no name is given.
ConfigSource::kind
fn ConfigSource::kind(self : ConfigSource) -> SourceKindThe kind of the source.
ConfigSource::name
fn ConfigSource::name(self : ConfigSource) -> StringThe display name of the source.
ConfigSource::overrides
fn ConfigSource::overrides(pairs : Array[(String, ConfigValue)], name? : String, priority? : Int) -> ConfigSource raise ConfigErrorAn overrides source from key-path pairs, for example command-line values.
It has the kind Overrides and the default priority 700.
ConfigSource::overrides_value
fn ConfigSource::overrides_value(value : ConfigValue, name? : String, priority? : Int) -> ConfigSource raise ConfigErrorAn overrides source from a value tree. The root must be a struct.
ConfigSource::parsed_file
fn ConfigSource::parsed_file(path : String, value : ConfigValue, role? : FileRole, name? : String, priority? : Int) -> ConfigSource raise ConfigErrorA file source whose text the caller already read and turned into a value
tree, for example a legacy file with its own format. The report and the
origins show path, which joins the working directory when it is relative.
The root must be a struct.
ConfigSource::skipped
fn ConfigSource::skipped(kind : SourceKind, name? : String, priority? : Int) -> ConfigSourceA source that loads nothing and reports the status Skipped. The name is
the report name of kind when no name is given.
ConfigSource::with_key_policy
fn ConfigSource::with_key_policy(self : ConfigSource, key : KeyPath, policy : MergePolicy) -> ConfigSourceA new source with the list merge policy policy at key. A key-path
policy beats the source policy.
ConfigSource::with_policy
fn ConfigSource::with_policy(self : ConfigSource, policy : MergePolicy) -> ConfigSourceA new source with the list merge policy policy for every list that has no
key-path policy.
ConfigValue
pub struct ConfigValue {
// private fields
} derive(@moonbitlang/core/debug.Debug)An immutable configuration value over an Ion value. Every format and source gives values of this one type before the merge.
ConfigValue::equal
fn ConfigValue::equal(self : ConfigValue, other : ConfigValue) -> BoolConfigValue::from_ion
fn ConfigValue::from_ion(ion : @moonrockz/ion/ion.Ion, origin? : String) -> ConfigValue raise ConfigErrorA source tree from an Ion value. The root must be a struct, else this
raises InvalidRoot with origin. A struct field name with no text, such
as an unresolved symbol ID, raises Parse for the Ion format. Two fields
with the same name in one struct raise DuplicateKey. The key path of a
field in a list item holds the struct field names only, because a key path
does not select list items.
ConfigValue::from_json
fn ConfigValue::from_json(json : Json, origin? : String) -> ConfigValue raise ConfigErrorA source tree from a JSON value, through its Ion form. The rules of
ConfigValue::from_ion apply.
ConfigValue::not_equal
fn ConfigValue::not_equal(x : ConfigValue, y : ConfigValue) -> BoolConfigValue::to_ion
fn ConfigValue::to_ion(self : ConfigValue) -> @moonrockz/ion/ion.IonThe Ion value.
ConfigValue::to_repr
fn ConfigValue::to_repr(ConfigValue) -> @moonbitlang/core/debug.ReprConfigValue::type_name
fn ConfigValue::type_name(self : ConfigValue) -> StringThe Ion type name in lowercase, for example struct or list.
impl Eq for ConfigValue
Eq::equal
fn equal(self : ConfigValue, other : ConfigValue) -> BoolEquality of the Ion data model. Struct fields compare as an unordered set.
ConfigWarning
pub(all) enum ConfigWarning {
KeyRemoved(KeyPath, Origin)
Note(source~ : String, message~ : String)
} derive(Eq, @moonbitlang/core/debug.Debug)A warning of a load.
ConfigWarning::equal
fn ConfigWarning::equal(ConfigWarning, ConfigWarning) -> BoolConfigWarning::not_equal
fn ConfigWarning::not_equal(x : ConfigWarning, y : ConfigWarning) -> BoolConfigWarning::to_repr
fn ConfigWarning::to_repr(ConfigWarning) -> @moonbitlang/core/debug.ReprDecodePath
pub(all) struct DecodePath {
key : KeyPath?
suffix : Array[DecodeStep]
} derive(Eq, @moonbitlang/core/debug.Debug)The path of a value that failed to decode. key holds the leading names up
to the first list index, and None is the root of the bound tree. suffix
is empty or starts with an Index step.
DecodePath::equal
fn DecodePath::equal(DecodePath, DecodePath) -> BoolDecodePath::not_equal
fn DecodePath::not_equal(x : DecodePath, y : DecodePath) -> BoolDecodePath::output
fn DecodePath::output(self : DecodePath, logger : &Logger) -> UnitDecodePath::to_repr
fn DecodePath::to_repr(DecodePath) -> @moonbitlang/core/debug.ReprDecodePath::to_string
fn DecodePath::to_string(self : DecodePath) -> Stringimpl Show for DecodePath
Show::output
fn output(self : DecodePath, logger : &Logger) -> UnitThe text form, for example targets[1].level or servers."eu.west".port.
A field name uses the quote rule of KeyPath. A path with no key and no
suffix gives (root).
DecodeStep
pub(all) enum DecodeStep {
Field(String)
Index(Int)
} derive(Eq, @moonbitlang/core/debug.Debug)One step of a decode path after the key path: a list index or a field name.
DecodeStep::equal
fn DecodeStep::equal(DecodeStep, DecodeStep) -> BoolDecodeStep::not_equal
fn DecodeStep::not_equal(x : DecodeStep, y : DecodeStep) -> BoolDecodeStep::to_repr
fn DecodeStep::to_repr(DecodeStep) -> @moonbitlang/core/debug.ReprDirEntry
pub(all) struct DirEntry {
name : String
kind : EntryKind
} derive(Eq, @moonbitlang/core/debug.Debug)One entry of a directory listing, with its real name.
DirEntry::equal
fn DirEntry::equal(DirEntry, DirEntry) -> BoolDirEntry::not_equal
fn DirEntry::not_equal(x : DirEntry, y : DirEntry) -> BoolDirEntry::to_repr
fn DirEntry::to_repr(DirEntry) -> @moonbitlang/core/debug.ReprEntryKind
pub(all) enum EntryKind {
File
Directory
Other
} derive(Eq, @moonbitlang/core/debug.Debug)The kind of a directory entry.
EntryKind::equal
fn EntryKind::equal(EntryKind, EntryKind) -> BoolEntryKind::not_equal
fn EntryKind::not_equal(x : EntryKind, y : EntryKind) -> BoolEntryKind::to_repr
fn EntryKind::to_repr(EntryKind) -> @moonbitlang/core/debug.ReprEnvResolver
pub struct EnvResolver {
// private fields
}A resolver over an explicit variable map. It resolves only Env references.
EnvResolver::resolve
fn EnvResolver::resolve(self : EnvResolver, reference : SecretRef, _origin : Origin) -> Secret raise SecretErrorimpl SecretResolver for EnvResolver
SecretResolver::resolve
fn resolve(self : EnvResolver, reference : SecretRef, _origin : Origin) -> Secret raise SecretErrorExpansion
pub(all) struct Expansion {
sources : Array[ConfigSource]
warnings : Array[ConfigWarning]
}The sources that a provider gives, in merge order, and its warnings.
FileRequest
pub(all) enum FileRequest {
ListDir(String)
ReadFile(String)
} derive(Eq, Hash, @moonbitlang/core/debug.Debug)A request that the pure load passes out to a host: the listing of a
directory or the text of a file. Paths use / separators.
FileRequest::equal
fn FileRequest::equal(FileRequest, FileRequest) -> BoolFileRequest::hash
fn FileRequest::hash(self : FileRequest) -> IntFileRequest::hash_combine
fn FileRequest::hash_combine(FileRequest, Hasher) -> UnitFileRequest::not_equal
fn FileRequest::not_equal(x : FileRequest, y : FileRequest) -> BoolFileRequest::to_repr
fn FileRequest::to_repr(FileRequest) -> @moonbitlang/core/debug.ReprFileRole
pub(all) enum FileRole {
Explicit
System
Global
Workspace
Member
EnvironmentFile
LocalOverride
UserOverride
Legacy
} derive(Eq, @moonbitlang/core/debug.Debug)The role of a file source. Reports and error text show a role by its report
name, for example user-override.
FileRole::equal
fn FileRole::equal(FileRole, FileRole) -> BoolFileRole::not_equal
fn FileRole::not_equal(x : FileRole, y : FileRole) -> BoolFileRole::to_repr
fn FileRole::to_repr(FileRole) -> @moonbitlang/core/debug.ReprFileTree
pub struct FileTree {
// private fields
}An immutable snapshot of the files that a load can read: directory
listings, file text, and absence records, keyed by path with /
separators. In a complete tree, a path that the tree does not hold is
absent. The pure load asks only for paths that the tree does not know.
FileTree::file
fn FileTree::file(self : FileTree, path : String) -> Lookup[String]The text of the file path.
FileTree::is_complete
fn FileTree::is_complete(self : FileTree) -> BoolWhether the tree is complete.
FileTree::is_file
fn FileTree::is_file(self : FileTree, path : String) -> Lookup[Bool]Whether path exists as a file: the listing of its directory holds its
exact name as a file. The compare is case-sensitive on every platform. A
missing directory gives Found(false).
FileTree::listing
fn FileTree::listing(self : FileTree, dir : String) -> Lookup[Array[DirEntry]]The listing of the directory dir.
FileTree::new
fn FileTree::new(complete? : Bool) -> FileTreeAn empty tree. With complete=true, every path is absent until a
with_* call adds it, so a load over it never asks for files.
FileTree::with_file
fn FileTree::with_file(self : FileTree, path : String, text : String) -> FileTreeA new tree that also holds the text of the file path.
FileTree::with_listing
fn FileTree::with_listing(self : FileTree, dir : String, entries : Array[DirEntry]) -> FileTreeA new tree that also holds the listing of the directory dir.
FileTree::with_missing
fn FileTree::with_missing(self : FileTree, path : String) -> FileTreeA new tree that records path as absent. When path is a directory, every
path under it is also absent.
Format
pub(all) struct Format {
name : String
extensions : Array[String]
parse : (String, String) -> ConfigValue raise ConfigError
}A configuration file format. parse takes the text and the origin, for
example a file path, and gives a value tree with a struct root.
KeyPath
pub struct KeyPath {
// private fields
} derive(Eq, Hash, @moonbitlang/core/debug.Debug)A path to a value in a configuration tree: a non-empty list of non-empty field names. Name matches are exact and case-sensitive. A key path does not select list items.
KeyPath::equal
fn KeyPath::equal(KeyPath, KeyPath) -> BoolKeyPath::from_names
fn KeyPath::from_names(names : Array[String]) -> KeyPath raise ConfigErrorA key path from field names, from the root down. The list and each name must not be empty.
KeyPath::hash
fn KeyPath::hash(self : KeyPath) -> IntKeyPath::hash_combine
fn KeyPath::hash_combine(KeyPath, Hasher) -> UnitKeyPath::names
fn KeyPath::names(self : KeyPath) -> Array[String]The field names, from the root down.
KeyPath::not_equal
fn KeyPath::not_equal(x : KeyPath, y : KeyPath) -> BoolKeyPath::output
fn KeyPath::output(self : KeyPath, logger : &Logger) -> UnitKeyPath::parse
fn KeyPath::parse(text : String) -> KeyPath raise ConfigErrorParse the dotted text form, for example ir.strict_mode. A name that
contains . or " uses double quotes, for example servers."eu.west".port.
In a quoted name, \" gives " and \\ gives \.
KeyPath::to_repr
fn KeyPath::to_repr(KeyPath) -> @moonbitlang/core/debug.ReprKeyPath::to_string
fn KeyPath::to_string(self : KeyPath) -> Stringimpl Show for KeyPath
Show::output
fn output(self : KeyPath, logger : &Logger) -> UnitThe text form, which KeyPath::parse reads back to an equal key path.
LoadContext
pub(all) struct LoadContext {
tree : FileTree
platform : Platform?
env_vars : Map[String, String]
working_dir : String?
formats : Array[Format]
}The inputs that a source provider gets during a load. platform is None
when no host gave it, and env_vars is empty when the builder holds no
variable set.
LoadStep
pub(all) enum LoadStep[T] {
Need(Array[FileRequest])
Done(T)
} derive(Eq, @moonbitlang/core/debug.Debug)One step of a pure load: the file requests that it still needs, or the result.
LoadStep::equal
fn[T : Eq] LoadStep::equal(LoadStep[T], LoadStep[T]) -> BoolLoadStep::not_equal
fn[T : Eq] LoadStep::not_equal(x : LoadStep[T], y : LoadStep[T]) -> BoolLoadStep::to_repr
fn[T : @moonbitlang/core/debug.Debug] LoadStep::to_repr(LoadStep[T]) -> @moonbitlang/core/debug.ReprLocated
pub(all) struct Located {
path : DecodePath
blame : Blame
} derive(Eq, @moonbitlang/core/debug.Debug)A decode path and the sources to blame for it.
Located::equal
fn Located::equal(Located, Located) -> BoolLocated::not_equal
fn Located::not_equal(x : Located, y : Located) -> BoolLocated::to_repr
fn Located::to_repr(Located) -> @moonbitlang/core/debug.ReprLookup
pub(all) enum Lookup[T] {
Found(T)
Missing
Unknown
} derive(Eq, @moonbitlang/core/debug.Debug)What a file tree knows about a path: it holds the value, it records the path as absent, or it does not know.
Lookup::equal
fn[T : Eq] Lookup::equal(Lookup[T], Lookup[T]) -> BoolLookup::not_equal
fn[T : Eq] Lookup::not_equal(x : Lookup[T], y : Lookup[T]) -> BoolLookup::to_repr
fn[T : @moonbitlang/core/debug.Debug] Lookup::to_repr(Lookup[T]) -> @moonbitlang/core/debug.ReprMergePolicy
pub(all) enum MergePolicy {
Replace
Append
MergeByKey(String)
} derive(Eq, @moonbitlang/core/debug.Debug)How two lists merge at one key path. The default is Replace. A key-path
policy beats the source policy.
MergePolicy::equal
fn MergePolicy::equal(MergePolicy, MergePolicy) -> BoolMergePolicy::not_equal
fn MergePolicy::not_equal(x : MergePolicy, y : MergePolicy) -> BoolMergePolicy::output
fn MergePolicy::output(self : MergePolicy, logger : &Logger) -> UnitMergePolicy::to_repr
fn MergePolicy::to_repr(MergePolicy) -> @moonbitlang/core/debug.ReprMergePolicy::to_string
fn MergePolicy::to_string(self : MergePolicy) -> Stringimpl Show for MergePolicy
Show::output
fn output(self : MergePolicy, logger : &Logger) -> UnitNamedOptions
pub struct NamedOptions[T] {
// private fields
}The options values of the children of one section, one for each instance name, in configuration order.
NamedOptions::get
fn[T] NamedOptions::get(self : NamedOptions[T], name : String) -> Options[T]?The options value of the instance name, or None when the section has no
child with that name.
NamedOptions::names
fn[T] NamedOptions::names(self : NamedOptions[T]) -> Array[String]The instance names, in configuration order.
Options
pub struct Options[T] {
value : T
key : KeyPath
name : String?
}A bound and validated value, the key path of its section, and the instance name of a named option. An options value exists only after decoding and validation succeed.
Origin
pub(all) struct Origin {
kind : SourceKind
source : String
priority : Int
location : String?
} derive(Eq, @moonbitlang/core/debug.Debug)The source that set a value: its kind, display name, display priority, and
location. The location is a file path in the / form or an environment
variable name.
Origin::equal
fn Origin::equal(Origin, Origin) -> BoolOrigin::not_equal
fn Origin::not_equal(x : Origin, y : Origin) -> BoolOrigin::to_repr
fn Origin::to_repr(Origin) -> @moonbitlang/core/debug.ReprPlatform
pub(all) enum Platform {
Linux
MacOs
Windows
} derive(Eq, @moonbitlang/core/debug.Debug)The operating system of a run.
Platform::equal
fn Platform::equal(Platform, Platform) -> BoolPlatform::not_equal
fn Platform::not_equal(x : Platform, y : Platform) -> BoolPlatform::to_repr
fn Platform::to_repr(Platform) -> @moonbitlang/core/debug.ReprSecret
pub struct Secret {
// private fields
}An opaque resolved secret. Show writes <redacted>.
Secret::expose
fn Secret::expose(self : Secret) -> StringThe secret text. Callers that display a value must not use this.
Secret::output
fn Secret::output(_self : Secret, logger : &Logger) -> UnitSecret::to_string
fn Secret::to_string(self : Secret) -> Stringimpl Show for Secret
Show::output
fn output(_self : Secret, logger : &Logger) -> UnitSecretRef
pub(all) enum SecretRef {
Env(String)
File(String)
Command(Array[String])
Keyring(service~ : String, account~ : String)
} derive(Eq, @moonbitlang/core/debug.Debug)A secret reference leaf: one of the Morphir shapes.
SecretRef::equal
fn SecretRef::equal(SecretRef, SecretRef) -> BoolSecretRef::from_config
fn SecretRef::from_config(node : ConfigNode) -> SecretRef raise ConfigErrorSecretRef::not_equal
fn SecretRef::not_equal(x : SecretRef, y : SecretRef) -> BoolSecretRef::to_repr
fn SecretRef::to_repr(SecretRef) -> @moonbitlang/core/debug.Reprimpl FromConfig for SecretRef
FromConfig::from_config
fn from_config(node : ConfigNode) -> SecretRef raise ConfigErrorThe unresolved reference. Binding never resolves it; use
Config::secret for that.
SecretSyntax
pub(all) enum SecretSyntax {
Standard
None
} derive(Eq, @moonbitlang/core/debug.Debug)Whether the load and the merge treat one-field env / file / command /
keyring structs as secret references.
SecretSyntax::equal
fn SecretSyntax::equal(SecretSyntax, SecretSyntax) -> BoolSecretSyntax::none
fn SecretSyntax::none() -> SecretSyntaxTurn secret-reference recognition off.
SecretSyntax::not_equal
fn SecretSyntax::not_equal(x : SecretSyntax, y : SecretSyntax) -> BoolSecretSyntax::standard
fn SecretSyntax::standard() -> SecretSyntaxThe Morphir secret-reference shapes. Recognition is on when the syntax is
Standard.
SecretSyntax::to_repr
fn SecretSyntax::to_repr(SecretSyntax) -> @moonbitlang/core/debug.ReprShowFormat
pub(all) enum ShowFormat {
Toml
Json
Ion
} derive(Eq, @moonbitlang/core/debug.Debug)The text form of a show helper.
ShowFormat::equal
fn ShowFormat::equal(ShowFormat, ShowFormat) -> BoolShowFormat::not_equal
fn ShowFormat::not_equal(x : ShowFormat, y : ShowFormat) -> BoolShowFormat::to_repr
fn ShowFormat::to_repr(ShowFormat) -> @moonbitlang/core/debug.ReprSourceKind
pub(all) enum SourceKind {
Defaults
InMemory
File(FileRole)
Environment
Overrides
} derive(Eq, @moonbitlang/core/debug.Debug)The kind of a configuration source.
SourceKind::equal
fn SourceKind::equal(SourceKind, SourceKind) -> BoolSourceKind::not_equal
fn SourceKind::not_equal(x : SourceKind, y : SourceKind) -> BoolSourceKind::report_name
fn SourceKind::report_name(self : SourceKind) -> StringThe report name of a source kind, as Morphir names its layers. A file
source shows the name of its role: project for workspace, explicit, and
legacy files.
SourceKind::to_repr
fn SourceKind::to_repr(SourceKind) -> @moonbitlang/core/debug.ReprSourceProvider
pub(all) struct SourceProvider {
name : String
expand : (LoadContext) -> LoadStep[Expansion] raise ConfigError
}A step of the builder that gives sources during the load. expand gives
the file requests that it still needs, or its sources. With a complete tree
it must give its sources.
SourceReport
pub(all) struct SourceReport {
kind : SourceKind
name : String
priority : Int
path : String?
candidates : Array[String]
status : SourceStatus
warnings : Array[ConfigWarning]
} derive(Eq, @moonbitlang/core/debug.Debug)The report of one source after a load. path is the file that the source
read, and candidates are the files that a candidate list looked for.
SourceReport::equal
fn SourceReport::equal(SourceReport, SourceReport) -> BoolSourceReport::not_equal
fn SourceReport::not_equal(x : SourceReport, y : SourceReport) -> BoolSourceReport::to_repr
fn SourceReport::to_repr(SourceReport) -> @moonbitlang/core/debug.ReprSourceSelection
pub(all) enum SourceSelection[T] {
Discover
Explicit(T)
Skip
} derive(Eq, @moonbitlang/core/debug.Debug)The selection of a source location or input. Discover uses the values
that a host or a source provider supplies, Explicit uses only the given
value, and Skip loads nothing.
SourceSelection::equal
fn[T : Eq] SourceSelection::equal(SourceSelection[T], SourceSelection[T]) -> BoolSourceSelection::not_equal
fn[T : Eq] SourceSelection::not_equal(x : SourceSelection[T], y : SourceSelection[T]) -> BoolSourceSelection::to_repr
fn[T : @moonbitlang/core/debug.Debug] SourceSelection::to_repr(SourceSelection[T]) -> @moonbitlang/core/debug.ReprSourceStatus
pub(all) enum SourceStatus {
Loaded
NotFound
Skipped
} derive(Eq, @moonbitlang/core/debug.Debug)What a load did with a source.
SourceStatus::equal
fn SourceStatus::equal(SourceStatus, SourceStatus) -> BoolSourceStatus::not_equal
fn SourceStatus::not_equal(x : SourceStatus, y : SourceStatus) -> BoolSourceStatus::to_repr
fn SourceStatus::to_repr(SourceStatus) -> @moonbitlang/core/debug.ReprSourced
pub struct Sourced[T] {
value : T
blame : Blame
} derive(Eq, @moonbitlang/core/debug.Debug)A decoded value with the sources to blame for it, for example to resolve a relative path against the file that set it.
Sourced::equal
fn[T : Eq] Sourced::equal(Sourced[T], Sourced[T]) -> BoolSourced::from_config
fn[T : FromConfig] Sourced::from_config(node : ConfigNode) -> Sourced[T] raise ConfigErrorSourced::not_equal
fn[T : Eq] Sourced::not_equal(x : Sourced[T], y : Sourced[T]) -> BoolSourced::to_repr
fn[T : @moonbitlang/core/debug.Debug] Sourced::to_repr(Sourced[T]) -> @moonbitlang/core/debug.Reprimpl FromConfig for Sourced[T]
FromConfig::from_config
fn[T : FromConfig] from_config(node : ConfigNode) -> Sourced[T] raise ConfigErrorUnknownKeys
pub(all) enum UnknownKeys {
Allow
Reject
RejectExcept(Array[String])
} derive(Eq, @moonbitlang/core/debug.Debug)What bind_or does with a configured key that the bound value does not
hold. FromJson ignores unknown keys, so a misspelled key has no effect
unless the check is on.
UnknownKeys::equal
fn UnknownKeys::equal(UnknownKeys, UnknownKeys) -> BoolUnknownKeys::not_equal
fn UnknownKeys::not_equal(x : UnknownKeys, y : UnknownKeys) -> BoolUnknownKeys::to_repr
fn UnknownKeys::to_repr(UnknownKeys) -> @moonbitlang/core/debug.ReprViolation
pub(all) struct Violation {
at : Array[Array[DecodeStep]]
detail : String
} derive(Eq, @moonbitlang/core/debug.Debug)A broken validation rule: the paths of the values it names, relative to
the bound section, and a detail text. An empty at names the section.
Violation::equal
fn Violation::equal(Violation, Violation) -> BoolViolation::not_equal
fn Violation::not_equal(x : Violation, y : Violation) -> BoolViolation::to_repr
fn Violation::to_repr(Violation) -> @moonbitlang/core/debug.ReprErrors
ConfigError
pub(all) suberror ConfigError {
Parse(format~ : String, origin~ : String, message~ : String, line~ : Int?, column~ : Int?)
UnsupportedYaml(origin~ : String, feature~ : String, line~ : Int, column~ : Int)
InvalidRoot(origin~ : String, found~ : String)
DuplicateKey(origin~ : String, key~ : KeyPath)
FileNotFound(path~ : String)
UnsupportedFormat(path~ : String, extensions~ : Array[String])
Ambiguous(display~ : String, location~ : String, candidates~ : Array[String])
InvalidKeyPath(text~ : String, reason~ : String)
InvalidEnvKey(variable~ : String)
MergeKey(key~ : KeyPath, index~ : Int, source~ : String)
InvalidSecret(key~ : KeyPath, origin~ : String, reason~ : String)
KeyNotFound(key~ : KeyPath)
Render(format~ : String, key~ : KeyPath, reason~ : String)
SourceOrder(source~ : String, priority~ : Int, previous~ : String, previous_priority~ : Int)
OutsideBoundary(start~ : String, boundary~ : String)
InvalidEnvironmentName(name~ : String, reason~ : String)
UnknownProject(selector~ : String, workspace~ : String)
AmbiguousProject(selector~ : String, matches~ : Array[String])
Decode(failure~ : BindFailure)
Validation(failures~ : Array[BindFailure])
} derive(Eq, @moonbitlang/core/debug.Debug)A configuration failure. Each case is one failure class, so a caller can match it without a string compare. The core, conventions, and binding capabilities raise these cases and have no error type of their own.
ConfigError::equal
fn ConfigError::equal(ConfigError, ConfigError) -> BoolConfigError::message
fn ConfigError::message(self : ConfigError) -> StringText for people that describes the failure. Paths show as the error holds
them; the host adapter gives them in the / form.
ConfigError::not_equal
fn ConfigError::not_equal(x : ConfigError, y : ConfigError) -> BoolConfigError::to_repr
fn ConfigError::to_repr(ConfigError) -> @moonbitlang/core/debug.ReprSecretError
pub(all) suberror SecretError {
MissingConfigKey(key~ : KeyPath)
EmptyEnvironment(variable~ : String)
FileRead(path~ : String, reason~ : String)
InvalidSecretValue(reason~ : String)
CommandFailed(reason~ : String)
KeyringLookupFailed(reason~ : String)
} derive(Eq, @moonbitlang/core/debug.Debug)A failure while resolving a secret. Messages never hold the secret or the backend output.
SecretError::equal
fn SecretError::equal(SecretError, SecretError) -> BoolSecretError::message
fn SecretError::message(self : SecretError) -> StringText for people that names the failure class and never holds a secret.
SecretError::not_equal
fn SecretError::not_equal(x : SecretError, y : SecretError) -> BoolSecretError::to_repr
fn SecretError::to_repr(SecretError) -> @moonbitlang/core/debug.ReprTraits
FromConfig
pub(open) trait FromConfig {
fn from_config(ConfigNode) -> Self raise ConfigError
}Exact decoding from the configuration tree. Unlike FromJson, it keeps Ion
decimals, timestamps and integers of any size, and it can read the blame of
each value.
impl FromConfig for Bool
FromConfig::from_config
fn from_config(node : ConfigNode) -> Bool raise ConfigErrorimpl FromConfig for Int
FromConfig::from_config
fn from_config(node : ConfigNode) -> Int raise ConfigErrorAn integer in the range of Int. A fraction fails.
impl FromConfig for Int64
FromConfig::from_config
fn from_config(node : ConfigNode) -> Int64 raise ConfigErrorAn integer in the range of Int64. A fraction fails.
impl FromConfig for UInt64
FromConfig::from_config
fn from_config(node : ConfigNode) -> UInt64 raise ConfigErrorAn integer in the range of UInt64. A fraction fails.
impl FromConfig for Double
FromConfig::from_config
fn from_config(node : ConfigNode) -> Double raise ConfigErrorA float, an integer or a decimal, as the nearest Double.
impl FromConfig for String
FromConfig::from_config
fn from_config(node : ConfigNode) -> String raise ConfigErrorText or a symbol with text.
impl FromConfig for Option[T]
FromConfig::from_config
fn[T : FromConfig] from_config(node : ConfigNode) -> T? raise ConfigErrorNone when no source sets the value or the value is a null.
impl FromConfig for BigInt
FromConfig::from_config
fn from_config(node : ConfigNode) -> @moonbitlang/core/bigint.BigInt raise ConfigErrorAn integer of any size.
impl FromConfig for Array[T]
FromConfig::from_config
fn[T : FromConfig] from_config(node : ConfigNode) -> Array[T] raise ConfigErrorEach item of a list, in order.
impl FromConfig for Map[String, T]
FromConfig::from_config
fn[T : FromConfig] from_config(node : ConfigNode) -> Map[String, T] raise ConfigErrorEach field of a table, in configuration order.
impl FromConfig for Decimal
FromConfig::from_config
fn from_config(node : ConfigNode) -> @moonrockz/ion/ion.Decimal raise ConfigErrorA decimal, or an integer as a decimal with exponent 0. A float fails, because a binary float has no exact decimal scale.
impl FromConfig for Timestamp
FromConfig::from_config
fn from_config(node : ConfigNode) -> @moonrockz/ion/ion.Timestamp raise ConfigErrorA timestamp with its precision, fraction and offset.
SecretResolver
pub(open) trait SecretResolver {
fn resolve(Self, SecretRef, Origin) -> Secret raise SecretError
}Resolves a secret reference. The origin lets a file resolver anchor a relative path to the directory of the declaring file.
Validate
pub(open) trait Validate {
fn validate(Self) -> Array[Violation] = _
}Validation rules that run after decoding. validate is pure: it returns
every broken rule and never raises. A type with no rules uses the default,
which returns no violations.
impl Validate for Option[T]
Validate::validate
fn[T : Validate] validate(self : T?) -> Array[Violation]The violations of the value, or none for None.
impl Validate for Array[T]
Validate::validate
fn[T : Validate] validate(self : Array[T]) -> Array[Violation]The violations of each item, below its list index.
impl Validate for Map[String, T]
Validate::validate
fn[T : Validate] validate(self : Map[String, T]) -> Array[Violation]The violations of each value, below its key.
Values
add
fn add(builder : ConfigBuilder, source : ConfigSource) -> ConfigBuilderAdd source after the sources that the builder holds.
bind
fn[T : @moonbitlang/core/json.FromJson] bind(config : Config, key : String) -> T raise ConfigErrorDecode the section at key into a T. key is the text form of a key
path, for example ir or servers."eu.west". A section that no source sets
decodes as null, so an Option target gives None. A decode failure
raises Decode with the decode path, the decoder detail, and the sources to
blame. A secret reference in the section raises Decode, and binding never
resolves it. Binding does not change the configuration.
bind_or
fn[T : @moonbitlang/core/json.FromJson + ToJson] bind_or(config : Config, key : String, default : T, unknown? : UnknownKeys) -> T raise ConfigErrorDecode the section at key merged over default. The default is written
with ToJson, the configured section merges over it with the core merge
rules, and the result decodes into a T: tables merge, a configured list
or scalar replaces the default, and an absent section keeps the default.
A None field of the default is not written, so a configured value fills
it. A failure in a value that the default gave has the blame Default. A
secret reference in the configured section raises Decode before the
merge. The default does not change.
unknown turns on the unknown-key check: with Reject, each configured
key that the ToJson form of the result does not hold is a failure with
its sources, and all of them raise one Validation error. The check is
correct only when ToJson writes every key that FromJson accepts, under
the same name; RejectExcept lists the other keys that the type accepts.
bind_root
fn[T : @moonbitlang/core/json.FromJson] bind_root(config : Config) -> T raise ConfigErrorDecode the full configuration into a T. Decode paths start at the root.
bind_with
fn[T : FromConfig] bind_with(config : Config, key : String) -> T raise ConfigErrorDecode the section at key exactly into a T. A section that no source
sets gives a node with no value, so an Option target gives None. A
failure raises Decode with the decode path and the sources to blame.
Binding never resolves a secret reference: only SecretRef accepts one.
bool
fn bool(value : Bool) -> ConfigValueA Boolean value.
build
fn build(sources : Array[ConfigSource]) -> Config raise ConfigErrorLoad the sources in list order over a complete empty file tree: a later
source wins. A file source raises FileNotFound, so this suits value
sources.
builder
fn builder() -> ConfigBuilderA builder with no sources, no formats, and no run inputs.
default_redact_fragments
fn default_redact_fragments() -> Array[String]The Morphir key-name fragments that mark a sensitive key.
defaults
fn defaults(builder : ConfigBuilder, json : Json) -> ConfigBuilder raise ConfigErrorAdd a defaults source from a JSON value, for example
Defaults::default().to_json().
env
fn env(builder : ConfigBuilder, prefix~ : String, reserved? : Array[String], selection? : SourceSelection[Map[String, String]]) -> ConfigBuilderAdd an environment variable source, as ConfigSource::env gives it.
env_resolver
fn env_resolver(vars : Map[String, String]) -> EnvResolverA resolver over vars. File, command, and keyring references raise
InvalidSecretValue.
env_vars
fn env_vars(builder : ConfigBuilder, vars : Map[String, String]) -> ConfigBuilderSet the variable set of the run. Source providers read variables only from this set.
explain
fn explain(config : Config, key : String) -> Array[(KeyPath, Array[Origin])] raise ConfigErrorThe origins of key: one entry for a leaf, or each descendant leaf for a
struct. A missing key raises KeyNotFound.
fields
fn fields(fields : Array[(String, ConfigValue)]) -> ConfigValueA struct value with the fields in the given order. When a name occurs more than once, the last value wins at the position of the first.
file
fn file(builder : ConfigBuilder, path : String, role? : FileRole, name? : String, priority? : Int) -> ConfigBuilderAdd a file source at an explicit path, as ConfigSource::file gives it.
float
fn float(value : Double) -> ConfigValueA floating-point value.
format
fn format(builder : ConfigBuilder, format : Format) -> ConfigBuilderRegister format after the formats that the builder holds.
get_json
fn get_json(config : Config, key : String) -> Json raise ConfigErrorThe value at the key path key as a JSON object with the fields key and
value, after redaction. A missing key raises KeyNotFound.
get_text
fn get_text(config : Config, key : String) -> String raise ConfigErrorThe value at the key path key as text, after redaction: a string gives its
text, and any other value gives compact JSON. A missing key raises
KeyNotFound.
in_memory
fn in_memory(value : ConfigValue, name? : String, priority? : Int) -> ConfigSource raise ConfigErrorAn in-memory source from a value tree. The root must be a struct.
in_memory_pairs
fn in_memory_pairs(pairs : Array[(String, ConfigValue)], name? : String, priority? : Int) -> ConfigSource raise ConfigErrorAn in-memory source from flat key-path pairs, for example
("ir.layout", @config.string("tree")). Pairs apply in list order with the
merge rules, so a later pair wins. Pair values keep their type.
int
fn int(value : Int64) -> ConfigValueAn integer value.
list
fn list(items : Array[ConfigValue]) -> ConfigValueA list value.
load
fn load(builder : ConfigBuilder, tree : FileTree) -> LoadStep[Config] raise ConfigErrorLoad the configuration from the builder and the file tree. This is pure: it reads only its inputs and gives the same result on every target.
It runs each provider at its position, then checks the priorities over the
expanded list and raises SourceOrder when a priority decreases. When a
provider or a file source needs a path that the tree does not know, it
gives all such requests in one Need. Otherwise it parses, excludes, and
merges the sources in list order and gives Done.
merge
fn merge(base : ConfigValue, overlay : ConfigValue, policy? : MergePolicy, key_policies? : Array[(KeyPath, MergePolicy)], source? : String, secret_syntax? : SecretSyntax) -> ConfigValue raise ConfigErrorMerge overlay over base. A null overlay keeps the base value. A secret
reference replaces and is not merged with a struct. Two structs merge field
by field, with base fields first and new overlay fields after. Two lists use
policy, or a matching entry of key_policies when one exists for the path.
In all other cases the overlay value wins. The inputs do not change, and
unchanged subtrees are shared.
named
fn[T] named(config : Config, key : String, bind_one : (Config, String) -> Options[T] raise ConfigError) -> NamedOptions[T] raise ConfigErrorBind each child of the section at key as one named instance. bind_one
gets the configuration and the key text of one child, for example
backends.ts, and gives its options value; bind, bind_or and
bind_with with validated all fit. Each options value gets the child
name as its instance name. The Decode and Validation failures of all
instances raise one Validation error. A section that no source sets gives
no instances. A section that is not a table raises Decode.
nested
fn nested(field : String, found : Array[Violation]) -> Array[Violation]The violations of the value in field, with each path moved below
field. A violation of the whole nested value names field.
options
fn[T : @moonbitlang/core/json.FromJson + Validate] options(config : Config, key : String) -> Options[T] raise ConfigErrorBind the section at key and validate it: bind, then validated.
overrides
fn overrides(builder : ConfigBuilder, pairs : Array[(String, ConfigValue)]) -> ConfigBuilder raise ConfigErrorAdd an overrides source from key-path pairs.
parse_file
fn parse_file(formats : Array[Format], path : String, text : String) -> ConfigValue raise ConfigErrorParse the text of the file path with the format that its extension
selects from formats. The extension compares in lowercase. No match
raises UnsupportedFormat with the registered extensions.
path_json
fn path_json(reports : Array[SourceReport]) -> JsonSource reports as JSON, in ascending priority (merge order).
path_text
fn path_text(reports : Array[SourceReport]) -> StringSource reports as text: highest priority first.
platform
fn platform(builder : ConfigBuilder, p : Platform) -> ConfigBuilderSet the platform of the run.
provider
fn provider(builder : ConfigBuilder, p : SourceProvider) -> ConfigBuilderAdd a source provider. During the load, its sources take its place in merge order.
redact
fn redact(value : ConfigValue, fragments? : Array[String]) -> ConfigValueA copy of value with each sensitive subtree replaced by the text
<redacted>. A key is sensitive when its name, in lowercase with -
changed to _, holds a fragment. The default fragment list is Morphir's.
secret_syntax
fn secret_syntax(builder : ConfigBuilder, syntax : SecretSyntax) -> ConfigBuilderSet whether one-field env / file / command / keyring structs are
secret references. The default is SecretSyntax::standard().
show
fn show(config : Config, format : ShowFormat) -> String raise ConfigErrorRender the redacted configuration as TOML, JSON, or Ion text.
string
fn string(text : String) -> ConfigValueA string value.
validated
fn[T : Validate] validated(value : T, config : Config, key : String, name? : String) -> Options[T] raise ConfigErrorValidate value, the section at key of config, and give it as an
options value. Each violation becomes a failure with its full decode path
and the sources to blame, and all of them raise one Validation. The
value comes first, so validated ends a binding pipeline:
config |> bind_or("ir", default) |> validated(config, "ir").
violation
fn violation(fields : Array[String], detail : String) -> ViolationA violation that names one field of the section for each name in
fields, or the section itself when fields is empty. A rule over two
fields names both, so the error shows the source of each value.
working_dir
fn working_dir(builder : ConfigBuilder, dir : String) -> ConfigBuilderSet the working directory of the run. A relative explicit file path joins it.