Mirror / foldkit-mirror
Writing and persistence behavior
Writes are throttled so rapidly changing local state does not hammer the external representation:
URL mirror default: 50 ms
KV mirror default: 250 msA newer slice supersedes a pending write through Foldkit's dependency restart behavior.
A key-value mirror stores one versioned JSON document under its configured key. It may also be scoped to a user or tenant:
Mirror.kv(App, {
key: 'todo/prefs',
scope: principal.userId,
fields: ...,
})A document with another version/scope, or a malformed document, is discarded and removed. This is safe because Mirror represents disposable state, not unsent user operations. Discarding is not migrating: a port that wants another application's saved state writes an importer for that shape, or stores under a new key and version, rather than letting the old document fail to decode and calling the clean start a migration.
Store failures are absorbed and logged rather than failing the application. A slice back at all defaults removes the stored document.
Contracts and Module
Every mirror exposes a contract of kind mirror.
Conceptually:
field owner: local application Model
mirror: observer / representationSo Module.manifest still reports the field as local with the mirror beside it.
A mirror never becomes a second owner.
A key-value mirror declares MirrorRestored among its Messages. If the
application union forgot to spread Mirror.messages, Module.validate can
report that as an unknown Message dependency.
A URL key belongs to one URL mirror per application. Constructing another mirror that claims the same key fails and names the original owner of that URL key.