diff --git a/CHANGELOG.md b/CHANGELOG.md index 490aa1884ac..90662b6203b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ * `Startup`: * `Launcher`: * Improvements in `StartLauncherPlugin#start` methods +* `Repos`: + * `Ktor`: + * `Client`: + * All clients repos got opportunity to customize their flows ## 0.16.5 diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorCRUDRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorCRUDRepoClient.kt index 51f79547dcc..811ce434cd1 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorCRUDRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorCRUDRepoClient.kt @@ -1,12 +1,17 @@ package dev.inmo.micro_utils.repos.ktor.client.crud +import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.pagination.PaginationResult import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.ktor.common.crud.deletedObjectsIdsFlowRouting +import dev.inmo.micro_utils.repos.ktor.common.crud.newObjectsFlowRouting +import dev.inmo.micro_utils.repos.ktor.common.crud.updatedObjectsFlowRouting import io.ktor.client.HttpClient import io.ktor.http.ContentType import io.ktor.util.reflect.TypeInfo import io.ktor.util.reflect.typeInfo +import kotlinx.coroutines.flow.Flow import kotlinx.serialization.* class KtorCRUDRepoClient ( @@ -21,6 +26,15 @@ class KtorCRUDRepoClient ( baseUrl: String, httpClient: HttpClient, contentType: ContentType, + newObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, newObjectsFlowRouting), + ), + updatedObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, updatedObjectsFlowRouting), + ), + deletedObjectsIdsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, deletedObjectsIdsFlowRouting), + ), noinline idSerializer: suspend (IdType) -> String ) = KtorCRUDRepoClient( KtorReadCRUDRepoClient( @@ -35,7 +49,10 @@ class KtorCRUDRepoClient ( KtorWriteCrudRepoClient( baseUrl, httpClient, - contentType + contentType, + newObjectsFlow, + updatedObjectsFlow, + deletedObjectsIdsFlow ) ) @@ -44,11 +61,23 @@ class KtorCRUDRepoClient ( subpart: String, httpClient: HttpClient, contentType: ContentType, + newObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, newObjectsFlowRouting), + ), + updatedObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, updatedObjectsFlowRouting), + ), + deletedObjectsIdsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, deletedObjectsIdsFlowRouting), + ), noinline idSerializer: suspend (IdType) -> String ) = KtorCRUDRepoClient( buildStandardUrl(baseUrl, subpart), httpClient, contentType, + newObjectsFlow, + updatedObjectsFlow, + deletedObjectsIdsFlow, idSerializer ) } @@ -80,11 +109,23 @@ inline fun KtorCRUDRepo subpart: String, httpClient: HttpClient, contentType: ContentType, + newObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, newObjectsFlowRouting), + ), + updatedObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, updatedObjectsFlowRouting), + ), + deletedObjectsIdsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, deletedObjectsIdsFlowRouting), + ), noinline idSerializer: suspend (IdType) -> String ) = KtorCRUDRepoClient( buildStandardUrl(baseUrl, subpart), httpClient, contentType, + newObjectsFlow, + updatedObjectsFlow, + deletedObjectsIdsFlow, idSerializer ) diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorWriteCrudRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorWriteCrudRepoClient.kt index 76270d80271..3fd3de7f319 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorWriteCrudRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorWriteCrudRepoClient.kt @@ -53,19 +53,22 @@ class KtorWriteCrudRepoClient ( inline operator fun invoke( baseUrl: String, httpClient: HttpClient, - contentType: ContentType + contentType: ContentType, + newObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, newObjectsFlowRouting), + ), + updatedObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, updatedObjectsFlowRouting), + ), + deletedObjectsIdsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, deletedObjectsIdsFlowRouting), + ), ) = KtorWriteCrudRepoClient( baseUrl, httpClient, - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, newObjectsFlowRouting), - ), - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, updatedObjectsFlowRouting), - ), - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, deletedObjectsIdsFlowRouting), - ), + newObjectsFlow, + updatedObjectsFlow, + deletedObjectsIdsFlow, { contentType(contentType) setBody(it) diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorKeyValueRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorKeyValueRepoClient.kt index b0f6aca4ad3..c6f2b27d9c2 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorKeyValueRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorKeyValueRepoClient.kt @@ -1,10 +1,14 @@ package dev.inmo.micro_utils.repos.ktor.client.key.value +import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.ktor.common.key_value.onNewValueRoute +import dev.inmo.micro_utils.repos.ktor.common.key_value.onValueRemovedRoute import io.ktor.client.HttpClient import io.ktor.http.ContentType import io.ktor.http.encodeURLQueryComponent +import kotlinx.coroutines.flow.Flow import kotlinx.serialization.* class KtorKeyValueRepoClient ( @@ -20,6 +24,12 @@ class KtorKeyValueRepoClient ( httpClient: HttpClient, contentType: ContentType, noinline idSerializer: suspend (Key) -> String, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), noinline valueSerializer: suspend (Value) -> String ) = KtorKeyValueRepoClient( KtorReadKeyValueRepoClient( @@ -28,7 +38,9 @@ class KtorKeyValueRepoClient ( KtorWriteKeyValueRepoClient( baseUrl, httpClient, - contentType + contentType, + onNewValue, + onValueRemoved ) ) inline operator fun invoke( @@ -37,12 +49,20 @@ class KtorKeyValueRepoClient ( httpClient: HttpClient, contentType: ContentType, noinline idSerializer: suspend (Key) -> String, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), noinline valueSerializer: suspend (Value) -> String ) = KtorKeyValueRepoClient( buildStandardUrl(baseUrl, subpart), httpClient, contentType, idSerializer, + onNewValue, + onValueRemoved, valueSerializer ) } diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorWriteKeyValueRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorWriteKeyValueRepoClient.kt index b8c2ca06f5e..12de3b5538a 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorWriteKeyValueRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorWriteKeyValueRepoClient.kt @@ -60,17 +60,19 @@ class KtorWriteKeyValueRepoClient( inline operator fun invoke( baseUrl: String, httpClient: HttpClient, - contentType: ContentType + contentType: ContentType, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), ) = KtorWriteKeyValueRepoClient( baseUrl, httpClient, contentType, - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, onNewValueRoute), - ), - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, onValueRemovedRoute), - ), + onNewValue, + onValueRemoved, typeInfo>(), typeInfo>(), typeInfo>() diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorKeyValuesRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorKeyValuesRepoClient.kt index 3913fecd742..467b7a664ac 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorKeyValuesRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorKeyValuesRepoClient.kt @@ -1,10 +1,15 @@ package dev.inmo.micro_utils.repos.ktor.client.key.values +import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.ktor.common.one_to_many.onDataClearedRoute +import dev.inmo.micro_utils.repos.ktor.common.one_to_many.onNewValueRoute +import dev.inmo.micro_utils.repos.ktor.common.one_to_many.onValueRemovedRoute import io.ktor.client.HttpClient import io.ktor.http.ContentType import io.ktor.http.encodeURLQueryComponent +import kotlinx.coroutines.flow.Flow import kotlinx.serialization.* class KtorKeyValuesRepoClient ( @@ -20,6 +25,15 @@ class KtorKeyValuesRepoClient ( httpClient: HttpClient, contentType: ContentType, noinline keySerializer: suspend (Key) -> String, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), + onDataCleared: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onDataClearedRoute), + ), noinline valueSerializer: suspend (Value) -> String ) = KtorKeyValuesRepoClient( KtorReadKeyValuesRepoClient( @@ -32,7 +46,10 @@ class KtorKeyValuesRepoClient ( KtorWriteKeyValuesRepoClient( baseUrl, httpClient, - contentType + contentType, + onNewValue, + onValueRemoved, + onDataCleared ) ) inline operator fun invoke( @@ -41,12 +58,24 @@ class KtorKeyValuesRepoClient ( httpClient: HttpClient, contentType: ContentType, noinline keySerializer: suspend (Key) -> String, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), + onDataCleared: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onDataClearedRoute), + ), noinline valueSerializer: suspend (Value) -> String ) = KtorKeyValuesRepoClient( buildStandardUrl(baseUrl, subpart), httpClient, contentType, keySerializer, + onNewValue, + onValueRemoved, + onDataCleared, valueSerializer ) } @@ -59,13 +88,25 @@ inline fun KtorKeyValuesRepoClient( keySerializer: SerializationStrategy, valueSerializer: SerializationStrategy, serialFormat: StringFormat, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), + onDataCleared: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onDataClearedRoute), + ), ) = KtorKeyValuesRepoClient( baseUrl, httpClient, contentType, { serialFormat.encodeToString(keySerializer, it).encodeURLQueryComponent() - } + }, + onNewValue, + onValueRemoved, + onDataCleared ) { serialFormat.encodeToString(valueSerializer, it).encodeURLQueryComponent() } @@ -77,13 +118,25 @@ inline fun KtorKeyValuesRepoClient( keySerializer: SerializationStrategy, valueSerializer: SerializationStrategy, serialFormat: BinaryFormat, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), + onDataCleared: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onDataClearedRoute), + ), ) = KtorKeyValuesRepoClient( baseUrl, httpClient, contentType, { serialFormat.encodeHex(keySerializer, it) - } + }, + onNewValue, + onValueRemoved, + onDataCleared ) { serialFormat.encodeHex(valueSerializer, it) } diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorWriteKeyValuesRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorWriteKeyValuesRepoClient.kt index 900ae7612cc..37f14d66b49 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorWriteKeyValuesRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorWriteKeyValuesRepoClient.kt @@ -84,20 +84,23 @@ class KtorWriteKeyValuesRepoClient( inline operator fun invoke( baseUrl: String, httpClient: HttpClient, - contentType: ContentType + contentType: ContentType, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), + onDataCleared: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onDataClearedRoute), + ), ) = KtorWriteKeyValuesRepoClient( baseUrl, httpClient, contentType, - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, onNewValueRoute), - ), - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, onValueRemovedRoute), - ), - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, onDataClearedRoute), - ), + onNewValue, + onValueRemoved, + onDataCleared, typeInfo(), typeInfo(), typeInfo>>()