@xtandard/kit/storage/file — file-system storage: one JSON file per key under a base
directory, case-safe segment encoding, write-then-rename, fs.watch change events, in-process
compare-and-swap, and read paths and a migration for stores in the legacy unencoded layout.
Create a file-backed FileKvStorage. Values are pretty-printed JSON. watch uses a recursive fs.watch on the base directory; it is best-effort and may coalesce or miss events on platforms without recursive-watch support. A rename event is reported as remove only when the file is actually gone.
Encode one key segment as a file name that survives case-insensitive and normalization-insensitive filesystems and never escapes its directory: uppercase letters become ^ + the lowercase letter, ^ becomes ^^, bytes outside [a-z0-9._~!@,=+-] become %XX (of the UTF-8 encoding, so é never folds with e), a leading . is %2E (no ., .. or dotfiles) and the empty segment is a lone %.
One-time upgrade of a store in the legacy layout (raw key segments as file names, so keys differing only by case shared a file on case-insensitive filesystems). Moves every leaf that is not in the encoded layout to its encodeSegment path and removes the emptied directories. Idempotent; run it with no writer on the store. Resolves how many keys moved.