Storage

net.zagart.storage — KMP scope-based storage with KSP entity generation

Modules

ModuleArtifactTargets
:annotationsnet.zagart.storage:annotationsAndroid, JVM, JS
:corenet.zagart.storage:coreAndroid, JVM, JS
:compilernet.zagart.storage:compilerJVM (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")

// Write
storage.putString("user", "name", "Alice")
storage.putBoolean("user", "notifications", true)

// Read
val name = storage.getString("user", "name", default = "Guest")

// Observe changes
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
)

// Write
storage.putEntity(user)

// Read
val user = storage.getEntity(User::class, "user-1")

// Observe
storage.observeEntity(User::class, "user-1").collect { ... }

// Auto-registration is handled automatically
// on JVM/Android via Storage.create().
// No manual init needed.

Features

FeatureDetails
Scope-based storageOrganize data into named scopes (e.g. "settings", "user_profile")
Reactive observationObserve changes via Flow<Snapshot> using the DSL builder
Entity persistence@Entity-annotated classes persisted via KSP code generation with @Embedded flattening
Zero-reflectionAdapters generated at compile time by KSP. No kotlin-reflect dependency
Auto-registrationGenerated adapters discovered automatically on JVM/Android via Storage.create()
Type-safe keysDefine keys and defaults using ObservationBuilder DSL
Compose-agnosticPure Kotlin — no Compose dependency

Platform Notes

Platformcreate() contextAuto-registration
AndroidRequires Context as platformContextYes (via Class.forName)
JVMplatformContext = nullYes (via Class.forName)
JSplatformContext = nullExplicit StorageEntities().register() required

Versioning & Releases

  1. Bump version in core/build.gradle.kts
  2. Run ./gradlew :core:publishAllPublicationsToLocalRepository
  3. Tag and push: git tag v1.1.18 && git push origin v1.1.18
  4. Maven Central deployment happens automatically via daily CI
← Back