diff --git a/.idea/misc.xml b/.idea/misc.xml index 40ba7a7..2304d43 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/firebase-firestore/build.gradle.kts b/firebase-firestore/build.gradle.kts index cb2b3ce..d3d4623 100644 --- a/firebase-firestore/build.gradle.kts +++ b/firebase-firestore/build.gradle.kts @@ -2,7 +2,7 @@ plugins { alias(libs.plugins.kotlin.libs.convention) } -version = "0.0.1" +version = "0.0.2" kotlin { sourceSets.jsMain { diff --git a/firebase-firestore/src/jsMain/kotlin/CollectionReference.kt b/firebase-firestore/src/jsMain/kotlin/CollectionReference.kt new file mode 100644 index 0000000..9302970 --- /dev/null +++ b/firebase-firestore/src/jsMain/kotlin/CollectionReference.kt @@ -0,0 +1,9 @@ +@file:JsModule("firebase/firestore") +@file:JsNonModule +@file:Suppress("unused") + +external interface CollectionReference : Query { + var id: String + var parent: DocumentReference? + var path: String +} diff --git a/firebase-firestore/src/jsMain/kotlin/DocumentData.kt b/firebase-firestore/src/jsMain/kotlin/DocumentData.kt new file mode 100644 index 0000000..82074ea --- /dev/null +++ b/firebase-firestore/src/jsMain/kotlin/DocumentData.kt @@ -0,0 +1 @@ +interface DocumentData diff --git a/firebase-firestore/src/jsMain/kotlin/DocumentReference.kt b/firebase-firestore/src/jsMain/kotlin/DocumentReference.kt new file mode 100644 index 0000000..788b525 --- /dev/null +++ b/firebase-firestore/src/jsMain/kotlin/DocumentReference.kt @@ -0,0 +1,36 @@ +@file:JsModule("firebase/firestore") +@file:JsNonModule +@file:Suppress("unused") + +/** + * A DocumentReference refers to a document location in a Firestore database + * and can be used to write, read, or listen to the location. + * The document at the referenced location may or may not exist. + */ +external class DocumentReference { + /** + * The Firestore instance the document is in. + * This is useful for performing transactions, for example. + */ + val firestore: Firestore + + /** + * The document's identifier within its collection. + */ + var id: String + + /** + * The collection this DocumentReference belongs to. + */ + var parent: CollectionReference + + /** + * A string representing the path of the referenced document (relative to the root of the database). + */ + var path: String + + /** + * The type of this Firestore reference. + */ + val type: String = definedExternally +} diff --git a/firebase-firestore/src/jsMain/kotlin/DocumentSnapshot.kt b/firebase-firestore/src/jsMain/kotlin/DocumentSnapshot.kt new file mode 100644 index 0000000..1f1cd67 --- /dev/null +++ b/firebase-firestore/src/jsMain/kotlin/DocumentSnapshot.kt @@ -0,0 +1,13 @@ +@file:JsModule("firebase/firestore") +@file:JsNonModule +@file:Suppress("unused") + +open external class DocumentSnapshot { + var id: String + val metadata: SnapshotMetadata + var ref: DocumentReference + fun data(options: SnapshotOptions?): DocumentData? + fun exists(): Boolean + fun get(fieldPath: String, options: SnapshotOptions?): dynamic + fun get(fieldPath: FieldPath, options: SnapshotOptions?): dynamic +} diff --git a/firebase-firestore/src/jsMain/kotlin/FieldPath.kt b/firebase-firestore/src/jsMain/kotlin/FieldPath.kt new file mode 100644 index 0000000..3bd9f44 --- /dev/null +++ b/firebase-firestore/src/jsMain/kotlin/FieldPath.kt @@ -0,0 +1,7 @@ +@file:JsModule("firebase/firestore") +@file:JsNonModule +@file:Suppress("unused") + +external class FieldPath(vararg fieldNames: String) { + fun isEqual(other: FieldPath): Boolean +} diff --git a/firebase-firestore/src/jsMain/kotlin/FirebaseFirestore.kt b/firebase-firestore/src/jsMain/kotlin/FirebaseFirestore.kt index d9b3e9a..194c97b 100644 --- a/firebase-firestore/src/jsMain/kotlin/FirebaseFirestore.kt +++ b/firebase-firestore/src/jsMain/kotlin/FirebaseFirestore.kt @@ -2,11 +2,20 @@ @file:JsNonModule @file:Suppress("unused") -external class Firestore { - val app: FirebaseApp - val type: String = definedExternally - - fun toJson(): dynamic -} +import kotlin.js.Promise external fun getFirestore(app: FirebaseApp): Firestore + +external fun collection( + firestore: Firestore, + path: String, + vararg pathSegments: String +): CollectionReference + +external fun addDoc(reference: CollectionReference, data: DocumentData): Promise + +external fun getDoc(reference: CollectionReference): Promise + +external fun updateDoc(reference: CollectionReference, data: DocumentData): Promise + +external fun deleteDoc(reference: CollectionReference): Promise diff --git a/firebase-firestore/src/jsMain/kotlin/Firestore.kt b/firebase-firestore/src/jsMain/kotlin/Firestore.kt new file mode 100644 index 0000000..0b8f1dd --- /dev/null +++ b/firebase-firestore/src/jsMain/kotlin/Firestore.kt @@ -0,0 +1,10 @@ +@file:JsModule("firebase/firestore") +@file:JsNonModule +@file:Suppress("unused") + +external class Firestore { + val app: FirebaseApp + val type: String = definedExternally + + fun toJson(): dynamic +} diff --git a/firebase-firestore/src/jsMain/kotlin/Query.kt b/firebase-firestore/src/jsMain/kotlin/Query.kt new file mode 100644 index 0000000..ce80b37 --- /dev/null +++ b/firebase-firestore/src/jsMain/kotlin/Query.kt @@ -0,0 +1,8 @@ +@file:JsModule("firebase/firestore") +@file:JsNonModule +@file:Suppress("unused") + +external interface Query { + val firestore: Firestore + val type: QueryType +} diff --git a/firebase-firestore/src/jsMain/kotlin/QueryDocumentSnapshot.kt b/firebase-firestore/src/jsMain/kotlin/QueryDocumentSnapshot.kt new file mode 100644 index 0000000..8a6c334 --- /dev/null +++ b/firebase-firestore/src/jsMain/kotlin/QueryDocumentSnapshot.kt @@ -0,0 +1,7 @@ +@file:JsModule("firebase/firestore") +@file:JsNonModule +@file:Suppress("unused") + +external class QueryDocumentSnapshot : DocumentSnapshot { + fun data(options: SnapshotOptions): DocumentData +} diff --git a/firebase-firestore/src/jsMain/kotlin/QueryType.kt b/firebase-firestore/src/jsMain/kotlin/QueryType.kt new file mode 100644 index 0000000..0a98291 --- /dev/null +++ b/firebase-firestore/src/jsMain/kotlin/QueryType.kt @@ -0,0 +1,18 @@ +@file:JsModule("firebase/firestore") +@file:JsNonModule +@file:Suppress("unused") + +import seskar.js.JsValue +import seskar.js.JsVirtual + +@Suppress("NESTED_CLASS_IN_EXTERNAL_INTERFACE") +@JsVirtual +sealed external interface QueryType { + companion object { + @JsValue("query") + val query: QueryType + + @JsValue("collection") + val collection: QueryType + } +} diff --git a/firebase-firestore/src/jsMain/kotlin/ServerTimeStamps.kt b/firebase-firestore/src/jsMain/kotlin/ServerTimeStamps.kt new file mode 100644 index 0000000..72845db --- /dev/null +++ b/firebase-firestore/src/jsMain/kotlin/ServerTimeStamps.kt @@ -0,0 +1,22 @@ +@file:JsModule("firebase/firestore") +@file:JsNonModule +@file:Suppress("unused") + +import seskar.js.JsValue +import seskar.js.JsVirtual + + +@Suppress("NESTED_CLASS_IN_EXTERNAL_INTERFACE") +@JsVirtual +external interface ServerTimeStamps { + companion object { + @JsValue("estimate") + val estimate: ServerTimeStamps + + @JsValue("previous") + val previous: ServerTimeStamps + + @JsValue("none") + val none: ServerTimeStamps + } +} diff --git a/firebase-firestore/src/jsMain/kotlin/SnapshotMetadata.kt b/firebase-firestore/src/jsMain/kotlin/SnapshotMetadata.kt new file mode 100644 index 0000000..d6db080 --- /dev/null +++ b/firebase-firestore/src/jsMain/kotlin/SnapshotMetadata.kt @@ -0,0 +1,9 @@ +@file:JsModule("firebase/firestore") +@file:JsNonModule +@file:Suppress("unused") + +external class SnapshotMetadata { + val fromCache: Boolean + val hasPendingWrites: Boolean + fun isEqual(other: SnapshotMetadata): Boolean +} diff --git a/firebase-firestore/src/jsMain/kotlin/SnapshotOptions.kt b/firebase-firestore/src/jsMain/kotlin/SnapshotOptions.kt new file mode 100644 index 0000000..d6b02a6 --- /dev/null +++ b/firebase-firestore/src/jsMain/kotlin/SnapshotOptions.kt @@ -0,0 +1,7 @@ +@file:JsModule("firebase/firestore") +@file:JsNonModule +@file:Suppress("unused") + +external interface SnapshotOptions { + val serverTimestamps: ServerTimeStamps +} diff --git a/firebase-wrapper-bom/build.gradle.kts b/firebase-wrapper-bom/build.gradle.kts index 5f3ae75..43b7b43 100644 --- a/firebase-wrapper-bom/build.gradle.kts +++ b/firebase-wrapper-bom/build.gradle.kts @@ -3,7 +3,7 @@ plugins { alias(libs.plugins.publish.convention) } -version = "0.0.1" +version = "0.0.2" javaPlatform { allowDependencies()