Merge pull request #250 from InsanusMokrassar/0.18.2

0.18.2
This commit is contained in:
InsanusMokrassar 2023-05-10 10:19:47 +06:00 committed by GitHub
commit dbc921d56d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 4 deletions

View File

@ -1,5 +1,10 @@
# Changelog
## 0.18.2
* `Startup`:
* Now internal `Json` is fully customizable
## 0.18.1
* `Common`:

View File

@ -14,5 +14,5 @@ crypto_js_version=4.1.1
# Project data
group=dev.inmo
version=0.18.1
android_code_version=192
version=0.18.2
android_code_version=193

View File

@ -2,6 +2,7 @@ plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
id "application"
id "com.google.devtools.ksp"
}
apply from: "$mppJvmJsLinuxMingwProjectPresetPath"
@ -11,6 +12,7 @@ kotlin {
commonMain {
dependencies {
api internalProject("micro_utils.startup.plugin")
api internalProject("micro_utils.koin")
}
}
commonTest {
@ -29,3 +31,10 @@ java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
add("kspCommonMainMetadata", project(":micro_utils.koin.generator"))
}
ksp {
}

View File

@ -0,0 +1,38 @@
// THIS CODE HAVE BEEN GENERATED AUTOMATICALLY
// TO REGENERATE IT JUST DELETE FILE
// ORIGINAL FILE: StartLauncherPlugin.kt
package dev.inmo.micro_utils.startup.launcher
import kotlin.Boolean
import kotlinx.serialization.json.Json
import org.koin.core.Koin
import org.koin.core.definition.Definition
import org.koin.core.definition.KoinDefinition
import org.koin.core.module.Module
import org.koin.core.qualifier.named
import org.koin.core.scope.Scope
/**
* @return Definition by key "baseJsonProvider"
*/
public val Scope.baseJsonProvider: Json?
get() = getOrNull(named("baseJsonProvider"))
/**
* @return Definition by key "baseJsonProvider"
*/
public val Koin.baseJsonProvider: Json?
get() = getOrNull(named("baseJsonProvider"))
/**
* Will register [definition] with [org.koin.core.module.Module.single] and key "baseJsonProvider"
*/
public fun Module.baseJsonProviderSingle(createdAtStart: Boolean = false, definition: Definition<Json>):
KoinDefinition<Json> = single(named("baseJsonProvider"), createdAtStart = createdAtStart, definition
= definition)
/**
* Will register [definition] with [org.koin.core.module.Module.factory] and key "baseJsonProvider"
*/
public fun Module.baseJsonProviderFactory(definition: Definition<Json>): KoinDefinition<Json> =
factory(named("baseJsonProvider"), definition = definition)

View File

@ -1,9 +1,11 @@
@file:GenerateKoinDefinition("baseJsonProvider", Json::class)
package dev.inmo.micro_utils.startup.launcher
import dev.inmo.kslog.common.i
import dev.inmo.kslog.common.taggedLogger
import dev.inmo.kslog.common.w
import dev.inmo.micro_utils.coroutines.runCatchingSafely
import dev.inmo.micro_utils.koin.annotations.GenerateKoinDefinition
import dev.inmo.micro_utils.startup.launcher.StartLauncherPlugin.setupDI
import dev.inmo.micro_utils.startup.launcher.StartLauncherPlugin.startPlugin
import dev.inmo.micro_utils.startup.plugin.StartPlugin
@ -13,9 +15,10 @@ import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
import kotlinx.serialization.SerialFormat
import kotlinx.serialization.StringFormat
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.decodeFromJsonElement
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.modules.SerializersModule
import org.koin.core.Koin
import org.koin.core.KoinApplication
import org.koin.core.context.startKoin
@ -35,7 +38,20 @@ object StartLauncherPlugin : StartPlugin {
single { rawJsonObject }
single { config }
single { CoroutineScope(Dispatchers.Default) }
single { defaultJson } binds arrayOf(StringFormat::class, SerialFormat::class)
single {
val serializersModules = getAll<SerializersModule>().distinct()
val baseJson = baseJsonProvider ?: defaultJson
if (serializersModules.isEmpty()) {
baseJson
} else {
Json(baseJson) {
serializersModule = SerializersModule {
include(baseJson.serializersModule)
serializersModules.forEach { include(it) }
}
}
}
} binds arrayOf(StringFormat::class, SerialFormat::class)
includes(
config.plugins.mapNotNull {