Skip to content

updated dependencies, added setSettings() / disableNetwork() / enableNetwork() to FirebaseFirestore #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ buildscript {
}
}
dependencies {
classpath("com.android.tools.build:gradle:4.0.2")
classpath("com.android.tools.build:gradle:4.1.1")
classpath("de.undercouch:gradle-download-task:4.1.1")
classpath("com.adarshr:gradle-test-logger-plugin:2.0.0")
}
Expand Down
2 changes: 1 addition & 1 deletion firebase-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ kotlin {
}
val androidMain by getting {
dependencies {
api("com.google.firebase:firebase-common:19.4.0")
api("com.google.firebase:firebase-common:19.5.0")
}
}

Expand Down
4 changes: 2 additions & 2 deletions firebase-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
},
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
"dependencies": {
"@gitlive/firebase-common": "1.1.0",
"firebase": "8.2.0",
"@gitlive/firebase-common": "1.2.0",
"firebase": "8.2.3",
"kotlin": "1.4.21",
"kotlinx-coroutines-core": "1.4.2"
}
Expand Down
2 changes: 1 addition & 1 deletion firebase-app/src/iosMain/c_interop/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json" == 7.3.0
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json" == 7.4.0
2 changes: 1 addition & 1 deletion firebase-auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ kotlin {

val androidMain by getting {
dependencies {
api("com.google.firebase:firebase-auth:20.0.1")
api("com.google.firebase:firebase-auth:20.0.2")
}
}

Expand Down
4 changes: 2 additions & 2 deletions firebase-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
},
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
"dependencies": {
"@gitlive/firebase-app": "1.1.0",
"firebase": "8.2.0",
"@gitlive/firebase-app": "1.2.0",
"firebase": "8.2.3",
"kotlin": "1.4.21",
"kotlinx-coroutines-core": "1.4.2"
}
Expand Down
2 changes: 1 addition & 1 deletion firebase-auth/src/iosMain/c_interop/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAuthBinary.json" == 7.3.0
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAuthBinary.json" == 7.4.0
2 changes: 1 addition & 1 deletion firebase-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ kotlin {
}
val androidMain by getting {
dependencies {
api("com.google.firebase:firebase-common:19.4.0")
api("com.google.firebase:firebase-common:19.5.0")
}
}
val jsMain by getting {
Expand Down
2 changes: 1 addition & 1 deletion firebase-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-multiplatform-sdk",
"dependencies": {
"firebase": "8.2.0",
"firebase": "8.2.3",
"kotlin": "1.4.21",
"kotlinx-coroutines-core": "1.4.2",
"kotlinx-serialization-kotlinx-serialization-runtime": "1.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ external object firebase {
fun enablePersistence(): Promise<Unit>
fun clearPersistence(): Promise<Unit>
fun useEmulator(host: String, port: Int)
fun disableNetwork(): Promise<Unit>
fun enableNetwork(): Promise<Unit>
}

open class Settings {
val cacheSizeBytes: Long?
val host: String?
val ss: Boolean?
}

open class Timestamp {
Expand Down
2 changes: 1 addition & 1 deletion firebase-database/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ kotlin {
}
val androidMain by getting {
dependencies {
api("com.google.firebase:firebase-database:19.5.1")
api("com.google.firebase:firebase-database:19.6.0")
}
}
val jsMain by getting {}
Expand Down
4 changes: 2 additions & 2 deletions firebase-database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
},
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
"dependencies": {
"@gitlive/firebase-app": "1.1.0",
"firebase": "8.2.0",
"@gitlive/firebase-app": "1.2.0",
"firebase": "8.2.3",
"kotlin": "1.4.21",
"kotlinx-coroutines-core": "1.4.2"
}
Expand Down
2 changes: 1 addition & 1 deletion firebase-database/src/iosMain/c_interop/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseDatabaseBinary.json" == 7.3.0
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseDatabaseBinary.json" == 7.4.0
2 changes: 1 addition & 1 deletion firebase-firestore/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ kotlin {
}
val androidMain by getting {
dependencies {
api("com.google.firebase:firebase-firestore:22.0.0")
api("com.google.firebase:firebase-firestore:22.0.1")
implementation("com.android.support:multidex:1.0.3")
}
}
Expand Down
4 changes: 2 additions & 2 deletions firebase-firestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
},
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
"dependencies": {
"@gitlive/firebase-app": "1.1.0",
"firebase": "8.2.0",
"@gitlive/firebase-app": "1.2.0",
"firebase": "8.2.3",
"kotlin": "1.4.21",
"kotlinx-coroutines-core": "1.4.2"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ package dev.gitlive.firebase.firestore

import com.google.firebase.Timestamp
import com.google.firebase.firestore.FieldValue
import com.google.firebase.firestore.FirebaseFirestoreSettings
import com.google.firebase.firestore.SetOptions
import dev.gitlive.firebase.*
import dev.gitlive.firebase.firestore.encode
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.tasks.await
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.serializer

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

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

// actual var settings: FirebaseFirestoreSettings
// get() = android.firestoreSettings.run { FirebaseFirestoreSettings(isPersistenceEnabled) }
// set(value) {
// android.firestoreSettings = value.run { Builder().setPersistenceEnabled(persistenceEnabled).build() }
// }

actual fun collection(collectionPath: String) = CollectionReference(android.collection(collectionPath))

actual fun document(documentPath: String) = DocumentReference(android.document(documentPath))
Expand All @@ -65,10 +56,28 @@ actual class FirebaseFirestore(val android: com.google.firebase.firestore.Fireba

actual fun useEmulator(host: String, port: Int) {
android.useEmulator(host, port)
android.firestoreSettings = FirebaseFirestoreSettings.Builder()
android.firestoreSettings = com.google.firebase.firestore.FirebaseFirestoreSettings.Builder()
.setPersistenceEnabled(false)
.build()
}

actual fun setSettings(value: FirebaseFirestoreSettings) {
android.firestoreSettings = value.run {
com.google.firebase.firestore.FirebaseFirestoreSettings.Builder().also { builder ->
persistenceEnabled?.let { builder.setPersistenceEnabled(it) }
sslEnabled?.let { builder.isSslEnabled = it }
host?.let { builder.host = it }
cacheSizeBytes?.let { builder.cacheSizeBytes = it }
}.build()
}
}

actual suspend fun disableNetwork() {
android.disableNetwork().await().run { }
}
actual suspend fun enableNetwork() {
android.enableNetwork().await().run { }
}
}

actual class WriteBatch(val android: com.google.firebase.firestore.WriteBatch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ expect val Firebase.firestore: FirebaseFirestore
expect fun Firebase.firestore(app: FirebaseApp): FirebaseFirestore

expect class FirebaseFirestore {
// var settings: FirebaseFirestoreSettings
fun collection(collectionPath: String): CollectionReference
fun document(documentPath: String): DocumentReference
fun batch(): WriteBatch
fun setLoggingEnabled(loggingEnabled: Boolean)
suspend fun clearPersistence()
suspend fun <T> runTransaction(func: suspend Transaction.() -> T): T
fun useEmulator(host: String, port: Int)
fun setSettings(value: FirebaseFirestoreSettings)
suspend fun disableNetwork()
suspend fun enableNetwork()
}

expect class Transaction {
Expand All @@ -49,9 +51,12 @@ expect class Transaction {
suspend fun get(documentRef: DocumentReference): DocumentSnapshot
}

//data class FirebaseFirestoreSettings(
// val persistenceEnabled: Boolean = true
//)
data class FirebaseFirestoreSettings(
val persistenceEnabled: Boolean? = null,
val sslEnabled: Boolean? = null,
val host: String? = null,
val cacheSizeBytes: Long? = null
)

expect open class Query {
fun limit(limit: Number): Query
Expand Down
2 changes: 1 addition & 1 deletion firebase-firestore/src/iosMain/c_interop/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseFirestoreBinary.json" == 7.3.0
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseFirestoreBinary.json" == 7.4.0
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ actual class FirebaseFirestore(val ios: FIRFirestore) {
FIRFirestore.enableLogging(loggingEnabled)

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

actual suspend fun clearPersistence() =
await { ios.clearPersistenceWithCompletion(it) }
Expand All @@ -62,6 +62,25 @@ actual class FirebaseFirestore(val ios: FIRFirestore) {
sslEnabled = false
}
}

actual fun setSettings(value: FirebaseFirestoreSettings) {
ios.settings = value.run {
FIRFirestoreSettings().also { settings ->
persistenceEnabled?.let { settings.persistenceEnabled = it }
sslEnabled?.let { settings.sslEnabled = it }
host?.let { settings.host }
cacheSizeBytes?.let { settings.cacheSizeBytes = it }
}
}
}

actual suspend fun disableNetwork() {
await { ios.disableNetworkWithCompletion(it) }
}

actual suspend fun enableNetwork() {
await { ios.enableNetworkWithCompletion(it) }
}
}

@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

package dev.gitlive.firebase.firestore

import dev.gitlive.firebase.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.await
Expand Down Expand Up @@ -35,12 +36,6 @@ actual fun Firebase.firestore(app: FirebaseApp) =

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

// actual var settings: FirebaseFirestoreSettings
// get() = js.settings().run { FirebaseFirestoreSettings(js.isPersistenceEnabled) }
// set(value) {
// js.settings() = value.run { Builder().setPersistenceEnabled(persistenceEnabled).build() }
// }

actual fun collection(collectionPath: String) = rethrow { CollectionReference(js.collection(collectionPath)) }

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

actual fun useEmulator(host: String, port: Int) = rethrow { js.useEmulator(host, port) }

actual fun setSettings(value: FirebaseFirestoreSettings) {
value.run {
persistenceEnabled?.let { js.enablePersistence() }

val settingsJson = mutableListOf<Pair<String, Any>>()

sslEnabled?.let { settingsJson.add("ssl" to it) }
host?.let { settingsJson.add("host" to it) }
cacheSizeBytes?.let { settingsJson.add("cacheSizeBytes" to it) }

js.settings(json(*settingsJson.toTypedArray()))
}
}

actual suspend fun disableNetwork() {
rethrow { js.disableNetwork().await() }
}

actual suspend fun enableNetwork() {
rethrow { js.enableNetwork().await() }
}
}

actual class WriteBatch(val js: firebase.firestore.WriteBatch) {
Expand Down
2 changes: 1 addition & 1 deletion firebase-functions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ kotlin {
}
val androidMain by getting {
dependencies {
api("com.google.firebase:firebase-functions:19.1.0")
api("com.google.firebase:firebase-functions:19.2.0")
}
}
val iosMain by getting {}
Expand Down
4 changes: 2 additions & 2 deletions firebase-functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
},
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
"dependencies": {
"@gitlive/firebase-app": "1.1.0",
"firebase": "8.2.0",
"@gitlive/firebase-app": "1.2.0",
"firebase": "8.2.3",
"kotlin": "1.4.21",
"kotlinx-coroutines-core": "1.4.2"
}
Expand Down
2 changes: 1 addition & 1 deletion firebase-functions/src/iosMain/c_interop/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseFunctionsBinary.json" == 7.3.0
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseFunctionsBinary.json" == 7.4.0