YamlConfigReader class final

Type-safe accessors over a plain config map, plus an explicit ${NAME} environment-variable expander.

The map is the plain Map<Object?, Object?> produced by loadYamlAsMap at the parse boundary — never a package:yaml YamlMap. This reader has no package:yaml import: the node types stay out of the read path entirely. Nested maps and lists it returns are likewise plain Map<Object?, Object?> / List<Object?>, so a loader can descend through the whole document without ever meeting a YamlMap.

This is the consolidation of the field-helper blocks that several brain loaders grew independently (SubstrateConfigLoader, MemoryConfigLoader). They were behaviourally identical line-for-line apart from the exception class they raised; the errorFactory seam preserves that one intended difference and removes the duplication.

Construction is per parse: a loader builds one reader with the env map for that call and its own error factory, then routes every typed read through it:

final doc = loadYamlAsMap(content, rootPath: 'substrate');
final reader = YamlConfigReader(
  env: env,
  errorFactory: SubstrateConfigException.new,
);
final id = reader.requireString(doc, 'id', 'substrate.providers[0].id');
final url = reader.expandEnv(rawUrl, 'substrate.providers[0].baseUrl');

Path argument. Every accessor takes a path — the dotted location of the value in the document (e.g. substrate.embedding.dims). It appears verbatim in error messages so a failure points the reader straight at the offending line. optionalMap is the one exception: it reports by key rather than path, matching the original loaders' message shape.

Constructors

YamlConfigReader({required Map<String, String> env, required YamlConfigErrorFactory errorFactory})
const

Properties

env → Map<String, String>
Environment used by expandEnv to resolve ${NAME} tokens.
final
errorFactory → YamlConfigErrorFactory
Wraps a message in the loader's domain exception type.
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

expandEnv(String input, String path) → String
Expands ${env:NAME} tokens in input against env.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
optionalBool(Map<Object?, Object?> node, String key, String path) → bool?
Returns the bool at key, or null when absent; throws if present but non-bool.
optionalDouble(Map<Object?, Object?> node, String key, String path) → double?
Returns the number at key as a double, or null when absent; throws if present but non-numeric.
optionalInt(Map<Object?, Object?> node, String key, String path) → int?
Returns the int at key, or null when absent; throws if present but non-int.
optionalList(Map<Object?, Object?> node, String key, String path) → List<Object?>?
Returns the list at key, or null when absent; throws if present but non-list.
optionalMap(Map<Object?, Object?> node, String key) → Map<Object?, Object?>?
Returns the map at key, or null when absent; throws if present but non-map.
optionalString(Map<Object?, Object?> node, String key, String path) → String?
Returns the string at key, or null when absent; throws if present but non-string.
parseUri(String raw, String path) → Uri
Parses raw as a Uri; throws if it is not a valid URI.
requireDouble(Map<Object?, Object?> node, String key, String path) → double
Returns the number at key as a double; throws if missing or non-numeric.
requireInt(Map<Object?, Object?> node, String key, String path) → int
Returns the int at key; throws if missing or non-int.
requireList(Map<Object?, Object?> node, String key, String path) → List<Object?>
Returns the list at key; throws if missing or non-list.
requireMap(Map<Object?, Object?> node, String key, String path) → Map<Object?, Object?>
Returns the map at key; throws if missing or non-map.
requireString(Map<Object?, Object?> node, String key, String path) → String
Returns the string at key; throws if missing or non-string.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited