@@ -28,52 +28,48 @@ import {
28
28
setOfflineComponentProvider ,
29
29
setOnlineComponentProvider
30
30
} from '../../../src/core/firestore_client' ;
31
- import { AsyncQueue } from '../../../src/util/async_queue' ;
32
31
import {
33
32
IndexedDbOfflineComponentProvider ,
34
33
MultiTabOfflineComponentProvider ,
35
34
OfflineComponentProvider ,
36
35
OnlineComponentProvider
37
36
} from '../../../src/core/component_provider' ;
38
- import {
39
- FirebaseFirestore as LiteFirestore ,
40
- Settings as LiteSettings
41
- } from '../../../lite/src/api/database' ;
37
+ import { FirebaseFirestore as LiteFirestore } from '../../../lite/src/api/database' ;
42
38
import { DatabaseId } from '../../../src/core/database_info' ;
43
39
import { Code , FirestoreError } from '../../../src/util/error' ;
44
40
import { Deferred } from '../../../src/util/promise' ;
45
- import { LRU_MINIMUM_CACHE_SIZE_BYTES } from '../../../src/local/lru_garbage_collector' ;
46
- import {
47
- CACHE_SIZE_UNLIMITED ,
48
- configureFirestore ,
49
- ensureFirestoreConfigured
50
- } from '../../../src/api/database' ;
41
+ import { LRU_MINIMUM_CACHE_SIZE_BYTES } from '../../../src/local/lru_garbage_collector_impl' ;
51
42
import {
52
43
indexedDbClearPersistence ,
53
44
indexedDbStoragePrefix
54
45
} from '../../../src/local/indexeddb_persistence' ;
55
46
import { cast } from '../../../src/util/input_validation' ;
47
+ import { makeDatabaseInfo } from '../../../lite/src/api/components' ;
48
+ import { LRU_COLLECTION_DISABLED } from '../../../src/local/lru_garbage_collector' ;
49
+ import { debugAssert } from '../../../src/util/assert' ;
50
+ import { PersistenceSettings , Settings } from './settings' ;
51
+ import { newAsyncQueue } from '../../../src/util/async_queue_impl' ;
52
+ import { AsyncQueue } from '../../../src/util/async_queue' ;
56
53
57
54
/** DOMException error code constants. */
58
55
const DOM_EXCEPTION_INVALID_STATE = 11 ;
59
56
const DOM_EXCEPTION_ABORTED = 20 ;
60
57
const DOM_EXCEPTION_QUOTA_EXCEEDED = 22 ;
61
58
62
- export interface PersistenceSettings {
63
- forceOwnership ?: boolean ;
64
- }
65
-
66
- export interface Settings extends LiteSettings {
67
- cacheSizeBytes ?: number ;
68
- }
59
+ /**
60
+ * Constant used to indicate the LRU garbage collection should be disabled.
61
+ * Set this value as the `cacheSizeBytes` on the settings passed to the
62
+ * `Firestore` instance.
63
+ */
64
+ export const CACHE_SIZE_UNLIMITED = LRU_COLLECTION_DISABLED ;
69
65
70
66
/**
71
67
* The Cloud Firestore service interface.
72
68
*
73
69
* Do not call this constructor directly. Instead, use {@link getFirestore}.
74
70
*/
75
71
export class FirebaseFirestore extends LiteFirestore {
76
- readonly _queue = new AsyncQueue ( ) ;
72
+ readonly _queue : AsyncQueue = newAsyncQueue ( ) ;
77
73
readonly _persistenceKey : string ;
78
74
79
75
_firestoreClient : FirestoreClient | undefined ;
@@ -146,6 +142,36 @@ export function getFirestore(app: FirebaseApp): FirebaseFirestore {
146
142
return _getProvider ( app , 'firestore-exp' ) . getImmediate ( ) as FirebaseFirestore ;
147
143
}
148
144
145
+ export function ensureFirestoreConfigured (
146
+ firestore : FirebaseFirestore
147
+ ) : FirestoreClient {
148
+ if ( ! firestore . _firestoreClient ) {
149
+ configureFirestore ( firestore ) ;
150
+ }
151
+ firestore . _firestoreClient ! . verifyNotTerminated ( ) ;
152
+ return firestore . _firestoreClient as FirestoreClient ;
153
+ }
154
+
155
+ export function configureFirestore ( firestore : FirebaseFirestore ) : void {
156
+ const settings = firestore . _freezeSettings ( ) ;
157
+ debugAssert ( ! ! settings . host , 'FirestoreSettings.host is not set' ) ;
158
+ debugAssert (
159
+ ! firestore . _firestoreClient ,
160
+ 'configureFirestore() called multiple times'
161
+ ) ;
162
+
163
+ const databaseInfo = makeDatabaseInfo (
164
+ firestore . _databaseId ,
165
+ firestore . _persistenceKey ,
166
+ settings
167
+ ) ;
168
+ firestore . _firestoreClient = new FirestoreClient (
169
+ firestore . _credentials ,
170
+ firestore . _queue ,
171
+ databaseInfo
172
+ ) ;
173
+ }
174
+
149
175
/**
150
176
* Attempts to enable persistent storage, if possible.
151
177
*
0 commit comments