Skip to content

Commit cc198ca

Browse files
Add Query/getQuery (firebase#3175)
1 parent 712dfde commit cc198ca

File tree

12 files changed

+844
-499
lines changed

12 files changed

+844
-499
lines changed

packages/firestore/lite/index.node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export {
3737
doc,
3838
parent,
3939
getDoc,
40+
getQuery,
4041
deleteDoc,
4142
setDoc,
4243
updateDoc,

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

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import {
3434
terminateDatastore
3535
} from '../../../src/remote/datastore';
3636
import { PlatformSupport } from '../../../src/platform/platform';
37-
import { Deferred } from '../../../src/util/promise';
3837
import { cast } from './util';
38+
import { Settings } from '../../';
3939

4040
// settings() defaults:
4141
const DEFAULT_HOST = 'firestore.googleapis.com';
@@ -52,8 +52,8 @@ export class Firestore implements firestore.FirebaseFirestore {
5252
private readonly _credentials: CredentialsProvider;
5353

5454
// Assigned via _configureClient()/_ensureClientConfigured()
55-
_settings?: firestore.Settings;
56-
private readonly _datastoreDeferred = new Deferred<Datastore>();
55+
private _settings?: firestore.Settings;
56+
private _datastorePromise?: Promise<Datastore>;
5757

5858
constructor(
5959
app: FirebaseApp,
@@ -78,31 +78,29 @@ export class Firestore implements firestore.FirebaseFirestore {
7878
);
7979
}
8080
this._settings = settings;
81-
82-
const databaseInfo = this._makeDatabaseInfo(settings);
83-
84-
// Kick off initializing the datastore but don't actually wait for it.
85-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
86-
PlatformSupport.getPlatform()
87-
.loadConnection(databaseInfo)
88-
.then(connection => {
89-
const serializer = PlatformSupport.getPlatform().newSerializer(
90-
databaseInfo.databaseId
91-
);
92-
const datastore = newDatastore(
93-
connection,
94-
this._credentials,
95-
serializer
96-
);
97-
this._datastoreDeferred.resolve(datastore);
98-
});
9981
}
10082

101-
_ensureClientConfigured(): Promise<Datastore> {
83+
_getSettings(): Settings {
10284
if (!this._settings) {
10385
this._settings = {};
10486
}
105-
return this._datastoreDeferred.promise;
87+
return this._settings;
88+
}
89+
90+
_getDatastore(): Promise<Datastore> {
91+
if (!this._datastorePromise) {
92+
const databaseInfo = this._makeDatabaseInfo(this._getSettings());
93+
this._datastorePromise = PlatformSupport.getPlatform()
94+
.loadConnection(databaseInfo)
95+
.then(connection => {
96+
const serializer = PlatformSupport.getPlatform().newSerializer(
97+
databaseInfo.databaseId
98+
);
99+
return newDatastore(connection, this._credentials, serializer);
100+
});
101+
}
102+
103+
return this._datastorePromise;
106104
}
107105

108106
private _makeDatabaseInfo(settings: firestore.Settings): DatabaseInfo {
@@ -149,6 +147,6 @@ export function terminate(
149147
// TODO(firestorelite): Call _removeServiceInstance when available
150148
const firestoreClient = cast(firestore, Firestore);
151149
return firestoreClient
152-
._ensureClientConfigured()
150+
._getDatastore()
153151
.then(datastore => terminateDatastore(datastore));
154152
}

0 commit comments

Comments
 (0)