Yokan / rebuild
Course 1 8624561

ProfileId.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/domain/ProfileId.kt

implementation23 lines
1package eu.friedcutlet.yokan.domain23import kotlinx.serialization.Serializable4import kotlin.jvm.JvmInline5import kotlin.random.Random67@Serializable8@JvmInline9value class ProfileId(val value: String) {10    init { require(value == "default" || Regex("p_[0-9a-f]{32}").matches(value)) { "Invalid profile ID" } }11    companion object {12        val Default = ProfileId("default")13        fun random(): ProfileId = ProfileId("p_" + Random.nextBytes(16).toHexString())14    }15}1617/** Only stable IDs enter paths/keys. Default aliases legacy locations; no adoption copy is needed. */18data class ProfileStorageNamespace(val id: ProfileId) {19    val relativeRoot: String? get() = if (id == ProfileId.Default) null else "profiles/${id.value}"20    val databaseRelativePath: String get() = relativeRoot?.let { "$it/yokan-room.db" } ?: "yokan-room.db"21    val browserSnapshotKey: String get() = if (id == ProfileId.Default) "yokan-database-v1" else "yokan-database-v1:${id.value}"22    fun ownedRoot(base: String): String = relativeRoot?.let { "${base.trimEnd('/')}/$it" } ?: base.trimEnd('/')23}24

Search chapters, reference and source filenames.