mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-08 17:49:44 +00:00
13
CHANGELOG.md
13
CHANGELOG.md
@@ -1,5 +1,18 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.24.6
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `KSLog`: `1.4.0` -> `1.4.1`
|
||||||
|
* `Exposed`: `0.58.0` -> `0.59.0`
|
||||||
|
* `SQLite`: `3.48.0.0` -> `3.49.0.0`
|
||||||
|
* `AndroidFragment`: `1.8.5` -> `1.8.6`
|
||||||
|
* `Coroutines`:
|
||||||
|
* Safely functions has been replaced with `Logging` variations (resolve of [#541](https://github.com/InsanusMokrassar/MicroUtils/issues/541))
|
||||||
|
* `KSP`:
|
||||||
|
* `Variations`:
|
||||||
|
* Module has been created
|
||||||
|
|
||||||
## 0.24.5
|
## 0.24.5
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
@@ -11,6 +11,7 @@ kotlin {
|
|||||||
commonMain {
|
commonMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
api libs.kt.coroutines
|
api libs.kt.coroutines
|
||||||
|
api libs.kslog
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsMain {
|
jsMain {
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
package dev.inmo.micro_utils.coroutines
|
package dev.inmo.micro_utils.coroutines
|
||||||
|
|
||||||
|
import dev.inmo.kslog.common.KSLog
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
@@ -16,6 +17,45 @@ inline fun <T> Flow<T>.subscribe(scope: CoroutineScope, noinline block: suspend
|
|||||||
* Use [subscribe], but all [block]s will be called inside of [safely] function.
|
* Use [subscribe], but all [block]s will be called inside of [safely] function.
|
||||||
* Use [onException] to set up your reaction for [Throwable]s
|
* Use [onException] to set up your reaction for [Throwable]s
|
||||||
*/
|
*/
|
||||||
|
inline fun <T> Flow<T>.subscribeLogging(
|
||||||
|
scope: CoroutineScope,
|
||||||
|
noinline errorMessageBuilder: T.(Throwable) -> Any = { "Something web wrong" },
|
||||||
|
logger: KSLog = KSLog,
|
||||||
|
noinline block: suspend (T) -> Unit
|
||||||
|
) = subscribe(scope) {
|
||||||
|
it.runCatchingLogging(
|
||||||
|
errorMessageBuilder,
|
||||||
|
logger
|
||||||
|
) {
|
||||||
|
block(it)
|
||||||
|
}.getOrThrow()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use [subscribeSafelyWithoutExceptions], but all exceptions will be passed to [defaultSafelyExceptionHandler]
|
||||||
|
*/
|
||||||
|
inline fun <T> Flow<T>.subscribeLoggingDropExceptions(
|
||||||
|
scope: CoroutineScope,
|
||||||
|
noinline errorMessageBuilder: T.(Throwable) -> Any = { "Something web wrong" },
|
||||||
|
logger: KSLog = KSLog,
|
||||||
|
noinline block: suspend (T) -> Unit
|
||||||
|
) = subscribe(scope) {
|
||||||
|
it.runCatchingLogging(
|
||||||
|
errorMessageBuilder,
|
||||||
|
logger
|
||||||
|
) {
|
||||||
|
block(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use [subscribe], but all [block]s will be called inside of [safely] function.
|
||||||
|
* Use [onException] to set up your reaction for [Throwable]s
|
||||||
|
*/
|
||||||
|
@Deprecated(
|
||||||
|
"Will be removed soon due to replacement by subscribeLogging",
|
||||||
|
ReplaceWith("this.subscribeLogging(scope = scope, block = block)")
|
||||||
|
)
|
||||||
inline fun <T> Flow<T>.subscribeSafely(
|
inline fun <T> Flow<T>.subscribeSafely(
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
noinline onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler,
|
noinline onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler,
|
||||||
@@ -29,6 +69,10 @@ inline fun <T> Flow<T>.subscribeSafely(
|
|||||||
/**
|
/**
|
||||||
* Use [subscribeSafelyWithoutExceptions], but all exceptions will be passed to [defaultSafelyExceptionHandler]
|
* Use [subscribeSafelyWithoutExceptions], but all exceptions will be passed to [defaultSafelyExceptionHandler]
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(
|
||||||
|
"Will be removed soon due to replacement by subscribeLoggingDropExceptions",
|
||||||
|
ReplaceWith("this.subscribeLoggingDropExceptions(scope = scope, block = block)")
|
||||||
|
)
|
||||||
inline fun <T> Flow<T>.subscribeSafelyWithoutExceptions(
|
inline fun <T> Flow<T>.subscribeSafelyWithoutExceptions(
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
noinline onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull,
|
noinline onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull,
|
||||||
@@ -42,6 +86,10 @@ inline fun <T> Flow<T>.subscribeSafelyWithoutExceptions(
|
|||||||
/**
|
/**
|
||||||
* Use [subscribeSafelyWithoutExceptions], but all exceptions inside of [safely] will be skipped
|
* Use [subscribeSafelyWithoutExceptions], but all exceptions inside of [safely] will be skipped
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(
|
||||||
|
"Will be removed soon due to replacement by subscribeLoggingDropExceptions",
|
||||||
|
ReplaceWith("this.subscribeLoggingDropExceptions(scope = scope, block = block)")
|
||||||
|
)
|
||||||
inline fun <T> Flow<T>.subscribeSafelySkippingExceptions(
|
inline fun <T> Flow<T>.subscribeSafelySkippingExceptions(
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
noinline block: suspend (T) -> Unit
|
noinline block: suspend (T) -> Unit
|
||||||
|
@@ -15,7 +15,7 @@ private class SubscribeAsyncReceiver<T>(
|
|||||||
get() = dataChannel
|
get() = dataChannel
|
||||||
|
|
||||||
init {
|
init {
|
||||||
scope.launchSafelyWithoutExceptions {
|
scope.launchLoggingDropExceptions {
|
||||||
for (data in dataChannel) {
|
for (data in dataChannel) {
|
||||||
output(data)
|
output(data)
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,10 @@ import kotlin.coroutines.coroutineContext
|
|||||||
*
|
*
|
||||||
* @return [Result] with result of [block] if no exceptions or [Result] from [onException] execution
|
* @return [Result] with result of [block] if no exceptions or [Result] from [onException] execution
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(
|
||||||
|
"This function become redundant since coroutines correctly handling throwing exceptions",
|
||||||
|
replaceWith = ReplaceWith("runCatching(block).replaceIfFailure { onException(it) }")
|
||||||
|
)
|
||||||
suspend inline fun <T> runCatchingSafely(
|
suspend inline fun <T> runCatchingSafely(
|
||||||
onException: ExceptionHandler<T>,
|
onException: ExceptionHandler<T>,
|
||||||
block: suspend () -> T
|
block: suspend () -> T
|
||||||
@@ -29,6 +33,10 @@ suspend inline fun <T> runCatchingSafely(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"This function become redundant since coroutines correctly handling throwing exceptions",
|
||||||
|
replaceWith = ReplaceWith("runCatching(block).replaceIfFailure { onException(it) }")
|
||||||
|
)
|
||||||
suspend inline fun <T, R> R.runCatchingSafely(
|
suspend inline fun <T, R> R.runCatchingSafely(
|
||||||
onException: ExceptionHandler<T>,
|
onException: ExceptionHandler<T>,
|
||||||
block: suspend R.() -> T
|
block: suspend R.() -> T
|
||||||
@@ -39,10 +47,18 @@ suspend inline fun <T, R> R.runCatchingSafely(
|
|||||||
/**
|
/**
|
||||||
* Launching [runCatchingSafely] with [defaultSafelyExceptionHandler] as `onException` parameter
|
* Launching [runCatchingSafely] with [defaultSafelyExceptionHandler] as `onException` parameter
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(
|
||||||
|
"This function become redundant since coroutines correctly handling throwing exceptions",
|
||||||
|
replaceWith = ReplaceWith("runCatching(block).replaceIfFailure { defaultSafelyExceptionHandler(it) }")
|
||||||
|
)
|
||||||
suspend inline fun <T> runCatchingSafely(
|
suspend inline fun <T> runCatchingSafely(
|
||||||
block: suspend () -> T
|
block: suspend () -> T
|
||||||
): Result<T> = runCatchingSafely(defaultSafelyExceptionHandler, block)
|
): Result<T> = runCatchingSafely(defaultSafelyExceptionHandler, block)
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"This function become redundant since coroutines correctly handling throwing exceptions",
|
||||||
|
replaceWith = ReplaceWith("runCatching(block).replaceIfFailure { defaultSafelyExceptionHandler(it) }")
|
||||||
|
)
|
||||||
suspend inline fun <T, R> R.runCatchingSafely(
|
suspend inline fun <T, R> R.runCatchingSafely(
|
||||||
block: suspend R.() -> T
|
block: suspend R.() -> T
|
||||||
): Result<T> = runCatchingSafely<T> {
|
): Result<T> = runCatchingSafely<T> {
|
||||||
@@ -73,6 +89,9 @@ suspend fun contextSafelyExceptionHandler() = coroutineContext[ContextSafelyExce
|
|||||||
* After all, will be called [withContext] method with created [ContextSafelyExceptionHandler] and block which will call
|
* After all, will be called [withContext] method with created [ContextSafelyExceptionHandler] and block which will call
|
||||||
* [safely] method with [safelyExceptionHandler] as onException parameter and [block] as execution block
|
* [safely] method with [safelyExceptionHandler] as onException parameter and [block] as execution block
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(
|
||||||
|
"This function become redundant since coroutines correctly handling throwing exceptions",
|
||||||
|
)
|
||||||
suspend fun <T> safelyWithContextExceptionHandler(
|
suspend fun <T> safelyWithContextExceptionHandler(
|
||||||
contextExceptionHandler: ExceptionHandler<Unit>,
|
contextExceptionHandler: ExceptionHandler<Unit>,
|
||||||
safelyExceptionHandler: ExceptionHandler<T> = defaultSafelyExceptionHandler,
|
safelyExceptionHandler: ExceptionHandler<T> = defaultSafelyExceptionHandler,
|
||||||
@@ -94,6 +113,10 @@ suspend fun <T> safelyWithContextExceptionHandler(
|
|||||||
*
|
*
|
||||||
* @see runCatchingSafely
|
* @see runCatchingSafely
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(
|
||||||
|
"This function become redundant since coroutines correctly handling throwing exceptions",
|
||||||
|
replaceWith = ReplaceWith("runCatching(block).replaceIfFailure { onException(it) }.getOrThrow()")
|
||||||
|
)
|
||||||
suspend inline fun <T> safely(
|
suspend inline fun <T> safely(
|
||||||
onException: ExceptionHandler<T>,
|
onException: ExceptionHandler<T>,
|
||||||
block: suspend () -> T
|
block: suspend () -> T
|
||||||
@@ -104,9 +127,17 @@ suspend inline fun <T> safely(
|
|||||||
*
|
*
|
||||||
* @see runCatchingSafely
|
* @see runCatchingSafely
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(
|
||||||
|
"This function become redundant since coroutines correctly handling throwing exceptions",
|
||||||
|
replaceWith = ReplaceWith("runCatching(block).replaceIfFailure { defaultSafelyExceptionHandler(it) }.getOrThrow()")
|
||||||
|
)
|
||||||
suspend inline fun <T> safely(
|
suspend inline fun <T> safely(
|
||||||
block: suspend () -> T
|
block: suspend () -> T
|
||||||
): T = safely(defaultSafelyExceptionHandler, block)
|
): T = safely(defaultSafelyExceptionHandler, block)
|
||||||
|
@Deprecated(
|
||||||
|
"This function become redundant since coroutines correctly handling throwing exceptions",
|
||||||
|
replaceWith = ReplaceWith("runCatching(block).replaceIfFailure { defaultSafelyExceptionHandler(it) }.getOrThrow()")
|
||||||
|
)
|
||||||
suspend inline fun <T, R> R.safely(
|
suspend inline fun <T, R> R.safely(
|
||||||
block: suspend R.() -> T
|
block: suspend R.() -> T
|
||||||
): T = safely<T> { block() }
|
): T = safely<T> { block() }
|
||||||
@@ -137,11 +168,19 @@ val defaultSafelyWithoutExceptionHandlerWithNull: ExceptionHandler<Nothing?> = {
|
|||||||
* Shortcut for [safely] with exception handler, that as expected must return null in case of impossible creating of
|
* Shortcut for [safely] with exception handler, that as expected must return null in case of impossible creating of
|
||||||
* result from exception (instead of throwing it, by default always returns null)
|
* result from exception (instead of throwing it, by default always returns null)
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(
|
||||||
|
"This function become redundant since coroutines correctly handling throwing exceptions",
|
||||||
|
replaceWith = ReplaceWith("runCatching(block).replaceIfFailure { onException(it) }.getOrNull()")
|
||||||
|
)
|
||||||
suspend fun <T> safelyWithoutExceptions(
|
suspend fun <T> safelyWithoutExceptions(
|
||||||
onException: ExceptionHandler<T> = defaultSafelyExceptionHandler,
|
onException: ExceptionHandler<T> = defaultSafelyExceptionHandler,
|
||||||
block: suspend () -> T
|
block: suspend () -> T
|
||||||
): T? = runCatchingSafely(onException, block).getOrNull()
|
): T? = runCatchingSafely(onException, block).getOrNull()
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"This function become redundant since coroutines correctly handling throwing exceptions",
|
||||||
|
replaceWith = ReplaceWith("runCatching(block).replaceIfFailure { onException(it) }.getOrNull()")
|
||||||
|
)
|
||||||
suspend fun <T> runCatchingSafelyWithoutExceptions(
|
suspend fun <T> runCatchingSafelyWithoutExceptions(
|
||||||
onException: ExceptionHandler<T?> = defaultSafelyExceptionHandler,
|
onException: ExceptionHandler<T?> = defaultSafelyExceptionHandler,
|
||||||
block: suspend () -> T
|
block: suspend () -> T
|
||||||
|
@@ -0,0 +1,55 @@
|
|||||||
|
package dev.inmo.micro_utils.coroutines
|
||||||
|
|
||||||
|
import dev.inmo.kslog.common.KSLog
|
||||||
|
import dev.inmo.kslog.common.e
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
|
||||||
|
fun CoroutineScope.launchLogging(
|
||||||
|
errorMessageBuilder: CoroutineScope.(Throwable) -> Any = { "Something web wrong" },
|
||||||
|
logger: KSLog = KSLog,
|
||||||
|
context: CoroutineContext = EmptyCoroutineContext,
|
||||||
|
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||||
|
block: suspend CoroutineScope.() -> Unit
|
||||||
|
) = launch(context, start) {
|
||||||
|
runCatching { block() }.onFailure {
|
||||||
|
logger.e(it) { errorMessageBuilder(it) }
|
||||||
|
}.getOrThrow()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun CoroutineScope.launchLoggingDropExceptions(
|
||||||
|
errorMessageBuilder: CoroutineScope.(Throwable) -> Any = { "Something web wrong" },
|
||||||
|
logger: KSLog = KSLog,
|
||||||
|
context: CoroutineContext = EmptyCoroutineContext,
|
||||||
|
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||||
|
block: suspend CoroutineScope.() -> Unit
|
||||||
|
) = launch(context, start) {
|
||||||
|
runCatching { block() }.onFailure {
|
||||||
|
logger.e(it) { errorMessageBuilder(it) }
|
||||||
|
} // just dropping exception
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> CoroutineScope.asyncLogging(
|
||||||
|
errorMessageBuilder: CoroutineScope.(Throwable) -> Any = { "Something web wrong" },
|
||||||
|
logger: KSLog = KSLog,
|
||||||
|
context: CoroutineContext = EmptyCoroutineContext,
|
||||||
|
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||||
|
block: suspend CoroutineScope.() -> T
|
||||||
|
) = async(context, start) {
|
||||||
|
runCatching { block() }.onFailure {
|
||||||
|
logger.e(it) { errorMessageBuilder(it) }
|
||||||
|
}.getOrThrow()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> CoroutineScope.asyncLoggingDropExceptions(
|
||||||
|
errorMessageBuilder: CoroutineScope.(Throwable) -> Any = { "Something web wrong" },
|
||||||
|
logger: KSLog = KSLog,
|
||||||
|
context: CoroutineContext = EmptyCoroutineContext,
|
||||||
|
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||||
|
block: suspend CoroutineScope.() -> T
|
||||||
|
) = async(context, start) {
|
||||||
|
runCatching { block() }.onFailure {
|
||||||
|
logger.e(it) { errorMessageBuilder(it) }
|
||||||
|
}
|
||||||
|
}
|
@@ -4,6 +4,10 @@ import kotlinx.coroutines.*
|
|||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
import kotlin.coroutines.EmptyCoroutineContext
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"This method will be removed soon. Use launchLogging instead",
|
||||||
|
ReplaceWith("this.launchLogging(context = context, start = start, block = block)")
|
||||||
|
)
|
||||||
fun CoroutineScope.launchSafely(
|
fun CoroutineScope.launchSafely(
|
||||||
context: CoroutineContext = EmptyCoroutineContext,
|
context: CoroutineContext = EmptyCoroutineContext,
|
||||||
start: CoroutineStart = CoroutineStart.DEFAULT,
|
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||||
@@ -15,6 +19,10 @@ fun CoroutineScope.launchSafely(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"This method will be removed soon. Use launchLoggingDropExceptions instead",
|
||||||
|
ReplaceWith("this.launchLoggingDropExceptions(context = context, start = start, block = block)")
|
||||||
|
)
|
||||||
fun CoroutineScope.launchSafelyWithoutExceptions(
|
fun CoroutineScope.launchSafelyWithoutExceptions(
|
||||||
context: CoroutineContext = EmptyCoroutineContext,
|
context: CoroutineContext = EmptyCoroutineContext,
|
||||||
start: CoroutineStart = CoroutineStart.DEFAULT,
|
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||||
@@ -26,6 +34,10 @@ fun CoroutineScope.launchSafelyWithoutExceptions(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"This method will be removed soon. Use asyncLogging instead",
|
||||||
|
ReplaceWith("this.asyncLogging(context = context, start = start, block = block)")
|
||||||
|
)
|
||||||
fun <T> CoroutineScope.asyncSafely(
|
fun <T> CoroutineScope.asyncSafely(
|
||||||
context: CoroutineContext = EmptyCoroutineContext,
|
context: CoroutineContext = EmptyCoroutineContext,
|
||||||
start: CoroutineStart = CoroutineStart.DEFAULT,
|
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||||
@@ -37,6 +49,10 @@ fun <T> CoroutineScope.asyncSafely(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"This method will be removed soon. Use asyncLoggingDropExceptions instead",
|
||||||
|
ReplaceWith("this.asyncLoggingDropExceptions(context = context, start = start, block = block)")
|
||||||
|
)
|
||||||
fun <T> CoroutineScope.asyncSafelyWithoutExceptions(
|
fun <T> CoroutineScope.asyncSafelyWithoutExceptions(
|
||||||
context: CoroutineContext = EmptyCoroutineContext,
|
context: CoroutineContext = EmptyCoroutineContext,
|
||||||
start: CoroutineStart = CoroutineStart.DEFAULT,
|
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||||
|
@@ -0,0 +1,3 @@
|
|||||||
|
package dev.inmo.micro_utils.coroutines
|
||||||
|
|
||||||
|
inline fun <T> Result<T>.replaceIfFailure(onException: (Throwable) -> T) = if (isSuccess) { this } else { runCatching { onException(exceptionOrNull()!!) } }
|
@@ -0,0 +1,12 @@
|
|||||||
|
package dev.inmo.micro_utils.coroutines
|
||||||
|
|
||||||
|
import dev.inmo.kslog.common.KSLog
|
||||||
|
import dev.inmo.kslog.common.e
|
||||||
|
|
||||||
|
inline fun <T, R> R.runCatchingLogging(
|
||||||
|
noinline errorMessageBuilder: R.(Throwable) -> Any = { "Something web wrong" },
|
||||||
|
logger: KSLog = KSLog,
|
||||||
|
block: R.() -> T
|
||||||
|
) = runCatching(block).onFailure {
|
||||||
|
logger.e(it) { errorMessageBuilder(it) }
|
||||||
|
}
|
@@ -128,8 +128,10 @@ open class DefaultStatesMachine <T: State>(
|
|||||||
*/
|
*/
|
||||||
override fun start(scope: CoroutineScope): Job {
|
override fun start(scope: CoroutineScope): Job {
|
||||||
val supervisorScope = scope.LinkedSupervisorScope()
|
val supervisorScope = scope.LinkedSupervisorScope()
|
||||||
supervisorScope.launchSafelyWithoutExceptions {
|
supervisorScope.launchLoggingDropExceptions {
|
||||||
(statesManager.getActiveStates().asFlow() + statesManager.onStartChain).subscribeSafelyWithoutExceptions(supervisorScope) {
|
(statesManager.getActiveStates().asFlow() + statesManager.onStartChain).subscribeSafelyWithoutExceptions(
|
||||||
|
supervisorScope
|
||||||
|
) {
|
||||||
supervisorScope.launch { performStateUpdate(Optional.absent(), it, supervisorScope) }
|
supervisorScope.launch { performStateUpdate(Optional.absent(), it, supervisorScope) }
|
||||||
}
|
}
|
||||||
statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(supervisorScope) {
|
statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(supervisorScope) {
|
||||||
|
@@ -15,5 +15,5 @@ crypto_js_version=4.1.1
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.24.5
|
version=0.24.6
|
||||||
android_code_version=285
|
android_code_version=286
|
||||||
|
@@ -4,18 +4,18 @@ kt = "2.1.10"
|
|||||||
kt-serialization = "1.8.0"
|
kt-serialization = "1.8.0"
|
||||||
kt-coroutines = "1.10.1"
|
kt-coroutines = "1.10.1"
|
||||||
|
|
||||||
kslog = "1.4.0"
|
kslog = "1.4.1"
|
||||||
|
|
||||||
jb-compose = "1.7.3"
|
jb-compose = "1.7.3"
|
||||||
jb-exposed = "0.58.0"
|
jb-exposed = "0.59.0"
|
||||||
jb-dokka = "2.0.0"
|
jb-dokka = "2.0.0"
|
||||||
|
|
||||||
sqlite = "3.48.0.0"
|
sqlite = "3.49.0.0"
|
||||||
|
|
||||||
korlibs = "5.4.0"
|
korlibs = "5.4.0"
|
||||||
uuid = "0.8.4"
|
uuid = "0.8.4"
|
||||||
|
|
||||||
ktor = "3.0.3"
|
ktor = "3.1.0"
|
||||||
|
|
||||||
gh-release = "2.5.2"
|
gh-release = "2.5.2"
|
||||||
|
|
||||||
@@ -28,16 +28,15 @@ kotlin-poet = "1.18.1"
|
|||||||
|
|
||||||
versions = "0.51.0"
|
versions = "0.51.0"
|
||||||
|
|
||||||
android-gradle = "8.2.2"
|
android-gradle = "8.7.+"
|
||||||
dexcount = "4.0.0"
|
dexcount = "4.0.0"
|
||||||
|
|
||||||
android-coreKtx = "1.15.0"
|
android-coreKtx = "1.15.0"
|
||||||
android-recyclerView = "1.4.0"
|
android-recyclerView = "1.4.0"
|
||||||
android-appCompat = "1.7.0"
|
android-appCompat = "1.7.0"
|
||||||
android-fragment = "1.8.5"
|
android-fragment = "1.8.6"
|
||||||
android-espresso = "3.6.1"
|
android-espresso = "3.6.1"
|
||||||
android-test = "1.2.1"
|
android-test = "1.2.1"
|
||||||
android-compose-material3 = "1.3.0"
|
|
||||||
|
|
||||||
android-props-minSdk = "21"
|
android-props-minSdk = "21"
|
||||||
android-props-compileSdk = "35"
|
android-props-compileSdk = "35"
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
|
if (ext.getProperties()["do_publish"] == false) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
|
|
||||||
task javadocsJar(type: Jar) {
|
task javadocsJar(type: Jar) {
|
||||||
|
@@ -5,6 +5,8 @@ plugins {
|
|||||||
id "com.google.devtools.ksp"
|
id "com.google.devtools.ksp"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ext.do_publish = false
|
||||||
|
|
||||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64Project"
|
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64Project"
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,28 +1,38 @@
|
|||||||
package dev.inmo.micro_ksp.generator
|
package dev.inmo.micro_ksp.generator
|
||||||
|
|
||||||
import com.google.devtools.ksp.symbol.KSClassDeclaration
|
import com.google.devtools.ksp.symbol.KSClassDeclaration
|
||||||
|
import com.google.devtools.ksp.symbol.KSDeclaration
|
||||||
import com.google.devtools.ksp.symbol.KSFile
|
import com.google.devtools.ksp.symbol.KSFile
|
||||||
|
import com.google.devtools.ksp.symbol.KSFunctionDeclaration
|
||||||
import com.squareup.kotlinpoet.FileSpec
|
import com.squareup.kotlinpoet.FileSpec
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
fun KSClassDeclaration.writeFile(
|
fun KSDeclaration.writeFile(
|
||||||
prefix: String = "",
|
prefix: String = "",
|
||||||
suffix: String = "",
|
suffix: String = "",
|
||||||
relatedPath: String = "",
|
relatedPath: String = "",
|
||||||
force: Boolean = false,
|
force: Boolean = false,
|
||||||
|
forceUppercase: Boolean = true,
|
||||||
fileSpecBuilder: () -> FileSpec
|
fileSpecBuilder: () -> FileSpec
|
||||||
) {
|
) {
|
||||||
val containingFile = containingFile!!
|
val containingFile = containingFile!!
|
||||||
|
val simpleName = if (forceUppercase) {
|
||||||
|
val rawSimpleName = simpleName.asString()
|
||||||
|
rawSimpleName.replaceFirst(rawSimpleName.first().toString(), rawSimpleName.first().uppercase())
|
||||||
|
} else {
|
||||||
|
simpleName.asString()
|
||||||
|
}
|
||||||
File(
|
File(
|
||||||
File(
|
File(
|
||||||
File(containingFile.filePath).parent,
|
File(containingFile.filePath).parent,
|
||||||
relatedPath
|
relatedPath
|
||||||
),
|
),
|
||||||
"$prefix${simpleName.asString()}$suffix.kt"
|
"$prefix${simpleName}$suffix.kt"
|
||||||
).takeIf { force || !it.exists() } ?.apply {
|
).takeIf { force || !it.exists() } ?.apply {
|
||||||
parentFile.mkdirs()
|
parentFile.mkdirs()
|
||||||
|
val fileSpec = fileSpecBuilder()
|
||||||
writer().use { writer ->
|
writer().use { writer ->
|
||||||
fileSpecBuilder().writeTo(writer)
|
fileSpec.writeTo(writer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,8 +52,9 @@ fun KSFile.writeFile(
|
|||||||
"$prefix${fileName.dropLastWhile { it != '.' }.removeSuffix(".")}$suffix.kt"
|
"$prefix${fileName.dropLastWhile { it != '.' }.removeSuffix(".")}$suffix.kt"
|
||||||
).takeIf { force || !it.exists() } ?.apply {
|
).takeIf { force || !it.exists() } ?.apply {
|
||||||
parentFile.mkdirs()
|
parentFile.mkdirs()
|
||||||
|
val fileSpec = fileSpecBuilder()
|
||||||
writer().use { writer ->
|
writer().use { writer ->
|
||||||
fileSpecBuilder().writeTo(writer)
|
fileSpec.writeTo(writer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
25
ksp/generator/src/main/kotlin/KClassWorkarounds.kt
Normal file
25
ksp/generator/src/main/kotlin/KClassWorkarounds.kt
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package dev.inmo.micro_ksp.generator
|
||||||
|
|
||||||
|
import com.google.devtools.ksp.KSTypeNotPresentException
|
||||||
|
import com.google.devtools.ksp.KSTypesNotPresentException
|
||||||
|
import com.google.devtools.ksp.KspExperimental
|
||||||
|
import com.google.devtools.ksp.symbol.KSType
|
||||||
|
import com.squareup.kotlinpoet.asClassName
|
||||||
|
import com.squareup.kotlinpoet.ksp.toClassName
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
@OptIn(KspExperimental::class)
|
||||||
|
inline fun convertToClassName(getter: () -> KClass<*>) = try {
|
||||||
|
getter().asClassName()
|
||||||
|
} catch (e: KSTypeNotPresentException) {
|
||||||
|
e.ksType.toClassName()
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(KspExperimental::class)
|
||||||
|
inline fun convertToClassNames(getter: () -> List<KClass<*>>) = try {
|
||||||
|
getter().map { it.asClassName() }
|
||||||
|
} catch (e: KSTypesNotPresentException) {
|
||||||
|
e.ksTypes.map {
|
||||||
|
it.toClassName()
|
||||||
|
}
|
||||||
|
}
|
@@ -5,6 +5,8 @@ plugins {
|
|||||||
id "com.google.devtools.ksp"
|
id "com.google.devtools.ksp"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ext.do_publish = false
|
||||||
|
|
||||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64Project"
|
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64Project"
|
||||||
|
|
||||||
|
|
||||||
|
7
ksp/variations/build.gradle
Normal file
7
ksp/variations/build.gradle
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
|
id "com.android.library"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64Project"
|
22
ksp/variations/generator/build.gradle
Normal file
22
ksp/variations/generator/build.gradle
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.jvm"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$publish_jvm"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation libs.kt.stdlib
|
||||||
|
api project(":micro_utils.ksp.generator")
|
||||||
|
api project(":micro_utils.ksp.variations")
|
||||||
|
api libs.kotlin.poet
|
||||||
|
api libs.ksp
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
}
|
243
ksp/variations/generator/src/main/kotlin/Processor.kt
Normal file
243
ksp/variations/generator/src/main/kotlin/Processor.kt
Normal file
@@ -0,0 +1,243 @@
|
|||||||
|
package dev.inmo.micro_utils.ksp.variations.generator
|
||||||
|
|
||||||
|
import com.google.devtools.ksp.KSTypeNotPresentException
|
||||||
|
import com.google.devtools.ksp.KspExperimental
|
||||||
|
import com.google.devtools.ksp.getAnnotationsByType
|
||||||
|
import com.google.devtools.ksp.processing.CodeGenerator
|
||||||
|
import com.google.devtools.ksp.processing.Resolver
|
||||||
|
import com.google.devtools.ksp.processing.SymbolProcessor
|
||||||
|
import com.google.devtools.ksp.symbol.*
|
||||||
|
import com.squareup.kotlinpoet.*
|
||||||
|
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
|
||||||
|
import com.squareup.kotlinpoet.ksp.toAnnotationSpec
|
||||||
|
import com.squareup.kotlinpoet.ksp.toClassName
|
||||||
|
import com.squareup.kotlinpoet.ksp.toKModifier
|
||||||
|
import com.squareup.kotlinpoet.ksp.toTypeName
|
||||||
|
import dev.inmo.micro_ksp.generator.convertToClassName
|
||||||
|
import dev.inmo.micro_ksp.generator.convertToClassNames
|
||||||
|
import dev.inmo.micro_ksp.generator.findSubClasses
|
||||||
|
import dev.inmo.micro_ksp.generator.writeFile
|
||||||
|
import dev.inmo.micro_utils.ksp.variations.GenerateVariations
|
||||||
|
import dev.inmo.micro_utils.ksp.variations.GenerationVariant
|
||||||
|
import kotlin.math.pow
|
||||||
|
|
||||||
|
class Processor(
|
||||||
|
private val codeGenerator: CodeGenerator
|
||||||
|
) : SymbolProcessor {
|
||||||
|
private fun KSClassDeclaration.findSealedConnection(potentialSealedParent: KSClassDeclaration): Boolean {
|
||||||
|
val targetClassname = potentialSealedParent.qualifiedName ?.asString()
|
||||||
|
return superTypes.any {
|
||||||
|
val itAsDeclaration = it.resolve().declaration as? KSClassDeclaration ?: return@any false
|
||||||
|
targetClassname == (itAsDeclaration.qualifiedName ?.asString()) || (itAsDeclaration.getSealedSubclasses().any() && itAsDeclaration.findSealedConnection(potentialSealedParent))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun KSClassDeclaration.resolveSubclasses(
|
||||||
|
searchIn: Sequence<KSAnnotated>,
|
||||||
|
allowNonSealed: Boolean
|
||||||
|
): Sequence<KSClassDeclaration> {
|
||||||
|
return findSubClasses(searchIn).let {
|
||||||
|
if (allowNonSealed) {
|
||||||
|
it
|
||||||
|
} else {
|
||||||
|
it.filter {
|
||||||
|
it.findSealedConnection(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(KspExperimental::class)
|
||||||
|
private fun FileSpec.Builder.generateVariations(
|
||||||
|
ksFunctionDeclaration: KSFunctionDeclaration,
|
||||||
|
resolver: Resolver
|
||||||
|
) {
|
||||||
|
val annotation = ksFunctionDeclaration.getAnnotationsByType(GenerateVariations::class).first()
|
||||||
|
val variations: List<Pair<List<GenerationVariant>, KSValueParameter>> = ksFunctionDeclaration.parameters.mapNotNull {
|
||||||
|
val variationAnnotations = it.getAnnotationsByType(GenerationVariant::class).toList()
|
||||||
|
variationAnnotations to it
|
||||||
|
}
|
||||||
|
val accumulatedGenerations = mutableSetOf<Pair<FunSpec, Map<String, String>>>()
|
||||||
|
val baseFunctionParameters = ksFunctionDeclaration.parameters.mapNotNull {
|
||||||
|
ParameterSpec
|
||||||
|
.builder(
|
||||||
|
it.name ?.asString() ?: return@mapNotNull null,
|
||||||
|
it.type.toTypeName(),
|
||||||
|
)
|
||||||
|
.apply {
|
||||||
|
if (it.isCrossInline) {
|
||||||
|
addModifiers(KModifier.CROSSINLINE)
|
||||||
|
}
|
||||||
|
if (it.isVal) {
|
||||||
|
addModifiers(KModifier.VALUE)
|
||||||
|
}
|
||||||
|
if (it.isNoInline) {
|
||||||
|
addModifiers(KModifier.NOINLINE)
|
||||||
|
}
|
||||||
|
if (it.isVararg) {
|
||||||
|
addModifiers(KModifier.VARARG)
|
||||||
|
}
|
||||||
|
it.annotations.forEach {
|
||||||
|
if (it.shortName.asString() == GenerationVariant::class.simpleName) return@forEach
|
||||||
|
|
||||||
|
addAnnotation(it.toAnnotationSpec(omitDefaultValues = false))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.build() to it.hasDefault
|
||||||
|
}
|
||||||
|
val baseFunctionFunSpecs = mutableListOf<Pair<FunSpec, Map<String, String>>>()
|
||||||
|
let {
|
||||||
|
var defaultParametersIndicator = 0u
|
||||||
|
val maxIndicator = baseFunctionParameters.filter { it.second }.foldIndexed(0u) { index, acc, _ ->
|
||||||
|
2.0.pow(index).toUInt() + acc
|
||||||
|
}
|
||||||
|
while (defaultParametersIndicator <= maxIndicator) {
|
||||||
|
var currentDefaultParameterIndex = 0u
|
||||||
|
val baseFunctionDefaults = mutableMapOf<String, String>()
|
||||||
|
val funSpec = FunSpec.builder(ksFunctionDeclaration.simpleName.asString()).apply {
|
||||||
|
modifiers.addAll(ksFunctionDeclaration.modifiers.mapNotNull { it.toKModifier() })
|
||||||
|
ksFunctionDeclaration.annotations.forEach {
|
||||||
|
if (it.shortName.asString() == GenerateVariations::class.simpleName) return@forEach
|
||||||
|
|
||||||
|
addAnnotation(it.toAnnotationSpec(omitDefaultValues = false))
|
||||||
|
}
|
||||||
|
ksFunctionDeclaration.extensionReceiver ?.let {
|
||||||
|
receiver(it.toTypeName())
|
||||||
|
}
|
||||||
|
ksFunctionDeclaration.returnType ?.let {
|
||||||
|
returns(it.toTypeName())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
baseFunctionParameters.forEach { (parameter, hasDefault) ->
|
||||||
|
if (hasDefault) {
|
||||||
|
val shouldBeIncluded = (2.0.pow(currentDefaultParameterIndex.toInt()).toUInt()).and(defaultParametersIndicator) > 0u
|
||||||
|
currentDefaultParameterIndex++
|
||||||
|
|
||||||
|
if (!shouldBeIncluded) {
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
}
|
||||||
|
funSpec.addParameter(parameter)
|
||||||
|
val name = parameter.name
|
||||||
|
val defaultValueString = if (parameter.modifiers.contains(KModifier.VARARG)) {
|
||||||
|
"*$name"
|
||||||
|
} else {
|
||||||
|
"$name"
|
||||||
|
}
|
||||||
|
baseFunctionDefaults[parameter.name] = defaultValueString
|
||||||
|
}
|
||||||
|
baseFunctionFunSpecs.add(
|
||||||
|
funSpec.build() to baseFunctionDefaults.toMap()
|
||||||
|
)
|
||||||
|
defaultParametersIndicator++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
variations.forEach { (variations, parameter) ->
|
||||||
|
(baseFunctionFunSpecs + accumulatedGenerations).forEach { (accumulatedGeneration, baseDefaults) ->
|
||||||
|
if ((parameter.name ?.asString() ?: "this") !in baseDefaults.keys) {
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
variations.forEach { variation ->
|
||||||
|
val defaults = mutableMapOf<String, String>()
|
||||||
|
accumulatedGenerations.add(
|
||||||
|
FunSpec.builder(accumulatedGeneration.name).apply {
|
||||||
|
modifiers.addAll(accumulatedGeneration.modifiers)
|
||||||
|
accumulatedGeneration.annotations.forEach {
|
||||||
|
addAnnotation(it)
|
||||||
|
}
|
||||||
|
accumulatedGeneration.receiverType ?.let {
|
||||||
|
receiver(it)
|
||||||
|
}
|
||||||
|
returns(accumulatedGeneration.returnType)
|
||||||
|
accumulatedGeneration.parameters.forEach {
|
||||||
|
val actualName = if (variation.argName.isEmpty()) it.name else variation.argName
|
||||||
|
parameters.add(
|
||||||
|
(if (it.name == (parameter.name ?.asString() ?: "this")) {
|
||||||
|
val type = convertToClassName { variation.type }
|
||||||
|
val genericTypes = convertToClassNames { variation.genericTypes.toList() }
|
||||||
|
ParameterSpec
|
||||||
|
.builder(
|
||||||
|
actualName,
|
||||||
|
if (genericTypes.isEmpty()) {
|
||||||
|
type
|
||||||
|
} else {
|
||||||
|
type.parameterizedBy(
|
||||||
|
*genericTypes.toTypedArray()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.apply {
|
||||||
|
addModifiers(it.modifiers)
|
||||||
|
val defaultValueString = """
|
||||||
|
with(${actualName}) {${
|
||||||
|
if (it.modifiers.contains(KModifier.VARARG)) {
|
||||||
|
"map { it.${variation.conversion} }.toTypedArray()"
|
||||||
|
} else {
|
||||||
|
"${variation.conversion}"
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
""".trimIndent()
|
||||||
|
defaults[it.name] = defaultValueString
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
it.toBuilder().apply {
|
||||||
|
defaults[it.name] = it.name
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.apply {
|
||||||
|
it.annotations.forEach {
|
||||||
|
addAnnotation(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val parameters = accumulatedGeneration.parameters.joinToString(", ") {
|
||||||
|
val itName = it.name
|
||||||
|
"""
|
||||||
|
$itName = ${defaults[itName] ?: baseDefaults[itName] ?: itName}
|
||||||
|
""".trimIndent()
|
||||||
|
}
|
||||||
|
addCode(
|
||||||
|
"""
|
||||||
|
return ${ksFunctionDeclaration.simpleName.asString()}(
|
||||||
|
$parameters
|
||||||
|
)
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}.build() to defaults.toMap()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
accumulatedGenerations.forEach {
|
||||||
|
addFunction(it.first)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(KspExperimental::class)
|
||||||
|
override fun process(resolver: Resolver): List<KSAnnotated> {
|
||||||
|
(resolver.getSymbolsWithAnnotation(GenerateVariations::class.qualifiedName!!)).filterIsInstance<KSFunctionDeclaration>().forEach {
|
||||||
|
val prefix = (it.getAnnotationsByType(GenerateVariations::class)).firstOrNull() ?.prefix ?.takeIf {
|
||||||
|
it.isNotEmpty()
|
||||||
|
} ?: it.simpleName.asString().replaceFirst(it.simpleName.asString(), "")
|
||||||
|
it.writeFile(prefix = prefix, suffix = "GeneratedVariation") {
|
||||||
|
FileSpec.builder(
|
||||||
|
it.packageName.asString(),
|
||||||
|
"${it.simpleName.getShortName().let { it.replaceFirst(it.first().toString(), it.first().uppercase()) }}GeneratedVariation"
|
||||||
|
).apply {
|
||||||
|
addFileComment(
|
||||||
|
"""
|
||||||
|
THIS CODE HAVE BEEN GENERATED AUTOMATICALLY
|
||||||
|
TO REGENERATE IT JUST DELETE FILE
|
||||||
|
ORIGINAL FILE: ${it.containingFile ?.fileName}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
generateVariations(it, resolver)
|
||||||
|
}.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
}
|
11
ksp/variations/generator/src/main/kotlin/Provider.kt
Normal file
11
ksp/variations/generator/src/main/kotlin/Provider.kt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package dev.inmo.micro_utils.ksp.variations.generator
|
||||||
|
|
||||||
|
import com.google.devtools.ksp.processing.SymbolProcessor
|
||||||
|
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
|
||||||
|
import com.google.devtools.ksp.processing.SymbolProcessorProvider
|
||||||
|
|
||||||
|
class Provider : SymbolProcessorProvider {
|
||||||
|
override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor = Processor(
|
||||||
|
environment.codeGenerator
|
||||||
|
)
|
||||||
|
}
|
@@ -0,0 +1 @@
|
|||||||
|
dev.inmo.micro_utils.ksp.variations.generator.Provider
|
30
ksp/variations/generator/test/build.gradle
Normal file
30
ksp/variations/generator/test/build.gradle
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
|
id "com.android.library"
|
||||||
|
id "com.google.devtools.ksp"
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.do_publish = false
|
||||||
|
|
||||||
|
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64Project"
|
||||||
|
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation libs.kt.stdlib
|
||||||
|
api project(":micro_utils.ksp.variations")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
add("kspCommonMainMetadata", project(":micro_utils.ksp.variations.generator"))
|
||||||
|
}
|
||||||
|
|
||||||
|
ksp {
|
||||||
|
}
|
@@ -0,0 +1,61 @@
|
|||||||
|
// THIS CODE HAVE BEEN GENERATED AUTOMATICALLY
|
||||||
|
// TO REGENERATE IT JUST DELETE FILE
|
||||||
|
// ORIGINAL FILE: SampleFun.kt
|
||||||
|
package dev.inmo.micro_utils.ksp.variations.generator.test
|
||||||
|
|
||||||
|
import kotlin.Boolean
|
||||||
|
import kotlin.Int
|
||||||
|
import kotlin.String
|
||||||
|
import kotlin.Unit
|
||||||
|
|
||||||
|
public suspend fun SimpleType.sample2(arg12: Int): Unit = sample2(
|
||||||
|
arg1 = with(arg12) {toString()}
|
||||||
|
)
|
||||||
|
|
||||||
|
public suspend fun SimpleType.sample2(arg12: Int, arg2: Int): Unit = sample2(
|
||||||
|
arg1 = with(arg12) {toString()}, arg2 = arg2
|
||||||
|
)
|
||||||
|
|
||||||
|
public suspend fun SimpleType.sample2(arg12: Int, arg3: Boolean): Unit = sample2(
|
||||||
|
arg1 = with(arg12) {toString()}, arg3 = arg3
|
||||||
|
)
|
||||||
|
|
||||||
|
public suspend fun SimpleType.sample2(
|
||||||
|
arg12: Int,
|
||||||
|
arg2: Int,
|
||||||
|
arg3: Boolean,
|
||||||
|
): Unit = sample2(
|
||||||
|
arg1 = with(arg12) {toString()}, arg2 = arg2, arg3 = arg3
|
||||||
|
)
|
||||||
|
|
||||||
|
public suspend fun SimpleType.sample2(arg22: String): Unit = sample2(
|
||||||
|
arg2 = with(arg22) {toInt()}
|
||||||
|
)
|
||||||
|
|
||||||
|
public suspend fun SimpleType.sample2(arg1: String, arg22: String): Unit = sample2(
|
||||||
|
arg1 = arg1, arg2 = with(arg22) {toInt()}
|
||||||
|
)
|
||||||
|
|
||||||
|
public suspend fun SimpleType.sample2(arg22: String, arg3: Boolean): Unit = sample2(
|
||||||
|
arg2 = with(arg22) {toInt()}, arg3 = arg3
|
||||||
|
)
|
||||||
|
|
||||||
|
public suspend fun SimpleType.sample2(
|
||||||
|
arg1: String,
|
||||||
|
arg22: String,
|
||||||
|
arg3: Boolean,
|
||||||
|
): Unit = sample2(
|
||||||
|
arg1 = arg1, arg2 = with(arg22) {toInt()}, arg3 = arg3
|
||||||
|
)
|
||||||
|
|
||||||
|
public suspend fun SimpleType.sample2(arg12: Int, arg22: String): Unit = sample2(
|
||||||
|
arg12 = arg12, arg2 = with(arg22) {toInt()}
|
||||||
|
)
|
||||||
|
|
||||||
|
public suspend fun SimpleType.sample2(
|
||||||
|
arg12: Int,
|
||||||
|
arg22: String,
|
||||||
|
arg3: Boolean,
|
||||||
|
): Unit = sample2(
|
||||||
|
arg12 = arg12, arg2 = with(arg22) {toInt()}, arg3 = arg3
|
||||||
|
)
|
@@ -0,0 +1,52 @@
|
|||||||
|
package dev.inmo.micro_utils.ksp.variations.generator.test
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.ksp.variations.GenerateVariations
|
||||||
|
import dev.inmo.micro_utils.ksp.variations.GenerationVariant
|
||||||
|
|
||||||
|
data class SimpleType(
|
||||||
|
val value: String
|
||||||
|
)
|
||||||
|
|
||||||
|
data class GenericType<T>(
|
||||||
|
val value: T
|
||||||
|
)
|
||||||
|
|
||||||
|
@GenerateVariations
|
||||||
|
fun sample(
|
||||||
|
@GenerationVariant(
|
||||||
|
SimpleType::class,
|
||||||
|
"value",
|
||||||
|
)
|
||||||
|
@GenerationVariant(
|
||||||
|
GenericType::class,
|
||||||
|
"value.toString()",
|
||||||
|
genericTypes = arrayOf(Int::class)
|
||||||
|
)
|
||||||
|
example: String = "12"
|
||||||
|
) = println(example)
|
||||||
|
|
||||||
|
@GenerateVariations
|
||||||
|
fun sampleVararg(
|
||||||
|
@GenerationVariant(
|
||||||
|
SimpleType::class,
|
||||||
|
"value",
|
||||||
|
)
|
||||||
|
vararg example: String = arrayOf("12")
|
||||||
|
) = println(example.joinToString())
|
||||||
|
|
||||||
|
@GenerateVariations
|
||||||
|
suspend fun SimpleType.sample2(
|
||||||
|
@GenerationVariant(
|
||||||
|
Int::class,
|
||||||
|
"toString()",
|
||||||
|
"arg12",
|
||||||
|
)
|
||||||
|
arg1: String = "1",
|
||||||
|
@GenerationVariant(
|
||||||
|
String::class,
|
||||||
|
"toInt()",
|
||||||
|
"arg22",
|
||||||
|
)
|
||||||
|
arg2: Int = 2,
|
||||||
|
arg3: Boolean = false
|
||||||
|
) = println(arg1)
|
@@ -0,0 +1,15 @@
|
|||||||
|
// THIS CODE HAVE BEEN GENERATED AUTOMATICALLY
|
||||||
|
// TO REGENERATE IT JUST DELETE FILE
|
||||||
|
// ORIGINAL FILE: SampleFun.kt
|
||||||
|
package dev.inmo.micro_utils.ksp.variations.generator.test
|
||||||
|
|
||||||
|
import kotlin.Int
|
||||||
|
import kotlin.Unit
|
||||||
|
|
||||||
|
public fun sample(example: SimpleType): Unit = sample(
|
||||||
|
example = with(example) {value}
|
||||||
|
)
|
||||||
|
|
||||||
|
public fun sample(example: GenericType<Int>): Unit = sample(
|
||||||
|
example = with(example) {value.toString()}
|
||||||
|
)
|
@@ -0,0 +1,10 @@
|
|||||||
|
// THIS CODE HAVE BEEN GENERATED AUTOMATICALLY
|
||||||
|
// TO REGENERATE IT JUST DELETE FILE
|
||||||
|
// ORIGINAL FILE: SampleFun.kt
|
||||||
|
package dev.inmo.micro_utils.ksp.variations.generator.test
|
||||||
|
|
||||||
|
import kotlin.Unit
|
||||||
|
|
||||||
|
public fun sampleVararg(vararg example: SimpleType): Unit = sampleVararg(
|
||||||
|
example = with(example) {map { it.value }.toTypedArray()}
|
||||||
|
)
|
@@ -0,0 +1,7 @@
|
|||||||
|
package dev.inmo.micro_utils.ksp.variations
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.BINARY)
|
||||||
|
@Target(AnnotationTarget.FUNCTION)
|
||||||
|
annotation class GenerateVariations(
|
||||||
|
val prefix: String = ""
|
||||||
|
)
|
18
ksp/variations/src/commonMain/kotlin/GenerationVariant.kt
Normal file
18
ksp/variations/src/commonMain/kotlin/GenerationVariant.kt
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package dev.inmo.micro_utils.ksp.variations
|
||||||
|
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param argName New argument name. Default - empty - means "use default arg name"
|
||||||
|
* @param type Qualified class name, like "dev.inmo.micro_utils.ksp.variants.GenerationVariant"
|
||||||
|
* @param conversion Conversion string with `this`
|
||||||
|
*/
|
||||||
|
@Retention(AnnotationRetention.BINARY)
|
||||||
|
@Repeatable
|
||||||
|
@Target(AnnotationTarget.TYPE_PARAMETER, AnnotationTarget.VALUE_PARAMETER)
|
||||||
|
annotation class GenerationVariant(
|
||||||
|
val type: KClass<*>,
|
||||||
|
val conversion: String,
|
||||||
|
val argName: String = "",
|
||||||
|
vararg val genericTypes: KClass<*>
|
||||||
|
)
|
@@ -2,7 +2,7 @@ package dev.inmo.micro_utils.ktor.client
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.common.MPPFile
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
import dev.inmo.micro_utils.coroutines.LinkedSupervisorJob
|
import dev.inmo.micro_utils.coroutines.LinkedSupervisorJob
|
||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
||||||
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.content.*
|
import io.ktor.client.content.*
|
||||||
@@ -27,7 +27,7 @@ suspend fun tempUpload(
|
|||||||
val request = XMLHttpRequest()
|
val request = XMLHttpRequest()
|
||||||
request.responseType = XMLHttpRequestResponseType.TEXT
|
request.responseType = XMLHttpRequestResponseType.TEXT
|
||||||
request.upload.onprogress = {
|
request.upload.onprogress = {
|
||||||
subscope.launchSafelyWithoutExceptions { onUpload.onProgress(it.loaded.toLong(), it.total.toLong()) }
|
subscope.launchLoggingDropExceptions { onUpload.onProgress(it.loaded.toLong(), it.total.toLong()) }
|
||||||
}
|
}
|
||||||
request.onload = {
|
request.onload = {
|
||||||
if (request.status == 200.toShort()) {
|
if (request.status == 200.toShort()) {
|
||||||
|
@@ -2,7 +2,7 @@ package dev.inmo.micro_utils.ktor.client
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.common.MPPFile
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
import dev.inmo.micro_utils.coroutines.LinkedSupervisorJob
|
import dev.inmo.micro_utils.coroutines.LinkedSupervisorJob
|
||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.content.*
|
import io.ktor.client.content.*
|
||||||
import io.ktor.http.Headers
|
import io.ktor.http.Headers
|
||||||
@@ -66,7 +66,7 @@ actual suspend fun <T> HttpClient.uniUpload(
|
|||||||
}
|
}
|
||||||
request.responseType = XMLHttpRequestResponseType.TEXT
|
request.responseType = XMLHttpRequestResponseType.TEXT
|
||||||
request.upload.onprogress = {
|
request.upload.onprogress = {
|
||||||
subscope.launchSafelyWithoutExceptions { onUpload.onProgress(it.loaded.toLong(), it.total.toLong()) }
|
subscope.launchLoggingDropExceptions { onUpload.onProgress(it.loaded.toLong(), it.total.toLong()) }
|
||||||
}
|
}
|
||||||
request.onload = {
|
request.onload = {
|
||||||
if (request.status == 200.toShort()) {
|
if (request.status == 200.toShort()) {
|
||||||
|
@@ -3,7 +3,7 @@ package dev.inmo.micro_utils.ktor.server
|
|||||||
import com.benasher44.uuid.uuid4
|
import com.benasher44.uuid.uuid4
|
||||||
import dev.inmo.micro_utils.common.FileName
|
import dev.inmo.micro_utils.common.FileName
|
||||||
import dev.inmo.micro_utils.common.MPPFile
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
||||||
import dev.inmo.micro_utils.ktor.common.DefaultTemporalFilesSubPath
|
import dev.inmo.micro_utils.ktor.common.DefaultTemporalFilesSubPath
|
||||||
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
||||||
import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator
|
import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator
|
||||||
@@ -44,7 +44,7 @@ class TemporalFilesRoutingConfigurator(
|
|||||||
filesMap: MutableMap<TemporalFileId, MPPFile>,
|
filesMap: MutableMap<TemporalFileId, MPPFile>,
|
||||||
filesMutex: Mutex,
|
filesMutex: Mutex,
|
||||||
onNewFileFlow: Flow<TemporalFileId>
|
onNewFileFlow: Flow<TemporalFileId>
|
||||||
): Job = scope.launchSafelyWithoutExceptions {
|
): Job = scope.launchLoggingDropExceptions {
|
||||||
while (currentCoroutineContext().isActive) {
|
while (currentCoroutineContext().isActive) {
|
||||||
val filesWithCreationInfo = filesMap.mapNotNull { (fileId, file) ->
|
val filesWithCreationInfo = filesMap.mapNotNull { (fileId, file) ->
|
||||||
fileId to ((Files.getAttribute(file.toPath(), "creationTime") as? FileTime) ?.toMillis() ?: return@mapNotNull null)
|
fileId to ((Files.getAttribute(file.toPath(), "creationTime") as? FileTime) ?.toMillis() ?: return@mapNotNull null)
|
||||||
|
@@ -2,10 +2,10 @@ package dev.inmo.micro_utils.pagination
|
|||||||
|
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
|
|
||||||
fun Query.paginate(with: Pagination, orderBy: Pair<Expression<*>, SortOrder>? = null) = limit(
|
fun Query.paginate(with: Pagination, orderBy: Pair<Expression<*>, SortOrder>? = null) =
|
||||||
with.size,
|
limit(with.size)
|
||||||
with.firstIndex.toLong()
|
.offset(with.firstIndex.toLong())
|
||||||
).let {
|
.let {
|
||||||
if (orderBy != null) {
|
if (orderBy != null) {
|
||||||
it.orderBy(
|
it.orderBy(
|
||||||
orderBy.first,
|
orderBy.first,
|
||||||
|
@@ -2,7 +2,7 @@ package dev.inmo.micro_utils.repos.cache.full
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.common.*
|
import dev.inmo.micro_utils.common.*
|
||||||
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
||||||
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
||||||
import dev.inmo.micro_utils.coroutines.withWriteLock
|
import dev.inmo.micro_utils.coroutines.withWriteLock
|
||||||
import dev.inmo.micro_utils.pagination.Pagination
|
import dev.inmo.micro_utils.pagination.Pagination
|
||||||
@@ -116,7 +116,7 @@ open class FullCRUDCacheRepo<ObjectType, IdType, InputValueType>(
|
|||||||
CRUDRepo<ObjectType, IdType, InputValueType> {
|
CRUDRepo<ObjectType, IdType, InputValueType> {
|
||||||
init {
|
init {
|
||||||
if (!skipStartInvalidate) {
|
if (!skipStartInvalidate) {
|
||||||
scope.launchSafelyWithoutExceptions {
|
scope.launchLoggingDropExceptions {
|
||||||
if (locker.writeMutex.isLocked) {
|
if (locker.writeMutex.isLocked) {
|
||||||
initialInvalidate()
|
initialInvalidate()
|
||||||
} else {
|
} else {
|
||||||
|
@@ -2,7 +2,7 @@ package dev.inmo.micro_utils.repos.cache.full
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.common.*
|
import dev.inmo.micro_utils.common.*
|
||||||
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
||||||
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
||||||
import dev.inmo.micro_utils.coroutines.withWriteLock
|
import dev.inmo.micro_utils.coroutines.withWriteLock
|
||||||
import dev.inmo.micro_utils.pagination.Pagination
|
import dev.inmo.micro_utils.pagination.Pagination
|
||||||
@@ -141,7 +141,7 @@ open class FullKeyValueCacheRepo<Key,Value>(
|
|||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
if (!skipStartInvalidate) {
|
if (!skipStartInvalidate) {
|
||||||
scope.launchSafelyWithoutExceptions {
|
scope.launchLoggingDropExceptions {
|
||||||
if (locker.writeMutex.isLocked) {
|
if (locker.writeMutex.isLocked) {
|
||||||
initialInvalidate()
|
initialInvalidate()
|
||||||
} else {
|
} else {
|
||||||
|
@@ -2,7 +2,7 @@ package dev.inmo.micro_utils.repos.cache.full
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.common.*
|
import dev.inmo.micro_utils.common.*
|
||||||
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
||||||
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
||||||
import dev.inmo.micro_utils.coroutines.withWriteLock
|
import dev.inmo.micro_utils.coroutines.withWriteLock
|
||||||
import dev.inmo.micro_utils.pagination.*
|
import dev.inmo.micro_utils.pagination.*
|
||||||
@@ -210,7 +210,7 @@ open class FullKeyValuesCacheRepo<Key,Value>(
|
|||||||
WriteKeyValuesRepo<Key, Value> by parentRepo {
|
WriteKeyValuesRepo<Key, Value> by parentRepo {
|
||||||
init {
|
init {
|
||||||
if (!skipStartInvalidate) {
|
if (!skipStartInvalidate) {
|
||||||
scope.launchSafelyWithoutExceptions {
|
scope.launchLoggingDropExceptions {
|
||||||
if (locker.writeMutex.isLocked) {
|
if (locker.writeMutex.isLocked) {
|
||||||
initialInvalidate()
|
initialInvalidate()
|
||||||
} else {
|
} else {
|
||||||
|
@@ -2,7 +2,7 @@ package dev.inmo.micro_utils.repos.cache.full.direct
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.common.*
|
import dev.inmo.micro_utils.common.*
|
||||||
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
||||||
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
||||||
import dev.inmo.micro_utils.coroutines.withWriteLock
|
import dev.inmo.micro_utils.coroutines.withWriteLock
|
||||||
import dev.inmo.micro_utils.pagination.Pagination
|
import dev.inmo.micro_utils.pagination.Pagination
|
||||||
@@ -82,7 +82,7 @@ open class DirectFullCRUDCacheRepo<ObjectType, IdType, InputValueType>(
|
|||||||
CRUDRepo<ObjectType, IdType, InputValueType> {
|
CRUDRepo<ObjectType, IdType, InputValueType> {
|
||||||
init {
|
init {
|
||||||
if (!skipStartInvalidate) {
|
if (!skipStartInvalidate) {
|
||||||
scope.launchSafelyWithoutExceptions {
|
scope.launchLoggingDropExceptions {
|
||||||
if (locker.writeMutex.isLocked) {
|
if (locker.writeMutex.isLocked) {
|
||||||
initialInvalidate()
|
initialInvalidate()
|
||||||
} else {
|
} else {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package dev.inmo.micro_utils.repos.cache.full.direct
|
package dev.inmo.micro_utils.repos.cache.full.direct
|
||||||
|
|
||||||
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
||||||
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
||||||
import dev.inmo.micro_utils.coroutines.withWriteLock
|
import dev.inmo.micro_utils.coroutines.withWriteLock
|
||||||
import dev.inmo.micro_utils.pagination.Pagination
|
import dev.inmo.micro_utils.pagination.Pagination
|
||||||
@@ -117,7 +117,7 @@ open class DirectFullKeyValueCacheRepo<Key, Value>(
|
|||||||
DirectFullReadKeyValueCacheRepo<Key, Value>(parentRepo, kvCache, locker) {
|
DirectFullReadKeyValueCacheRepo<Key, Value>(parentRepo, kvCache, locker) {
|
||||||
init {
|
init {
|
||||||
if (!skipStartInvalidate) {
|
if (!skipStartInvalidate) {
|
||||||
scope.launchSafelyWithoutExceptions {
|
scope.launchLoggingDropExceptions {
|
||||||
if (locker.writeMutex.isLocked) {
|
if (locker.writeMutex.isLocked) {
|
||||||
initialInvalidate()
|
initialInvalidate()
|
||||||
} else {
|
} else {
|
||||||
|
@@ -2,7 +2,7 @@ package dev.inmo.micro_utils.repos.cache.full.direct
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.common.*
|
import dev.inmo.micro_utils.common.*
|
||||||
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
||||||
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
||||||
import dev.inmo.micro_utils.coroutines.withWriteLock
|
import dev.inmo.micro_utils.coroutines.withWriteLock
|
||||||
import dev.inmo.micro_utils.pagination.*
|
import dev.inmo.micro_utils.pagination.*
|
||||||
@@ -145,7 +145,7 @@ open class DirectFullKeyValuesCacheRepo<Key,Value>(
|
|||||||
WriteKeyValuesRepo<Key, Value> by parentRepo {
|
WriteKeyValuesRepo<Key, Value> by parentRepo {
|
||||||
init {
|
init {
|
||||||
if (!skipStartInvalidate) {
|
if (!skipStartInvalidate) {
|
||||||
scope.launchSafelyWithoutExceptions {
|
scope.launchLoggingDropExceptions {
|
||||||
if (locker.writeMutex.isLocked) {
|
if (locker.writeMutex.isLocked) {
|
||||||
initialInvalidate()
|
initialInvalidate()
|
||||||
} else {
|
} else {
|
||||||
|
@@ -137,7 +137,7 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
|||||||
override suspend fun deleteById(ids: List<IdType>) {
|
override suspend fun deleteById(ids: List<IdType>) {
|
||||||
onBeforeDelete(ids)
|
onBeforeDelete(ids)
|
||||||
transaction(db = database) {
|
transaction(db = database) {
|
||||||
val deleted = deleteWhere(null, null) { selectByIds(it, ids) }
|
val deleted = deleteWhere { selectByIds(it, ids) }
|
||||||
if (deleted == ids.size) {
|
if (deleted == ids.size) {
|
||||||
ids
|
ids
|
||||||
} else {
|
} else {
|
||||||
|
@@ -62,6 +62,10 @@ String[] includes = [
|
|||||||
":ksp:classcasts:generator",
|
":ksp:classcasts:generator",
|
||||||
":ksp:classcasts:generator:test",
|
":ksp:classcasts:generator:test",
|
||||||
|
|
||||||
|
":ksp:variations",
|
||||||
|
":ksp:variations:generator",
|
||||||
|
":ksp:variations:generator:test",
|
||||||
|
|
||||||
":dokka"
|
":dokka"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user