Skip to content

Commit 223bc9a

Browse files
authored
Move bundle integration tests under api/ and complete exp API (#3962)
* Rolls a node app building bundles. * Build bundle files for given list of project IDs. * Build the bundle json map and save it for integration tests. * Add emulator_settings.ts to gulp * Move bundle.test.ts to api/ * Bundles passes all tests and expose in classic API * Add CI project ID to bundles. * Adhoc string replacement and length re-calculation * Fix lint errors. * Delete old changes from make node app * Address comments * Manually prepares the bundle strings. * More fixes.
1 parent 3b208b2 commit 223bc9a

File tree

10 files changed

+204
-154
lines changed

10 files changed

+204
-154
lines changed

packages/firebase/index.d.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8255,12 +8255,45 @@ declare namespace firebase.firestore {
82558255
*/
82568256
terminate(): Promise<void>;
82578257

8258+
loadBundle(
8259+
bundleData: ArrayBuffer | ReadableStream<ArrayBuffer> | string
8260+
): LoadBundleTask;
8261+
8262+
namedQuery(name: string): Promise<Query<DocumentData> | null>;
8263+
82588264
/**
82598265
* @hidden
82608266
*/
82618267
INTERNAL: { delete: () => Promise<void> };
82628268
}
82638269

8270+
export interface LoadBundleTask {
8271+
onProgress(
8272+
next?: (progress: LoadBundleTaskProgress) => any,
8273+
error?: (error: Error) => any,
8274+
complete?: () => void
8275+
): void;
8276+
8277+
then<T, R>(
8278+
onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>,
8279+
onRejected?: (a: Error) => R | PromiseLike<R>
8280+
): Promise<T | R>;
8281+
8282+
catch<R>(
8283+
onRejected: (a: Error) => R | PromiseLike<R>
8284+
): Promise<R | LoadBundleTaskProgress>;
8285+
}
8286+
8287+
export interface LoadBundleTaskProgress {
8288+
documentsLoaded: number;
8289+
totalDocuments: number;
8290+
bytesLoaded: number;
8291+
totalBytes: number;
8292+
taskState: TaskState;
8293+
}
8294+
8295+
export type TaskState = 'Error' | 'Running' | 'Success';
8296+
82648297
/**
82658298
* An immutable object representing a geo point in Firestore. The geo point
82668299
* is represented as latitude/longitude pair.

packages/firestore-types/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ export class FirebaseFirestore {
9696

9797
terminate(): Promise<void>;
9898

99+
loadBundle(
100+
bundleData: ArrayBuffer | ReadableStream<ArrayBuffer> | string
101+
): LoadBundleTask;
102+
103+
namedQuery(name: string): Promise<Query<DocumentData> | null>;
104+
99105
INTERNAL: { delete: () => Promise<void> };
100106
}
101107

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
import { Code, FirestoreError } from '../../../src/util/error';
4343
import { Deferred } from '../../../src/util/promise';
4444
import { LruParams } from '../../../src/local/lru_garbage_collector';
45-
import { CACHE_SIZE_UNLIMITED, Query } from '../../../src/api/database';
45+
import { CACHE_SIZE_UNLIMITED } from '../../../src/api/database';
4646
import {
4747
indexedDbClearPersistence,
4848
indexedDbStoragePrefix
@@ -74,6 +74,7 @@ import {
7474
import { PersistenceSettings } from '../../../exp-types';
7575
import { getNamedQuery } from '../../../src/local/local_store';
7676
import { newSerializer } from '../../../src/platform/serializer';
77+
import { Query } from '../../../lite/src/api/reference';
7778

7879
const LOG_TAG = 'Firestore';
7980

@@ -578,14 +579,15 @@ export function namedQuery(
578579
firestore: FirebaseFirestore,
579580
name: string
580581
): Promise<Query | null> {
581-
return getLocalStore(firestore).then(localStore => {
582-
return getNamedQuery(localStore, name).then(namedQuery => {
583-
if (!namedQuery) {
584-
return null;
585-
}
582+
return firestore._queue.enqueue(() => {
583+
return getLocalStore(firestore).then(localStore => {
584+
return getNamedQuery(localStore, name).then(namedQuery => {
585+
if (!namedQuery) {
586+
return null;
587+
}
586588

587-
return null;
588-
// return new Query(namedQuery.query, firestore, null);
589+
return new Query(firestore, null, namedQuery.query);
590+
});
589591
});
590592
});
591593
}

packages/firestore/exp/test/shim.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
getDocsFromServer,
4343
initializeFirestore,
4444
loadBundle,
45+
namedQuery,
4546
onSnapshot,
4647
onSnapshotsInSync,
4748
query,
@@ -175,8 +176,8 @@ export class FirebaseFirestore
175176
}
176177

177178
async namedQuery(name: string): Promise<Query | null> {
178-
return null;
179-
// return namedQuery(this._delegate, name);
179+
const query = await namedQuery(this._delegate, name);
180+
return !!query ? new Query<legacy.DocumentData>(this, query) : null;
180181
}
181182

182183
INTERNAL = {

packages/firestore/src/api/database.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ import {
111111
valueDescription,
112112
validateIsNotUsedTogether
113113
} from '../util/input_validation';
114-
import {
115-
setLogLevel as setClientLogLevel,
116-
logWarn
117-
} from '../util/log';
114+
import { setLogLevel as setClientLogLevel, logWarn } from '../util/log';
118115
import { AutoId } from '../util/misc';
119116
import { Deferred } from '../util/promise';
120117
import { FieldPath as ExternalFieldPath } from './field_path';
@@ -627,7 +624,7 @@ export class Firestore implements PublicFirestore, FirebaseService {
627624
}
628625
}
629626

630-
_loadBundle(
627+
loadBundle(
631628
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
632629
): LoadBundleTask {
633630
this.ensureClientConfigured();
@@ -636,7 +633,7 @@ export class Firestore implements PublicFirestore, FirebaseService {
636633
return resultTask;
637634
}
638635

639-
_namedQuery(name: string): Promise<PublicQuery | null> {
636+
namedQuery(name: string): Promise<PublicQuery | null> {
640637
this.ensureClientConfigured();
641638
return this._firestoreClient!.getNamedQuery(name).then(namedQuery => {
642639
if (!namedQuery) {

packages/firestore/src/core/firestore_client.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
} from '../remote/remote_store';
3939
import { AsyncQueue, wrapInUserErrorIfRecoverable } from '../util/async_queue';
4040
import { Code, FirestoreError } from '../util/error';
41-
import { logDebug, logWarn } from '../util/log';
41+
import { logDebug } from '../util/log';
4242
import { Deferred } from '../util/promise';
4343
import {
4444
addSnapshotsInSyncListener,
@@ -535,15 +535,14 @@ export class FirestoreClient {
535535
);
536536
this.asyncQueue.enqueueAndForget(async () => {
537537
loadBundle(this.syncEngine, reader, resultTask);
538-
return resultTask.catch(e => {
539-
logWarn(LOG_TAG, `Loading bundle failed with ${e}`);
540-
});
541538
});
542539
}
543540

544541
getNamedQuery(queryName: string): Promise<NamedQuery | undefined> {
545542
this.verifyNotTerminated();
546-
return getNamedQuery(this.localStore, queryName);
543+
return this.asyncQueue.enqueue(() =>
544+
getNamedQuery(this.localStore, queryName)
545+
);
547546
}
548547
}
549548

packages/firestore/src/core/sync_engine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import {
6060
} from '../remote/remote_store';
6161
import { debugAssert, debugCast, fail, hardAssert } from '../util/assert';
6262
import { Code, FirestoreError } from '../util/error';
63-
import { logDebug } from '../util/log';
63+
import { logDebug, logWarn } from '../util/log';
6464
import { primitiveComparator } from '../util/misc';
6565
import { ObjectMap } from '../util/obj_map';
6666
import { Deferred } from '../util/promise';
@@ -1602,6 +1602,7 @@ async function loadBundleImpl(
16021602
await saveBundle(syncEngine.localStore, metadata);
16031603
task._completeWith(result.progress);
16041604
} catch (e) {
1605+
logWarn(LOG_TAG, `Loading bundle failed with ${e}`);
16051606
task._failWith(e);
16061607
}
16071608
}

packages/firestore/src/remote/serializer.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -339,21 +339,26 @@ export function fromName(
339339
name: string
340340
): DocumentKey {
341341
const resource = fromResourceName(name);
342-
hardAssert(
343-
resource.get(1) === serializer.databaseId.projectId,
344-
'Tried to deserialize key from different project: ' +
345-
resource.get(1) +
346-
' vs ' +
347-
serializer.databaseId.projectId
348-
);
349-
hardAssert(
350-
(!resource.get(3) && !serializer.databaseId.database) ||
351-
resource.get(3) === serializer.databaseId.database,
352-
'Tried to deserialize key from different database: ' +
353-
resource.get(3) +
354-
' vs ' +
355-
serializer.databaseId.database
356-
);
342+
343+
if (resource.get(1) !== serializer.databaseId.projectId) {
344+
throw new FirestoreError(
345+
Code.INVALID_ARGUMENT,
346+
'Tried to deserialize key from different project: ' +
347+
resource.get(1) +
348+
' vs ' +
349+
serializer.databaseId.projectId
350+
);
351+
}
352+
353+
if (resource.get(3) !== serializer.databaseId.database) {
354+
throw new FirestoreError(
355+
Code.INVALID_ARGUMENT,
356+
'Tried to deserialize key from different database: ' +
357+
resource.get(3) +
358+
' vs ' +
359+
serializer.databaseId.database
360+
);
361+
}
357362
return new DocumentKey(extractLocalPathFromResourceName(resource));
358363
}
359364

0 commit comments

Comments
 (0)