Skip to content

Commit be096bd

Browse files
committed
upgrade storage to js v9
1 parent ff85d16 commit be096bd

File tree

13 files changed

+134
-24
lines changed

13 files changed

+134
-24
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ external fun updatePassword(user: User, newPassword: String): Promise<Unit>
9595

9696
external fun updatePhoneNumber(user: User, phoneCredential: AuthCredential): Promise<Unit>
9797

98-
external fun updateProfile(user: User, profile: ProfileUpdateRequest): Promise<Unit>
98+
external fun updateProfile(user: User, profile: Json): Promise<Unit>
9999

100100
external fun verifyBeforeUpdateEmail(
101101
user: User,

firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth/user.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ actual class FirebaseUser internal constructor(val js: User) {
4545
actual suspend fun updateEmail(email: String) = rethrow { updateEmail(js, email).await() }
4646
actual suspend fun updatePassword(password: String) = rethrow { updatePassword(js, password).await() }
4747
actual suspend fun updatePhoneNumber(credential: PhoneAuthCredential) = rethrow { updatePhoneNumber(js, credential.js).await() }
48-
actual suspend fun updateProfile(displayName: String?, photoUrl: String?) = rethrow {
48+
actual suspend fun updateProfile(displayName: String?, photoUrl: String?): Unit = rethrow {
4949
val request = listOfNotNull(
5050
displayName.takeUnless { it === UNCHANGED }?.let { "displayName" to it },
5151
photoUrl.takeUnless { it === UNCHANGED }?.let { "photoURL" to it }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ inline fun <R> rethrow(function: () -> R): R {
223223
}
224224
}
225225

226-
suspend fun <T> Promise<T>.awaitWhileOnline(database: firebase.database.Database): T = coroutineScope {
226+
suspend fun <T> Promise<T>.awaitWhileOnline(database: Database): T = coroutineScope {
227227

228228
val notConnected = FirebaseDatabase(database)
229229
.reference(".info/connected")

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ external interface ThenableReference : DatabaseReference
126126
external interface DataSnapshot {
127127
val key: String?
128128
val size: Int
129+
val ref: DatabaseReference
129130
fun `val`(): Any
130131
fun exists(): Boolean
131132
fun forEach(action: (a: DataSnapshot) -> Boolean): Boolean
132133
fun child(path: String): DataSnapshot
134+
fun hasChildren(): Boolean;
133135
}
134136

135137
external interface OnDisconnect {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dev.gitlive.firebase.*
44
import kotlinx.serialization.Serializable
55

66
/** A class representing a platform specific Firebase GeoPoint. */
7-
actual typealias NativeGeoPoint = firebase.firestore.GeoPoint
7+
actual typealias NativeGeoPoint = dev.gitlive.firebase.firestore.externals.GeoPoint
88

99
/** A class representing a Firebase GeoPoint. */
1010
@Serializable(with = GeoPointSerializer::class)

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ external class FieldPath(vararg fieldNames: String) {
1212
companion object {
1313
val documentId: FieldPath
1414
}
15+
fun isEqual(other: FieldPath): Boolean
16+
1517
}
1618

19+
external fun refEqual(left: DocumentReference, right: DocumentReference): Boolean
20+
1721
external fun addDoc(reference: CollectionReference, data: Any): Promise<DocumentReference>
1822

1923
external fun arrayRemove(vararg elements: Any): FieldValue
@@ -81,6 +85,13 @@ external fun onSnapshot(
8185
error: (error: Throwable) -> Unit
8286
): Unsubscribe
8387

88+
external fun onSnapshot(
89+
reference: DocumentReference,
90+
options: Json,
91+
next: (snapshot: DocumentSnapshot) -> Unit,
92+
error: (error: Throwable) -> Unit
93+
): Unsubscribe
94+
8495
external fun onSnapshot(
8596
reference: Query,
8697
next: (snapshot: QuerySnapshot) -> Unit,
@@ -150,6 +161,12 @@ external interface Firestore {
150161
val app: FirebaseApp
151162
}
152163

164+
external class GeoPoint constructor(latitude: Double, longitude: Double) {
165+
val latitude: Double
166+
val longitude: Double
167+
fun isEqual(other: GeoPoint): Boolean
168+
}
169+
153170
external interface CollectionReference : Query {
154171
val id: String
155172
val path: String
@@ -163,7 +180,7 @@ external interface DocumentChange {
163180
val type: String
164181
}
165182

166-
external interface DocumentReference {
183+
external class DocumentReference {
167184
val id: String
168185
val path: String
169186
val parent: CollectionReference

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ actual class DocumentReference actual constructor(internal actual val nativeValu
282282
}
283283

284284
override fun equals(other: Any?): Boolean =
285-
this === other || other is DocumentReference && nativeValue.isEqual(other.nativeValue)
285+
this === other || other is DocumentReference && refEqual(nativeValue, other.nativeValue)
286286
override fun hashCode(): Int = nativeValue.hashCode()
287287
override fun toString(): String = "DocumentReference(path=$path)"
288288
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ actual class FirebaseStorage(val android: com.google.firebase.storage.FirebaseSt
4343
android.useEmulator(host, port)
4444
}
4545

46-
actual val reference = StorageReference(android.reference)
46+
actual val reference get() = StorageReference(android.reference)
47+
48+
actual fun reference(location: String )= StorageReference(android.getReference(location))
49+
4750
}
4851

4952
actual class StorageReference(val android: com.google.firebase.storage.StorageReference) {
@@ -62,6 +65,8 @@ actual class StorageReference(val android: com.google.firebase.storage.StorageRe
6265

6366
actual suspend fun listAll(): ListResult = ListResult(android.listAll().await())
6467

68+
actual suspend fun putFile(file: File) = android.putFile(file.uri).await().run {}
69+
6570
actual fun putFileResumable(file: File): ProgressFlow {
6671
val android = android.putFile(file.uri)
6772

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ expect class FirebaseStorage {
2020
fun useEmulator(host: String, port: Int)
2121

2222
val reference: StorageReference
23+
fun reference(location: String): StorageReference
24+
2325
}
2426

2527
expect class StorageReference {
@@ -38,6 +40,8 @@ expect class StorageReference {
3840

3941
suspend fun listAll(): ListResult
4042

43+
suspend fun putFile(file: File)
44+
4145
fun putFileResumable(file: File): ProgressFlow
4246
}
4347

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ actual class FirebaseStorage(val ios: FIRStorage) {
5050
}
5151

5252
actual val reference get() = StorageReference(ios.reference())
53+
54+
actual fun reference(location: String) = StorageReference(ios.referenceWithPath(location))
5355
}
5456

5557
actual class StorageReference(val ios: FIRStorageReference) {
@@ -74,6 +76,8 @@ actual class StorageReference(val ios: FIRStorageReference) {
7476
}
7577
}
7678

79+
actual suspend fun putFile(file: File) = ios.awaitResult { putFile(file.url, null, completion = it) }.run {}
80+
7781
actual fun putFileResumable(file: File): ProgressFlow {
7882
val ios = ios.putFile(file.url)
7983

0 commit comments

Comments
 (0)