Skip to content

Commit a35a34e

Browse files
committed
JVM support
1 parent 6c72df4 commit a35a34e

File tree

6 files changed

+575
-13
lines changed

6 files changed

+575
-13
lines changed

firebase-firestore/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ kotlin {
171171
api("com.google.firebase:firebase-firestore")
172172
}
173173
}
174-
175-
getByName("jvmMain") {
176-
kotlin.srcDir("src/androidMain/kotlin")
177-
}
178174
}
179175
}
180176

firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/FieldValueTests.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dev.gitlive.firebase.firestore
22

3-
import dev.gitlive.firebase.firebaseSerializer
43
import dev.gitlive.firebase.runTest
54
import kotlin.test.Test
65
import kotlin.test.assertEquals

firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/firestore.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -510,17 +510,15 @@ class FirebaseFirestoreTest {
510510
collection.add(DocumentWithTimestamp.serializer(), DocumentWithTimestamp(pastTimestamp))
511511
collection.add(DocumentWithTimestamp.serializer(), DocumentWithTimestamp(futureTimestamp))
512512

513-
val equalityQueryResult = collection.where(
514-
path = FieldPath(DocumentWithTimestamp::time.name),
515-
equalTo = pastTimestamp
516-
).get().documents.map { it.data(DocumentWithTimestamp.serializer()) }.toSet()
513+
val equalityQueryResult = collection.where {
514+
FieldPath(DocumentWithTimestamp::time.name) equalTo pastTimestamp
515+
}.get().documents.map { it.data(DocumentWithTimestamp.serializer()) }.toSet()
517516

518517
assertEquals(setOf(DocumentWithTimestamp(pastTimestamp)), equalityQueryResult)
519518

520-
val gtQueryResult = collection.where(
521-
path = FieldPath(DocumentWithTimestamp::time.name),
522-
greaterThan = timestamp
523-
).get().documents.map { it.data(DocumentWithTimestamp.serializer()) }.toSet()
519+
val gtQueryResult = collection.where {
520+
FieldPath(DocumentWithTimestamp::time.name) greaterThan timestamp
521+
}.get().documents.map { it.data(DocumentWithTimestamp.serializer()) }.toSet()
524522

525523
assertEquals(setOf(DocumentWithTimestamp(futureTimestamp)), gtQueryResult)
526524
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package dev.gitlive.firebase.firestore
2+
3+
import kotlinx.serialization.Serializable
4+
5+
/** A class representing a platform specific Firebase GeoPoint. */
6+
actual typealias NativeGeoPoint = com.google.firebase.firestore.GeoPoint
7+
8+
/** A class representing a Firebase GeoPoint. */
9+
@Serializable(with = GeoPointSerializer::class)
10+
actual class GeoPoint internal actual constructor(internal actual val nativeValue: NativeGeoPoint) {
11+
actual constructor(latitude: Double, longitude: Double) : this(NativeGeoPoint(latitude, longitude))
12+
actual val latitude: Double = nativeValue.latitude
13+
actual val longitude: Double = nativeValue.longitude
14+
15+
override fun equals(other: Any?): Boolean =
16+
this === other || other is GeoPoint && nativeValue == other.nativeValue
17+
override fun hashCode(): Int = nativeValue.hashCode()
18+
override fun toString(): String = nativeValue.toString()
19+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@file:JvmName("androidTimestamp")
2+
package dev.gitlive.firebase.firestore
3+
4+
import kotlinx.serialization.Serializable
5+
6+
/** A class representing a platform specific Firebase Timestamp. */
7+
actual typealias NativeTimestamp = com.google.firebase.Timestamp
8+
9+
/** A base class that could be used to combine [Timestamp] and [Timestamp.ServerTimestamp] in the same field. */
10+
@Serializable(with = BaseTimestampSerializer::class)
11+
actual sealed class BaseTimestamp
12+
13+
/** A class representing a Firebase Timestamp. */
14+
@Serializable(with = TimestampSerializer::class)
15+
actual class Timestamp internal actual constructor(
16+
internal actual val nativeValue: NativeTimestamp
17+
): BaseTimestamp() {
18+
actual constructor(seconds: Long, nanoseconds: Int) : this(NativeTimestamp(seconds, nanoseconds))
19+
20+
actual val seconds: Long = nativeValue.seconds
21+
actual val nanoseconds: Int = nativeValue.nanoseconds
22+
23+
override fun equals(other: Any?): Boolean =
24+
this === other || other is Timestamp && nativeValue == other.nativeValue
25+
override fun hashCode(): Int = nativeValue.hashCode()
26+
override fun toString(): String = nativeValue.toString()
27+
28+
actual companion object {
29+
actual fun now(): Timestamp = Timestamp(NativeTimestamp.now())
30+
}
31+
32+
/** A server time timestamp. */
33+
@Serializable(with = ServerTimestampSerializer::class)
34+
actual object ServerTimestamp: BaseTimestamp()
35+
}

0 commit comments

Comments
 (0)