Skip to content

Commit ae1c8a8

Browse files
authored
Merge branch 'master' into add-authDomain-to-FirebaseOptions
2 parents d05b644 + 7733c7c commit ae1c8a8

File tree

19 files changed

+168
-54
lines changed

19 files changed

+168
-54
lines changed

.github/workflows/pull_request.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ jobs:
3030
run: ./gradlew assemble
3131
- name: Run JS Tests
3232
run: ./gradlew cleanTest jsTest
33+
- name: Upload test artifact
34+
uses: actions/upload-artifact@v2
35+
if: failure()
36+
with:
37+
name: "JSTest Report HTML"
38+
path: "firebase-firestore/build/reports/tests/jsTest/"
3339
- name: Run Android Instrumented Tests
3440
uses: reactivecircus/android-emulator-runner@v2
3541
with:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<i>Real-time code collaboration inside any IDE</i><br/>
55
<br/>
66
<br/>
7-
The Firebase Kotlin SDK is a Kotlin-first SDK for Firebase. It's API is similar to the [Firebase Android SDK Kotlin Extensions](https://firebase.github.io/firebase-android-sdk/reference/kotlin/firebase-ktx/) but also supports multiplatform projects, enabling you to use Firebase directly from your common source targeting *iOS*, *Android* or *JS*.
7+
The Firebase Kotlin SDK is a Kotlin-first SDK for Firebase. It's API is similar to the <a href="https://firebase.github.io/firebase-android-sdk/reference/kotlin/firebase-ktx/">Firebase Android SDK Kotlin Extensions</a> but also supports multiplatform projects, enabling you to use Firebase directly from your common source targeting <strong>iOS</strong>, <strong>Android</strong> or <strong>JS</strong>.
88

99
## Available libraries
1010

build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ subprojects {
6767
onlyIf { !project.gradle.startParameter.taskNames.contains("publishToMavenLocal") }
6868
}
6969

70+
tasks.whenTaskAdded {
71+
enabled = when(name) {
72+
"compileDebugUnitTestKotlinAndroid" -> false
73+
"compileReleaseUnitTestKotlinAndroid" -> false
74+
"testDebugUnitTest" -> false
75+
"testReleaseUnitTest" -> false
76+
else -> enabled
77+
}
78+
}
79+
7080
tasks {
7181

7282
val updateVersion by registering(Exec::class) {

firebase-app/build.gradle.kts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,20 @@ kotlin {
7777

7878
js {
7979
useCommonJs()
80-
nodejs()
81-
browser()
80+
nodejs {
81+
testTask {
82+
useMocha {
83+
timeout = "5s"
84+
}
85+
}
86+
}
87+
browser {
88+
testTask {
89+
useMocha {
90+
timeout = "5s"
91+
}
92+
}
93+
}
8294
}
8395

8496
sourceSets {

firebase-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
2626
"@gitlive/firebase-common": "1.2.0",
27-
"firebase": "8.2.10",
27+
"firebase": "8.5.0",
2828
"kotlin": "1.4.31",
2929
"kotlinx-coroutines-core": "1.4.3"
3030
}

firebase-auth/build.gradle.kts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,20 @@ kotlin {
102102

103103
js {
104104
useCommonJs()
105-
nodejs()
106-
browser()
105+
nodejs {
106+
testTask {
107+
useMocha {
108+
timeout = "5s"
109+
}
110+
}
111+
}
112+
browser {
113+
testTask {
114+
useMocha {
115+
timeout = "5s"
116+
}
117+
}
118+
}
107119
}
108120

109121
sourceSets {

firebase-auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
2626
"@gitlive/firebase-app": "1.2.0",
27-
"firebase": "8.2.10",
27+
"firebase": "8.5.0",
2828
"kotlin": "1.4.31",
2929
"kotlinx-coroutines-core": "1.4.3"
3030
}

firebase-common/build.gradle.kts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,20 @@ kotlin {
5858

5959
js {
6060
useCommonJs()
61-
nodejs()
62-
browser()
61+
nodejs {
62+
testTask {
63+
useMocha {
64+
timeout = "5s"
65+
}
66+
}
67+
}
68+
browser {
69+
testTask {
70+
useMocha {
71+
timeout = "5s"
72+
}
73+
}
74+
}
6375
}
6476

6577
sourceSets {

firebase-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-multiplatform-sdk",
2525
"dependencies": {
26-
"firebase": "8.2.10",
26+
"firebase": "8.5.0",
2727
"kotlin": "1.4.31",
2828
"kotlinx-coroutines-core": "1.4.3",
2929
"kotlinx-serialization-kotlinx-serialization-runtime": "1.1.0"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class EncodersTest {
5151

5252
@Test
5353
fun decodeObjectNullableValue() {
54-
val decoded = decode(TestData.serializer(), mapOf("map" to mapOf("key" to "value"), "nullableBool" to null))
54+
val decoded = decode(TestData.serializer(), nativeMapOf("map" to mapOf("key" to "value"), "nullableBool" to null))
5555
assertNull(decoded.nullableBool)
5656
}
5757
}

firebase-database/build.gradle.kts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,20 @@ kotlin {
7878

7979
js {
8080
useCommonJs()
81-
nodejs()
82-
browser()
81+
nodejs {
82+
testTask {
83+
useMocha {
84+
timeout = "5s"
85+
}
86+
}
87+
}
88+
browser {
89+
testTask {
90+
useMocha {
91+
timeout = "5s"
92+
}
93+
}
94+
}
8395
}
8496

8597
sourceSets {

firebase-database/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
2626
"@gitlive/firebase-app": "1.2.0",
27-
"firebase": "8.2.10",
27+
"firebase": "8.5.0",
2828
"kotlin": "1.4.31",
2929
"kotlinx-coroutines-core": "1.4.3"
3030
}

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
package dev.gitlive.firebase.database
66

77
import dev.gitlive.firebase.*
8-
import kotlinx.coroutines.await
8+
import kotlinx.coroutines.*
99
import kotlinx.coroutines.channels.awaitClose
1010
import kotlinx.coroutines.flow.callbackFlow
11+
import kotlinx.coroutines.flow.filter
12+
import kotlinx.coroutines.flow.produceIn
13+
import kotlinx.coroutines.selects.select
1114
import kotlinx.serialization.DeserializationStrategy
1215
import kotlinx.serialization.SerializationStrategy
16+
import kotlin.js.Promise
1317

1418
@PublishedApi
1519
internal inline fun <reified T> encode(value: T, shouldEncodeElementDefault: Boolean) =
@@ -113,16 +117,16 @@ actual class DatabaseReference internal constructor(override val js: firebase.da
113117
actual fun onDisconnect() = rethrow { OnDisconnect(js.onDisconnect()) }
114118

115119
actual suspend fun updateChildren(update: Map<String, Any?>, encodeDefaults: Boolean) =
116-
rethrow { js.update(encode(update, encodeDefaults)).await() }
120+
rethrow { js.update(encode(update, encodeDefaults)).awaitWhileOnline() }
117121

118-
actual suspend fun removeValue() = rethrow { js.remove().await() }
122+
actual suspend fun removeValue() = rethrow { js.remove().awaitWhileOnline() }
119123

120124
actual suspend inline fun <reified T> setValue(value: T?, encodeDefaults: Boolean) = rethrow {
121-
js.set(encode(value, encodeDefaults)).await()
125+
js.set(encode(value, encodeDefaults)).awaitWhileOnline()
122126
}
123127

124128
actual suspend fun <T> setValue(strategy: SerializationStrategy<T>, value: T, encodeDefaults: Boolean) =
125-
rethrow { js.set(encode(strategy, value, encodeDefaults)).await() }
129+
rethrow { js.set(encode(strategy, value, encodeDefaults)).awaitWhileOnline() }
126130
}
127131

128132
actual class DataSnapshot internal constructor(val js: firebase.database.DataSnapshot) {
@@ -147,17 +151,17 @@ actual class DataSnapshot internal constructor(val js: firebase.database.DataSna
147151

148152
actual class OnDisconnect internal constructor(val js: firebase.database.OnDisconnect) {
149153

150-
actual suspend fun removeValue() = rethrow { js.remove().await() }
151-
actual suspend fun cancel() = rethrow { js.cancel().await() }
154+
actual suspend fun removeValue() = rethrow { js.remove().awaitWhileOnline() }
155+
actual suspend fun cancel() = rethrow { js.cancel().awaitWhileOnline() }
152156

153157
actual suspend fun updateChildren(update: Map<String, Any?>, encodeDefaults: Boolean) =
154-
rethrow { js.update(encode(update, encodeDefaults)).await() }
158+
rethrow { js.update(encode(update, encodeDefaults)).awaitWhileOnline() }
155159

156160
actual suspend inline fun <reified T> setValue(value: T, encodeDefaults: Boolean) =
157-
rethrow { js.set(encode(value, encodeDefaults)).await() }
161+
rethrow { js.set(encode(value, encodeDefaults)).awaitWhileOnline() }
158162

159163
actual suspend fun <T> setValue(strategy: SerializationStrategy<T>, value: T, encodeDefaults: Boolean) =
160-
rethrow { js.set(encode(strategy, value, encodeDefaults)).await() }
164+
rethrow { js.set(encode(strategy, value, encodeDefaults)).awaitWhileOnline() }
161165
}
162166

163167
actual class DatabaseException(error: dynamic) :
@@ -174,3 +178,18 @@ inline fun <R> rethrow(function: () -> R): R {
174178
throw DatabaseException(e)
175179
}
176180
}
181+
182+
suspend fun <T> Promise<T>.awaitWhileOnline(): T = coroutineScope {
183+
184+
val notConnected = Firebase.database
185+
.reference(".info/connected")
186+
.valueEvents
187+
.filter { !it.value<Boolean>() }
188+
.produceIn(this)
189+
190+
select<T> {
191+
this@awaitWhileOnline.asDeferred().onAwait { it.also { notConnected.cancel() } }
192+
notConnected.onReceive { throw DatabaseException("Database not connected") }
193+
}
194+
195+
}

firebase-firestore/build.gradle.kts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,20 @@ kotlin {
8080

8181
js {
8282
useCommonJs()
83-
nodejs()
84-
browser()
83+
nodejs {
84+
testTask {
85+
useMocha {
86+
timeout = "5s"
87+
}
88+
}
89+
}
90+
browser {
91+
testTask {
92+
useMocha {
93+
timeout = "5s"
94+
}
95+
}
96+
}
8597
}
8698

8799
sourceSets {

firebase-firestore/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
2626
"@gitlive/firebase-app": "1.2.0",
27-
"firebase": "8.2.10",
27+
"firebase": "8.5.0",
2828
"kotlin": "1.4.31",
2929
"kotlinx-coroutines-core": "1.4.3"
3030
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ class FirebaseFirestoreTest {
3939
@Test
4040
fun testStringOrderBy() = runTest {
4141
setupFirestoreData()
42-
43-
val resultDocs = Firebase.firestore.collection("FirebaseFirestoreTest")
44-
.orderBy("prop1").get().documents
42+
val resultDocs = Firebase.firestore
43+
.collection("FirebaseFirestoreTest")
44+
.orderBy("prop1")
45+
.get()
46+
.documents
4547
assertEquals(3, resultDocs.size)
4648
assertEquals("aaa", resultDocs[0].get("prop1"))
4749
assertEquals("bbb", resultDocs[1].get("prop1"))

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

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -471,25 +471,30 @@ inline fun <R> rethrow(function: () -> R): R {
471471
}
472472
}
473473

474-
fun errorToException(e: dynamic) = when(e?.code?.toString()?.toLowerCase()) {
475-
"cancelled" -> FirebaseFirestoreException(e, FirestoreExceptionCode.CANCELLED)
476-
"invalid-argument" -> FirebaseFirestoreException(e, FirestoreExceptionCode.INVALID_ARGUMENT)
477-
"deadline-exceeded" -> FirebaseFirestoreException(e, FirestoreExceptionCode.DEADLINE_EXCEEDED)
478-
"not-found" -> FirebaseFirestoreException(e, FirestoreExceptionCode.NOT_FOUND)
479-
"already-exists" -> FirebaseFirestoreException(e, FirestoreExceptionCode.ALREADY_EXISTS)
480-
"permission-denied" -> FirebaseFirestoreException(e, FirestoreExceptionCode.PERMISSION_DENIED)
481-
"resource-exhausted" -> FirebaseFirestoreException(e, FirestoreExceptionCode.RESOURCE_EXHAUSTED)
482-
"failed-precondition" -> FirebaseFirestoreException(e, FirestoreExceptionCode.FAILED_PRECONDITION)
483-
"aborted" -> FirebaseFirestoreException(e, FirestoreExceptionCode.ABORTED)
484-
"out-of-range" -> FirebaseFirestoreException(e, FirestoreExceptionCode.OUT_OF_RANGE)
485-
"unimplemented" -> FirebaseFirestoreException(e, FirestoreExceptionCode.UNIMPLEMENTED)
486-
"internal" -> FirebaseFirestoreException(e, FirestoreExceptionCode.INTERNAL)
487-
"unavailable" -> FirebaseFirestoreException(e, FirestoreExceptionCode.UNAVAILABLE)
488-
"data-loss" -> FirebaseFirestoreException(e, FirestoreExceptionCode.DATA_LOSS)
489-
"unauthenticated" -> FirebaseFirestoreException(e, FirestoreExceptionCode.UNAUTHENTICATED)
490-
"unknown" -> FirebaseFirestoreException(e, FirestoreExceptionCode.UNKNOWN)
491-
else -> {
492-
println("Unknown error code in ${JSON.stringify(e)}")
493-
FirebaseFirestoreException(e, FirestoreExceptionCode.UNKNOWN)
494-
}
474+
fun errorToException(e: dynamic) = (e?.code ?: e?.message ?: "")
475+
.toString()
476+
.toLowerCase()
477+
.let {
478+
when {
479+
"cancelled" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.CANCELLED)
480+
"invalid-argument" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.INVALID_ARGUMENT)
481+
"deadline-exceeded" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.DEADLINE_EXCEEDED)
482+
"not-found" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.NOT_FOUND)
483+
"already-exists" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.ALREADY_EXISTS)
484+
"permission-denied" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.PERMISSION_DENIED)
485+
"resource-exhausted" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.RESOURCE_EXHAUSTED)
486+
"failed-precondition" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.FAILED_PRECONDITION)
487+
"aborted" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.ABORTED)
488+
"out-of-range" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.OUT_OF_RANGE)
489+
"unimplemented" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.UNIMPLEMENTED)
490+
"internal" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.INTERNAL)
491+
"unavailable" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.UNAVAILABLE)
492+
"data-loss" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.DATA_LOSS)
493+
"unauthenticated" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.UNAUTHENTICATED)
494+
"unknown" in it -> FirebaseFirestoreException(e, FirestoreExceptionCode.UNKNOWN)
495+
else -> {
496+
println("Unknown error code in ${JSON.stringify(e)}")
497+
FirebaseFirestoreException(e, FirestoreExceptionCode.UNKNOWN)
498+
}
499+
}
495500
}

firebase-functions/build.gradle.kts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,20 @@ kotlin {
7272

7373
js {
7474
useCommonJs()
75-
nodejs()
76-
browser()
75+
nodejs {
76+
testTask {
77+
useMocha {
78+
timeout = "5s"
79+
}
80+
}
81+
}
82+
browser {
83+
testTask {
84+
useMocha {
85+
timeout = "5s"
86+
}
87+
}
88+
}
7789
}
7890

7991
sourceSets {

firebase-functions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
2626
"@gitlive/firebase-app": "1.2.0",
27-
"firebase": "8.2.10",
27+
"firebase": "8.5.0",
2828
"kotlin": "1.4.31",
2929
"kotlinx-coroutines-core": "1.4.3"
3030
}

0 commit comments

Comments
 (0)