Skip to content

Commit

Permalink
Settings as write only property
Browse files Browse the repository at this point in the history
  • Loading branch information
Daeda88 committed Jul 11, 2024
1 parent 4be99fd commit c987bea
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
4 changes: 2 additions & 2 deletions firebase-firestore/api/android/firebase-firestore.api
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,18 @@ public final class dev/gitlive/firebase/firestore/FilterBuilder {

public final class dev/gitlive/firebase/firestore/FirebaseFirestore {
public static final field Companion Ldev/gitlive/firebase/firestore/FirebaseFirestore$Companion;
public final fun applySettings (Ldev/gitlive/firebase/firestore/FirebaseFirestoreSettings;)V
public final fun batch ()Ldev/gitlive/firebase/firestore/WriteBatch;
public final fun clearPersistence (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun collection (Ljava/lang/String;)Ldev/gitlive/firebase/firestore/CollectionReference;
public final fun collectionGroup (Ljava/lang/String;)Ldev/gitlive/firebase/firestore/Query;
public final fun disableNetwork (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun document (Ljava/lang/String;)Ldev/gitlive/firebase/firestore/DocumentReference;
public final fun enableNetwork (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getSettings ()Ldev/gitlive/firebase/firestore/FirebaseFirestoreSettings;
public final fun runTransaction (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun setLoggingEnabled (Z)V
public final fun setSettings (Ldev/gitlive/firebase/firestore/FirebaseFirestoreSettings;)V
public final fun setSettings (Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/Long;)V
public final fun setSettings (Lkotlin/jvm/functions/Function1;)V
public static synthetic fun setSettings$default (Ldev/gitlive/firebase/firestore/FirebaseFirestore;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/Long;ILjava/lang/Object;)V
public final fun useEmulator (Ljava/lang/String;I)V
}
Expand Down
4 changes: 2 additions & 2 deletions firebase-firestore/api/jvm/firebase-firestore.api
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,18 @@ public final class dev/gitlive/firebase/firestore/FilterBuilder {

public final class dev/gitlive/firebase/firestore/FirebaseFirestore {
public static final field Companion Ldev/gitlive/firebase/firestore/FirebaseFirestore$Companion;
public final fun applySettings (Ldev/gitlive/firebase/firestore/FirebaseFirestoreSettings;)V
public final fun batch ()Ldev/gitlive/firebase/firestore/WriteBatch;
public final fun clearPersistence (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun collection (Ljava/lang/String;)Ldev/gitlive/firebase/firestore/CollectionReference;
public final fun collectionGroup (Ljava/lang/String;)Ldev/gitlive/firebase/firestore/Query;
public final fun disableNetwork (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun document (Ljava/lang/String;)Ldev/gitlive/firebase/firestore/DocumentReference;
public final fun enableNetwork (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getSettings ()Ldev/gitlive/firebase/firestore/FirebaseFirestoreSettings;
public final fun runTransaction (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun setLoggingEnabled (Z)V
public final fun setSettings (Ldev/gitlive/firebase/firestore/FirebaseFirestoreSettings;)V
public final fun setSettings (Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/Long;)V
public final fun setSettings (Lkotlin/jvm/functions/Function1;)V
public static synthetic fun setSettings$default (Ldev/gitlive/firebase/firestore/FirebaseFirestore;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/Long;ILjava/lang/Object;)V
public final fun useEmulator (Ljava/lang/String;I)V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public class FirebaseFirestore internal constructor(private val wrapper: NativeF
// Important to leave this as a get property since on JS it is initialized lazily
internal val native: NativeFirebaseFirestore get() = wrapper.native

public var settings: FirebaseFirestoreSettings
@Deprecated("Property can only be written.", level = DeprecationLevel.ERROR)
get() = throw NotImplementedError()
set(value) {
wrapper.applySettings(value)
}

public fun collection(collectionPath: String): CollectionReference = CollectionReference(wrapper.collection(collectionPath))
public fun collectionGroup(collectionId: String): Query = Query(wrapper.collectionGroup(collectionId))
public fun document(documentPath: String): DocumentReference = DocumentReference(wrapper.document(documentPath))
Expand All @@ -60,36 +67,33 @@ public class FirebaseFirestore internal constructor(private val wrapper: NativeF
wrapper.useEmulator(host, port)
}

@Deprecated("Use SettingsBuilder instead", replaceWith = ReplaceWith("setSettings { }"))
@Deprecated("Use SettingsBuilder instead", replaceWith = ReplaceWith("settings = firestoreSettings { }", "dev.gitlive.firebase.firestore.firestoreSettings"))
public fun setSettings(
persistenceEnabled: Boolean? = null,
sslEnabled: Boolean? = null,
host: String? = null,
cacheSizeBytes: Long? = null,
): Unit = setSettings {
this.sslEnabled = sslEnabled ?: true
this.host = host ?: FirebaseFirestoreSettings.DEFAULT_HOST
this.cacheSettings = if (persistenceEnabled != false) {
LocalCacheSettings.Persistent(cacheSizeBytes ?: FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED)
} else {
val cacheSize = cacheSizeBytes ?: FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED
val garbageCollectionSettings = if (cacheSize == FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED) {
MemoryGarbageCollectorSettings.Eager
) {
settings = firestoreSettings {
this.sslEnabled = sslEnabled ?: true
this.host = host ?: FirebaseFirestoreSettings.DEFAULT_HOST
this.cacheSettings = if (persistenceEnabled != false) {
LocalCacheSettings.Persistent(
cacheSizeBytes ?: FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED,
)
} else {
MemoryGarbageCollectorSettings.LRUGC(cacheSize)
val cacheSize = cacheSizeBytes ?: FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED
val garbageCollectionSettings =
if (cacheSize == FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED) {
MemoryGarbageCollectorSettings.Eager
} else {
MemoryGarbageCollectorSettings.LRUGC(cacheSize)
}
LocalCacheSettings.Memory(garbageCollectionSettings)
}
LocalCacheSettings.Memory(garbageCollectionSettings)
}
}

public fun applySettings(settings: FirebaseFirestoreSettings) {
wrapper.applySettings(settings)
}

public fun setSettings(builder: FirebaseFirestoreSettings.Builder.() -> Unit): Unit = wrapper.applySettings(
firestoreSettings(builder = builder),
)

public suspend fun disableNetwork() {
wrapper.disableNetwork()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FirestoreSourceTest {
)

firestore = Firebase.firestore(app).apply {
setSettings {
settings = firestoreSettings {
cacheSettings = if (persistenceEnabled) {
persistentCacheSettings { }
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class FirebaseFirestoreTest {
firebaseApp = app

firestore = Firebase.firestore(app).apply {
setSettings {
settings = firestoreSettings {
cacheSettings = memoryCacheSettings {
gcSettings = memoryEagerGcSettings { }
}
Expand Down

0 comments on commit c987bea

Please sign in to comment.