-
Notifications
You must be signed in to change notification settings - Fork 946
Implement bundle features in local store. #3200
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
Changes from 22 commits
9602712
c5e783e
5e7fb89
1ee1615
18f0be1
aa455bf
78248cd
83160a1
24e10cb
9d6edc5
4cbe608
4313e51
296cfc4
fff3d36
fb762de
1ec4182
cd3ab7a
d991c75
af097c5
8f0d5da
7ea8335
5a38f0a
9340d6a
6fc7f4a
bdbd70a
8a94ed5
6fc92ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -17,6 +17,12 @@ | |||||||||||
|
||||||||||||
import { Query } from './query'; | ||||||||||||
import { SnapshotVersion } from './snapshot_version'; | ||||||||||||
import { JsonProtoSerializer } from '../remote/serializer'; | ||||||||||||
import * as bundleProto from '../protos/firestore_bundle_proto'; | ||||||||||||
import * as api from '../protos/firestore_proto_api'; | ||||||||||||
import { DocumentKey } from '../model/document_key'; | ||||||||||||
import { MaybeDocument, NoDocument } from '../model/document'; | ||||||||||||
import { debugAssert } from '../util/assert'; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Represents a Firestore bundle saved by the SDK in its local storage. | ||||||||||||
|
@@ -40,3 +46,53 @@ export interface NamedQuery { | |||||||||||
/** The time at which the results for this query were read. */ | ||||||||||||
readonly readTime: SnapshotVersion; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Represents a bundled document, including the metadata and the document | ||||||||||||
* itself, if exists. | ||||||||||||
*/ | ||||||||||||
interface BundledDocument { | ||||||||||||
metadata: bundleProto.BundledDocumentMetadata; | ||||||||||||
document: api.Document | undefined; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* An array of `BundledDocument`. | ||||||||||||
*/ | ||||||||||||
export type BundledDocuments = Array<{ | ||||||||||||
metadata: bundleProto.BundledDocumentMetadata; | ||||||||||||
document: api.Document | undefined; | ||||||||||||
}>; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It might be cleaner just to inline this type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, I forgot to do it earlier. |
||||||||||||
|
||||||||||||
/** | ||||||||||||
* Helper to convert objects from bundles to model objects in the SDK. | ||||||||||||
*/ | ||||||||||||
export class BundleConverter { | ||||||||||||
constructor(private serializer: JsonProtoSerializer) {} | ||||||||||||
|
||||||||||||
toDocumentKey(name: string): DocumentKey { | ||||||||||||
schmidt-sebastian marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
return this.serializer.fromName(name); | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Converts a [metadata, document] pair to a MaybeDocument. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||||||||
*/ | ||||||||||||
toMaybeDocument(bundledDoc: BundledDocument): MaybeDocument { | ||||||||||||
if (bundledDoc.metadata.exists) { | ||||||||||||
debugAssert( | ||||||||||||
!!bundledDoc.document, | ||||||||||||
'Document is undefined when metadata.exist is true.' | ||||||||||||
); | ||||||||||||
return this.serializer.fromDocument(bundledDoc.document!, false); | ||||||||||||
} else { | ||||||||||||
return new NoDocument( | ||||||||||||
this.toDocumentKey(bundledDoc.metadata.name!), | ||||||||||||
this.toSnapshotVersion(bundledDoc.metadata.readTime!) | ||||||||||||
); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
toSnapshotVersion(time: api.Timestamp): SnapshotVersion { | ||||||||||||
return this.serializer.fromVersion(time); | ||||||||||||
} | ||||||||||||
} |
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.
missing "it"
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.