Manage state with finesse
Statecraft is a protocol and set of tools for interacting with data that changes over time. It is the spiritual successor to Sharedb.
Statecraft sees the world as a series of stores. Each store has:
The store guarantees that the data is immutable with respect to time. (So if the data changes, the version number goes up).
Stores provide a standard set of methods to interact with the data:
A Statecraft store is more than just a database abstraction. They can provide an interface to:
And much more.
Unlike traditional transactional databases, Statecraft stores compose together like LEGO. Stores wrap one another, adding functionality or changing the behaviour of the store living underneath in the process.
For example:
readonly store transparently provides access to the underlying store, but disallows any mutation.cache store caches all queries made to the underlying store, and can return subsequent queries directlymap store runs all fetch and subscribe result values through a mapping function.The philosophy of Statecraft is to "ship the architecture diagram". You should be able to take your whiteboard diagram of your application and construct (almost) all of it directly out of Statecraft stores. No reimplementation or integration necessary. And because the stores are standard, we can have standard tools for debugging too.
Statecraft's fetch and subscribe functions use queries to specify the data to return.
Currently there's 3 standard supported query types:
Single). This is for stores which just expose a single value. Aka, fetch everything. Single value queries return a single value result.KV). These contain a list (or a set) of keys to fetch, and return a map of key-value pairs in response. There is also an AllKV variant which requests all key-value pairs in the store.I've made a proof-of-concept store which adds GraphQL schema & query support, but this is not yet fully merged.
Full developer API documentation is still in the works. Sorry.
For now you can look through the type definitions (with documentation) for stores and queries in lib/interfaces.ts. The set of available core stores is in lib/stores/. And there are some demos showing different ways to use the API in demos/.
Javascript has been to make a proof of concept because it was easy and it demos well.
Statecraft is language agnostic and my plan is to have implementations in many other languages too. Once async/await support is in rust proper, I would like to port Statecraft's core into rust.
The API is designed to make it easy to re-expose a statecraft store over the network. For this reason it should be easy to build applications on top of Statecraft which use a mixed set of languages. For example, you should be able to write your blog rendering function in Rust or Go but use the existing nodejs code to cache the results and expose it over websockets. This requires compatible Statecraft implementations in Go, Rails, Python, Rust, Swift, etc. These are waiting on a standardization push for the network API, which is coming but not here yet.
Statecraft is in an advanced proof-of-concept stage. It works, but you and your application may need some hand holding. There are rough edges.
If you want help building Statecraft, making stuff on top of Statecraft, or if you would like to help with Statecraft get in touch.
Statecraft is licensed under the ISC:
…No open issues yet, or sync has not completed.