Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
clementetb committed Jun 27, 2024
1 parent ed2c8f4 commit f83118f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ import io.realm.kotlin.test.mongodb.TEST_APP_CLUSTER_NAME
import io.realm.kotlin.types.BaseRealmObject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.json.ClassDiscriminatorMode
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
Expand All @@ -73,7 +75,11 @@ import kotlin.reflect.KClass
private const val ADMIN_PATH = "/api/admin/v3.0"
private const val PRIVATE_PATH = "/api/private/v1.0"

private val JsonDefaults: Json = Json { encodeDefaults = true }
@OptIn(ExperimentalSerializationApi::class)
private val json = Json {
classDiscriminatorMode = ClassDiscriminatorMode.NONE
encodeDefaults = true
}

data class SyncPermissions(
val read: Boolean,
Expand Down Expand Up @@ -142,20 +148,18 @@ data class Schema(
val schema: SchemaData,
val relationships: Map<String, SchemaRelationship> = emptyMap(),
) {
companion object {
fun create(
database: String,
schema: SchemaData,
relationships: Map<String, SchemaRelationship>
) = Schema(
metadata = SchemaMetadata(
database = database,
collection = schema.title
),
schema = schema,
relationships = relationships
)
}
constructor(
database: String,
schema: SchemaData,
relationships: Map<String, SchemaRelationship>,
) : this(
metadata = SchemaMetadata(
database = database,
collection = schema.title
),
schema = schema,
relationships = relationships
)
}

@Serializable
Expand All @@ -168,16 +172,26 @@ data class SchemaMetadata(

@Serializable
data class SchemaRelationship(
@Transient val target: String = "",
@Transient val database: String = "",
@SerialName("source_key")
val sourceKey: String,
@SerialName("foreign_key")
val foreignKey: String,
@SerialName("is_list")
val isList: Boolean
val isList: Boolean,
val ref: String = "",
) {
val ref: String = "#/relationship/BackingDB/$database/$target"
constructor(
target: String,
database: String,
sourceKey: String,
foreignKey: String,
isList: Boolean,
) : this(
sourceKey = sourceKey,
foreignKey = foreignKey,
isList = isList,
ref = "#/relationship/BackingDB/$database/$target"
)
}

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SchemaProcessor private constructor(
.filterNot { (_, schema) -> schema.kind == RealmClassKind.EMBEDDED }
.associate { (name, schema) ->
// add metadata
name to Schema.create(
name to Schema(
databaseName,
schema,
processor.processedRelationships[name]!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import io.realm.kotlin.test.mongodb.TEST_APP_PARTITION
import io.realm.kotlin.test.mongodb.common.FLEXIBLE_SYNC_SCHEMA
import io.realm.kotlin.test.mongodb.common.PARTITION_BASED_SCHEMA
import kotlinx.coroutines.delay
import kotlinx.serialization.json.ClassDiscriminatorMode
import kotlinx.serialization.json.Json

interface AppInitializer {
Expand Down Expand Up @@ -158,7 +157,8 @@ suspend fun AppServicesClient.initializeFlexibleSync(
"name",
"section",
"stringField",
"location"
"location",
"selector"
],
"asymmetric_tables": [
"AsymmetricA",
Expand All @@ -170,11 +170,6 @@ suspend fun AppServicesClient.initializeFlexibleSync(
)
}

val json = Json {
classDiscriminatorMode = ClassDiscriminatorMode.NONE
encodeDefaults = true
}

@Suppress("LongMethod")
suspend fun AppServicesClient.initializePartitionSync(
app: BaasApp,
Expand Down

0 comments on commit f83118f

Please sign in to comment.