Skip to content

Commit

Permalink
Update schema, enable explicit API mode for KMP modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
ychescale9 committed Nov 23, 2023
1 parent 71ae5b8 commit 53799d7
Show file tree
Hide file tree
Showing 27 changed files with 135 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.gradle.api.Project
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

/**
* Apply common configs to KMP project.
Expand Down Expand Up @@ -33,7 +34,7 @@ internal fun KotlinMultiplatformExtension.configureKMPCommon(
/**
* Apply test configs to KMP project.
*/
internal fun KotlinMultiplatformExtension.configureKMPCommon() {
internal fun KotlinMultiplatformExtension.configureKMPTest() {
with(sourceSets) {
commonTest {
dependencies {
Expand All @@ -60,3 +61,14 @@ internal fun Project.configureKotlinCommonCompileOptions() {
}
}
}

/**
* Enable explicit API mode for non-test Kotlin compilations
*/
internal fun Project.enableExplicitApi() {
tasks.withType<KotlinCompile>().configureEach {
if (!name.contains("TestKotlin")) {
kotlinOptions.freeCompilerArgs += "-Xexplicit-api=strict"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.reactivecircus.kstreamlined.buildlogic.convention

import io.github.reactivecircus.kstreamlined.buildlogic.configureDetekt
import io.github.reactivecircus.kstreamlined.buildlogic.enableExplicitApi
import io.github.reactivecircus.kstreamlined.buildlogic.configureKMPCommon
import io.github.reactivecircus.kstreamlined.buildlogic.configureKotlinCommonCompileOptions
import io.github.reactivecircus.kstreamlined.buildlogic.configureTest
Expand All @@ -16,6 +17,7 @@ internal class KMPCommonConventionPlugin : Plugin<Project> {

extensions.configure<KotlinMultiplatformExtension> {
configureKMPCommon(target)
enableExplicitApi()
}

configureKotlinCommonCompileOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.github.reactivecircus.kstreamlined.buildlogic.configureDetekt
import io.github.reactivecircus.kstreamlined.buildlogic.configureKMPCommon
import io.github.reactivecircus.kstreamlined.buildlogic.configureKotlinCommonCompileOptions
import io.github.reactivecircus.kstreamlined.buildlogic.configureTest
import io.github.reactivecircus.kstreamlined.buildlogic.enableExplicitApi
import io.github.reactivecircus.kstreamlined.buildlogic.markNonCompatibleConfigurationCacheTasks
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -16,6 +17,7 @@ internal class KMPIosOnlyConventionPlugin : Plugin<Project> {

extensions.configure<KotlinMultiplatformExtension> {
configureKMPCommon(target, enableJvmTarget = false)
enableExplicitApi()
}

configureKotlinCommonCompileOptions()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.reactivecircus.kstreamlined.buildlogic.convention

import io.github.reactivecircus.kstreamlined.buildlogic.configureKMPCommon
import io.github.reactivecircus.kstreamlined.buildlogic.configureKMPTest
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
Expand All @@ -11,7 +11,7 @@ internal class KMPTestConventionPlugin : Plugin<Project> {
pluginManager.apply("org.jetbrains.kotlin.multiplatform")

extensions.configure<KotlinMultiplatformExtension> {
configureKMPCommon()
configureKMPTest()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlin.coroutines.cancellation.CancellationException
* [block] function execution and encapsulating it as a failure.
*/
@Suppress("TooGenericExceptionCaught", "InstanceOfCheckForException")
inline fun <T, R> T.runCatchingNonCancellationException(block: () -> R): Result<R> {
public inline fun <T, R> T.runCatchingNonCancellationException(block: () -> R): Result<R> {
return try {
Result.success(block())
} catch (e: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
package io.github.reactivecircus.kstreamlined.kmp.data.feed

import co.touchlab.kermit.Logger
import io.github.reactivecircus.kstreamlined.kmp.data.feed.model.FeedItem
import io.github.reactivecircus.kstreamlined.kmp.data.feed.model.FeedOriginItem
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.FeedDataSource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow

class FeedRepository(
public class FeedRepository(
private val feedDataSource: FeedDataSource
) {

val feedSyncState: Flow<FeedSyncState> = TODO()
public val feedSyncState: Flow<FeedSyncState> = emptyFlow()

suspend fun syncNow() {
feedDataSource.loadFeedEntries(null, true)
TODO()
public suspend fun syncNow() {
feedDataSource.loadFeedEntries(null, true).also {
Logger.i("<<Number of entries: ${it.size}>>")
it.forEach { entry ->
Logger.i("${entry::class.simpleName}: ${entry.title}, ${entry.publishTime}}")
}
}
}

suspend fun selectFeedSource(feedOrigin: FeedOriginItem) {
public suspend fun selectFeedSource(feedOrigin: FeedOriginItem) {
feedOrigin.selected
TODO()
}

suspend fun unselectFeedSource(feedOrigin: FeedOriginItem) {
public suspend fun unselectFeedSource(feedOrigin: FeedOriginItem) {
feedOrigin.selected
TODO()
}

suspend fun getSavedFeedItems() {
public suspend fun loadSavedFeedItems(): List<FeedItem> {
TODO()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.github.reactivecircus.kstreamlined.kmp.data.feed
import io.github.reactivecircus.kstreamlined.kmp.data.feed.model.FeedItem
import io.github.reactivecircus.kstreamlined.kmp.data.feed.model.FeedOriginItem

data class FeedSyncState(
public data class FeedSyncState(
val feedOrigins: List<FeedOriginItem>,
val feedItems: List<FeedItem>,
)
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
package io.github.reactivecircus.kstreamlined.kmp.data.feed.model

sealed interface FeedItem {
val id: String
val title: String
val publishTimestamp: String
val contentUrl: String
val savedForLater: Boolean
public sealed interface FeedItem {
public val id: String
public val title: String
public val publishTime: String
public val contentUrl: String
public val savedForLater: Boolean

data class KotlinBlog(
public data class KotlinBlog(
override val id: String,
override val title: String,
override val publishTimestamp: String,
override val publishTime: String,
override val contentUrl: String,
override val savedForLater: Boolean,
val featuredImageUrl: String?,
val description: String,
) : FeedItem

data class KotlinYouTube(
public data class KotlinYouTube(
override val id: String,
override val title: String,
override val publishTimestamp: String,
override val publishTime: String,
override val contentUrl: String,
override val savedForLater: Boolean,
val thumbnailUrl: String,
val description: String,
) : FeedItem

data class TalkingKotlin(
public data class TalkingKotlin(
override val id: String,
override val title: String,
override val publishTimestamp: String,
override val publishTime: String,
override val contentUrl: String,
override val savedForLater: Boolean,
val podcastLogoUrl: String,
val tags: List<String>,
) : FeedItem

data class KotlinWeekly(
public data class KotlinWeekly(
override val id: String,
override val title: String,
override val publishTimestamp: String,
override val publishTime: String,
override val contentUrl: String,
override val savedForLater: Boolean,
val newsletterLogoUrl: String,
) : FeedItem
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.github.reactivecircus.kstreamlined.kmp.data.feed.model

data class FeedOriginItem(
public data class FeedOriginItem(
val key: Key,
val title: String,
val description: String,
val selected: Boolean,
) {
enum class Key {
public enum class Key {
KotlinBlog,
KotlinYouTubeChannel,
TalkingKotlinPodcast,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ query FeedEntriesQuery($filters: [FeedSourceKey!]) {
feedEntries(filters: $filters) {
id
title
publishTimestamp
publishTime
contentUrl
... on KotlinBlog {
featuredImageUrl
Expand All @@ -17,7 +17,7 @@ query FeedEntriesQuery($filters: [FeedSourceKey!]) {
tags
}
... on KotlinWeekly {
newsletterLogoUrl
contentUrl
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ interface FeedEntry {
title: String!

"""
Publish date of the feed entry as UTC timestamp.
Publish time of the feed entry in ISO 8601.
"""
publishTimestamp: String!
publishTime: String!

"""
Url of the content.
Expand Down Expand Up @@ -328,9 +328,9 @@ type KotlinBlog implements FeedEntry {
title: String!

"""
Publish date of the feed entry as UTC timestamp.
Publish time of the feed entry in ISO 8601.
"""
publishTimestamp: String!
publishTime: String!

"""
Url of the content.
Expand All @@ -340,7 +340,7 @@ type KotlinBlog implements FeedEntry {
"""
Url of the feature image.
"""
featuredImageUrl: String
featuredImageUrl: String!

"""
Description of the blog post.
Expand All @@ -360,19 +360,14 @@ type KotlinWeekly implements FeedEntry {
title: String!

"""
Publish date of the feed entry as UTC timestamp.
Publish time of the feed entry in ISO 8601.
"""
publishTimestamp: String!
publishTime: String!

"""
Url of the content.
"""
contentUrl: String!

"""
Url of the newsletter logo.
"""
newsletterLogoUrl: String!
}

type KotlinYouTube implements FeedEntry {
Expand All @@ -387,9 +382,9 @@ type KotlinYouTube implements FeedEntry {
title: String!

"""
Publish date of the feed entry as UTC timestamp.
Publish time of the feed entry in ISO 8601.
"""
publishTimestamp: String!
publishTime: String!

"""
Url of the content.
Expand Down Expand Up @@ -433,9 +428,9 @@ type TalkingKotlin implements FeedEntry {
title: String!

"""
Publish date of the feed entry as UTC timestamp.
Publish time of the feed entry in ISO 8601.
"""
publishTimestamp: String!
publishTime: String!

"""
Url of the content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.model.FeedEntry
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.model.FeedOrigin
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.networking.defaultFetchPolicy

class CloudFeedDataSource(private val apolloClient: ApolloClient) : FeedDataSource {
public class CloudFeedDataSource(private val apolloClient: ApolloClient) : FeedDataSource {

override suspend fun loadFeedOrigins(refresh: Boolean): List<FeedOrigin> {
return runCatching {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal fun FeedEntriesQuery.KotlinBlogFeedEntry.asExternalModel(): FeedEntry.K
return FeedEntry.KotlinBlog(
id = this.id,
title = this.title,
publishTimestamp = this.publishTimestamp,
publishTime = this.publishTime,
contentUrl = this.contentUrl,
featuredImageUrl = this.onKotlinBlog.featuredImageUrl,
description = this.onKotlinBlog.description,
Expand All @@ -28,7 +28,7 @@ internal fun FeedEntriesQuery.KotlinYouTubeFeedEntry.asExternalModel(): FeedEntr
return FeedEntry.KotlinYouTube(
id = this.id,
title = this.title,
publishTimestamp = this.publishTimestamp,
publishTime = this.publishTime,
contentUrl = this.contentUrl,
thumbnailUrl = this.onKotlinYouTube.thumbnailUrl,
description = this.onKotlinYouTube.description,
Expand All @@ -39,7 +39,7 @@ internal fun FeedEntriesQuery.TalkingKotlinFeedEntry.asExternalModel(): FeedEntr
return FeedEntry.TalkingKotlin(
id = this.id,
title = this.title,
publishTimestamp = this.publishTimestamp,
publishTime = this.publishTime,
contentUrl = this.contentUrl,
podcastLogoUrl = this.onTalkingKotlin.podcastLogoUrl,
tags = this.onTalkingKotlin.tags,
Expand All @@ -50,8 +50,7 @@ internal fun FeedEntriesQuery.KotlinWeeklyFeedEntry.asExternalModel(): FeedEntry
return FeedEntry.KotlinWeekly(
id = this.id,
title = this.title,
publishTimestamp = this.publishTimestamp,
publishTime = this.publishTime,
contentUrl = this.contentUrl,
newsletterLogoUrl = this.onKotlinWeekly.newsletterLogoUrl,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.apollographql.apollo3.cache.normalized.api.MemoryCacheFactory
import kotlin.time.DurationUnit
import kotlin.time.toDuration

object ApolloClientConfigs {
val apolloStore = ApolloStore(
public object ApolloClientConfigs {
public val apolloStore: ApolloStore = ApolloStore(
normalizedCacheFactory = MemoryCacheFactory(
maxSizeBytes = MaxSizeBytes,
expireAfterMillis = CacheExpiry.toLong(DurationUnit.MILLISECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.github.reactivecircus.kstreamlined.kmp.feed.datasource.util
import com.apollographql.apollo3.exception.ApolloNetworkException
import com.apollographql.apollo3.exception.NoDataException

object ApolloApiErrorChecker : ApiErrorChecker {
public object ApolloApiErrorChecker : ApiErrorChecker {
override fun isNetworkError(throwable: Throwable?): Boolean {
return when (throwable) {
// when using dataOrThrow() exceptions are wrapped in NoDataException
Expand Down
Loading

0 comments on commit 53799d7

Please sign in to comment.