Skip to content

Commit 3846b15

Browse files
committed
Refactor firestore
1 parent ea7fa10 commit 3846b15

File tree

16 files changed

+417
-285
lines changed

16 files changed

+417
-285
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
package dev.gitlive.firebase
66

7-
import dev.gitlive.firebase.externals.getApp
8-
import dev.gitlive.firebase.externals.getApps
9-
import dev.gitlive.firebase.externals.initializeApp
7+
import dev.gitlive.firebase.externals.app.getApp
8+
import dev.gitlive.firebase.externals.app.getApps
9+
import dev.gitlive.firebase.externals.app.initializeApp
1010
import kotlin.js.json
11-
import dev.gitlive.firebase.externals.FirebaseApp as JsFirebaseApp
11+
import dev.gitlive.firebase.externals.app.FirebaseApp as JsFirebaseApp
1212

1313
actual val Firebase.app: FirebaseApp get() = FirebaseApp(getApp())
1414

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ package dev.gitlive.firebase.auth
66

77
import dev.gitlive.firebase.*
88
import dev.gitlive.firebase.FirebaseApp
9-
import dev.gitlive.firebase.externals.*
9+
import dev.gitlive.firebase.externals.auth.*
1010
import kotlinx.coroutines.await
1111
import kotlinx.coroutines.channels.awaitClose
1212
import kotlinx.coroutines.flow.callbackFlow
1313
import kotlin.js.json
14-
import dev.gitlive.firebase.externals.AuthResult as JsAuthResult
14+
import dev.gitlive.firebase.externals.auth.AuthResult as JsAuthResult
1515

1616
actual val Firebase.auth
1717
get() = rethrow { FirebaseAuth(getAuth()) }

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package dev.gitlive.firebase.auth
22

3-
import dev.gitlive.firebase.externals.*
4-
import dev.gitlive.firebase.externals.EmailAuthProvider
5-
import dev.gitlive.firebase.externals.FacebookAuthProvider
6-
import dev.gitlive.firebase.externals.GithubAuthProvider
7-
import dev.gitlive.firebase.externals.GoogleAuthProvider
8-
import dev.gitlive.firebase.externals.PhoneAuthProvider
9-
import dev.gitlive.firebase.externals.TwitterAuthProvider
3+
import dev.gitlive.firebase.externals.auth.*
4+
import dev.gitlive.firebase.externals.auth.EmailAuthProvider
5+
import dev.gitlive.firebase.externals.auth.FacebookAuthProvider
6+
import dev.gitlive.firebase.externals.auth.GithubAuthProvider
7+
import dev.gitlive.firebase.externals.auth.GoogleAuthProvider
8+
import dev.gitlive.firebase.externals.auth.PhoneAuthProvider
9+
import dev.gitlive.firebase.externals.auth.TwitterAuthProvider
1010
import kotlinx.coroutines.await
1111
import kotlin.js.json
12-
import dev.gitlive.firebase.externals.AuthCredential as JsAuthCredential
13-
import dev.gitlive.firebase.externals.OAuthProvider as JsOAuthProvider
12+
import dev.gitlive.firebase.externals.auth.AuthCredential as JsAuthCredential
13+
import dev.gitlive.firebase.externals.auth.OAuthProvider as JsOAuthProvider
1414

1515
actual open class AuthCredential(val js: JsAuthCredential) {
1616
actual val providerId: String

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package dev.gitlive.firebase.auth
22

3-
import dev.gitlive.firebase.externals.MultiFactorUser
3+
import dev.gitlive.firebase.externals.auth.MultiFactorUser
44
import kotlinx.coroutines.await
55
import kotlin.js.Date
6-
import dev.gitlive.firebase.externals.MultiFactorAssertion as JsMultiFactorAssertion
7-
import dev.gitlive.firebase.externals.MultiFactorInfo as JsMultiFactorInfo
8-
import dev.gitlive.firebase.externals.MultiFactorResolver as JsMultiFactorResolver
9-
import dev.gitlive.firebase.externals.MultiFactorSession as JsMultiFactorSession
6+
import dev.gitlive.firebase.externals.auth.MultiFactorAssertion as JsMultiFactorAssertion
7+
import dev.gitlive.firebase.externals.auth.MultiFactorInfo as JsMultiFactorInfo
8+
import dev.gitlive.firebase.externals.auth.MultiFactorResolver as JsMultiFactorResolver
9+
import dev.gitlive.firebase.externals.auth.MultiFactorSession as JsMultiFactorSession
1010

1111
actual class MultiFactor(val js: MultiFactorUser) {
1212
actual val enrolledFactors: List<MultiFactorInfo>

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
package dev.gitlive.firebase.auth
22

3-
import dev.gitlive.firebase.externals.*
3+
import dev.gitlive.firebase.externals.auth.*
44
import kotlinx.coroutines.await
55
import kotlin.js.Date
6-
import dev.gitlive.firebase.externals.UserInfo as JsUserInfo
7-
import dev.gitlive.firebase.externals.getIdTokenResult
8-
import dev.gitlive.firebase.externals.linkWithCredential
9-
import dev.gitlive.firebase.externals.sendEmailVerification
10-
import dev.gitlive.firebase.externals.unlink
11-
import dev.gitlive.firebase.externals.updateEmail
12-
import dev.gitlive.firebase.externals.updatePassword
13-
import dev.gitlive.firebase.externals.updatePhoneNumber
14-
import dev.gitlive.firebase.externals.updateProfile
6+
import dev.gitlive.firebase.externals.auth.UserInfo as JsUserInfo
157

168
actual class FirebaseUser internal constructor(val js: User) {
179
actual val uid: String

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

Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ external object firebase {
1414

1515
open class App {
1616
fun functions(region: String? = definedExternally): functions.Functions
17-
fun firestore(): firestore.Firestore
1817
}
1918

2019
fun app(name: String? = definedExternally): App
@@ -41,140 +40,6 @@ external object firebase {
4140

4241
}
4342

44-
fun firestore(): firestore.Firestore
45-
46-
object firestore {
47-
fun setLogLevel(level: String)
48-
49-
open class PersistenceSettings {
50-
var experimentalTabSynchronization: Boolean
51-
}
52-
53-
open class Firestore {
54-
fun <T> runTransaction(func: (transaction: Transaction) -> Promise<T>): Promise<T>
55-
fun batch(): WriteBatch
56-
fun collection(collectionPath: String): CollectionReference
57-
fun collectionGroup(collectionId: String): Query
58-
fun doc(documentPath: String): DocumentReference
59-
fun settings(settings: Json)
60-
fun enablePersistence(): Promise<Unit>
61-
fun clearPersistence(): Promise<Unit>
62-
fun useEmulator(host: String, port: Int)
63-
fun disableNetwork(): Promise<Unit>
64-
fun enableNetwork(): Promise<Unit>
65-
}
66-
67-
open class Timestamp {
68-
val seconds: Double
69-
val nanoseconds: Double
70-
fun toMillis(): Double
71-
}
72-
73-
open class Query {
74-
fun get(options: Any? = definedExternally): Promise<QuerySnapshot>
75-
fun where(field: String, opStr: String, value: Any?): Query
76-
fun where(field: FieldPath, opStr: String, value: Any?): Query
77-
fun onSnapshot(next: (snapshot: QuerySnapshot) -> Unit, error: (error: Error) -> Unit): () -> Unit
78-
fun onSnapshot(options: Json, next: (snapshot: QuerySnapshot) -> Unit, error: (error: Error) -> Unit): () -> Unit
79-
fun limit(limit: Double): Query
80-
fun orderBy(field: String, direction: Any): Query
81-
fun orderBy(field: FieldPath, direction: Any): Query
82-
fun startAfter(document: DocumentSnapshot): Query
83-
fun startAfter(vararg fieldValues: Any): Query
84-
fun startAt(document: DocumentSnapshot): Query
85-
fun startAt(vararg fieldValues: Any): Query
86-
fun endBefore(document: DocumentSnapshot): Query
87-
fun endBefore(vararg fieldValues: Any): Query
88-
fun endAt(document: DocumentSnapshot): Query
89-
fun endAt(vararg fieldValues: Any): Query
90-
}
91-
92-
open class CollectionReference : Query {
93-
val path: String
94-
val parent: DocumentReference?
95-
fun doc(path: String = definedExternally): DocumentReference
96-
fun add(data: Any): Promise<DocumentReference>
97-
}
98-
99-
open class QuerySnapshot {
100-
val docs: Array<DocumentSnapshot>
101-
fun docChanges(): Array<DocumentChange>
102-
val empty: Boolean
103-
val metadata: SnapshotMetadata
104-
}
105-
106-
open class DocumentChange {
107-
val doc: DocumentSnapshot
108-
val newIndex: Int
109-
val oldIndex: Int
110-
val type: String
111-
}
112-
113-
open class DocumentSnapshot {
114-
val id: String
115-
val ref: DocumentReference
116-
val exists: Boolean
117-
val metadata: SnapshotMetadata
118-
fun data(options: Any? = definedExternally): Any?
119-
fun get(fieldPath: String, options: Any? = definedExternally): Any?
120-
fun get(fieldPath: FieldPath, options: Any? = definedExternally): Any?
121-
}
122-
123-
open class SnapshotMetadata {
124-
val hasPendingWrites: Boolean
125-
val fromCache: Boolean
126-
}
127-
128-
open class DocumentReference {
129-
val id: String
130-
val path: String
131-
val parent: CollectionReference
132-
133-
fun collection(path: String): CollectionReference
134-
fun get(options: Any? = definedExternally): Promise<DocumentSnapshot>
135-
fun set(data: Any, options: Any? = definedExternally): Promise<Unit>
136-
fun update(data: Any): Promise<Unit>
137-
fun update(field: String, value: Any?, vararg moreFieldsAndValues: Any?): Promise<Unit>
138-
fun update(field: FieldPath, value: Any?, vararg moreFieldsAndValues: Any?): Promise<Unit>
139-
fun delete(): Promise<Unit>
140-
fun onSnapshot(next: (snapshot: DocumentSnapshot) -> Unit, error: (error: Error) -> Unit): ()->Unit
141-
}
142-
143-
open class WriteBatch {
144-
fun commit(): Promise<Unit>
145-
fun delete(documentReference: DocumentReference): WriteBatch
146-
fun set(documentReference: DocumentReference, data: Any, options: Any? = definedExternally): WriteBatch
147-
fun update(documentReference: DocumentReference, data: Any): WriteBatch
148-
fun update(documentReference: DocumentReference, field: String, value: Any?, vararg moreFieldsAndValues: Any?): WriteBatch
149-
fun update(documentReference: DocumentReference, field: FieldPath, value: Any?, vararg moreFieldsAndValues: Any?): WriteBatch
150-
}
151-
152-
open class Transaction {
153-
fun get(documentReference: DocumentReference): Promise<DocumentSnapshot>
154-
fun set(documentReference: DocumentReference, data: Any, options: Any? = definedExternally): Transaction
155-
fun update(documentReference: DocumentReference, data: Any): Transaction
156-
fun update(documentReference: DocumentReference, field: String, value: Any?, vararg moreFieldsAndValues: Any?): Transaction
157-
fun update(documentReference: DocumentReference, field: FieldPath, value: Any?, vararg moreFieldsAndValues: Any?): Transaction
158-
fun delete(documentReference: DocumentReference): Transaction
159-
}
160-
161-
open class FieldPath(vararg fieldNames: String) {
162-
companion object {
163-
val documentId: FieldPath
164-
}
165-
}
166-
167-
abstract class FieldValue {
168-
companion object {
169-
fun serverTimestamp(): FieldValue
170-
fun delete(): FieldValue
171-
fun increment(value: Int): FieldValue
172-
fun arrayRemove(vararg elements: Any): FieldValue
173-
fun arrayUnion(vararg elements: Any): FieldValue
174-
}
175-
}
176-
}
177-
17843
fun remoteConfig(app: App? = definedExternally): remoteConfig.RemoteConfig
17944

18045
object remoteConfig {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@file:JsModule("firebase/app")
22
@file:JsNonModule
33

4-
package dev.gitlive.firebase.externals
4+
package dev.gitlive.firebase.externals.app
55

66
external fun initializeApp(options: Any, name: String = definedExternally): FirebaseApp
77

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
@file:JsModule("firebase/auth")
22
@file:JsNonModule
33

4-
package dev.gitlive.firebase.externals
4+
package dev.gitlive.firebase.externals.auth
55

66
import dev.gitlive.firebase.Unsubscribe
7+
import dev.gitlive.firebase.externals.app.FirebaseApp
78
import kotlin.js.Json
89
import kotlin.js.Promise
910

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
@file:JsModule("firebase/database")
22
@file:JsNonModule
33

4-
package dev.gitlive.firebase.externals
4+
package dev.gitlive.firebase.externals.database
55

66
import dev.gitlive.firebase.*
7+
import dev.gitlive.firebase.externals.app.FirebaseApp
78
import kotlin.js.Promise
89

910
external fun child(parent: DatabaseReference, path: String): DatabaseReference

0 commit comments

Comments
 (0)