From 0ef10ebb5bab002d5bf4340d5e09d1f6b5c5b08b Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Mon, 6 Nov 2023 12:01:24 -0700 Subject: [PATCH 01/17] Replicator is AutoCloseable --- .../kotlin/kotbase/Replicator.apple.kt | 8 +++++++- .../commonMain/kotlin/kotbase/Replicator.kt | 5 ++++- .../kotlin/kotbase/Replicator.jvmCommon.kt | 6 +++++- .../kotlin/kotbase/Replicator.native.kt | 19 ++++++++++++++++--- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/couchbase-lite/src/appleMain/kotlin/kotbase/Replicator.apple.kt b/couchbase-lite/src/appleMain/kotlin/kotbase/Replicator.apple.kt index 2d321f57e..ac50b1547 100644 --- a/couchbase-lite/src/appleMain/kotlin/kotbase/Replicator.apple.kt +++ b/couchbase-lite/src/appleMain/kotlin/kotbase/Replicator.apple.kt @@ -27,11 +27,12 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlin.coroutines.CoroutineContext +@OptIn(ExperimentalStdlibApi::class) public actual class Replicator internal constructor( actual: CBLReplicator, private val _config: ReplicatorConfiguration -) : DelegatedClass(actual) { +) : DelegatedClass(actual), AutoCloseable { public actual constructor(config: ReplicatorConfiguration) : this( CBLReplicator(config.actual), @@ -145,4 +146,9 @@ internal constructor( actual.removeChangeListenerWithToken(token.actual) } } + + actual override fun close() { + // no close() in Objective-C SDK + // https://github.com/couchbase/couchbase-lite-ios/blob/b1eca5996b06564e65ae1c0a1a8bb55db28f37f5/Objective-C/CBLReplicator.mm#L122 + } } diff --git a/couchbase-lite/src/commonMain/kotlin/kotbase/Replicator.kt b/couchbase-lite/src/commonMain/kotlin/kotbase/Replicator.kt index 84f0e5d03..28d96c3a4 100755 --- a/couchbase-lite/src/commonMain/kotlin/kotbase/Replicator.kt +++ b/couchbase-lite/src/commonMain/kotlin/kotbase/Replicator.kt @@ -24,6 +24,7 @@ import kotlin.coroutines.CoroutineContext * or continuous. The replicator runs asynchronously, so observe the status to * be notified of progress. */ +@OptIn(ExperimentalStdlibApi::class) public expect class Replicator /** @@ -31,7 +32,7 @@ public expect class Replicator * * @param config replicator configuration */ -constructor(config: ReplicatorConfiguration) { +constructor(config: ReplicatorConfiguration) : AutoCloseable { internal constructor(config: ReplicatorConfiguration, test: Boolean) @@ -181,4 +182,6 @@ constructor(config: ReplicatorConfiguration) { * @param token returned by a previous call to [addChangeListener] or [addDocumentReplicationListener]. */ public fun removeChangeListener(token: ListenerToken) + + override fun close() } diff --git a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Replicator.jvmCommon.kt b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Replicator.jvmCommon.kt index a330753ae..7c9ddddd3 100644 --- a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Replicator.jvmCommon.kt +++ b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Replicator.jvmCommon.kt @@ -30,7 +30,7 @@ public actual class Replicator internal constructor( actual: CBLReplicator, private val _config: ReplicatorConfiguration -) : DelegatedClass(actual) { +) : DelegatedClass(actual), AutoCloseable { public actual constructor(config: ReplicatorConfiguration) : this(CBLReplicator(config.actual), config) @@ -137,4 +137,8 @@ internal constructor( actual.removeChangeListener(token) } } + + actual override fun close() { + actual.close() + } } diff --git a/couchbase-lite/src/nativeMain/kotlin/kotbase/Replicator.native.kt b/couchbase-lite/src/nativeMain/kotlin/kotbase/Replicator.native.kt index 9d94d84e3..ec0ba66c0 100644 --- a/couchbase-lite/src/nativeMain/kotlin/kotbase/Replicator.native.kt +++ b/couchbase-lite/src/nativeMain/kotlin/kotbase/Replicator.native.kt @@ -34,16 +34,24 @@ import kotlin.coroutines.CoroutineContext import kotlin.experimental.ExperimentalNativeApi import kotlin.native.ref.createCleaner +@OptIn(ExperimentalStdlibApi::class) public actual class Replicator private constructor( internal val actual: CPointer, private val immutableConfig: ImmutableReplicatorConfiguration -) { +) : AutoCloseable { + + private val memory = object { + var closeCalled = false + val actual = this@Replicator.actual + } @OptIn(ExperimentalNativeApi::class) @Suppress("unused") - private val cleaner = createCleaner(actual) { - CBLReplicator_Release(it) + private val cleaner = createCleaner(memory) { + if (!it.closeCalled) { + CBLReplicator_Release(it.actual) + } } public actual constructor(config: ReplicatorConfiguration) : @@ -229,4 +237,9 @@ private constructor( } } } + + actual override fun close() { + memory.closeCalled = true + CBLReplicator_Release(actual) + } } From 23de96ad00dc53ceea36451b5cccb39807fa9bcd Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Mon, 6 Nov 2023 12:02:27 -0700 Subject: [PATCH 02/17] iterator() is operator fun --- couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt | 2 +- couchbase-lite/src/appleMain/kotlin/kotbase/Result.apple.kt | 2 +- couchbase-lite/src/appleMain/kotlin/kotbase/ResultSet.apple.kt | 2 +- couchbase-lite/src/commonMain/kotlin/kotbase/Result.kt | 2 +- couchbase-lite/src/commonMain/kotlin/kotbase/ResultSet.kt | 2 +- .../src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt | 2 +- .../src/nativeMain/kotlin/kotbase/Dictionary.native.kt | 2 +- couchbase-lite/src/nativeMain/kotlin/kotbase/Result.native.kt | 2 +- .../src/nativeMain/kotlin/kotbase/ResultSet.native.kt | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt b/couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt index eb71ecebe..7cc069e1b 100644 --- a/couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt +++ b/couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt @@ -92,7 +92,7 @@ internal constructor(actual: CBLDictionary) : DelegatedClass(actu actual.containsValueForKey(key) @Suppress("UNCHECKED_CAST") - override fun iterator(): Iterator = + override operator fun iterator(): Iterator = (actual.keys as List).iterator() } diff --git a/couchbase-lite/src/appleMain/kotlin/kotbase/Result.apple.kt b/couchbase-lite/src/appleMain/kotlin/kotbase/Result.apple.kt index bdfc6eb2c..1a72c5c5e 100644 --- a/couchbase-lite/src/appleMain/kotlin/kotbase/Result.apple.kt +++ b/couchbase-lite/src/appleMain/kotlin/kotbase/Result.apple.kt @@ -142,7 +142,7 @@ internal constructor(actual: CBLQueryResult) : DelegatedClass(ac actual.containsValueForKey(key) @Suppress("UNCHECKED_CAST") - actual override fun iterator(): Iterator = + actual override operator fun iterator(): Iterator = (actual.keys as List).iterator() private fun isInBounds(index: Int): Boolean { diff --git a/couchbase-lite/src/appleMain/kotlin/kotbase/ResultSet.apple.kt b/couchbase-lite/src/appleMain/kotlin/kotbase/ResultSet.apple.kt index 4ddeb96e5..9518f7f78 100644 --- a/couchbase-lite/src/appleMain/kotlin/kotbase/ResultSet.apple.kt +++ b/couchbase-lite/src/appleMain/kotlin/kotbase/ResultSet.apple.kt @@ -31,7 +31,7 @@ internal constructor(actual: CBLQueryResultSet) : public actual fun allResults(): List = (actual.allResults() as List).map { Result(it) } - actual override fun iterator(): Iterator = + actual override operator fun iterator(): Iterator = allResults().iterator() actual override fun close() { diff --git a/couchbase-lite/src/commonMain/kotlin/kotbase/Result.kt b/couchbase-lite/src/commonMain/kotlin/kotbase/Result.kt index 0d9f2b28d..c751c8c3f 100755 --- a/couchbase-lite/src/commonMain/kotlin/kotbase/Result.kt +++ b/couchbase-lite/src/commonMain/kotlin/kotbase/Result.kt @@ -268,7 +268,7 @@ public expect class Result : Iterable { * * @return The Iterator object of all result keys. */ - override fun iterator(): Iterator + override operator fun iterator(): Iterator } /** diff --git a/couchbase-lite/src/commonMain/kotlin/kotbase/ResultSet.kt b/couchbase-lite/src/commonMain/kotlin/kotbase/ResultSet.kt index bae917cd7..a278a0798 100755 --- a/couchbase-lite/src/commonMain/kotlin/kotbase/ResultSet.kt +++ b/couchbase-lite/src/commonMain/kotlin/kotbase/ResultSet.kt @@ -51,7 +51,7 @@ public expect class ResultSet : Iterable, AutoCloseable { * * @return an iterator over the elements in this list in proper sequence */ - override fun iterator(): Iterator + override operator fun iterator(): Iterator override fun close() } diff --git a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt index 60bf8dbb1..8e9f564b2 100644 --- a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt +++ b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt @@ -88,7 +88,7 @@ internal constructor(actual: CBLDictionary) : DelegatedClass(actu public actual operator fun contains(key: String): Boolean = actual.contains(key) - override fun iterator(): Iterator = + override operator fun iterator(): Iterator = actual.iterator() } diff --git a/couchbase-lite/src/nativeMain/kotlin/kotbase/Dictionary.native.kt b/couchbase-lite/src/nativeMain/kotlin/kotbase/Dictionary.native.kt index 7012fd67f..398c0c9f9 100644 --- a/couchbase-lite/src/nativeMain/kotlin/kotbase/Dictionary.native.kt +++ b/couchbase-lite/src/nativeMain/kotlin/kotbase/Dictionary.native.kt @@ -124,7 +124,7 @@ internal constructor( public actual operator fun contains(key: String): Boolean = keys.contains(key) - override fun iterator(): Iterator = + override operator fun iterator(): Iterator = keys.iterator() override fun equals(other: Any?): Boolean { diff --git a/couchbase-lite/src/nativeMain/kotlin/kotbase/Result.native.kt b/couchbase-lite/src/nativeMain/kotlin/kotbase/Result.native.kt index 524f52353..e0ac3b354 100644 --- a/couchbase-lite/src/nativeMain/kotlin/kotbase/Result.native.kt +++ b/couchbase-lite/src/nativeMain/kotlin/kotbase/Result.native.kt @@ -168,7 +168,7 @@ private constructor( public actual operator fun contains(key: String): Boolean = dict.getValue(key) != null - actual override fun iterator(): Iterator = + actual override operator fun iterator(): Iterator = keys.iterator() private fun isInBounds(index: Int): Boolean { diff --git a/couchbase-lite/src/nativeMain/kotlin/kotbase/ResultSet.native.kt b/couchbase-lite/src/nativeMain/kotlin/kotbase/ResultSet.native.kt index f2051bf04..cb79baade 100644 --- a/couchbase-lite/src/nativeMain/kotlin/kotbase/ResultSet.native.kt +++ b/couchbase-lite/src/nativeMain/kotlin/kotbase/ResultSet.native.kt @@ -58,7 +58,7 @@ internal constructor( return results } - actual override fun iterator(): Iterator = + actual override operator fun iterator(): Iterator = allResults().iterator() actual override fun close() { From fc75eee0b5bcee92480db9d2b4dec0abc4600fb8 Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Mon, 6 Nov 2023 12:07:14 -0700 Subject: [PATCH 03/17] Explicitly check for single dictionary entry in toObjects() Handle edge case where more than one projected property, but first happens to be a dictionary --- .../src/commonMain/kotlin/kotbase/ktx/ResultSetExt.kt | 7 +++++-- .../commonMain/kotlin/kotbase/ktx/ResultSetExtensions.kt | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/ResultSetExt.kt b/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/ResultSetExt.kt index 2f20cc223..88fa436aa 100644 --- a/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/ResultSetExt.kt +++ b/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/ResultSetExt.kt @@ -59,8 +59,11 @@ public inline fun ResultSet.toObjects(factory: (String) -> T?): List 0) getDictionary(0)?.toJSON() ?: toJSON() - else null + when (count) { + 0 -> null + 1 -> getDictionary(0)?.toJSON() ?: toJSON() + else -> toJSON() + } }?.let(factory) } diff --git a/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/ResultSetExtensions.kt b/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/ResultSetExtensions.kt index 9727d6a30..8bea0f458 100644 --- a/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/ResultSetExtensions.kt +++ b/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/ResultSetExtensions.kt @@ -63,7 +63,10 @@ public inline fun ResultSet.toObjects(factory: (Map) -> // 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) } \ No newline at end of file From f92f16c514fe5eab5f27b41609ee7630c1cdd43e Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Mon, 6 Nov 2023 12:13:05 -0700 Subject: [PATCH 04/17] API dump --- couchbase-lite-ee/api/android/couchbase-lite-ee.api | 3 ++- couchbase-lite-ee/api/jvm/couchbase-lite-ee.api | 3 ++- couchbase-lite/api/android/couchbase-lite.api | 3 ++- couchbase-lite/api/jvm/couchbase-lite.api | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/couchbase-lite-ee/api/android/couchbase-lite-ee.api b/couchbase-lite-ee/api/android/couchbase-lite-ee.api index 627323e4c..7fa1b7232 100644 --- a/couchbase-lite-ee/api/android/couchbase-lite-ee.api +++ b/couchbase-lite-ee/api/android/couchbase-lite-ee.api @@ -1125,7 +1125,7 @@ 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 (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; @@ -1133,6 +1133,7 @@ public final class kotbase/Replicator : kotbase/internal/DelegatedClass { 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; diff --git a/couchbase-lite-ee/api/jvm/couchbase-lite-ee.api b/couchbase-lite-ee/api/jvm/couchbase-lite-ee.api index 57f369532..1aec890d2 100644 --- a/couchbase-lite-ee/api/jvm/couchbase-lite-ee.api +++ b/couchbase-lite-ee/api/jvm/couchbase-lite-ee.api @@ -1120,7 +1120,7 @@ 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 (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; @@ -1128,6 +1128,7 @@ public final class kotbase/Replicator : kotbase/internal/DelegatedClass { 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; diff --git a/couchbase-lite/api/android/couchbase-lite.api b/couchbase-lite/api/android/couchbase-lite.api index d29febad0..2c6ca085d 100644 --- a/couchbase-lite/api/android/couchbase-lite.api +++ b/couchbase-lite/api/android/couchbase-lite.api @@ -972,7 +972,7 @@ 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 (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; @@ -980,6 +980,7 @@ public final class kotbase/Replicator : kotbase/internal/DelegatedClass { 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; diff --git a/couchbase-lite/api/jvm/couchbase-lite.api b/couchbase-lite/api/jvm/couchbase-lite.api index 74b96d33e..8d3b0f42b 100644 --- a/couchbase-lite/api/jvm/couchbase-lite.api +++ b/couchbase-lite/api/jvm/couchbase-lite.api @@ -972,7 +972,7 @@ 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 (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; @@ -980,6 +980,7 @@ public final class kotbase/Replicator : kotbase/internal/DelegatedClass { 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; From 8ff1d573dfe4b97e3d57e88811c69381650ee24e Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Mon, 6 Nov 2023 16:08:36 -0700 Subject: [PATCH 05/17] Test ResultSet.toObjects() --- .../kotlin/kotbase/ktx/ResultSetExtTest.kt | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 couchbase-lite-ktx/src/commonTest/kotlin/kotbase/ktx/ResultSetExtTest.kt diff --git a/couchbase-lite-ktx/src/commonTest/kotlin/kotbase/ktx/ResultSetExtTest.kt b/couchbase-lite-ktx/src/commonTest/kotlin/kotbase/ktx/ResultSetExtTest.kt new file mode 100644 index 000000000..848713e58 --- /dev/null +++ b/couchbase-lite-ktx/src/commonTest/kotlin/kotbase/ktx/ResultSetExtTest.kt @@ -0,0 +1,119 @@ +/* + * Copyright 2023 Jeff Lockhart + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package kotbase.ktx + +import kotbase.BaseDbTest +import kotlin.test.Test +import kotlin.test.assertContentEquals +import kotlin.test.assertEquals + +class ResultSetExtTest : BaseDbTest() { + + class User(map: Map) { + val name: String by map + val surname: String by map + val age: Int by map + } + + private fun addDocumentsToDatabase() { + baseTestDb.save(MutableDocument("john_smith") { + "name" to "John" + "surname" to "Smith" + "age" to 42 + }) + baseTestDb.save(MutableDocument { + "name" to "Jane" + "surname" to "Johnson" + "age" to 35 + }) + baseTestDb.save(MutableDocument { + "name" to "Sally" + "surname" to "Smith" + "age" to 54 + }) + baseTestDb.save(MutableDocument { + "name" to "Jimmy" + "surname" to "Johnson" + "age" to 27 + }) + } + + @Test + fun test_toObjects_singleUserAll() { + addDocumentsToDatabase() + + val results = select(all()) + .from(baseTestDb) + .where { "name" equalTo "John" } + .execute() + .toObjects(::User) + + assertEquals(1, results.size) + assertEquals("John", results.first().name) + assertEquals("Smith", results.first().surname) + assertEquals(42, results.first().age) + } + + @Test + fun test_toObjects_multipleUsersAll() { + addDocumentsToDatabase() + + val results = select(all()) + .from(baseTestDb) + .where { "surname" equalTo "Smith" } + .orderBy { "name".ascending() } + .execute() + .toObjects(::User) + + assertEquals(2, results.size) + assertContentEquals(listOf("John", "Sally"), results.map { it.name }) + assertContentEquals(listOf("Smith", "Smith"), results.map { it.surname }) + assertContentEquals(listOf(42, 54), results.map { it.age }) + } + + @Test + fun test_toObjects_singleUserProjection() { + addDocumentsToDatabase() + + val results = select("name", "surname", "age") + .from(baseTestDb) + .where { "age" equalTo 27 } + .execute() + .toObjects(::User) + + assertEquals(1, results.size) + assertEquals("Jimmy", results.first().name) + assertEquals("Johnson", results.first().surname) + assertEquals(27, results.first().age) + } + + @Test + fun test_toObjects_multipleUsersProjection() { + addDocumentsToDatabase() + + val results = select("name", "surname", "age") + .from(baseTestDb) + .where { "surname" equalTo "Johnson" } + .orderBy { "name".ascending() } + .execute() + .toObjects(::User) + + assertEquals(2, results.size) + assertContentEquals(listOf("Jane", "Jimmy"), results.map { it.name }) + assertContentEquals(listOf("Johnson", "Johnson"), results.map { it.surname }) + assertContentEquals(listOf(35, 27), results.map { it.age }) + } +} From 149c9a0f37a72fa8d56d8d012043647176275b96 Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Mon, 6 Nov 2023 16:10:41 -0700 Subject: [PATCH 06/17] Add MutableDocument builder API with ID --- .../api/android/couchbase-lite-ee-ktx.api | 1 + couchbase-lite-ee-ktx/api/jvm/couchbase-lite-ee-ktx.api | 1 + couchbase-lite-ktx/api/android/couchbase-lite-ktx.api | 1 + couchbase-lite-ktx/api/jvm/couchbase-lite-ktx.api | 1 + .../commonMain/kotlin/kotbase/ktx/DocumentExtensions.kt | 9 ++++++--- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/couchbase-lite-ee-ktx/api/android/couchbase-lite-ee-ktx.api b/couchbase-lite-ee-ktx/api/android/couchbase-lite-ee-ktx.api index c20779bb3..1d8474cad 100644 --- a/couchbase-lite-ee-ktx/api/android/couchbase-lite-ee-ktx.api +++ b/couchbase-lite-ee-ktx/api/android/couchbase-lite-ee-ktx.api @@ -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; } diff --git a/couchbase-lite-ee-ktx/api/jvm/couchbase-lite-ee-ktx.api b/couchbase-lite-ee-ktx/api/jvm/couchbase-lite-ee-ktx.api index 7a328d162..88e74371e 100644 --- a/couchbase-lite-ee-ktx/api/jvm/couchbase-lite-ee-ktx.api +++ b/couchbase-lite-ee-ktx/api/jvm/couchbase-lite-ee-ktx.api @@ -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; } diff --git a/couchbase-lite-ktx/api/android/couchbase-lite-ktx.api b/couchbase-lite-ktx/api/android/couchbase-lite-ktx.api index c20779bb3..1d8474cad 100644 --- a/couchbase-lite-ktx/api/android/couchbase-lite-ktx.api +++ b/couchbase-lite-ktx/api/android/couchbase-lite-ktx.api @@ -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; } diff --git a/couchbase-lite-ktx/api/jvm/couchbase-lite-ktx.api b/couchbase-lite-ktx/api/jvm/couchbase-lite-ktx.api index 7a328d162..88e74371e 100644 --- a/couchbase-lite-ktx/api/jvm/couchbase-lite-ktx.api +++ b/couchbase-lite-ktx/api/jvm/couchbase-lite-ktx.api @@ -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; } diff --git a/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/DocumentExtensions.kt b/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/DocumentExtensions.kt index b5aa418e3..87e46fc6c 100644 --- a/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/DocumentExtensions.kt +++ b/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/DocumentExtensions.kt @@ -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 From 3e20959e459b824419a14e1dc2bee5ad808b0d7e Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Mon, 6 Nov 2023 16:10:54 -0700 Subject: [PATCH 07/17] Suppress false warnings --- .../kotlin/kotbase/paging/OffsetQueryPagingSourceTest.kt | 2 +- couchbase-lite/src/commonTest/kotlin/kotbase/QueryTest.kt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/couchbase-lite-paging/src/commonTest/kotlin/kotbase/paging/OffsetQueryPagingSourceTest.kt b/couchbase-lite-paging/src/commonTest/kotlin/kotbase/paging/OffsetQueryPagingSourceTest.kt index 0ef48eb14..53872569a 100644 --- a/couchbase-lite-paging/src/commonTest/kotlin/kotbase/paging/OffsetQueryPagingSourceTest.kt +++ b/couchbase-lite-paging/src/commonTest/kotlin/kotbase/paging/OffsetQueryPagingSourceTest.kt @@ -18,7 +18,7 @@ * Based on https://github.com/cashapp/sqldelight/blob/master/extensions/androidx-paging3/src/commonTest/kotlin/app/cash/sqldelight/paging3/OffsetQueryPagingSourceTest.kt */ -@file:Suppress("CAST_NEVER_SUCCEEDS") +@file:Suppress("CAST_NEVER_SUCCEEDS", "USELESS_CAST", "KotlinRedundantDiagnosticSuppress") package kotbase.paging diff --git a/couchbase-lite/src/commonTest/kotlin/kotbase/QueryTest.kt b/couchbase-lite/src/commonTest/kotlin/kotbase/QueryTest.kt index 7c3148123..d30634d1b 100755 --- a/couchbase-lite/src/commonTest/kotlin/kotbase/QueryTest.kt +++ b/couchbase-lite/src/commonTest/kotlin/kotbase/QueryTest.kt @@ -1945,6 +1945,7 @@ class QueryTest : BaseQueryTest() { // https://forums.couchbase.com/t/unicode-collation-locale-null-or-device-locale/34103 //assertEquals(expected[i], collations[i].asJSON()) val expectedCollation = expected[i] + @Suppress("UNNECESSARY_SAFE_CALL", "KotlinRedundantDiagnosticSuppress") val collation = collations[i].asJSON()?.massageJson(expectedCollation) assertEquals(expectedCollation, collation) } From 545eeec7b0a93e040c8aa7de320456c37e1f8c69 Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Mon, 6 Nov 2023 16:22:39 -0700 Subject: [PATCH 08/17] Add modification comment --- .../src/commonMain/kotlin/kotbase/ktx/ResultSetExtensions.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/ResultSetExtensions.kt b/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/ResultSetExtensions.kt index 8bea0f458..d74ee1001 100644 --- a/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/ResultSetExtensions.kt +++ b/couchbase-lite-ktx/src/commonMain/kotlin/kotbase/ktx/ResultSetExtensions.kt @@ -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 From 563332038edf59b5153e3ac9b3565d5c4a18b02f Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Tue, 7 Nov 2023 17:56:43 -0700 Subject: [PATCH 09/17] Add .fleet to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3087aaf28..3df8d6c9e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .gradle local.properties .idea +.fleet .DS_Store build /captures From fe18aa4b9edbe35b6fd5c4d222cd5ad32d461e79 Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Tue, 7 Nov 2023 22:04:00 -0700 Subject: [PATCH 10/17] Remove unnecessary operator keyword on overrides --- couchbase-lite/src/appleMain/kotlin/kotbase/Array.apple.kt | 2 +- couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt | 2 +- couchbase-lite/src/appleMain/kotlin/kotbase/Document.apple.kt | 2 +- couchbase-lite/src/appleMain/kotlin/kotbase/Result.apple.kt | 2 +- couchbase-lite/src/appleMain/kotlin/kotbase/ResultSet.apple.kt | 2 +- couchbase-lite/src/commonMain/kotlin/kotbase/Array.kt | 2 +- couchbase-lite/src/commonMain/kotlin/kotbase/Document.kt | 2 +- couchbase-lite/src/commonMain/kotlin/kotbase/Result.kt | 2 +- couchbase-lite/src/commonMain/kotlin/kotbase/ResultSet.kt | 2 +- .../src/jvmCommonMain/kotlin/kotbase/Array.jvmCommon.kt | 2 +- .../src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt | 2 +- .../src/jvmCommonMain/kotlin/kotbase/Document.jvmCommon.kt | 2 +- .../src/jvmCommonMain/kotlin/kotbase/Result.jvmCommon.kt | 2 +- .../src/jvmCommonMain/kotlin/kotbase/ResultSet.jvmCommon.kt | 2 +- couchbase-lite/src/nativeMain/kotlin/kotbase/Array.native.kt | 2 +- .../src/nativeMain/kotlin/kotbase/Dictionary.native.kt | 2 +- couchbase-lite/src/nativeMain/kotlin/kotbase/Document.native.kt | 2 +- couchbase-lite/src/nativeMain/kotlin/kotbase/Result.native.kt | 2 +- .../src/nativeMain/kotlin/kotbase/ResultSet.native.kt | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/couchbase-lite/src/appleMain/kotlin/kotbase/Array.apple.kt b/couchbase-lite/src/appleMain/kotlin/kotbase/Array.apple.kt index 4674d0379..0180c061f 100644 --- a/couchbase-lite/src/appleMain/kotlin/kotbase/Array.apple.kt +++ b/couchbase-lite/src/appleMain/kotlin/kotbase/Array.apple.kt @@ -105,7 +105,7 @@ internal constructor(actual: CBLArray) : DelegatedClass(actual), Itera public actual open fun toJSON(): String = actual.toJSON() - actual override operator fun iterator(): Iterator = + actual override fun iterator(): Iterator = ArrayIterator(count) private inner class ArrayIterator(private val count: Int) : Iterator { diff --git a/couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt b/couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt index 7cc069e1b..eb71ecebe 100644 --- a/couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt +++ b/couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt @@ -92,7 +92,7 @@ internal constructor(actual: CBLDictionary) : DelegatedClass(actu actual.containsValueForKey(key) @Suppress("UNCHECKED_CAST") - override operator fun iterator(): Iterator = + override fun iterator(): Iterator = (actual.keys as List).iterator() } diff --git a/couchbase-lite/src/appleMain/kotlin/kotbase/Document.apple.kt b/couchbase-lite/src/appleMain/kotlin/kotbase/Document.apple.kt index 5160e0716..484116097 100644 --- a/couchbase-lite/src/appleMain/kotlin/kotbase/Document.apple.kt +++ b/couchbase-lite/src/appleMain/kotlin/kotbase/Document.apple.kt @@ -102,7 +102,7 @@ internal constructor(actual: CBLDocument) : DelegatedClass(actual), actual.toDictionary().containsKey(key) @Suppress("UNCHECKED_CAST") - actual override operator fun iterator(): Iterator = + actual override fun iterator(): Iterator = (actual.keys as List).iterator() } diff --git a/couchbase-lite/src/appleMain/kotlin/kotbase/Result.apple.kt b/couchbase-lite/src/appleMain/kotlin/kotbase/Result.apple.kt index 1a72c5c5e..bdfc6eb2c 100644 --- a/couchbase-lite/src/appleMain/kotlin/kotbase/Result.apple.kt +++ b/couchbase-lite/src/appleMain/kotlin/kotbase/Result.apple.kt @@ -142,7 +142,7 @@ internal constructor(actual: CBLQueryResult) : DelegatedClass(ac actual.containsValueForKey(key) @Suppress("UNCHECKED_CAST") - actual override operator fun iterator(): Iterator = + actual override fun iterator(): Iterator = (actual.keys as List).iterator() private fun isInBounds(index: Int): Boolean { diff --git a/couchbase-lite/src/appleMain/kotlin/kotbase/ResultSet.apple.kt b/couchbase-lite/src/appleMain/kotlin/kotbase/ResultSet.apple.kt index 9518f7f78..4ddeb96e5 100644 --- a/couchbase-lite/src/appleMain/kotlin/kotbase/ResultSet.apple.kt +++ b/couchbase-lite/src/appleMain/kotlin/kotbase/ResultSet.apple.kt @@ -31,7 +31,7 @@ internal constructor(actual: CBLQueryResultSet) : public actual fun allResults(): List = (actual.allResults() as List).map { Result(it) } - actual override operator fun iterator(): Iterator = + actual override fun iterator(): Iterator = allResults().iterator() actual override fun close() { diff --git a/couchbase-lite/src/commonMain/kotlin/kotbase/Array.kt b/couchbase-lite/src/commonMain/kotlin/kotbase/Array.kt index b286fe726..4965e4664 100755 --- a/couchbase-lite/src/commonMain/kotlin/kotbase/Array.kt +++ b/couchbase-lite/src/commonMain/kotlin/kotbase/Array.kt @@ -159,7 +159,7 @@ public expect open class Array : Iterable { public fun toJSON(): String - public override operator fun iterator(): Iterator + public override fun iterator(): Iterator } /** diff --git a/couchbase-lite/src/commonMain/kotlin/kotbase/Document.kt b/couchbase-lite/src/commonMain/kotlin/kotbase/Document.kt index c6de528f0..43776b30a 100755 --- a/couchbase-lite/src/commonMain/kotlin/kotbase/Document.kt +++ b/couchbase-lite/src/commonMain/kotlin/kotbase/Document.kt @@ -210,7 +210,7 @@ public expect open class Document : Iterable { * * @return The key iterator */ - override operator fun iterator(): Iterator + override fun iterator(): Iterator } /** diff --git a/couchbase-lite/src/commonMain/kotlin/kotbase/Result.kt b/couchbase-lite/src/commonMain/kotlin/kotbase/Result.kt index c751c8c3f..0d9f2b28d 100755 --- a/couchbase-lite/src/commonMain/kotlin/kotbase/Result.kt +++ b/couchbase-lite/src/commonMain/kotlin/kotbase/Result.kt @@ -268,7 +268,7 @@ public expect class Result : Iterable { * * @return The Iterator object of all result keys. */ - override operator fun iterator(): Iterator + override fun iterator(): Iterator } /** diff --git a/couchbase-lite/src/commonMain/kotlin/kotbase/ResultSet.kt b/couchbase-lite/src/commonMain/kotlin/kotbase/ResultSet.kt index a278a0798..bae917cd7 100755 --- a/couchbase-lite/src/commonMain/kotlin/kotbase/ResultSet.kt +++ b/couchbase-lite/src/commonMain/kotlin/kotbase/ResultSet.kt @@ -51,7 +51,7 @@ public expect class ResultSet : Iterable, AutoCloseable { * * @return an iterator over the elements in this list in proper sequence */ - override operator fun iterator(): Iterator + override fun iterator(): Iterator override fun close() } diff --git a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Array.jvmCommon.kt b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Array.jvmCommon.kt index 72492f7b2..7bcb5d462 100644 --- a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Array.jvmCommon.kt +++ b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Array.jvmCommon.kt @@ -82,7 +82,7 @@ internal constructor(actual: CBLArray) : DelegatedClass(actual), Itera public actual fun toJSON(): String = actual.toJSON() - actual override operator fun iterator(): Iterator = object : Iterator { + actual override fun iterator(): Iterator = object : Iterator { private val itr = actual.iterator() diff --git a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt index 8e9f564b2..60bf8dbb1 100644 --- a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt +++ b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt @@ -88,7 +88,7 @@ internal constructor(actual: CBLDictionary) : DelegatedClass(actu public actual operator fun contains(key: String): Boolean = actual.contains(key) - override operator fun iterator(): Iterator = + override fun iterator(): Iterator = actual.iterator() } diff --git a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Document.jvmCommon.kt b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Document.jvmCommon.kt index 1fdd73336..daa928bec 100644 --- a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Document.jvmCommon.kt +++ b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Document.jvmCommon.kt @@ -97,7 +97,7 @@ internal constructor(actual: CBLDocument) : DelegatedClass(actual), public actual operator fun contains(key: String): Boolean = actual.contains(key) - actual override operator fun iterator(): Iterator = + actual override fun iterator(): Iterator = actual.iterator() } diff --git a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Result.jvmCommon.kt b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Result.jvmCommon.kt index cc1329111..bfe5996c0 100644 --- a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Result.jvmCommon.kt +++ b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Result.jvmCommon.kt @@ -113,7 +113,7 @@ internal constructor(actual: CBLResult) : DelegatedClass(actual), Ite public actual operator fun contains(key: String): Boolean = actual.contains(key) - actual override operator fun iterator(): Iterator = + actual override fun iterator(): Iterator = actual.iterator() } diff --git a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/ResultSet.jvmCommon.kt b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/ResultSet.jvmCommon.kt index 5e0289e77..5a1ef4780 100644 --- a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/ResultSet.jvmCommon.kt +++ b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/ResultSet.jvmCommon.kt @@ -30,7 +30,7 @@ internal constructor(actual: CBLResultSet) : DelegatedClass(actual public actual fun allResults(): List = actual.allResults().map { Result(it) } - actual override operator fun iterator(): Iterator = object : Iterator { + actual override fun iterator(): Iterator = object : Iterator { private val iter: Iterator = actual.iterator() diff --git a/couchbase-lite/src/nativeMain/kotlin/kotbase/Array.native.kt b/couchbase-lite/src/nativeMain/kotlin/kotbase/Array.native.kt index 47f2b2767..9910e359d 100644 --- a/couchbase-lite/src/nativeMain/kotlin/kotbase/Array.native.kt +++ b/couchbase-lite/src/nativeMain/kotlin/kotbase/Array.native.kt @@ -119,7 +119,7 @@ internal constructor( public actual open fun toJSON(): String = FLValue_ToJSON(actual.reinterpret()).toKString()!! - actual override operator fun iterator(): Iterator = + actual override fun iterator(): Iterator = ArrayIterator(count) private inner class ArrayIterator(private val count: Int) : Iterator { diff --git a/couchbase-lite/src/nativeMain/kotlin/kotbase/Dictionary.native.kt b/couchbase-lite/src/nativeMain/kotlin/kotbase/Dictionary.native.kt index 398c0c9f9..7012fd67f 100644 --- a/couchbase-lite/src/nativeMain/kotlin/kotbase/Dictionary.native.kt +++ b/couchbase-lite/src/nativeMain/kotlin/kotbase/Dictionary.native.kt @@ -124,7 +124,7 @@ internal constructor( public actual operator fun contains(key: String): Boolean = keys.contains(key) - override operator fun iterator(): Iterator = + override fun iterator(): Iterator = keys.iterator() override fun equals(other: Any?): Boolean { diff --git a/couchbase-lite/src/nativeMain/kotlin/kotbase/Document.native.kt b/couchbase-lite/src/nativeMain/kotlin/kotbase/Document.native.kt index 57c8a33b6..68ff6b55d 100644 --- a/couchbase-lite/src/nativeMain/kotlin/kotbase/Document.native.kt +++ b/couchbase-lite/src/nativeMain/kotlin/kotbase/Document.native.kt @@ -148,7 +148,7 @@ internal constructor( public actual operator fun contains(key: String): Boolean = keys.contains(key) - actual override operator fun iterator(): Iterator = + actual override fun iterator(): Iterator = keys.iterator() override fun equals(other: Any?): Boolean { diff --git a/couchbase-lite/src/nativeMain/kotlin/kotbase/Result.native.kt b/couchbase-lite/src/nativeMain/kotlin/kotbase/Result.native.kt index e0ac3b354..524f52353 100644 --- a/couchbase-lite/src/nativeMain/kotlin/kotbase/Result.native.kt +++ b/couchbase-lite/src/nativeMain/kotlin/kotbase/Result.native.kt @@ -168,7 +168,7 @@ private constructor( public actual operator fun contains(key: String): Boolean = dict.getValue(key) != null - actual override operator fun iterator(): Iterator = + actual override fun iterator(): Iterator = keys.iterator() private fun isInBounds(index: Int): Boolean { diff --git a/couchbase-lite/src/nativeMain/kotlin/kotbase/ResultSet.native.kt b/couchbase-lite/src/nativeMain/kotlin/kotbase/ResultSet.native.kt index cb79baade..f2051bf04 100644 --- a/couchbase-lite/src/nativeMain/kotlin/kotbase/ResultSet.native.kt +++ b/couchbase-lite/src/nativeMain/kotlin/kotbase/ResultSet.native.kt @@ -58,7 +58,7 @@ internal constructor( return results } - actual override operator fun iterator(): Iterator = + actual override fun iterator(): Iterator = allResults().iterator() actual override fun close() { From 68ca29d4304046c470d1abb3f0826600510a2b8c Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Tue, 14 Nov 2023 22:30:11 -0700 Subject: [PATCH 11/17] Add override fun iterator() to common Dicitionary --- couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt | 2 +- couchbase-lite/src/commonMain/kotlin/kotbase/Dictionary.kt | 2 ++ .../src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt | 2 +- .../src/nativeMain/kotlin/kotbase/Dictionary.native.kt | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt b/couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt index eb71ecebe..3a516f858 100644 --- a/couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt +++ b/couchbase-lite/src/appleMain/kotlin/kotbase/Dictionary.apple.kt @@ -92,7 +92,7 @@ internal constructor(actual: CBLDictionary) : DelegatedClass(actu actual.containsValueForKey(key) @Suppress("UNCHECKED_CAST") - override fun iterator(): Iterator = + actual override fun iterator(): Iterator = (actual.keys as List).iterator() } diff --git a/couchbase-lite/src/commonMain/kotlin/kotbase/Dictionary.kt b/couchbase-lite/src/commonMain/kotlin/kotbase/Dictionary.kt index e625fb092..28e109d96 100755 --- a/couchbase-lite/src/commonMain/kotlin/kotbase/Dictionary.kt +++ b/couchbase-lite/src/commonMain/kotlin/kotbase/Dictionary.kt @@ -176,6 +176,8 @@ public expect open class Dictionary : Iterable { * @return the boolean value representing whether a property exists or not. */ public operator fun contains(key: String): Boolean + + override fun iterator(): Iterator } /** diff --git a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt index 60bf8dbb1..532f129f0 100644 --- a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt +++ b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Dictionary.jvmCommon.kt @@ -88,7 +88,7 @@ internal constructor(actual: CBLDictionary) : DelegatedClass(actu public actual operator fun contains(key: String): Boolean = actual.contains(key) - override fun iterator(): Iterator = + actual override fun iterator(): Iterator = actual.iterator() } diff --git a/couchbase-lite/src/nativeMain/kotlin/kotbase/Dictionary.native.kt b/couchbase-lite/src/nativeMain/kotlin/kotbase/Dictionary.native.kt index 7012fd67f..f2c1f1501 100644 --- a/couchbase-lite/src/nativeMain/kotlin/kotbase/Dictionary.native.kt +++ b/couchbase-lite/src/nativeMain/kotlin/kotbase/Dictionary.native.kt @@ -124,7 +124,7 @@ internal constructor( public actual operator fun contains(key: String): Boolean = keys.contains(key) - override fun iterator(): Iterator = + actual override fun iterator(): Iterator = keys.iterator() override fun equals(other: Any?): Boolean { From 0978461b30daa8b562d08ed5ddb6fe71ef010194 Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Tue, 14 Nov 2023 23:17:01 -0700 Subject: [PATCH 12/17] MIN_PORT and MAX_PORT are static properties --- .../ee/kotbase/URLEndpointListenerConfiguration.apple.kt | 2 ++ .../ee/kotbase/URLEndpointListenerConfiguration.kt | 8 ++++---- .../kotbase/URLEndpointListenerConfiguration.jvmCommon.kt | 2 ++ .../ee/kotbase/URLEndpointListenerConfiguration.native.kt | 2 ++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/couchbase-lite-ee/src/appleMain/ee/kotbase/URLEndpointListenerConfiguration.apple.kt b/couchbase-lite-ee/src/appleMain/ee/kotbase/URLEndpointListenerConfiguration.apple.kt index b7711c173..ad3c26ae8 100644 --- a/couchbase-lite-ee/src/appleMain/ee/kotbase/URLEndpointListenerConfiguration.apple.kt +++ b/couchbase-lite-ee/src/appleMain/ee/kotbase/URLEndpointListenerConfiguration.apple.kt @@ -98,4 +98,6 @@ private constructor( set(value) { actual.enableDeltaSync = value } + + public actual companion object } diff --git a/couchbase-lite-ee/src/commonMain/ee/kotbase/URLEndpointListenerConfiguration.kt b/couchbase-lite-ee/src/commonMain/ee/kotbase/URLEndpointListenerConfiguration.kt index c0a6e3ad2..f45ee4215 100644 --- a/couchbase-lite-ee/src/commonMain/ee/kotbase/URLEndpointListenerConfiguration.kt +++ b/couchbase-lite-ee/src/commonMain/ee/kotbase/URLEndpointListenerConfiguration.kt @@ -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 diff --git a/couchbase-lite-ee/src/jvmCommonMain/ee/kotbase/URLEndpointListenerConfiguration.jvmCommon.kt b/couchbase-lite-ee/src/jvmCommonMain/ee/kotbase/URLEndpointListenerConfiguration.jvmCommon.kt index 724d7de7f..7cad600cc 100644 --- a/couchbase-lite-ee/src/jvmCommonMain/ee/kotbase/URLEndpointListenerConfiguration.jvmCommon.kt +++ b/couchbase-lite-ee/src/jvmCommonMain/ee/kotbase/URLEndpointListenerConfiguration.jvmCommon.kt @@ -99,4 +99,6 @@ private constructor( set(value) { actual.setEnableDeltaSync(value) } + + public actual companion object } diff --git a/couchbase-lite-ee/src/nativeMain/ee/kotbase/URLEndpointListenerConfiguration.native.kt b/couchbase-lite-ee/src/nativeMain/ee/kotbase/URLEndpointListenerConfiguration.native.kt index 0032b09ed..220d9bee5 100644 --- a/couchbase-lite-ee/src/nativeMain/ee/kotbase/URLEndpointListenerConfiguration.native.kt +++ b/couchbase-lite-ee/src/nativeMain/ee/kotbase/URLEndpointListenerConfiguration.native.kt @@ -49,4 +49,6 @@ public actual class URLEndpointListenerConfiguration private constructor() { public actual var isReadOnly: Boolean public actual var isDeltaSyncEnabled: Boolean + + public actual companion object } From 80e41858132635e598b90398b1fd9976d32025dc Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Tue, 14 Nov 2023 23:53:13 -0700 Subject: [PATCH 13/17] Prefer explicit constructor declarations without default parameters --- .../api/android/couchbase-lite-ee.api | 14 +++++++---- .../api/jvm/couchbase-lite-ee.api | 14 +++++++---- .../ee/kotbase/DatabaseConfiguration.kt | 2 -- couchbase-lite/api/android/couchbase-lite.api | 6 ++--- couchbase-lite/api/jvm/couchbase-lite.api | 6 ++--- .../kotbase/DatabaseConfiguration.apple.kt | 2 ++ .../kotlin/kotbase/Parameters.apple.kt | 2 ++ .../kotbase/SessionAuthenticator.apple.kt | 2 ++ .../kotlin/kotbase/DatabaseConfiguration.kt | 8 +++--- .../commonMain/kotlin/kotbase/Parameters.kt | 6 ++++- .../kotlin/kotbase/SessionAuthenticator.kt | 25 ++++++++++++------- .../DatabaseConfiguration.jvmCommon.kt | 2 ++ .../kotlin/kotbase/Parameters.jvmCommon.kt | 2 ++ .../kotbase/SessionAuthenticator.jvmCommon.kt | 2 ++ .../kotbase/DatabaseConfiguration.native.kt | 2 ++ .../kotlin/kotbase/Parameters.native.kt | 2 ++ .../kotbase/SessionAuthenticator.native.kt | 2 ++ 17 files changed, 68 insertions(+), 31 deletions(-) diff --git a/couchbase-lite-ee/api/android/couchbase-lite-ee.api b/couchbase-lite-ee/api/android/couchbase-lite-ee.api index 7fa1b7232..22d30fca8 100644 --- a/couchbase-lite-ee/api/android/couchbase-lite-ee.api +++ b/couchbase-lite-ee/api/android/couchbase-lite-ee.api @@ -331,8 +331,8 @@ public final class kotbase/DatabaseChange : kotbase/internal/DelegatedClass { } public final class kotbase/DatabaseConfiguration : kotbase/internal/DelegatedClass { + public fun ()V public fun (Lkotbase/DatabaseConfiguration;)V - public synthetic fun (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 @@ -1052,8 +1052,8 @@ public final class kotbase/Ordering$SortOrder : kotbase/Ordering { } public final class kotbase/Parameters : kotbase/internal/DelegatedClass { + public fun ()V public fun (Lkotbase/Parameters;)V - public synthetic fun (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; @@ -1336,8 +1336,8 @@ public final class kotbase/SelectResult$From : kotbase/SelectResult { } public final class kotbase/SessionAuthenticator : kotbase/Authenticator { + public fun (Ljava/lang/String;)V public fun (Ljava/lang/String;Ljava/lang/String;)V - public synthetic fun (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; @@ -1392,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 (Lkotbase/Database;Ljava/lang/String;IZLkotbase/TLSIdentity;Lkotbase/ListenerAuthenticator;ZZ)V public synthetic fun (Lkotbase/Database;Ljava/lang/String;IZLkotbase/TLSIdentity;Lkotbase/ListenerAuthenticator;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun (Lkotbase/URLEndpointListenerConfiguration;)V @@ -1412,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 { diff --git a/couchbase-lite-ee/api/jvm/couchbase-lite-ee.api b/couchbase-lite-ee/api/jvm/couchbase-lite-ee.api index 1aec890d2..2381f7d6c 100644 --- a/couchbase-lite-ee/api/jvm/couchbase-lite-ee.api +++ b/couchbase-lite-ee/api/jvm/couchbase-lite-ee.api @@ -331,8 +331,8 @@ public final class kotbase/DatabaseChange : kotbase/internal/DelegatedClass { } public final class kotbase/DatabaseConfiguration : kotbase/internal/DelegatedClass { + public fun ()V public fun (Lkotbase/DatabaseConfiguration;)V - public synthetic fun (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 @@ -1047,8 +1047,8 @@ public final class kotbase/Ordering$SortOrder : kotbase/Ordering { } public final class kotbase/Parameters : kotbase/internal/DelegatedClass { + public fun ()V public fun (Lkotbase/Parameters;)V - public synthetic fun (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; @@ -1331,8 +1331,8 @@ public final class kotbase/SelectResult$From : kotbase/SelectResult { } public final class kotbase/SessionAuthenticator : kotbase/Authenticator { + public fun (Ljava/lang/String;)V public fun (Ljava/lang/String;Ljava/lang/String;)V - public synthetic fun (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; @@ -1391,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 (Lkotbase/Database;Ljava/lang/String;IZLkotbase/TLSIdentity;Lkotbase/ListenerAuthenticator;ZZ)V public synthetic fun (Lkotbase/Database;Ljava/lang/String;IZLkotbase/TLSIdentity;Lkotbase/ListenerAuthenticator;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun (Lkotbase/URLEndpointListenerConfiguration;)V @@ -1411,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 { diff --git a/couchbase-lite-ee/src/commonMain/ee/kotbase/DatabaseConfiguration.kt b/couchbase-lite-ee/src/commonMain/ee/kotbase/DatabaseConfiguration.kt index a1dcffac0..64ab59665 100644 --- a/couchbase-lite-ee/src/commonMain/ee/kotbase/DatabaseConfiguration.kt +++ b/couchbase-lite-ee/src/commonMain/ee/kotbase/DatabaseConfiguration.kt @@ -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 diff --git a/couchbase-lite/api/android/couchbase-lite.api b/couchbase-lite/api/android/couchbase-lite.api index 2c6ca085d..e56088fca 100644 --- a/couchbase-lite/api/android/couchbase-lite.api +++ b/couchbase-lite/api/android/couchbase-lite.api @@ -308,8 +308,8 @@ public final class kotbase/DatabaseChange : kotbase/internal/DelegatedClass { } public final class kotbase/DatabaseConfiguration : kotbase/internal/DelegatedClass { + public fun ()V public fun (Lkotbase/DatabaseConfiguration;)V - public synthetic fun (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 @@ -920,8 +920,8 @@ public final class kotbase/Ordering$SortOrder : kotbase/Ordering { } public final class kotbase/Parameters : kotbase/internal/DelegatedClass { + public fun ()V public fun (Lkotbase/Parameters;)V - public synthetic fun (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; @@ -1169,8 +1169,8 @@ public final class kotbase/SelectResult$From : kotbase/SelectResult { } public final class kotbase/SessionAuthenticator : kotbase/Authenticator { + public fun (Ljava/lang/String;)V public fun (Ljava/lang/String;Ljava/lang/String;)V - public synthetic fun (Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public synthetic fun getActual$couchbase_lite_release ()Ljava/lang/Object; public final fun getCookieName ()Ljava/lang/String; public final fun getSessionID ()Ljava/lang/String; diff --git a/couchbase-lite/api/jvm/couchbase-lite.api b/couchbase-lite/api/jvm/couchbase-lite.api index 8d3b0f42b..a4a56a68e 100644 --- a/couchbase-lite/api/jvm/couchbase-lite.api +++ b/couchbase-lite/api/jvm/couchbase-lite.api @@ -308,8 +308,8 @@ public final class kotbase/DatabaseChange : kotbase/internal/DelegatedClass { } public final class kotbase/DatabaseConfiguration : kotbase/internal/DelegatedClass { + public fun ()V public fun (Lkotbase/DatabaseConfiguration;)V - public synthetic fun (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 @@ -920,8 +920,8 @@ public final class kotbase/Ordering$SortOrder : kotbase/Ordering { } public final class kotbase/Parameters : kotbase/internal/DelegatedClass { + public fun ()V public fun (Lkotbase/Parameters;)V - public synthetic fun (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; @@ -1169,8 +1169,8 @@ public final class kotbase/SelectResult$From : kotbase/SelectResult { } public final class kotbase/SessionAuthenticator : kotbase/Authenticator { + public fun (Ljava/lang/String;)V public fun (Ljava/lang/String;Ljava/lang/String;)V - public synthetic fun (Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public synthetic fun getActual$couchbase_lite ()Ljava/lang/Object; public final fun getCookieName ()Ljava/lang/String; public final fun getSessionID ()Ljava/lang/String; diff --git a/couchbase-lite/src/appleMain/kotlin/kotbase/DatabaseConfiguration.apple.kt b/couchbase-lite/src/appleMain/kotlin/kotbase/DatabaseConfiguration.apple.kt index 87a5fc9ca..321c354ad 100644 --- a/couchbase-lite/src/appleMain/kotlin/kotbase/DatabaseConfiguration.apple.kt +++ b/couchbase-lite/src/appleMain/kotlin/kotbase/DatabaseConfiguration.apple.kt @@ -21,6 +21,8 @@ import kotbase.internal.DelegatedClass public actual class DatabaseConfiguration internal constructor(actual: CBLDatabaseConfiguration) : DelegatedClass(actual) { + public actual constructor() : this(CBLDatabaseConfiguration()) + public actual constructor(config: DatabaseConfiguration?) : this( CBLDatabaseConfiguration(config?.actual) ) diff --git a/couchbase-lite/src/appleMain/kotlin/kotbase/Parameters.apple.kt b/couchbase-lite/src/appleMain/kotlin/kotbase/Parameters.apple.kt index 76934ddbe..0328ddacd 100644 --- a/couchbase-lite/src/appleMain/kotlin/kotbase/Parameters.apple.kt +++ b/couchbase-lite/src/appleMain/kotlin/kotbase/Parameters.apple.kt @@ -25,6 +25,8 @@ import platform.Foundation.NSNumber public actual class Parameters internal constructor(actual: CBLQueryParameters) : DelegatedClass(actual) { + public actual constructor() : this(CBLQueryParameters()) + public actual constructor(parameters: Parameters?) : this( CBLQueryParameters(parameters?.actual) ) diff --git a/couchbase-lite/src/appleMain/kotlin/kotbase/SessionAuthenticator.apple.kt b/couchbase-lite/src/appleMain/kotlin/kotbase/SessionAuthenticator.apple.kt index aa66b689f..5bcc2d00b 100644 --- a/couchbase-lite/src/appleMain/kotlin/kotbase/SessionAuthenticator.apple.kt +++ b/couchbase-lite/src/appleMain/kotlin/kotbase/SessionAuthenticator.apple.kt @@ -22,6 +22,8 @@ internal constructor( override val actual: CBLSessionAuthenticator ) : Authenticator(actual) { + public actual constructor(sessionID: String) : this(CBLSessionAuthenticator(sessionID)) + public actual constructor(sessionID: String, cookieName: String?) : this( CBLSessionAuthenticator(sessionID, cookieName) ) diff --git a/couchbase-lite/src/commonMain/kotlin/kotbase/DatabaseConfiguration.kt b/couchbase-lite/src/commonMain/kotlin/kotbase/DatabaseConfiguration.kt index 035ffe24a..18b3f116e 100755 --- a/couchbase-lite/src/commonMain/kotlin/kotbase/DatabaseConfiguration.kt +++ b/couchbase-lite/src/commonMain/kotlin/kotbase/DatabaseConfiguration.kt @@ -18,9 +18,11 @@ package kotbase /** * Configuration for opening a database. */ -public expect class DatabaseConfiguration( - config: DatabaseConfiguration? = null -) { +public expect class DatabaseConfiguration { + + public constructor() + + public constructor(config: DatabaseConfiguration?) /** * Set the canonical path of the directory to store the database in. diff --git a/couchbase-lite/src/commonMain/kotlin/kotbase/Parameters.kt b/couchbase-lite/src/commonMain/kotlin/kotbase/Parameters.kt index 79f9a8ab5..e8d0c43f4 100755 --- a/couchbase-lite/src/commonMain/kotlin/kotbase/Parameters.kt +++ b/couchbase-lite/src/commonMain/kotlin/kotbase/Parameters.kt @@ -20,7 +20,11 @@ import kotlinx.datetime.Instant /** * A Parameters object used for setting values to the query parameters defined in the query. */ -public expect class Parameters(parameters: Parameters? = null) { +public expect class Parameters { + + public constructor() + + public constructor(parameters: Parameters?) /** * Gets a parameter's value. diff --git a/couchbase-lite/src/commonMain/kotlin/kotbase/SessionAuthenticator.kt b/couchbase-lite/src/commonMain/kotlin/kotbase/SessionAuthenticator.kt index 3be700596..c8c6185f3 100755 --- a/couchbase-lite/src/commonMain/kotlin/kotbase/SessionAuthenticator.kt +++ b/couchbase-lite/src/commonMain/kotlin/kotbase/SessionAuthenticator.kt @@ -19,16 +19,23 @@ package kotbase * SessionAuthenticator class is an authenticator that will authenticate by using the session ID of * the session created by a Sync Gateway */ -public expect class SessionAuthenticator +public expect class SessionAuthenticator : Authenticator { -/** - * Initializes with the session ID and the cookie name. If the given cookieName - * is null, the default cookie name will be used. - * - * @param sessionID Sync Gateway session ID - * @param cookieName The cookie name - */ -constructor(sessionID: String, cookieName: String? = null) : Authenticator { + /** + * Initializes with the Sync Gateway session ID and uses the default cookie name. + * + * @param sessionID Sync Gateway session ID + */ + public constructor(sessionID: String) + + /** + * Initializes with the session ID and the cookie name. If the given cookieName + * is null, the default cookie name will be used. + * + * @param sessionID Sync Gateway session ID + * @param cookieName The cookie name + */ + public constructor(sessionID: String, cookieName: String?) /** * Return session ID of the session created by a Sync Gateway. diff --git a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/DatabaseConfiguration.jvmCommon.kt b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/DatabaseConfiguration.jvmCommon.kt index 62ee61c45..4674e399b 100644 --- a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/DatabaseConfiguration.jvmCommon.kt +++ b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/DatabaseConfiguration.jvmCommon.kt @@ -21,6 +21,8 @@ import com.couchbase.lite.DatabaseConfiguration as CBLDatabaseConfiguration public actual class DatabaseConfiguration internal constructor(actual: CBLDatabaseConfiguration) : DelegatedClass(actual) { + public actual constructor() : this(CBLDatabaseConfiguration()) + public actual constructor(config: DatabaseConfiguration?) : this(CBLDatabaseConfiguration(config?.actual)) public actual fun setDirectory(directory: String): DatabaseConfiguration { diff --git a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Parameters.jvmCommon.kt b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Parameters.jvmCommon.kt index 50267d18d..5ae871b49 100644 --- a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Parameters.jvmCommon.kt +++ b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/Parameters.jvmCommon.kt @@ -23,6 +23,8 @@ import com.couchbase.lite.Parameters as CBLParameters public actual class Parameters internal constructor(actual: CBLParameters) : DelegatedClass(actual) { + public actual constructor() : this(CBLParameters()) + public actual constructor(parameters: Parameters?) : this(CBLParameters(parameters?.actual)) public actual fun getValue(name: String): Any? = diff --git a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/SessionAuthenticator.jvmCommon.kt b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/SessionAuthenticator.jvmCommon.kt index b4877251d..ef0001ac7 100644 --- a/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/SessionAuthenticator.jvmCommon.kt +++ b/couchbase-lite/src/jvmCommonMain/kotlin/kotbase/SessionAuthenticator.jvmCommon.kt @@ -22,6 +22,8 @@ internal constructor( override val actual: CBLSessionAuthenticator ) : Authenticator(actual) { + public actual constructor(sessionID: String) : this(CBLSessionAuthenticator(sessionID)) + public actual constructor(sessionID: String, cookieName: String?) : this( CBLSessionAuthenticator(sessionID, cookieName) ) diff --git a/couchbase-lite/src/nativeMain/kotlin/kotbase/DatabaseConfiguration.native.kt b/couchbase-lite/src/nativeMain/kotlin/kotbase/DatabaseConfiguration.native.kt index 695a607d1..c2355a071 100644 --- a/couchbase-lite/src/nativeMain/kotlin/kotbase/DatabaseConfiguration.native.kt +++ b/couchbase-lite/src/nativeMain/kotlin/kotbase/DatabaseConfiguration.native.kt @@ -30,6 +30,8 @@ import kotlin.native.ref.createCleaner public actual class DatabaseConfiguration public actual constructor(config: DatabaseConfiguration?) { + public actual constructor() : this(null) + private val arena = Arena() internal val actual: CPointer = diff --git a/couchbase-lite/src/nativeMain/kotlin/kotbase/Parameters.native.kt b/couchbase-lite/src/nativeMain/kotlin/kotbase/Parameters.native.kt index 77b7f80ab..f77f55772 100644 --- a/couchbase-lite/src/nativeMain/kotlin/kotbase/Parameters.native.kt +++ b/couchbase-lite/src/nativeMain/kotlin/kotbase/Parameters.native.kt @@ -37,6 +37,8 @@ internal constructor( FLDict_Release(it) } + public actual constructor() : this(null) + public actual constructor(parameters: Parameters?) : this( if (parameters != null) { FLDict_MutableCopy(parameters.actual, kFLDefaultCopy) diff --git a/couchbase-lite/src/nativeMain/kotlin/kotbase/SessionAuthenticator.native.kt b/couchbase-lite/src/nativeMain/kotlin/kotbase/SessionAuthenticator.native.kt index 17c5fd165..90aba42d0 100644 --- a/couchbase-lite/src/nativeMain/kotlin/kotbase/SessionAuthenticator.native.kt +++ b/couchbase-lite/src/nativeMain/kotlin/kotbase/SessionAuthenticator.native.kt @@ -27,6 +27,8 @@ private constructor( actual: CPointer ) : Authenticator(actual) { + public actual constructor(sessionID: String) : this(sessionID, null) + public actual constructor(sessionID: String, cookieName: String?) : this( sessionID, cookieName ?: DEFAULT_SYNC_GATEWAY_SESSION_ID_NAME, From ffd50662effa5de96d588b6ae814172753c2368f Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Wed, 15 Nov 2023 21:33:59 -0700 Subject: [PATCH 14/17] Set version to 1.0.1-SNAPSHOT --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1cb42f61c..63af9c757 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,4 +19,4 @@ android.nonTransitiveRClass=true # Publishing GROUP=dev.kotbase -VERSION=1.1.0-SNAPSHOT +VERSION=1.0.1-SNAPSHOT From 6448686434a7f80c71a2161d32c23241ebf86434 Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Thu, 16 Nov 2023 10:08:40 -0700 Subject: [PATCH 15/17] Use compilerOptions instead of kotlinOptions --- buildSrc/src/main/kotlin/base-convention.gradle.kts | 3 ++- examples/getting-started-compose/androidApp/build.gradle.kts | 3 ++- examples/getting-started-compose/shared/build.gradle.kts | 3 ++- examples/getting-started/shared/build.gradle.kts | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/kotlin/base-convention.gradle.kts b/buildSrc/src/main/kotlin/base-convention.gradle.kts index 3215b45ac..43715d8e2 100644 --- a/buildSrc/src/main/kotlin/base-convention.gradle.kts +++ b/buildSrc/src/main/kotlin/base-convention.gradle.kts @@ -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 @@ -66,7 +67,7 @@ kotlin { } tasks.withType().configureEach { - kotlinOptions.jvmTarget = "1.8" + compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8) } android { diff --git a/examples/getting-started-compose/androidApp/build.gradle.kts b/examples/getting-started-compose/androidApp/build.gradle.kts index 6eb325854..f58dc037f 100644 --- a/examples/getting-started-compose/androidApp/build.gradle.kts +++ b/examples/getting-started-compose/androidApp/build.gradle.kts @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -18,7 +19,7 @@ kotlin { } tasks.withType { - kotlinOptions.jvmTarget = "11" + compilerOptions.jvmTarget.set(JvmTarget.JVM_11) } android { diff --git a/examples/getting-started-compose/shared/build.gradle.kts b/examples/getting-started-compose/shared/build.gradle.kts index d6a45f43f..5b759d40d 100644 --- a/examples/getting-started-compose/shared/build.gradle.kts +++ b/examples/getting-started-compose/shared/build.gradle.kts @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -50,7 +51,7 @@ kotlin { } tasks.withType { - kotlinOptions.jvmTarget = "11" + compilerOptions.jvmTarget.set(JvmTarget.JVM_11) } android { diff --git a/examples/getting-started/shared/build.gradle.kts b/examples/getting-started/shared/build.gradle.kts index 140b5b75b..26e3ffc4f 100644 --- a/examples/getting-started/shared/build.gradle.kts +++ b/examples/getting-started/shared/build.gradle.kts @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -54,7 +55,7 @@ kotlin { } tasks.withType { - kotlinOptions.jvmTarget = "1.8" + compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8) } android { From 797cde3f8eb68afdead9cfb88b5a1ce7b4a1f2a0 Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Thu, 16 Nov 2023 10:15:07 -0700 Subject: [PATCH 16/17] Replace kotlinOptions in Android build script --- examples/getting-started/androidApp/build.gradle.kts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/getting-started/androidApp/build.gradle.kts b/examples/getting-started/androidApp/build.gradle.kts index 54454d4bb..0a1f4bb7a 100644 --- a/examples/getting-started/androidApp/build.gradle.kts +++ b/examples/getting-started/androidApp/build.gradle.kts @@ -1,3 +1,6 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + plugins { alias(libs.plugins.android.application) alias(libs.plugins.kotlin.android) @@ -22,13 +25,16 @@ android { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } - kotlinOptions.jvmTarget = "1.8" buildFeatures { viewBinding = true } packagingOptions.resources.pickFirsts += "META-INF/**" } +tasks.withType { + compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8) +} + dependencies { implementation(projects.shared) implementation(libs.androidx.core.ktx) From d9b3be2f8a4e7b07099402580f06c14adb85cd54 Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Mon, 20 Nov 2023 15:50:04 -0700 Subject: [PATCH 17/17] Add note about linking native binary in installation --- README.md | 5 +++++ docs/installation.md | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 84d6fabfb..07d423202 100644 --- a/README.md +++ b/README.md @@ -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]( diff --git a/docs/installation.md b/docs/installation.md index 5ea8b5194..459c3c56b 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -49,3 +49,8 @@ Couchbase Maven repository. mavenCentral() } ``` + +## Native Platforms + +Native platform targets should additionally link to the Couchbase Lite dependency native binary. See [Supported Platforms]( +platforms.md) for more details.