Skip to content

Add getDoc() to firestore-exp #3274

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

Merged
merged 8 commits into from
Jun 26, 2020
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Jun 24, 2020

This adds getDoc() to the firestore-exp SDK. It re-uses most code from the Lite SDK where possible (e.g. DocumentReferences, CollectionReferences) but includes new full featured implementation for DocumentSnapshot and QueryDocumentSnapshot (tests for those will come when we add setDoc).

The new getDoc() uses FirestoreClient to fetch a latency compensated snapshot, and uses some factored out methods from the current SDK to convert them to a ViewSnapshot. This is the reason for the changes in src/api/database.ts, which is refactored so that the existing methods to use generic ViewSnapshots (which can be consumed by both the current and the firestore-exp SDK).

@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/getdoc-exp branch 4 times, most recently from d6a126c to a970170 Compare June 25, 2020 18:24
@changeset-bot
Copy link

changeset-bot bot commented Jun 25, 2020

🦋 Changeset is good to go

Latest commit: 11bc080

We got this.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@schmidt-sebastian schmidt-sebastian changed the title Mrschmidt/getdoc exp Add getDoc() to firestore-exp Jun 25, 2020
Comment on lines +35 to +45
export {
DocumentReference,
CollectionReference,
Query,
doc,
collection,
collectionGroup,
parent
} from '../lite/src/api/reference';

export { runTransaction, Transaction } from '../lite/src/api/transaction';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All these exports can be re-used without modification since they don't rely on latency-compensation.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 25, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (8e0c036) Head (09390d8) Diff
    browser 248 kB 249 kB +334 B (+0.1%)
    esm2017 194 kB 194 kB +315 B (+0.2%)
    main 494 kB 494 kB +759 B (+0.2%)
    module 246 kB 246 kB +334 B (+0.1%)
  • @firebase/firestore/exp

    Type Base (8e0c036) Head (09390d8) Diff
    main 37.4 kB 271 kB +234 kB (+625.9%)
  • @firebase/firestore/lite

    Type Base (8e0c036) Head (09390d8) Diff
    main 140 kB 141 kB +448 B (+0.3%)
  • @firebase/firestore/memory

    Type Base (8e0c036) Head (09390d8) Diff
    browser 186 kB 186 kB +334 B (+0.2%)
    esm2017 145 kB 145 kB +315 B (+0.2%)
    main 363 kB 364 kB +759 B (+0.2%)
    module 184 kB 185 kB +334 B (+0.2%)
  • firebase

    Type Base (8e0c036) Head (09390d8) Diff
    firebase-firestore.js 287 kB 287 kB +324 B (+0.1%)
    firebase-firestore.memory.js 226 kB 226 kB +324 B (+0.1%)
    firebase.js 820 kB 820 kB +324 B (+0.0%)

Test Logs

private _convertToDocSnapshot(snapshot: ViewSnapshot): DocumentSnapshot<T> {
debugAssert(
snapshot.docs.size <= 1,
'Too many documents returned on a document query'
Copy link
Contributor

Choose a reason for hiding this comment

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

This message is odd relative to the check being done. Can you add a comment with some context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to Expected zero or a single result on a document-only query.

@@ -41,6 +41,7 @@ import { Settings } from '../../';
// settings() defaults:
const DEFAULT_HOST = 'firestore.googleapis.com';
const DEFAULT_SSL = true;
const DEFAULT_FORCE_LONG_POLLING = false; // Used by full SDK
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary given the fixes we have in the pipeline? Will you pull this out later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current API of the experimental SDK exposes this setting. We can probably remove it once we update our closure dependency (which, by the way, seems to be unblocked now: https://www.npmjs.com/package/google-closure-library). With that update, we could just turn on the new mode in the experimental build directly and not expose it as an option.

@schmidt-sebastian schmidt-sebastian merged commit 3d43b00 into master Jun 26, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/getdoc-exp branch July 9, 2020 17:45
@firebase firebase locked and limited conversation to collaborators Jul 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants