|
| 1 | +/*! |
| 2 | + * Copyright 2020 Google Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { FirebaseApp } from '../firebase-app'; |
| 18 | +import * as _firestore from '@google-cloud/firestore'; |
| 19 | +import * as firebaseAdmin from '../index'; |
| 20 | + |
| 21 | +export function firestore(app?: FirebaseApp): _firestore.Firestore { |
| 22 | + if (typeof (app) === 'undefined') { |
| 23 | + app = firebaseAdmin.app(); |
| 24 | + } |
| 25 | + return app.firestore(); |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * We must define a namespace to make the typings work correctly. Otherwise |
| 30 | + * `admin.firestore()` cannot be called like a function. Temporarily, |
| 31 | + * admin.firestore is used as the namespace name because we cannot barrel |
| 32 | + * re-export the contents from firestore, and we want it to |
| 33 | + * match the namespacing in the re-export inside src/index.d.ts |
| 34 | + */ |
| 35 | +/* eslint-disable @typescript-eslint/no-namespace */ |
| 36 | +export namespace admin.firestore { |
| 37 | + // See https://github.com/microsoft/TypeScript/issues/4336 |
| 38 | + /* eslint-disable @typescript-eslint/no-unused-vars */ |
| 39 | + // See https://github.com/typescript-eslint/typescript-eslint/issues/363 |
| 40 | + export import v1beta1 = _firestore.v1beta1; |
| 41 | + export import v1 = _firestore.v1; |
| 42 | + |
| 43 | + export import CollectionReference = _firestore.CollectionReference; |
| 44 | + export import DocumentData = _firestore.DocumentData; |
| 45 | + export import DocumentReference = _firestore.DocumentReference; |
| 46 | + export import DocumentSnapshot = _firestore.DocumentSnapshot; |
| 47 | + export import FieldPath = _firestore.FieldPath; |
| 48 | + export import FieldValue = _firestore.FieldValue; |
| 49 | + export import Firestore = _firestore.Firestore; |
| 50 | + export import GeoPoint = _firestore.GeoPoint; |
| 51 | + export import Query = _firestore.Query; |
| 52 | + export import QueryDocumentSnapshot = _firestore.QueryDocumentSnapshot; |
| 53 | + export import QuerySnapshot = _firestore.QuerySnapshot; |
| 54 | + export import Timestamp = _firestore.Timestamp; |
| 55 | + export import Transaction = _firestore.Transaction; |
| 56 | + export import WriteBatch = _firestore.WriteBatch; |
| 57 | + export import WriteResult = _firestore.WriteResult; |
| 58 | + |
| 59 | + export import setLogFunction = _firestore.setLogFunction; |
| 60 | +} |
0 commit comments