@@ -41,35 +41,7 @@ import {
41
41
42
42
export const encoder = new TextEncoder ( ) ;
43
43
44
- /**
45
- * Returns a valid bundle string from replacing project id in `BUNDLE_TEMPLATE` with the given
46
- * db project id (also recalculate length prefixes).
47
- */
48
- export function bundleString ( db : Firestore ) : string {
49
- const projectId : string = db . app . options . projectId ! ;
50
-
51
- // Extract elements from BUNDLE_TEMPLATE and replace the project ID.
52
- const elements = BUNDLE_TEMPLATE . map ( e =>
53
- e . replace ( '{0}' , projectId ) . replace ( '(default)' , db . _databaseId . database )
54
- ) ;
55
-
56
- // Recalculating length prefixes for elements that are not BundleMetadata.
57
- let bundleContent = '' ;
58
- for ( const element of elements . slice ( 1 ) ) {
59
- const length = encoder . encode ( element ) . byteLength ;
60
- bundleContent += `${ length } ${ element } ` ;
61
- }
62
-
63
- // Update BundleMetadata with new totalBytes.
64
- const totalBytes = encoder . encode ( bundleContent ) . byteLength ;
65
- const metadata = JSON . parse ( elements [ 0 ] ) ;
66
- metadata . metadata . totalBytes = totalBytes ;
67
- const metadataContent = JSON . stringify ( metadata ) ;
68
- const metadataLength = encoder . encode ( metadataContent ) . byteLength ;
69
- return `${ metadataLength } ${ metadataContent } ${ bundleContent } ` ;
70
- }
71
-
72
- export function verifySuccessProgress ( p : LoadBundleTaskProgress ) : void {
44
+ function verifySuccessProgress ( p : LoadBundleTaskProgress ) : void {
73
45
expect ( p . taskState ) . to . equal ( 'Success' ) ;
74
46
expect ( p . bytesLoaded ) . to . be . equal ( p . totalBytes ) ;
75
47
expect ( p . documentsLoaded ) . to . equal ( p . totalDocuments ) ;
@@ -105,6 +77,34 @@ apiDescribe('Bundles', persistence => {
105
77
] ) ;
106
78
}
107
79
80
+ /**
81
+ * Returns a valid bundle string from replacing project id in `BUNDLE_TEMPLATE` with the given
82
+ * db project id (also recalculate length prefixes).
83
+ */
84
+ function bundleString ( db : Firestore ) : string {
85
+ const projectId : string = db . app . options . projectId ! ;
86
+
87
+ // Extract elements from BUNDLE_TEMPLATE and replace the project ID.
88
+ const elements = BUNDLE_TEMPLATE . map ( e =>
89
+ e . replace ( '{0}' , projectId ) . replace ( '(default)' , db . _databaseId . database )
90
+ ) ;
91
+
92
+ // Recalculating length prefixes for elements that are not BundleMetadata.
93
+ let bundleContent = '' ;
94
+ for ( const element of elements . slice ( 1 ) ) {
95
+ const length = encoder . encode ( element ) . byteLength ;
96
+ bundleContent += `${ length } ${ element } ` ;
97
+ }
98
+
99
+ // Update BundleMetadata with new totalBytes.
100
+ const totalBytes = encoder . encode ( bundleContent ) . byteLength ;
101
+ const metadata = JSON . parse ( elements [ 0 ] ) ;
102
+ metadata . metadata . totalBytes = totalBytes ;
103
+ const metadataContent = JSON . stringify ( metadata ) ;
104
+ const metadataLength = encoder . encode ( metadataContent ) . byteLength ;
105
+ return `${ metadataLength } ${ metadataContent } ${ bundleContent } ` ;
106
+ }
107
+
108
108
it ( 'load with documents only with on progress and promise interface' , ( ) => {
109
109
return withTestDb ( persistence , async db => {
110
110
const progressEvents : LoadBundleTaskProgress [ ] = [ ] ;
0 commit comments