-
Notifications
You must be signed in to change notification settings - Fork 929
[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
[FEAT] Doc/QuerySnapshot fromJSON #8960
Conversation
|
Vertex AI Mock Responses Check
|
Size Report 1Affected Products
Test Logs |
Size Analysis Report 1This 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 |
There was a problem hiding this 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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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[] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same suggestion
There was a problem hiding this comment.
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[] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
c88ea8e
into
ddb-firestore-result-serialization
Discussion
This is a PR pointed at a feature branch.
Add a methods to parse bundles synchronously to extract single
DocumentSnapshots
orQuerySnapshots
containing documents. Hook the new bundle parser up thedocumentSnapshotFromJSON
andquerySnapshotFromJSON
.Testing
Local testing with Next.js app.
Added unit tests and integration tests.
API Changes
go/fs-js-json-serialization