Skip to content

Commit 9e4422e

Browse files
committed
Revert formatting
1 parent 3846b15 commit 9e4422e

File tree

3 files changed

+34
-74
lines changed
  • firebase-app/src/jsMain/kotlin/dev/gitlive/firebase
  • firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth
  • firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database

3 files changed

+34
-74
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import dev.gitlive.firebase.externals.app.initializeApp
1010
import kotlin.js.json
1111
import dev.gitlive.firebase.externals.app.FirebaseApp as JsFirebaseApp
1212

13-
actual val Firebase.app: FirebaseApp get() = FirebaseApp(getApp())
13+
actual val Firebase.app: FirebaseApp
14+
get() = FirebaseApp(getApp())
1415

15-
actual fun Firebase.app(name: String): FirebaseApp = FirebaseApp(getApp(name))
16+
actual fun Firebase.app(name: String): FirebaseApp =
17+
FirebaseApp(getApp(name))
1618

1719
actual fun Firebase.initialize(context: Any?): FirebaseApp? =
1820
throw UnsupportedOperationException("Cannot initialize firebase without options in JS")
@@ -28,16 +30,7 @@ actual class FirebaseApp internal constructor(val js: JsFirebaseApp) {
2830
get() = js.name
2931
actual val options: FirebaseOptions
3032
get() = js.options.run {
31-
FirebaseOptions(
32-
js.options.appId,
33-
js.options.apiKey,
34-
js.options.databaseURL,
35-
js.options.gaTrackingId,
36-
js.options.storageBucket,
37-
js.options.projectId,
38-
js.options.messagingSenderId,
39-
js.options.authDomain
40-
)
33+
FirebaseOptions(appId, apiKey, databaseURL, gaTrackingId, storageBucket, projectId, messagingSenderId, authDomain)
4134
}
4235
}
4336

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,12 @@ actual class FirebaseAuth internal constructor(val js: Auth) {
4343
set(value) { js.languageCode = value }
4444

4545
actual suspend fun applyActionCode(code: String) = rethrow { applyActionCode(js, code).await() }
46-
actual suspend fun confirmPasswordReset(code: String, newPassword: String) = rethrow {
47-
confirmPasswordReset(js, code, newPassword).await()
48-
}
46+
actual suspend fun confirmPasswordReset(code: String, newPassword: String) = rethrow { confirmPasswordReset(js, code, newPassword).await() }
4947

5048
actual suspend fun createUserWithEmailAndPassword(email: String, password: String) =
5149
rethrow { AuthResult(createUserWithEmailAndPassword(js, email, password).await()) }
5250

53-
actual suspend fun fetchSignInMethodsForEmail(email: String): List<String> = rethrow {
54-
fetchSignInMethodsForEmail(js, email).await().asList()
55-
}
51+
actual suspend fun fetchSignInMethodsForEmail(email: String): List<String> = rethrow { fetchSignInMethodsForEmail(js, email).await().asList() }
5652

5753
actual suspend fun sendPasswordResetEmail(email: String, actionCodeSettings: ActionCodeSettings?) =
5854
rethrow { sendPasswordResetEmail(js, email, actionCodeSettings?.toJson()).await() }
@@ -105,9 +101,7 @@ actual class FirebaseAuth internal constructor(val js: Auth) {
105101
} as T
106102
}
107103

108-
actual fun useEmulator(host: String, port: Int) = rethrow {
109-
connectAuthEmulator(js, "http://$host:$port")
110-
}
104+
actual fun useEmulator(host: String, port: Int) = rethrow { connectAuthEmulator(js, "http://$host:$port") }
111105
}
112106

113107
actual class AuthResult internal constructor(val js: JsAuthResult) {

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

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import kotlinx.coroutines.selects.select
1616
import kotlinx.serialization.DeserializationStrategy
1717
import kotlinx.serialization.SerializationStrategy
1818
import kotlin.js.Promise
19+
import kotlin.js.json
1920
import dev.gitlive.firebase.externals.database.DataSnapshot as JsDataSnapshot
2021
import dev.gitlive.firebase.externals.database.DatabaseReference as JsDatabaseReference
2122
import dev.gitlive.firebase.externals.database.OnDisconnect as JsOnDisconnect
@@ -33,19 +34,18 @@ import dev.gitlive.firebase.externals.database.startAt as jsStartAt
3334
internal inline fun <reified T> encode(value: T, shouldEncodeElementDefault: Boolean) =
3435
encode(value, shouldEncodeElementDefault, serverTimestamp())
3536

36-
internal fun <T> encode(
37-
strategy: SerializationStrategy<T>,
38-
value: T,
39-
shouldEncodeElementDefault: Boolean
40-
): Any? = encode(strategy, value, shouldEncodeElementDefault, serverTimestamp())
37+
internal fun <T> encode(strategy: SerializationStrategy<T>, value: T, shouldEncodeElementDefault: Boolean): Any? =
38+
encode(strategy, value, shouldEncodeElementDefault, serverTimestamp())
4139

4240

43-
actual val Firebase.database get() = rethrow { FirebaseDatabase(getDatabase()) }
41+
actual val Firebase.database
42+
get() = rethrow { FirebaseDatabase(getDatabase()) }
4443

4544
actual fun Firebase.database(app: FirebaseApp) =
4645
rethrow { FirebaseDatabase(getDatabase(app = app.js)) }
4746

48-
actual fun Firebase.database(url: String) = rethrow { FirebaseDatabase(getDatabase(url = url)) }
47+
actual fun Firebase.database(url: String) =
48+
rethrow { FirebaseDatabase(getDatabase(url = url)) }
4949

5050
actual fun Firebase.database(app: FirebaseApp, url: String) =
5151
rethrow { FirebaseDatabase(getDatabase(app = app.js, url = url)) }
@@ -55,9 +55,7 @@ actual class FirebaseDatabase internal constructor(val js: Database) {
5555
actual fun reference() = rethrow { DatabaseReference(ref(js)) }
5656
actual fun setPersistenceEnabled(enabled: Boolean) {}
5757
actual fun setLoggingEnabled(enabled: Boolean) = rethrow { enableLogging(enabled) }
58-
59-
actual fun useEmulator(host: String, port: Int) =
60-
rethrow { connectDatabaseEmulator(js, host, port) }
58+
actual fun useEmulator(host: String, port: Int) = rethrow { connectDatabaseEmulator(js, host, port) }
6159
}
6260

6361
actual open class Query internal constructor(open val js: JsQuery) {
@@ -79,7 +77,6 @@ actual open class Query internal constructor(open val js: JsQuery) {
7977
}
8078

8179
actual fun childEvents(vararg types: ChildEvent.Type) = callbackFlow<ChildEvent> {
82-
8380
val unsubscribes = rethrow {
8481
types.map { type ->
8582
val callback: ChangeSnapshotCallback = { snapshot, previousChildName ->
@@ -105,48 +102,36 @@ actual open class Query internal constructor(open val js: JsQuery) {
105102

106103
}
107104
}
108-
109105
awaitClose { rethrow { unsubscribes.forEach { it.invoke() } } }
110106
}
111107

112-
actual fun startAt(value: String, key: String?) =
113-
Query(query(js, jsStartAt(value, key ?: undefined)))
108+
actual fun startAt(value: String, key: String?) = Query(query(js, jsStartAt(value, key ?: undefined)))
114109

115-
actual fun startAt(value: Double, key: String?) =
116-
Query(query(js, jsStartAt(value, key ?: undefined)))
110+
actual fun startAt(value: Double, key: String?) = Query(query(js, jsStartAt(value, key ?: undefined)))
117111

118-
actual fun startAt(value: Boolean, key: String?) =
119-
Query(query(js, jsStartAt(value, key ?: undefined)))
112+
actual fun startAt(value: Boolean, key: String?) = Query(query(js, jsStartAt(value, key ?: undefined)))
120113

121-
actual fun endAt(value: String, key: String?) =
122-
Query(query(js, jsEndAt(value, key ?: undefined)))
114+
actual fun endAt(value: String, key: String?) = Query(query(js, jsEndAt(value, key ?: undefined)))
123115

124-
actual fun endAt(value: Double, key: String?) =
125-
Query(query(js, jsEndAt(value, key ?: undefined)))
116+
actual fun endAt(value: Double, key: String?) = Query(query(js, jsEndAt(value, key ?: undefined)))
126117

127-
actual fun endAt(value: Boolean, key: String?) =
128-
Query(query(js, jsEndAt(value, key ?: undefined)))
118+
actual fun endAt(value: Boolean, key: String?) = Query(query(js, jsEndAt(value, key ?: undefined)))
129119

130120
actual fun limitToFirst(limit: Int) = Query(query(js, jsLimitToFirst(limit)))
131121

132122
actual fun limitToLast(limit: Int) = Query(query(js, jsLimitToLast(limit)))
133123

134-
actual fun equalTo(value: String, key: String?) =
135-
Query(query(js, jsEqualTo(value, key ?: undefined)))
124+
actual fun equalTo(value: String, key: String?) = Query(query(js, jsEqualTo(value, key ?: undefined)))
136125

137-
actual fun equalTo(value: Double, key: String?) =
138-
Query(query(js, jsEqualTo(value, key ?: undefined)))
126+
actual fun equalTo(value: Double, key: String?) = Query(query(js, jsEqualTo(value, key ?: undefined)))
139127

140-
actual fun equalTo(value: Boolean, key: String?) =
141-
Query(query(js, jsEqualTo(value, key ?: undefined)))
128+
actual fun equalTo(value: Boolean, key: String?) = Query(query(js, jsEqualTo(value, key ?: undefined)))
142129

143130
override fun toString() = js.toString()
144131

145132
}
146133

147-
actual class DatabaseReference internal constructor(
148-
override val js: JsDatabaseReference
149-
) : Query(js) {
134+
actual class DatabaseReference internal constructor(override val js: JsDatabaseReference) : Query(js) {
150135

151136
actual val key get() = rethrow { js.key }
152137
actual fun push() = rethrow { DatabaseReference(push(js)) }
@@ -155,19 +140,16 @@ actual class DatabaseReference internal constructor(
155140
actual fun onDisconnect() = rethrow { OnDisconnect(onDisconnect(js)) }
156141

157142
actual suspend fun updateChildren(update: Map<String, Any?>, encodeDefaults: Boolean) =
158-
rethrow { update(js, encode(update, encodeDefaults)!!).awaitWhileOnline() }
143+
rethrow { update(js, encode(update, encodeDefaults) ?: json()).awaitWhileOnline() }
159144

160145
actual suspend fun removeValue() = rethrow { remove(js).awaitWhileOnline() }
161146

162147
actual suspend inline fun <reified T> setValue(value: T?, encodeDefaults: Boolean) = rethrow {
163148
set(js, encode(value, encodeDefaults)).awaitWhileOnline()
164149
}
165150

166-
actual suspend fun <T> setValue(
167-
strategy: SerializationStrategy<T>,
168-
value: T,
169-
encodeDefaults: Boolean
170-
) = rethrow { set(js, encode(strategy, value, encodeDefaults)).awaitWhileOnline() }
151+
actual suspend fun <T> setValue(strategy: SerializationStrategy<T>, value: T, encodeDefaults: Boolean) =
152+
rethrow { set(js, encode(strategy, value, encodeDefaults)).awaitWhileOnline() }
171153
}
172154

173155
actual class DataSnapshot internal constructor(val js: JsDataSnapshot) {
@@ -196,29 +178,20 @@ actual class OnDisconnect internal constructor(val js: JsOnDisconnect) {
196178
actual suspend fun cancel() = rethrow { js.cancel().awaitWhileOnline() }
197179

198180
actual suspend fun updateChildren(update: Map<String, Any?>, encodeDefaults: Boolean) =
199-
rethrow { js.update(encode(update, encodeDefaults)!!).awaitWhileOnline() }
181+
rethrow { js.update(encode(update, encodeDefaults) ?: json()).awaitWhileOnline() }
200182

201183
actual suspend inline fun <reified T> setValue(value: T, encodeDefaults: Boolean) =
202184
rethrow { js.set(encode(value, encodeDefaults)).awaitWhileOnline() }
203185

204-
actual suspend fun <T> setValue(
205-
strategy: SerializationStrategy<T>,
206-
value: T,
207-
encodeDefaults: Boolean
208-
) =
186+
actual suspend fun <T> setValue(strategy: SerializationStrategy<T>, value: T, encodeDefaults: Boolean) =
209187
rethrow { js.set(encode(strategy, value, encodeDefaults)).awaitWhileOnline() }
210188
}
211189

212-
actual class DatabaseException actual constructor(message: String?, cause: Throwable?) :
213-
RuntimeException(message, cause) {
214-
constructor(error: dynamic) : this(
215-
"${error.code ?: "UNKNOWN"}: ${error.message}",
216-
error.unsafeCast<Throwable>()
217-
)
190+
actual class DatabaseException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
191+
constructor(error: dynamic) : this("${error.code ?: "UNKNOWN"}: ${error.message}", error.unsafeCast<Throwable>())
218192
}
219193

220-
inline fun <T, R> T.rethrow(function: T.() -> R): R =
221-
dev.gitlive.firebase.database.rethrow { function() }
194+
inline fun <T, R> T.rethrow(function: T.() -> R): R = dev.gitlive.firebase.database.rethrow { function() }
222195

223196
inline fun <R> rethrow(function: () -> R): R {
224197
try {

0 commit comments

Comments
 (0)