Skip to content

Commit 23ea4d8

Browse files
committed
Make loadBundle work with exp build
1 parent a9bf16c commit 23ea4d8

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

packages/firestore/exp-types/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,11 @@ export interface LoadBundleTaskProgress {
536536

537537
export type TaskState = 'Error' | 'Running' | 'Success';
538538

539+
export function loadBundle(
540+
firestore: FirebaseFirestore,
541+
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
542+
): LoadBundleTask;
543+
539544
export type FirestoreErrorCode =
540545
| 'cancelled'
541546
| 'unknown'

packages/firestore/exp/src/api/database.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
indexedDbStoragePrefix,
5151
indexedDbClearPersistence
5252
} from '../../../src/local/indexeddb_persistence';
53+
import { LoadBundleTask } from '../../../src/api/bundle';
5354

5455
/**
5556
* The root reference to the Firestore database and the entry point for the
@@ -299,9 +300,13 @@ export function terminate(
299300
export function loadBundle(
300301
firestore: firestore.FirebaseFirestore,
301302
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
302-
): firestore.LoadBundleTask | null {
303-
return null;
304-
// const firestoreImpl = cast(firestore, Firestore);
305-
// return firestoreImpl._getFirestoreClient()
306-
// .then(firestoreClient => firestoreClient.loadBundle(bundleData));
303+
): LoadBundleTask {
304+
const firestoreImpl = cast(firestore, Firestore);
305+
const resultTask = new LoadBundleTask();
306+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
307+
firestoreImpl._getFirestoreClient().then(firestoreClient => {
308+
firestoreClient.loadBundle(bundleData, resultTask);
309+
});
310+
311+
return resultTask;
307312
}

packages/firestore/exp/test/shim.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import {
7272
import { UntypedFirestoreDataConverter } from '../../src/api/user_data_reader';
7373
import { isPartialObserver, PartialObserver } from '../../src/api/observer';
7474
import { isPlainObject } from '../../src/util/input_validation';
75+
import { LoadBundleTask } from '../../exp-types';
7576

7677
export { GeoPoint, Blob, Timestamp } from '../index';
7778

@@ -168,7 +169,7 @@ export class FirebaseFirestore implements legacy.FirebaseFirestore {
168169

169170
loadBundle(
170171
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
171-
): legacy.LoadBundleTask {
172+
): LoadBundleTask {
172173
return loadBundle(this._delegate, bundleData)!;
173174
}
174175

packages/firestore/src/api/database.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ import {
112112
import { UserDataWriter } from './user_data_writer';
113113
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
114114
import { Provider } from '@firebase/component';
115+
import { LoadBundleTask } from './bundle';
115116

116117
// settings() defaults:
117118
const DEFAULT_HOST = 'firestore.googleapis.com';
@@ -498,7 +499,9 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
498499
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
499500
): firestore.LoadBundleTask {
500501
this.ensureClientConfigured();
501-
return this._firestoreClient!.loadBundle(bundleData);
502+
const resultTask = new LoadBundleTask();
503+
this._firestoreClient!.loadBundle(bundleData, resultTask);
504+
return resultTask;
502505
}
503506

504507
ensureClientConfigured(): FirestoreClient {

packages/firestore/src/core/firestore_client.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firestore from '@firebase/firestore-types';
1918
import { CredentialsProvider } from '../api/credentials';
2019
import { User } from '../auth/user';
2120
import { LocalStore } from '../local/local_store';
@@ -515,8 +514,9 @@ export class FirestoreClient {
515514
}
516515

517516
loadBundle(
518-
data: ReadableStream<Uint8Array> | ArrayBuffer | string
519-
): firestore.LoadBundleTask {
517+
data: ReadableStream<Uint8Array> | ArrayBuffer | string,
518+
resultTask: LoadBundleTask
519+
): void {
520520
this.verifyNotTerminated();
521521

522522
let content: ReadableStream<Uint8Array> | ArrayBuffer;
@@ -526,14 +526,11 @@ export class FirestoreClient {
526526
content = data;
527527
}
528528
const reader = new BundleReader(toByteStreamReader(content));
529-
const task = new LoadBundleTask();
530529
this.asyncQueue.enqueueAndForget(async () => {
531-
loadBundle(this.syncEngine, reader, task);
532-
return task.catch(e => {
530+
loadBundle(this.syncEngine, reader, resultTask);
531+
return resultTask.catch(e => {
533532
logWarn(LOG_TAG, `Loading bundle failed with ${e}`);
534533
});
535534
});
536-
537-
return task;
538535
}
539536
}

0 commit comments

Comments
 (0)