|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2021 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-exp/compat'; |
| 19 | +import { FirebaseAuth, User } from '@firebase/auth-types'; |
| 20 | +import { FirebaseAnalytics } from '@firebase/analytics-types'; |
| 21 | +import { FirebaseApp } from '@firebase/app-compat'; |
| 22 | +import { |
| 23 | + FirebaseFirestore, |
| 24 | + DocumentReference, |
| 25 | + CollectionReference |
| 26 | +} from '@firebase/firestore-types'; |
| 27 | +import { FirebaseFunctions } from '@firebase/functions-types'; |
| 28 | +import { FirebaseInstallations } from '@firebase/installations-types'; |
| 29 | +// Get type directly from messaging package, messaging-compat does not implement |
| 30 | +// the current messaging API. |
| 31 | +import { MessagingCompat } from '../../packages-exp/messaging-compat/src/messaging-compat'; |
| 32 | +import { FirebasePerformance } from '@firebase/performance-types'; |
| 33 | +import { RemoteConfig } from '@firebase/remote-config-types'; |
| 34 | +import { |
| 35 | + FirebaseStorage, |
| 36 | + Reference as StorageReference |
| 37 | +} from '@firebase/storage-types'; |
| 38 | + |
| 39 | +/** |
| 40 | + * Test namespaced types from compat/index.d.ts against the types used in |
| 41 | + * implementation of the actual compat services. In almost all cases the services |
| 42 | + * implement types found in the corresponding -types package. The only exceptions |
| 43 | + * are |
| 44 | + * - messaging, which has changed its public API in the compat version |
| 45 | + * - app-compat, which defines its FirebaseApp type in its own package |
| 46 | + */ |
| 47 | + |
| 48 | +const namespaced: { |
| 49 | + auth: firebase.auth.Auth; |
| 50 | + analytics: firebase.analytics.Analytics; |
| 51 | + app: firebase.app.App; |
| 52 | + firestore: firebase.firestore.Firestore; |
| 53 | + functions: firebase.functions.Functions; |
| 54 | + installations?: firebase.installations.Installations; |
| 55 | + messaging: firebase.messaging.Messaging; |
| 56 | + performance: firebase.performance.Performance; |
| 57 | + remoteConfig: firebase.remoteConfig.RemoteConfig; |
| 58 | + storage: firebase.storage.Storage; |
| 59 | + storageReference: firebase.storage.Reference; |
| 60 | + firestoreDocumentReference: firebase.firestore.DocumentReference; |
| 61 | + firestoreCollectionReference: firebase.firestore.CollectionReference; |
| 62 | + authUser: firebase.User; |
| 63 | +} = { |
| 64 | + auth: firebase.auth(), |
| 65 | + analytics: firebase.analytics(), |
| 66 | + app: firebase.initializeApp({}), |
| 67 | + firestore: firebase.firestore(), |
| 68 | + functions: firebase.functions(), |
| 69 | + installations: {} as firebase.installations.Installations, |
| 70 | + messaging: firebase.messaging(), |
| 71 | + performance: firebase.performance(), |
| 72 | + remoteConfig: firebase.remoteConfig(), |
| 73 | + storage: firebase.storage(), |
| 74 | + storageReference: {} as firebase.storage.Reference, |
| 75 | + firestoreDocumentReference: {} as firebase.firestore.DocumentReference, |
| 76 | + firestoreCollectionReference: {} as firebase.firestore.CollectionReference, |
| 77 | + authUser: {} as firebase.User |
| 78 | +}; |
| 79 | + |
| 80 | +const compatTypes: { |
| 81 | + auth: FirebaseAuth; |
| 82 | + analytics: FirebaseAnalytics; |
| 83 | + app: FirebaseApp; |
| 84 | + firestore: FirebaseFirestore; |
| 85 | + functions: FirebaseFunctions; |
| 86 | + installations?: FirebaseInstallations; |
| 87 | + messaging: MessagingCompat; |
| 88 | + performance: FirebasePerformance; |
| 89 | + remoteConfig: RemoteConfig; |
| 90 | + storage: FirebaseStorage; |
| 91 | + storageReference: StorageReference; |
| 92 | + firestoreDocumentReference: DocumentReference; |
| 93 | + firestoreCollectionReference: CollectionReference; |
| 94 | + authUser: User; |
| 95 | +} = { |
| 96 | + auth: namespaced.auth, |
| 97 | + analytics: namespaced.analytics, |
| 98 | + app: namespaced.app, |
| 99 | + firestore: namespaced.firestore, |
| 100 | + functions: namespaced.functions, |
| 101 | + installations: namespaced.installations, |
| 102 | + messaging: namespaced.messaging, |
| 103 | + performance: namespaced.performance, |
| 104 | + remoteConfig: namespaced.remoteConfig, |
| 105 | + storage: namespaced.storage, |
| 106 | + storageReference: namespaced.storageReference, |
| 107 | + firestoreDocumentReference: namespaced.firestoreDocumentReference, |
| 108 | + firestoreCollectionReference: namespaced.firestoreCollectionReference, |
| 109 | + authUser: namespaced.authUser |
| 110 | +}; |
0 commit comments