A multiplatform reactive storage abstraction for key–value data. Part of the Arch Toolkit.
KeyValue interface for any storage backend.instant().by syntax.* Web targets fallback to noop stubs.
Add the core module as dependency:
implementation("io.github.matheus-corregiari:storage-core:<version>")
Then choose one of the available providers:
DataStore (persistent)
implementation("io.github.matheus-corregiari:storage-datastore:<version>")
Memory (in-memory, for tests or ephemeral cache)
implementation("io.github.matheus-corregiari:storage-memory:<version>")
val storage: StorageProvider = DataStoreProvider(store)
val isLoggedIn = storage.boolean("is_logged_in")
val userName = storage.string("user_name")
isLoggedIn.set(true)
println("User: ${userName.instant()}")
enum class Theme { Light, Dark }
val theme = storage.enum("theme", Theme.entries, Theme.Light)
theme.set(Theme.Dark)
println("Theme is ${theme.instant()}")
@kotlinx.serialization.Serializable
data class User(val id: String, val name: String)
val user = storage.model<User>("user")
user.set(User("42", "Alice"))
println("User: ${user.instant()}")
@Composable
fun UserNameInput(userName: KeyValue<String?>) {
val state = userName.state()
TextField(
value = state.value.orEmpty(),
onValueChange = { state.value = it }
)
}
var counter by storage.int("counter").required { 0 }.delegate()
counter += 1
println("Counter is $counter")
By default, models use the built-in Json configuration:
ignoreUnknownKeys = true
encodeDefaults = true
prettyPrint = true
Override globally if needed:
StorageProvider.json(Json {
ignoreUnknownKeys = false
})
| Target | Provider(s) | Status |
|---|---|---|
| Android/JVM | DataStore | ✅ |
| iOS/macOS | DataStore (KMP) | ✅ |
| JS/WASM | Noop (stub only) | ⚠️ |
| Any | Memory | ✅ |
For unit tests or non-persistent use cases, use the in-memory provider:
val memory = MemoryStoreProvider(mutableMapOf())
val flag = memory.boolean("feature_enabled")
flag.set(true)
println(flag.instant()) // true
📦 storage-datastore
Implementation backed by AndroidX DataStore.
📦 storage-memory
In-memory provider for tests and ephemeral use.
📦 storage-core
Abstractions and contracts (this module).
The Storage Core is one of the building blocks of Arch Toolkit, designed to provide:
This module is released under the Apache 2.0 License. See LICENSE for details.
```