-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves DSL for updating firestore references
- Loading branch information
Showing
21 changed files
with
318 additions
and
327 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/EncodableValue.kt
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldValueBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dev.gitlive.firebase.firestore | ||
|
||
import dev.gitlive.firebase.EncodeSettings | ||
import kotlinx.serialization.SerializationStrategy | ||
|
||
public class FieldValueBuilder internal constructor() { | ||
|
||
internal val fieldValues: MutableList<Any> = mutableListOf() | ||
public var buildSettings: EncodeSettings.Builder.() -> Unit = { | ||
encodeDefaults = true | ||
} | ||
|
||
public inline fun <reified T> add(value: T) { | ||
addEncoded(encode(value, buildSettings)!!) | ||
} | ||
|
||
public fun <T : Any> addWithStrategy(strategy: SerializationStrategy<T>, value: T) { | ||
addEncoded(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)!!) | ||
} | ||
|
||
@PublishedApi | ||
internal fun addEncoded(encodedValue: Any) { | ||
fieldValues += encodedValue | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldsAndValuesBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package dev.gitlive.firebase.firestore | ||
|
||
import dev.gitlive.firebase.EncodeSettings | ||
import dev.gitlive.firebase.firestore.internal.FieldAndValue | ||
import kotlinx.serialization.SerializationStrategy | ||
|
||
public class FieldsAndValuesBuilder internal constructor() { | ||
|
||
internal val fieldAndValues: MutableList<FieldAndValue> = mutableListOf() | ||
public var buildSettings: EncodeSettings.Builder.() -> Unit = { | ||
encodeDefaults = true | ||
} | ||
|
||
public inline infix fun <reified T> String.to(value: T) { | ||
toEncoded(encode(value, buildSettings)) | ||
} | ||
|
||
public inline infix fun <reified T> FieldPath.to(value: T) { | ||
toEncoded(encode(value, buildSettings)) | ||
} | ||
|
||
public fun <T : Any> String.to(strategy: SerializationStrategy<T>, value: T) { | ||
toEncoded(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)) | ||
} | ||
|
||
public fun <T : Any> FieldPath.to(strategy: SerializationStrategy<T>, value: T) { | ||
toEncoded(dev.gitlive.firebase.internal.encode(strategy, value, buildSettings)) | ||
} | ||
|
||
@PublishedApi | ||
internal fun String.toEncoded(encodedValue: Any?) { | ||
fieldAndValues += FieldAndValue.WithStringField(this, encodedValue) | ||
} | ||
|
||
@PublishedApi | ||
internal fun FieldPath.toEncoded(encodedValue: Any?) { | ||
fieldAndValues += FieldAndValue.WithFieldPath(this, encodedValue) | ||
} | ||
} |
Oops, something went wrong.