Skip to content

Commit 5bdddfd

Browse files
committed
Merge branch 'master' into update-jvm-target
# Conflicts: # firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals.kt # firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt # settings.gradle.kts
2 parents b7f9e53 + a3c295f commit 5bdddfd

File tree

35 files changed

+625
-87
lines changed

35 files changed

+625
-87
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ db.collection("cities").document("LA").set(City.serializer(), city, encodeDefaul
8888
```
8989

9090
The `encodeDefaults` parameter is optional and defaults to `true`, set this to false to omit writing optional properties if they are equal to theirs default values.
91+
Using [@EncodeDefault](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-encode-default/) on properties is a recommended way to locally override the behavior set with `encodeDefaults`.
9192

9293
You can also omit the serializer but this is discouraged due to a [current limitation on Kotlin/JS and Kotlin/Native](https://github.com/Kotlin/kotlinx.serialization/issues/1116#issuecomment-704342452)
9394

@@ -110,6 +111,21 @@ data class Post(
110111
)
111112
```
112113

114+
In addition `firebase-firestore` provides [GeoPoint] and [DocumentReference] classes which allow persisting
115+
geo points and document references in a native way:
116+
117+
```kotlin
118+
@Serializable
119+
data class PointOfInterest(
120+
val reference: DocumentReference,
121+
val location: GeoPoint
122+
)
123+
val document = PointOfInterest(
124+
reference = Firebase.firestore.collection("foo").document("bar"),
125+
location = GeoPoint(51.939, 4.506)
126+
)
127+
```
128+
113129
<h4>Polymorphic serialization (sealed classes)</h4>
114130

115131
This sdk will handle polymorphic serialization automatically if you have a sealed class and its children marked as `Serializable`. It will include a `type` property that will be used to discriminate which child class is the serialized.

build.gradle.kts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,28 @@ subprojects {
7373
onlyIf { !project.gradle.startParameter.taskNames.any { "MavenLocal" in it } && !project.gradle.startParameter.taskNames.contains("publishToGitHubPackagesRepository") }
7474
}
7575

76+
val skipPublishing = project.name == "test-utils" // skip publishing for test utils
77+
7678
tasks {
79+
withType<Test> {
80+
testLogging {
81+
showExceptions = true
82+
exceptionFormat = TestExceptionFormat.FULL
83+
showStandardStreams = true
84+
showCauses = true
85+
showStackTraces = true
86+
events = setOf(
87+
TestLogEvent.STARTED,
88+
TestLogEvent.FAILED,
89+
TestLogEvent.PASSED,
90+
TestLogEvent.SKIPPED,
91+
TestLogEvent.STANDARD_OUT,
92+
TestLogEvent.STANDARD_ERROR
93+
)
94+
}
95+
}
96+
97+
if (skipPublishing) return@tasks
7798

7899
val updateVersion by registering(Exec::class) {
79100
commandLine("npm", "--allow-same-version", "--prefix", projectDir, "version", "${project.property("${project.name}.version")}")
@@ -144,24 +165,6 @@ subprojects {
144165
commandLine("npm", "publish")
145166
}
146167
}
147-
148-
withType<Test> {
149-
testLogging {
150-
showExceptions = true
151-
exceptionFormat = TestExceptionFormat.FULL
152-
showStandardStreams = true
153-
showCauses = true
154-
showStackTraces = true
155-
events = setOf(
156-
TestLogEvent.STARTED,
157-
TestLogEvent.FAILED,
158-
TestLogEvent.PASSED,
159-
TestLogEvent.SKIPPED,
160-
TestLogEvent.STANDARD_OUT,
161-
TestLogEvent.STANDARD_ERROR
162-
)
163-
}
164-
}
165168
}
166169

167170
afterEvaluate {
@@ -193,8 +196,10 @@ subprojects {
193196
}
194197
}
195198

196-
apply(plugin="maven-publish")
197-
apply(plugin="signing")
199+
if (skipPublishing) return@subprojects
200+
201+
apply(plugin = "maven-publish")
202+
apply(plugin = "signing")
198203

199204

200205
configure<PublishingExtension> {
@@ -247,6 +252,7 @@ subprojects {
247252
}
248253
}
249254
}
255+
250256
}
251257
}
252258

firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import platform.Foundation.*
1919
actual val Firebase.auth
2020
get() = FirebaseAuth(FIRAuth.auth())
2121

22-
actual fun Firebase.auth(app: FirebaseApp): FirebaseAuth = TODO("Come back to issue")
23-
// FirebaseAuth(FIRAuth.authWithApp(app.ios))
22+
actual fun Firebase.auth(app: FirebaseApp): FirebaseAuth = FirebaseAuth(
23+
FIRAuth.authWithApp(app.ios as objcnames.classes.FIRApp)
24+
)
2425

2526
actual class FirebaseAuth internal constructor(val ios: FIRAuth) {
2627

firebase-common/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ kotlin {
103103
}
104104
}
105105

106+
val commonTest by getting {
107+
dependencies {
108+
implementation(project(":test-utils"))
109+
}
110+
}
111+
106112
val androidMain by getting {
107113
dependencies {
108114
api("com.google.firebase:firebase-common")

firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/serializers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class FirebaseListSerializer : KSerializer<Iterable<Any?>> {
108108
* A special case of serializer for values natively supported by Firebase and
109109
* don't require an additional encoding/decoding.
110110
*/
111-
abstract class SpecialValueSerializer<T>(
111+
class SpecialValueSerializer<T>(
112112
serialName: String,
113113
private val toNativeValue: (T) -> Any?,
114114
private val fromNativeValue: (Any?) -> T

firebase-common/src/commonTest/kotlin/dev/gitlive/firebase/EncodersTest.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import kotlin.test.Test
1111
import kotlin.test.assertEquals
1212
import kotlin.test.assertNull
1313

14-
expect fun nativeMapOf(vararg pairs: Pair<String, Any?>): Any
15-
expect fun nativeListOf(vararg elements: Any): Any
16-
expect fun nativeAssertEquals(expected: Any?, actual: Any?): Unit
17-
1814
@Serializable
1915
data class TestData(val map: Map<String, String>, val bool: Boolean = false, val nullableBool: Boolean? = null)
2016

firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ external object firebase {
276276
object functions {
277277
class Functions {
278278
fun httpsCallable(name: String, options: Json?): HttpsCallable
279-
fun useFunctionsEmulator(origin: String)
280279
fun useEmulator(host: String, port: Int)
281280
}
282281
interface HttpsCallableResult {
@@ -455,6 +454,7 @@ external object firebase {
455454
fun update(field: FieldPath, value: Any?, vararg moreFieldsAndValues: Any?): Promise<Unit>
456455
fun delete(): Promise<Unit>
457456
fun onSnapshot(options: Json, next: (snapshot: DocumentSnapshot) -> Unit, error: (error: Error) -> Unit): ()->Unit
457+
fun isEqual(other: DocumentReference): Boolean
458458
}
459459

460460
open class WriteBatch {
@@ -479,6 +479,8 @@ external object firebase {
479479
companion object {
480480
val documentId: FieldPath
481481
}
482+
483+
fun isEqual(other: FieldPath): Boolean
482484
}
483485

484486
abstract class FieldValue {
@@ -492,6 +494,13 @@ external object firebase {
492494

493495
fun isEqual(other: FieldValue): Boolean
494496
}
497+
498+
open class GeoPoint(latitude: Double, longitude: Double) {
499+
val latitude: Double
500+
val longitude: Double
501+
502+
fun isEqual(other: GeoPoint): Boolean
503+
}
495504
}
496505

497506
fun remoteConfig(app: App? = definedExternally): remoteConfig.RemoteConfig

firebase-config/src/iosMain/kotlin/dev/gitlive/firebase/remoteconfig/FirebaseRemoteConfig.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import platform.Foundation.timeIntervalSince1970
1919
actual val Firebase.remoteConfig: FirebaseRemoteConfig
2020
get() = FirebaseRemoteConfig(FIRRemoteConfig.remoteConfig())
2121

22-
actual fun Firebase.remoteConfig(app: FirebaseApp): FirebaseRemoteConfig = TODO("Come back to issue")
23-
// FirebaseRemoteConfig(FIRRemoteConfig.remoteConfigWithApp(Firebase.app.ios))
22+
actual fun Firebase.remoteConfig(app: FirebaseApp): FirebaseRemoteConfig = FirebaseRemoteConfig(
23+
FIRRemoteConfig.remoteConfigWithApp(Firebase.app.ios as objcnames.classes.FIRApp)
24+
)
2425

2526
actual class FirebaseRemoteConfig internal constructor(val ios: FIRRemoteConfig) {
2627
actual val all: Map<String, FirebaseRemoteConfigValue>

firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/ServerValue.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dev.gitlive.firebase.database
33
import dev.gitlive.firebase.FirebaseDecoder
44
import dev.gitlive.firebase.FirebaseEncoder
55
import dev.gitlive.firebase.SpecialValueSerializer
6+
import kotlinx.serialization.KSerializer
67
import kotlinx.serialization.Serializable
78
import kotlinx.serialization.SerializationException
89

@@ -18,7 +19,7 @@ expect class ServerValue internal constructor(nativeValue: Any){
1819
}
1920

2021
/** Serializer for [ServerValue]. Must be used with [FirebaseEncoder]/[FirebaseDecoder].*/
21-
object ServerValueSerializer: SpecialValueSerializer<ServerValue>(
22+
object ServerValueSerializer: KSerializer<ServerValue> by SpecialValueSerializer(
2223
serialName = "ServerValue",
2324
toNativeValue = ServerValue::nativeValue,
2425
fromNativeValue = { raw ->

firebase-database/src/iosMain/kotlin/dev/gitlive/firebase/database/database.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ actual val Firebase.database
3333
actual fun Firebase.database(url: String) =
3434
FirebaseDatabase(FIRDatabase.databaseWithURL(url))
3535

36-
actual fun Firebase.database(app: FirebaseApp): FirebaseDatabase = TODO("Come back to issue")
37-
// FirebaseDatabase(FIRDatabase.databaseForApp(app.ios))
36+
actual fun Firebase.database(app: FirebaseApp): FirebaseDatabase = FirebaseDatabase(
37+
FIRDatabase.databaseForApp(app.ios as objcnames.classes.FIRApp)
38+
)
3839

39-
actual fun Firebase.database(app: FirebaseApp, url: String): FirebaseDatabase = TODO("Come back to issue")
40-
// FirebaseDatabase(FIRDatabase.databaseForApp(app.ios, url))
40+
actual fun Firebase.database(app: FirebaseApp, url: String): FirebaseDatabase = FirebaseDatabase(
41+
FIRDatabase.databaseForApp(app.ios as objcnames.classes.FIRApp, url)
42+
)
4143

4244
actual class FirebaseDatabase internal constructor(val ios: FIRDatabase) {
4345

0 commit comments

Comments
 (0)