Skip to content

Commit cd6cc63

Browse files
authored
[RKOTLIN-612] MongoClient API (#1593)
1 parent dccafa2 commit cd6cc63

File tree

50 files changed

+4958
-543
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4958
-543
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This release will bump the Realm file format 24. Opening a file with an older fo
1616
* Support for RealmLists and RealmDictionaries in `RealmAny`. (Issue [#1434](https://github.com/realm/realm-kotlin/issues/1434))
1717
* Optimized `RealmList.indexOf()` and `RealmList.contains()` using Core implementation of operations instead of iterating elements and comparing them in Kotlin. (Issue [#1625](https://github.com/realm/realm-kotlin/pull/1666) [RKOTLIN-995](https://jira.mongodb.org/browse/RKOTLIN-995)).
1818
* Add support for filtering logs by category. (Issue [#1691](https://github.com/realm/realm-kotlin/issues/1691) [JIRA](https://jira.mongodb.org/browse/RKOTLIN-1038))
19+
* [Sync] Add Mongo Client API to access Atlas App Service collections. It can be accessed through `User.mongoClient`. (Issue [#972](https://github.com/realm/realm-kotlin/issues/972)/[RKOTLIN-612](https://jira.mongodb.org/browse/RKOTLIN-612))
1920

2021
### Fixed
2122
* Inserting the same typed link to the same key in a dictionary more than once would incorrectly create multiple backlinks to the object. This did not appear to cause any crashes later, but would have affecting explicit backlink count queries (eg: `...@links.@count`) and possibly notifications (Core Issue [realm/realm-core#7676](https://github.com/realm/realm-core/issues/7676) since v1.16.0).
@@ -177,9 +178,9 @@ This release will bump the Realm file format from version 23 to 24. Opening a fi
177178
* None.
178179

179180
### Enhancements
180-
* [Sync] Added option to use managed WebSockets via OkHttp instead of Realm's built-in WebSocket client for Sync traffic (Only Android and JVM targets for now). Managed WebSockets offer improved support for proxies and firewalls that require authentication. This feature is currently opt-in and can be enabled by using `AppConfiguration.usePlatformNetworking()`. Managed WebSockets will become the default in a future version. (PR [#1528](https://github.com/realm/realm-kotlin/pull/1528)).
181-
* `AutoClientResetFailed` exception now reports as the throwable cause any user exceptions that might occur during a client reset. (Issue [#1580](https://github.com/realm/realm-kotlin/issues/1580))
182181
* The Unpacking of JVM native library will use the current library version instead of a calculated hash for the path. (Issue [#1617](https://github.com/realm/realm-kotlin/issues/1617)).
182+
* [Sync] Added option to use managed WebSockets via OkHttp instead of Realm's built-in WebSocket client for Sync traffic (Only Android and JVM targets for now). Managed WebSockets offer improved support for proxies and firewalls that require authentication. This feature is currently opt-in and can be enabled by using `AppConfiguration.usePlatformNetworking()`. Managed WebSockets will become the default in a future version. (PR [#1528](https://github.com/realm/realm-kotlin/pull/1528)).
183+
* [Sync] `AutoClientResetFailed` exception now reports as the throwable cause any user exceptions that might occur during a client reset. (Issue [#1580](https://github.com/realm/realm-kotlin/issues/1580))
183184

184185
### Fixed
185186
* Cache notification callback JNI references at startup to ensure that symbols can be resolved in core callbacks. (Issue [#1577](https://github.com/realm/realm-kotlin/issues/1577))

buildSrc/src/main/kotlin/Config.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ object Versions {
121121
const val jmh = "1.34" // https://github.com/openjdk/jmh
122122
const val jmhPlugin = "0.6.6" // https://github.com/melix/jmh-gradle-plugin
123123
const val junit = "4.13.2" // https://mvnrepository.com/artifact/junit/junit
124-
const val kbson = "0.3.0" // https://github.com/mongodb/kbson
124+
const val kbson = "0.4.0" // https://github.com/mongodb/kbson
125125
// When updating the Kotlin version, also remember to update /examples/min-android-sample/build.gradle.kts
126126
const val kotlin = "1.9.0" // https://github.com/JetBrains/kotlin and https://kotlinlang.org/docs/releases.html#release-details
127127
const val kotlinJvmTarget = "1.8" // Which JVM bytecode version is kotlin compiled to.

packages/cinterop/src/commonMain/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ expect object RealmInterop {
772772
app: RealmAppPointer,
773773
user: RealmUserPointer,
774774
name: String,
775+
serviceName: String? = null,
775776
serializedEjsonArgs: String, // as ejson
776777
callback: AppCallback<String>
777778
)

packages/cinterop/src/jvm/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,14 +1710,16 @@ actual object RealmInterop {
17101710
)
17111711
}
17121712

1713+
@Suppress("LongParameterList")
17131714
actual fun realm_app_call_function(
17141715
app: RealmAppPointer,
17151716
user: RealmUserPointer,
17161717
name: String,
1718+
serviceName: String?,
17171719
serializedEjsonArgs: String,
17181720
callback: AppCallback<String>
17191721
) {
1720-
realmc.realm_app_call_function(app.cptr(), user.cptr(), name, serializedEjsonArgs, null, callback)
1722+
realmc.realm_app_call_function(app.cptr(), user.cptr(), name, serializedEjsonArgs, serviceName, callback)
17211723
}
17221724

17231725
actual fun realm_app_call_reset_password_function(

packages/cinterop/src/nativeDarwin/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3262,6 +3262,7 @@ actual object RealmInterop {
32623262
app: RealmAppPointer,
32633263
user: RealmUserPointer,
32643264
name: String,
3265+
serviceName: String?,
32653266
serializedEjsonArgs: String,
32663267
callback: AppCallback<String>
32673268
) {
@@ -3270,7 +3271,7 @@ actual object RealmInterop {
32703271
user.cptr(),
32713272
name,
32723273
serializedEjsonArgs,
3273-
null,
3274+
serviceName,
32743275
staticCFunction { userData: CPointer<out CPointed>?, data: CPointer<ByteVarOf<Byte>>?, error: CPointer<realm_app_error_t>? ->
32753276
handleAppCallback(userData, error) {
32763277
data.safeKString()

packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/RealmInstantImpl.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ public fun RealmInstant.toDuration(): Duration {
3636
return epochSeconds.seconds + nanosecondsOfSecond.nanoseconds
3737
}
3838

39-
internal fun Duration.toRealmInstant(): RealmInstant {
39+
public fun Duration.toRealmInstant(): RealmInstant {
4040
val seconds: Long = this.inWholeSeconds
41-
val nanos: Duration = (this - seconds.seconds)
42-
return RealmInstant.from(seconds, nanos.inWholeNanoseconds.toInt())
41+
// We cannot do duration arithmetic as some operations on INFINITE and NEG_INFINITE will overflow
42+
val nanos: Int = (this.inWholeNanoseconds - (seconds * RealmInstant.SEC_AS_NANOSECOND)).toInt()
43+
return RealmInstant.from(seconds, nanos)
4344
}
4445

4546
internal fun RealmInstant.restrictToMillisPrecision() =
4647
toDuration().inWholeMilliseconds.milliseconds.toRealmInstant()
4748

48-
internal fun RealmInstant.asBsonDateTime() = BsonDateTime(toDuration().inWholeMilliseconds)
49+
public inline fun RealmInstant.asBsonDateTime(): BsonDateTime = BsonDateTime(toDuration().inWholeMilliseconds)
50+
public inline fun BsonDateTime.asRealmInstant(): RealmInstant = value.milliseconds.toRealmInstant()

packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/RealmObjectCompanion.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import kotlin.reflect.KProperty1
3030
public interface RealmObjectCompanion {
3131
public val `io_realm_kotlin_class`: KClass<out TypedRealmObject>
3232
public val `io_realm_kotlin_className`: String
33-
public val `io_realm_kotlin_fields`: Map<String, KProperty1<BaseRealmObject, Any?>>
33+
public val `io_realm_kotlin_fields`: Map<String, Pair<KClass<*>, KProperty1<BaseRealmObject, Any?>>>
3434
public val `io_realm_kotlin_primaryKey`: KMutableProperty1<*, *>?
3535
public val `io_realm_kotlin_classKind`: RealmClassKind
3636
public fun `io_realm_kotlin_schema`(): RealmClassImpl

packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/RealmObjectUtil.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,15 @@ internal fun <T : BaseRealmObject> RealmObjectReference<T>.toRealmObject(): T =
107107
* Returns the [RealmObjectCompanion] associated with a given [BaseRealmObject]'s [KClass].
108108
*/
109109
internal inline fun KClass<*>.realmObjectCompanionOrNull(): RealmObjectCompanion? {
110+
@Suppress("invisible_reference", "invisible_member")
110111
return realmObjectCompanionOrNull(this)
111112
}
112113

113114
/**
114115
* Returns the [RealmObjectCompanion] associated with a given [BaseRealmObject]'s [KClass].
115116
*/
116117
internal inline fun <reified T : BaseRealmObject> KClass<T>.realmObjectCompanionOrThrow(): RealmObjectCompanion {
118+
@Suppress("invisible_reference", "invisible_member")
117119
return realmObjectCompanionOrThrow(this)
118120
}
119121

packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/RealmUUIDImpl.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import io.realm.kotlin.internal.util.HEX_PATTERN
2121
import io.realm.kotlin.internal.util.parseHex
2222
import io.realm.kotlin.internal.util.toHexString
2323
import io.realm.kotlin.types.RealmUUID
24+
import org.mongodb.kbson.BsonBinary
25+
import org.mongodb.kbson.BsonBinarySubType
2426
import kotlin.experimental.and
2527
import kotlin.experimental.or
2628

@@ -101,3 +103,6 @@ public class RealmUUIDImpl : RealmUUID {
101103
}
102104
}
103105
}
106+
107+
public inline fun RealmUUID.asBsonBinary(): BsonBinary = BsonBinary(BsonBinarySubType.UUID_STANDARD, bytes)
108+
public inline fun BsonBinary.asRealmUUID(): RealmUUID = RealmUUID.from(data)

packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/platform/RealmObject.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ import kotlin.reflect.KClass
2525
* associated [RealmObjectCompanion], in which case the `clazz` wasn't a user defined class
2626
* implementing [BaseRealmObject] augmented by our compiler plugin.
2727
*/
28+
@PublishedApi
2829
internal expect fun <T : Any> realmObjectCompanionOrNull(clazz: KClass<T>): RealmObjectCompanion?
2930

3031
/**
3132
* Returns the [RealmObjectCompanion] associated with a given [BaseRealmObject]'s [KClass].
3233
*/
34+
35+
@PublishedApi
3336
internal expect fun <T : BaseRealmObject> realmObjectCompanionOrThrow(clazz: KClass<T>): RealmObjectCompanion

0 commit comments

Comments
 (0)