FileStore
A persistent Store that keeps its items in files inside directory: a folder for each part of a namespace, and in it one file of JSON with the items of that namespace. The items of listOf("users", "ana") are in users/ana/items.json.
val store = FileStore(Path(appDirectory, "memories"))
graph.invoke(input, GraphConfig(threadId = "plan-7", store = store.within("users", userId)))Works on every target that has a file system, as FileCheckpointer does: JVM/Android, Apple, Linux and Windows native, and JS/Wasm on Node.js. It is not available in browsers.
A write is atomic: the file of its namespace is written to a temporary file and then moved into place, so a crash in the middle of a write leaves the items as they were. A write writes the whole file of its namespace again, which is quick for the few hundred items a user has. One instance is safe to share between coroutines; do not point several instances or processes at the same directory.
The names of folders are made from the parts of the namespace, with every character that is not a lowercase letter, a digit, _ or - written as %XX, so that two parts never get the same folder, also on a file system that ignores case.
Parameters
where the items are kept. Created if it does not exist.
the file system to use; replaceable in tests.
gives StoreItem.updatedAt. Two writes of one store never get the same time, so list keeps their order also with a clock that is not precise.