-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Docs blocks and @SurrealDbOnlyApi to 'kill'
- Loading branch information
Showing
10 changed files
with
146 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/commonMain/kotlin/uk/gibby/driver/annotation/SurrealDbNightlyOnlyApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package uk.gibby.driver.annotation | ||
|
||
@RequiresOptIn(message = "This function is only available while using nightly builds of SurrealDB. See https://surrealdb.com/docs/installation/nightly.") | ||
@Target(AnnotationTarget.FUNCTION) | ||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class SurrealDbNightlyOnlyApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/commonMain/kotlin/uk/gibby/driver/model/rpc/LiveQueryActionSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package uk.gibby.driver.model.rpc | ||
|
||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.SerializationException | ||
import kotlinx.serialization.builtins.serializer | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.descriptors.buildClassSerialDescriptor | ||
import kotlinx.serialization.encoding.CompositeDecoder | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
import uk.gibby.driver.model.Thing | ||
import uk.gibby.driver.model.ThingSerializer | ||
|
||
class LiveQueryActionSerializer<T: Any>(private val resultSerializer: KSerializer<T>): KSerializer<LiveQueryAction<T>> { | ||
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("LiveQueryAction") { | ||
element("action", String.serializer().descriptor) | ||
element("id", String.serializer().descriptor) | ||
element("result", resultSerializer.descriptor) | ||
} | ||
|
||
override fun deserialize(decoder: Decoder): LiveQueryAction<T> { | ||
val input = decoder.beginStructure(descriptor) | ||
var action: String? = null | ||
var id: String? = null | ||
var result: Thing<T>? = null | ||
loop@ while (true) { | ||
when (val i = input.decodeElementIndex(descriptor)) { | ||
CompositeDecoder.DECODE_DONE -> break@loop | ||
0 -> action = input.decodeStringElement(descriptor, i) | ||
1 -> id = input.decodeStringElement(descriptor, i) | ||
2 -> result = input.decodeSerializableElement(descriptor, i, ThingSerializer(resultSerializer)) | ||
else -> throw SerializationException("Unknown index $i") | ||
} | ||
} | ||
input.endStructure(descriptor) | ||
if (action == null || id == null || result == null) throw SerializationException("Missing fields") | ||
return when(action) { | ||
"CREATE" -> LiveQueryAction.Create(id, (result as Thing.Record<T>).result) | ||
"UPDATE" -> LiveQueryAction.Update(id, (result as Thing.Record<T>).result) | ||
"DELETE" -> LiveQueryAction.Delete(id, (result as Thing.Reference).id) | ||
else -> throw SerializationException("Unknown action $action") | ||
} | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: LiveQueryAction<T>) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters