| 1338 | } |
| 1339 | |
| 1340 | export class Firestore implements IFirestore { |
| 1341 | _native: FIRFirestore; |
| 1342 | _app: FirebaseApp; |
| 1343 | |
| 1344 | constructor(app?: FirebaseApp) { |
| 1345 | if (app) { |
| 1346 | this._native = FIRFirestore.firestoreForApp(app.native); |
| 1347 | } else { |
| 1348 | if (defaultFirestore) { |
| 1349 | return defaultFirestore; |
| 1350 | } |
| 1351 | defaultFirestore = this; |
| 1352 | this._native = FIRFirestore.firestore(); |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | static fromNative(store: FIRFirestore) { |
| 1357 | if (store instanceof FIRFirestore) { |
| 1358 | const firestore = new Firestore(); |
| 1359 | firestore._native = store; |
| 1360 | return firestore; |
| 1361 | } |
| 1362 | return null; |
| 1363 | } |
| 1364 | |
| 1365 | useEmulator(host: string, port: number) { |
| 1366 | this.native.useEmulatorWithHostPort(host, port); |
| 1367 | } |
| 1368 | |
| 1369 | batch(): WriteBatch { |
| 1370 | return WriteBatch.fromNative(this.native.batch()); |
| 1371 | } |
| 1372 | |
| 1373 | collection(collectionPath: string): CollectionReference { |
| 1374 | return CollectionReference.fromNative(this.native.collectionWithPath(collectionPath)); |
| 1375 | } |
| 1376 | |
| 1377 | clearPersistence(): Promise<void> { |
| 1378 | return new Promise((resolve, reject) => { |
| 1379 | this.native.clearPersistenceWithCompletion((error) => { |
| 1380 | if (error) { |
| 1381 | reject(FirebaseError.fromNative(error)); |
| 1382 | } else { |
| 1383 | resolve(); |
| 1384 | } |
| 1385 | }); |
| 1386 | }); |
| 1387 | } |
| 1388 | |
| 1389 | collectionGroup(collectionId: string): any { |
| 1390 | return Query.fromNative(this.native.collectionGroupWithID(collectionId)); |
| 1391 | } |
| 1392 | |
| 1393 | disableNetwork(): Promise<void> { |
| 1394 | return new Promise((resolve, reject) => { |
| 1395 | this.native.disableNetworkWithCompletion((error) => { |
| 1396 | if (error) { |
| 1397 | reject(FirebaseError.fromNative(error)); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…