Skip to content

Don't use interface types #3770

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 5 commits into from
Sep 14, 2020
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Sep 11, 2020

This PR updates the firestore-exp and firestore/lite SDK so that we no longer have to maintain manual type definitions.

The first commit:

  • removes the reliance on the types in the SDK code
  • moves interface-only types into the SDK itself, which allows us to export them directly in the index.ts (this affects things such as Settings and FirestoreDataConverter)
  • renames Firestore to FirebaseFirestore as that is the name in the public API
  • renames some private classes (DocumentKeyReference, SerializeableFieldValue, ...) that leak into the public API (via inheritance) to use underscore prefixes, which allows us to hide the class from the auto-generated interfaces.

The second commit removes the now unnecessary cast() calls from the interface to the SDK type from most callsites. I maintained the cast to FirebaseFirestore in some instances as this allows me to share DocumentReference, CollectionReference and Query between the different SDKs (the firestore-exp SDK used the Lite classes, which are only typed to return LiteFirestore and not ExpFirebaseFirestore).

The third commit regenerates the dependency files.

There should be no logic changes.

@changeset-bot
Copy link

changeset-bot bot commented Sep 11, 2020

💥 No Changeset

Latest commit: dba59c3

Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂

If these changes should be published to npm, you need to add a changeset.

This PR includes no changesets

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

Click here to learn what changesets are, and how to add one.

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

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 11, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (b1854ab) Head (568343b) Diff
    browser 249 kB 249 kB -311 B (-0.1%)
    esm2017 196 kB 196 kB -304 B (-0.2%)
    main 483 kB 483 kB -398 B (-0.1%)
    module 246 kB 246 kB -311 B (-0.1%)
    react-native 197 kB 196 kB -304 B (-0.2%)
  • @firebase/firestore/exp

    Type Base (b1854ab) Head (568343b) Diff
    browser 190 kB 189 kB -312 B (-0.2%)
    main 478 kB 478 kB -653 B (-0.1%)
    module 190 kB 189 kB -312 B (-0.2%)
    react-native 190 kB 189 kB -312 B (-0.2%)
  • @firebase/firestore/lite

    Type Base (b1854ab) Head (568343b) Diff
    browser 64.3 kB 63.9 kB -404 B (-0.6%)
    main 142 kB 141 kB -637 B (-0.4%)
    module 64.3 kB 63.9 kB -404 B (-0.6%)
    react-native 64.6 kB 64.2 kB -408 B (-0.6%)
  • @firebase/firestore/memory

    Type Base (b1854ab) Head (568343b) Diff
    browser 187 kB 186 kB -311 B (-0.2%)
    esm2017 147 kB 147 kB -304 B (-0.2%)
    main 357 kB 356 kB -398 B (-0.1%)
    module 185 kB 184 kB -311 B (-0.2%)
    react-native 147 kB 147 kB -304 B (-0.2%)
  • firebase

    Type Base (b1854ab) Head (568343b) Diff
    firebase-firestore.js 287 kB 287 kB -321 B (-0.1%)
    firebase-firestore.memory.js 226 kB 226 kB -321 B (-0.1%)
    firebase.js 830 kB 830 kB -321 B (-0.0%)

Test Logs

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 11, 2020

Size Analysis Report

Affected Products

No changes between base commit (b1854ab) and head commit (568343b).

Test Logs

Copy link

@thebrianchen thebrianchen left a comment

Choose a reason for hiding this comment

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

lgtm with some questions

const query = cast<Query<T>>(ref, Query);
firestore = cast(query.firestore, Firestore);
internalQuery = query._query;
firestore = cast(ref.firestore, FirebaseFirestore);

Choose a reason for hiding this comment

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

nit: s/ref/reference (here and throughout) since you're already standardizing it elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

extends LiteDocumentSnapshot<T>
implements firestore.DocumentSnapshot<T> {
private readonly _firestoreImpl: Firestore;
export interface FirestoreDataConverter<T> {

Choose a reason for hiding this comment

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

Is there any reason why you're defining these types here instead of importing them from the firestore main SDK? For example, I don't follow why we import SnapshotMetadata from firestore/src/api/database.ts in this file, but not SnapshotOptions. Is there something special about SnapshotMetadata?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In our code, SnapshotMetadata is an actual class, which makes it a bit different from the other types that are merely defined in the interface. I just cross-checked some types and could not find any other type that is already defined in the sources.

@@ -19,7 +19,7 @@ import { FirebaseApp as FirebaseAppLegacy } from '@firebase/app-types';
import { FirebaseApp as FirebaseAppExp } from '@firebase/app-types-exp';
import { deleteApp } from '@firebase/app-exp';
import * as legacy from '@firebase/firestore-types';
import * as exp from '../../exp-types';
import * as exp from '../index';

Choose a reason for hiding this comment

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

Just to make sure I'm following the big picture here: Is the ultimate goal for no files to depend on any of the exports in exp-types/index.d.ts?

Also, what is rough plan to use the existing instance of FirebaseFirestore instead of instantiating a new one?

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 goal of this entire effort is to remove the explicit types, which will allow us to write JSDoc comments in code and use the same JSDoc documentation across all implementations. That does mean that the typings file will go away in its current form. The generated form will not be used internally and only shipped to customers.

import { removeComponents } from './components';

declare module '@firebase/component' {

Choose a reason for hiding this comment

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

Can you please explain what this module here is doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not my area of expertise... this piece of code extends the available services that we can theoretically fetch via getComponent to include firestore/lite. This is needed to avoid a compile time error in this file (at the bottom, we have getFirestore() for the Lite SDK, which is compiled but not used when building firestore-exp).

@schmidt-sebastian schmidt-sebastian merged commit a865ae9 into master Sep 14, 2020
@firebase firebase locked and limited conversation to collaborators Oct 15, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/removeinterface branch November 9, 2020 22:38
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.

3 participants