File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Sources/SHFirestoreService Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -388,4 +388,23 @@ extension FirestoreService: FirestoreTransactional {
388388 } . eraseToAnyPublisher ( )
389389 }
390390}
391+
392+ // MARK: - FirestoreDocumentSupportable
393+ extension FirestoreService : FirestoreDocumentSupportable {
394+ /// Determine whether a document exists
395+ ///
396+ /// Notes:
397+ /// 1. Do not need to specify FirestoreMethod's specific type when using this function.
398+ /// 2. Set up requestType of FirestoreAccessible in endpoint to access firestore's a specific document before call this function.
399+ public func isDocumentExists( endpoint: any FirestoreEndopintable ) -> AnyPublisher < Bool , FirestoreServiceError > {
400+ guard let documentRef = endpoint. reference. asDocumentRef else {
401+ return Fail ( error: FirestoreServiceError . documentNotFound) . eraseToAnyPublisher ( )
402+ }
403+ return documentRef
404+ . getDocument ( )
405+ . convertFirestoreServiceError ( )
406+ . map { snapshot -> Bool in return snapshot. exists } . eraseToAnyPublisher ( )
407+ . eraseToAnyPublisher ( )
408+ }
409+ }
391410#endif
You can’t perform that action at this time.
0 commit comments