Skip to content

Commit

Permalink
Add kotlin() unwrap functions to Firestore types
Browse files Browse the repository at this point in the history
  • Loading branch information
marcprux committed Jan 9, 2024
1 parent 7469d15 commit 79834e2
Showing 1 changed file with 73 additions and 3 deletions.
76 changes: 73 additions & 3 deletions Sources/SkipFirebaseFirestore/SkipFirebaseFirestore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public final class Firestore {
store.toString()
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.FirebaseFirestore {
store
}

public static func firestore(app: FirebaseApp, database: String) -> Firestore {
return Firestore(store: com.google.firebase.firestore.FirebaseFirestore.getInstance(app.app, database))
}
Expand Down Expand Up @@ -53,7 +57,7 @@ public final class Firestore {
}

/// A FieldPath refers to a field in a document. The path may consist of a single field name (referring to a top level field in the document), or a list of field names (referring to a nested field in the document).
public class FieldPath : Equatable {
public class FieldPath : Hashable {
public let fieldPath: com.google.firebase.firestore.FieldPath

public init(fieldPath: com.google.firebase.firestore.FieldPath) {
Expand All @@ -65,6 +69,10 @@ public class FieldPath : Equatable {
self.fieldPath = com.google.firebase.firestore.FieldPath.of(*fnames)
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.FieldPath {
fieldPath
}

public var description: String {
fieldPath.toString()
}
Expand All @@ -73,6 +81,11 @@ public class FieldPath : Equatable {
lhs.fieldPath == rhs.fieldPath
}

public func hash(into hasher: inout Hasher) {
hasher.combine(fieldPath.hashCode())
}

/// A special sentinel FieldPath to refer to the ID of a document. It can be used in queries to sort or filter by the document ID.
public static func documentID() -> FieldPath {
FieldPath(fieldPath: com.google.firebase.firestore.FieldPath.documentId())
}
Expand All @@ -86,6 +99,10 @@ public class AggregateQuery {
self.query = query
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.AggregateQuery {
query
}

public var description: String {
query.toString()
}
Expand All @@ -110,6 +127,10 @@ public class Filter {
self.filter = filter
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.Filter {
filter
}

public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.filter == rhs.filter
}
Expand All @@ -123,6 +144,10 @@ public class SnapshotMetadata {
self.meta = meta
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.SnapshotMetadata {
meta
}

public var description: String {
meta.toString()
}
Expand All @@ -139,6 +164,10 @@ public class Query {
self.query = query
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.Query {
query
}

public var description: String {
query.toString()
}
Expand Down Expand Up @@ -280,6 +309,10 @@ public class CollectionReference : Query {
super.init(query: ref)
}

public override func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.CollectionReference {
ref
}

public var firestore: Firestore {
Firestore(store: ref.firestore)
}
Expand Down Expand Up @@ -319,6 +352,10 @@ public class ListenerRegistration {
self.reg = reg
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.ListenerRegistration {
reg
}

public var description: String {
reg.toString()
}
Expand All @@ -339,6 +376,10 @@ public class Transaction {
self.transaction = transaction
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.Transaction {
transaction
}

public var description: String {
transaction.toString()
}
Expand All @@ -355,6 +396,10 @@ public class QuerySnapshot {
self.snap = snap
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.QuerySnapshot {
snap
}

public var description: String {
snap.toString()
}
Expand Down Expand Up @@ -406,6 +451,10 @@ public struct AggregateField {
self.agg = agg
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.AggregateField {
agg
}

public var description: String {
agg.toString()
}
Expand Down Expand Up @@ -442,6 +491,10 @@ public class AggregateQuerySnapshot {
self.snap = snap
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.AggregateQuerySnapshot {
snap
}

public var description: String {
snap.toString()
}
Expand Down Expand Up @@ -473,6 +526,10 @@ public class DocumentChange {
self.change = change
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.DocumentChange {
change
}

public var description: String {
change.toString()
}
Expand Down Expand Up @@ -510,6 +567,10 @@ public class DocumentSnapshot {
self.doc = doc
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.DocumentSnapshot {
doc
}

public var description: String {
doc.toString()
}
Expand Down Expand Up @@ -543,6 +604,10 @@ public class QueryDocumentSnapshot : DocumentSnapshot {
doc as! com.google.firebase.firestore.QueryDocumentSnapshot
}

public override func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.QueryDocumentSnapshot {
snapshot
}

public init(snapshot: com.google.firebase.firestore.QueryDocumentSnapshot) {
super.init(doc: snapshot)
}
Expand All @@ -559,6 +624,10 @@ public class DocumentReference {
self.ref = ref
}

public func kotlin(nocopy: Bool = false) -> com.google.firebase.firestore.DocumentReference {
ref
}

public var description: String {
ref.toString()
}
Expand Down Expand Up @@ -589,6 +658,7 @@ public class DocumentReference {
}

public func delete() async throws {
// SKIP NOWARN
try await ref.delete().await()
}

Expand Down Expand Up @@ -616,7 +686,7 @@ fileprivate func deepKotlin(value: Any) -> Any {
} else if let collection = value as? Collection<Any> {
return deepKotlin(collection: collection)
} else {
return value
return value.kotlin()
}
}

Expand Down Expand Up @@ -645,7 +715,7 @@ fileprivate func deepSwift(value: Any) -> Any {
} else if let collection = value as? kotlin.collections.Collection<Any> {
return deepSwift(collection: collection)
} else {
return value
return value.kotlin()
}
}

Expand Down

0 comments on commit 79834e2

Please sign in to comment.