Skip to content

Commit

Permalink
Merge pull request #487 from splendo/feature/fix-fieldpath-documentid
Browse files Browse the repository at this point in the history
Move FieldPath.documentId to companion object
  • Loading branch information
nbransby authored Apr 3, 2024
2 parents 7a49f42 + 38b6a9c commit f808163
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,18 @@ actual class SnapshotMetadata(val android: com.google.firebase.firestore.Snapsho
}

actual class FieldPath private constructor(val android: com.google.firebase.firestore.FieldPath) {

actual companion object {
actual val documentId = FieldPath(com.google.firebase.firestore.FieldPath.documentId())
}

actual constructor(vararg fieldNames: String) : this(
com.google.firebase.firestore.FieldPath.of(
*fieldNames
)
)

actual val documentId: FieldPath get() = FieldPath(com.google.firebase.firestore.FieldPath.documentId())
actual val documentId: FieldPath get() = FieldPath.documentId
actual val encoded: EncodedFieldPath = android
override fun equals(other: Any?): Boolean = other is FieldPath && android == other.android
override fun hashCode(): Int = android.hashCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ expect class SnapshotMetadata {
}

expect class FieldPath(vararg fieldNames: String) {
companion object {
val documentId: FieldPath
}
@Deprecated("Use companion object instead", replaceWith = ReplaceWith("FieldPath.documentId"))
val documentId: FieldPath
val encoded: EncodedFieldPath
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,6 @@ class FirebaseFirestoreTest {
assertEquals(setOf(DocumentWithTimestamp(futureTimestamp)), gtQueryResult)
}


@Test
fun testGeoPointSerialization() = runTest {
@Serializable
Expand Down Expand Up @@ -1017,6 +1016,16 @@ class FirebaseFirestoreTest {
andOrQuery.assertDocuments(FirestoreTest.serializer(), testOne)
}

@Test
fun testQueryByDocumentId() = runTest {
setupFirestoreData()

val fieldQuery = firestore
.collection("testFirestoreQuerying")
.where { FieldPath.documentId equalTo "one" }
fieldQuery.assertDocuments(FirestoreTest.serializer(), testOne)
}

private suspend fun setupFirestoreData(
documentOne: FirestoreTest = testOne,
documentTwo: FirestoreTest = testTwo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,11 @@ actual class SnapshotMetadata(val ios: FIRSnapshotMetadata) {
}

actual class FieldPath private constructor(val ios: FIRFieldPath) {
actual companion object {
actual val documentId = FieldPath(FIRFieldPath.documentID())
}
actual constructor(vararg fieldNames: String) : this(FIRFieldPath(fieldNames.asList()))
actual val documentId: FieldPath get() = FieldPath(FIRFieldPath.documentID())
actual val documentId: FieldPath get() = FieldPath.documentId
actual val encoded: EncodedFieldPath = ios
override fun equals(other: Any?): Boolean = other is FieldPath && ios == other.ios
override fun hashCode(): Int = ios.hashCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,14 @@ actual class SnapshotMetadata(val js: JsSnapshotMetadata) {
}

actual class FieldPath private constructor(val js: JsFieldPath) {

actual companion object {
actual val documentId = FieldPath(JsFieldPath.documentId)
}
actual constructor(vararg fieldNames: String) : this(dev.gitlive.firebase.firestore.rethrow {
js("Reflect").construct(JsFieldPath, fieldNames).unsafeCast<JsFieldPath>()
})
actual val documentId: FieldPath get() = FieldPath(JsFieldPath.documentId)
actual val documentId: FieldPath get() = FieldPath.documentId
actual val encoded: EncodedFieldPath = js
override fun equals(other: Any?): Boolean = other is FieldPath && js.isEqual(other.js)
override fun hashCode(): Int = js.hashCode()
Expand Down

0 comments on commit f808163

Please sign in to comment.