Skip to content

Commit

Permalink
Replicator AutoCloseable (#2)
Browse files Browse the repository at this point in the history
* Replicator is AutoCloseable

* Explicitly check for single dictionary entry in toObjects()

Handle edge case where more than one projected property, but first happens to be a dictionary

* Test ResultSet.toObjects()

* Add MutableDocument builder API with ID

* MIN_PORT and MAX_PORT are static properties

* Prefer explicit constructor declarations without default parameters

* Set version to 1.0.1-SNAPSHOT

* Use compilerOptions instead of kotlinOptions

* Replace kotlinOptions in Android build script

* Add note about linking native binary in installation
  • Loading branch information
jeffdgr8 authored Nov 27, 2023
1 parent 275549f commit 84698fe
Show file tree
Hide file tree
Showing 58 changed files with 302 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.gradle
local.properties
.idea
.fleet
.DS_Store
build
/captures
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ repositories {
}
```

### Native Platforms

Native platform targets should additionally link to the Couchbase Lite dependency native binary. See [Supported
Platforms](https://kotbase.dev/platforms/) for more details.

## Documentation

Kotbase documentation can be found at [kotbase.dev](https://kotbase.dev/), including [getting started examples](
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/base-convention.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand Down Expand Up @@ -66,7 +67,7 @@ kotlin {
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "1.8"
compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8)
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public final class kotbase/ktx/DocumentBuilder {
}

public final class kotbase/ktx/DocumentExtensionsKt {
public static final fun MutableDocument (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lkotbase/MutableDocument;
public static final fun MutableDocument (Lkotlin/jvm/functions/Function1;)Lkotbase/MutableDocument;
}

Expand Down
1 change: 1 addition & 0 deletions couchbase-lite-ee-ktx/api/jvm/couchbase-lite-ee-ktx.api
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public final class kotbase/ktx/DocumentBuilder {
}

public final class kotbase/ktx/DocumentExtensionsKt {
public static final fun MutableDocument (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lkotbase/MutableDocument;
public static final fun MutableDocument (Lkotlin/jvm/functions/Function1;)Lkotbase/MutableDocument;
}

Expand Down
17 changes: 11 additions & 6 deletions couchbase-lite-ee/api/android/couchbase-lite-ee.api
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ public final class kotbase/DatabaseChange : kotbase/internal/DelegatedClass {
}

public final class kotbase/DatabaseConfiguration : kotbase/internal/DelegatedClass {
public fun <init> ()V
public fun <init> (Lkotbase/DatabaseConfiguration;)V
public synthetic fun <init> (Lkotbase/DatabaseConfiguration;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getDirectory ()Ljava/lang/String;
public final fun setDirectory (Ljava/lang/String;)Lkotbase/DatabaseConfiguration;
public final fun setDirectory (Ljava/lang/String;)V
Expand Down Expand Up @@ -1052,8 +1052,8 @@ public final class kotbase/Ordering$SortOrder : kotbase/Ordering {
}

public final class kotbase/Parameters : kotbase/internal/DelegatedClass {
public fun <init> ()V
public fun <init> (Lkotbase/Parameters;)V
public synthetic fun <init> (Lkotbase/Parameters;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getValue (Ljava/lang/String;)Ljava/lang/Object;
public final fun setArray (Ljava/lang/String;Lkotbase/Array;)Lkotbase/Parameters;
public final fun setBlob (Ljava/lang/String;Lkotbase/Blob;)Lkotbase/Parameters;
Expand Down Expand Up @@ -1125,14 +1125,15 @@ public final class kotbase/ReplicatedDocument : kotbase/internal/DelegatedClass
public final fun getId ()Ljava/lang/String;
}

public final class kotbase/Replicator : kotbase/internal/DelegatedClass {
public final class kotbase/Replicator : kotbase/internal/DelegatedClass, java/lang/AutoCloseable {
public fun <init> (Lkotbase/ReplicatorConfiguration;)V
public final fun addChangeListener (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;)Lcom/couchbase/lite/ListenerToken;
public final fun addChangeListener (Lkotlin/jvm/functions/Function1;)Lcom/couchbase/lite/ListenerToken;
public final fun addChangeListener (Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;)V
public final fun addDocumentReplicationListener (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;)Lcom/couchbase/lite/ListenerToken;
public final fun addDocumentReplicationListener (Lkotlin/jvm/functions/Function1;)Lcom/couchbase/lite/ListenerToken;
public final fun addDocumentReplicationListener (Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;)V
public fun close ()V
public final fun getConfig ()Lkotbase/ReplicatorConfiguration;
public final fun getPendingDocumentIds ()Ljava/util/Set;
public final fun getServerCertificates ()Ljava/util/List;
Expand Down Expand Up @@ -1335,8 +1336,8 @@ public final class kotbase/SelectResult$From : kotbase/SelectResult {
}

public final class kotbase/SessionAuthenticator : kotbase/Authenticator {
public fun <init> (Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun getActual$couchbase_lite_ee_release ()Ljava/lang/Object;
public final fun getCookieName ()Ljava/lang/String;
public final fun getSessionID ()Ljava/lang/String;
Expand Down Expand Up @@ -1391,6 +1392,7 @@ public final class kotbase/URLEndpointListener : kotbase/internal/DelegatedClass
}

public final class kotbase/URLEndpointListenerConfiguration : kotbase/internal/DelegatedClass {
public static final field Companion Lkotbase/URLEndpointListenerConfiguration$Companion;
public fun <init> (Lkotbase/Database;Ljava/lang/String;IZLkotbase/TLSIdentity;Lkotbase/ListenerAuthenticator;ZZ)V
public synthetic fun <init> (Lkotbase/Database;Ljava/lang/String;IZLkotbase/TLSIdentity;Lkotbase/ListenerAuthenticator;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lkotbase/URLEndpointListenerConfiguration;)V
Expand All @@ -1411,9 +1413,12 @@ public final class kotbase/URLEndpointListenerConfiguration : kotbase/internal/D
public final fun setTlsIdentity (Lkotbase/TLSIdentity;)V
}

public final class kotbase/URLEndpointListenerConfiguration$Companion {
}

public final class kotbase/URLEndpointListenerConfigurationKt {
public static final fun getMAX_PORT (Lkotbase/URLEndpointListenerConfiguration;)I
public static final fun getMIN_PORT (Lkotbase/URLEndpointListenerConfiguration;)I
public static final fun getMAX_PORT (Lkotbase/URLEndpointListenerConfiguration$Companion;)I
public static final fun getMIN_PORT (Lkotbase/URLEndpointListenerConfiguration$Companion;)I
}

public final class kotbase/ValueIndex : kotbase/Index {
Expand Down
17 changes: 11 additions & 6 deletions couchbase-lite-ee/api/jvm/couchbase-lite-ee.api
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ public final class kotbase/DatabaseChange : kotbase/internal/DelegatedClass {
}

public final class kotbase/DatabaseConfiguration : kotbase/internal/DelegatedClass {
public fun <init> ()V
public fun <init> (Lkotbase/DatabaseConfiguration;)V
public synthetic fun <init> (Lkotbase/DatabaseConfiguration;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getDirectory ()Ljava/lang/String;
public final fun setDirectory (Ljava/lang/String;)Lkotbase/DatabaseConfiguration;
public final fun setDirectory (Ljava/lang/String;)V
Expand Down Expand Up @@ -1047,8 +1047,8 @@ public final class kotbase/Ordering$SortOrder : kotbase/Ordering {
}

public final class kotbase/Parameters : kotbase/internal/DelegatedClass {
public fun <init> ()V
public fun <init> (Lkotbase/Parameters;)V
public synthetic fun <init> (Lkotbase/Parameters;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getValue (Ljava/lang/String;)Ljava/lang/Object;
public final fun setArray (Ljava/lang/String;Lkotbase/Array;)Lkotbase/Parameters;
public final fun setBlob (Ljava/lang/String;Lkotbase/Blob;)Lkotbase/Parameters;
Expand Down Expand Up @@ -1120,14 +1120,15 @@ public final class kotbase/ReplicatedDocument : kotbase/internal/DelegatedClass
public final fun getId ()Ljava/lang/String;
}

public final class kotbase/Replicator : kotbase/internal/DelegatedClass {
public final class kotbase/Replicator : kotbase/internal/DelegatedClass, java/lang/AutoCloseable {
public fun <init> (Lkotbase/ReplicatorConfiguration;)V
public final fun addChangeListener (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;)Lcom/couchbase/lite/ListenerToken;
public final fun addChangeListener (Lkotlin/jvm/functions/Function1;)Lcom/couchbase/lite/ListenerToken;
public final fun addChangeListener (Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;)V
public final fun addDocumentReplicationListener (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;)Lcom/couchbase/lite/ListenerToken;
public final fun addDocumentReplicationListener (Lkotlin/jvm/functions/Function1;)Lcom/couchbase/lite/ListenerToken;
public final fun addDocumentReplicationListener (Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;)V
public fun close ()V
public final fun getConfig ()Lkotbase/ReplicatorConfiguration;
public final fun getPendingDocumentIds ()Ljava/util/Set;
public final fun getServerCertificates ()Ljava/util/List;
Expand Down Expand Up @@ -1330,8 +1331,8 @@ public final class kotbase/SelectResult$From : kotbase/SelectResult {
}

public final class kotbase/SessionAuthenticator : kotbase/Authenticator {
public fun <init> (Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun getActual$couchbase_lite_ee ()Ljava/lang/Object;
public final fun getCookieName ()Ljava/lang/String;
public final fun getSessionID ()Ljava/lang/String;
Expand Down Expand Up @@ -1390,6 +1391,7 @@ public final class kotbase/URLEndpointListener : kotbase/internal/DelegatedClass
}

public final class kotbase/URLEndpointListenerConfiguration : kotbase/internal/DelegatedClass {
public static final field Companion Lkotbase/URLEndpointListenerConfiguration$Companion;
public fun <init> (Lkotbase/Database;Ljava/lang/String;IZLkotbase/TLSIdentity;Lkotbase/ListenerAuthenticator;ZZ)V
public synthetic fun <init> (Lkotbase/Database;Ljava/lang/String;IZLkotbase/TLSIdentity;Lkotbase/ListenerAuthenticator;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lkotbase/URLEndpointListenerConfiguration;)V
Expand All @@ -1410,9 +1412,12 @@ public final class kotbase/URLEndpointListenerConfiguration : kotbase/internal/D
public final fun setTlsIdentity (Lkotbase/TLSIdentity;)V
}

public final class kotbase/URLEndpointListenerConfiguration$Companion {
}

public final class kotbase/URLEndpointListenerConfigurationKt {
public static final fun getMAX_PORT (Lkotbase/URLEndpointListenerConfiguration;)I
public static final fun getMIN_PORT (Lkotbase/URLEndpointListenerConfiguration;)I
public static final fun getMAX_PORT (Lkotbase/URLEndpointListenerConfiguration$Companion;)I
public static final fun getMIN_PORT (Lkotbase/URLEndpointListenerConfiguration$Companion;)I
}

public final class kotbase/ValueIndex : kotbase/Index {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,6 @@ private constructor(
set(value) {
actual.enableDeltaSync = value
}

public actual companion object
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,3 @@ public fun DatabaseConfiguration.setEncryptionKey(encryptionKey: EncryptionKey?)
* A key to encrypt the database with.
*/
public expect var DatabaseConfiguration.encryptionKey: EncryptionKey?

// TODO: provide update EE KTX creator function
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ public expect class URLEndpointListenerConfiguration {
* Is delta sync enabled.
*/
public var isDeltaSyncEnabled: Boolean

public companion object
}

@Suppress("UnusedReceiverParameter")
public val URLEndpointListenerConfiguration.MIN_PORT: Int
public val URLEndpointListenerConfiguration.Companion.MIN_PORT: Int
get() = 0

@Suppress("UnusedReceiverParameter")
public val URLEndpointListenerConfiguration.MAX_PORT: Int
public val URLEndpointListenerConfiguration.Companion.MAX_PORT: Int
get() = 65535
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,6 @@ private constructor(
set(value) {
actual.setEnableDeltaSync(value)
}

public actual companion object
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ public actual class URLEndpointListenerConfiguration private constructor() {
public actual var isReadOnly: Boolean

public actual var isDeltaSyncEnabled: Boolean

public actual companion object
}
1 change: 1 addition & 0 deletions couchbase-lite-ktx/api/android/couchbase-lite-ktx.api
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public final class kotbase/ktx/DocumentBuilder {
}

public final class kotbase/ktx/DocumentExtensionsKt {
public static final fun MutableDocument (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lkotbase/MutableDocument;
public static final fun MutableDocument (Lkotlin/jvm/functions/Function1;)Lkotbase/MutableDocument;
}

Expand Down
1 change: 1 addition & 0 deletions couchbase-lite-ktx/api/jvm/couchbase-lite-ktx.api
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public final class kotbase/ktx/DocumentBuilder {
}

public final class kotbase/ktx/DocumentExtensionsKt {
public static final fun MutableDocument (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lkotbase/MutableDocument;
public static final fun MutableDocument (Lkotlin/jvm/functions/Function1;)Lkotbase/MutableDocument;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ import kotlinx.datetime.Instant
public fun MutableDocument(block: DocumentBuilder.() -> Unit): MutableDocument =
DocumentBuilder().apply(block).build()

public class DocumentBuilder internal constructor(
private val document: MutableDocument = MutableDocument()
) {
public fun MutableDocument(id: String, block: DocumentBuilder.() -> Unit): MutableDocument =
DocumentBuilder(id).apply(block).build()

public class DocumentBuilder internal constructor(id: String? = null) {

private val document: MutableDocument = id?.let { MutableDocument(it) } ?: MutableDocument()

internal fun build() = document

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ public inline fun <T : Any> ResultSet.toObjects(factory: (String) -> T?): List<T
// projections for each Document key. We can then use the `Result` object as a
// JSON String.

if (count > 0) getDictionary(0)?.toJSON() ?: toJSON()
else null
when (count) {
0 -> null
1 -> getDictionary(0)?.toJSON() ?: toJSON()
else -> toJSON()
}
}?.let(factory)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Modified by Jeff Lockhart
* - Use kotbase package
* - Resolve explicitApiWarning() requirements
* - Handle first projected property is dictionary edge case
*/

package kotbase.ktx
Expand Down Expand Up @@ -63,7 +64,10 @@ public inline fun <T : Any> ResultSet.toObjects(factory: (Map<String, Any?>) ->
// If the first dictionary is `null`, then the query was written using the
// projections for each Document key. We can then use the `Result` object as a Map.

if (count > 0) getDictionary(0)?.toMap() ?: toMap()
else null
when (count) {
0 -> null
1 -> getDictionary(0)?.toMap() ?: toMap()
else -> toMap()
}
}?.let(factory)
}
Loading

0 comments on commit 84698fe

Please sign in to comment.