Skip to content

Commit ae90c6d

Browse files
suntrixnbransby
andauthored
updated dependencies, added setSettings() / disableNetwork() / enableNetwork() to FirebaseFirestore (#138)
* updated dependencies, added setSettings() / disableNetwork() / enableNetwork() to FirebaseFirestore * PR feedback * rename settings back to setSettings * handle when sslEnabled is false correctly Co-authored-by: nbransby <[email protected]>
1 parent 9558271 commit ae90c6d

File tree

23 files changed

+83
-47
lines changed

23 files changed

+83
-47
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ buildscript {
1919
}
2020
}
2121
dependencies {
22-
classpath("com.android.tools.build:gradle:4.0.2")
22+
classpath("com.android.tools.build:gradle:4.1.1")
2323
classpath("de.undercouch:gradle-download-task:4.1.1")
2424
classpath("com.adarshr:gradle-test-logger-plugin:2.0.0")
2525
}

firebase-app/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ kotlin {
6868
}
6969
val androidMain by getting {
7070
dependencies {
71-
api("com.google.firebase:firebase-common:19.4.0")
71+
api("com.google.firebase:firebase-common:19.5.0")
7272
}
7373
}
7474

firebase-app/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
},
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
26-
"@gitlive/firebase-common": "1.1.0",
27-
"firebase": "8.2.0",
26+
"@gitlive/firebase-common": "1.2.0",
27+
"firebase": "8.2.3",
2828
"kotlin": "1.4.21",
2929
"kotlinx-coroutines-core": "1.4.2"
3030
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json" == 7.3.0
1+
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json" == 7.4.0

firebase-auth/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ kotlin {
102102

103103
val androidMain by getting {
104104
dependencies {
105-
api("com.google.firebase:firebase-auth:20.0.1")
105+
api("com.google.firebase:firebase-auth:20.0.2")
106106
}
107107
}
108108

firebase-auth/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
},
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
26-
"@gitlive/firebase-app": "1.1.0",
27-
"firebase": "8.2.0",
26+
"@gitlive/firebase-app": "1.2.0",
27+
"firebase": "8.2.3",
2828
"kotlin": "1.4.21",
2929
"kotlinx-coroutines-core": "1.4.2"
3030
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAuthBinary.json" == 7.3.0
1+
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAuthBinary.json" == 7.4.0

firebase-common/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ kotlin {
6868
}
6969
val androidMain by getting {
7070
dependencies {
71-
api("com.google.firebase:firebase-common:19.4.0")
71+
api("com.google.firebase:firebase-common:19.5.0")
7272
}
7373
}
7474
val jsMain by getting {

firebase-common/package.json

+1-1
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.0",
26+
"firebase": "8.2.3",
2727
"kotlin": "1.4.21",
2828
"kotlinx-coroutines-core": "1.4.2",
2929
"kotlinx-serialization-kotlinx-serialization-runtime": "1.0.1"

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

+2
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ external object firebase {
344344
fun enablePersistence(): Promise<Unit>
345345
fun clearPersistence(): Promise<Unit>
346346
fun useEmulator(host: String, port: Int)
347+
fun disableNetwork(): Promise<Unit>
348+
fun enableNetwork(): Promise<Unit>
347349
}
348350

349351
open class Timestamp {

firebase-database/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ kotlin {
7676
}
7777
val androidMain by getting {
7878
dependencies {
79-
api("com.google.firebase:firebase-database:19.5.1")
79+
api("com.google.firebase:firebase-database:19.6.0")
8080
}
8181
}
8282
val jsMain by getting {}

firebase-database/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
},
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
26-
"@gitlive/firebase-app": "1.1.0",
27-
"firebase": "8.2.0",
26+
"@gitlive/firebase-app": "1.2.0",
27+
"firebase": "8.2.3",
2828
"kotlin": "1.4.21",
2929
"kotlinx-coroutines-core": "1.4.2"
3030
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseDatabaseBinary.json" == 7.3.0
1+
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseDatabaseBinary.json" == 7.4.0

firebase-firestore/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ kotlin {
7878
}
7979
val androidMain by getting {
8080
dependencies {
81-
api("com.google.firebase:firebase-firestore:22.0.0")
81+
api("com.google.firebase:firebase-firestore:22.0.1")
8282
implementation("com.android.support:multidex:1.0.3")
8383
}
8484
}

firebase-firestore/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
},
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
26-
"@gitlive/firebase-app": "1.1.0",
27-
"firebase": "8.2.0",
26+
"@gitlive/firebase-app": "1.2.0",
27+
"firebase": "8.2.3",
2828
"kotlin": "1.4.21",
2929
"kotlinx-coroutines-core": "1.4.2"
3030
}

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

+18-12
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ package dev.gitlive.firebase.firestore
77

88
import com.google.firebase.Timestamp
99
import com.google.firebase.firestore.FieldValue
10-
import com.google.firebase.firestore.FirebaseFirestoreSettings
1110
import com.google.firebase.firestore.SetOptions
1211
import dev.gitlive.firebase.*
13-
import dev.gitlive.firebase.firestore.encode
1412
import kotlinx.coroutines.channels.awaitClose
1513
import kotlinx.coroutines.flow.callbackFlow
1614
import kotlinx.coroutines.runBlocking
1715
import kotlinx.coroutines.tasks.await
1816
import kotlinx.serialization.DeserializationStrategy
1917
import kotlinx.serialization.SerializationStrategy
20-
import kotlinx.serialization.serializer
2118

2219
@PublishedApi
2320
internal inline fun <reified T> decode(value: Any?): T =
@@ -41,12 +38,6 @@ actual fun Firebase.firestore(app: FirebaseApp) =
4138

4239
actual class FirebaseFirestore(val android: com.google.firebase.firestore.FirebaseFirestore) {
4340

44-
// actual var settings: FirebaseFirestoreSettings
45-
// get() = android.firestoreSettings.run { FirebaseFirestoreSettings(isPersistenceEnabled) }
46-
// set(value) {
47-
// android.firestoreSettings = value.run { Builder().setPersistenceEnabled(persistenceEnabled).build() }
48-
// }
49-
5041
actual fun collection(collectionPath: String) = CollectionReference(android.collection(collectionPath))
5142

5243
actual fun document(documentPath: String) = DocumentReference(android.document(documentPath))
@@ -60,15 +51,30 @@ actual class FirebaseFirestore(val android: com.google.firebase.firestore.Fireba
6051
android.runTransaction { runBlocking { Transaction(it).func() } }.await()
6152

6253
actual suspend fun clearPersistence() =
63-
android.clearPersistence().await()
64-
.run { Unit }
54+
android.clearPersistence().await().run { }
6555

6656
actual fun useEmulator(host: String, port: Int) {
6757
android.useEmulator(host, port)
68-
android.firestoreSettings = FirebaseFirestoreSettings.Builder()
58+
android.firestoreSettings = com.google.firebase.firestore.FirebaseFirestoreSettings.Builder()
6959
.setPersistenceEnabled(false)
7060
.build()
7161
}
62+
63+
actual fun setSettings(persistenceEnabled: Boolean?, sslEnabled: Boolean?, host: String?, cacheSizeBytes: Long?) {
64+
android.firestoreSettings = com.google.firebase.firestore.FirebaseFirestoreSettings.Builder().also { builder ->
65+
persistenceEnabled?.let { builder.setPersistenceEnabled(it) }
66+
sslEnabled?.let { builder.isSslEnabled = it }
67+
host?.let { builder.host = it }
68+
cacheSizeBytes?.let { builder.cacheSizeBytes = it }
69+
}.build()
70+
}
71+
72+
actual suspend fun disableNetwork() =
73+
android.disableNetwork().await().run { }
74+
75+
actual suspend fun enableNetwork() =
76+
android.enableNetwork().await().run { }
77+
7278
}
7379

7480
actual class WriteBatch(val android: com.google.firebase.firestore.WriteBatch) {

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ expect val Firebase.firestore: FirebaseFirestore
1919
expect fun Firebase.firestore(app: FirebaseApp): FirebaseFirestore
2020

2121
expect class FirebaseFirestore {
22-
// var settings: FirebaseFirestoreSettings
2322
fun collection(collectionPath: String): CollectionReference
2423
fun document(documentPath: String): DocumentReference
2524
fun batch(): WriteBatch
2625
fun setLoggingEnabled(loggingEnabled: Boolean)
2726
suspend fun clearPersistence()
2827
suspend fun <T> runTransaction(func: suspend Transaction.() -> T): T
2928
fun useEmulator(host: String, port: Int)
29+
fun setSettings(persistenceEnabled: Boolean? = null, sslEnabled: Boolean? = null, host: String? = null, cacheSizeBytes: Long? = null)
30+
suspend fun disableNetwork()
31+
suspend fun enableNetwork()
3032
}
3133

3234
expect class Transaction {
@@ -49,10 +51,6 @@ expect class Transaction {
4951
suspend fun get(documentRef: DocumentReference): DocumentSnapshot
5052
}
5153

52-
//data class FirebaseFirestoreSettings(
53-
// val persistenceEnabled: Boolean = true
54-
//)
55-
5654
expect open class Query {
5755
fun limit(limit: Number): Query
5856
val snapshots: Flow<QuerySnapshot>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseFirestoreBinary.json" == 7.3.0
1+
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseFirestoreBinary.json" == 7.4.0

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ actual class FirebaseFirestore(val ios: FIRFirestore) {
5050
FIRFirestore.enableLogging(loggingEnabled)
5151

5252
actual suspend fun <T> runTransaction(func: suspend Transaction.() -> T) =
53-
awaitResult<Any?> { ios.runTransactionWithBlock({ transaction, error -> runBlocking { Transaction(transaction!!).func() } }, it) } as T
53+
awaitResult<Any?> { ios.runTransactionWithBlock({ transaction, _ -> runBlocking { Transaction(transaction!!).func() } }, it) } as T
5454

5555
actual suspend fun clearPersistence() =
5656
await { ios.clearPersistenceWithCompletion(it) }
@@ -62,6 +62,23 @@ actual class FirebaseFirestore(val ios: FIRFirestore) {
6262
sslEnabled = false
6363
}
6464
}
65+
66+
actual fun setSettings(persistenceEnabled: Boolean?, sslEnabled: Boolean?, host: String?, cacheSizeBytes: Long?) {
67+
ios.settings = FIRFirestoreSettings().also { settings ->
68+
persistenceEnabled?.let { settings.persistenceEnabled = it }
69+
sslEnabled?.let { settings.sslEnabled = it }
70+
host?.let { settings.host = it }
71+
cacheSizeBytes?.let { settings.cacheSizeBytes = it }
72+
}
73+
}
74+
75+
actual suspend fun disableNetwork() {
76+
await { ios.disableNetworkWithCompletion(it) }
77+
}
78+
79+
actual suspend fun enableNetwork() {
80+
await { ios.enableNetworkWithCompletion(it) }
81+
}
6582
}
6683

6784
@Suppress("UNCHECKED_CAST")

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

+19-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
package dev.gitlive.firebase.firestore
6+
67
import dev.gitlive.firebase.*
78
import kotlinx.coroutines.GlobalScope
89
import kotlinx.coroutines.await
@@ -35,12 +36,6 @@ actual fun Firebase.firestore(app: FirebaseApp) =
3536

3637
actual class FirebaseFirestore(val js: firebase.firestore.Firestore) {
3738

38-
// actual var settings: FirebaseFirestoreSettings
39-
// get() = js.settings().run { FirebaseFirestoreSettings(js.isPersistenceEnabled) }
40-
// set(value) {
41-
// js.settings() = value.run { Builder().setPersistenceEnabled(persistenceEnabled).build() }
42-
// }
43-
4439
actual fun collection(collectionPath: String) = rethrow { CollectionReference(js.collection(collectionPath)) }
4540

4641
actual fun document(documentPath: String) = rethrow { DocumentReference(js.doc(documentPath)) }
@@ -57,6 +52,24 @@ actual class FirebaseFirestore(val js: firebase.firestore.Firestore) {
5752
rethrow { js.clearPersistence().await() }
5853

5954
actual fun useEmulator(host: String, port: Int) = rethrow { js.useEmulator(host, port) }
55+
56+
actual fun setSettings(persistenceEnabled: Boolean?, sslEnabled: Boolean?, host: String?, cacheSizeBytes: Long?) {
57+
if(persistenceEnabled == true) js.enablePersistence()
58+
59+
js.settings(json().apply {
60+
sslEnabled?.let { set("ssl", it) }
61+
host?.let { set("host", it) }
62+
cacheSizeBytes?.let { set("cacheSizeBytes", it) }
63+
})
64+
}
65+
66+
actual suspend fun disableNetwork() {
67+
rethrow { js.disableNetwork().await() }
68+
}
69+
70+
actual suspend fun enableNetwork() {
71+
rethrow { js.enableNetwork().await() }
72+
}
6073
}
6174

6275
actual class WriteBatch(val js: firebase.firestore.WriteBatch) {

firebase-functions/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ kotlin {
7070
}
7171
val androidMain by getting {
7272
dependencies {
73-
api("com.google.firebase:firebase-functions:19.1.0")
73+
api("com.google.firebase:firebase-functions:19.2.0")
7474
}
7575
}
7676
val iosMain by getting {}

firebase-functions/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
},
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
26-
"@gitlive/firebase-app": "1.1.0",
27-
"firebase": "8.2.0",
26+
"@gitlive/firebase-app": "1.2.0",
27+
"firebase": "8.2.3",
2828
"kotlin": "1.4.21",
2929
"kotlinx-coroutines-core": "1.4.2"
3030
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseFunctionsBinary.json" == 7.3.0
1+
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseFunctionsBinary.json" == 7.4.0

0 commit comments

Comments
 (0)