diff --git a/CHANGELOG.md b/CHANGELOG.md index 39a0b9c..3895a9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change log +Version 0.0.5 *(2021-11-18)* +---------------------------- +* Unify Notion icon model +* Add `icon` to the database rows + Version 0.0.4 *(2021-11-16)* ---------------------------- * Fix missing pagination logic for block children endpoint diff --git a/README.md b/README.md index 185ad8f..e6b9663 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ implementation("com.petersamokhin.notionsdk:notionsdk:$latestVersion") ``` Library is published to the Maven Central repository. -Latest version: [![maven-central](https://img.shields.io/badge/Maven%20Central-0.0.4-yellowgreen?style=flat)](https://search.maven.org/search?q=g:com.petersamokhin.notionsdk) +Latest version: [![maven-central](https://img.shields.io/badge/Maven%20Central-0.0.5-yellowgreen?style=flat)](https://search.maven.org/search?q=g:com.petersamokhin.notionsdk) ### Supported endpoints - [`/databases/:id/query`](https://developers.notion.com/reference/retrieve-a-database) diff --git a/gradle.properties b/gradle.properties index 05c20b1..8139437 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.petersamokhin.notionsdk -VERSION_NAME=0.0.4 +VERSION_NAME=0.0.5 POM_ARTIFACT_ID=notionsdk POM_NAME=Notion SDK Kotlin Multiplatform diff --git a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/mapper/BlockMapper.kt b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/mapper/BlockMapper.kt index 387f923..a77bc42 100644 --- a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/mapper/BlockMapper.kt +++ b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/mapper/BlockMapper.kt @@ -221,10 +221,4 @@ internal fun BlockFileValue.toDomain(): NotionFile = file != null -> NotionFile.File(url = file.url, expiryTime = file.expiryTime) external != null -> NotionFile.External(url = external.url) else -> error("cannot map block file value: $this") - } - -internal fun Block.Callout.Value.Icon.toDomain(): NotionBlock.Callout.Icon = - when (this) { - is Block.Callout.Value.Icon.Emoji -> NotionBlock.Callout.Icon.Emoji(emoji = emoji) - is Block.Callout.Value.Icon.File -> NotionBlock.Callout.Icon.File(url = url, expiryTime = expiryTime) } \ No newline at end of file diff --git a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/mapper/DatabasePageMapper.kt b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/mapper/DatabasePageMapper.kt index b3b0d9e..845807e 100644 --- a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/mapper/DatabasePageMapper.kt +++ b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/mapper/DatabasePageMapper.kt @@ -7,5 +7,6 @@ import com.petersamokhin.notionsdk.data.model.result.NotionDatabaseRow internal fun PageObject.toDomain(): NotionDatabaseRow = NotionDatabaseRow( id = id, + icon = icon?.toDomain(), columns = properties.mapValues { (key, value) -> NotionDatabaseColumn(key, value.toDomain()) } ) \ No newline at end of file diff --git a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/mapper/IconMapper.kt b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/mapper/IconMapper.kt new file mode 100644 index 0000000..c6e803f --- /dev/null +++ b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/mapper/IconMapper.kt @@ -0,0 +1,11 @@ +package com.petersamokhin.notionsdk.data.mapper + +import com.petersamokhin.notionsdk.data.model.internal.obj.Icon +import com.petersamokhin.notionsdk.data.model.result.NotionIcon + +internal fun Icon.toDomain(): NotionIcon = + when { + emoji != null -> NotionIcon.Emoji(emoji) + file != null -> NotionIcon.File(file.url, file.expiryTime) + else -> error("$this is not a valid Notion icon") + } \ No newline at end of file diff --git a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/internal/obj/Block.kt b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/internal/obj/Block.kt index 32f38de..55d2037 100644 --- a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/internal/obj/Block.kt +++ b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/internal/obj/Block.kt @@ -365,24 +365,7 @@ internal sealed class Block { internal data class Value( val text: List, val icon: Icon, - ) { - @Serializable - internal sealed class Icon { - @Serializable - @SerialName("emoji") - internal data class Emoji( - val emoji: String, - ) : Icon() - - @Serializable - @SerialName("file") - internal data class File( - val url: String, - @SerialName("expiry_time") - val expiryTime: String? = null, - ) : Icon() - } - } + ) } @SerialName("quote") diff --git a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/internal/obj/Icon.kt b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/internal/obj/Icon.kt new file mode 100644 index 0000000..08519ba --- /dev/null +++ b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/internal/obj/Icon.kt @@ -0,0 +1,18 @@ +package com.petersamokhin.notionsdk.data.model.internal.obj + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +internal data class Icon( + val type: String, + val emoji: String? = null, + val file: File? = null, +) { + @Serializable + data class File( + val url: String, + @SerialName("expiry_time") + val expiryTime: String? = null, + ) +} \ No newline at end of file diff --git a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/internal/response/NotionObject.kt b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/internal/response/NotionObject.kt index 33b0337..ebb48ea 100644 --- a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/internal/response/NotionObject.kt +++ b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/internal/response/NotionObject.kt @@ -1,5 +1,6 @@ package com.petersamokhin.notionsdk.data.model.internal.response +import com.petersamokhin.notionsdk.data.model.internal.obj.Icon import kotlinx.serialization.Serializable @Serializable @@ -7,4 +8,5 @@ internal data class PageObject( val id: String, val url: String, val properties: Map, + val icon: Icon? = null, ) \ No newline at end of file diff --git a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/result/NotionBlock.kt b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/result/NotionBlock.kt index 3ae5e63..cab9971 100644 --- a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/result/NotionBlock.kt +++ b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/result/NotionBlock.kt @@ -280,26 +280,8 @@ public sealed class NotionBlock { override val hasChildren: Boolean, public val text: List, - public val icon: Icon, - ) : NotionBlock() { - - @Serializable - public sealed class Icon { - @Serializable - @SerialName("emoji") - public data class Emoji( - val emoji: String, - ) : Icon() - - @Serializable - @SerialName("file") - public data class File( - val url: String, - @SerialName("expiry_time") - val expiryTime: String? = null, - ) : Icon() - } - } + public val icon: NotionIcon, + ) : NotionBlock() @SerialName("quote") @Serializable diff --git a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/result/NotionIcon.kt b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/result/NotionIcon.kt new file mode 100644 index 0000000..b5b5af0 --- /dev/null +++ b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/result/NotionIcon.kt @@ -0,0 +1,21 @@ +package com.petersamokhin.notionsdk.data.model.result + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +public sealed class NotionIcon { + @Serializable + @SerialName("emoji") + public data class Emoji( + val emoji: String, + ) : NotionIcon() + + @Serializable + @SerialName("file") + public data class File( + val url: String, + @SerialName("expiry_time") + val expiryTime: String? = null, + ) : NotionIcon() +} \ No newline at end of file diff --git a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/result/NotionResults.kt b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/result/NotionResults.kt index a4888c9..7cc6d39 100644 --- a/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/result/NotionResults.kt +++ b/src/commonMain/kotlin/com/petersamokhin/notionsdk/data/model/result/NotionResults.kt @@ -17,6 +17,7 @@ public data class NotionResults( @Serializable public data class NotionDatabaseRow( val id: String, + val icon: NotionIcon? = null, val columns: Map, ) diff --git a/src/commonMain/kotlin/com/petersamokhin/notionsdk/markdown/NotionMarkdownExporterImpl.kt b/src/commonMain/kotlin/com/petersamokhin/notionsdk/markdown/NotionMarkdownExporterImpl.kt index d1168a3..191027c 100644 --- a/src/commonMain/kotlin/com/petersamokhin/notionsdk/markdown/NotionMarkdownExporterImpl.kt +++ b/src/commonMain/kotlin/com/petersamokhin/notionsdk/markdown/NotionMarkdownExporterImpl.kt @@ -198,10 +198,10 @@ internal class NotionMarkdownExporterImpl : NotionMarkdownExporter { is NotionRichText.Equation -> copy(annotations = annotations.copy(strikethrough = true)) } - private fun NotionBlock.Callout.Icon.toMarkdown(settings: NotionMarkdownExporter.Settings): String = + private fun NotionIcon.toMarkdown(settings: NotionMarkdownExporter.Settings): String = when (this) { - is NotionBlock.Callout.Icon.Emoji -> emoji - is NotionBlock.Callout.Icon.File -> { + is NotionIcon.Emoji -> emoji + is NotionIcon.File -> { val resultMarkdown = "![image](${url})" if (expiryTime != null && settings.addExpiryNoticeForInternalFiles) {