Skip to content

Commit ca0261e

Browse files
Make clearIndexedDbPersistence() work without enableIndexedDbPersistence()
1 parent 9b53ec8 commit ca0261e

File tree

10 files changed

+222
-137
lines changed

10 files changed

+222
-137
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 firebase from 'firebase/app/dist/index.esm.js';
19+
20+
let appCount = 0;
21+
export function newTestFirestore(projectId, nameOrApp, settings) {
22+
if (nameOrApp === undefined) {
23+
nameOrApp = 'test-app-' + appCount++;
24+
}
25+
26+
const app =
27+
typeof nameOrApp === 'string'
28+
? firebase.initializeApp({ apiKey: 'fake-api-key', projectId }, nameOrApp)
29+
: nameOrApp;
30+
31+
const firestore = firebase.firestore(app);
32+
if (settings) {
33+
firestore.settings(settings);
34+
}
35+
return firestore;
36+
}

packages/auth/src/args.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 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.

packages/auth/src/auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 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.

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ import { Code, FirestoreError } from '../../../src/util/error';
4545
import { Deferred } from '../../../src/util/promise';
4646
import { LruParams } from '../../../src/local/lru_garbage_collector';
4747
import { CACHE_SIZE_UNLIMITED } from '../../../src/api/database';
48-
import { DatabaseInfo } from '../../../src/core/database_info';
48+
import { DatabaseId, DatabaseInfo } from '../../../src/core/database_info';
49+
import {
50+
buildStoragePrefix,
51+
clearPersistence
52+
} from '../../../src/local/indexeddb_persistence';
4953

5054
/**
5155
* The root reference to the Firestore database and the entry point for the
@@ -143,7 +147,16 @@ export class Firestore extends LiteFirestore
143147
return terminate(this);
144148
}
145149

146-
_clearPersistence(): Promise<void> {
150+
/**
151+
* Verifies that the client is not running and clears persistence by invoking
152+
* `clearPersistenceDelegate` on the async queue.
153+
*
154+
* @param delegate A function that clears the clients
155+
* backing storage.
156+
*/
157+
_clearPersistence(
158+
delegate: (databaseId: DatabaseId, persistenceKey: string) => Promise<void>
159+
): Promise<void> {
147160
if (this._deferredInitialization !== undefined && !this._terminated) {
148161
throw new FirestoreError(
149162
Code.FAILED_PRECONDITION,
@@ -152,16 +165,10 @@ export class Firestore extends LiteFirestore
152165
);
153166
}
154167

155-
const settings = this._getSettings();
156168
const deferred = new Deferred<void>();
157169
this._queue.enqueueAndForgetEvenAfterShutdown(async () => {
158170
try {
159-
const databaseInfo = this._makeDatabaseInfo(
160-
settings.host,
161-
settings.ssl,
162-
settings.experimentalForceLongPolling
163-
);
164-
await this._componentProvider.clearPersistence(databaseInfo);
171+
await delegate(this._databaseId, this._persistenceKey);
165172
deferred.resolve();
166173
} catch (e) {
167174
deferred.reject(e);
@@ -247,7 +254,9 @@ export function clearIndexedDbPersistence(
247254
firestore: firestore.FirebaseFirestore
248255
): Promise<void> {
249256
const firestoreImpl = cast(firestore, Firestore);
250-
return firestoreImpl._clearPersistence();
257+
return firestoreImpl._clearPersistence((databaseId, persistenceKey) => {
258+
return clearPersistence(buildStoragePrefix(databaseId, persistenceKey));
259+
});
251260
}
252261

253262
export function waitForPendingWrites(

0 commit comments

Comments
 (0)