less annotations to god of lessannotations

This commit is contained in:
InsanusMokrassar 2020-10-15 17:33:35 +06:00
parent f8a8808508
commit 87230d010c
32 changed files with 25 additions and 52 deletions

View File

@ -9,7 +9,6 @@ import kotlin.js.JsExport
typealias ByteArrayAllocator = () -> ByteArray
@JsExport
val ByteArray.asAllocator: ByteArrayAllocator
get() = { this }

View File

@ -3,8 +3,10 @@ package dev.inmo.micro_utils.coroutines
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.flow.*
import kotlin.js.JsExport
import kotlin.js.JsName
@JsExport
@JsName("BroadcastFlowFactory")
@Suppress("FunctionName")
fun <T> BroadcastFlow(
internalChannelSize: Int = Channel.BUFFERED

View File

@ -5,6 +5,7 @@ import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.*
import kotlin.js.JsExport
import kotlin.js.JsName
@JsExport
class BroadcastStateFlow<T> internal constructor(
@ -25,6 +26,7 @@ fun <T> BroadcastChannel<T>.asStateFlow(value: T, scope: CoroutineScope): StateF
}
@JsExport
@JsName("nullableAsStateFlow")
fun <T> BroadcastChannel<T?>.asStateFlow(scope: CoroutineScope): StateFlow<T?> = asStateFlow(null, scope)
@JsExport
@ -35,5 +37,6 @@ fun <T> broadcastStateFlow(initial: T, scope: CoroutineScope, channelSize: Int =
}
@JsExport
@JsName("nullableBroadcastStateFlow")
fun <T> broadcastStateFlow(scope: CoroutineScope, channelSize: Int = Channel.BUFFERED) = broadcastStateFlow<T?>(null, scope, channelSize)

View File

@ -2,8 +2,6 @@ package dev.inmo.micro_utils.coroutines
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred
import kotlin.js.JsExport
@JsExport
val <T> T.asDeferred: Deferred<T>
get() = CompletableDeferred(this)

View File

@ -6,7 +6,6 @@ import kotlin.js.JsExport
/**
* Call this method in case you need to do something in common thread (like reading of file in JVM)
*/
@JsExport
suspend fun <T> doOutsideOfCoroutine(block: () -> T): T = suspendCoroutine {
try {
it.resume(block())

View File

@ -12,7 +12,6 @@ typealias ExceptionHandler<T> = suspend (Throwable) -> T
* @param [onException] Will be called when happen exception inside of [block]. By default will throw exception - this
* exception will be available for catching
*/
@JsExport
suspend inline fun <T> safely(
noinline onException: ExceptionHandler<T> = { throw it },
noinline block: suspend CoroutineScope.() -> T

View File

@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.serialization.DeserializationStrategy
import kotlin.js.JsExport
import kotlin.js.JsName
/**
* @param checkReconnection This lambda will be called when it is required to reconnect to websocket to establish
@ -63,6 +64,7 @@ inline fun <T> HttpClient.createStandardWebsocketFlow(
* connection. Must return true in case if must be reconnected. By default always reconnecting
*/
@JsExport
@JsName("createStandardWebsocketFlowWithDeserializer")
inline fun <T> HttpClient.createStandardWebsocketFlow(
url: String,
crossinline checkReconnection: (Throwable?) -> Boolean = { true },

View File

@ -9,7 +9,6 @@ import kotlin.js.JsExport
typealias BodyPair<T> = Pair<SerializationStrategy<T>, T>
@JsExport
suspend fun <ResultType> HttpClient.uniget(
url: String,
resultDeserializer: DeserializationStrategy<ResultType>
@ -26,7 +25,6 @@ fun <T> SerializationStrategy<T>.encodeUrlQueryValue(value: T) = standardKtorSer
value
)
@JsExport
suspend fun <BodyType, ResultType> HttpClient.unipost(
url: String,
bodyInfo: BodyPair<BodyType>,

View File

@ -1,6 +1,7 @@
package dev.inmo.micro_utils.ktor.common
import kotlin.js.JsExport
import kotlin.js.JsName
@JsExport
fun buildStandardUrl(
@ -12,6 +13,7 @@ fun buildStandardUrl(
)
@JsExport
@JsName("buildStandardUrlWithParametersList")
fun buildStandardUrl(
basePart: String,
subpart: String,
@ -21,6 +23,7 @@ fun buildStandardUrl(
)
@JsExport
@JsName("buildStandardUrlWithParametersVararg")
fun buildStandardUrl(
basePart: String,
subpart: String,

View File

@ -4,7 +4,6 @@ import kotlin.js.JsExport
private val schemaRegex = Regex("^[^:]*://")
@JsExport
val String.asCorrectWebSocketUrl: String
get() = if (startsWith("ws")) {
this

View File

@ -5,14 +5,12 @@ import kotlin.js.JsExport
typealias FromToDateTime = Pair<DateTime?, DateTime?>
@JsExport
val FromToDateTime.asFromToUrlPart: QueryParams
get() = mapOf(
"from" to first ?.unixMillis ?.toString(),
"to" to second ?.unixMillis ?.toString()
)
@JsExport
val QueryParams.extractFromToDateTime: FromToDateTime
get() = FromToDateTime(
get("from") ?.toDoubleOrNull() ?.let { DateTime(it) },

View File

@ -1,15 +1,14 @@
package dev.inmo.micro_utils.ktor.common
import kotlin.js.JsExport
import kotlin.js.JsName
typealias QueryParam = Pair<String, String?>
typealias QueryParams = Map<String, String?>
@JsExport
val QueryParams.asUrlQuery: String
get() = keys.joinToString("&") { "${it}${get(it) ?.let { value -> "=$value" }}" }
@JsExport
val List<QueryParam>.asUrlQuery: String
get() = joinToString("&") { (key, value) -> "${key}${value ?.let { _ -> "=$value" }}" }
@ -19,11 +18,11 @@ fun String.includeQueryParams(
): String = "$this${if(queryParams.isNotEmpty()) "${if (contains("?")) "&" else "?"}${queryParams.asUrlQuery}" else ""}"
@JsExport
@JsName("includeQueryParamsWithList")
fun String.includeQueryParams(
queryParams: List<QueryParam>
): String = "$this${if (contains("?")) "&" else "?"}${queryParams.asUrlQuery}"
@JsExport
val String.parseUrlQuery: QueryParams
get() = split("&").map {
it.split("=").let { pair ->

View File

@ -1,6 +1,7 @@
package dev.inmo.micro_utils.pagination
import kotlin.js.JsExport
import kotlin.js.JsName
import kotlin.math.ceil
import kotlin.math.floor
@ -27,7 +28,6 @@ interface Pagination {
/**
* First number in index of objects. It can be used as offset for databases or other data sources
*/
@JsExport
val Pagination.firstIndex: Int
get() = page * size
@ -37,7 +37,6 @@ val Pagination.firstIndex: Int
* [[firstIndex], [lastIndex]]; That means, that for [Pagination] with [Pagination.size] == 10 and [Pagination.page] == 1
* you will retrieve [Pagination.firstIndex] == 10 and [Pagination.lastIndex] == 19.
*/
@JsExport
val Pagination.lastIndex: Int
get() = firstIndex + size - 1
@ -52,6 +51,7 @@ fun calculatePagesNumber(datasetSize: Long, pageSize: Int): Int {
* Calculates pages count for given [datasetSize]
*/
@JsExport
@JsName("calculatePagesNumberWithInt")
fun calculatePagesNumber(datasetSize: Int, pageSize: Int): Int =
calculatePagesNumber(
datasetSize.toLong(),

View File

@ -2,6 +2,7 @@ package dev.inmo.micro_utils.pagination
import kotlinx.serialization.Serializable
import kotlin.js.JsExport
import kotlin.js.JsName
@JsExport
@Serializable
@ -16,6 +17,7 @@ data class PaginationResult<T>(
fun <T> emptyPaginationResult() = PaginationResult<T>(0, 0, emptyList(), 0)
@JsExport
@JsName("createPaginationResultWithPagination")
fun <T> List<T>.createPaginationResult(
pagination: Pagination,
commonObjectsNumber: Long
@ -30,6 +32,7 @@ fun <T> List<T>.createPaginationResult(
)
@JsExport
@JsName("createPaginationResultWithFirstIndex")
fun <T> List<T>.createPaginationResult(
firstIndex: Int,
commonObjectsNumber: Long
@ -44,6 +47,7 @@ fun <T> List<T>.createPaginationResult(
)
@JsExport
@JsName("createPaginationResultWithPair")
fun <T> Pair<Long, List<T>>.createPaginationResult(
pagination: Pagination
) = second.createPaginationResult(pagination, first)

View File

@ -2,6 +2,7 @@ package dev.inmo.micro_utils.pagination
import kotlinx.serialization.Serializable
import kotlin.js.JsExport
import kotlin.js.JsName
const val defaultSmallPageSize = 2
const val defaultMediumPageSize = 5
@ -32,6 +33,7 @@ data class SimplePagination(
) : Pagination
@JsExport
@JsName("PaginationFactory")
fun Pagination(
page: Int,
size: Int

View File

@ -2,6 +2,7 @@ package dev.inmo.micro_utils.pagination.utils
import dev.inmo.micro_utils.pagination.*
import kotlin.js.JsExport
import kotlin.js.JsName
@JsExport
fun <T> Iterable<T>.paginate(with: Pagination): PaginationResult<T> {
@ -23,6 +24,7 @@ fun <T> Iterable<T>.paginate(with: Pagination): PaginationResult<T> {
}
@JsExport
@JsName("paginateList")
fun <T> List<T>.paginate(with: Pagination): PaginationResult<T> {
return subList(with.firstIndex, with.lastIndex + 1).createPaginationResult(
with,
@ -31,6 +33,7 @@ fun <T> List<T>.paginate(with: Pagination): PaginationResult<T> {
}
@JsExport
@JsName("paginateSet")
fun <T> Set<T>.paginate(with: Pagination): PaginationResult<T> {
return this.drop(with.firstIndex).take(with.size).createPaginationResult(
with,

View File

@ -7,21 +7,18 @@ const val paginationPageKey = "ppage"
@JsExport
const val paginationSizeKey = "psize"
@JsExport
val Pagination.asUrlQueryParts
get() = mapOf(
paginationPageKey to page.toString(),
paginationSizeKey to size.toString()
)
@JsExport
val Pagination.asUrlQueryArrayParts
get() = arrayOf(
paginationPageKey to page.toString(),
paginationSizeKey to size.toString()
)
@JsExport
val Map<String, String?>.extractPagination: Pagination
get() = SimplePagination(
get(paginationPageKey) ?.toIntOrNull() ?: 0,

View File

@ -5,7 +5,6 @@ import dev.inmo.micro_utils.pagination.PaginationResult
import kotlinx.coroutines.flow.Flow
import kotlin.js.JsExport
@JsExport
interface ReadOneToManyKeyValueRepo<Key, Value> : Repo {
suspend fun get(k: Key, pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>
suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
@ -17,7 +16,6 @@ interface ReadOneToManyKeyValueRepo<Key, Value> : Repo {
@Deprecated("Renamed", ReplaceWith("ReadOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo"))
typealias OneToManyReadKeyValueRepo<Key, Value> = ReadOneToManyKeyValueRepo<Key, Value>
@JsExport
interface WriteOneToManyKeyValueRepo<Key, Value> : Repo {
val onNewValue: Flow<Pair<Key, Value>>
val onValueRemoved: Flow<Pair<Key, Value>>
@ -30,5 +28,4 @@ interface WriteOneToManyKeyValueRepo<Key, Value> : Repo {
@Deprecated("Renamed", ReplaceWith("WriteOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.WriteOneToManyKeyValueRepo"))
typealias OneToManyWriteKeyValueRepo<Key, Value> = WriteOneToManyKeyValueRepo<Key, Value>
@JsExport
interface OneToManyKeyValueRepo<Key, Value> : ReadOneToManyKeyValueRepo<Key, Value>, WriteOneToManyKeyValueRepo<Key, Value>

View File

@ -5,7 +5,6 @@ import dev.inmo.micro_utils.pagination.PaginationResult
import kotlinx.coroutines.flow.Flow
import kotlin.js.JsExport
@JsExport
interface ReadStandardCRUDRepo<ObjectType, IdType> : Repo {
suspend fun getByPagination(pagination: Pagination): PaginationResult<ObjectType>
suspend fun getById(id: IdType): ObjectType?
@ -14,14 +13,11 @@ interface ReadStandardCRUDRepo<ObjectType, IdType> : Repo {
}
typealias UpdatedValuePair<IdType, ValueType> = Pair<IdType, ValueType>
@JsExport
val <IdType> UpdatedValuePair<IdType, *>.id
get() = first
@JsExport
val <ValueType> UpdatedValuePair<*, ValueType>.value
get() = second
@JsExport
interface WriteStandardCRUDRepo<ObjectType, IdType, InputValueType> : Repo {
val newObjectsFlow: Flow<ObjectType>
val updatedObjectsFlow: Flow<ObjectType>
@ -33,15 +29,12 @@ interface WriteStandardCRUDRepo<ObjectType, IdType, InputValueType> : Repo {
suspend fun deleteById(ids: List<IdType>)
}
@JsExport
suspend fun <ObjectType, IdType, InputValueType> WriteStandardCRUDRepo<ObjectType, IdType, InputValueType>.create(
vararg values: InputValueType
): List<ObjectType> = create(values.toList())
@JsExport
suspend fun <ObjectType, IdType, InputValueType> WriteStandardCRUDRepo<ObjectType, IdType, InputValueType>.update(
vararg values: UpdatedValuePair<IdType, InputValueType>
): List<ObjectType> = update(values.toList())
@JsExport
suspend fun <ObjectType, IdType, InputValueType> WriteStandardCRUDRepo<ObjectType, IdType, InputValueType>.deleteById(
vararg ids: IdType
) = deleteById(ids.toList())

View File

@ -5,7 +5,6 @@ import dev.inmo.micro_utils.pagination.PaginationResult
import kotlinx.coroutines.flow.Flow
import kotlin.js.JsExport
@JsExport
interface ReadStandardKeyValueRepo<Key, Value> : Repo {
suspend fun get(k: Key): Value?
suspend fun values(pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>
@ -14,7 +13,6 @@ interface ReadStandardKeyValueRepo<Key, Value> : Repo {
suspend fun count(): Long
}
@JsExport
interface WriteStandardKeyValueRepo<Key, Value> : Repo {
val onNewValue: Flow<Pair<Key, Value>>
val onValueRemoved: Flow<Key>
@ -23,5 +21,4 @@ interface WriteStandardKeyValueRepo<Key, Value> : Repo {
suspend fun unset(k: Key)
}
@JsExport
interface StandardKeyValueRepo<Key, Value> : ReadStandardKeyValueRepo<Key, Value>, WriteStandardKeyValueRepo<Key, Value>

View File

@ -4,7 +4,6 @@ import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.repos.ReadStandardCRUDRepo
import kotlin.js.JsExport
@JsExport
suspend inline fun <T, ID, REPO : ReadStandardCRUDRepo<T, ID>> REPO.doForAll(
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
methodCaller: suspend REPO.(Pagination) -> PaginationResult<T>,
@ -17,12 +16,10 @@ suspend inline fun <T, ID, REPO : ReadStandardCRUDRepo<T, ID>> REPO.doForAll(
}
}
@JsExport
suspend inline fun <T, ID, REPO : ReadStandardCRUDRepo<T, ID>> REPO.doForAll(
block: (List<T>) -> Unit
) = doForAll({ getByPagination(it) }, block)
@JsExport
suspend inline fun <T, ID, REPO : ReadStandardCRUDRepo<T, ID>> REPO.getAll(
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
methodCaller: suspend REPO.(Pagination) -> PaginationResult<T>

View File

@ -4,7 +4,6 @@ import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.repos.*
import kotlin.js.JsExport
@JsExport
suspend inline fun <Key, Value, REPO : ReadStandardKeyValueRepo<Key, Value>> REPO.doForAll(
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>,
@ -17,12 +16,10 @@ suspend inline fun <Key, Value, REPO : ReadStandardKeyValueRepo<Key, Value>> REP
}
}
@JsExport
suspend inline fun <Key, Value, REPO : ReadStandardKeyValueRepo<Key, Value>> REPO.doForAll(
block: (List<Pair<Key, Value>>) -> Unit
) = doForAll({ keys(it, false) }, block)
@JsExport
suspend inline fun <Key, Value, REPO : ReadStandardKeyValueRepo<Key, Value>> REPO.getAll(
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>

View File

@ -4,7 +4,6 @@ import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.repos.*
import kotlin.js.JsExport
@JsExport
suspend inline fun <Key, Value, REPO : ReadOneToManyKeyValueRepo<Key, Value>> REPO.doForAll(
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>,
@ -27,12 +26,10 @@ suspend inline fun <Key, Value, REPO : ReadOneToManyKeyValueRepo<Key, Value>> RE
}
}
@JsExport
suspend inline fun <Key, Value, REPO : ReadOneToManyKeyValueRepo<Key, Value>> REPO.doForAll(
block: (List<Pair<Key, List<Value>>>) -> Unit
) = doForAll({ keys(it, false) }, block)
@JsExport
suspend inline fun <Key, Value, REPO : ReadOneToManyKeyValueRepo<Key, Value>> REPO.getAll(
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>

View File

@ -4,8 +4,8 @@ import dev.inmo.micro_utils.coroutines.BroadcastFlow
import dev.inmo.micro_utils.pagination.*
import kotlinx.coroutines.flow.Flow
import kotlin.js.JsExport
import kotlin.js.JsName
@JsExport
class ReadMapCRUDRepo<ObjectType, IdType>(
private val map: Map<IdType, ObjectType> = emptyMap()
) : ReadStandardCRUDRepo<ObjectType, IdType> {
@ -25,7 +25,6 @@ class ReadMapCRUDRepo<ObjectType, IdType>(
override suspend fun count(): Long = map.size.toLong()
}
@JsExport
abstract class WriteMapCRUDRepo<ObjectType, IdType, InputValueType>(
private val map: MutableMap<IdType, ObjectType> = mutableMapOf()
) : WriteStandardCRUDRepo<ObjectType, IdType, InputValueType> {
@ -81,6 +80,7 @@ abstract class MapCRUDRepo<ObjectType, IdType, InputValueType>(
WriteMapCRUDRepo<ObjectType, IdType, InputValueType>(map)
@JsExport
@JsName("MapCRUDRepoFactory")
fun <ObjectType, IdType, InputValueType> MapCRUDRepo(
map: MutableMap<IdType, ObjectType>,
updateCallback: suspend (newValue: InputValueType, id: IdType, old: ObjectType) -> ObjectType,

View File

@ -5,7 +5,6 @@ import dev.inmo.micro_utils.pagination.*
import kotlinx.coroutines.flow.Flow
import kotlin.js.JsExport
@JsExport
class ReadMapKeyValueRepo<Key, Value>(
private val map: Map<Key, Value> = emptyMap()
) : ReadStandardKeyValueRepo<Key, Value> {
@ -47,7 +46,6 @@ class ReadMapKeyValueRepo<Key, Value>(
override suspend fun count(): Long = map.size.toLong()
}
@JsExport
class WriteMapKeyValueRepo<Key, Value>(
private val map: MutableMap<Key, Value> = mutableMapOf()
) : WriteStandardKeyValueRepo<Key, Value> {

View File

@ -6,7 +6,6 @@ import dev.inmo.micro_utils.pagination.utils.paginate
import kotlinx.coroutines.flow.Flow
import kotlin.js.JsExport
@JsExport
class MapReadOneToManyKeyValueRepo<Key, Value>(
private val map: Map<Key, List<Value>> = emptyMap()
) : ReadOneToManyKeyValueRepo<Key, Value> {
@ -46,7 +45,6 @@ class MapReadOneToManyKeyValueRepo<Key, Value>(
override suspend fun count(): Long = map.size.toLong()
}
@JsExport
class MapWriteOneToManyKeyValueRepo<Key, Value>(
private val map: MutableMap<Key, MutableList<Value>> = mutableMapOf()
) : WriteOneToManyKeyValueRepo<Key, Value> {

View File

@ -13,7 +13,6 @@ import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.serializer
import kotlin.js.JsExport
@JsExport
class KtorReadStandardCrudRepo<ObjectType, IdType> (
private val baseUrl: String,
private val client: HttpClient = HttpClient(),

View File

@ -13,7 +13,6 @@ import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.*
import kotlin.js.JsExport
@JsExport
class KtorWriteStandardCrudRepo<ObjectType, IdType, InputValue> (
private val baseUrl: String,
private val client: HttpClient = HttpClient(),

View File

@ -13,7 +13,6 @@ import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.serializer
import kotlin.js.JsExport
@JsExport
class KtorReadStandardKeyValueRepo<Key, Value> (
private var baseUrl: String,
private var client: HttpClient = HttpClient(),

View File

@ -13,7 +13,6 @@ import kotlinx.serialization.builtins.PairSerializer
import kotlinx.serialization.builtins.serializer
import kotlin.js.JsExport
@JsExport
class KtorWriteStandardKeyValueRepo<K, V> (
private var baseUrl: String,
private var client: HttpClient = HttpClient(),

View File

@ -13,7 +13,6 @@ import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.serializer
import kotlin.js.JsExport
@JsExport
class KtorReadOneToManyKeyValueRepo<Key, Value> (
private val baseUrl: String,
private val client: HttpClient = HttpClient(),

View File

@ -13,7 +13,6 @@ import kotlinx.serialization.builtins.PairSerializer
import kotlinx.serialization.builtins.serializer
import kotlin.js.JsExport
@JsExport
class KtorWriteOneToManyKeyValueRepo<Key, Value> (
private val baseUrl: String,
private val client: HttpClient = HttpClient(),