Skip to content

Commit 2541375

Browse files
Remove Cyclic Dependencies (#4160)
1 parent b662f8c commit 2541375

File tree

144 files changed

+7783
-7144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+7783
-7144
lines changed

packages/firestore/exp/index.ts

+29-29
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { registerFirestore } from './register';
1919

2020
registerFirestore();
2121

22-
export { FieldPath, documentId } from '../lite/src/api/field_path';
22+
export { FieldPath, documentId } from './src/api/field_path';
2323

2424
export {
2525
FirebaseFirestore,
@@ -31,11 +31,11 @@ export {
3131
waitForPendingWrites,
3232
disableNetwork,
3333
enableNetwork,
34-
terminate,
35-
Settings,
36-
PersistenceSettings
34+
terminate
3735
} from './src/api/database';
3836

37+
export { Settings, PersistenceSettings } from './src/api/settings';
38+
3939
export {
4040
DocumentChange,
4141
DocumentSnapshot,
@@ -44,41 +44,46 @@ export {
4444
snapshotEqual,
4545
SnapshotOptions,
4646
FirestoreDataConverter,
47-
DocumentChangeType
47+
DocumentChangeType,
48+
SnapshotMetadata
4849
} from './src/api/snapshot';
4950

50-
export { SnapshotMetadata } from '../src/api/database';
51-
5251
export {
5352
DocumentReference,
5453
CollectionReference,
55-
QueryConstraint,
5654
Query,
5755
doc,
5856
collection,
5957
collectionGroup,
60-
startAt,
61-
startAfter,
58+
SetOptions,
59+
DocumentData,
60+
UpdateData,
61+
refEqual,
62+
queryEqual
63+
} from './src/api/reference';
64+
65+
export {
6266
endAt,
6367
endBefore,
64-
query,
68+
startAt,
69+
startAfter,
6570
limit,
6671
limitToLast,
6772
where,
6873
orderBy,
69-
SetOptions,
74+
query,
75+
QueryConstraint,
7076
QueryConstraintType,
71-
DocumentData,
72-
UpdateData,
7377
OrderByDirection,
7478
WhereFilterOp
75-
} from '../lite/src/api/reference';
79+
} from './src/api/query';
7680

7781
export { Unsubscribe } from '../src/api/observer';
7882

7983
export { runTransaction, Transaction } from './src/api/transaction';
8084

8185
export {
86+
SnapshotListenOptions,
8287
getDoc,
8388
getDocFromCache,
8489
getDocFromServer,
@@ -91,33 +96,28 @@ export {
9196
updateDoc,
9297
deleteDoc,
9398
addDoc
94-
} from './src/api/reference';
99+
} from './src/api/reference_impl';
100+
101+
export { FieldValue } from './src/api/field_value';
95102

96103
export {
97-
FieldValue,
98-
deleteField,
99104
increment,
100105
arrayRemove,
101106
arrayUnion,
102-
serverTimestamp
103-
} from '../lite/src/api/field_value';
107+
serverTimestamp,
108+
deleteField
109+
} from './src/api/field_value_impl';
104110

105111
export { setLogLevel, LogLevelString as LogLevel } from '../src/util/log';
106112

107-
export { Bytes } from '../lite/src/api/bytes';
113+
export { Bytes } from './src/api/bytes';
108114

109-
export { writeBatch } from './src/api/write_batch';
110-
111-
export { WriteBatch } from '../lite/src/api/write_batch';
115+
export { WriteBatch, writeBatch } from './src/api/write_batch';
112116

113117
export { GeoPoint } from '../src/api/geo_point';
114118

115119
export { Timestamp } from '../src/api/timestamp';
116120

117-
export { refEqual, queryEqual } from '../lite/src/api/reference';
118-
119-
export { SnapshotListenOptions } from './src/api/reference';
120-
121-
export { CACHE_SIZE_UNLIMITED } from '../src/api/database';
121+
export { CACHE_SIZE_UNLIMITED } from './src/api/database';
122122

123123
export { FirestoreErrorCode, FirestoreError } from '../src/util/error';
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
export { Bytes } from '../../../lite/src/api/bytes';

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

+45-19
Original file line numberDiff line numberDiff line change
@@ -28,52 +28,48 @@ import {
2828
setOfflineComponentProvider,
2929
setOnlineComponentProvider
3030
} from '../../../src/core/firestore_client';
31-
import { AsyncQueue } from '../../../src/util/async_queue';
3231
import {
3332
IndexedDbOfflineComponentProvider,
3433
MultiTabOfflineComponentProvider,
3534
OfflineComponentProvider,
3635
OnlineComponentProvider
3736
} 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';
4238
import { DatabaseId } from '../../../src/core/database_info';
4339
import { Code, FirestoreError } from '../../../src/util/error';
4440
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';
5142
import {
5243
indexedDbClearPersistence,
5344
indexedDbStoragePrefix
5445
} from '../../../src/local/indexeddb_persistence';
5546
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';
5653

5754
/** DOMException error code constants. */
5855
const DOM_EXCEPTION_INVALID_STATE = 11;
5956
const DOM_EXCEPTION_ABORTED = 20;
6057
const DOM_EXCEPTION_QUOTA_EXCEEDED = 22;
6158

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;
6965

7066
/**
7167
* The Cloud Firestore service interface.
7268
*
7369
* Do not call this constructor directly. Instead, use {@link getFirestore}.
7470
*/
7571
export class FirebaseFirestore extends LiteFirestore {
76-
readonly _queue = new AsyncQueue();
72+
readonly _queue: AsyncQueue = newAsyncQueue();
7773
readonly _persistenceKey: string;
7874

7975
_firestoreClient: FirestoreClient | undefined;
@@ -146,6 +142,36 @@ export function getFirestore(app: FirebaseApp): FirebaseFirestore {
146142
return _getProvider(app, 'firestore-exp').getImmediate() as FirebaseFirestore;
147143
}
148144

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+
149175
/**
150176
* Attempts to enable persistent storage, if possible.
151177
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
export { FieldPath, documentId } from '../../../lite/src/api/field_path';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
export { FieldValue } from '../../../lite/src/api/field_value';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
export {
19+
increment,
20+
arrayRemove,
21+
arrayUnion,
22+
serverTimestamp,
23+
deleteField
24+
} from '../../../lite/src/api/field_value_impl';
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
export {
19+
endAt,
20+
endBefore,
21+
startAfter,
22+
startAt,
23+
limitToLast,
24+
limit,
25+
orderBy,
26+
OrderByDirection,
27+
where,
28+
WhereFilterOp,
29+
query,
30+
QueryConstraint,
31+
QueryConstraintType
32+
} from '../../../lite/src/api/query';

0 commit comments

Comments
 (0)