Skip to content

Commit

Permalink
feat: firestoreのCRUDの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
cotrin8672 committed Mar 27, 2024
1 parent 8da6d1d commit 5f1a907
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion firebase-firestore/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
alias(libs.plugins.kotlin.libs.convention)
}

version = "0.0.1"
version = "0.0.2"

kotlin {
sourceSets.jsMain {
Expand Down
9 changes: 9 additions & 0 deletions firebase-firestore/src/jsMain/kotlin/CollectionReference.kt
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions firebase-firestore/src/jsMain/kotlin/DocumentData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
interface DocumentData
36 changes: 36 additions & 0 deletions firebase-firestore/src/jsMain/kotlin/DocumentReference.kt
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 13 additions & 0 deletions firebase-firestore/src/jsMain/kotlin/DocumentSnapshot.kt
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions firebase-firestore/src/jsMain/kotlin/FieldPath.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@file:JsModule("firebase/firestore")
@file:JsNonModule
@file:Suppress("unused")

external class FieldPath(vararg fieldNames: String) {
fun isEqual(other: FieldPath): Boolean
}
21 changes: 15 additions & 6 deletions firebase-firestore/src/jsMain/kotlin/FirebaseFirestore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<DocumentReference>

external fun getDoc(reference: CollectionReference): Promise<DocumentReference>

external fun updateDoc(reference: CollectionReference, data: DocumentData): Promise<Unit>

external fun deleteDoc(reference: CollectionReference): Promise<Unit>
10 changes: 10 additions & 0 deletions firebase-firestore/src/jsMain/kotlin/Firestore.kt
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions firebase-firestore/src/jsMain/kotlin/Query.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@file:JsModule("firebase/firestore")
@file:JsNonModule
@file:Suppress("unused")

external interface Query {
val firestore: Firestore
val type: QueryType
}
7 changes: 7 additions & 0 deletions firebase-firestore/src/jsMain/kotlin/QueryDocumentSnapshot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@file:JsModule("firebase/firestore")
@file:JsNonModule
@file:Suppress("unused")

external class QueryDocumentSnapshot : DocumentSnapshot {
fun data(options: SnapshotOptions): DocumentData
}
18 changes: 18 additions & 0 deletions firebase-firestore/src/jsMain/kotlin/QueryType.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
22 changes: 22 additions & 0 deletions firebase-firestore/src/jsMain/kotlin/ServerTimeStamps.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
9 changes: 9 additions & 0 deletions firebase-firestore/src/jsMain/kotlin/SnapshotMetadata.kt
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions firebase-firestore/src/jsMain/kotlin/SnapshotOptions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@file:JsModule("firebase/firestore")
@file:JsNonModule
@file:Suppress("unused")

external interface SnapshotOptions {
val serverTimestamps: ServerTimeStamps
}
2 changes: 1 addition & 1 deletion firebase-wrapper-bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
alias(libs.plugins.publish.convention)
}

version = "0.0.1"
version = "0.0.2"

javaPlatform {
allowDependencies()
Expand Down

0 comments on commit 5f1a907

Please sign in to comment.