-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Write + Conflict Resolution (#496)
* Stub Store write Signed-off-by: mramotar <[email protected]> * Format Signed-off-by: mramotar <[email protected]> * Compile Signed-off-by: mramotar <[email protected]> * Fix tests Signed-off-by: mramotar <[email protected]> * Stash M1 Signed-off-by: mramotar <[email protected]> * Make Updater and Bookkeeper optional Signed-off-by: Matt Ramotar <[email protected]> * Add conflict resolution Signed-off-by: Matt Ramotar <[email protected]> * Cover simple write Signed-off-by: Matt Ramotar <[email protected]> * Add MutableStore Signed-off-by: mramotar <[email protected]> * Add RealMutableStore Signed-off-by: mramotar <[email protected]> * Update workflows Signed-off-by: mramotar <[email protected]> * Format Signed-off-by: mramotar <[email protected]> * Remove references to Market Signed-off-by: mramotar <[email protected]> * Remove Converter interface Signed-off-by: mramotar <[email protected]> * Move Converter typealias Signed-off-by: mramotar <[email protected]> * Remove Google copyright Signed-off-by: mramotar <[email protected]> * Update CHANGELOG.md Signed-off-by: mramotar <[email protected]> Signed-off-by: mramotar <[email protected]> Signed-off-by: Matt Ramotar <[email protected]>
- Loading branch information
1 parent
1e09dac
commit ab03aa1
Showing
67 changed files
with
1,722 additions
and
797 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/Bookkeeper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.mobilenativefoundation.store.store5 | ||
|
||
import org.mobilenativefoundation.store.store5.impl.RealBookkeeper | ||
import org.mobilenativefoundation.store.store5.impl.RealMutableStore | ||
import org.mobilenativefoundation.store.store5.impl.extensions.now | ||
|
||
/** | ||
* Tracks when local changes fail to sync with network. | ||
* @see [RealMutableStore] usage to persist write request failures and eagerly resolve conflicts before completing a read request. | ||
*/ | ||
|
||
interface Bookkeeper<Key : Any> { | ||
suspend fun getLastFailedSync(key: Key): Long? | ||
suspend fun setLastFailedSync(key: Key, timestamp: Long = now()): Boolean | ||
suspend fun clear(key: Key): Boolean | ||
suspend fun clearAll(): Boolean | ||
|
||
companion object { | ||
fun <Key : Any> by( | ||
getLastFailedSync: suspend (key: Key) -> Long?, | ||
setLastFailedSync: suspend (key: Key, timestamp: Long) -> Boolean, | ||
clear: suspend (key: Key) -> Boolean, | ||
clearAll: suspend () -> Boolean | ||
): Bookkeeper<Key> = RealBookkeeper(getLastFailedSync, setLastFailedSync, clear, clearAll) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/Clear.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.mobilenativefoundation.store.store5 | ||
|
||
interface Clear { | ||
interface Key<Key : Any> { | ||
/** | ||
* Purge a particular entry from memory and disk cache. | ||
* Persistent storage will only be cleared if a delete function was passed to | ||
* [StoreBuilder.persister] or [StoreBuilder.nonFlowingPersister] when creating the [Store]. | ||
*/ | ||
suspend fun clear(key: Key) | ||
} | ||
|
||
interface All { | ||
/** | ||
* Purge all entries from memory and disk cache. | ||
* Persistent storage will only be cleared if a clear function was passed to | ||
* [StoreBuilder.persister] or [StoreBuilder.nonFlowingPersister] when creating the [Store]. | ||
*/ | ||
@ExperimentalStoreApi | ||
suspend fun clear() | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/ItemValidator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.mobilenativefoundation.store.store5 | ||
|
||
import org.mobilenativefoundation.store.store5.impl.RealItemValidator | ||
|
||
/** | ||
* Enables custom validation of [Store] items. | ||
* @see [StoreReadRequest] | ||
*/ | ||
interface ItemValidator<CommonRepresentation : Any> { | ||
/** | ||
* Determines whether a [Store] item is valid. | ||
* If invalid, [MutableStore] will get the latest network value using [Fetcher]. | ||
* [MutableStore] will not validate network responses. | ||
*/ | ||
suspend fun isValid(item: CommonRepresentation): Boolean | ||
|
||
companion object { | ||
fun <CommonRepresentation : Any> by( | ||
validator: suspend (item: CommonRepresentation) -> Boolean | ||
): ItemValidator<CommonRepresentation> = RealItemValidator(validator) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/MutableStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.mobilenativefoundation.store.store5 | ||
|
||
interface MutableStore<Key : Any, CommonRepresentation : Any> : | ||
Read.StreamWithConflictResolution<Key, CommonRepresentation>, | ||
Write<Key, CommonRepresentation>, | ||
Write.Stream<Key, CommonRepresentation>, | ||
Clear.Key<Key>, | ||
Clear |
6 changes: 6 additions & 0 deletions
6
store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/OnFetcherCompletion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.mobilenativefoundation.store.store5 | ||
|
||
data class OnFetcherCompletion<NetworkRepresentation : Any>( | ||
val onSuccess: (FetcherResult.Data<NetworkRepresentation>) -> Unit, | ||
val onFailure: (FetcherResult.Error) -> Unit | ||
) |
6 changes: 6 additions & 0 deletions
6
store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/OnUpdaterCompletion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.mobilenativefoundation.store.store5 | ||
|
||
data class OnUpdaterCompletion<NetworkWriteResponse : Any>( | ||
val onSuccess: (UpdaterResult.Success) -> Unit, | ||
val onFailure: (UpdaterResult.Error) -> Unit | ||
) |
17 changes: 17 additions & 0 deletions
17
store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/Read.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.mobilenativefoundation.store.store5 | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface Read { | ||
interface Stream<Key : Any, CommonRepresentation : Any> { | ||
/** | ||
* Return a flow for the given key | ||
* @param request - see [StoreReadRequest] for configurations | ||
*/ | ||
fun stream(request: StoreReadRequest<Key>): Flow<StoreReadResponse<CommonRepresentation>> | ||
} | ||
|
||
interface StreamWithConflictResolution<Key : Any, CommonRepresentation : Any> { | ||
fun <NetworkWriteResponse : Any> stream(request: StoreReadRequest<Key>): Flow<StoreReadResponse<CommonRepresentation>> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.