diff --git a/README.md b/README.md index 47342ceb0..ede0080eb 100644 --- a/README.md +++ b/README.md @@ -196,12 +196,12 @@ documentRef.updateFields { // Set the value of otherField to "1" using a custom Serializer "otherField".to(IntAsStringSerializer(), 1) - // Overwrite build settings. All fields added after this will have these build settings applied - encodeNextWith { + // Overwrite build settings. All fields added within this block will have these build settings applied + withEncodeSettings { encodeDefaults = true serializersModule = module + "city" to abstractCity } - "city" to abstractCity } ``` @@ -214,12 +214,12 @@ query.orderBy("field", "otherField", "city").startAtFieldValues { // similar syn // Starts at "1" for the otherField value add(1, IntAsStringSerializer()) - // Overwrite build settings. All field values added after this will have these build settings applied - encodeNextWith { + // Overwrite build settings. All field values added within this block will have these build settings applied + withEncodeSettings { encodeDefaults = true serializersModule = module + add(abstractCity) } - add(abstractCity) } ``` diff --git a/firebase-common/api/android/firebase-common.api b/firebase-common/api/android/firebase-common.api index 14df6bc61..789d376fd 100644 --- a/firebase-common/api/android/firebase-common.api +++ b/firebase-common/api/android/firebase-common.api @@ -13,6 +13,11 @@ public abstract interface class dev/gitlive/firebase/EncodeDecodeSettings { public abstract interface class dev/gitlive/firebase/EncodeDecodeSettingsBuilder : dev/gitlive/firebase/DecodeSettings$Builder, dev/gitlive/firebase/EncodeSettings$Builder { } +public final class dev/gitlive/firebase/EncodeDecodeSettingsKt { + public static final fun copyFrom (Ldev/gitlive/firebase/DecodeSettings$Builder;Ldev/gitlive/firebase/DecodeSettings$Builder;)V + public static final fun copyFrom (Ldev/gitlive/firebase/EncodeSettings$Builder;Ldev/gitlive/firebase/EncodeSettings$Builder;)V +} + public abstract interface class dev/gitlive/firebase/EncodeSettings : dev/gitlive/firebase/EncodeDecodeSettings { public abstract fun getEncodeDefaults ()Z } diff --git a/firebase-common/api/jvm/firebase-common.api b/firebase-common/api/jvm/firebase-common.api index 14df6bc61..789d376fd 100644 --- a/firebase-common/api/jvm/firebase-common.api +++ b/firebase-common/api/jvm/firebase-common.api @@ -13,6 +13,11 @@ public abstract interface class dev/gitlive/firebase/EncodeDecodeSettings { public abstract interface class dev/gitlive/firebase/EncodeDecodeSettingsBuilder : dev/gitlive/firebase/DecodeSettings$Builder, dev/gitlive/firebase/EncodeSettings$Builder { } +public final class dev/gitlive/firebase/EncodeDecodeSettingsKt { + public static final fun copyFrom (Ldev/gitlive/firebase/DecodeSettings$Builder;Ldev/gitlive/firebase/DecodeSettings$Builder;)V + public static final fun copyFrom (Ldev/gitlive/firebase/EncodeSettings$Builder;Ldev/gitlive/firebase/EncodeSettings$Builder;)V +} + public abstract interface class dev/gitlive/firebase/EncodeSettings : dev/gitlive/firebase/EncodeDecodeSettings { public abstract fun getEncodeDefaults ()Z } diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt index d73b9ede0..23f8456cc 100644 --- a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt +++ b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt @@ -27,6 +27,11 @@ public interface EncodeSettings : EncodeDecodeSettings { } } +public fun EncodeSettings.Builder.copyFrom(other: EncodeSettings.Builder) { + encodeDefaults = other.encodeDefaults + serializersModule = other.serializersModule +} + /** * [EncodeDecodeSettings] used when decoding an object * @param serializersModule the [SerializersModule] to use for deserialization. This allows for polymorphic serialization on runtime @@ -38,6 +43,10 @@ public interface DecodeSettings : EncodeDecodeSettings { } } +public fun DecodeSettings.Builder.copyFrom(other: DecodeSettings.Builder) { + serializersModule = other.serializersModule +} + public interface EncodeDecodeSettingsBuilder : EncodeSettings.Builder, DecodeSettings.Builder diff --git a/firebase-firestore/api/android/firebase-firestore.api b/firebase-firestore/api/android/firebase-firestore.api index f843fe52a..f446276bd 100644 --- a/firebase-firestore/api/android/firebase-firestore.api +++ b/firebase-firestore/api/android/firebase-firestore.api @@ -169,22 +169,27 @@ public final class dev/gitlive/firebase/firestore/FieldValueSerializer : kotlinx public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V } -public final class dev/gitlive/firebase/firestore/FieldValuesDSL { - public final fun addEncoded (Ljava/lang/Object;)V +public final class dev/gitlive/firebase/firestore/FieldValuesDSL : dev/gitlive/firebase/EncodeSettings$Builder { public final fun addWithStrategy (Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V - public final fun encodeNextWith (Lkotlin/jvm/functions/Function1;)V - public final fun getEncodeNextWith ()Lkotlin/jvm/functions/Function1; - public final fun setEncodeNextWith (Lkotlin/jvm/functions/Function1;)V -} - -public final class dev/gitlive/firebase/firestore/FieldsAndValuesUpdateDSL { - public final fun encodeNextWith (Lkotlin/jvm/functions/Function1;)V - public final fun getEncodeNextWith ()Lkotlin/jvm/functions/Function1; - public final fun setEncodeNextWith (Lkotlin/jvm/functions/Function1;)V + public fun getEncodeDefaults ()Z + public final fun getFieldValuesToAdd ()Ljava/util/List; + public fun getSerializersModule ()Lkotlinx/serialization/modules/SerializersModule; + public fun setEncodeDefaults (Z)V + public fun setSerializersModule (Lkotlinx/serialization/modules/SerializersModule;)V + public final fun withEncodeSettings (Lkotlin/jvm/functions/Function1;)V +} + +public final class dev/gitlive/firebase/firestore/FieldsAndValuesUpdateDSL : dev/gitlive/firebase/EncodeSettings$Builder { + public fun getEncodeDefaults ()Z + public final fun getFieldAndValueToAdd ()Ljava/util/List; + public fun getSerializersModule ()Lkotlinx/serialization/modules/SerializersModule; + public fun setEncodeDefaults (Z)V + public fun setSerializersModule (Lkotlinx/serialization/modules/SerializersModule;)V public final fun to (Ldev/gitlive/firebase/firestore/FieldPath;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V public final fun to (Ljava/lang/String;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V - public final fun toEncoded (Ldev/gitlive/firebase/firestore/FieldPath;Ljava/lang/Object;)V - public final fun toEncoded (Ljava/lang/String;Ljava/lang/Object;)V + public final fun toEncoded (Ldev/gitlive/firebase/firestore/FieldPath;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/internal/FieldAndValue$WithFieldPath; + public final fun toEncoded (Ljava/lang/String;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/internal/FieldAndValue$WithStringField; + public final fun withEncodeSettings (Lkotlin/jvm/functions/Function1;)V } public abstract class dev/gitlive/firebase/firestore/Filter { @@ -232,7 +237,7 @@ public abstract class dev/gitlive/firebase/firestore/Filter$WithConstraint : dev public abstract fun getConstraint ()Ldev/gitlive/firebase/firestore/WhereConstraint; } -public final class dev/gitlive/firebase/firestore/FilterBuilder { +public final class dev/gitlive/firebase/firestore/FilterBuilder : dev/gitlive/firebase/EncodeSettings$Builder { public final fun all ([Ldev/gitlive/firebase/firestore/Filter;)Ldev/gitlive/firebase/firestore/Filter; public final fun and (Ldev/gitlive/firebase/firestore/Filter;Ldev/gitlive/firebase/firestore/Filter;)Ldev/gitlive/firebase/firestore/Filter$And; public final fun any ([Ldev/gitlive/firebase/firestore/Filter;)Ldev/gitlive/firebase/firestore/Filter; @@ -240,10 +245,11 @@ public final class dev/gitlive/firebase/firestore/FilterBuilder { public final fun contains (Ljava/lang/String;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun containsAny (Ldev/gitlive/firebase/firestore/FieldPath;Lkotlinx/serialization/SerializationStrategy;Ljava/util/List;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun containsAny (Ljava/lang/String;Lkotlinx/serialization/SerializationStrategy;Ljava/util/List;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; - public final fun encodeNextWith (Lkotlin/jvm/functions/Function1;)V public final fun equalTo (Ldev/gitlive/firebase/firestore/FieldPath;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun equalTo (Ljava/lang/String;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; - public final fun getEncodeNextWith ()Lkotlin/jvm/functions/Function1; + public fun getEncodeDefaults ()Z + public final fun getEncodeSettingsBuilder ()Lkotlin/jvm/functions/Function1; + public fun getSerializersModule ()Lkotlinx/serialization/modules/SerializersModule; public final fun greaterThan (Ldev/gitlive/firebase/firestore/FieldPath;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun greaterThan (Ljava/lang/String;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun greaterThanOrEqualTo (Ldev/gitlive/firebase/firestore/FieldPath;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; @@ -263,7 +269,9 @@ public final class dev/gitlive/firebase/firestore/FilterBuilder { public final fun notInArray (Ldev/gitlive/firebase/firestore/FieldPath;Lkotlinx/serialization/SerializationStrategy;Ljava/util/List;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun notInArray (Ljava/lang/String;Lkotlinx/serialization/SerializationStrategy;Ljava/util/List;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun or (Ldev/gitlive/firebase/firestore/Filter;Ldev/gitlive/firebase/firestore/Filter;)Ldev/gitlive/firebase/firestore/Filter$Or; - public final fun setEncodeNextWith (Lkotlin/jvm/functions/Function1;)V + public fun setEncodeDefaults (Z)V + public fun setSerializersModule (Lkotlinx/serialization/modules/SerializersModule;)V + public final fun withEncoder (Lkotlin/jvm/functions/Function1;)Ldev/gitlive/firebase/firestore/Filter; } public final class dev/gitlive/firebase/firestore/FirebaseFirestore { diff --git a/firebase-firestore/api/jvm/firebase-firestore.api b/firebase-firestore/api/jvm/firebase-firestore.api index 3f1d200c4..5b6bc21df 100644 --- a/firebase-firestore/api/jvm/firebase-firestore.api +++ b/firebase-firestore/api/jvm/firebase-firestore.api @@ -169,22 +169,27 @@ public final class dev/gitlive/firebase/firestore/FieldValueSerializer : kotlinx public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V } -public final class dev/gitlive/firebase/firestore/FieldValuesDSL { - public final fun addEncoded (Ljava/lang/Object;)V +public final class dev/gitlive/firebase/firestore/FieldValuesDSL : dev/gitlive/firebase/EncodeSettings$Builder { public final fun addWithStrategy (Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V - public final fun encodeNextWith (Lkotlin/jvm/functions/Function1;)V - public final fun getEncodeNextWith ()Lkotlin/jvm/functions/Function1; - public final fun setEncodeNextWith (Lkotlin/jvm/functions/Function1;)V -} - -public final class dev/gitlive/firebase/firestore/FieldsAndValuesUpdateDSL { - public final fun encodeNextWith (Lkotlin/jvm/functions/Function1;)V - public final fun getEncodeNextWith ()Lkotlin/jvm/functions/Function1; - public final fun setEncodeNextWith (Lkotlin/jvm/functions/Function1;)V + public fun getEncodeDefaults ()Z + public final fun getFieldValuesToAdd ()Ljava/util/List; + public fun getSerializersModule ()Lkotlinx/serialization/modules/SerializersModule; + public fun setEncodeDefaults (Z)V + public fun setSerializersModule (Lkotlinx/serialization/modules/SerializersModule;)V + public final fun withEncodeSettings (Lkotlin/jvm/functions/Function1;)V +} + +public final class dev/gitlive/firebase/firestore/FieldsAndValuesUpdateDSL : dev/gitlive/firebase/EncodeSettings$Builder { + public fun getEncodeDefaults ()Z + public final fun getFieldAndValueToAdd ()Ljava/util/List; + public fun getSerializersModule ()Lkotlinx/serialization/modules/SerializersModule; + public fun setEncodeDefaults (Z)V + public fun setSerializersModule (Lkotlinx/serialization/modules/SerializersModule;)V public final fun to (Ldev/gitlive/firebase/firestore/FieldPath;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V public final fun to (Ljava/lang/String;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V - public final fun toEncoded (Ldev/gitlive/firebase/firestore/FieldPath;Ljava/lang/Object;)V - public final fun toEncoded (Ljava/lang/String;Ljava/lang/Object;)V + public final fun toEncoded (Ldev/gitlive/firebase/firestore/FieldPath;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/internal/FieldAndValue$WithFieldPath; + public final fun toEncoded (Ljava/lang/String;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/internal/FieldAndValue$WithStringField; + public final fun withEncodeSettings (Lkotlin/jvm/functions/Function1;)V } public abstract class dev/gitlive/firebase/firestore/Filter { @@ -232,7 +237,7 @@ public abstract class dev/gitlive/firebase/firestore/Filter$WithConstraint : dev public abstract fun getConstraint ()Ldev/gitlive/firebase/firestore/WhereConstraint; } -public final class dev/gitlive/firebase/firestore/FilterBuilder { +public final class dev/gitlive/firebase/firestore/FilterBuilder : dev/gitlive/firebase/EncodeSettings$Builder { public final fun all ([Ldev/gitlive/firebase/firestore/Filter;)Ldev/gitlive/firebase/firestore/Filter; public final fun and (Ldev/gitlive/firebase/firestore/Filter;Ldev/gitlive/firebase/firestore/Filter;)Ldev/gitlive/firebase/firestore/Filter$And; public final fun any ([Ldev/gitlive/firebase/firestore/Filter;)Ldev/gitlive/firebase/firestore/Filter; @@ -240,10 +245,11 @@ public final class dev/gitlive/firebase/firestore/FilterBuilder { public final fun contains (Ljava/lang/String;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun containsAny (Ldev/gitlive/firebase/firestore/FieldPath;Lkotlinx/serialization/SerializationStrategy;Ljava/util/List;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun containsAny (Ljava/lang/String;Lkotlinx/serialization/SerializationStrategy;Ljava/util/List;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; - public final fun encodeNextWith (Lkotlin/jvm/functions/Function1;)V public final fun equalTo (Ldev/gitlive/firebase/firestore/FieldPath;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun equalTo (Ljava/lang/String;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; - public final fun getEncodeNextWith ()Lkotlin/jvm/functions/Function1; + public fun getEncodeDefaults ()Z + public final fun getEncodeSettingsBuilder ()Lkotlin/jvm/functions/Function1; + public fun getSerializersModule ()Lkotlinx/serialization/modules/SerializersModule; public final fun greaterThan (Ldev/gitlive/firebase/firestore/FieldPath;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun greaterThan (Ljava/lang/String;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun greaterThanOrEqualTo (Ldev/gitlive/firebase/firestore/FieldPath;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; @@ -263,7 +269,9 @@ public final class dev/gitlive/firebase/firestore/FilterBuilder { public final fun notInArray (Ldev/gitlive/firebase/firestore/FieldPath;Lkotlinx/serialization/SerializationStrategy;Ljava/util/List;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun notInArray (Ljava/lang/String;Lkotlinx/serialization/SerializationStrategy;Ljava/util/List;)Ldev/gitlive/firebase/firestore/Filter$WithConstraint; public final fun or (Ldev/gitlive/firebase/firestore/Filter;Ldev/gitlive/firebase/firestore/Filter;)Ldev/gitlive/firebase/firestore/Filter$Or; - public final fun setEncodeNextWith (Lkotlin/jvm/functions/Function1;)V + public fun setEncodeDefaults (Z)V + public fun setSerializersModule (Lkotlinx/serialization/modules/SerializersModule;)V + public final fun withEncoder (Lkotlin/jvm/functions/Function1;)Ldev/gitlive/firebase/firestore/Filter; } public final class dev/gitlive/firebase/firestore/FirebaseFirestore { diff --git a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldValuesDSL.kt b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldValuesDSL.kt index d2f119641..570a3ea90 100644 --- a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldValuesDSL.kt +++ b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldValuesDSL.kt @@ -1,58 +1,60 @@ package dev.gitlive.firebase.firestore import dev.gitlive.firebase.EncodeSettings +import dev.gitlive.firebase.copyFrom import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.modules.EmptySerializersModule +import kotlinx.serialization.modules.SerializersModule /** * A builder for generating the field values of a [Query]. * The order of the field values must match the order by clauses of the [Query] */ -public class FieldValuesDSL internal constructor() { +public class FieldValuesDSL internal constructor() : EncodeSettings.Builder { - internal val fieldValues: MutableList = mutableListOf() + override var encodeDefaults: Boolean = true + override var serializersModule: SerializersModule = EmptySerializersModule() @PublishedApi - internal var encodeNextWith: EncodeSettings.Builder.() -> Unit = { - encodeDefaults = true - } - - /** - * Sets the [EncodeSettings.Builder] to apply to the next field values added. - * Updating this value will only influence the encoding of field values not yet added to the update. - * This allows for custom encoding per value, e.g. - * - * ``` - * encodeNextWith { encodeDefaults = true } - * add(ClassWithDefaults()) - * encodeNextWith { encodeDefaults = false } - * add(ClassWithDefaults()) - * ``` - */ - public fun encodeNextWith(builder: EncodeSettings.Builder.() -> Unit) { - encodeNextWith = builder + internal val fieldValuesToAdd: MutableList<() -> Any> = mutableListOf() + internal val fieldValues = fieldValuesToAdd.map { valueToEncode -> + valueToEncode.invoke() } /** * Adds a field value to the [Query] + * The [value] will be encoded according to the [EncodeSettings] set by this builder. * @param T the type of the value to add * @param value the value [T] to add */ public inline fun add(value: T) { - addEncoded(encode(value, encodeNextWith)!!) + fieldValuesToAdd.add { + encode(value, { copyFrom(this@FieldValuesDSL) })!! + } } /** * Adds a field value to the [Query] + * The [value] will be encoded according to the [EncodeSettings] set by this builder. * @param T the type of the value to add * @param strategy the [SerializationStrategy] to apply to the value * @param value the value [T] to add */ public fun addWithStrategy(strategy: SerializationStrategy, value: T) { - addEncoded(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)!!) + fieldValuesToAdd.add { + dev.gitlive.firebase.internal.encode(strategy, value, { copyFrom(this@FieldValuesDSL) })!! + } } - @PublishedApi - internal fun addEncoded(encodedValue: Any) { - fieldValues += encodedValue + /** + * Provides an accessor for encoding values with [EncodeSettings] + * @param dls the [FieldValuesDSL] to specify the [EncodeSettings] and values to add + */ + public fun withEncodeSettings(dls: FieldValuesDSL.() -> Unit) { + fieldValuesToAdd.addAll( + FieldValuesDSL() + .apply { copyFrom(this@FieldValuesDSL) } + .apply(dls).fieldValuesToAdd, + ) } } diff --git a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldsAndValuesUpdateDSL.kt b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldsAndValuesUpdateDSL.kt index a1280c6fb..939ccbba3 100644 --- a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldsAndValuesUpdateDSL.kt +++ b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldsAndValuesUpdateDSL.kt @@ -1,8 +1,11 @@ package dev.gitlive.firebase.firestore import dev.gitlive.firebase.EncodeSettings +import dev.gitlive.firebase.copyFrom import dev.gitlive.firebase.firestore.internal.FieldAndValue import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.modules.EmptySerializersModule +import kotlinx.serialization.modules.SerializersModule /** * A builder for generating a collection of updates to a document. @@ -11,84 +14,91 @@ import kotlinx.serialization.SerializationStrategy * * ``` * val update: FieldsAndValuesUpdateBuilder.() -> Unit = { - * buildSettings = { encodeDefaults = false } - * * "path" to 1 * FieldPath("subpath", "field") to "value" * "otherPath".to(strategy, value) * } * ``` */ -public class FieldsAndValuesUpdateDSL internal constructor() { +public class FieldsAndValuesUpdateDSL internal constructor() : EncodeSettings.Builder { - internal val fieldAndValues: MutableList = mutableListOf() + override var encodeDefaults: Boolean = true + override var serializersModule: SerializersModule = EmptySerializersModule() @PublishedApi - internal var encodeNextWith: EncodeSettings.Builder.() -> Unit = { - encodeDefaults = true - } - - /** - * Sets the [EncodeSettings.Builder] to apply to the next values added to this update. - * Updating this value will only influence the encoding of values not yet added to the update. - * This allows for custom encoding per update, e.g. - * - * ``` - * encodeNextWith { encodeDefaults = true } - * "path" to ClassWithDefaults() - * encodeNextWith { encodeDefaults = false } - * "otherPath" to ClassWithDefaults() - * ``` - */ - public fun encodeNextWith(builder: EncodeSettings.Builder.() -> Unit) { - encodeNextWith = builder + internal val fieldAndValueToAdd: MutableList<() -> FieldAndValue> = mutableListOf() + internal val fieldsAndValues = fieldAndValueToAdd.map { fieldAndValueToEncode -> + fieldAndValueToEncode.invoke() } /** * Updates the field represented by a String to a given value + * The [value] will be encoded according to the [EncodeSettings] set by this builder. * @param T the type of the value * @param value the value [T] to update to */ public inline infix fun String.to(value: T) { - toEncoded(encode(value, encodeNextWith)) + fieldAndValueToAdd.add { + toEncoded(encode(value, { copyFrom(this@FieldsAndValuesUpdateDSL) })) + } } /** * Updates a [FieldPath] to a given value + * The [value] will be encoded according to the [EncodeSettings] set by this builder. * @param T the type of the value * @param value the value [T] to update to */ public inline infix fun FieldPath.to(value: T) { - toEncoded(encode(value, encodeNextWith)) + fieldAndValueToAdd.add { + toEncoded(encode(value, { copyFrom(this@FieldsAndValuesUpdateDSL) })) + } } /** * Updates the field represented by a String to a given value + * The [value] will be encoded according to the [EncodeSettings] set by this builder. * @param T the type of the value * @param strategy the [SerializationStrategy] to apply to the value * @param value the value [T] to update to */ public fun String.to(strategy: SerializationStrategy, value: T) { - toEncoded(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)) + fieldAndValueToAdd.add { + toEncoded(dev.gitlive.firebase.internal.encode(strategy, value, { copyFrom(this@FieldsAndValuesUpdateDSL) })) + } } /** * Updates a [FieldPath] to a given value + * The [value] will be encoded according to the [EncodeSettings] set by this builder. * @param T the type of the value * @param strategy the [SerializationStrategy] to apply to the value * @param value the value [T] to update to */ public fun FieldPath.to(strategy: SerializationStrategy, value: T) { - toEncoded(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)) + fieldAndValueToAdd.add { + toEncoded(dev.gitlive.firebase.internal.encode(strategy, value, { copyFrom(this@FieldsAndValuesUpdateDSL) })) + } } - @PublishedApi - internal fun String.toEncoded(encodedValue: Any?) { - fieldAndValues += FieldAndValue.WithStringField(this, encodedValue) + /** + * Provides an accessor for encoding values with [EncodeSettings] + * @param dls the [WithEncoder] to specify the [EncodeSettings] and values to add + */ + public fun withEncodeSettings(dls: FieldsAndValuesUpdateDSL.() -> Unit) { + fieldAndValueToAdd.addAll( + FieldsAndValuesUpdateDSL() + .apply { copyFrom(this@FieldsAndValuesUpdateDSL) } + .apply(dls) + .fieldAndValueToAdd, + ) } @PublishedApi - internal fun FieldPath.toEncoded(encodedValue: Any?) { - fieldAndValues += FieldAndValue.WithFieldPath(this, encodedValue) - } + internal fun String.toEncoded(encodedValue: Any?): FieldAndValue.WithStringField = + FieldAndValue.WithStringField(this, encodedValue) + + @PublishedApi + internal fun FieldPath.toEncoded(encodedValue: Any?): FieldAndValue.WithFieldPath = + FieldAndValue.WithFieldPath(this, encodedValue) } diff --git a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/Filter.kt b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/Filter.kt index ee9004fda..640c24fdb 100644 --- a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/Filter.kt +++ b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/Filter.kt @@ -1,7 +1,10 @@ package dev.gitlive.firebase.firestore import dev.gitlive.firebase.EncodeSettings +import dev.gitlive.firebase.copyFrom import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.modules.EmptySerializersModule +import kotlinx.serialization.modules.SerializersModule public sealed interface WhereConstraint { @@ -39,211 +42,224 @@ public sealed class Filter { public data class Path @PublishedApi internal constructor(val path: FieldPath, override val constraint: WhereConstraint) : WithConstraint() } -public class FilterBuilder internal constructor() { +public class FilterBuilder internal constructor() : EncodeSettings.Builder { + + private var _encodeDefaults: Boolean = true + override var encodeDefaults: Boolean + get() = _encodeDefaults + set(value) { + if (_encodeSettingsBuilder.isInitialized()) { + throw IllegalStateException("You should not change encode settings after they've been used. Call withEncoder again") + } else { + _encodeDefaults = value + } + } + private var _serializersModule: SerializersModule = EmptySerializersModule() + override var serializersModule: SerializersModule + get() = _serializersModule + set(value) { + if (_encodeSettingsBuilder.isInitialized()) { + throw IllegalStateException("You should not change encode settings after they've been used. Call withEncoder again") + } else { + _serializersModule = value + } + } - @PublishedApi - internal var encodeNextWith: EncodeSettings.Builder.() -> Unit = { - encodeDefaults = true + private val _encodeSettingsBuilder: Lazy Unit> = lazy { + { + copyFrom(this@FilterBuilder) + } } - /** - * Sets the [EncodeSettings.Builder] to apply to the next [WhereConstraint] added. - * Updating this value will only influence the encoding of [WhereConstraint] not yet added to the update. - * This allows for custom encoding per value, e.g. - * - * ``` - * encodeNextWith { encodeDefaults = true } - * "path" equalTo value - * encodeNextWith { encodeDefaults = false } - * "otherPath" equalTo otherValue - * ``` - */ - public fun encodeNextWith(builder: EncodeSettings.Builder.() -> Unit) { - encodeNextWith = builder - } + @PublishedApi + internal val encodeSettingsBuilder: EncodeSettings.Builder.() -> Unit = _encodeSettingsBuilder.value + + public fun withEncoder(dsl: FilterBuilder.() -> Filter): Filter = FilterBuilder() + .apply { copyFrom(this@FilterBuilder) } + .run(dsl) public val String.isNull: Filter.WithConstraint get() = Filter.Field(this, WhereConstraint.EqualTo(null)) public inline infix fun String.equalTo(value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.EqualTo(encode(value, encodeNextWith)), + WhereConstraint.EqualTo(encode(value, encodeSettingsBuilder)), ) public fun String.equalTo(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.EqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)), + WhereConstraint.EqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)), ) public val FieldPath.isNull: Filter.WithConstraint get() = Filter.Path(this, WhereConstraint.EqualTo(null)) public inline infix fun FieldPath.equalTo(value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.EqualTo(encode(value, encodeNextWith)), + WhereConstraint.EqualTo(encode(value, encodeSettingsBuilder)), ) public fun FieldPath.equalTo(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.EqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)), + WhereConstraint.EqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)), ) public val String.isNotNull: Filter.WithConstraint get() = Filter.Field(this, WhereConstraint.NotEqualTo(null)) public inline infix fun String.notEqualTo(value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.NotEqualTo(encode(value, encodeNextWith)), + WhereConstraint.NotEqualTo(encode(value, encodeSettingsBuilder)), ) public fun String.notEqualTo(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.NotEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)), + WhereConstraint.NotEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)), ) public val FieldPath.isNotNull: Filter.WithConstraint get() = Filter.Path(this, WhereConstraint.NotEqualTo(null)) public inline infix fun FieldPath.notEqualTo(value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.NotEqualTo(encode(value, encodeNextWith)), + WhereConstraint.NotEqualTo(encode(value, encodeSettingsBuilder)), ) public fun FieldPath.notEqualTo(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.NotEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)), + WhereConstraint.NotEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)), ) public inline infix fun String.lessThan(value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.LessThan(encode(value, encodeNextWith)!!), + WhereConstraint.LessThan(encode(value, encodeSettingsBuilder)!!), ) public fun String.lessThan(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.LessThan(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)!!), + WhereConstraint.LessThan(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)!!), ) public inline infix fun FieldPath.lessThan(value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.LessThan(encode(value, encodeNextWith)!!), + WhereConstraint.LessThan(encode(value, encodeSettingsBuilder)!!), ) public fun FieldPath.lessThan(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.LessThan(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)!!), + WhereConstraint.LessThan(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)!!), ) public inline infix fun String.greaterThan(value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.GreaterThan(encode(value, encodeNextWith)!!), + WhereConstraint.GreaterThan(encode(value, encodeSettingsBuilder)!!), ) public fun String.greaterThan(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.GreaterThan(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)!!), + WhereConstraint.GreaterThan(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)!!), ) public inline infix fun FieldPath.greaterThan(value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.GreaterThan(encode(value, encodeNextWith)!!), + WhereConstraint.GreaterThan(encode(value, encodeSettingsBuilder)!!), ) public fun FieldPath.greaterThan(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.GreaterThan(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)!!), + WhereConstraint.GreaterThan(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)!!), ) public inline infix fun String.lessThanOrEqualTo(value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.LessThanOrEqualTo(encode(value, encodeNextWith)!!), + WhereConstraint.LessThanOrEqualTo(encode(value, encodeSettingsBuilder)!!), ) public fun String.lessThanOrEqualTo(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.LessThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)!!), + WhereConstraint.LessThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)!!), ) public inline infix fun FieldPath.lessThanOrEqualTo(value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.LessThanOrEqualTo(encode(value, encodeNextWith)!!), + WhereConstraint.LessThanOrEqualTo(encode(value, encodeSettingsBuilder)!!), ) public fun FieldPath.lessThanOrEqualTo(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.LessThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)!!), + WhereConstraint.LessThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)!!), ) public inline infix fun String.greaterThanOrEqualTo(value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.GreaterThanOrEqualTo(encode(value, encodeNextWith)!!), + WhereConstraint.GreaterThanOrEqualTo(encode(value, encodeSettingsBuilder)!!), ) public fun String.greaterThanOrEqualTo(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.GreaterThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)!!), + WhereConstraint.GreaterThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)!!), ) public inline infix fun FieldPath.greaterThanOrEqualTo(value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.GreaterThanOrEqualTo(encode(value, encodeNextWith)!!), + WhereConstraint.GreaterThanOrEqualTo(encode(value, encodeSettingsBuilder)!!), ) public fun FieldPath.greaterThanOrEqualTo(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.GreaterThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)!!), + WhereConstraint.GreaterThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)!!), ) public inline infix fun String.contains(value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.ArrayContains(encode(value, encodeNextWith)!!), + WhereConstraint.ArrayContains(encode(value, encodeSettingsBuilder)!!), ) public fun String.contains(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.ArrayContains(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)!!), + WhereConstraint.ArrayContains(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)!!), ) public inline infix fun FieldPath.contains(value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.ArrayContains(encode(value, encodeNextWith)!!), + WhereConstraint.ArrayContains(encode(value, encodeSettingsBuilder)!!), ) public fun FieldPath.contains(strategy: SerializationStrategy, value: T): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.ArrayContains(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)!!), + WhereConstraint.ArrayContains(dev.gitlive.firebase.internal.encode(strategy, value, encodeSettingsBuilder)!!), ) public inline infix fun String.containsAny(values: List): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.ArrayContainsAny(values.map { encode(it, encodeNextWith)!! }), + WhereConstraint.ArrayContainsAny(values.map { encode(it, encodeSettingsBuilder)!! }), ) public fun String.containsAny(strategy: SerializationStrategy, values: List): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.ArrayContainsAny(values.map { dev.gitlive.firebase.internal.encode(strategy, it, encodeNextWith)!! }), + WhereConstraint.ArrayContainsAny(values.map { dev.gitlive.firebase.internal.encode(strategy, it, encodeSettingsBuilder)!! }), ) public inline infix fun FieldPath.containsAny(values: List): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.ArrayContainsAny(values.map { encode(it, encodeNextWith)!! }), + WhereConstraint.ArrayContainsAny(values.map { encode(it, encodeSettingsBuilder)!! }), ) public fun FieldPath.containsAny(strategy: SerializationStrategy, values: List): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.ArrayContainsAny(values.map { dev.gitlive.firebase.internal.encode(strategy, it, encodeNextWith)!! }), + WhereConstraint.ArrayContainsAny(values.map { dev.gitlive.firebase.internal.encode(strategy, it, encodeSettingsBuilder)!! }), ) public inline infix fun String.inArray(values: List): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.InArray(values.map { encode(it, encodeNextWith)!! }), + WhereConstraint.InArray(values.map { encode(it, encodeSettingsBuilder)!! }), ) public fun String.inArray(strategy: SerializationStrategy, values: List): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.InArray(values.map { dev.gitlive.firebase.internal.encode(strategy, it, encodeNextWith)!! }), + WhereConstraint.InArray(values.map { dev.gitlive.firebase.internal.encode(strategy, it, encodeSettingsBuilder)!! }), ) public inline infix fun FieldPath.inArray(values: List): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.InArray(values.map { encode(it, encodeNextWith)!! }), + WhereConstraint.InArray(values.map { encode(it, encodeSettingsBuilder)!! }), ) public fun FieldPath.inArray(strategy: SerializationStrategy, values: List): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.InArray(values.map { dev.gitlive.firebase.internal.encode(strategy, it, encodeNextWith)!! }), + WhereConstraint.InArray(values.map { dev.gitlive.firebase.internal.encode(strategy, it, encodeSettingsBuilder)!! }), ) public inline infix fun String.notInArray(values: List): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.NotInArray(values.map { encode(it, encodeNextWith)!! }), + WhereConstraint.NotInArray(values.map { encode(it, encodeSettingsBuilder)!! }), ) public fun String.notInArray(strategy: SerializationStrategy, values: List): Filter.WithConstraint = Filter.Field( this, - WhereConstraint.NotInArray(values.map { dev.gitlive.firebase.internal.encode(strategy, it, encodeNextWith)!! }), + WhereConstraint.NotInArray(values.map { dev.gitlive.firebase.internal.encode(strategy, it, encodeSettingsBuilder)!! }), ) public inline infix fun FieldPath.notInArray(values: List): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.NotInArray(values.map { encode(it, encodeNextWith)!! }), + WhereConstraint.NotInArray(values.map { encode(it, encodeSettingsBuilder)!! }), ) public fun FieldPath.notInArray(strategy: SerializationStrategy, values: List): Filter.WithConstraint = Filter.Path( this, - WhereConstraint.NotInArray(values.map { dev.gitlive.firebase.internal.encode(strategy, it, encodeNextWith)!! }), + WhereConstraint.NotInArray(values.map { dev.gitlive.firebase.internal.encode(strategy, it, encodeSettingsBuilder)!! }), ) public infix fun Filter.and(right: Filter): Filter.And { diff --git a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt index b030660cf..660e4fcd9 100644 --- a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt +++ b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt @@ -200,7 +200,7 @@ public data class Transaction internal constructor(internal val nativeWrapper: N updateFields( documentRef, ) { - encodeNextWith(buildSettings) + apply(buildSettings) fieldsAndValues.forEach { (field, value) -> field to value } @@ -215,7 +215,7 @@ public data class Transaction internal constructor(internal val nativeWrapper: N updateFields( documentRef, ) { - encodeNextWith(buildSettings) + apply(buildSettings) fieldsAndValues.forEach { (field, value) -> field to value } @@ -229,7 +229,7 @@ public data class Transaction internal constructor(internal val nativeWrapper: N public fun updateFields( documentRef: DocumentReference, fieldsAndValuesUpdateDSL: FieldsAndValuesUpdateDSL.() -> Unit, - ): Transaction = Transaction(nativeWrapper.updateEncoded(documentRef, FieldsAndValuesUpdateDSL().apply(fieldsAndValuesUpdateDSL).fieldAndValues)) + ): Transaction = Transaction(nativeWrapper.updateEncoded(documentRef, FieldsAndValuesUpdateDSL().apply(fieldsAndValuesUpdateDSL).fieldsAndValues)) @PublishedApi internal fun updateEncoded(documentRef: DocumentReference, encodedData: EncodedObject): Transaction = Transaction(nativeWrapper.updateEncoded(documentRef, encodedData)) @@ -262,7 +262,8 @@ public open class Query internal constructor(internal val nativeQuery: NativeQue public fun startAfter(vararg fieldValues: Any?): Query = startAfter(*fieldValues) {} public fun startAfter(vararg fieldValues: Any?, buildSettings: EncodeSettings.Builder.() -> Unit): Query = startAfterFieldValues { - encodeNextWith(buildSettings) + apply(buildSettings) + fieldValues.forEach { add(it) } @@ -280,7 +281,7 @@ public open class Query internal constructor(internal val nativeQuery: NativeQue public fun startAt(vararg fieldValues: Any?): Query = startAt(*fieldValues) {} public fun startAt(vararg fieldValues: Any?, buildSettings: EncodeSettings.Builder.() -> Unit): Query = startAtFieldValues { - encodeNextWith(buildSettings) + apply(buildSettings) fieldValues.forEach { add(it) } @@ -298,9 +299,11 @@ public open class Query internal constructor(internal val nativeQuery: NativeQue public fun endBefore(vararg fieldValues: Any?): Query = endBefore(*fieldValues) {} public fun endBefore(vararg fieldValues: Any?, buildSettings: EncodeSettings.Builder.() -> Unit): Query = endBeforeFieldValues { - encodeNextWith(buildSettings) - fieldValues.forEach { - add(it) + withEncodeSettings { + apply(buildSettings) + fieldValues.forEach { + add(it) + } } } @@ -316,7 +319,7 @@ public open class Query internal constructor(internal val nativeQuery: NativeQue public fun endAt(vararg fieldValues: Any?): Query = endAt(*fieldValues) {} public fun endAt(vararg fieldValues: Any?, buildSettings: EncodeSettings.Builder.() -> Unit): Query = endAtFieldValues { - encodeNextWith(buildSettings) + apply(buildSettings) fieldValues.forEach { add(it) } @@ -463,7 +466,7 @@ public data class WriteBatch internal constructor(internal val nativeWrapper: Na updateFields( documentRef, ) { - encodeNextWith(buildSettings) + apply(buildSettings) fieldsAndValues.forEach { (field, value) -> field to value } @@ -478,7 +481,7 @@ public data class WriteBatch internal constructor(internal val nativeWrapper: Na updateFields( documentRef, ) { - encodeNextWith(buildSettings) + apply(buildSettings) fieldsAndValues.forEach { (path, value) -> path to value } @@ -495,7 +498,7 @@ public data class WriteBatch internal constructor(internal val nativeWrapper: Na ): WriteBatch = WriteBatch( nativeWrapper.updateEncoded( documentRef, - FieldsAndValuesUpdateDSL().apply(fieldsAndValuesUpdateDSL).fieldAndValues, + FieldsAndValuesUpdateDSL().apply(fieldsAndValuesUpdateDSL).fieldsAndValues, ), ) @@ -645,7 +648,7 @@ public data class DocumentReference internal constructor(internal val native: Na @JvmName("updateFields") public suspend fun update(vararg fieldsAndValues: Pair, buildSettings: EncodeSettings.Builder.() -> Unit): Unit = updateFields { - encodeNextWith(buildSettings) + apply(buildSettings) fieldsAndValues.forEach { (field, value) -> field to value } @@ -658,7 +661,7 @@ public data class DocumentReference internal constructor(internal val native: Na @JvmName("updateFieldPaths") public suspend fun update(vararg fieldsAndValues: Pair, buildSettings: EncodeSettings.Builder.() -> Unit): Unit = updateFields { - encodeNextWith(buildSettings) + apply(buildSettings) fieldsAndValues.forEach { (fieldPath, value) -> fieldPath to value } @@ -671,7 +674,7 @@ public data class DocumentReference internal constructor(internal val native: Na public suspend fun updateFields( fieldsAndValuesUpdateDSL: FieldsAndValuesUpdateDSL.() -> Unit, ) { - native.updateEncoded(FieldsAndValuesUpdateDSL().apply(fieldsAndValuesUpdateDSL).fieldAndValues) + native.updateEncoded(FieldsAndValuesUpdateDSL().apply(fieldsAndValuesUpdateDSL).fieldsAndValues) } public suspend fun delete() {