Skip to content

Commit

Permalink
Add support for customizing encoding behaviour when updating Values a…
Browse files Browse the repository at this point in the history
…t paths
  • Loading branch information
Daeda88 committed Aug 30, 2024
1 parent f682e3e commit bf8680c
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 194 deletions.
17 changes: 0 additions & 17 deletions firebase-common/api/android/firebase-common.api
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,3 @@ public final class dev/gitlive/firebase/FirebaseEncoder$DefaultImpls {
public static fun encodeSerializableValue (Ldev/gitlive/firebase/FirebaseEncoder;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V
}

public final class dev/gitlive/firebase/ValueWithSerializer {
public fun <init> (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)V
public final fun component1 ()Ljava/lang/Object;
public final fun component2 ()Lkotlinx/serialization/SerializationStrategy;
public final fun copy (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)Ldev/gitlive/firebase/ValueWithSerializer;
public static synthetic fun copy$default (Ldev/gitlive/firebase/ValueWithSerializer;Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;ILjava/lang/Object;)Ldev/gitlive/firebase/ValueWithSerializer;
public fun equals (Ljava/lang/Object;)Z
public final fun getSerializer ()Lkotlinx/serialization/SerializationStrategy;
public final fun getValue ()Ljava/lang/Object;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class dev/gitlive/firebase/ValueWithSerializerKt {
public static final fun withSerializer (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)Ljava/lang/Object;
}

17 changes: 0 additions & 17 deletions firebase-common/api/jvm/firebase-common.api
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,3 @@ public final class dev/gitlive/firebase/FirebaseEncoder$DefaultImpls {
public static fun encodeSerializableValue (Ldev/gitlive/firebase/FirebaseEncoder;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V
}

public final class dev/gitlive/firebase/ValueWithSerializer {
public fun <init> (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)V
public final fun component1 ()Ljava/lang/Object;
public final fun component2 ()Lkotlinx/serialization/SerializationStrategy;
public final fun copy (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)Ldev/gitlive/firebase/ValueWithSerializer;
public static synthetic fun copy$default (Ldev/gitlive/firebase/ValueWithSerializer;Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;ILjava/lang/Object;)Ldev/gitlive/firebase/ValueWithSerializer;
public fun equals (Ljava/lang/Object;)Z
public final fun getSerializer ()Lkotlinx/serialization/SerializationStrategy;
public final fun getValue ()Ljava/lang/Object;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class dev/gitlive/firebase/ValueWithSerializerKt {
public static final fun withSerializer (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)Ljava/lang/Object;
}

130 changes: 81 additions & 49 deletions firebase-firestore/api/android/firebase-firestore.api

Large diffs are not rendered by default.

130 changes: 81 additions & 49 deletions firebase-firestore/api/jvm/firebase-firestore.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.gitlive.firebase.firestore

import dev.gitlive.firebase.EncodeSettings
import kotlinx.serialization.SerializationStrategy

public data class EncodableValue(public val encoded: (EncodeSettings.Builder.() -> Unit) -> Any?)

public inline fun <reified T> T.encodable(): EncodableValue = EncodableValue {
encode(this, it)
}
public fun <T : Any> T.encodableWithStrategy(stategy: SerializationStrategy<T>): EncodableValue = EncodableValue {
dev.gitlive.firebase.internal.encode(stategy, this, it)
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,185 +48,185 @@ public class FilterBuilder internal constructor() {
public val String.isNull: Filter.WithConstraint get() = Filter.Field(this, WhereConstraint.EqualTo(null))
public inline infix fun <reified T> String.equalTo(value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.EqualTo(encode(value, buildSettings))
WhereConstraint.EqualTo(encode(value, buildSettings)),
)
public fun <T : Any> String.equalTo(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.EqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings))
WhereConstraint.EqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)),
)

public val FieldPath.isNull: Filter.WithConstraint get() = Filter.Path(this, WhereConstraint.EqualTo(null))
public inline infix fun <reified T> FieldPath.equalTo(value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.EqualTo(encode(value, buildSettings))
WhereConstraint.EqualTo(encode(value, buildSettings)),
)
public fun <T : Any> FieldPath.equalTo(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.EqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings))
WhereConstraint.EqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)),
)

public val String.isNotNull: Filter.WithConstraint get() = Filter.Field(this, WhereConstraint.NotEqualTo(null))
public inline infix fun <reified T> String.notEqualTo(value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.NotEqualTo(encode(value, buildSettings))
WhereConstraint.NotEqualTo(encode(value, buildSettings)),
)
public fun <T : Any> String.notEqualTo(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.NotEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings))
WhereConstraint.NotEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)),
)

public val FieldPath.isNotNull: Filter.WithConstraint get() = Filter.Path(this, WhereConstraint.NotEqualTo(null))
public inline infix fun <reified T> FieldPath.notEqualTo(value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.NotEqualTo(encode(value, buildSettings))
WhereConstraint.NotEqualTo(encode(value, buildSettings)),
)
public fun <T : Any> FieldPath.notEqualTo(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.NotEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings))
WhereConstraint.NotEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)),
)

public inline infix fun <reified T : Any> String.lessThan(value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.LessThan(encode(value, buildSettings)!!)
WhereConstraint.LessThan(encode(value, buildSettings)!!),
)
public fun <T : Any> String.lessThan(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.LessThan(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!)
WhereConstraint.LessThan(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!),
)

public inline infix fun <reified T : Any> FieldPath.lessThan(value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.LessThan(encode(value, buildSettings)!!)
WhereConstraint.LessThan(encode(value, buildSettings)!!),
)
public fun <T : Any> FieldPath.lessThan(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.LessThan(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!)
WhereConstraint.LessThan(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!),
)

public inline infix fun <reified T : Any> String.greaterThan(value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.GreaterThan(encode(value, buildSettings)!!)
WhereConstraint.GreaterThan(encode(value, buildSettings)!!),
)
public fun <T : Any> String.greaterThan(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.GreaterThan(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!)
WhereConstraint.GreaterThan(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!),
)

public inline infix fun <reified T : Any> FieldPath.greaterThan(value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.GreaterThan(encode(value, buildSettings)!!)
WhereConstraint.GreaterThan(encode(value, buildSettings)!!),
)
public fun <T : Any> FieldPath.greaterThan(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.GreaterThan(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!)
WhereConstraint.GreaterThan(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!),
)

public inline infix fun <reified T : Any> String.lessThanOrEqualTo(value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.LessThanOrEqualTo(encode(value, buildSettings)!!)
WhereConstraint.LessThanOrEqualTo(encode(value, buildSettings)!!),
)
public fun <T : Any> String.lessThanOrEqualTo(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.LessThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!)
WhereConstraint.LessThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!),
)

public inline infix fun <reified T : Any> FieldPath.lessThanOrEqualTo(value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.LessThanOrEqualTo(encode(value, buildSettings)!!)
WhereConstraint.LessThanOrEqualTo(encode(value, buildSettings)!!),
)
public fun <T : Any> FieldPath.lessThanOrEqualTo(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.GreaterThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!)
WhereConstraint.GreaterThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!),
)

public inline infix fun <reified T : Any> String.greaterThanOrEqualTo(value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.GreaterThanOrEqualTo(encode(value, buildSettings)!!)
WhereConstraint.GreaterThanOrEqualTo(encode(value, buildSettings)!!),
)
public fun <T : Any> String.greaterThanOrEqualTo(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.GreaterThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!)
WhereConstraint.GreaterThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!),
)

public inline infix fun <reified T : Any> FieldPath.greaterThanOrEqualTo(value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.GreaterThanOrEqualTo(encode(value, buildSettings)!!)
WhereConstraint.GreaterThanOrEqualTo(encode(value, buildSettings)!!),
)
public fun <T : Any> FieldPath.greaterThanOrEqualTo(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.LessThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!)
WhereConstraint.LessThanOrEqualTo(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!),
)

public inline infix fun <reified T : Any> String.contains(value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.ArrayContains(encode(value, buildSettings)!!)
WhereConstraint.ArrayContains(encode(value, buildSettings)!!),
)
public fun <T : Any> String.contains(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.ArrayContains(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!)
WhereConstraint.ArrayContains(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!),
)

public inline infix fun <reified T : Any> FieldPath.contains(value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.ArrayContains(encode(value, buildSettings)!!)
WhereConstraint.ArrayContains(encode(value, buildSettings)!!),
)
public fun <T : Any> FieldPath.contains(strategy: SerializationStrategy<T>, value: T): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.ArrayContains(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!)
WhereConstraint.ArrayContains(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!),
)

public inline infix fun <reified T : Any> String.containsAny(values: List<T>): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.ArrayContainsAny(values.map { encode(it, buildSettings)!! })
WhereConstraint.ArrayContainsAny(values.map { encode(it, buildSettings)!! }),
)
public fun <T : Any> String.containsAny(strategy: SerializationStrategy<T>, values: List<T>): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.ArrayContainsAny(values.map {dev.gitlive.firebase.internal.encode(strategy, it, buildSettings)!! })
WhereConstraint.ArrayContainsAny(values.map { dev.gitlive.firebase.internal.encode(strategy, it, buildSettings)!! }),
)

public inline infix fun <reified T : Any> FieldPath.containsAny(values: List<T>): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.ArrayContainsAny(values.map { encode(it, buildSettings)!! })
WhereConstraint.ArrayContainsAny(values.map { encode(it, buildSettings)!! }),
)
public fun <T : Any> FieldPath.containsAny(strategy: SerializationStrategy<T>, values: List<T>): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.ArrayContainsAny(values.map {dev.gitlive.firebase.internal.encode(strategy, it, buildSettings)!! })
WhereConstraint.ArrayContainsAny(values.map { dev.gitlive.firebase.internal.encode(strategy, it, buildSettings)!! }),
)

public inline infix fun <reified T : Any> String.inArray(values: List<T>): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.InArray(values.map { encode(it, buildSettings)!! })
WhereConstraint.InArray(values.map { encode(it, buildSettings)!! }),
)
public fun <T : Any> String.inArray(strategy: SerializationStrategy<T>, values: List<T>): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.InArray(values.map {dev.gitlive.firebase.internal.encode(strategy, it, buildSettings)!! })
WhereConstraint.InArray(values.map { dev.gitlive.firebase.internal.encode(strategy, it, buildSettings)!! }),
)

public inline infix fun <reified T : Any> FieldPath.inArray(values: List<T>): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.InArray(values.map { encode(it, buildSettings)!! })
WhereConstraint.InArray(values.map { encode(it, buildSettings)!! }),
)
public fun <T : Any> FieldPath.inArray(strategy: SerializationStrategy<T>, values: List<T>): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.InArray(values.map {dev.gitlive.firebase.internal.encode(strategy, it, buildSettings)!! })
WhereConstraint.InArray(values.map { dev.gitlive.firebase.internal.encode(strategy, it, buildSettings)!! }),
)

public inline infix fun <reified T : Any> String.notInArray(values: List<T>): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.NotInArray(values.map { encode(it, buildSettings)!! })
WhereConstraint.NotInArray(values.map { encode(it, buildSettings)!! }),
)
public fun <T : Any> String.notInArray(strategy: SerializationStrategy<T>, values: List<T>): Filter.WithConstraint = Filter.Field(
this,
WhereConstraint.NotInArray(values.map {dev.gitlive.firebase.internal.encode(strategy, it, buildSettings)!! })
WhereConstraint.NotInArray(values.map { dev.gitlive.firebase.internal.encode(strategy, it, buildSettings)!! }),
)

public inline infix fun <reified T : Any> FieldPath.notInArray(values: List<T>): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.NotInArray(values.map { encode(it, buildSettings)!! })
WhereConstraint.NotInArray(values.map { encode(it, buildSettings)!! }),
)
public fun <T : Any> FieldPath.notInArray(strategy: SerializationStrategy<T>, values: List<T>): Filter.WithConstraint = Filter.Path(
this,
WhereConstraint.NotInArray(values.map {dev.gitlive.firebase.internal.encode(strategy, it, buildSettings)!! })
WhereConstraint.NotInArray(values.map { dev.gitlive.firebase.internal.encode(strategy, it, buildSettings)!! }),
)

public infix fun Filter.and(right: Filter): Filter.And {
Expand Down
Loading

0 comments on commit bf8680c

Please sign in to comment.