Skip to content

Commit

Permalink
Convert cloud modules to kotlin multiplatform (#892)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashdavies authored Mar 12, 2024
1 parent b671097 commit 1a71db8
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 101 deletions.
28 changes: 16 additions & 12 deletions app-check/app-check-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("io.ashdavies.cloud")
id("io.ashdavies.kotlin")
id("io.ashdavies.properties")

alias(libs.plugins.build.config)
Expand All @@ -25,15 +25,19 @@ buildConfig {
packageName.set("io.ashdavies.check")
}

dependencies {
implementation(libs.auth.java.jwt)
implementation(libs.auth.jwks.rsa)
implementation(libs.google.auth.http)
implementation(libs.google.firebase.admin)
implementation(libs.kotlinx.datetime)
implementation(libs.kotlinx.serialization.core)
implementation(libs.ktor.client.core)

runtimeOnly(libs.google.guava.jre)
runtimeOnly(libs.slf4j.simple)
kotlin {
commonMain.dependencies {
implementation(libs.auth.java.jwt)
implementation(libs.auth.jwks.rsa)
implementation(libs.google.auth.http)
implementation(libs.google.firebase.admin)
implementation(libs.kotlinx.datetime)
implementation(libs.kotlinx.serialization.core)
implementation(libs.ktor.client.core)
}

jvmMain.dependencies {
runtimeOnly(libs.google.guava.jre)
runtimeOnly(libs.slf4j.simple)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlinx.datetime.toJavaInstant
import kotlin.time.Duration.Companion.hours

private const val APP_CHECK_ENDPOINT = "https://firebaseappcheck.googleapis.com"
private const val APP_CHECK_AUDIENCE = "${APP_CHECK_ENDPOINT}/google.firebase.appcheck.v1.TokenExchangeService"
private const val APP_CHECK_AUDIENCE = "$APP_CHECK_ENDPOINT/google.firebase.appcheck.v1.TokenExchangeService"

internal object Jwt : JWT()

Expand Down
16 changes: 0 additions & 16 deletions build-plugins/src/main/kotlin/io.ashdavies.cloud.gradle.kts

This file was deleted.

10 changes: 0 additions & 10 deletions build-plugins/src/main/kotlin/io.ashdavies.graphql.gradle.kts

This file was deleted.

28 changes: 19 additions & 9 deletions events-aggregator/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode

plugins {
id("io.ashdavies.cloud")
id("io.ashdavies.graphql")
id("io.ashdavies.kotlin")
id("io.ashdavies.properties")

alias(libs.plugins.apollo.graphql)
alias(libs.plugins.build.config)
}

apollo {
generateKotlinModels.set(true)
}

buildConfig {
val githubToken by stringPropertyOrNull { value ->
buildConfigField<String?>("GITHUB_TOKEN", value)
Expand All @@ -14,12 +20,16 @@ buildConfig {
packageName.set("io.ashdavies.playground.aggregator")
}

dependencies {
implementation(projects.microYaml)
kotlin {
explicitApi = ExplicitApiMode.Disabled

implementation(libs.apollo.graphql.coroutines.support)
implementation(libs.apollo.graphql.runtime)
implementation(libs.kotlinx.serialization.core)
implementation(libs.squareup.okhttp)
implementation(libs.squareup.okio)
commonMain.dependencies {
implementation(projects.microYaml)

implementation(libs.apollo.graphql.coroutines.support)
implementation(libs.apollo.graphql.runtime)
implementation(libs.kotlinx.serialization.core)
implementation(libs.squareup.okhttp)
implementation(libs.squareup.okio)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,16 @@ import io.ashdavies.playground.apollo.entries
import io.ashdavies.playground.apollo.requireOid
import io.ashdavies.playground.apollo.requireText
import io.ashdavies.yaml.Yaml
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

public interface GitHubService {
public suspend fun <T : Any> getEvents(
mapper: (
@ParameterName("id")
String,
@ParameterName("name")
String,
@ParameterName("website")
String,
@ParameterName("location")
String,
@ParameterName("status")
String?,
@ParameterName("online")
Boolean?,
@ParameterName("dateStart")
String,
@ParameterName("dateEnd")
String,
@ParameterName("cfpStart")
String?,
@ParameterName("cfpEnd")
String?,
@ParameterName("cfpSite")
String?,
) -> T,
): List<T>

public companion object Default : GitHubService by GitHubService(
client = ApolloClient(),
yaml = Yaml,
)
}
public suspend fun <T : Any> getEvents(mapper: Mapper<T>): List<T>

@Suppress("NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_WARNING")
public fun GitHubService(client: ApolloClient, yaml: Yaml) = object : GitHubService {
override suspend fun <T : Any> getEvents(
mapper: (
public fun interface Mapper<T : Any> {
public operator fun invoke(
id: String,
name: String,
website: String,
Expand All @@ -60,30 +29,36 @@ public fun GitHubService(client: ApolloClient, yaml: Yaml) = object : GitHubServ
cfpStart: String?,
cfpEnd: String?,
cfpSite: String?,
) -> T,
): List<T> {
): T
}

@OptIn(ExperimentalSerializationApi::class)
public companion object Default : GitHubService by GitHubService(
client = ApolloClient(),
yaml = Yaml,
)
}

@ExperimentalSerializationApi
public fun GitHubService(client: ApolloClient, yaml: Yaml): GitHubService = object : GitHubService {
override suspend fun <T : Any> getEvents(mapper: GitHubService.Mapper<T>): List<T> {
val entries: List<EventsQuery.AsBlob> = client
.query(EventsQuery())
.await()
.entries
.asBlobs()

return entries.map {
with(yaml.decodeFromString(GitHubConference.serializer(), it.requireText())) {
mapper(
/* id */ it.requireOid(),
/* name */ name,
/* website */ website,
/* location */ location,
/* status */ status,
/* online */ online,
/* dateStart */ dateStart,
/* dateEnd */ dateEnd,
/* cfpStart */ cfp?.start,
/* cfpEnd */ cfp?.end,
/* cfpSite */ cfp?.site,
)
}
val serializer = GitHubConference.serializer()

return entries.map { blob ->
val value = yaml.decodeFromString(serializer, blob.requireText())

mapper(
id = blob.requireOid(), name = value.name, website = value.website,
location = value.location, status = value.status, online = value.online,
dateStart = value.dateStart, dateEnd = value.dateEnd, cfpStart = value.cfp?.start,
cfpEnd = value.cfp?.end, cfpSite = value.cfp?.site,
)
}
}
}
Expand Down

0 comments on commit 1a71db8

Please sign in to comment.