sema-config 0.1.0

Layered configuration: files, env vars, profiles, and reference expansion

API reference 6 exports

Exported declarations from this release. Parameter names and descriptions come directly from its source.

config/env-overrides

Source :288
(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

Source :307
(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

Source :311
(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

Source :273
(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

Source :263
(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!

Source :315
(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 af204b86a5aa61c332dd185e99ab3e8895b225ffc75bf05ca4e8cec34cf0ffd9