diff --git a/search-client/build.gradle.kts b/search-client/build.gradle.kts index 09780940..b19ebfe8 100644 --- a/search-client/build.gradle.kts +++ b/search-client/build.gradle.kts @@ -89,6 +89,11 @@ kotlin { mingwX64() macosX64() macosArm64() + // iOS targets + iosArm64() + iosX64() + // Blocked on json-dsl and kotlinx-serialization-extensions support + // iosSimulatorArm64() // Blocked on ktor-client support // wasmJs { // browser() @@ -155,7 +160,19 @@ kotlin { } } - nativeMain { + iosMain { + dependencies { + implementation(Ktor.client.darwin) + } + } + + macosMain { + dependencies { + implementation(Ktor.client.darwin) + } + } + + mingwMain { dependencies { implementation(Ktor.client.curl) } diff --git a/search-client/src/iosMain/kotlin/com/jillesvangurp/ktsearch/KtorRestClient.ios.kt b/search-client/src/iosMain/kotlin/com/jillesvangurp/ktsearch/KtorRestClient.ios.kt new file mode 100644 index 00000000..a302f8a1 --- /dev/null +++ b/search-client/src/iosMain/kotlin/com/jillesvangurp/ktsearch/KtorRestClient.ios.kt @@ -0,0 +1,56 @@ +package com.jillesvangurp.ktsearch + +import com.jillesvangurp.serializationext.DEFAULT_JSON +import io.ktor.client.* +import io.ktor.client.plugins.auth.* +import io.ktor.client.plugins.auth.providers.* +import io.ktor.client.plugins.contentnegotiation.* +import io.ktor.client.plugins.logging.* +import io.ktor.http.* +import io.ktor.serialization.kotlinx.json.* + + +import io.ktor.client.* +import io.ktor.client.engine.darwin.* + +actual fun defaultKtorHttpClient( + logging: Boolean, + user: String?, + password: String?, + elasticApiKey: String? +): HttpClient { + return HttpClient(Darwin) { + engine { + pipelining = true + configureRequest { + setAllowsCellularAccess(true) + } + } + if(!user.isNullOrBlank() && !password.isNullOrBlank()) { + install(Auth) { + basic { + credentials { + BasicAuthCredentials(user, password) + } + sendWithoutRequest { + true + } + } + } + } + if(!elasticApiKey.isNullOrBlank()) { + headers { + append("Authorization", "ApiKey $elasticApiKey") + } + } + install(ContentNegotiation) { + json(DEFAULT_JSON) + } + if (logging) { + install(Logging) { + level = LogLevel.ALL + } + } + + } +} \ No newline at end of file diff --git a/search-client/src/nativeMain/kotlin/com/jillesvangurp/ktsearch/RoundRobinNodeSelector.native.kt b/search-client/src/iosMain/kotlin/com/jillesvangurp/ktsearch/RoundRobinNodeSelector.ios.kt similarity index 100% rename from search-client/src/nativeMain/kotlin/com/jillesvangurp/ktsearch/RoundRobinNodeSelector.native.kt rename to search-client/src/iosMain/kotlin/com/jillesvangurp/ktsearch/RoundRobinNodeSelector.ios.kt diff --git a/search-client/src/nativeMain/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelector.native.kt b/search-client/src/iosMain/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelector.ios.kt similarity index 100% rename from search-client/src/nativeMain/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelector.native.kt rename to search-client/src/iosMain/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelector.ios.kt diff --git a/search-client/src/macosMain/kotlin/com/jillesvangurp/ktsearch/KtorRestClient.macos.kt b/search-client/src/macosMain/kotlin/com/jillesvangurp/ktsearch/KtorRestClient.macos.kt new file mode 100644 index 00000000..a302f8a1 --- /dev/null +++ b/search-client/src/macosMain/kotlin/com/jillesvangurp/ktsearch/KtorRestClient.macos.kt @@ -0,0 +1,56 @@ +package com.jillesvangurp.ktsearch + +import com.jillesvangurp.serializationext.DEFAULT_JSON +import io.ktor.client.* +import io.ktor.client.plugins.auth.* +import io.ktor.client.plugins.auth.providers.* +import io.ktor.client.plugins.contentnegotiation.* +import io.ktor.client.plugins.logging.* +import io.ktor.http.* +import io.ktor.serialization.kotlinx.json.* + + +import io.ktor.client.* +import io.ktor.client.engine.darwin.* + +actual fun defaultKtorHttpClient( + logging: Boolean, + user: String?, + password: String?, + elasticApiKey: String? +): HttpClient { + return HttpClient(Darwin) { + engine { + pipelining = true + configureRequest { + setAllowsCellularAccess(true) + } + } + if(!user.isNullOrBlank() && !password.isNullOrBlank()) { + install(Auth) { + basic { + credentials { + BasicAuthCredentials(user, password) + } + sendWithoutRequest { + true + } + } + } + } + if(!elasticApiKey.isNullOrBlank()) { + headers { + append("Authorization", "ApiKey $elasticApiKey") + } + } + install(ContentNegotiation) { + json(DEFAULT_JSON) + } + if (logging) { + install(Logging) { + level = LogLevel.ALL + } + } + + } +} \ No newline at end of file diff --git a/search-client/src/macosMain/kotlin/com/jillesvangurp/ktsearch/RoundRobinNodeSelector.macos.kt b/search-client/src/macosMain/kotlin/com/jillesvangurp/ktsearch/RoundRobinNodeSelector.macos.kt new file mode 100644 index 00000000..100faf45 --- /dev/null +++ b/search-client/src/macosMain/kotlin/com/jillesvangurp/ktsearch/RoundRobinNodeSelector.macos.kt @@ -0,0 +1,11 @@ +package com.jillesvangurp.ktsearch + +actual fun simpleIndexProvider(initialIndex: Int): IndexProvider = object : IndexProvider { + private var index = 0 + + override fun get(): Int = index + + override fun set(value: Int) { + index = value + } +} \ No newline at end of file diff --git a/search-client/src/macosMain/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelector.macos.kt b/search-client/src/macosMain/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelector.macos.kt new file mode 100644 index 00000000..c77ac9a3 --- /dev/null +++ b/search-client/src/macosMain/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelector.macos.kt @@ -0,0 +1,6 @@ +package com.jillesvangurp.ktsearch + +/** + * On JVM this will return the current thread name, otherwise this will return null and pick a random node + */ +actual fun threadId(): String? = null \ No newline at end of file diff --git a/search-client/src/nativeMain/kotlin/com/jillesvangurp/ktsearch/KtorRestClient.native.kt b/search-client/src/mingwMain/kotlin/com/jillesvangurp/ktsearch/KtorRestClient.mingw.kt similarity index 100% rename from search-client/src/nativeMain/kotlin/com/jillesvangurp/ktsearch/KtorRestClient.native.kt rename to search-client/src/mingwMain/kotlin/com/jillesvangurp/ktsearch/KtorRestClient.mingw.kt diff --git a/search-client/src/mingwMain/kotlin/com/jillesvangurp/ktsearch/RoundRobinNodeSelector.mingw.kt b/search-client/src/mingwMain/kotlin/com/jillesvangurp/ktsearch/RoundRobinNodeSelector.mingw.kt new file mode 100644 index 00000000..100faf45 --- /dev/null +++ b/search-client/src/mingwMain/kotlin/com/jillesvangurp/ktsearch/RoundRobinNodeSelector.mingw.kt @@ -0,0 +1,11 @@ +package com.jillesvangurp.ktsearch + +actual fun simpleIndexProvider(initialIndex: Int): IndexProvider = object : IndexProvider { + private var index = 0 + + override fun get(): Int = index + + override fun set(value: Int) { + index = value + } +} \ No newline at end of file diff --git a/search-client/src/mingwMain/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelector.mingw.kt b/search-client/src/mingwMain/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelector.mingw.kt new file mode 100644 index 00000000..c77ac9a3 --- /dev/null +++ b/search-client/src/mingwMain/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelector.mingw.kt @@ -0,0 +1,6 @@ +package com.jillesvangurp.ktsearch + +/** + * On JVM this will return the current thread name, otherwise this will return null and pick a random node + */ +actual fun threadId(): String? = null \ No newline at end of file diff --git a/search-dsls/build.gradle.kts b/search-dsls/build.gradle.kts index 520ab77a..1bd35528 100644 --- a/search-dsls/build.gradle.kts +++ b/search-dsls/build.gradle.kts @@ -26,6 +26,10 @@ kotlin { mingwX64() macosX64() macosArm64() + iosArm64() + iosX64() + // Blocked on json-dsl and kotlinx-serialization-extensions support + // iosSimulatorArm64() wasmJs { browser() nodejs()