Skip to content

Make loadBundle work with exp build #3488

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

Merged
merged 2 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/firestore/exp-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ export interface LoadBundleTaskProgress {

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

export function loadBundle(
firestore: FirebaseFirestore,
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
): LoadBundleTask;

export type FirestoreErrorCode =
| 'cancelled'
| 'unknown'
Expand Down
15 changes: 10 additions & 5 deletions packages/firestore/exp/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
indexedDbStoragePrefix,
indexedDbClearPersistence
} from '../../../src/local/indexeddb_persistence';
import { LoadBundleTask } from '../../../src/api/bundle';

/**
* The root reference to the Firestore database and the entry point for the
Expand Down Expand Up @@ -299,9 +300,13 @@ export function terminate(
export function loadBundle(
firestore: firestore.FirebaseFirestore,
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
): firestore.LoadBundleTask | null {
return null;
// const firestoreImpl = cast(firestore, Firestore);
// return firestoreImpl._getFirestoreClient()
// .then(firestoreClient => firestoreClient.loadBundle(bundleData));
): LoadBundleTask {
const firestoreImpl = cast(firestore, Firestore);
const resultTask = new LoadBundleTask();
// eslint-disable-next-line @typescript-eslint/no-floating-promises
firestoreImpl._getFirestoreClient().then(firestoreClient => {
firestoreClient.loadBundle(bundleData, resultTask);
});

return resultTask;
}
1 change: 1 addition & 0 deletions packages/firestore/exp/test/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
import { UntypedFirestoreDataConverter } from '../../src/api/user_data_reader';
import { isPartialObserver, PartialObserver } from '../../src/api/observer';
import { isPlainObject } from '../../src/util/input_validation';
import { LoadBundleTask } from '../../exp-types';

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

Expand Down
5 changes: 4 additions & 1 deletion packages/firestore/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ import {
import { UserDataWriter } from './user_data_writer';
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
import { Provider } from '@firebase/component';
import { LoadBundleTask } from './bundle';

// settings() defaults:
const DEFAULT_HOST = 'firestore.googleapis.com';
Expand Down Expand Up @@ -498,7 +499,9 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
): firestore.LoadBundleTask {
this.ensureClientConfigured();
return this._firestoreClient!.loadBundle(bundleData);
const resultTask = new LoadBundleTask();
this._firestoreClient!.loadBundle(bundleData, resultTask);
return resultTask;
}

ensureClientConfigured(): FirestoreClient {
Expand Down
13 changes: 5 additions & 8 deletions packages/firestore/src/core/firestore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

import * as firestore from '@firebase/firestore-types';
import { CredentialsProvider } from '../api/credentials';
import { User } from '../auth/user';
import { LocalStore } from '../local/local_store';
Expand Down Expand Up @@ -515,8 +514,9 @@ export class FirestoreClient {
}

loadBundle(
data: ReadableStream<Uint8Array> | ArrayBuffer | string
): firestore.LoadBundleTask {
data: ReadableStream<Uint8Array> | ArrayBuffer | string,
resultTask: LoadBundleTask
): void {
this.verifyNotTerminated();

let content: ReadableStream<Uint8Array> | ArrayBuffer;
Expand All @@ -526,14 +526,11 @@ export class FirestoreClient {
content = data;
}
const reader = new BundleReader(toByteStreamReader(content));
const task = new LoadBundleTask();
this.asyncQueue.enqueueAndForget(async () => {
loadBundle(this.syncEngine, reader, task);
return task.catch(e => {
loadBundle(this.syncEngine, reader, resultTask);
return resultTask.catch(e => {
logWarn(LOG_TAG, `Loading bundle failed with ${e}`);
});
});

return task;
}
}