Storage
net.zagart.storage — KMP scope-based storage with KSP entity generation
Modules
| Module | Artifact | Targets |
:annotations | net.zagart.storage:annotations | Android, JVM, JS |
:core | net.zagart.storage:core | Android, JVM, JS |
:compiler | net.zagart.storage:compiler | JVM (KSP processor) |
Installation
plugins {
id("com.google.devtools.ksp") version "<ksp-version>"
}
commonMain.dependencies {
implementation("net.zagart.storage:annotations:<version>")
implementation("net.zagart.storage:core:<version>")
ksp("net.zagart.storage:compiler:<version>")
}
Basic Usage
val storage = Storage.create(name = "my_app")
storage.putString("user", "name", "Alice")
storage.putBoolean("user", "notifications", true)
val name = storage.getString("user", "name", default = "Guest")
storage.observe("user") {
string("name")
boolean("notifications")
}.collect { snapshot ->
updateUI(snapshot)
}
Entity Persistence
@Entity
data class User(
@Key val id: String,
val name: String,
val age: Int,
@Embedded(prefix = "user_") val address: Address
)
storage.putEntity(user)
val user = storage.getEntity(User::class, "user-1")
storage.observeEntity(User::class, "user-1").collect { ... }
Features
| Feature | Details |
| Scope-based storage | Organize data into named scopes (e.g. "settings", "user_profile") |
| Reactive observation | Observe changes via Flow<Snapshot> using the DSL builder |
| Entity persistence | @Entity-annotated classes persisted via KSP code generation with @Embedded flattening |
| Zero-reflection | Adapters generated at compile time by KSP. No kotlin-reflect dependency |
| Auto-registration | Generated adapters discovered automatically on JVM/Android via Storage.create() |
| Type-safe keys | Define keys and defaults using ObservationBuilder DSL |
| Compose-agnostic | Pure Kotlin — no Compose dependency |
Platform Notes
| Platform | create() context | Auto-registration |
| Android | Requires Context as platformContext | Yes (via Class.forName) |
| JVM | platformContext = null | Yes (via Class.forName) |
| JS | platformContext = null | Explicit StorageEntities().register() required |
Versioning & Releases
- Bump version in
core/build.gradle.kts
- Run
./gradlew :core:publishAllPublicationsToLocalRepository
- Tag and push:
git tag v1.1.18 && git push origin v1.1.18
- Maven Central deployment happens automatically via daily CI