-
Notifications
You must be signed in to change notification settings - Fork 57
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
Functions support #1110
Functions support #1110
Conversation
# Conflicts: # CHANGELOG.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks way nicer now 🎉 ... I am just not landed on whether it makes sense to have the public API with both T
and the KType
🤔
Further, there is also missing some tests when arguments and return value cannot be encoded and decoded with the default BsonEncoder.
packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/RealmInstantImpl.kt
Outdated
Show resolved
Hide resolved
* | ||
* @throws FunctionExecutionException if the function failed in some way. | ||
*/ | ||
public suspend fun <T> call( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit annoying that we cannot somehow tie the T
with resultType
... Since there is no way to get the KType
from a class at runtime, then there is no use cases for this method besides being called from the inlined one. Should we rather internalize this method then 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also a bit funny to have the generic parameter throughout the BsonConverter.decodeFromBsonValue
but maybe it is ok 🤔 ... But if we keep the T
along with a KType
that is not bound to be the same then we should definitely be very explicit about that it will throw a ClassCastException
if they don't match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't think it thoughtfully. Yes, we might like to internalize the method. And yes, the T value doesn't make sense in the BsonEncoder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it internal and accessible to the extension function via de @PublishedApi
annotation.
packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/BsonEncoder.kt
Outdated
Show resolved
Hide resolved
...androidAndroidTest/kotlin/io/realm/kotlin/test/mongodb/shared/serializer/BsonEncoderTests.kt
Outdated
Show resolved
Hide resolved
...androidAndroidTest/kotlin/io/realm/kotlin/test/mongodb/shared/serializer/BsonEncoderTests.kt
Outdated
Show resolved
Hide resolved
|
||
@Test | ||
fun decodeFromBsonElement_throwsWrongType() { | ||
(wrongPrimitiveAsserters + wrongRealmValueAsserters).forEach { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing serious, but since we don't really uses these variables elsewhere we could maybe just define them locally in the method. Also a bit hard to track because you need to look up the DecoderAsserter
class to understand it. Why not just use a Triple
and have all the logic here and then destruct them into named variables to that it was easier to follow. Anyway, nothing critical 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The asserters data structure has 4 parameters and is being reused in several tests.
Yes, we could use a Triple
because not all parameters are used in every test, but it would mean that we would have to define multiple similar datasets in several tests..
...est-sync/src/androidAndroidTest/kotlin/io/realm/kotlin/test/mongodb/shared/FunctionsTests.kt
Show resolved
Hide resolved
...est-sync/src/androidAndroidTest/kotlin/io/realm/kotlin/test/mongodb/shared/FunctionsTests.kt
Show resolved
Hide resolved
packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/Functions.kt
Outdated
Show resolved
Hide resolved
packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/Functions.kt
Outdated
Show resolved
Hide resolved
…ternal/RealmInstantImpl.kt Co-authored-by: Claus Rørbech <claus.rorbech@mongodb.com>
…ngodb/internal/BsonEncoder.kt Co-authored-by: Claus Rørbech <claus.rorbech@mongodb.com>
…ngodb/Functions.kt Co-authored-by: Christian Melchior <christian@ilios.dk>
… ct/app-functions # Conflicts: # packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/BsonEncoder.kt
packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/BsonEncoder.kt
Outdated
Show resolved
Hide resolved
packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/ext/FunctionsExt.kt
Show resolved
Hide resolved
…ngodb/internal/BsonEncoder.kt Co-authored-by: Christian Melchior <christian@ilios.dk>
# Conflicts: # CHANGELOG.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Only some minor comments ... and then of course CI 😬 Seems to fail due to asserting on class names that are obfuscated. Either remove the actual class name in the expected methods or maybe add keep
the specific classes for testing purposes, just as the other rules in https://github.com/realm/realm-kotlin/blob/main/packages/test-base/proguard-rules-test.pro
packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/BsonEncoder.kt
Outdated
Show resolved
Hide resolved
...est-sync/src/androidAndroidTest/kotlin/io/realm/kotlin/test/mongodb/shared/FunctionsTests.kt
Outdated
Show resolved
Hide resolved
...est-sync/src/androidAndroidTest/kotlin/io/realm/kotlin/test/mongodb/shared/FunctionsTests.kt
Outdated
Show resolved
Hide resolved
…ngodb/internal/BsonEncoder.kt Co-authored-by: Claus Rørbech <claus.rorbech@mongodb.com>
App function support
Add support for authenticated users to invoke App Services Application functions via the SDK.
Due to the serialization engine does not support third-party libraries yet, there are some limitations in what types can be used as arguments and return types:
Bson
, lists, and maps are valid argument types.Bson
types.These limitations would be lifted once the
Kserializer
decoder for third-party libraries becomes stable.The current implementation of the
Ejson
decoder does a case-by-case decoding based on thedeserializationStrategy
used. This would allow us to avoid future breaking changes, as it uses the same function signatures that we would be using in the future.Pending
kbson
stable version.Depends on