Skip to content

Commit dc24a99

Browse files
Review feedback
1 parent a4a8856 commit dc24a99

22 files changed

+375
-490
lines changed

integration/firestore/gulpfile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function clean() {
2828
}
2929

3030
function isPersistenceEnabled() {
31-
return process.env.USE_FIRESTORE_PERSISTENCE !== 'false';
31+
return process.env.DISABLE_FIRESTORE_PERSISTENCE !== 'true';
3232
}
3333

3434
function copyTests() {
@@ -72,9 +72,9 @@ function copyTests() {
7272
import '${firebaseFirestoreSdk}';
7373
7474
if (typeof process === 'undefined') {
75-
process = { env: { USE_FIRESTORE_PERSISTENCE: '${isPersistenceEnabled()}' } } as any;
75+
process = { env: { DISABLE_FIRESTORE_PERSISTENCE: '${!isPersistenceEnabled()}' } } as any;
7676
} else {
77-
process.env.USE_FIRESTORE_PERSISTENCE = '${isPersistenceEnabled()}';
77+
process.env.DISABLE_FIRESTORE_PERSISTENCE = '${!isPersistenceEnabled()}';
7878
}
7979
`
8080
)

integration/firestore/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"private": true,
55
"scripts": {
66
"build:dependencies": "(cd ../../ ; yarn build)",
7-
"build": "yarn build:dependencies; USE_FIRESTORE_PERSISTENCE=true gulp compile-tests",
8-
"build:memory": "yarn build:dependencies; USE_FIRESTORE_PERSISTENCE=false gulp compile-tests",
7+
"build": "yarn build:dependencies; gulp compile-tests",
8+
"build:memory": "yarn build:dependencies; DISABLE_FIRESTORE_PERSISTENCE=true gulp compile-tests",
99
"pretest": "yarn build:dependencies",
1010
"pretest:manual": "yarn build",
1111
"pretest:manual:memory": "yarn build:memory",
1212
"pretest:debug": "yarn build",
1313
"pretest:debug:memort": "yarn build:memory",
14-
"test": "USE_FIRESTORE_PERSISTENCE=true gulp compile-tests; karma start --single-run; USE_FIRESTORE_PERSISTENCE=false gulp compile-tests; karma start --single-run;",
14+
"test": "gulp compile-tests; karma start --single-run; DISABLE_FIRESTORE_PERSISTENCE=true gulp compile-tests; karma start --single-run;",
1515
"test:manual": "karma start --single-run",
1616
"test:manual:memory": "karma start --single-run",
1717
"test:debug": "karma start --auto-watch --browsers Chrome",

packages/firestore/index.memory.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2020 Google Inc.
3+
* Copyright 2020 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -20,12 +20,14 @@ import * as types from '@firebase/firestore-types';
2020
import { FirebaseNamespace } from '@firebase/app-types';
2121

2222
import { configureForFirebase } from './src/platform/config';
23+
import './register-module';
2324
import './src/platform_browser/browser_init';
2425

2526
import { name, version } from './package.json';
27+
import {Firestore, PublicMemoryFirestore} from "./src/api/database";
2628

2729
export function registerFirestore(instance: FirebaseNamespace): void {
28-
configureForFirebase(instance);
30+
configureForFirebase(instance, PublicMemoryFirestore, Firestore);
2931
instance.registerVersion(name, version);
3032
}
3133

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2020 Google Inc.
3+
* Copyright 2020 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -16,43 +16,19 @@
1616
*/
1717

1818
import firebase from '@firebase/app';
19-
import * as types from '@firebase/firestore-types';
2019
import { FirebaseNamespace } from '@firebase/app-types';
2120

2221
import { configureForFirebase } from './src/platform/config';
23-
import './src/platform_browser/browser_init';
22+
import './register-module';
23+
import './src/platform_node/node_init';
2424

2525
import { name, version } from './package.json';
26+
import {Firestore, PublicMemoryFirestore} from "./src/api/database";
2627

2728
export function registerFirestore(instance: FirebaseNamespace): void {
28-
configureForFirebase(instance);
29+
configureForFirebase(instance, PublicMemoryFirestore, Firestore);
2930
instance.registerVersion(name, version);
3031
}
3132

3233
registerFirestore(firebase);
3334

34-
declare module '@firebase/app-types' {
35-
interface FirebaseNamespace {
36-
firestore?: {
37-
(app?: FirebaseApp): types.FirebaseFirestore;
38-
Blob: typeof types.Blob;
39-
CollectionReference: typeof types.CollectionReference;
40-
DocumentReference: typeof types.DocumentReference;
41-
DocumentSnapshot: typeof types.DocumentSnapshot;
42-
FieldPath: typeof types.FieldPath;
43-
FieldValue: typeof types.FieldValue;
44-
Firestore: typeof types.FirebaseFirestore;
45-
GeoPoint: typeof types.GeoPoint;
46-
Query: typeof types.Query;
47-
QueryDocumentSnapshot: typeof types.QueryDocumentSnapshot;
48-
QuerySnapshot: typeof types.QuerySnapshot;
49-
Timestamp: typeof types.Timestamp;
50-
Transaction: typeof types.Transaction;
51-
WriteBatch: typeof types.WriteBatch;
52-
setLogLevel: typeof types.setLogLevel;
53-
};
54-
}
55-
interface FirebaseApp {
56-
firestore?(): types.FirebaseFirestore;
57-
}
58-
}

packages/firestore/index.node.ts

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,21 @@
1515
* limitations under the License.
1616
*/
1717
import firebase from '@firebase/app';
18-
import * as types from '@firebase/firestore-types';
1918
import { configureForFirebase } from './src/platform/config';
20-
import { registerFirestorePersistence } from './src/platform/persistence';
19+
import './register-module';
2120
import './src/platform_node/node_init';
2221
import { FirebaseNamespace } from '@firebase/app-types';
2322

2423
import { name, version } from './package.json';
24+
import {
25+
PersistenceFirestore,
26+
PublicPersistenceFirestore
27+
} from "./src/api/persistence";
2528

2629
export function registerFirestore(instance: FirebaseNamespace): void {
27-
configureForFirebase(instance);
28-
registerFirestorePersistence(instance);
30+
configureForFirebase(instance, PublicPersistenceFirestore, PersistenceFirestore);
2931
instance.registerVersion(name, version, 'node');
3032
}
3133

3234
registerFirestore(firebase);
3335

34-
declare module '@firebase/app-types' {
35-
interface FirebaseNamespace {
36-
firestore?: {
37-
(app?: FirebaseApp): types.FirebaseFirestore;
38-
Blob: typeof types.Blob;
39-
CollectionReference: typeof types.CollectionReference;
40-
DocumentReference: typeof types.DocumentReference;
41-
DocumentSnapshot: typeof types.DocumentSnapshot;
42-
FieldPath: typeof types.FieldPath;
43-
FieldValue: typeof types.FieldValue;
44-
Firestore: typeof types.FirebaseFirestore;
45-
GeoPoint: typeof types.GeoPoint;
46-
Query: typeof types.Query;
47-
QueryDocumentSnapshot: typeof types.QueryDocumentSnapshot;
48-
QuerySnapshot: typeof types.QuerySnapshot;
49-
Timestamp: typeof types.Timestamp;
50-
Transaction: typeof types.Transaction;
51-
WriteBatch: typeof types.WriteBatch;
52-
setLogLevel: typeof types.setLogLevel;
53-
};
54-
}
55-
interface FirebaseApp {
56-
firestore?(): types.FirebaseFirestore;
57-
}
58-
}

packages/firestore/index.ts

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,19 @@
1717

1818
import firebase from '@firebase/app';
1919
import { configureForFirebase } from './src/platform/config';
20-
import { registerFirestorePersistence } from './src/platform/persistence';
2120
import './src/platform_browser/browser_init';
2221

23-
import * as types from '@firebase/firestore-types';
2422
import { FirebaseNamespace } from '@firebase/app-types';
2523

2624
import { name, version } from './package.json';
25+
import {
26+
PersistenceFirestore,
27+
PublicPersistenceFirestore
28+
} from "./src/api/persistence";
2729

2830
export function registerFirestore(instance: FirebaseNamespace): void {
29-
configureForFirebase(instance);
30-
registerFirestorePersistence(instance);
31+
configureForFirebase(instance, PublicPersistenceFirestore, PersistenceFirestore);
3132
instance.registerVersion(name, version);
3233
}
3334

3435
registerFirestore(firebase);
35-
36-
declare module '@firebase/app-types' {
37-
interface FirebaseNamespace {
38-
firestore?: {
39-
(app?: FirebaseApp): types.FirebaseFirestore;
40-
Blob: typeof types.Blob;
41-
CollectionReference: typeof types.CollectionReference;
42-
DocumentReference: typeof types.DocumentReference;
43-
DocumentSnapshot: typeof types.DocumentSnapshot;
44-
FieldPath: typeof types.FieldPath;
45-
FieldValue: typeof types.FieldValue;
46-
Firestore: typeof types.FirebaseFirestore;
47-
GeoPoint: typeof types.GeoPoint;
48-
Query: typeof types.Query;
49-
QueryDocumentSnapshot: typeof types.QueryDocumentSnapshot;
50-
QuerySnapshot: typeof types.QuerySnapshot;
51-
Timestamp: typeof types.Timestamp;
52-
Transaction: typeof types.Transaction;
53-
WriteBatch: typeof types.WriteBatch;
54-
setLogLevel: typeof types.setLogLevel;
55-
};
56-
}
57-
interface FirebaseApp {
58-
firestore?(): types.FirebaseFirestore;
59-
}
60-
}

packages/firestore/register-module.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import * as types from '@firebase/firestore-types';
19+
20+
declare module '@firebase/app-types' {
21+
interface FirebaseNamespace {
22+
firestore?: {
23+
(app?: FirebaseApp): types.FirebaseFirestore;
24+
Blob: typeof types.Blob;
25+
CollectionReference: typeof types.CollectionReference;
26+
DocumentReference: typeof types.DocumentReference;
27+
DocumentSnapshot: typeof types.DocumentSnapshot;
28+
FieldPath: typeof types.FieldPath;
29+
FieldValue: typeof types.FieldValue;
30+
Firestore: typeof types.FirebaseFirestore;
31+
GeoPoint: typeof types.GeoPoint;
32+
Query: typeof types.Query;
33+
QueryDocumentSnapshot: typeof types.QueryDocumentSnapshot;
34+
QuerySnapshot: typeof types.QuerySnapshot;
35+
Timestamp: typeof types.Timestamp;
36+
Transaction: typeof types.Transaction;
37+
WriteBatch: typeof types.WriteBatch;
38+
setLogLevel: typeof types.setLogLevel;
39+
};
40+
}
41+
interface FirebaseApp {
42+
firestore?(): types.FirebaseFirestore;
43+
}
44+
}

packages/firestore/rollup.config.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,6 @@ const es2017Builds = [
200200
},
201201
plugins: es2017BuildPlugins,
202202
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
203-
<<<<<<< HEAD
204-
},
205-
{
206-
input: 'index.ts',
207-
output: {
208-
file: pkg.esm2017Minified,
209-
format: 'es',
210-
sourcemap: true
211-
},
212-
plugins: es2017MinifiedBuildPlugins,
213-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
214203
},
215204
{
216205
input: 'index.memory.ts',
@@ -227,8 +216,6 @@ const es2017Builds = [
227216
}
228217
return deps.some(dep => id === dep || id.startsWith(`${dep}/`));
229218
}
230-
=======
231-
>>>>>>> master
232219
}
233220
];
234221

packages/firestore/src/api/database.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ import { FirebaseApp } from '@firebase/app-types';
2121
import { FirebaseService, _FirebaseApp } from '@firebase/app-types/private';
2222
import { DatabaseId, DatabaseInfo } from '../core/database_info';
2323
import { ListenOptions } from '../core/event_manager';
24-
import {
25-
FirestoreClient,
26-
PersistenceFactory,
27-
newMemoryPersistence
28-
} from '../core/firestore_client';
24+
import { FirestoreClient } from '../core/firestore_client';
2925
import {
3026
Bound,
3127
Direction,
@@ -104,6 +100,8 @@ import {
104100
} from './user_data_converter';
105101
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
106102
import { Provider } from '@firebase/component';
103+
import { newMemoryPersistence } from '../local/memory_persistence';
104+
import { PersistenceFactory } from '../local/persistence';
107105

108106
// settings() defaults:
109107
const DEFAULT_HOST = 'firestore.googleapis.com';
@@ -142,7 +140,7 @@ export interface FirestoreDatabase {
142140
* user-supplied firestore.Settings object. This is a separate type so that
143141
* defaults can be supplied and the value can be checked for equality.
144142
*/
145-
export class FirestoreSettings {
143+
class FirestoreSettings {
146144
/** The hostname to connect to. */
147145
readonly host: string;
148146

@@ -292,15 +290,15 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
292290
private readonly _persistenceKey: string;
293291
private _credentials: CredentialsProvider;
294292
private readonly _firebaseApp: FirebaseApp | null = null;
295-
private _settings: FirestoreSettings;
293+
protected _settings: FirestoreSettings;
296294

297295
// The firestore client instance. This will be available as soon as
298296
// configureClient is called, but any calls against it will block until
299297
// setup has completed.
300298
//
301299
// Operations on the _firestoreClient don't block on _firestoreReady. Those
302300
// are already set to synchronize on the async queue.
303-
private _firestoreClient: FirestoreClient | undefined;
301+
protected _firestoreClient: FirestoreClient | undefined;
304302

305303
// Public for use in tests.
306304
// TODO(mikelehen): Use modularized initialization instead.
@@ -443,12 +441,12 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
443441
if (!this._firestoreClient) {
444442
// Kick off starting the client but don't actually wait for it.
445443
// eslint-disable-next-line @typescript-eslint/no-floating-promises
446-
this._configureClient(newMemoryPersistence);
444+
this._configureClient(newMemoryPersistence, /* persistenceSettings= */ {});
447445
}
448446
return this._firestoreClient as FirestoreClient;
449447
}
450448

451-
private makeDatabaseInfo(): DatabaseInfo {
449+
protected makeDatabaseInfo(): DatabaseInfo {
452450
return new DatabaseInfo(
453451
this._databaseId,
454452
this._persistenceKey,
@@ -458,8 +456,9 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
458456
);
459457
}
460458

461-
private _configureClient(
462-
persistenceFactory: PersistenceFactory
459+
protected _configureClient<T>(
460+
persistenceFactory: PersistenceFactory<T>,
461+
persistenceSettings: T
463462
): Promise<void> {
464463
assert(!!this._settings.host, 'FirestoreSettings.host is not set');
465464

@@ -474,7 +473,7 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
474473
this._queue
475474
);
476475

477-
return this._firestoreClient.start(persistenceFactory);
476+
return this._firestoreClient.start(persistenceFactory, persistenceSettings);
478477
}
479478

480479
private createDataConverter(databaseId: DatabaseId): UserDataConverter {
@@ -2622,7 +2621,7 @@ function applyFirestoreDataConverter<T>(
26222621

26232622
// We're treating the variables as class names, so disable checking for lower
26242623
// case variable names.
2625-
export const PublicFirestore = makeConstructorPrivate(
2624+
export const PublicMemoryFirestore = makeConstructorPrivate(
26262625
Firestore,
26272626
'Use firebase.firestore() instead.'
26282627
);

0 commit comments

Comments
 (0)