From 221df23cd9db4746655ae03f303b0465f1e64070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Thu, 2 Apr 2026 21:53:28 +0200 Subject: [PATCH] feat(driver-sync): Migrate to the new BSON hierarchy --- .../kotlin/operations/UpdateOperations.kt | 4 +- driver-sync/src/jvmMain/kotlin/JvmExt.kt | 5 +-- .../src/jvmMain/kotlin/JvmMongoCollection.kt | 38 +++++++++---------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/driver-sync/src/commonMain/kotlin/operations/UpdateOperations.kt b/driver-sync/src/commonMain/kotlin/operations/UpdateOperations.kt index 3fb414d4..c92ed12d 100644 --- a/driver-sync/src/commonMain/kotlin/operations/UpdateOperations.kt +++ b/driver-sync/src/commonMain/kotlin/operations/UpdateOperations.kt @@ -16,7 +16,7 @@ package opensavvy.ktmongo.sync.operations -import opensavvy.ktmongo.bson.BsonValueReader +import opensavvy.ktmongo.bson.BsonValue import opensavvy.ktmongo.dsl.LowLevelApi import opensavvy.ktmongo.dsl.command.BulkWrite import opensavvy.ktmongo.dsl.command.BulkWriteOptions @@ -472,7 +472,7 @@ interface UpdateOperations : BaseOperations { * @throws UnsupportedOperationException If the update was not [acknowledged]. */ @OptIn(LowLevelApi::class) - val upsertedId: BsonValueReader? + val upsertedId: BsonValue? /** * The number of upserted documents. diff --git a/driver-sync/src/jvmMain/kotlin/JvmExt.kt b/driver-sync/src/jvmMain/kotlin/JvmExt.kt index 17ac6686..ac13f1d3 100644 --- a/driver-sync/src/jvmMain/kotlin/JvmExt.kt +++ b/driver-sync/src/jvmMain/kotlin/JvmExt.kt @@ -16,8 +16,7 @@ package opensavvy.ktmongo.sync -import opensavvy.ktmongo.bson.Bson import org.bson.BsonDocument -internal fun Bson.toJava(): BsonDocument = - (this as opensavvy.ktmongo.bson.official.Bson).raw +internal fun opensavvy.ktmongo.bson.BsonDocument.toJava(): BsonDocument = + (this as opensavvy.ktmongo.bson.official.BsonDocument).raw diff --git a/driver-sync/src/jvmMain/kotlin/JvmMongoCollection.kt b/driver-sync/src/jvmMain/kotlin/JvmMongoCollection.kt index efa9cb81..ca75590f 100644 --- a/driver-sync/src/jvmMain/kotlin/JvmMongoCollection.kt +++ b/driver-sync/src/jvmMain/kotlin/JvmMongoCollection.kt @@ -19,8 +19,8 @@ package opensavvy.ktmongo.sync import com.mongodb.client.model.* import com.mongodb.client.model.ReplaceOptions import com.mongodb.client.model.UpdateOptions -import opensavvy.ktmongo.bson.BsonValueReader -import opensavvy.ktmongo.bson.official.JvmBsonFactory +import opensavvy.ktmongo.bson.BsonValue +import opensavvy.ktmongo.bson.official.BsonFactory import opensavvy.ktmongo.bson.official.types.Jvm import opensavvy.ktmongo.bson.types.ObjectId import opensavvy.ktmongo.bson.types.ObjectIdGenerator @@ -65,13 +65,13 @@ class JvmMongoCollection internal constructor( @LowLevelApi override val context = JvmBsonContext( - bsonFactory = JvmBsonFactory(inner.codecRegistry), + bsonFactory = BsonFactory(inner.codecRegistry), objectIdGenerator = ObjectIdGenerator.Jvm(), nameStrategy = nameStrategy, ) @OptIn(LowLevelApi::class) - private val inner = inner.withCodecRegistry(context.codecRegistry) + private val inner = inner.withCodecRegistry(context.bsonFactory.codecRegistry) @OptIn(LowLevelApi::class) override fun newId(): ObjectId = @@ -95,7 +95,7 @@ class JvmMongoCollection internal constructor( return JvmMongoIterable( inner.withReadConcern(model.options.readReadConcern()) .withReadPreference(model.options.readReadPreference()) - .find(context.buildDocument(model.filter).raw) + .find(context.bsonFactory.buildDocument(model.filter).raw) .limit(model.options.readLimit()) .skip(model.options.readSkip()) .maxTime(model.options.readMaxTimeMS().toLong(), TimeUnit.MILLISECONDS) @@ -121,7 +121,7 @@ class JvmMongoCollection internal constructor( model.filter.predicate() return inner.countDocuments( - context.buildDocument(model.filter).raw, + context.bsonFactory.buildDocument(model.filter).raw, model.options.toJava() ) } @@ -144,7 +144,7 @@ class JvmMongoCollection internal constructor( model.filter.filter() model.update.update() - val result = inner.withWriteConcern(model.options).updateMany(context.buildDocument(model.filter).raw, context.buildDocument(model.update).raw, UpdateOptions()) + val result = inner.withWriteConcern(model.options).updateMany(context.bsonFactory.buildDocument(model.filter).raw, context.bsonFactory.buildDocument(model.update).raw, UpdateOptions()) return JvmUpdateResult(result, context) } @@ -160,7 +160,7 @@ class JvmMongoCollection internal constructor( model.filter.filter() model.update.update() - val result = inner.withWriteConcern(model.options).updateOne(context.buildDocument(model.filter).raw, context.buildDocument(model.update).raw, UpdateOptions()) + val result = inner.withWriteConcern(model.options).updateOne(context.bsonFactory.buildDocument(model.filter).raw, context.bsonFactory.buildDocument(model.update).raw, UpdateOptions()) return JvmUpdateResult(result, context) } @@ -176,7 +176,7 @@ class JvmMongoCollection internal constructor( model.filter.filter() model.update.update() - val result = inner.withWriteConcern(model.options).updateOne(context.buildDocument(model.filter).raw, context.buildDocument(model.update).raw, UpdateOptions().upsert(true)) + val result = inner.withWriteConcern(model.options).updateOne(context.bsonFactory.buildDocument(model.filter).raw, context.bsonFactory.buildDocument(model.update).raw, UpdateOptions().upsert(true)) return JvmUpdateResult(result, context) } @@ -191,7 +191,7 @@ class JvmMongoCollection internal constructor( model.options.options() model.filter.filter() - inner.withWriteConcern(model.options).replaceOne(context.buildDocument(model.filter).raw, document, ReplaceOptions()) + inner.withWriteConcern(model.options).replaceOne(context.bsonFactory.buildDocument(model.filter).raw, document, ReplaceOptions()) } @OptIn(LowLevelApi::class) @@ -205,7 +205,7 @@ class JvmMongoCollection internal constructor( model.options.options() model.filter.filter() - inner.withWriteConcern(model.options).replaceOne(context.buildDocument(model.filter).raw, document, ReplaceOptions().upsert(true)) + inner.withWriteConcern(model.options).replaceOne(context.bsonFactory.buildDocument(model.filter).raw, document, ReplaceOptions().upsert(true)) } @OptIn(LowLevelApi::class) @@ -220,7 +220,7 @@ class JvmMongoCollection internal constructor( model.filter.filter() model.update.update() - return inner.withWriteConcern(model.options).findOneAndUpdate(context.buildDocument(model.filter).raw, context.buildDocument(model.update).raw, FindOneAndUpdateOptions()) + return inner.withWriteConcern(model.options).findOneAndUpdate(context.bsonFactory.buildDocument(model.filter).raw, context.bsonFactory.buildDocument(model.update).raw, FindOneAndUpdateOptions()) } @OptIn(LowLevelApi::class) @@ -255,7 +255,7 @@ class JvmMongoCollection internal constructor( model.filter.filter() model.update.update() - val result = inner.withWriteConcern(model.options).updateMany(context.buildDocument(model.filter).raw, model.updates.map { it.toJava() }, UpdateOptions()) + val result = inner.withWriteConcern(model.options).updateMany(context.bsonFactory.buildDocument(model.filter).raw, model.updates.map { it.toJava() }, UpdateOptions()) return JvmUpdateResult(result, context) } @@ -271,7 +271,7 @@ class JvmMongoCollection internal constructor( model.filter.filter() model.update.update() - val result = inner.withWriteConcern(model.options).updateOne(context.buildDocument(model.filter).raw, model.updates.map { it.toJava() }, UpdateOptions()) + val result = inner.withWriteConcern(model.options).updateOne(context.bsonFactory.buildDocument(model.filter).raw, model.updates.map { it.toJava() }, UpdateOptions()) return JvmUpdateResult(result, context) } @@ -287,7 +287,7 @@ class JvmMongoCollection internal constructor( model.filter.filter() model.update.update() - val result = inner.withWriteConcern(model.options).updateOne(context.buildDocument(model.filter).raw, model.updates.map { it.toJava() }, UpdateOptions().upsert(true)) + val result = inner.withWriteConcern(model.options).updateOne(context.bsonFactory.buildDocument(model.filter).raw, model.updates.map { it.toJava() }, UpdateOptions().upsert(true)) return JvmUpdateResult(result, context) } @@ -332,7 +332,7 @@ class JvmMongoCollection internal constructor( model.options.options() inner.withWriteConcern(model.options).deleteOne( - filter = context.buildDocument(model.filter).raw, + filter = context.bsonFactory.buildDocument(model.filter).raw, options = DeleteOptions() ) } @@ -348,7 +348,7 @@ class JvmMongoCollection internal constructor( model.options.options() inner.withWriteConcern(model.options).deleteOne( - filter = context.buildDocument(model.filter).raw, + filter = context.bsonFactory.buildDocument(model.filter).raw, options = DeleteOptions() ) } @@ -418,8 +418,8 @@ private class JvmUpdateResult( get() = inner.modifiedCount @OptIn(LowLevelApi::class) - override val upsertedId: BsonValueReader? - get() = inner.upsertedId?.let { context.readValue(it) } + override val upsertedId: BsonValue? + get() = inner.upsertedId?.let { context.bsonFactory.readValue(it) } override val upsertedCount: Int get() = if (inner.upsertedId == null) 0 else 1 -- 2.51.2