Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make @Throws getter functions properties #12

Merged
merged 12 commits into from
Jan 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ internal constructor(

@Deprecated(
"Use MessageEndpointListener(Collection, ProtocolType)",
ReplaceWith("MessageEndpointListener(setOf(database.getDefaultCollection()!!), protocolType)")
ReplaceWith("MessageEndpointListener(setOf(database.defaultCollection), protocolType)")
)
public actual constructor(
database: Database,
protocolType: ProtocolType
) : this(
CBLMessageEndpointListenerConfiguration(database.actual, protocolType.actual),
database,
setOf(database.getDefaultCollection())
setOf(database.defaultCollection)
)

public actual constructor(collections: Set<Collection>, protocolType: ProtocolType) : this(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private constructor(

@Deprecated(
"Use URLEndpointListenerConfiguration(Collections)",
ReplaceWith("URLEndpointListenerConfiguration(setOf(database.getDefaultCollection()!!), networkInterface, port, disableTls, identity, authenticator, readOnly, enableDeltaSync)")
ReplaceWith("URLEndpointListenerConfiguration(setOf(database.defaultCollection), networkInterface, port, disableTls, identity, authenticator, readOnly, enableDeltaSync)")
)
public actual constructor(
database: Database,
Expand All @@ -45,7 +45,7 @@ private constructor(
enableDeltaSync: Boolean
) : this(
database,
setOf(database.getDefaultCollection()),
setOf(database.defaultCollection),
identity,
authenticator,
CBLURLEndpointListenerConfiguration(database.actual).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public expect class MessageEndpointListenerConfiguration {
*/
@Deprecated(
"Use MessageEndpointListener(Collection, ProtocolType)",
ReplaceWith("MessageEndpointListener(setOf(database.getDefaultCollection()!!), protocolType)")
ReplaceWith("MessageEndpointListener(setOf(database.defaultCollection), protocolType)")
)
public constructor(database: Database, protocolType: ProtocolType)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public expect class URLEndpointListenerConfiguration {
*/
@Deprecated(
"Use URLEndpointListenerConfiguration(Collections)",
ReplaceWith("URLEndpointListenerConfiguration(setOf(database.getDefaultCollection()!!), networkInterface, port, disableTls, identity, authenticator, readOnly, enableDeltaSync)")
ReplaceWith("URLEndpointListenerConfiguration(setOf(database.defaultCollection), networkInterface, port, disableTls, identity, authenticator, readOnly, enableDeltaSync)")
)
public constructor(
database: Database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DatabaseEncryptionTest : BaseDbTest() {
seekrit = openSeekrit(null)

val doc = MutableDocument(mapOf("answer" to 42))
seekrit!!.getDefaultCollection()!!.save(doc)
seekrit!!.defaultCollection.save(doc)
seekrit!!.close()
seekrit = null

Expand All @@ -52,7 +52,7 @@ class DatabaseEncryptionTest : BaseDbTest() {

// Reopen with no password:
seekrit = openSeekrit(null)
assertEquals(1, seekrit!!.getDefaultCollection()!!.count)
assertEquals(1, seekrit!!.defaultCollection.count)
}

@Test
Expand All @@ -61,7 +61,7 @@ class DatabaseEncryptionTest : BaseDbTest() {
seekrit = openSeekrit("letmein")

val doc = MutableDocument(mapOf("answer" to 42))
seekrit!!.getDefaultCollection()!!.save(doc)
seekrit!!.defaultCollection.save(doc)
seekrit!!.close()
seekrit = null

Expand Down Expand Up @@ -89,12 +89,12 @@ class DatabaseEncryptionTest : BaseDbTest() {

// Re-create database:
seekrit = openSeekrit(null)
assertEquals(0, seekrit!!.getDefaultCollection()!!.count)
assertEquals(0, seekrit!!.defaultCollection.count)
seekrit!!.close()

// Make sure it doesn't need a password now:
seekrit = openSeekrit(null)
assertEquals(0, seekrit!!.getDefaultCollection()!!.count)
assertEquals(0, seekrit!!.defaultCollection.count)
seekrit!!.close()

// Make sure old password doesn't work:
Expand All @@ -117,7 +117,7 @@ class DatabaseEncryptionTest : BaseDbTest() {
val body = "This is a blob!".encodeToByteArray()
var blob = Blob("text/plain", body)
doc.setValue("blob", blob)
seekrit!!.getDefaultCollection()!!.save(doc)
seekrit!!.defaultCollection.save(doc)

// Read content from the raw blob file:
blob = doc.getBlob("blob")!!
Expand All @@ -134,7 +134,7 @@ class DatabaseEncryptionTest : BaseDbTest() {
}

// Check blob content:
val savedDoc = seekrit!!.getDefaultCollection()!!.getDocument("att")
val savedDoc = seekrit!!.defaultCollection.getDocument("att")
assertNotNull(savedDoc)
blob = savedDoc.getBlob("blob")!!
assertNotNull(blob.digest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ internal constructor(
@Suppress("DEPRECATION")
@Deprecated(
"Use MessageEndpointListener(Collection, ProtocolType)",
ReplaceWith("MessageEndpointListener(setOf(database.getDefaultCollection()!!), protocolType)")
ReplaceWith("MessageEndpointListener(setOf(database.defaultCollection), protocolType)")
)
public actual constructor(
database: Database,
protocolType: ProtocolType
) : this(
CBLMessageEndpointListenerConfiguration(database.actual, protocolType),
database,
setOf(database.getDefaultCollection())
setOf(database.defaultCollection)
)

public actual constructor(collections: Set<Collection>, protocolType: ProtocolType) : this(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private constructor(
@Suppress("DEPRECATION")
@Deprecated(
"Use URLEndpointListenerConfiguration(Collections)",
ReplaceWith("URLEndpointListenerConfiguration(setOf(database.getDefaultCollection()!!), networkInterface, port, disableTls, identity, authenticator, readOnly, enableDeltaSync)")
ReplaceWith("URLEndpointListenerConfiguration(setOf(database.defaultCollection), networkInterface, port, disableTls, identity, authenticator, readOnly, enableDeltaSync)")
)
public actual constructor(
database: Database,
Expand All @@ -45,7 +45,7 @@ private constructor(
enableDeltaSync: Boolean
) : this(
database,
setOf(database.getDefaultCollection()),
setOf(database.defaultCollection),
identity,
authenticator,
CBLURLEndpointListenerConfiguration(database.actual).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ internal constructor(

@Deprecated(
"Use MessageEndpointListener(Collection, ProtocolType)",
ReplaceWith("MessageEndpointListener(setOf(database.getDefaultCollection()!!), protocolType)")
ReplaceWith("MessageEndpointListener(setOf(database.defaultCollection), protocolType)")
)
public actual constructor(
database: Database,
protocolType: ProtocolType
) : this(
database,
setOf(database.getDefaultCollection()),
setOf(database.defaultCollection),
protocolType
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public actual class URLEndpointListenerConfiguration private constructor() {

@Deprecated(
"Use URLEndpointListenerConfiguration(Collections)",
ReplaceWith("URLEndpointListenerConfiguration(setOf(database.getDefaultCollection()!!), networkInterface, port, disableTls, identity, authenticator, readOnly, enableDeltaSync)")
ReplaceWith("URLEndpointListenerConfiguration(setOf(database.defaultCollection), networkInterface, port, disableTls, identity, authenticator, readOnly, enableDeltaSync)")
)
public actual constructor(
database: Database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class KermitCouchbaseLiteLoggerTest : BaseTest() {
logWriter.checkLog(Severity.Info, CBL_DATABASE, "Instantiated")
logWriter.clearCache()

database.getDefaultCollection()!!.save(MutableDocument("doc-1", """{"foo":"bar","baz":42}"""))
database.defaultCollection.save(MutableDocument("doc-1", """{"foo":"bar","baz":42}"""))
logWriter.checkLog(Severity.Verbose, CBL_DATABASE, "{DB#", "begin transaction")
logWriter.checkLog(Severity.Verbose, CBL_DATABASE, "{DB#", "Saved 'doc-1' rev #1-", "as seq 1")
logWriter.checkLog(Severity.Verbose, CBL_DATABASE, "{DB#", "commit transaction")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import kotlin.coroutines.CoroutineContext
*/
@Suppress("DEPRECATION")
@Deprecated(
"Use getDefaultCollection().documentFlow()",
ReplaceWith("getDefaultCollection()!!.documentFlow(id)")
"Use defaultCollection.documentFlow()",
ReplaceWith("defaultCollection.documentFlow(id)")
)
public fun Database.documentFlow(id: String): Flow<Document?> = documentFlow(id, Dispatchers.IO)

Expand All @@ -48,8 +48,8 @@ public fun Database.documentFlow(id: String): Flow<Document?> = documentFlow(id,
*/
@Suppress("DEPRECATION")
@Deprecated(
"Use getDefaultCollection().documentFlow()",
ReplaceWith("getDefaultCollection()!!.documentFlow(id, fetchContext)")
"Use defaultCollection.documentFlow()",
ReplaceWith("defaultCollection.documentFlow(id, fetchContext)")
)
public fun Database.documentFlow(
id: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public inline fun all(): SelectResult.From = SelectResult.all()
@Suppress("DEPRECATION")
@Deprecated(
"Use from(Collection)",
ReplaceWith("from(database.getDefaultCollection()!!)")
ReplaceWith("from(database.defaultCollection)")
)
public inline infix fun FromRouter.from(database: Database): From = from(DataSource.database(database))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public fun <RowType : Any> QueryPagingSource(
*/
@Deprecated(
"Use collection instead of database",
ReplaceWith("QueryPagingSource(context, select, database.getDefaultCollection()!!, mapper) { this }")
ReplaceWith("QueryPagingSource(context, select, database.defaultCollection, mapper) { this }")
)
public fun <RowType : Any> QueryPagingSource(
context: CoroutineContext,
Expand All @@ -135,7 +135,7 @@ public fun <RowType : Any> QueryPagingSource(
mapper: (Map<String, Any?>) -> RowType
): PagingSource<Int, RowType> = OffsetQueryPagingSource(
select,
database.getDefaultCollection(),
database.defaultCollection,
{ this },
context,
mapMapper = mapper
Expand Down Expand Up @@ -164,7 +164,7 @@ public fun <RowType : Any> QueryPagingSource(
*/
@Deprecated(
"Use collection instead of database",
ReplaceWith("QueryPagingSource(context, select, database.getDefaultCollection()!!, mapper) { this }")
ReplaceWith("QueryPagingSource(context, select, database.defaultCollection, mapper) { this }")
)
@JvmName("QueryPagingSourceString")
public fun <RowType : Any> QueryPagingSource(
Expand All @@ -174,7 +174,7 @@ public fun <RowType : Any> QueryPagingSource(
mapper: (String) -> RowType
): PagingSource<Int, RowType> = OffsetQueryPagingSource(
select,
database.getDefaultCollection(),
database.defaultCollection,
{ this },
context,
jsonStringMapper = mapper
Expand Down Expand Up @@ -203,7 +203,7 @@ public fun <RowType : Any> QueryPagingSource(
*/
@Deprecated(
"Use collection instead of database",
ReplaceWith("QueryPagingSource(context, select, database.getDefaultCollection()!!, mapper, queryProvider)")
ReplaceWith("QueryPagingSource(context, select, database.defaultCollection, mapper, queryProvider)")
)
@JvmName("QueryPagingSourceWithQuery")
public fun <RowType : Any> QueryPagingSource(
Expand All @@ -214,7 +214,7 @@ public fun <RowType : Any> QueryPagingSource(
queryProvider: From.() -> LimitRouter
): PagingSource<Int, RowType> = OffsetQueryPagingSource(
select,
database.getDefaultCollection(),
database.defaultCollection,
queryProvider,
context,
mapMapper = mapper
Expand Down Expand Up @@ -243,7 +243,7 @@ public fun <RowType : Any> QueryPagingSource(
*/
@Deprecated(
"Use collection instead of database",
ReplaceWith("QueryPagingSource(context, select, database.getDefaultCollection()!!, mapper, queryProvider)")
ReplaceWith("QueryPagingSource(context, select, database.defaultCollection, mapper, queryProvider)")
)
@JvmName("QueryPagingSourceStringWithQuery")
public fun <RowType : Any> QueryPagingSource(
Expand All @@ -254,11 +254,8 @@ public fun <RowType : Any> QueryPagingSource(
queryProvider: From.() -> LimitRouter
): PagingSource<Int, RowType> = OffsetQueryPagingSource(
select,
database.getDefaultCollection(),
database.defaultCollection,
queryProvider,
context,
jsonStringMapper = mapper
)

private fun Database.getDefaultCollection(): Collection =
requireNotNull(getDefaultCollection()) { "Default collection must exist" }
26 changes: 20 additions & 6 deletions couchbase-lite/src/appleMain/kotlin/kotbase/Collection.apple.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import kotlinx.datetime.Instant
import kotlinx.datetime.toKotlinInstant
import kotlinx.datetime.toNSDate
import kotlin.coroutines.CoroutineContext
import kotlin.experimental.ExperimentalObjCRefinement

@OptIn(ExperimentalStdlibApi::class)
public actual class Collection
Expand Down Expand Up @@ -212,13 +213,26 @@ internal constructor(
}
}

@OptIn(ExperimentalObjCRefinement::class)
@HiddenFromObjC
@Suppress("ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT") // https://youtrack.jetbrains.com/issue/KT-63047
//@get:Throws(CouchbaseLiteException::class)
public actual val indexes: Set<String>
get() {
return wrapCBLError { error ->
@Suppress("UNCHECKED_CAST")
actual.indexes(error) as List<String>
}.toSet()
}

/**
* Get a list of the names of indices in the collection.
*
* @throws CouchbaseLiteException on failure
*/
// For Objective-C/Swift throws
@Throws(CouchbaseLiteException::class)
public actual fun getIndexes(): Set<String> {
return wrapCBLError { error ->
@Suppress("UNCHECKED_CAST")
actual.indexes(error) as List<String>
}.toSet()
}
public fun indexes(): Set<String> = indexes

@Throws(CouchbaseLiteException::class)
public actual fun createIndex(name: String, config: IndexConfiguration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private constructor(override var actual: CBLQueryDataSource) : DelegatedClass<CB

@Deprecated(
"Use DataSource.collection(Collection)",
ReplaceWith("collection(database.getDefaultCollection()!!)")
ReplaceWith("collection(database.defaultCollection)")
)
public actual fun database(database: Database): As =
As(database = database.actual)
Expand Down
Loading