From 9aae858eece808422bf65e5b3b19d28d191dc138 Mon Sep 17 00:00:00 2001 From: mramotar_dbx Date: Thu, 7 Dec 2023 22:36:29 -0500 Subject: [PATCH] Fix formatting errors --- .../store/cache5/StoreMultiCache.kt | 2 +- .../store/core5/InsertionStrategy.kt | 2 +- .../store/core5/KeyProvider.kt | 2 +- .../store/core5/StoreData.kt | 3 +-- .../store/core5/StoreKey.kt | 2 +- .../store/paging5/LaunchPagingStore.kt | 21 ++++++++++--------- .../store/paging5/LaunchPagingStoreTests.kt | 17 ++++++++++++--- .../store/paging5/util/FakePostApi.kt | 3 +-- .../store/paging5/util/FakePostDatabase.kt | 4 +--- .../paging5/util/FeedGetRequestResult.kt | 2 +- .../store/paging5/util/PostApi.kt | 2 +- .../store/paging5/util/PostData.kt | 3 --- .../store/paging5/util/PostDatabase.kt | 2 +- .../paging5/util/PostGetRequestResult.kt | 2 +- .../store/paging5/util/PostKey.kt | 1 - .../paging5/util/PostPutRequestResult.kt | 2 +- .../store/paging5/util/PostStoreFactory.kt | 4 +--- .../store/store5/impl/extensions/store.kt | 16 +++++++++----- 18 files changed, 49 insertions(+), 41 deletions(-) diff --git a/cache/src/commonMain/kotlin/org/mobilenativefoundation/store/cache5/StoreMultiCache.kt b/cache/src/commonMain/kotlin/org/mobilenativefoundation/store/cache5/StoreMultiCache.kt index baa7db834..7003bc582 100644 --- a/cache/src/commonMain/kotlin/org/mobilenativefoundation/store/cache5/StoreMultiCache.kt +++ b/cache/src/commonMain/kotlin/org/mobilenativefoundation/store/cache5/StoreMultiCache.kt @@ -150,4 +150,4 @@ class StoreMultiCache, Single : StoreData.Single> { fun fromCollection(key: StoreKey.Collection, value: Single): StoreKey.Single fun fromSingle(key: StoreKey.Single, value: Single): StoreKey.Collection -} \ No newline at end of file +} diff --git a/core/src/commonMain/kotlin/org/mobilenativefoundation/store/core5/StoreData.kt b/core/src/commonMain/kotlin/org/mobilenativefoundation/store/core5/StoreData.kt index e163605bb..ca285a6a2 100644 --- a/core/src/commonMain/kotlin/org/mobilenativefoundation/store/core5/StoreData.kt +++ b/core/src/commonMain/kotlin/org/mobilenativefoundation/store/core5/StoreData.kt @@ -1,6 +1,5 @@ package org.mobilenativefoundation.store.core5 - /** * An interface that defines items that can be uniquely identified. * Every item that implements the [StoreData] interface must have a means of identification. @@ -32,4 +31,4 @@ interface StoreData { */ fun insertItems(strategy: InsertionStrategy, items: List): Collection } -} \ No newline at end of file +} diff --git a/core/src/commonMain/kotlin/org/mobilenativefoundation/store/core5/StoreKey.kt b/core/src/commonMain/kotlin/org/mobilenativefoundation/store/core5/StoreKey.kt index 245ce05a9..9026c9dd0 100644 --- a/core/src/commonMain/kotlin/org/mobilenativefoundation/store/core5/StoreKey.kt +++ b/core/src/commonMain/kotlin/org/mobilenativefoundation/store/core5/StoreKey.kt @@ -58,4 +58,4 @@ interface StoreKey { interface Filter { operator fun invoke(items: List): List } -} \ No newline at end of file +} diff --git a/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStore.kt b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStore.kt index ceb8b3619..563800138 100644 --- a/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStore.kt +++ b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStore.kt @@ -1,19 +1,25 @@ @file:Suppress("UNCHECKED_CAST") - package org.mobilenativefoundation.store.paging5 - import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.drop +import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import org.mobilenativefoundation.store.core5.StoreData import org.mobilenativefoundation.store.core5.StoreKey -import org.mobilenativefoundation.store.store5.* +import org.mobilenativefoundation.store.store5.ExperimentalStoreApi +import org.mobilenativefoundation.store.store5.MutableStore +import org.mobilenativefoundation.store.store5.Store +import org.mobilenativefoundation.store.store5.StoreReadRequest +import org.mobilenativefoundation.store.store5.StoreReadResponse private class StopProcessingException : Exception() - /** * Initializes and returns a [StateFlow] that reflects the state of the Store, updating by a flow of provided keys. * @param scope A [CoroutineScope]. @@ -28,7 +34,6 @@ private fun , Output : StoreData> launchPagingS ): StateFlow> { val stateFlow = MutableStateFlow>(StoreReadResponse.Initial) - scope.launch { try { @@ -50,9 +55,7 @@ private fun , Output : StoreData> launchPagingS throw StopProcessingException() } } - } catch (_: StopProcessingException) { - } keys.drop(1).collect { key -> @@ -93,7 +96,6 @@ fun , Output : StoreData> MutableStore, Output : StoreData> joinData( key: Key, prevResponse: StoreReadResponse, @@ -109,4 +111,3 @@ private fun , Output : StoreData> jo val joinedOutput = (lastOutput?.insertItems(key.insertionStrategy, currentData.items) ?: currentData) as Output return StoreReadResponse.Data(joinedOutput, currentResponse.origin) } - diff --git a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStoreTests.kt b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStoreTests.kt index 8fbcb903d..8dc2b78d2 100644 --- a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStoreTests.kt +++ b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStoreTests.kt @@ -7,8 +7,20 @@ import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test -import org.mobilenativefoundation.store.paging5.util.* -import org.mobilenativefoundation.store.store5.* +import org.mobilenativefoundation.store.paging5.util.FakePostApi +import org.mobilenativefoundation.store.paging5.util.FakePostDatabase +import org.mobilenativefoundation.store.paging5.util.PostApi +import org.mobilenativefoundation.store.paging5.util.PostData +import org.mobilenativefoundation.store.paging5.util.PostDatabase +import org.mobilenativefoundation.store.paging5.util.PostKey +import org.mobilenativefoundation.store.paging5.util.PostPutRequestResult +import org.mobilenativefoundation.store.paging5.util.PostStoreFactory +import org.mobilenativefoundation.store.store5.ExperimentalStoreApi +import org.mobilenativefoundation.store.store5.MutableStore +import org.mobilenativefoundation.store.store5.StoreReadRequest +import org.mobilenativefoundation.store.store5.StoreReadResponse +import org.mobilenativefoundation.store.store5.StoreReadResponseOrigin +import org.mobilenativefoundation.store.store5.StoreWriteRequest import kotlin.test.assertEquals import kotlin.test.assertIs @@ -132,7 +144,6 @@ class LaunchPagingStoreTests { assertIs(data2) assertEquals("2", data2.title) - store.write(StoreWriteRequest.of(PostKey.Single("2"), PostData.Post("2", "2-modified"))) val cached3 = store.stream(StoreReadRequest.cached(PostKey.Single("2"), refresh = false)) diff --git a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/FakePostApi.kt b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/FakePostApi.kt index be6ae1076..7764cc65e 100644 --- a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/FakePostApi.kt +++ b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/FakePostApi.kt @@ -33,5 +33,4 @@ class FakePostApi : PostApi { posts.put(post.id, post) return PostPutRequestResult.Data(post) } - -} \ No newline at end of file +} diff --git a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/FakePostDatabase.kt b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/FakePostDatabase.kt index 6eab782c0..a126c9b3f 100644 --- a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/FakePostDatabase.kt +++ b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/FakePostDatabase.kt @@ -30,7 +30,5 @@ class FakePostDatabase(private val userId: String) : PostDatabase { override fun findFeedByUserId(cursor: String?, size: Int): PostData.Feed? { val feed = feeds[userId] return feed - } - -} \ No newline at end of file +} diff --git a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/FeedGetRequestResult.kt b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/FeedGetRequestResult.kt index 8e6081a8d..e1d13e50e 100644 --- a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/FeedGetRequestResult.kt +++ b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/FeedGetRequestResult.kt @@ -7,4 +7,4 @@ sealed class FeedGetRequestResult { data class Message(val error: String) : Error() data class Exception(val error: kotlin.Exception) : Error() } -} \ No newline at end of file +} diff --git a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostApi.kt b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostApi.kt index fd733e301..90d87e601 100644 --- a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostApi.kt +++ b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostApi.kt @@ -4,4 +4,4 @@ interface PostApi { suspend fun get(postId: String): PostGetRequestResult suspend fun get(cursor: String?, size: Int): FeedGetRequestResult suspend fun put(post: PostData.Post): PostPutRequestResult -} \ No newline at end of file +} diff --git a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostData.kt b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostData.kt index be2a911c9..ad6b05d28 100644 --- a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostData.kt +++ b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostData.kt @@ -33,6 +33,3 @@ sealed class PostData : StoreData { } } } - - - diff --git a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostDatabase.kt b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostDatabase.kt index 38b3d40b0..d8ae595c9 100644 --- a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostDatabase.kt +++ b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostDatabase.kt @@ -5,4 +5,4 @@ interface PostDatabase { fun add(feed: PostData.Feed) fun findPostByPostId(postId: String): PostData.Post? fun findFeedByUserId(cursor: String?, size: Int): PostData.Feed? -} \ No newline at end of file +} diff --git a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostGetRequestResult.kt b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostGetRequestResult.kt index f8f3e31ac..d481f661f 100644 --- a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostGetRequestResult.kt +++ b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostGetRequestResult.kt @@ -7,4 +7,4 @@ sealed class PostGetRequestResult { data class Message(val error: String) : Error() data class Exception(val error: kotlin.Exception) : Error() } -} \ No newline at end of file +} diff --git a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostKey.kt b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostKey.kt index df5f0254c..451c5e0b9 100644 --- a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostKey.kt +++ b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostKey.kt @@ -15,5 +15,4 @@ sealed class PostKey : StoreKey { data class Single( override val id: String ) : StoreKey.Single, PostKey() - } diff --git a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostPutRequestResult.kt b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostPutRequestResult.kt index 8fd415099..fdf855dbb 100644 --- a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostPutRequestResult.kt +++ b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostPutRequestResult.kt @@ -7,4 +7,4 @@ sealed class PostPutRequestResult { data class Message(val error: String) : Error() data class Exception(val error: kotlin.Exception) : Error() } -} \ No newline at end of file +} diff --git a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostStoreFactory.kt b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostStoreFactory.kt index f6d201a56..40ef9d872 100644 --- a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostStoreFactory.kt +++ b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/util/PostStoreFactory.kt @@ -35,7 +35,6 @@ class PostStoreFactory(private val api: PostApi, private val db: PostDatabase) { throw Throwable(result.error) } } - } is PostKey.Cursor -> { @@ -121,7 +120,6 @@ class PostStoreFactory(private val api: PostApi, private val db: PostDatabase) { val cursor = (floor(id.toDouble() / 10) * 10) + 1 return PostKey.Cursor(cursor.toInt().toString(), 10) } - } private fun createMemoryCache(): Cache = @@ -137,4 +135,4 @@ class PostStoreFactory(private val api: PostApi, private val db: PostDatabase) { updater = createUpdater(), bookkeeper = null ) -} \ No newline at end of file +} diff --git a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/extensions/store.kt b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/extensions/store.kt index d72a62859..21ab44e54 100644 --- a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/extensions/store.kt +++ b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/extensions/store.kt @@ -2,7 +2,13 @@ package org.mobilenativefoundation.store.store5.impl.extensions import kotlinx.coroutines.flow.filterNot import kotlinx.coroutines.flow.first -import org.mobilenativefoundation.store.store5.* +import org.mobilenativefoundation.store.store5.Bookkeeper +import org.mobilenativefoundation.store.store5.ExperimentalStoreApi +import org.mobilenativefoundation.store.store5.MutableStore +import org.mobilenativefoundation.store.store5.Store +import org.mobilenativefoundation.store.store5.StoreReadRequest +import org.mobilenativefoundation.store.store5.StoreReadResponse +import org.mobilenativefoundation.store.store5.Updater import org.mobilenativefoundation.store.store5.impl.RealMutableStore import org.mobilenativefoundation.store.store5.impl.RealStore @@ -30,6 +36,7 @@ suspend fun Store.fresh(key: Key) = .first() .requireData() +@OptIn(ExperimentalStoreApi::class) @Suppress("UNCHECKED_CAST") fun Store.asMutableStore( updater: Updater, @@ -45,17 +52,16 @@ fun Store< ) } - @OptIn(ExperimentalStoreApi::class) -suspend fun MutableStore.get(key: Key) = +suspend fun MutableStore.get(key: Key) = stream(StoreReadRequest.cached(key, refresh = false)) .filterNot { it is StoreReadResponse.Loading || it is StoreReadResponse.NoNewData } .first() .requireData() @OptIn(ExperimentalStoreApi::class) -suspend fun MutableStore.fresh(key: Key) = +suspend fun MutableStore.fresh(key: Key) = stream(StoreReadRequest.fresh(key)) .filterNot { it is StoreReadResponse.Loading || it is StoreReadResponse.NoNewData } .first() - .requireData() \ No newline at end of file + .requireData()