@@ -61,8 +61,10 @@ export class BundleBuilder {
6161 // The latest read time among all bundled documents and queries.
6262 private latestReadTime = new Timestamp ( 0 , 0 ) ;
6363
64+ // Database identifier which is part of the serialized bundle.
6465 private databaseId : DatabaseId ;
6566
67+ // Tools to convert public data types into their serialized form.
6668 private readonly serializer : JsonProtoSerializer ;
6769 private readonly userDataReader : UserDataReader ;
6870
@@ -83,31 +85,6 @@ export class BundleBuilder {
8385 ) ;
8486 }
8587
86- private toBundleDocument (
87- docBundleData : DocumentSnapshotBundleData
88- ) : ProtoDocument {
89- // TODO handle documents that have mutations
90- debugAssert (
91- ! docBundleData . documentData . hasLocalMutations ,
92- "Can't serialize documents with mutations."
93- ) ;
94-
95- // a parse context is typically used for validating and parsing user data, but in this
96- // case we are using it internally to convert DocumentData to Proto3 JSON
97- const context = this . userDataReader . createContext (
98- UserDataSource . ArrayArgument ,
99- 'internal toBundledDocument'
100- ) ;
101- const proto3Fields = parseObject ( docBundleData . documentData , context ) ;
102-
103- return {
104- name : toName ( this . serializer , docBundleData . documentKey ) ,
105- fields : proto3Fields . mapValue . fields ,
106- updateTime : toTimestamp ( this . serializer , docBundleData . versionTime ) ,
107- createTime : toTimestamp ( this . serializer , docBundleData . createdTime )
108- } ;
109- }
110-
11188 /**
11289 * Adds data from a DocumentSnapshot to the bundle.
11390 * @internal
@@ -188,6 +165,38 @@ export class BundleBuilder {
188165 } ) ;
189166 }
190167
168+ /**
169+ * Convert data from a DocumentSnapshot into the serialized form within a bundle.
170+ * @private
171+ * @internal
172+ * @param docBundleData a DocumentSnapshotBundleData containing the data required to
173+ * serialize a document.
174+ */
175+ private toBundleDocument (
176+ docBundleData : DocumentSnapshotBundleData
177+ ) : ProtoDocument {
178+ // TODO handle documents that have mutations
179+ debugAssert (
180+ ! docBundleData . documentData . hasLocalMutations ,
181+ "Can't serialize documents with mutations."
182+ ) ;
183+
184+ // a parse context is typically used for validating and parsing user data, but in this
185+ // case we are using it internally to convert DocumentData to Proto3 JSON
186+ const context = this . userDataReader . createContext (
187+ UserDataSource . ArrayArgument ,
188+ 'internal toBundledDocument'
189+ ) ;
190+ const proto3Fields = parseObject ( docBundleData . documentData , context ) ;
191+
192+ return {
193+ name : toName ( this . serializer , docBundleData . documentKey ) ,
194+ fields : proto3Fields . mapValue . fields ,
195+ updateTime : toTimestamp ( this . serializer , docBundleData . versionTime ) ,
196+ createTime : toTimestamp ( this . serializer , docBundleData . createdTime )
197+ } ;
198+ }
199+
191200 /**
192201 * Converts a IBundleElement to a Buffer whose content is the length prefixed JSON representation
193202 * of the element.
@@ -205,6 +214,11 @@ export class BundleBuilder {
205214 return `${ l } ${ str } ` ;
206215 }
207216
217+ /**
218+ * Construct a serialized string containing document and query information that has previously
219+ * been added to the BundleBuilder through the addBundleDocument and addBundleQuery methods.
220+ * @internal
221+ */
208222 build ( ) : string {
209223 let bundleString = '' ;
210224
0 commit comments