Skip to content

[FEAT] Doc/QuerySnapshot fromJSON #8960

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 28 commits into from
May 16, 2025

Conversation

DellaBitta
Copy link
Contributor

@DellaBitta DellaBitta commented Apr 22, 2025

Discussion

This is a PR pointed at a feature branch.

Add a methods to parse bundles synchronously to extract single DocumentSnapshots or QuerySnapshots containing documents. Hook the new bundle parser up the documentSnapshotFromJSON and querySnapshotFromJSON.

Testing

Local testing with Next.js app.
Added unit tests and integration tests.

API Changes

go/fs-js-json-serialization

Copy link

changeset-bot bot commented Apr 22, 2025

⚠️ No Changeset found

Latest commit: 04620bc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, 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

Copy link
Contributor

Vertex AI Mock Responses Check ⚠️

A newer major version of the mock responses for Vertex AI unit tests is available. update_vertexai_responses.sh should be updated to clone the latest version of the responses: v10.0

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 22, 2025

Size Report 1

Affected Products

  • @firebase/firestore

    TypeBase (c211ea2)Merge (5252520)Diff
    browser394 kB398 kB+3.30 kB (+0.8%)
    main608 kB613 kB+4.63 kB (+0.8%)
    module394 kB398 kB+3.30 kB (+0.8%)
    react-native395 kB398 kB+3.30 kB (+0.8%)
  • @firebase/firestore-lite

    TypeBase (c211ea2)Merge (5252520)Diff
    browser116 kB116 kB+12 B (+0.0%)
    main160 kB160 kB+8 B (+0.0%)
    module116 kB116 kB+12 B (+0.0%)
    react-native116 kB117 kB+12 B (+0.0%)
  • bundle

    15 size changes

    TypeBase (c211ea2)Merge (5252520)Diff
    firestore (CSI Auto Indexing Disable and Delete)281 kB293 kB+12.4 kB (+4.4%)
    firestore (CSI Auto Indexing Enable)281 kB293 kB+12.4 kB (+4.4%)
    firestore (Persistence)312 kB324 kB+12.2 kB (+3.9%)
    firestore (Query Cursors)259 kB259 kB+474 B (+0.2%)
    firestore (Query)266 kB257 kB-8.80 kB (-3.3%)
    firestore (Read data once)248 kB251 kB+3.00 kB (+1.2%)
    firestore (Read Write w Persistence)337 kB340 kB+3.00 kB (+0.9%)
    firestore (Realtime updates)260 kB251 kB-8.80 kB (-3.4%)
    firestore (Transaction)225 kB228 kB+3.00 kB (+1.3%)
    firestore (Write data)219 kB229 kB+9.34 kB (+4.3%)
    firestore-lite (Query Cursors)106 kB106 kB+12 B (+0.0%)
    firestore-lite (Query)103 kB103 kB+12 B (+0.0%)
    firestore-lite (Read data once)78.1 kB78.1 kB+12 B (+0.0%)
    firestore-lite (Transaction)103 kB103 kB+12 B (+0.0%)
    firestore-lite (Write data)87.6 kB87.6 kB+12 B (+0.0%)

  • firebase

    TypeBase (c211ea2)Merge (5252520)Diff
    firebase-compat.js805 kB804 kB-1.07 kB (-0.1%)
    firebase-firestore-compat.js351 kB350 kB-1.07 kB (-0.3%)
    firebase-firestore-lite.js135 kB135 kB+12 B (+0.0%)
    firebase-firestore.js453 kB456 kB+3.30 kB (+0.7%)

Test Logs

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

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 22, 2025

Size Analysis Report 1

This report is too large (1,733,811 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.

Test Logs

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

@DellaBitta DellaBitta changed the base branch from main to ddb-firestore-result-serialization April 23, 2025 15:12
@DellaBitta DellaBitta changed the title [FEAT] [WIP] Doc/QuerySnapshot fromJSON. [FEAT] Doc/QuerySnapshot fromJSON May 6, 2025
@DellaBitta DellaBitta requested a review from MarkDuckworth May 6, 2025 16:40
@DellaBitta DellaBitta marked this pull request as ready for review May 7, 2025 15:06
@DellaBitta DellaBitta requested review from a team as code owners May 7, 2025 15:06
Copy link
Contributor

@MarkDuckworth MarkDuckworth left a comment

Choose a reason for hiding this comment

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

Looking good. Left a few suggestions.

let curArg = 0;
let options: SnapshotListenOptions | undefined = undefined;
if (typeof args[curArg] === 'object' && !isPartialObserver(args[curArg])) {
console.error('DEDB arg 0 is SnapsotLsitenOptions');
Copy link
Contributor

Choose a reason for hiding this comment

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

use logError(...) if you want to keep this in the SDK

Copy link
Contributor

Choose a reason for hiding this comment

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

This ensures the logging level is correctly applied

Copy link
Contributor

Choose a reason for hiding this comment

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

it might even be better to use a hardAssert(...) instead of this if else, to ensure the state is correct. But that will throw.

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 was debug code I left in by accident. Removing it!

console.error('DEDB arg 0 is SnapsotLsitenOptions');
options = args[curArg++] as SnapshotListenOptions;
} else {
console.error('DEDB arg 0 is NOT SnapsotLsitenOptions');
Copy link
Contributor

Choose a reason for hiding this comment

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

use logError(...) if you want to keep this in the SDK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ditto

>(
db: Firestore,
json: object,
...args: unknown[]
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like you could just change this to converter?: FirestoreDataConverter<AppModelType, DbModelType>. It would improve readability of the code since there are no other overloads where this could be another type.

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!

>(
db: Firestore,
json: object,
...args: unknown[]
Copy link
Contributor

Choose a reason for hiding this comment

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

same suggestion

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!

static fromJSON<
NewAppModelType = DocumentData,
NewDbModelType extends DocumentData = DocumentData
>(
firestore: Firestore,
json: object,
converter?: FirestoreDataConverter<NewAppModelType, NewDbModelType>
...args: unknown[]
Copy link
Contributor

Choose a reason for hiding this comment

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

same suggestion. Just to be clear, I'm not recommending removing the overloads, just renaming the param in the implementation

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! Thanks for the tip.

*/
private readJsonString(length: number): string {
if (this.cursor + length > this.bundleData.length) {
throw new Error('Reached the end of bundle when more is expected.');
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be more appropriate to throw FirestoreError

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!

bundleSource: 'QuerySnapshot',
bundleName: 'test name'
});
}).to.throw;
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, it's usually good to assert that the error message is like expected. Mostly because bad or incorrect error messages can make for bad DX. Just a comment for your consideration.

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!

@DellaBitta DellaBitta merged commit c88ea8e into ddb-firestore-result-serialization May 16, 2025
40 of 45 checks passed
@DellaBitta DellaBitta deleted the ddb-sync-bundle-parse branch May 16, 2025 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants