Config / Explain and validate
Explain and validate
"Why is the rate 200 when the file says 1000?" explain answers it: every
setting, its value, the layer that gave it and every value it went over.
validate runs the program's own checks, the ones a single setting's rule
cannot say, on the whole value at open and before every change.
console.table(config.explain())for line in config.explain(): # Line(path, value, from_, over, given)
print(line)for _, line := range config.Explain() { // tinystore.Line{Path, Value, From, Over, Given}
fmt.Println(line)
}println!("{}", config.explain());For a config that reads app.toml and the variables PORT,
DATABASE_URL_FILE and APP_REGION, after a change of limits.rps, each
language prints:
┌───┬────────────┬───────┬──────────────────────────────────────────────┬───────────────────────────────────────────────┐
│ │ path │ value │ from │ over │
├───┼────────────┼───────┼──────────────────────────────────────────────┼───────────────────────────────────────────────┤
│ 0 │ db.url │ *** │ DATABASE_URL_FILE, secrets/db-url │ │
│ 1 │ limits.rps │ 200 │ a change, version 1, 2026-10-24 09:34:52 UTC │ 1000 from app.toml, 100 from the declaration │
│ 2 │ port │ 9000 │ PORT │ 8000 from app.toml, 8080 from the declaration │
│ 3 │ region │ "eu" │ APP_REGION │ │
└───┴────────────┴───────┴──────────────────────────────────────────────┴───────────────────────────────────────────────┘Line(path='db.url', value='***', from_='DATABASE_URL_FILE, secrets/db-url', over='')
Line(path='limits.rps', value='200', from_='a change, version 1, 2026-10-24 09:34:55 UTC', over='1000 from app.toml, 100 from the declaration')
Line(path='port', value='9000', from_='PORT', over='8000 from app.toml, 8080 from the declaration')
Line(path='region', value='"eu"', from_='APP_REGION', over='')db.url *** DATABASE_URL_FILE, secrets/db-url
limits.rps 200 a change, version 1, 2026-10-24 09:34:59 UTC over 1000 from app.toml, 100 from the declaration
port 9000 PORT over 8000 from app.toml, 8080 from the declaration
region "eu" APP_REGIONdb.url *** DATABASE_URL_FILE, secrets/db-url
limits.rps 200 a change, version 1, 2026-10-24 09:35:00 UTC over 1000 from app.toml, 100 from the declaration
port 9000 PORT over 8000 from app.toml, 8080 from the declaration
region "eu" APP_REGIONover is newest first: the layer that won, then what it went over. An object
in code is named by its place in the list, layer 2. Secrets show as ***
here too. A setting with no value shows
as unset, from the declaration, until a layer gives it one:
db.password unset the declarationEach value as data
Each line also has given: every value the setting was given, newest first.
The first item is the line's own value, and the rest are the values it went
over. Each item has its value, as explain shows it, and from, which says
where the value came from as data. Use it to show a setting's history in your
own words, instead of parsing the text:
const rps = config.explain().find(line => line.path === 'limits.rps')
const [own, under] = rps?.given ?? []
if (own?.from.kind === 'change') {
own.from.version // 1
own.from.at // a Date: when the change was made
under?.value // '1000': what a reset gives back
under?.from // { kind: 'file', path: 'app.toml' }
}rps = next(line for line in config.explain() if line.path == "limits.rps")
if len(rps.given) > 1 and rps.given[0].from_.kind == "change":
own, under = rps.given[0], rps.given[1]
own.from_.version # 1
own.from_.at # a datetime in UTC: when the change was made
under.value # "1000": what a reset gives back
under.from_ # Origin(kind='file', path='app.toml')for _, line := range config.Explain() {
if line.Path != "limits.rps" || len(line.Given) < 2 {
continue
}
own, under := line.Given[0], line.Given[1]
if own.From.Kind == tinystore.OriginChange {
own.From.Version // 1
own.From.At // a time.Time: when the change was made
under.Value // "1000": what a reset gives back
under.From // tinystore.Origin{Kind: tinystore.OriginFile, Path: "app.toml"}
}
}use tinystore::config::Origin;
let explained = config.explain();
let rps = explained.settings.iter().find(|line| line.path == "limits.rps").unwrap();
if let [own, under, ..] = rps.given.as_slice()
&& let Origin::Change { version, at, .. } = &own.from
{
// version is 1, and at is a SystemTime: when the change was made
// under.value is "1000": what a reset gives back
// under.from is Origin::File { path: "app.toml" }
}from has a kind, and only the fields that its kind names:
kind | Fields | Its text |
|---|---|---|
declaration | the declaration | |
layer | place, where the declaration is 1 | layer 2 |
file | path | app.toml |
env | variable, and dotenv or file | PORT, PORT in .env, DATABASE_URL_FILE, secrets/db-url |
change | version and at | a change, version 1, 2026-10-24 09:35:00 UTC |
dotenvis the.envfile that set the variable, andfileis the file that aNAME_FILEvariable named. At most one of the two is set.fromisfrom_in Python andFromin Go. In Go the kinds are the constantstinystore.OriginDeclaration,OriginLayer,OriginFile,OriginEnvandOriginChange. In Rust they are the variants ofOrigin.Originand each of its variants are#[non_exhaustive], so amatchon it needs a_arm, and a variant's pattern needs.., as inOrigin::File { path, .. }.- A newer server may send a
kindthat your SDK does not know. The SDK keeps it as it was sent, and its text is the kind, so give aswitchonkinda default case. - The first item's
from, as text, is the line'sfrom:String(given[0].from),str(given[0].from_),Given[0].From.String()andgiven[0].from.to_string(). - In TypeScript,
console.tableand a spread such as{ ...line }leavegivenout, so the table keeps its four columns, andJSON.stringifykeeps it. Python'sprint(line)leaves it out too. - A server older than 0.1.1 sends no
given, so the SDK's is empty. Check its length before you readgiven[0], as the code above does, or Go panics and TypeScript readsundefined.
What was read and not used
After the settings, explain lists what was read and not used, each with
why. The open logs each once:
app.local.toml: absent
APP_PROT: a variable with the prefix that names no setting; did you mean APP_PORT?
limits.rps: the change of version 1 is ignored: 800 is above 500These are the notes of what explain() returns in TypeScript and Python,
Notes() in Go and Explained.notes in Rust. A typo in a variable is said,
never silently ignored, and the nearest setting's name is offered when one is
an edit or two away.
Validate
const config = await store.config('app', layers, { validate: Settings }) // a zod or valibot schema, or a functiondef check(settings: Settings) -> None:
if settings.limits.burst < settings.limits.rps:
raise ValueError("limits.burst is below limits.rps")
config = await store.config("app", layers, validate=check) # or a pydantic modelconfig, err := tinystore.OpenConfig(ctx, store, "app", defaults, tinystore.Validate(func(s Settings) error {
if s.Limits.Burst < s.Limits.RPS {
return errors.New("limits.burst is below limits.rps")
}
return nil
}))validatesees the whole value at open and before a change is kept; a change it refuses keeps nothing and failsinvalidwith its message.- It takes a Standard Schema, zod's or valibot's, a pydantic model in Python, or a function that throws.
- What one value says of itself, a range, a set, a list's length, is a
rule, which the core checks in every layer and names the
variable or file. What relates two settings, or a format, a URL, an email,
is
validate's.
At open, a kept change that validate now refuses is ignored and said, as
A change that no longer fits shows.
validate runs in the program that makes a change, because it is the
program's code. Another program's change it refuses leaves the value before
it, says so, and explain lists it.
Errors
Every error of an open is invalid, and one error lists every problem:
config app: app.toml: prot: no such setting; did you mean port?; APP_PORT: "eighty" is not a number;
region is required: region in app.toml, or set APP_REGION: invalidand one a change:
config app: limits.rps: "fast" is not a number: invalid
config app: changed since the version the change was made on: conflictSee also
- Config: the engine's overview.
- Layers and files: the layers
explainnames.