Skip to content

Commit

Permalink
Refactored buildSettings variable to encodeNextWith cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Daeda88 committed Oct 30, 2024
1 parent 6d72b0d commit ee34197
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 81 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ documentRef.updateFields {
"otherField".to(IntAsStringSerializer(), 1)

// Overwrite build settings. All fields added after this will have these build settings applied
buildSettings = {
encodeNextWith {
encodeDefaults = true
serializersModule = module
}
Expand All @@ -215,7 +215,7 @@ query.orderBy("field", "otherField", "city").startAtFieldValues { // similar syn
add(1, IntAsStringSerializer())

// Overwrite build settings. All field values added after this will have these build settings applied
buildSettings = {
encodeNextWith {
encodeDefaults = true
serializersModule = module
}
Expand Down
15 changes: 9 additions & 6 deletions firebase-firestore/api/android/firebase-firestore.api
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ public final class dev/gitlive/firebase/firestore/FieldValueSerializer : kotlinx
public final class dev/gitlive/firebase/firestore/FieldValuesDSL {
public final fun addEncoded (Ljava/lang/Object;)V
public final fun addWithStrategy (Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V
public final fun getBuildSettings ()Lkotlin/jvm/functions/Function1;
public final fun setBuildSettings (Lkotlin/jvm/functions/Function1;)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 getBuildSettings ()Lkotlin/jvm/functions/Function1;
public final fun setBuildSettings (Lkotlin/jvm/functions/Function1;)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 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
Expand Down Expand Up @@ -238,9 +240,10 @@ 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 getBuildSettings ()Lkotlin/jvm/functions/Function1;
public final fun getEncodeNextWith ()Lkotlin/jvm/functions/Function1;
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;
Expand All @@ -260,7 +263,7 @@ 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 setBuildSettings (Lkotlin/jvm/functions/Function1;)V
public final fun setEncodeNextWith (Lkotlin/jvm/functions/Function1;)V
}

public final class dev/gitlive/firebase/firestore/FirebaseFirestore {
Expand Down
15 changes: 9 additions & 6 deletions firebase-firestore/api/jvm/firebase-firestore.api
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ public final class dev/gitlive/firebase/firestore/FieldValueSerializer : kotlinx
public final class dev/gitlive/firebase/firestore/FieldValuesDSL {
public final fun addEncoded (Ljava/lang/Object;)V
public final fun addWithStrategy (Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V
public final fun getBuildSettings ()Lkotlin/jvm/functions/Function1;
public final fun setBuildSettings (Lkotlin/jvm/functions/Function1;)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 getBuildSettings ()Lkotlin/jvm/functions/Function1;
public final fun setBuildSettings (Lkotlin/jvm/functions/Function1;)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 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
Expand Down Expand Up @@ -238,9 +240,10 @@ 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 getBuildSettings ()Lkotlin/jvm/functions/Function1;
public final fun getEncodeNextWith ()Lkotlin/jvm/functions/Function1;
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;
Expand All @@ -260,7 +263,7 @@ 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 setBuildSettings (Lkotlin/jvm/functions/Function1;)V
public final fun setEncodeNextWith (Lkotlin/jvm/functions/Function1;)V
}

public final class dev/gitlive/firebase/firestore/FirebaseFirestore {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@ public class FieldValuesDSL internal constructor() {

internal val fieldValues: MutableList<Any> = mutableListOf()

@PublishedApi
internal var encodeNextWith: EncodeSettings.Builder.() -> Unit = {
encodeDefaults = true
}

/**
* The [EncodeSettings.Builder] to apply to the next field values added.
* 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.
*
* ```
* buildSettings = { encodeDefaults = true }
* encodeNextWith { encodeDefaults = true }
* add(ClassWithDefaults())
* buildSettings = { encodeDefaults = false }
* encodeNextWith { encodeDefaults = false }
* add(ClassWithDefaults())
* ```
*/
public var buildSettings: EncodeSettings.Builder.() -> Unit = {
encodeDefaults = true
public fun encodeNextWith(builder: EncodeSettings.Builder.() -> Unit) {
encodeNextWith = builder
}

/**
Expand All @@ -33,7 +38,7 @@ public class FieldValuesDSL internal constructor() {
* @param value the value [T] to add
*/
public inline fun <reified T> add(value: T) {
addEncoded(encode(value, buildSettings)!!)
addEncoded(encode(value, encodeNextWith)!!)
}

/**
Expand All @@ -43,7 +48,7 @@ public class FieldValuesDSL internal constructor() {
* @param value the value [T] to add
*/
public fun <T : Any> addWithStrategy(strategy: SerializationStrategy<T>, value: T) {
addEncoded(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!)
addEncoded(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith)!!)
}

@PublishedApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@ public class FieldsAndValuesUpdateDSL internal constructor() {

internal val fieldAndValues: MutableList<FieldAndValue> = mutableListOf()

@PublishedApi
internal var encodeNextWith: EncodeSettings.Builder.() -> Unit = {
encodeDefaults = true
}

/**
* The [EncodeSettings.Builder] to apply to the next values added to this update.
* 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.
*
* ```
* buildSettings = { encodeDefaults = true }
* encodeNextWith { encodeDefaults = true }
* "path" to ClassWithDefaults()
* buildSettings = { encodeDefaults = false }
* encodeNextWith { encodeDefaults = false }
* "otherPath" to ClassWithDefaults()
* ```
*/
public var buildSettings: EncodeSettings.Builder.() -> Unit = {
encodeDefaults = true
public fun encodeNextWith(builder: EncodeSettings.Builder.() -> Unit) {
encodeNextWith = builder
}

/**
Expand All @@ -45,7 +50,7 @@ public class FieldsAndValuesUpdateDSL internal constructor() {
* @param value the value [T] to update to
*/
public inline infix fun <reified T> String.to(value: T) {
toEncoded(encode(value, buildSettings))
toEncoded(encode(value, encodeNextWith))
}

/**
Expand All @@ -54,7 +59,7 @@ public class FieldsAndValuesUpdateDSL internal constructor() {
* @param value the value [T] to update to
*/
public inline infix fun <reified T> FieldPath.to(value: T) {
toEncoded(encode(value, buildSettings))
toEncoded(encode(value, encodeNextWith))
}

/**
Expand All @@ -64,7 +69,7 @@ public class FieldsAndValuesUpdateDSL internal constructor() {
* @param value the value [T] to update to
*/
public fun <T : Any> String.to(strategy: SerializationStrategy<T>, value: T) {
toEncoded(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings))
toEncoded(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith))
}

/**
Expand All @@ -74,7 +79,7 @@ public class FieldsAndValuesUpdateDSL internal constructor() {
* @param value the value [T] to update to
*/
public fun <T : Any> FieldPath.to(strategy: SerializationStrategy<T>, value: T) {
toEncoded(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings))
toEncoded(dev.gitlive.firebase.internal.encode(strategy, value, encodeNextWith))
}

@PublishedApi
Expand Down
Loading

0 comments on commit ee34197

Please sign in to comment.