config_manager 0.4.2
config_manager: ^0.4.2 copied to clipboard
A JSON-based configuration manager with path-based access to nested values, singleton pattern, and mixin support.
0.4.2 #
- Adds
lookupPath/deepMergeMapstop-level utility functions for path-walking and deep-merging plainMap<String, dynamic>trees. - Adds
getOrDefault<T>(key, defaults, {sector})andgetDurationSeconds(key, defaults, {sector})toConfigManagerBaseandConfigExtension, for reading a value (or a seconds-basedDuration) with a fallback to a default configuration tree when the key isn't present in the loaded configuration.
0.4.1 #
- Breaking:
loadFromJson,loadFromString, andloadFromMapno longer replace a sector's configuration outright; they deep-merge the loaded content into whatever is already loaded for that sector. Keys not present in the new data are left untouched, and keys present in both are overwritten (recursively, for nested maps). - Breaking:
clearnow takes a requiredList<String> keyargument (clear(key, {sector})), in the same path form asget. An emptykeykeeps the previous behavior (clears the given sector, or every sector whensectoris also omitted); a non-emptykeyremoves just that key (a map entry or list index) from the sector, leaving the rest untouched.
0.4.0 #
getbecomes generic (get<T>(key, {sector})) acrossIConfigBase,ConfigManagerBase, andConfigExtension.Tdefaults todynamicwhen omitted, preserving existing call sites; when specified (e.g.get<String>(['appName'])), the value is cast toTbefore being returned. Since the underlying JSON carries no type information, a mismatchedTthrows aTypeErrorat call time rather than at compile time.setnow enforces type consistency: writing a non-null value for a key whose type is already known (see below) and differs from it throws the newConfigTypeMismatchExceptioninstead of overwriting it. Writingnull, or writing to a key with no known type yet, is unrestricted.- Add an optional per-sector type schema on
IConfigManager:setSchema(schema, {sector})registers expected types as a tree mirroring the configuration's shape (Typeat the leaves, e.g.{'database': {'port': int}}), andtypeOf(key, {sector})queries it.setand everyloadFromJson/loadFromString/loadFromMapcall also extend the schema on their own with the runtime type of every non-null value they write or load — so the very first write or load for a key is enough to have it checked from then on, with no separate declaration needed. Each of those four calls validates against whatever schema is already known for the target sector before applying its own change, throwingConfigTypeMismatchExceptionon a mismatch.clearalso removes the schema for the cleared sector(s). A schema leaf declared asdynamicopts that key out of checking entirely and is never overwritten by the type actually observed, so it stays unrestricted.
0.3.0 #
- Breaking: dot-notation
Stringkeys are removed.get,set, andcontainsKeysnow take an explicitList<String>key path instead (e.g.['database', 'host']), so a literal.inside a key name is never ambiguous with nesting. A single top-level key is a one-element list (['appName']); an empty list addresses the whole configuration map. operator []/operator []=accept the sameList<String>path.
0.2.3 #
- Add
isLoaded({sector})to check whether a sector currently has a loaded configuration. - Add
containsKeys(keys, {sector})to check whether a set of keys (with the same dot/list-index notation asget) are all present in a sector. loadFromJson,loadFromString, andloadFromMapaccept aforceparameter (defaults totrue); whenforce: falseand the target sector is already loaded, the call is a no-op.
0.2.2 #
- Extract shared load/read/write logic into
ConfigManagerBase, an abstractIConfigManagerimplementation;ConfigManagerSingletonnow extends it instead of duplicating the sector store. This lets consumers create their own non-singleton config managers with an independent default sector. setbecomes generic (set<DataType>(key, data, {sector})) acrossIConfigBase,ConfigManagerBase, andConfigExtension.- The singleton's constructor now also tolerates a malformed default
config.json, starting empty instead of leaving the singleton unconstructable.
0.2.0 #
- Add sector-based configuration: each sector holds its own configuration and
operations accept an optional
sectorargument, falling back to the default sector when omitted. - Introduce
IConfigManagerandIConfigBaseinterfaces, splitting the manager contract from the shared load/read operations. - Simplify
IConfigExtensionto a marker interface overIConfigBase; value access is provided by the inheritedget(key, {sector}).
0.1.0 #
- Initial release.
- JSON configuration file loading.
- Dot-notation access to nested values.
- List support with index access.
- Singleton-based configuration access.
- Mixin-based configuration extension.