Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental support for AsyncSequence on Firestore snapshot listeners #11508

Draft
wants to merge 178 commits into
base: auth-swift
Choose a base branch
from

Conversation

peterfriese
Copy link
Contributor

@peterfriese peterfriese commented Jul 5, 2023

This PR adds support for using Swift's AsyncSequence to listen to changes on Firestore collections and documents.

Here is how to use it:

Listening to updates on a single document

let doc = Firestore.firestore().collection("fruits").document("1uxSAlCvYWmfrXN7rn2s")
for try await fruit in doc.snapshotSequence(Fruit.self) {
  print(fruit.name)
}

Listening to updates on a collection

let collection = Firestore.firestore().collection("fruits")
for try await fruits in collection.snapshotSequence(Fruit.self) {
  print(fruits.count)
}

See Example/FirestoreSample/FirestoreSample/Views/FavouriteFruitsAsyncSequenceView.swift and Example/FirestoreSample/FirestoreSample/Views/FavouriteFruitView.swift for more complete examples how to use this.

…ners

Signed-off-by: Peter Friese <peter@peterfriese.de>
@google-oss-bot
Copy link

1 Warning
⚠️ Did you forget to add a changelog entry? (Add #no-changelog to the PR description to silence this warning.)

Generated by 🚫 Danger

@github-actions
Copy link
Contributor

github-actions bot commented Jul 5, 2023

Apple API Diff Report

Commit: f9781a0
Last updated: Fri Jul 7 04:30 PDT 2023
View workflow logs & download artifacts


FirebaseFirestoreSwift

Extensions

[ADDED] Query
[ADDED] Query
Swift:
+  public extension Query
+    func snapshotSequence < T > ( _ type : T . Type , includeMetadataChanges : Bool = false ) -> AsyncThrowingStream < [ T ], Error > where T : Decodable
[MODIFIED] DocumentReference
[MODIFIED] DocumentReference
Swift:
+  public extension DocumentReference extension DocumentReference : DocumentIDWrappable
-  extension DocumentReference : DocumentIDWrappable
+    func snapshotSequence < T > ( _ type : T . Type , includeMetadataChanges : Bool = false ) -> AsyncThrowingStream < T , Error > where T : Decodable

Signed-off-by: Peter Friese <peter@peterfriese.de>
Signed-off-by: Peter Friese <peter@peterfriese.de>
Signed-off-by: Peter Friese <peter@peterfriese.de>
@google-oss-bot
Copy link

google-oss-bot commented Jul 5, 2023

Coverage Report 1

Affected Products

  • FirebaseFirestore-iOS-FirebaseFirestore.framework

    Overall coverage changed from 88.11% (cc3ed01) to 88.04% (f9781a0) by -0.07%.

    FilenameBase (cc3ed01)Merge (f9781a0)Diff
    exception.cc84.21%23.68%-60.53%
    leveldb_key.cc98.14%98.82%+0.69%
    leveldb_remote_document_cache.cc96.41%94.61%-1.80%
    ordered_code.cc93.90%94.39%+0.49%
  • FirebaseFirestore-iOS-FirebaseFirestoreSwift.framework

    Overall coverage changed from 40.79% (cc3ed01) to 36.78% (f9781a0) by -4.02%.

    FilenameBase (cc3ed01)Merge (f9781a0)Diff
    DocumentReference+AsyncStream.swift?0.00%?
    Query+AsyncStream.swift?0.00%?

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/NBBJHovuKW.html

import FirebaseFirestore
import Foundation

#if compiler(>=5.5.2) && canImport(_Concurrency)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this check anymore with our current Xcode supported versions

@mortenbekditlevsen
Copy link
Contributor

It could also make sense to have a similar abstraction for a document rather than a query.

Signed-off-by: Peter Friese <peter@peterfriese.de>
@peterfriese
Copy link
Contributor Author

It could also make sense to have a similar abstraction for a document rather than a query.

Good point. Added!

Signed-off-by: Peter Friese <peter@peterfriese.de>
@peterfriese peterfriese changed the title [DO NOT MERGE] Experimental support for AsyncSequence on Firestore snapshot listeners Experimental support for AsyncSequence on Firestore snapshot listeners Jul 7, 2023
includeMetadataChanges: Bool = false)
-> AsyncThrowingStream<T, Error> where T: Decodable {
.init { continuation in
let listener = addSnapshotListener(includeMetadataChanges: false) { documentSnapshot, error in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably use the argument passed to the method.

Signed-off-by: Peter Friese <peter@peterfriese.de>
Signed-off-by: Peter Friese <peter@peterfriese.de>
paulb777 and others added 26 commits July 14, 2023 14:48
* Rewrite Auth RPC types using Swift types.

This largely stems from the unsafe casting that occurs. Current state:
all types have been converted, almost no calls using those types have
been converted, ran into an issue with TwitterAuthCredential where it
takes a parameter that's an RPC type, but can't be visible in ObjC. This
may result in an API change unfortunately, or a rethinking of how the
AuthCredential and Providers work.
---------

Co-authored-by: Ryan Wilson <wilsonryan@google.com>
Signed-off-by: Peter Friese <peter@peterfriese.de>
Signed-off-by: Peter Friese <peter@peterfriese.de>
@peterfriese peterfriese changed the base branch from master to auth-swift July 14, 2023 16:36
@paulb777
Copy link
Member

Looks likes you might have had an out of date auth-swift branch. It's been rebased a few times.

@paulb777
Copy link
Member

Please close, merge, or comment. We plan to close stale PRs on November 28, 2023.

@peterfriese
Copy link
Contributor Author

I'd like to land this in Q4. Will rebase on the latest auth-swift branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants