sema-config 0.1.1
Layered configuration: files, env vars, profiles, and reference expansion
Exported declarations from this release. Parameter names and descriptions come directly from its source.
No matching exports. Try a function name or a word from its description.
(config/env-overrides prefix)Collect all environment variables starting with prefix into a nested map: APP_DB__HOST=x → {:db {:host "x"}}. Double underscores nest; single segments become lowercase kebab-case keywords. Values stay strings — coerce at the consumer via :%env or your own parsing.
View source definition
(define (config/env-overrides prefix)
"Collect all environment variables starting with prefix into a nested map: APP_DB__HOST=x → {:db {:host \"x\"}}. Double underscores nest; single segments become lowercase kebab-case keywords. Values stay strings — coerce at the consumer via :%env or your own parsing."
(foldl (fn (acc entry)
(let ((name (keyword/to-string (first entry))))
(if (string/starts-with? name prefix)
(let* ((tail (substring name (string-length prefix) (string-length name)))
(segments (filter (fn (s) (not (= s "")))
(string/split tail "__")))
(path (map (fn (s)
(string/to-keyword
(string/replace (string/lower s) "_" "-")))
segments)))
(if (null? path)
acc
(map/assoc-in acc path (nth entry 1))))
acc)))
{}
(map/entries (sys/env-all))))(config/get cfg key . default)Get a top-level config value, falling back to default (nil when omitted). Thin wrapper over the stdlib get, kept for API symmetry.
View source definition
(define (config/get cfg key . default)
"Get a top-level config value, falling back to default (nil when omitted). Thin wrapper over the stdlib get, kept for API symmetry."
(get cfg key (if (null? default) nil (first default))))(config/get-in cfg path . default)Get a nested config value at a key path, falling back to default (nil when omitted). Same semantics as the stdlib map/get-in, kept for API symmetry.
View source definition
(define (config/get-in cfg path . default)
"Get a nested config value at a key path, falling back to default (nil when omitted). Same semantics as the stdlib map/get-in, kept for API symmetry."
(map/get-in cfg (seq->list path) (if (null? default) nil (first default))))(config/load sources . opts)Load layered configuration: deep-merge sources left-to-right (later wins), apply the selected profile, then expand :%env/:%ref/:%or directives and ${VAR} strings. Sources are file paths and/or maps; a single path or map is also accepted. Options: {:profile :prod} (falls back to the SEMA_PROFILE env var).
View source definition
(define (config/load sources . opts)
"Load layered configuration: deep-merge sources left-to-right (later wins), apply the selected profile, then expand :%env/:%ref/:%or directives and ${VAR} strings. Sources are file paths and/or maps; a single path or map is also accepted. Options: {:profile :prod} (falls back to the SEMA_PROFILE env var)."
(let* ((o (if (null? opts) {} (first opts)))
(srcs (cond
((or (string? sources) (map? sources)) (list sources))
((or (list? sources) (vector? sources)) (seq->list sources))
(#t (error (format "config/load: sources must be a list of paths/maps — got ~a" sources)))))
(profile (resolve-profile o))
;; Profiles resolve per source before merging, so a base file's
;; :%profiles section can never clobber a later source's override.
(layers (map (fn (src) (apply-profiles (load-source src) profile))
srcs))
(merged (foldl map/deep-merge {} layers)))
(expand merged merged (list) (list))))(config/read path . opts)Read one config file by extension (.toml, .json, or .sema) into a keyword-keyed map. Options: {:optional #t} returns {} instead of erroring when the file is missing.
View source definition
(define (config/read path . opts)
"Read one config file by extension (.toml, .json, or .sema) into a keyword-keyed map. Options: {:optional #t} returns {} instead of erroring when the file is missing."
(let* ((o (if (null? opts) {} (first opts)))
(optional (get o :optional #f)))
(if (file/exists? path)
(normalize-keys (parse-file path))
(if optional
{}
(error (format "config/read: file not found: ~a — create it or pass {:optional #t}" path))))))(config/require! cfg paths)Assert that every key path in paths exists in cfg — errors listing ALL missing paths at once. Returns cfg for chaining.
View source definition
(define (config/require! cfg paths)
"Assert that every key path in paths exists in cfg — errors listing ALL missing paths at once. Returns cfg for chaining."
(let ((missing (filter (fn (p) (not (path-present? cfg (seq->list p))))
(seq->list paths))))
(when (not (null? missing))
(error (format "config/require!: missing required config paths: ~a — provide them in a config source or env override"
(string/join (map (fn (p) (path->str (seq->list p))) missing) ", "))))
cfg)))About this reference
Generated with sema-reader 1.37.0 without executing package code. These are source declarations; dynamic exports, aliases, and runtime changes are not inferred.
Archive SHA-256 a2c7e5323994f7e8e0e9c7f6d92f0b879a6a1102dc96a0faa116d95e0fa39ba1