From 7c7a821750b40c74655b8db78d7de0d1967d3830 Mon Sep 17 00:00:00 2001 From: Josh Crowther Date: Tue, 26 Dec 2017 14:40:09 -1000 Subject: [PATCH 1/9] Partial revert of a6b6689 to fix wrapper package typings --- packages/firebase/app/index.d.ts | 1598 +++++++++++++++++++- packages/firebase/auth/index.d.ts | 17 - packages/firebase/database/index.d.ts | 17 - packages/firebase/firestore/index.d.ts | 17 - packages/firebase/index.d.ts | 1602 ++++++++++++++++++++- packages/firebase/index.node.d.ts | 20 - packages/firebase/index.react-native.d.ts | 21 - packages/firebase/messaging/index.d.ts | 17 - packages/firebase/storage/index.d.ts | 17 - 9 files changed, 3194 insertions(+), 132 deletions(-) delete mode 100644 packages/firebase/auth/index.d.ts delete mode 100644 packages/firebase/database/index.d.ts delete mode 100644 packages/firebase/firestore/index.d.ts delete mode 100644 packages/firebase/index.node.d.ts delete mode 100644 packages/firebase/index.react-native.d.ts delete mode 100644 packages/firebase/messaging/index.d.ts delete mode 100644 packages/firebase/storage/index.d.ts diff --git a/packages/firebase/app/index.d.ts b/packages/firebase/app/index.d.ts index b1a43ac6c34..a870d29173b 100644 --- a/packages/firebase/app/index.d.ts +++ b/packages/firebase/app/index.d.ts @@ -13,6 +13,1602 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +declare namespace firebase { + type CompleteFn = () => void; + + interface FirebaseError { + code: string; + message: string; + name: string; + stack?: string; + } + + interface Observer { + complete(): any; + error(error: E): any; + next(value: V | null): any; + } + + var SDK_VERSION: string; + + type Unsubscribe = () => void; + + interface User extends firebase.UserInfo { + delete(): Promise; + emailVerified: boolean; + getIdToken(forceRefresh?: boolean): Promise; + getToken(forceRefresh?: boolean): Promise; + isAnonymous: boolean; + linkAndRetrieveDataWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + linkWithCredential(credential: firebase.auth.AuthCredential): Promise; + linkWithPhoneNumber( + phoneNumber: string, + applicationVerifier: firebase.auth.ApplicationVerifier + ): Promise; + linkWithPopup(provider: firebase.auth.AuthProvider): Promise; + linkWithRedirect(provider: firebase.auth.AuthProvider): Promise; + metadata: firebase.auth.UserMetadata; + phoneNumber: string | null; + providerData: (firebase.UserInfo | null)[]; + reauthenticateAndRetrieveDataWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + reauthenticateWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + reauthenticateWithPhoneNumber( + phoneNumber: string, + applicationVerifier: firebase.auth.ApplicationVerifier + ): Promise; + reauthenticateWithPopup(provider: firebase.auth.AuthProvider): Promise; + reauthenticateWithRedirect( + provider: firebase.auth.AuthProvider + ): Promise; + refreshToken: string; + reload(): Promise; + sendEmailVerification( + actionCodeSettings?: firebase.auth.ActionCodeSettings | null + ): Promise; + toJSON(): Object; + unlink(providerId: string): Promise; + updateEmail(newEmail: string): Promise; + updatePassword(newPassword: string): Promise; + updatePhoneNumber( + phoneCredential: firebase.auth.AuthCredential + ): Promise; + updateProfile(profile: { + displayName: string | null; + photoURL: string | null; + }): Promise; + } + + interface UserInfo { + displayName: string | null; + email: string | null; + phoneNumber: string | null; + photoURL: string | null; + providerId: string; + uid: string; + } + + function app(name?: string): firebase.app.App; + + var apps: (firebase.app.App | null)[]; + + function auth(app?: firebase.app.App): firebase.auth.Auth; + + function database(app?: firebase.app.App): firebase.database.Database; + + function initializeApp(options: Object, name?: string): firebase.app.App; + + function messaging(app?: firebase.app.App): firebase.messaging.Messaging; + + function storage(app?: firebase.app.App): firebase.storage.Storage; + + function firestore(app?: firebase.app.App): firebase.firestore.Firestore; +} + +declare namespace firebase.app { + interface App { + auth(): firebase.auth.Auth; + database(): firebase.database.Database; + delete(): Promise; + messaging(): firebase.messaging.Messaging; + name: string; + options: Object; + storage(url?: string): firebase.storage.Storage; + firestore(): firebase.firestore.Firestore; + } +} + +declare namespace firebase.auth { + interface ActionCodeInfo { } + + type ActionCodeSettings = { + android?: { + installApp?: boolean; + minimumVersion?: string; + packageName: string; + }; + handleCodeInApp?: boolean; + iOS?: { bundleId: string }; + url: string; + }; + + type AdditionalUserInfo = { + isNewUser: boolean; + profile: Object | null; + providerId: string; + username?: string | null; + }; + + interface ApplicationVerifier { + type: string; + verify(): Promise; + } + + interface Auth { + app: firebase.app.App; + applyActionCode(code: string): Promise; + checkActionCode(code: string): Promise; + confirmPasswordReset(code: string, newPassword: string): Promise; + createUserWithEmailAndPassword( + email: string, + password: string + ): Promise; + currentUser: firebase.User | null; + fetchProvidersForEmail(email: string): Promise; + getRedirectResult(): Promise; + languageCode: string | null; + onAuthStateChanged( + nextOrObserver: + | firebase.Observer + | ((a: firebase.User | null) => any), + error?: (a: firebase.auth.Error) => any, + completed?: firebase.Unsubscribe + ): firebase.Unsubscribe; + onIdTokenChanged( + nextOrObserver: + | firebase.Observer + | ((a: firebase.User | null) => any), + error?: (a: firebase.auth.Error) => any, + completed?: firebase.Unsubscribe + ): firebase.Unsubscribe; + sendPasswordResetEmail( + email: string, + actionCodeSettings?: firebase.auth.ActionCodeSettings | null + ): Promise; + setPersistence(persistence: firebase.auth.Auth.Persistence): Promise; + signInAndRetrieveDataWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + signInAnonymously(): Promise; + signInWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + signInWithCustomToken(token: string): Promise; + signInWithEmailAndPassword(email: string, password: string): Promise; + signInWithPhoneNumber( + phoneNumber: string, + applicationVerifier: firebase.auth.ApplicationVerifier + ): Promise; + signInWithPopup(provider: firebase.auth.AuthProvider): Promise; + signInWithRedirect(provider: firebase.auth.AuthProvider): Promise; + signOut(): Promise; + useDeviceLanguage(): any; + verifyPasswordResetCode(code: string): Promise; + } + + interface AuthCredential { + providerId: string; + } + + interface AuthProvider { + providerId: string; + } + + interface ConfirmationResult { + confirm(verificationCode: string): Promise; + verificationId: string; + } + + class EmailAuthProvider extends EmailAuthProvider_Instance { + static PROVIDER_ID: string; + static credential( + email: string, + password: string + ): firebase.auth.AuthCredential; + } + class EmailAuthProvider_Instance implements firebase.auth.AuthProvider { + providerId: string; + } + + interface Error { + code: string; + message: string; + } + + class FacebookAuthProvider extends FacebookAuthProvider_Instance { + static PROVIDER_ID: string; + static credential(token: string): firebase.auth.AuthCredential; + } + class FacebookAuthProvider_Instance implements firebase.auth.AuthProvider { + addScope(scope: string): firebase.auth.AuthProvider; + providerId: string; + setCustomParameters( + customOAuthParameters: Object + ): firebase.auth.AuthProvider; + } + + class GithubAuthProvider extends GithubAuthProvider_Instance { + static PROVIDER_ID: string; + static credential(token: string): firebase.auth.AuthCredential; + } + class GithubAuthProvider_Instance implements firebase.auth.AuthProvider { + addScope(scope: string): firebase.auth.AuthProvider; + providerId: string; + setCustomParameters( + customOAuthParameters: Object + ): firebase.auth.AuthProvider; + } + + class GoogleAuthProvider extends GoogleAuthProvider_Instance { + static PROVIDER_ID: string; + static credential( + idToken?: string | null, + accessToken?: string | null + ): firebase.auth.AuthCredential; + } + class GoogleAuthProvider_Instance implements firebase.auth.AuthProvider { + addScope(scope: string): firebase.auth.AuthProvider; + providerId: string; + setCustomParameters( + customOAuthParameters: Object + ): firebase.auth.AuthProvider; + } + + class PhoneAuthProvider extends PhoneAuthProvider_Instance { + static PROVIDER_ID: string; + static credential( + verificationId: string, + verificationCode: string + ): firebase.auth.AuthCredential; + } + class PhoneAuthProvider_Instance implements firebase.auth.AuthProvider { + constructor(auth?: firebase.auth.Auth | null); + providerId: string; + verifyPhoneNumber( + phoneNumber: string, + applicationVerifier: firebase.auth.ApplicationVerifier + ): Promise; + } + + class RecaptchaVerifier extends RecaptchaVerifier_Instance { } + class RecaptchaVerifier_Instance + implements firebase.auth.ApplicationVerifier { + constructor( + container: any | string, + parameters?: Object | null, + app?: firebase.app.App | null + ); + clear(): any; + render(): Promise; + type: string; + verify(): Promise; + } + + class TwitterAuthProvider extends TwitterAuthProvider_Instance { + static PROVIDER_ID: string; + static credential( + token: string, + secret: string + ): firebase.auth.AuthCredential; + } + class TwitterAuthProvider_Instance implements firebase.auth.AuthProvider { + providerId: string; + setCustomParameters( + customOAuthParameters: Object + ): firebase.auth.AuthProvider; + } + + type UserCredential = { + additionalUserInfo?: firebase.auth.AdditionalUserInfo | null; + credential: firebase.auth.AuthCredential | null; + operationType?: string | null; + user: firebase.User | null; + }; + + interface UserMetadata { + creationTime?: string; + lastSignInTime?: string; + } +} + +declare namespace firebase.auth.Auth { + type Persistence = string; + var Persistence: { + LOCAL: Persistence; + NONE: Persistence; + SESSION: Persistence; + }; +} + +declare namespace firebase.database { + interface DataSnapshot { + child(path: string): firebase.database.DataSnapshot; + exists(): boolean; + exportVal(): any; + forEach(action: (a: firebase.database.DataSnapshot) => boolean): boolean; + getPriority(): string | number | null; + hasChild(path: string): boolean; + hasChildren(): boolean; + key: string | null; + numChildren(): number; + val(): any; + ref: firebase.database.Reference; + toJSON(): Object | null; + } + + interface Database { + app: firebase.app.App; + goOffline(): any; + goOnline(): any; + ref(path?: string): firebase.database.Reference; + refFromURL(url: string): firebase.database.Reference; + } + + interface OnDisconnect { + cancel(onComplete?: (a: Error | null) => any): Promise; + remove(onComplete?: (a: Error | null) => any): Promise; + set(value: any, onComplete?: (a: Error | null) => any): Promise; + setWithPriority( + value: any, + priority: number | string | null, + onComplete?: (a: Error | null) => any + ): Promise; + update(values: Object, onComplete?: (a: Error | null) => any): Promise; + } + + interface Query { + endAt( + value: number | string | boolean | null, + key?: string + ): firebase.database.Query; + equalTo( + value: number | string | boolean | null, + key?: string + ): firebase.database.Query; + isEqual(other: firebase.database.Query | null): boolean; + limitToFirst(limit: number): firebase.database.Query; + limitToLast(limit: number): firebase.database.Query; + off( + eventType?: string, + callback?: (a: firebase.database.DataSnapshot, b?: string | null) => any, + context?: Object | null + ): any; + on( + eventType: string, + callback: (a: firebase.database.DataSnapshot | null, b?: string) => any, + cancelCallbackOrContext?: Object | null, + context?: Object | null + ): (a: firebase.database.DataSnapshot | null, b?: string) => any; + once( + eventType: string, + successCallback?: (a: firebase.database.DataSnapshot, b?: string) => any, + failureCallbackOrContext?: Object | null, + context?: Object | null + ): Promise; + orderByChild(path: string): firebase.database.Query; + orderByKey(): firebase.database.Query; + orderByPriority(): firebase.database.Query; + orderByValue(): firebase.database.Query; + ref: firebase.database.Reference; + startAt( + value: number | string | boolean | null, + key?: string + ): firebase.database.Query; + toJSON(): Object; + toString(): string; + } + + interface Reference extends firebase.database.Query { + child(path: string): firebase.database.Reference; + key: string | null; + onDisconnect(): firebase.database.OnDisconnect; + parent: firebase.database.Reference | null; + path: string; + push( + value?: any, + onComplete?: (a: Error | null) => any + ): firebase.database.ThenableReference; + remove(onComplete?: (a: Error | null) => any): Promise; + root: firebase.database.Reference; + set(value: any, onComplete?: (a: Error | null) => any): Promise; + setPriority( + priority: string | number | null, + onComplete: (a: Error | null) => any + ): Promise; + setWithPriority( + newVal: any, + newPriority: string | number | null, + onComplete?: (a: Error | null) => any + ): Promise; + transaction( + transactionUpdate: (a: any) => any, + onComplete?: ( + a: Error | null, + b: boolean, + c: firebase.database.DataSnapshot | null + ) => any, + applyLocally?: boolean + ): Promise; + update(values: Object, onComplete?: (a: Error | null) => any): Promise; + } + + interface ThenableReference + extends firebase.database.Reference, + PromiseLike { } + + function enableLogging( + logger?: boolean | ((a: string) => any), + persistent?: boolean + ): any; +} + +declare namespace firebase.database.ServerValue { + var TIMESTAMP: Object; +} + +declare namespace firebase.messaging { + interface Messaging { + deleteToken(token: string): Promise | null; + getToken(): Promise | null; + onMessage( + nextOrObserver: firebase.Observer | ((a: Object) => any) + ): firebase.Unsubscribe; + onTokenRefresh( + nextOrObserver: firebase.Observer | ((a: Object) => any) + ): firebase.Unsubscribe; + requestPermission(): Promise | null; + setBackgroundMessageHandler(callback: (a: Object) => any): any; + useServiceWorker(registration: any): any; + } +} + +declare namespace firebase.storage { + interface FullMetadata extends firebase.storage.UploadMetadata { + bucket: string; + downloadURLs: string[]; + fullPath: string; + generation: string; + metageneration: string; + name: string; + size: number; + timeCreated: string; + updated: string; + } + + interface Reference { + bucket: string; + child(path: string): firebase.storage.Reference; + delete(): Promise; + fullPath: string; + getDownloadURL(): Promise; + getMetadata(): Promise; + name: string; + parent: firebase.storage.Reference | null; + put( + data: any | any | any, + metadata?: firebase.storage.UploadMetadata + ): firebase.storage.UploadTask; + putString( + data: string, + format?: firebase.storage.StringFormat, + metadata?: firebase.storage.UploadMetadata + ): firebase.storage.UploadTask; + root: firebase.storage.Reference; + storage: firebase.storage.Storage; + toString(): string; + updateMetadata(metadata: firebase.storage.SettableMetadata): Promise; + } + + interface SettableMetadata { + cacheControl?: string | null; + contentDisposition?: string | null; + contentEncoding?: string | null; + contentLanguage?: string | null; + contentType?: string | null; + customMetadata?: { + [/* warning: coerced from ? */ key: string]: string; + } | null; + } + + interface Storage { + app: firebase.app.App; + maxOperationRetryTime: number; + maxUploadRetryTime: number; + ref(path?: string): firebase.storage.Reference; + refFromURL(url: string): firebase.storage.Reference; + setMaxOperationRetryTime(time: number): any; + setMaxUploadRetryTime(time: number): any; + } + + type StringFormat = string; + var StringFormat: { + BASE64: StringFormat; + BASE64URL: StringFormat; + DATA_URL: StringFormat; + RAW: StringFormat; + }; + + type TaskEvent = string; + var TaskEvent: { + STATE_CHANGED: TaskEvent; + }; + + type TaskState = string; + var TaskState: { + CANCELED: TaskState; + ERROR: TaskState; + PAUSED: TaskState; + RUNNING: TaskState; + SUCCESS: TaskState; + }; + + interface UploadMetadata extends firebase.storage.SettableMetadata { + md5Hash?: string | null; + } + + interface UploadTask { + cancel(): boolean; + catch(onRejected: (a: Error) => any): Promise; + on( + event: firebase.storage.TaskEvent, + nextOrObserver?: + | firebase.Observer + | null + | ((a: Object) => any), + error?: ((a: Error) => any) | null, + complete?: (firebase.Unsubscribe) | null + ): Function; + pause(): boolean; + resume(): boolean; + snapshot: firebase.storage.UploadTaskSnapshot; + then( + onFulfilled?: ((a: firebase.storage.UploadTaskSnapshot) => any) | null, + onRejected?: ((a: Error) => any) | null + ): Promise; + } + + interface UploadTaskSnapshot { + bytesTransferred: number; + downloadURL: string | null; + metadata: firebase.storage.FullMetadata; + ref: firebase.storage.Reference; + state: firebase.storage.TaskState; + task: firebase.storage.UploadTask; + totalBytes: number; + } +} + +declare namespace firebase.firestore { + /** + * Document data (for use with `DocumentReference.set()`) consists of fields + * mapped to values. + */ + export type DocumentData = { [field: string]: any }; + + /** + * Update data (for use with `DocumentReference.update()`) consists of field + * paths (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots + * reference nested fields within the document. + */ + export type UpdateData = { [fieldPath: string]: any }; + + /** Settings used to configure a `Firestore` instance. */ + export interface Settings { + /** The hostname to connect to. */ + host?: string; + /** Whether to use SSL when connecting. */ + ssl?: boolean; + } + + export type LogLevel = 'debug' | 'error' | 'silent'; + + function setLogLevel(logLevel: LogLevel): void; + + /** + * `Firestore` represents a Firestore Database and is the entry point for all + * Firestore operations. + */ + export class Firestore { + private constructor(); + + /** + * Specifies custom settings to be used to configure the `Firestore` + * instance. Must be set before invoking any other methods. + * + * @param settings The settings to use. + */ + settings(settings: Settings): void; + + /** + * Attempts to enable persistent storage, if possible. + * + * Must be called before any other methods (other than settings()). + * + * If this fails, enablePersistence() will reject the promise it returns. + * Note that even after this failure, the firestore instance will remain + * usable, however offline persistence will be disabled. + * + * There are several reasons why this can fail, which can be identified by + * the `code` on the error. + * + * * failed-precondition: The app is already open in another browser tab. + * * unimplemented: The browser is incompatible with the offline + * persistence implementation. + * + * @return A promise that represents successfully enabling persistent + * storage. + */ + enablePersistence(): Promise; + + /** + * Gets a `CollectionReference` instance that refers to the collection at + * the specified path. + * + * @param collectionPath A slash-separated path to a collection. + * @return The `CollectionReference` instance. + */ + collection(collectionPath: string): CollectionReference; + + /** + * Gets a `DocumentReference` instance that refers to the document at the + * specified path. + * + * @param documentPath A slash-separated path to a document. + * @return The `DocumentReference` instance. + */ + doc(documentPath: string): DocumentReference; + + /** + * Executes the given updateFunction and then attempts to commit the + * changes applied within the transaction. If any document read within the + * transaction has changed, the updateFunction will be retried. If it fails + * to commit after 5 attempts, the transaction will fail. + * + * @param updateFunction The function to execute within the transaction + * context. + * @return If the transaction completed successfully or was explicitly + * aborted (by the updateFunction returning a failed Promise), the Promise + * returned by the updateFunction will be returned here. Else if the + * transaction failed, a rejected Promise with the corresponding failure + * error will be returned. + */ + runTransaction( + updateFunction: (transaction: Transaction) => Promise + ): Promise; + + /** + * Creates a write batch, used for performing multiple writes as a single + * atomic operation. + */ + batch(): WriteBatch; + + /** + * The `firebase.app.App` associated with this `Firestore` instance. + */ + app: firebase.app.App; + + INTERNAL: { delete: () => Promise }; + } + + /** + * An immutable object representing a geo point in Firestore. The geo point + * is represented as latitude/longitude pair. + * + * Latitude values are in the range of [-90, 90]. + * Longitude values are in the range of [-180, 180]. + */ + export class GeoPoint { + /** + * Creates a new immutable GeoPoint object with the provided latitude and + * longitude values. + * @param latitude The latitude as number between -90 and 90. + * @param longitude The longitude as number between -180 and 180. + */ + constructor(latitude: number, longitude: number); + + readonly latitude: number; + readonly longitude: number; + } + + /** + * An immutable object representing an array of bytes. + */ + export class Blob { + private constructor(); + + /** + * Creates a new Blob from the given Base64 string, converting it to + * bytes. + */ + static fromBase64String(base64: string): Blob; + + /** + * Creates a new Blob from the given Uint8Array. + */ + static fromUint8Array(array: Uint8Array): Blob; + + /** + * Returns the bytes of this Blob as a Base64-encoded string. + */ + public toBase64(): string; + + /** + * Returns the bytes of this Blob in a new Uint8Array. + */ + public toUint8Array(): Uint8Array; + } + + /** + * A reference to a transaction. + * The `Transaction` object passed to a transaction's updateFunction provides + * the methods to read and write data within the transaction context. See + * `Firestore.runTransaction()`. + */ + export class Transaction { + private constructor(); + + /** + * Reads the document referenced by the provided `DocumentReference.` + * + * @param documentRef A reference to the document to be read. + * @return A DocumentSnapshot for the read data. + */ + get(documentRef: DocumentReference): Promise; + + /** + * Writes to the document referred to by the provided `DocumentReference`. + * If the document does not exist yet, it will be created. If you pass + * `SetOptions`, the provided data can be merged into the existing document. + * + * @param documentRef A reference to the document to be set. + * @param data An object of the fields and values for the document. + * @param options An object to configure the set behavior. + * @return This `Transaction` instance. Used for chaining method calls. + */ + set( + documentRef: DocumentReference, + data: DocumentData, + options?: SetOptions + ): Transaction; + + /** + * Updates fields in the document referred to by the provided + * `DocumentReference`. The update will fail if applied to a document that + * does not exist. + * + * @param documentRef A reference to the document to be updated. + * @param data An object containing the fields and values with which to + * update the document. Fields can contain dots to reference nested fields + * within the document. + * @return This `Transaction` instance. Used for chaining method calls. + */ + update(documentRef: DocumentReference, data: UpdateData): Transaction; + + /** + * Updates fields in the document referred to by the provided + * `DocumentReference`. The update will fail if applied to a document that + * does not exist. + * + * Nested fields can be updated by providing dot-separated field path + * strings or by providing FieldPath objects. + * + * @param documentRef A reference to the document to be updated. + * @param field The first field to update. + * @param value The first value. + * @param moreFieldsAndValues Additional key/value pairs. + * @return A Promise resolved once the data has been successfully written + * to the backend (Note that it won't resolve while you're offline). + */ + update( + documentRef: DocumentReference, + field: string | FieldPath, + value: any, + ...moreFieldsAndValues: any[] + ): Transaction; + + /** + * Deletes the document referred to by the provided `DocumentReference`. + * + * @param documentRef A reference to the document to be deleted. + * @return This `Transaction` instance. Used for chaining method calls. + */ + delete(documentRef: DocumentReference): Transaction; + } + + /** + * A write batch, used to perform multiple writes as a single atomic unit. + * + * A `WriteBatch` object can be acquired by calling `Firestore.batch()`. It + * provides methods for adding writes to the write batch. None of the + * writes will be committed (or visible locally) until `WriteBatch.commit()` + * is called. + * + * Unlike transactions, write batches are persisted offline and therefore are + * preferable when you don't need to condition your writes on read data. + */ + export class WriteBatch { + private constructor(); + + /** + * Writes to the document referred to by the provided `DocumentReference`. + * If the document does not exist yet, it will be created. If you pass + * `SetOptions`, the provided data can be merged into the existing document. + * + * @param documentRef A reference to the document to be set. + * @param data An object of the fields and values for the document. + * @param options An object to configure the set behavior. + * @return This `WriteBatch` instance. Used for chaining method calls. + */ + set( + documentRef: DocumentReference, + data: DocumentData, + options?: SetOptions + ): WriteBatch; + + /** + * Updates fields in the document referred to by the provided + * `DocumentReference`. The update will fail if applied to a document that + * does not exist. + * + * @param documentRef A reference to the document to be updated. + * @param data An object containing the fields and values with which to + * update the document. Fields can contain dots to reference nested fields + * within the document. + * @return This `WriteBatch` instance. Used for chaining method calls. + */ + update(documentRef: DocumentReference, data: UpdateData): WriteBatch; + + /** + * Updates fields in the document referred to by this `DocumentReference`. + * The update will fail if applied to a document that does not exist. + * + * Nested fields can be update by providing dot-separated field path strings + * or by providing FieldPath objects. + * + * @param documentRef A reference to the document to be updated. + * @param field The first field to update. + * @param value The first value. + * @param moreFieldsAndValues Additional key value pairs. + * @return A Promise resolved once the data has been successfully written + * to the backend (Note that it won't resolve while you're offline). + */ + update( + documentRef: DocumentReference, + field: string | FieldPath, + value: any, + ...moreFieldsAndValues: any[] + ): WriteBatch; + + /** + * Deletes the document referred to by the provided `DocumentReference`. + * + * @param documentRef A reference to the document to be deleted. + * @return This `WriteBatch` instance. Used for chaining method calls. + */ + delete(documentRef: DocumentReference): WriteBatch; + + /** + * Commits all of the writes in this write batch as a single atomic unit. + * + * @return A Promise resolved once all of the writes in the batch have been + * successfully written to the backend as an atomic unit. Note that it won't + * resolve while you're offline. + */ + commit(): Promise; + } + + /** + * Options for use with `DocumentReference.onSnapshot()` to control the + * behavior of the snapshot listener. + */ + export interface DocumentListenOptions { + /** + * Raise an event even if only metadata of the document changed. Default is + * false. + */ + readonly includeMetadataChanges?: boolean; + } + + /** + * An options object that configures the behavior of `set()` calls in + * `DocumentReference`, `WriteBatch` and `Transaction`. These calls can be + * configured to perform granular merges instead of overwriting the target + * documents in their entirety by providing a `SetOptions` with `merge: true`. + */ + export interface SetOptions { + /** + * Changes the behavior of a set() call to only replace the values specified + * in its data argument. Fields omitted from the set() call remain + * untouched. + */ + readonly merge?: boolean; + } + + /** + * A `DocumentReference` refers to a document location in a Firestore database + * and can be used to write, read, or listen to the location. The document at + * the referenced location may or may not exist. A `DocumentReference` can + * also be used to create a `CollectionReference` to a subcollection. + */ + export class DocumentReference { + private constructor(); + + /** The identifier of the document within its collection. */ + readonly id: string; + + /** + * The `Firestore` for the Firestore database (useful for performing + * transactions, etc.). + */ + readonly firestore: Firestore; + + /** + * A reference to the Collection to which this DocumentReference belongs. + */ + readonly parent: CollectionReference; + + /** + * A string representing the path of the referenced document (relative + * to the root of the database). + */ + readonly path: string; + + /** + * Gets a `CollectionReference` instance that refers to the collection at + * the specified path. + * + * @param collectionPath A slash-separated path to a collection. + * @return The `CollectionReference` instance. + */ + collection(collectionPath: string): CollectionReference; + + /** + * Returns true if this `DocumentReference` is equal to the provided one. + * + * @param other The `DocumentReference` to compare against. + * @return true if this `DocumentReference` is equal to the provided one. + */ + isEqual(other: DocumentReference): boolean; + + /** + * Writes to the document referred to by this `DocumentReference`. If the + * document does not yet exist, it will be created. If you pass + * `SetOptions`, the provided data can be merged into an existing document. + * + * @param data A map of the fields and values for the document. + * @param options An object to configure the set behavior. + * @return A Promise resolved once the data has been successfully written + * to the backend (Note that it won't resolve while you're offline). + */ + set(data: DocumentData, options?: SetOptions): Promise; + + /** + * Updates fields in the document referred to by this `DocumentReference`. + * The update will fail if applied to a document that does not exist. + * + * @param data An object containing the fields and values with which to + * update the document. Fields can contain dots to reference nested fields + * within the document. + * @return A Promise resolved once the data has been successfully written + * to the backend (Note that it won't resolve while you're offline). + */ + update(data: UpdateData): Promise; + + /** + * Updates fields in the document referred to by this `DocumentReference`. + * The update will fail if applied to a document that does not exist. + * + * Nested fields can be updated by providing dot-separated field path + * strings or by providing FieldPath objects. + * + * @param field The first field to update. + * @param value The first value. + * @param moreFieldsAndValues Additional key value pairs. + * @return A Promise resolved once the data has been successfully written + * to the backend (Note that it won't resolve while you're offline). + */ + update( + field: string | FieldPath, + value: any, + ...moreFieldsAndValues: any[] + ): Promise; + + /** + * Deletes the document referred to by this `DocumentReference`. + * + * @return A Promise resolved once the document has been successfully + * deleted from the backend (Note that it won't resolve while you're + * offline). + */ + delete(): Promise; + + /** + * Reads the document referred to by this `DocumentReference`. + * + * Note: get() attempts to provide up-to-date data when possible by waiting + * for data from the server, but it may return cached data or fail if you + * are offline and the server cannot be reached. + * + * @return A Promise resolved with a DocumentSnapshot containing the + * current document contents. + */ + get(): Promise; + + /** + * Attaches a listener for DocumentSnapshot events. You may either pass + * individual `onNext` and `onError` callbacks or pass a single observer + * object with `next` and `error` callbacks. + * + * NOTE: Although an `onCompletion` callback can be provided, it will + * never be called because the snapshot stream is never-ending. + * + * @param options Options controlling the listen behavior. + * @param onNext A callback to be called every time a new `DocumentSnapshot` + * is available. + * @param onError A callback to be called if the listen fails or is + * cancelled. No further callbacks will occur. + * @param observer A single object containing `next` and `error` callbacks. + * @return An unsubscribe function that can be called to cancel + * the snapshot listener. + */ + onSnapshot(observer: { + next?: (snapshot: DocumentSnapshot) => void; + error?: (error: FirestoreError) => void; + complete?: () => void; + }): () => void; + onSnapshot( + options: DocumentListenOptions, + observer: { + next?: (snapshot: DocumentSnapshot) => void; + error?: (error: Error) => void; + complete?: () => void; + } + ): () => void; + onSnapshot( + onNext: (snapshot: DocumentSnapshot) => void, + onError?: (error: Error) => void, + onCompletion?: () => void + ): () => void; + onSnapshot( + options: DocumentListenOptions, + onNext: (snapshot: DocumentSnapshot) => void, + onError?: (error: Error) => void, + onCompletion?: () => void + ): () => void; + } + + /** Metadata about a snapshot, describing the state of the snapshot. */ + export interface SnapshotMetadata { + /** + * True if the snapshot contains the result of local writes (e.g. set() or + * update() calls) that have not yet been committed to the backend. + * If your listener has opted into metadata updates (via + * `DocumentListenOptions` or `QueryListenOptions`) you will receive another + * snapshot with `hasPendingWrites` equal to false once the writes have been + * committed to the backend. + */ + readonly hasPendingWrites: boolean; + + /** + * True if the snapshot was created from cached data rather than + * guaranteed up-to-date server data. If your listener has opted into + * metadata updates (via `DocumentListenOptions` or `QueryListenOptions`) + * you will receive another snapshot with `fromCache` equal to false once + * the client has received up-to-date data from the backend. + */ + readonly fromCache: boolean; + } + + /** + * A `DocumentSnapshot` contains data read from a document in your Firestore + * database. The data can be extracted with `.data()` or `.get()` to + * get a specific field. + */ + export class DocumentSnapshot { + private constructor(); + + /** True if the document exists. */ + readonly exists: boolean; + /** A `DocumentReference` to the document location. */ + readonly ref: DocumentReference; + /** + * The ID of the document for which this `DocumentSnapshot` contains data. + */ + readonly id: string; + /** + * Metadata about this snapshot, concerning its source and if it has local + * modifications. + */ + readonly metadata: SnapshotMetadata; + + /** + * Retrieves all fields in the document as an Object. + * + * @return An Object containing all fields in the document. + */ + data(): DocumentData; + + /** + * Retrieves the field specified by `fieldPath`. + * + * @param fieldPath The path (e.g. 'foo' or 'foo.bar') to a specific field. + * @return The data at the specified field location or undefined if no such + * field exists in the document. + */ + get(fieldPath: string | FieldPath): any; + } + + /** + * The direction of a `Query.orderBy()` clause is specified as 'desc' or 'asc' + * (descending or ascending). + */ + export type OrderByDirection = 'desc' | 'asc'; + + /** + * Filter conditions in a `Query.where()` clause are specified using the + * strings '<', '<=', '==', '>=', and '>'. + */ + export type WhereFilterOp = '<' | '<=' | '==' | '>=' | '>'; + + /** + * Options for use with `Query.onSnapshot() to control the behavior of the + * snapshot listener. + */ + export interface QueryListenOptions { + /** + * Raise an event even if only metadata changes (i.e. one of the + * `QuerySnapshot.metadata` properties). Default is false. + */ + readonly includeQueryMetadataChanges?: boolean; + + /** + * Raise an event even if only metadata of a document in the query results + * changes (i.e. one of the `DocumentSnapshot.metadata` properties on one of + * the documents). Default is false. + */ + readonly includeDocumentMetadataChanges?: boolean; + } + + /** + * A `Query` refers to a Query which you can read or listen to. You can also + * construct refined `Query` objects by adding filters and ordering. + */ + export class Query { + protected constructor(); + + /** + * The `Firestore` for the Firestore database (useful for performing + * transactions, etc.). + */ + readonly firestore: Firestore; + + /** + * Creates and returns a new Query with the additional filter that documents + * must contain the specified field and the value should satisfy the + * relation constraint provided. + * + * @param fieldPath The path to compare + * @param opStr The operation string (e.g "<", "<=", "==", ">", ">="). + * @param value The value for comparison + * @return The created Query. + */ + where( + fieldPath: string | FieldPath, + opStr: WhereFilterOp, + value: any + ): Query; + + /** + * Creates and returns a new Query that's additionally sorted by the + * specified field, optionally in descending order instead of ascending. + * + * @param fieldPath The field to sort by. + * @param directionStr Optional direction to sort by ('asc' or 'desc'). If + * not specified, order will be ascending. + * @return The created Query. + */ + orderBy( + fieldPath: string | FieldPath, + directionStr?: OrderByDirection + ): Query; + + /** + * Creates and returns a new Query that's additionally limited to only + * return up to the specified number of documents. + * + * @param limit The maximum number of items to return. + * @return The created Query. + */ + limit(limit: number): Query; + + /** + * Creates and returns a new Query that starts at the provided document + * (inclusive). The starting position is relative to the order of the query. + * The document must contain all of the fields provided in the orderBy of + * this query. + * + * @param snapshot The snapshot of the document to start at. + * @return The created Query. + */ + startAt(snapshot: DocumentSnapshot): Query; + + /** + * Creates and returns a new Query that starts at the provided fields + * relative to the order of the query. The order of the field values + * must match the order of the order by clauses of the query. + * + * @param fieldValues The field values to start this query at, in order + * of the query's order by. + * @return The created Query. + */ + startAt(...fieldValues: any[]): Query; + + /** + * Creates and returns a new Query that starts after the provided document + * (exclusive). The starting position is relative to the order of the query. + * The document must contain all of the fields provided in the orderBy of + * this query. + * + * @param snapshot The snapshot of the document to start after. + * @return The created Query. + */ + startAfter(snapshot: DocumentSnapshot): Query; + + /** + * Creates and returns a new Query that starts after the provided fields + * relative to the order of the query. The order of the field values + * must match the order of the order by clauses of the query. + * + * @param fieldValues The field values to start this query after, in order + * of the query's order by. + * @return The created Query. + */ + startAfter(...fieldValues: any[]): Query; + + /** + * Creates and returns a new Query that ends before the provided document + * (exclusive). The end position is relative to the order of the query. The + * document must contain all of the fields provided in the orderBy of this + * query. + * + * @param snapshot The snapshot of the document to end before. + * @return The created Query. + */ + endBefore(snapshot: DocumentSnapshot): Query; + + /** + * Creates and returns a new Query that ends before the provided fields + * relative to the order of the query. The order of the field values + * must match the order of the order by clauses of the query. + * + * @param fieldValues The field values to end this query before, in order + * of the query's order by. + * @return The created Query. + */ + endBefore(...fieldValues: any[]): Query; + + /** + * Creates and returns a new Query that ends at the provided document + * (inclusive). The end position is relative to the order of the query. The + * document must contain all of the fields provided in the orderBy of this + * query. + * + * @param snapshot The snapshot of the document to end at. + * @return The created Query. + */ + endAt(snapshot: DocumentSnapshot): Query; + + /** + * Creates and returns a new Query that ends at the provided fields + * relative to the order of the query. The order of the field values + * must match the order of the order by clauses of the query. + * + * @param fieldValues The field values to end this query at, in order + * of the query's order by. + * @return The created Query. + */ + endAt(...fieldValues: any[]): Query; + + /** + * Returns true if this `Query` is equal to the provided one. + * + * @param other The `Query` to compare against. + * @return true if this `Query` is equal to the provided one. + */ + isEqual(other: Query): boolean; + + /** + * Executes the query and returns the results as a QuerySnapshot. + * + * @return A Promise that will be resolved with the results of the Query. + */ + get(): Promise; + + /** + * Attaches a listener for QuerySnapshot events. You may either pass + * individual `onNext` and `onError` callbacks or pass a single observer + * object with `next` and `error` callbacks. + * + * NOTE: Although an `onCompletion` callback can be provided, it will + * never be called because the snapshot stream is never-ending. + * + * @param options Options controlling the listen behavior. + * @param onNext A callback to be called every time a new `QuerySnapshot` + * is available. + * @param onError A callback to be called if the listen fails or is + * cancelled. No further callbacks will occur. + * @param observer A single object containing `next` and `error` callbacks. + * @return An unsubscribe function that can be called to cancel + * the snapshot listener. + */ + onSnapshot(observer: { + next?: (snapshot: QuerySnapshot) => void; + error?: (error: Error) => void; + complete?: () => void; + }): () => void; + onSnapshot( + options: QueryListenOptions, + observer: { + next?: (snapshot: QuerySnapshot) => void; + error?: (error: Error) => void; + complete?: () => void; + } + ): () => void; + onSnapshot( + onNext: (snapshot: QuerySnapshot) => void, + onError?: (error: Error) => void, + onCompletion?: () => void + ): () => void; + onSnapshot( + options: QueryListenOptions, + onNext: (snapshot: QuerySnapshot) => void, + onError?: (error: Error) => void, + onCompletion?: () => void + ): () => void; + } + + /** + * A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects + * representing the results of a query. The documents can be accessed as an + * array via the `docs` property or enumerated using the `forEach` method. The + * number of documents can be determined via the `empty` and `size` + * properties. + */ + export class QuerySnapshot { + private constructor(); + + /** + * The query on which you called `get` or `onSnapshot` in order to get this + * `QuerySnapshot`. + */ + readonly query: Query; + /** + * Metadata about this snapshot, concerning its source and if it has local + * modifications. + */ + readonly metadata: SnapshotMetadata; + /** + * An array of the documents that changed since the last snapshot. If this + * is the first snapshot, all documents will be in the list as added + * changes. + */ + readonly docChanges: DocumentChange[]; + + /** An array of all the documents in the QuerySnapshot. */ + readonly docs: DocumentSnapshot[]; + + /** The number of documents in the QuerySnapshot. */ + readonly size: number; + + /** True if there are no documents in the QuerySnapshot. */ + readonly empty: boolean; + + /** + * Enumerates all of the documents in the QuerySnapshot. + * + * @param callback A callback to be called with a `DocumentSnapshot` for + * each document in the snapshot. + * @param thisArg The `this` binding for the callback. + */ + forEach(callback: (result: DocumentSnapshot) => void, thisArg?: any): void; + } + + /** + * The type of of a `DocumentChange` may be 'added', 'removed', or 'modified'. + */ + export type DocumentChangeType = 'added' | 'removed' | 'modified'; + + /** + * A `DocumentChange` represents a change to the documents matching a query. + * It contains the document affected and the type of change that occurred. + */ + export interface DocumentChange { + /** The type of change ('added', 'modified', or 'removed'). */ + readonly type: DocumentChangeType; + + /** The document affected by this change. */ + readonly doc: DocumentSnapshot; + + /** + * The index of the changed document in the result set immediately prior to + * this DocumentChange (i.e. supposing that all prior DocumentChange objects + * have been applied). Is -1 for 'added' events. + */ + readonly oldIndex: number; + + /** + * The index of the changed document in the result set immediately after + * this DocumentChange (i.e. supposing that all prior DocumentChange + * objects and the current DocumentChange object have been applied). + * Is -1 for 'removed' events. + */ + readonly newIndex: number; + } + + /** + * A `CollectionReference` object can be used for adding documents, getting + * document references, and querying for documents (using the methods + * inherited from `Query`). + */ + export class CollectionReference extends Query { + private constructor(); + + /** The identifier of the collection. */ + readonly id: string; + + /** + * A reference to the containing Document if this is a subcollection, else + * null. + */ + readonly parent: DocumentReference | null; + + /** + * A string representing the path of the referenced collection (relative + * to the root of the database). + */ + readonly path: string; + + /** + * Get a `DocumentReference` for the document within the collection at the + * specified path. If no path is specified, an automatically-generated + * unique ID will be used for the returned DocumentReference. + * + * @param documentPath A slash-separated path to a document. + * @return The `DocumentReference` instance. + */ + doc(documentPath?: string): DocumentReference; + + /** + * Add a new document to this collection with the specified data, assigning + * it a document ID automatically. + * + * @param data An Object containing the data for the new document. + * @return A Promise resolved with a `DocumentReference` pointing to the + * newly created document after it has been written to the backend. + */ + add(data: DocumentData): Promise; + } + + /** + * Sentinel values that can be used when writing document fields with set() + * or update(). + */ + export class FieldValue { + private constructor(); + + /** + * Returns a sentinel used with set() or update() to include a + * server-generated timestamp in the written data. + */ + static serverTimestamp(): FieldValue; + + /** + * Returns a sentinel for use with update() to mark a field for deletion. + */ + static delete(): FieldValue; + } + + /** + * A FieldPath refers to a field in a document. The path may consist of a + * single field name (referring to a top-level field in the document), or a + * list of field names (referring to a nested field in the document). + */ + export class FieldPath { + /** + * Creates a FieldPath from the provided field names. If more than one field + * name is provided, the path will point to a nested field in a document. + * + * @param fieldNames A list of field names. + */ + constructor(...fieldNames: string[]); + + /** + * Returns a special sentinel FieldPath to refer to the ID of a document. + * It can be used in queries to sort or filter by the document ID. + */ + static documentId(): FieldPath; + } + + /** + * The set of Firestore status codes. The codes are the same at the ones + * exposed by gRPC here: + * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md + * + * Possible values: + * - 'cancelled': The operation was cancelled (typically by the caller). + * - 'unknown': Unknown error or an error from a different error domain. + * - 'invalid-argument': Client specified an invalid argument. Note that this + * differs from 'failed-precondition'. 'invalid-argument' indicates + * arguments that are problematic regardless of the state of the system + * (e.g. an invalid field name). + * - 'deadline-exceeded': Deadline expired before operation could complete. + * For operations that change the state of the system, this error may be + * returned even if the operation has completed successfully. For example, + * a successful response from a server could have been delayed long enough + * for the deadline to expire. + * - 'not-found': Some requested document was not found. + * - 'already-exists': Some document that we attempted to create already + * exists. + * - 'permission-denied': The caller does not have permission to execute the + * specified operation. + * - 'resource-exhausted': Some resource has been exhausted, perhaps a + * per-user quota, or perhaps the entire file system is out of space. + * - 'failed-precondition': Operation was rejected because the system is not + * in a state required for the operation's execution. + * - 'aborted': The operation was aborted, typically due to a concurrency + * issue like transaction aborts, etc. + * - 'out-of-range': Operation was attempted past the valid range. + * - 'unimplemented': Operation is not implemented or not supported/enabled. + * - 'internal': Internal errors. Means some invariants expected by + * underlying system has been broken. If you see one of these errors, + * something is very broken. + * - 'unavailable': The service is currently unavailable. This is most likely + * a transient condition and may be corrected by retrying with a backoff. + * - 'data-loss': Unrecoverable data loss or corruption. + * - 'unauthenticated': The request does not have valid authentication + * credentials for the operation. + */ + export type FirestoreErrorCode = + | 'cancelled' + | 'unknown' + | 'invalid-argument' + | 'deadline-exceeded' + | 'not-found' + | 'already-exists' + | 'permission-denied' + | 'resource-exhausted' + | 'failed-precondition' + | 'aborted' + | 'out-of-range' + | 'unimplemented' + | 'internal' + | 'unavailable' + | 'data-loss' + | 'unauthenticated'; + + /** An error returned by a Firestore operation. */ + // TODO(b/63008957): FirestoreError should extend firebase.FirebaseError + export interface FirestoreError { + code: FirestoreErrorCode; + message: string; + name: string; + stack?: string; + } +} -import firebase from '@firebase/app'; export = firebase; diff --git a/packages/firebase/auth/index.d.ts b/packages/firebase/auth/index.d.ts deleted file mode 100644 index 89f0d70592e..00000000000 --- a/packages/firebase/auth/index.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright 2017 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import '@firebase/auth'; diff --git a/packages/firebase/database/index.d.ts b/packages/firebase/database/index.d.ts deleted file mode 100644 index 73bafde0e0a..00000000000 --- a/packages/firebase/database/index.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright 2017 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import '@firebase/database'; diff --git a/packages/firebase/firestore/index.d.ts b/packages/firebase/firestore/index.d.ts deleted file mode 100644 index 525e7d92700..00000000000 --- a/packages/firebase/firestore/index.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright 2017 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import '@firebase/firestore'; diff --git a/packages/firebase/index.d.ts b/packages/firebase/index.d.ts index 4bbd48b5612..a870d29173b 100644 --- a/packages/firebase/index.d.ts +++ b/packages/firebase/index.d.ts @@ -13,10 +13,1602 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +declare namespace firebase { + type CompleteFn = () => void; + + interface FirebaseError { + code: string; + message: string; + name: string; + stack?: string; + } + + interface Observer { + complete(): any; + error(error: E): any; + next(value: V | null): any; + } + + var SDK_VERSION: string; + + type Unsubscribe = () => void; + + interface User extends firebase.UserInfo { + delete(): Promise; + emailVerified: boolean; + getIdToken(forceRefresh?: boolean): Promise; + getToken(forceRefresh?: boolean): Promise; + isAnonymous: boolean; + linkAndRetrieveDataWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + linkWithCredential(credential: firebase.auth.AuthCredential): Promise; + linkWithPhoneNumber( + phoneNumber: string, + applicationVerifier: firebase.auth.ApplicationVerifier + ): Promise; + linkWithPopup(provider: firebase.auth.AuthProvider): Promise; + linkWithRedirect(provider: firebase.auth.AuthProvider): Promise; + metadata: firebase.auth.UserMetadata; + phoneNumber: string | null; + providerData: (firebase.UserInfo | null)[]; + reauthenticateAndRetrieveDataWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + reauthenticateWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + reauthenticateWithPhoneNumber( + phoneNumber: string, + applicationVerifier: firebase.auth.ApplicationVerifier + ): Promise; + reauthenticateWithPopup(provider: firebase.auth.AuthProvider): Promise; + reauthenticateWithRedirect( + provider: firebase.auth.AuthProvider + ): Promise; + refreshToken: string; + reload(): Promise; + sendEmailVerification( + actionCodeSettings?: firebase.auth.ActionCodeSettings | null + ): Promise; + toJSON(): Object; + unlink(providerId: string): Promise; + updateEmail(newEmail: string): Promise; + updatePassword(newPassword: string): Promise; + updatePhoneNumber( + phoneCredential: firebase.auth.AuthCredential + ): Promise; + updateProfile(profile: { + displayName: string | null; + photoURL: string | null; + }): Promise; + } + + interface UserInfo { + displayName: string | null; + email: string | null; + phoneNumber: string | null; + photoURL: string | null; + providerId: string; + uid: string; + } + + function app(name?: string): firebase.app.App; + + var apps: (firebase.app.App | null)[]; + + function auth(app?: firebase.app.App): firebase.auth.Auth; + + function database(app?: firebase.app.App): firebase.database.Database; + + function initializeApp(options: Object, name?: string): firebase.app.App; + + function messaging(app?: firebase.app.App): firebase.messaging.Messaging; + + function storage(app?: firebase.app.App): firebase.storage.Storage; + + function firestore(app?: firebase.app.App): firebase.firestore.Firestore; +} + +declare namespace firebase.app { + interface App { + auth(): firebase.auth.Auth; + database(): firebase.database.Database; + delete(): Promise; + messaging(): firebase.messaging.Messaging; + name: string; + options: Object; + storage(url?: string): firebase.storage.Storage; + firestore(): firebase.firestore.Firestore; + } +} + +declare namespace firebase.auth { + interface ActionCodeInfo { } + + type ActionCodeSettings = { + android?: { + installApp?: boolean; + minimumVersion?: string; + packageName: string; + }; + handleCodeInApp?: boolean; + iOS?: { bundleId: string }; + url: string; + }; + + type AdditionalUserInfo = { + isNewUser: boolean; + profile: Object | null; + providerId: string; + username?: string | null; + }; + + interface ApplicationVerifier { + type: string; + verify(): Promise; + } + + interface Auth { + app: firebase.app.App; + applyActionCode(code: string): Promise; + checkActionCode(code: string): Promise; + confirmPasswordReset(code: string, newPassword: string): Promise; + createUserWithEmailAndPassword( + email: string, + password: string + ): Promise; + currentUser: firebase.User | null; + fetchProvidersForEmail(email: string): Promise; + getRedirectResult(): Promise; + languageCode: string | null; + onAuthStateChanged( + nextOrObserver: + | firebase.Observer + | ((a: firebase.User | null) => any), + error?: (a: firebase.auth.Error) => any, + completed?: firebase.Unsubscribe + ): firebase.Unsubscribe; + onIdTokenChanged( + nextOrObserver: + | firebase.Observer + | ((a: firebase.User | null) => any), + error?: (a: firebase.auth.Error) => any, + completed?: firebase.Unsubscribe + ): firebase.Unsubscribe; + sendPasswordResetEmail( + email: string, + actionCodeSettings?: firebase.auth.ActionCodeSettings | null + ): Promise; + setPersistence(persistence: firebase.auth.Auth.Persistence): Promise; + signInAndRetrieveDataWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + signInAnonymously(): Promise; + signInWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + signInWithCustomToken(token: string): Promise; + signInWithEmailAndPassword(email: string, password: string): Promise; + signInWithPhoneNumber( + phoneNumber: string, + applicationVerifier: firebase.auth.ApplicationVerifier + ): Promise; + signInWithPopup(provider: firebase.auth.AuthProvider): Promise; + signInWithRedirect(provider: firebase.auth.AuthProvider): Promise; + signOut(): Promise; + useDeviceLanguage(): any; + verifyPasswordResetCode(code: string): Promise; + } + + interface AuthCredential { + providerId: string; + } + + interface AuthProvider { + providerId: string; + } + + interface ConfirmationResult { + confirm(verificationCode: string): Promise; + verificationId: string; + } + + class EmailAuthProvider extends EmailAuthProvider_Instance { + static PROVIDER_ID: string; + static credential( + email: string, + password: string + ): firebase.auth.AuthCredential; + } + class EmailAuthProvider_Instance implements firebase.auth.AuthProvider { + providerId: string; + } + + interface Error { + code: string; + message: string; + } + + class FacebookAuthProvider extends FacebookAuthProvider_Instance { + static PROVIDER_ID: string; + static credential(token: string): firebase.auth.AuthCredential; + } + class FacebookAuthProvider_Instance implements firebase.auth.AuthProvider { + addScope(scope: string): firebase.auth.AuthProvider; + providerId: string; + setCustomParameters( + customOAuthParameters: Object + ): firebase.auth.AuthProvider; + } + + class GithubAuthProvider extends GithubAuthProvider_Instance { + static PROVIDER_ID: string; + static credential(token: string): firebase.auth.AuthCredential; + } + class GithubAuthProvider_Instance implements firebase.auth.AuthProvider { + addScope(scope: string): firebase.auth.AuthProvider; + providerId: string; + setCustomParameters( + customOAuthParameters: Object + ): firebase.auth.AuthProvider; + } + + class GoogleAuthProvider extends GoogleAuthProvider_Instance { + static PROVIDER_ID: string; + static credential( + idToken?: string | null, + accessToken?: string | null + ): firebase.auth.AuthCredential; + } + class GoogleAuthProvider_Instance implements firebase.auth.AuthProvider { + addScope(scope: string): firebase.auth.AuthProvider; + providerId: string; + setCustomParameters( + customOAuthParameters: Object + ): firebase.auth.AuthProvider; + } + + class PhoneAuthProvider extends PhoneAuthProvider_Instance { + static PROVIDER_ID: string; + static credential( + verificationId: string, + verificationCode: string + ): firebase.auth.AuthCredential; + } + class PhoneAuthProvider_Instance implements firebase.auth.AuthProvider { + constructor(auth?: firebase.auth.Auth | null); + providerId: string; + verifyPhoneNumber( + phoneNumber: string, + applicationVerifier: firebase.auth.ApplicationVerifier + ): Promise; + } + + class RecaptchaVerifier extends RecaptchaVerifier_Instance { } + class RecaptchaVerifier_Instance + implements firebase.auth.ApplicationVerifier { + constructor( + container: any | string, + parameters?: Object | null, + app?: firebase.app.App | null + ); + clear(): any; + render(): Promise; + type: string; + verify(): Promise; + } + + class TwitterAuthProvider extends TwitterAuthProvider_Instance { + static PROVIDER_ID: string; + static credential( + token: string, + secret: string + ): firebase.auth.AuthCredential; + } + class TwitterAuthProvider_Instance implements firebase.auth.AuthProvider { + providerId: string; + setCustomParameters( + customOAuthParameters: Object + ): firebase.auth.AuthProvider; + } + + type UserCredential = { + additionalUserInfo?: firebase.auth.AdditionalUserInfo | null; + credential: firebase.auth.AuthCredential | null; + operationType?: string | null; + user: firebase.User | null; + }; + + interface UserMetadata { + creationTime?: string; + lastSignInTime?: string; + } +} + +declare namespace firebase.auth.Auth { + type Persistence = string; + var Persistence: { + LOCAL: Persistence; + NONE: Persistence; + SESSION: Persistence; + }; +} + +declare namespace firebase.database { + interface DataSnapshot { + child(path: string): firebase.database.DataSnapshot; + exists(): boolean; + exportVal(): any; + forEach(action: (a: firebase.database.DataSnapshot) => boolean): boolean; + getPriority(): string | number | null; + hasChild(path: string): boolean; + hasChildren(): boolean; + key: string | null; + numChildren(): number; + val(): any; + ref: firebase.database.Reference; + toJSON(): Object | null; + } + + interface Database { + app: firebase.app.App; + goOffline(): any; + goOnline(): any; + ref(path?: string): firebase.database.Reference; + refFromURL(url: string): firebase.database.Reference; + } + + interface OnDisconnect { + cancel(onComplete?: (a: Error | null) => any): Promise; + remove(onComplete?: (a: Error | null) => any): Promise; + set(value: any, onComplete?: (a: Error | null) => any): Promise; + setWithPriority( + value: any, + priority: number | string | null, + onComplete?: (a: Error | null) => any + ): Promise; + update(values: Object, onComplete?: (a: Error | null) => any): Promise; + } + + interface Query { + endAt( + value: number | string | boolean | null, + key?: string + ): firebase.database.Query; + equalTo( + value: number | string | boolean | null, + key?: string + ): firebase.database.Query; + isEqual(other: firebase.database.Query | null): boolean; + limitToFirst(limit: number): firebase.database.Query; + limitToLast(limit: number): firebase.database.Query; + off( + eventType?: string, + callback?: (a: firebase.database.DataSnapshot, b?: string | null) => any, + context?: Object | null + ): any; + on( + eventType: string, + callback: (a: firebase.database.DataSnapshot | null, b?: string) => any, + cancelCallbackOrContext?: Object | null, + context?: Object | null + ): (a: firebase.database.DataSnapshot | null, b?: string) => any; + once( + eventType: string, + successCallback?: (a: firebase.database.DataSnapshot, b?: string) => any, + failureCallbackOrContext?: Object | null, + context?: Object | null + ): Promise; + orderByChild(path: string): firebase.database.Query; + orderByKey(): firebase.database.Query; + orderByPriority(): firebase.database.Query; + orderByValue(): firebase.database.Query; + ref: firebase.database.Reference; + startAt( + value: number | string | boolean | null, + key?: string + ): firebase.database.Query; + toJSON(): Object; + toString(): string; + } + + interface Reference extends firebase.database.Query { + child(path: string): firebase.database.Reference; + key: string | null; + onDisconnect(): firebase.database.OnDisconnect; + parent: firebase.database.Reference | null; + path: string; + push( + value?: any, + onComplete?: (a: Error | null) => any + ): firebase.database.ThenableReference; + remove(onComplete?: (a: Error | null) => any): Promise; + root: firebase.database.Reference; + set(value: any, onComplete?: (a: Error | null) => any): Promise; + setPriority( + priority: string | number | null, + onComplete: (a: Error | null) => any + ): Promise; + setWithPriority( + newVal: any, + newPriority: string | number | null, + onComplete?: (a: Error | null) => any + ): Promise; + transaction( + transactionUpdate: (a: any) => any, + onComplete?: ( + a: Error | null, + b: boolean, + c: firebase.database.DataSnapshot | null + ) => any, + applyLocally?: boolean + ): Promise; + update(values: Object, onComplete?: (a: Error | null) => any): Promise; + } + + interface ThenableReference + extends firebase.database.Reference, + PromiseLike { } + + function enableLogging( + logger?: boolean | ((a: string) => any), + persistent?: boolean + ): any; +} + +declare namespace firebase.database.ServerValue { + var TIMESTAMP: Object; +} + +declare namespace firebase.messaging { + interface Messaging { + deleteToken(token: string): Promise | null; + getToken(): Promise | null; + onMessage( + nextOrObserver: firebase.Observer | ((a: Object) => any) + ): firebase.Unsubscribe; + onTokenRefresh( + nextOrObserver: firebase.Observer | ((a: Object) => any) + ): firebase.Unsubscribe; + requestPermission(): Promise | null; + setBackgroundMessageHandler(callback: (a: Object) => any): any; + useServiceWorker(registration: any): any; + } +} + +declare namespace firebase.storage { + interface FullMetadata extends firebase.storage.UploadMetadata { + bucket: string; + downloadURLs: string[]; + fullPath: string; + generation: string; + metageneration: string; + name: string; + size: number; + timeCreated: string; + updated: string; + } + + interface Reference { + bucket: string; + child(path: string): firebase.storage.Reference; + delete(): Promise; + fullPath: string; + getDownloadURL(): Promise; + getMetadata(): Promise; + name: string; + parent: firebase.storage.Reference | null; + put( + data: any | any | any, + metadata?: firebase.storage.UploadMetadata + ): firebase.storage.UploadTask; + putString( + data: string, + format?: firebase.storage.StringFormat, + metadata?: firebase.storage.UploadMetadata + ): firebase.storage.UploadTask; + root: firebase.storage.Reference; + storage: firebase.storage.Storage; + toString(): string; + updateMetadata(metadata: firebase.storage.SettableMetadata): Promise; + } + + interface SettableMetadata { + cacheControl?: string | null; + contentDisposition?: string | null; + contentEncoding?: string | null; + contentLanguage?: string | null; + contentType?: string | null; + customMetadata?: { + [/* warning: coerced from ? */ key: string]: string; + } | null; + } + + interface Storage { + app: firebase.app.App; + maxOperationRetryTime: number; + maxUploadRetryTime: number; + ref(path?: string): firebase.storage.Reference; + refFromURL(url: string): firebase.storage.Reference; + setMaxOperationRetryTime(time: number): any; + setMaxUploadRetryTime(time: number): any; + } + + type StringFormat = string; + var StringFormat: { + BASE64: StringFormat; + BASE64URL: StringFormat; + DATA_URL: StringFormat; + RAW: StringFormat; + }; + + type TaskEvent = string; + var TaskEvent: { + STATE_CHANGED: TaskEvent; + }; + + type TaskState = string; + var TaskState: { + CANCELED: TaskState; + ERROR: TaskState; + PAUSED: TaskState; + RUNNING: TaskState; + SUCCESS: TaskState; + }; + + interface UploadMetadata extends firebase.storage.SettableMetadata { + md5Hash?: string | null; + } + + interface UploadTask { + cancel(): boolean; + catch(onRejected: (a: Error) => any): Promise; + on( + event: firebase.storage.TaskEvent, + nextOrObserver?: + | firebase.Observer + | null + | ((a: Object) => any), + error?: ((a: Error) => any) | null, + complete?: (firebase.Unsubscribe) | null + ): Function; + pause(): boolean; + resume(): boolean; + snapshot: firebase.storage.UploadTaskSnapshot; + then( + onFulfilled?: ((a: firebase.storage.UploadTaskSnapshot) => any) | null, + onRejected?: ((a: Error) => any) | null + ): Promise; + } + + interface UploadTaskSnapshot { + bytesTransferred: number; + downloadURL: string | null; + metadata: firebase.storage.FullMetadata; + ref: firebase.storage.Reference; + state: firebase.storage.TaskState; + task: firebase.storage.UploadTask; + totalBytes: number; + } +} + +declare namespace firebase.firestore { + /** + * Document data (for use with `DocumentReference.set()`) consists of fields + * mapped to values. + */ + export type DocumentData = { [field: string]: any }; + + /** + * Update data (for use with `DocumentReference.update()`) consists of field + * paths (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots + * reference nested fields within the document. + */ + export type UpdateData = { [fieldPath: string]: any }; + + /** Settings used to configure a `Firestore` instance. */ + export interface Settings { + /** The hostname to connect to. */ + host?: string; + /** Whether to use SSL when connecting. */ + ssl?: boolean; + } + + export type LogLevel = 'debug' | 'error' | 'silent'; + + function setLogLevel(logLevel: LogLevel): void; + + /** + * `Firestore` represents a Firestore Database and is the entry point for all + * Firestore operations. + */ + export class Firestore { + private constructor(); + + /** + * Specifies custom settings to be used to configure the `Firestore` + * instance. Must be set before invoking any other methods. + * + * @param settings The settings to use. + */ + settings(settings: Settings): void; + + /** + * Attempts to enable persistent storage, if possible. + * + * Must be called before any other methods (other than settings()). + * + * If this fails, enablePersistence() will reject the promise it returns. + * Note that even after this failure, the firestore instance will remain + * usable, however offline persistence will be disabled. + * + * There are several reasons why this can fail, which can be identified by + * the `code` on the error. + * + * * failed-precondition: The app is already open in another browser tab. + * * unimplemented: The browser is incompatible with the offline + * persistence implementation. + * + * @return A promise that represents successfully enabling persistent + * storage. + */ + enablePersistence(): Promise; + + /** + * Gets a `CollectionReference` instance that refers to the collection at + * the specified path. + * + * @param collectionPath A slash-separated path to a collection. + * @return The `CollectionReference` instance. + */ + collection(collectionPath: string): CollectionReference; + + /** + * Gets a `DocumentReference` instance that refers to the document at the + * specified path. + * + * @param documentPath A slash-separated path to a document. + * @return The `DocumentReference` instance. + */ + doc(documentPath: string): DocumentReference; + + /** + * Executes the given updateFunction and then attempts to commit the + * changes applied within the transaction. If any document read within the + * transaction has changed, the updateFunction will be retried. If it fails + * to commit after 5 attempts, the transaction will fail. + * + * @param updateFunction The function to execute within the transaction + * context. + * @return If the transaction completed successfully or was explicitly + * aborted (by the updateFunction returning a failed Promise), the Promise + * returned by the updateFunction will be returned here. Else if the + * transaction failed, a rejected Promise with the corresponding failure + * error will be returned. + */ + runTransaction( + updateFunction: (transaction: Transaction) => Promise + ): Promise; + + /** + * Creates a write batch, used for performing multiple writes as a single + * atomic operation. + */ + batch(): WriteBatch; + + /** + * The `firebase.app.App` associated with this `Firestore` instance. + */ + app: firebase.app.App; + + INTERNAL: { delete: () => Promise }; + } + + /** + * An immutable object representing a geo point in Firestore. The geo point + * is represented as latitude/longitude pair. + * + * Latitude values are in the range of [-90, 90]. + * Longitude values are in the range of [-180, 180]. + */ + export class GeoPoint { + /** + * Creates a new immutable GeoPoint object with the provided latitude and + * longitude values. + * @param latitude The latitude as number between -90 and 90. + * @param longitude The longitude as number between -180 and 180. + */ + constructor(latitude: number, longitude: number); + + readonly latitude: number; + readonly longitude: number; + } + + /** + * An immutable object representing an array of bytes. + */ + export class Blob { + private constructor(); + + /** + * Creates a new Blob from the given Base64 string, converting it to + * bytes. + */ + static fromBase64String(base64: string): Blob; + + /** + * Creates a new Blob from the given Uint8Array. + */ + static fromUint8Array(array: Uint8Array): Blob; + + /** + * Returns the bytes of this Blob as a Base64-encoded string. + */ + public toBase64(): string; + + /** + * Returns the bytes of this Blob in a new Uint8Array. + */ + public toUint8Array(): Uint8Array; + } + + /** + * A reference to a transaction. + * The `Transaction` object passed to a transaction's updateFunction provides + * the methods to read and write data within the transaction context. See + * `Firestore.runTransaction()`. + */ + export class Transaction { + private constructor(); + + /** + * Reads the document referenced by the provided `DocumentReference.` + * + * @param documentRef A reference to the document to be read. + * @return A DocumentSnapshot for the read data. + */ + get(documentRef: DocumentReference): Promise; + + /** + * Writes to the document referred to by the provided `DocumentReference`. + * If the document does not exist yet, it will be created. If you pass + * `SetOptions`, the provided data can be merged into the existing document. + * + * @param documentRef A reference to the document to be set. + * @param data An object of the fields and values for the document. + * @param options An object to configure the set behavior. + * @return This `Transaction` instance. Used for chaining method calls. + */ + set( + documentRef: DocumentReference, + data: DocumentData, + options?: SetOptions + ): Transaction; + + /** + * Updates fields in the document referred to by the provided + * `DocumentReference`. The update will fail if applied to a document that + * does not exist. + * + * @param documentRef A reference to the document to be updated. + * @param data An object containing the fields and values with which to + * update the document. Fields can contain dots to reference nested fields + * within the document. + * @return This `Transaction` instance. Used for chaining method calls. + */ + update(documentRef: DocumentReference, data: UpdateData): Transaction; + + /** + * Updates fields in the document referred to by the provided + * `DocumentReference`. The update will fail if applied to a document that + * does not exist. + * + * Nested fields can be updated by providing dot-separated field path + * strings or by providing FieldPath objects. + * + * @param documentRef A reference to the document to be updated. + * @param field The first field to update. + * @param value The first value. + * @param moreFieldsAndValues Additional key/value pairs. + * @return A Promise resolved once the data has been successfully written + * to the backend (Note that it won't resolve while you're offline). + */ + update( + documentRef: DocumentReference, + field: string | FieldPath, + value: any, + ...moreFieldsAndValues: any[] + ): Transaction; + + /** + * Deletes the document referred to by the provided `DocumentReference`. + * + * @param documentRef A reference to the document to be deleted. + * @return This `Transaction` instance. Used for chaining method calls. + */ + delete(documentRef: DocumentReference): Transaction; + } + + /** + * A write batch, used to perform multiple writes as a single atomic unit. + * + * A `WriteBatch` object can be acquired by calling `Firestore.batch()`. It + * provides methods for adding writes to the write batch. None of the + * writes will be committed (or visible locally) until `WriteBatch.commit()` + * is called. + * + * Unlike transactions, write batches are persisted offline and therefore are + * preferable when you don't need to condition your writes on read data. + */ + export class WriteBatch { + private constructor(); + + /** + * Writes to the document referred to by the provided `DocumentReference`. + * If the document does not exist yet, it will be created. If you pass + * `SetOptions`, the provided data can be merged into the existing document. + * + * @param documentRef A reference to the document to be set. + * @param data An object of the fields and values for the document. + * @param options An object to configure the set behavior. + * @return This `WriteBatch` instance. Used for chaining method calls. + */ + set( + documentRef: DocumentReference, + data: DocumentData, + options?: SetOptions + ): WriteBatch; + + /** + * Updates fields in the document referred to by the provided + * `DocumentReference`. The update will fail if applied to a document that + * does not exist. + * + * @param documentRef A reference to the document to be updated. + * @param data An object containing the fields and values with which to + * update the document. Fields can contain dots to reference nested fields + * within the document. + * @return This `WriteBatch` instance. Used for chaining method calls. + */ + update(documentRef: DocumentReference, data: UpdateData): WriteBatch; + + /** + * Updates fields in the document referred to by this `DocumentReference`. + * The update will fail if applied to a document that does not exist. + * + * Nested fields can be update by providing dot-separated field path strings + * or by providing FieldPath objects. + * + * @param documentRef A reference to the document to be updated. + * @param field The first field to update. + * @param value The first value. + * @param moreFieldsAndValues Additional key value pairs. + * @return A Promise resolved once the data has been successfully written + * to the backend (Note that it won't resolve while you're offline). + */ + update( + documentRef: DocumentReference, + field: string | FieldPath, + value: any, + ...moreFieldsAndValues: any[] + ): WriteBatch; + + /** + * Deletes the document referred to by the provided `DocumentReference`. + * + * @param documentRef A reference to the document to be deleted. + * @return This `WriteBatch` instance. Used for chaining method calls. + */ + delete(documentRef: DocumentReference): WriteBatch; + + /** + * Commits all of the writes in this write batch as a single atomic unit. + * + * @return A Promise resolved once all of the writes in the batch have been + * successfully written to the backend as an atomic unit. Note that it won't + * resolve while you're offline. + */ + commit(): Promise; + } + + /** + * Options for use with `DocumentReference.onSnapshot()` to control the + * behavior of the snapshot listener. + */ + export interface DocumentListenOptions { + /** + * Raise an event even if only metadata of the document changed. Default is + * false. + */ + readonly includeMetadataChanges?: boolean; + } + + /** + * An options object that configures the behavior of `set()` calls in + * `DocumentReference`, `WriteBatch` and `Transaction`. These calls can be + * configured to perform granular merges instead of overwriting the target + * documents in their entirety by providing a `SetOptions` with `merge: true`. + */ + export interface SetOptions { + /** + * Changes the behavior of a set() call to only replace the values specified + * in its data argument. Fields omitted from the set() call remain + * untouched. + */ + readonly merge?: boolean; + } + + /** + * A `DocumentReference` refers to a document location in a Firestore database + * and can be used to write, read, or listen to the location. The document at + * the referenced location may or may not exist. A `DocumentReference` can + * also be used to create a `CollectionReference` to a subcollection. + */ + export class DocumentReference { + private constructor(); + + /** The identifier of the document within its collection. */ + readonly id: string; + + /** + * The `Firestore` for the Firestore database (useful for performing + * transactions, etc.). + */ + readonly firestore: Firestore; + + /** + * A reference to the Collection to which this DocumentReference belongs. + */ + readonly parent: CollectionReference; + + /** + * A string representing the path of the referenced document (relative + * to the root of the database). + */ + readonly path: string; + + /** + * Gets a `CollectionReference` instance that refers to the collection at + * the specified path. + * + * @param collectionPath A slash-separated path to a collection. + * @return The `CollectionReference` instance. + */ + collection(collectionPath: string): CollectionReference; + + /** + * Returns true if this `DocumentReference` is equal to the provided one. + * + * @param other The `DocumentReference` to compare against. + * @return true if this `DocumentReference` is equal to the provided one. + */ + isEqual(other: DocumentReference): boolean; + + /** + * Writes to the document referred to by this `DocumentReference`. If the + * document does not yet exist, it will be created. If you pass + * `SetOptions`, the provided data can be merged into an existing document. + * + * @param data A map of the fields and values for the document. + * @param options An object to configure the set behavior. + * @return A Promise resolved once the data has been successfully written + * to the backend (Note that it won't resolve while you're offline). + */ + set(data: DocumentData, options?: SetOptions): Promise; + + /** + * Updates fields in the document referred to by this `DocumentReference`. + * The update will fail if applied to a document that does not exist. + * + * @param data An object containing the fields and values with which to + * update the document. Fields can contain dots to reference nested fields + * within the document. + * @return A Promise resolved once the data has been successfully written + * to the backend (Note that it won't resolve while you're offline). + */ + update(data: UpdateData): Promise; + + /** + * Updates fields in the document referred to by this `DocumentReference`. + * The update will fail if applied to a document that does not exist. + * + * Nested fields can be updated by providing dot-separated field path + * strings or by providing FieldPath objects. + * + * @param field The first field to update. + * @param value The first value. + * @param moreFieldsAndValues Additional key value pairs. + * @return A Promise resolved once the data has been successfully written + * to the backend (Note that it won't resolve while you're offline). + */ + update( + field: string | FieldPath, + value: any, + ...moreFieldsAndValues: any[] + ): Promise; + + /** + * Deletes the document referred to by this `DocumentReference`. + * + * @return A Promise resolved once the document has been successfully + * deleted from the backend (Note that it won't resolve while you're + * offline). + */ + delete(): Promise; + + /** + * Reads the document referred to by this `DocumentReference`. + * + * Note: get() attempts to provide up-to-date data when possible by waiting + * for data from the server, but it may return cached data or fail if you + * are offline and the server cannot be reached. + * + * @return A Promise resolved with a DocumentSnapshot containing the + * current document contents. + */ + get(): Promise; + + /** + * Attaches a listener for DocumentSnapshot events. You may either pass + * individual `onNext` and `onError` callbacks or pass a single observer + * object with `next` and `error` callbacks. + * + * NOTE: Although an `onCompletion` callback can be provided, it will + * never be called because the snapshot stream is never-ending. + * + * @param options Options controlling the listen behavior. + * @param onNext A callback to be called every time a new `DocumentSnapshot` + * is available. + * @param onError A callback to be called if the listen fails or is + * cancelled. No further callbacks will occur. + * @param observer A single object containing `next` and `error` callbacks. + * @return An unsubscribe function that can be called to cancel + * the snapshot listener. + */ + onSnapshot(observer: { + next?: (snapshot: DocumentSnapshot) => void; + error?: (error: FirestoreError) => void; + complete?: () => void; + }): () => void; + onSnapshot( + options: DocumentListenOptions, + observer: { + next?: (snapshot: DocumentSnapshot) => void; + error?: (error: Error) => void; + complete?: () => void; + } + ): () => void; + onSnapshot( + onNext: (snapshot: DocumentSnapshot) => void, + onError?: (error: Error) => void, + onCompletion?: () => void + ): () => void; + onSnapshot( + options: DocumentListenOptions, + onNext: (snapshot: DocumentSnapshot) => void, + onError?: (error: Error) => void, + onCompletion?: () => void + ): () => void; + } + + /** Metadata about a snapshot, describing the state of the snapshot. */ + export interface SnapshotMetadata { + /** + * True if the snapshot contains the result of local writes (e.g. set() or + * update() calls) that have not yet been committed to the backend. + * If your listener has opted into metadata updates (via + * `DocumentListenOptions` or `QueryListenOptions`) you will receive another + * snapshot with `hasPendingWrites` equal to false once the writes have been + * committed to the backend. + */ + readonly hasPendingWrites: boolean; + + /** + * True if the snapshot was created from cached data rather than + * guaranteed up-to-date server data. If your listener has opted into + * metadata updates (via `DocumentListenOptions` or `QueryListenOptions`) + * you will receive another snapshot with `fromCache` equal to false once + * the client has received up-to-date data from the backend. + */ + readonly fromCache: boolean; + } + + /** + * A `DocumentSnapshot` contains data read from a document in your Firestore + * database. The data can be extracted with `.data()` or `.get()` to + * get a specific field. + */ + export class DocumentSnapshot { + private constructor(); + + /** True if the document exists. */ + readonly exists: boolean; + /** A `DocumentReference` to the document location. */ + readonly ref: DocumentReference; + /** + * The ID of the document for which this `DocumentSnapshot` contains data. + */ + readonly id: string; + /** + * Metadata about this snapshot, concerning its source and if it has local + * modifications. + */ + readonly metadata: SnapshotMetadata; + + /** + * Retrieves all fields in the document as an Object. + * + * @return An Object containing all fields in the document. + */ + data(): DocumentData; + + /** + * Retrieves the field specified by `fieldPath`. + * + * @param fieldPath The path (e.g. 'foo' or 'foo.bar') to a specific field. + * @return The data at the specified field location or undefined if no such + * field exists in the document. + */ + get(fieldPath: string | FieldPath): any; + } + + /** + * The direction of a `Query.orderBy()` clause is specified as 'desc' or 'asc' + * (descending or ascending). + */ + export type OrderByDirection = 'desc' | 'asc'; + + /** + * Filter conditions in a `Query.where()` clause are specified using the + * strings '<', '<=', '==', '>=', and '>'. + */ + export type WhereFilterOp = '<' | '<=' | '==' | '>=' | '>'; + + /** + * Options for use with `Query.onSnapshot() to control the behavior of the + * snapshot listener. + */ + export interface QueryListenOptions { + /** + * Raise an event even if only metadata changes (i.e. one of the + * `QuerySnapshot.metadata` properties). Default is false. + */ + readonly includeQueryMetadataChanges?: boolean; + + /** + * Raise an event even if only metadata of a document in the query results + * changes (i.e. one of the `DocumentSnapshot.metadata` properties on one of + * the documents). Default is false. + */ + readonly includeDocumentMetadataChanges?: boolean; + } + + /** + * A `Query` refers to a Query which you can read or listen to. You can also + * construct refined `Query` objects by adding filters and ordering. + */ + export class Query { + protected constructor(); + + /** + * The `Firestore` for the Firestore database (useful for performing + * transactions, etc.). + */ + readonly firestore: Firestore; + + /** + * Creates and returns a new Query with the additional filter that documents + * must contain the specified field and the value should satisfy the + * relation constraint provided. + * + * @param fieldPath The path to compare + * @param opStr The operation string (e.g "<", "<=", "==", ">", ">="). + * @param value The value for comparison + * @return The created Query. + */ + where( + fieldPath: string | FieldPath, + opStr: WhereFilterOp, + value: any + ): Query; + + /** + * Creates and returns a new Query that's additionally sorted by the + * specified field, optionally in descending order instead of ascending. + * + * @param fieldPath The field to sort by. + * @param directionStr Optional direction to sort by ('asc' or 'desc'). If + * not specified, order will be ascending. + * @return The created Query. + */ + orderBy( + fieldPath: string | FieldPath, + directionStr?: OrderByDirection + ): Query; + + /** + * Creates and returns a new Query that's additionally limited to only + * return up to the specified number of documents. + * + * @param limit The maximum number of items to return. + * @return The created Query. + */ + limit(limit: number): Query; + + /** + * Creates and returns a new Query that starts at the provided document + * (inclusive). The starting position is relative to the order of the query. + * The document must contain all of the fields provided in the orderBy of + * this query. + * + * @param snapshot The snapshot of the document to start at. + * @return The created Query. + */ + startAt(snapshot: DocumentSnapshot): Query; + + /** + * Creates and returns a new Query that starts at the provided fields + * relative to the order of the query. The order of the field values + * must match the order of the order by clauses of the query. + * + * @param fieldValues The field values to start this query at, in order + * of the query's order by. + * @return The created Query. + */ + startAt(...fieldValues: any[]): Query; + + /** + * Creates and returns a new Query that starts after the provided document + * (exclusive). The starting position is relative to the order of the query. + * The document must contain all of the fields provided in the orderBy of + * this query. + * + * @param snapshot The snapshot of the document to start after. + * @return The created Query. + */ + startAfter(snapshot: DocumentSnapshot): Query; + + /** + * Creates and returns a new Query that starts after the provided fields + * relative to the order of the query. The order of the field values + * must match the order of the order by clauses of the query. + * + * @param fieldValues The field values to start this query after, in order + * of the query's order by. + * @return The created Query. + */ + startAfter(...fieldValues: any[]): Query; + + /** + * Creates and returns a new Query that ends before the provided document + * (exclusive). The end position is relative to the order of the query. The + * document must contain all of the fields provided in the orderBy of this + * query. + * + * @param snapshot The snapshot of the document to end before. + * @return The created Query. + */ + endBefore(snapshot: DocumentSnapshot): Query; + + /** + * Creates and returns a new Query that ends before the provided fields + * relative to the order of the query. The order of the field values + * must match the order of the order by clauses of the query. + * + * @param fieldValues The field values to end this query before, in order + * of the query's order by. + * @return The created Query. + */ + endBefore(...fieldValues: any[]): Query; + + /** + * Creates and returns a new Query that ends at the provided document + * (inclusive). The end position is relative to the order of the query. The + * document must contain all of the fields provided in the orderBy of this + * query. + * + * @param snapshot The snapshot of the document to end at. + * @return The created Query. + */ + endAt(snapshot: DocumentSnapshot): Query; + + /** + * Creates and returns a new Query that ends at the provided fields + * relative to the order of the query. The order of the field values + * must match the order of the order by clauses of the query. + * + * @param fieldValues The field values to end this query at, in order + * of the query's order by. + * @return The created Query. + */ + endAt(...fieldValues: any[]): Query; + + /** + * Returns true if this `Query` is equal to the provided one. + * + * @param other The `Query` to compare against. + * @return true if this `Query` is equal to the provided one. + */ + isEqual(other: Query): boolean; + + /** + * Executes the query and returns the results as a QuerySnapshot. + * + * @return A Promise that will be resolved with the results of the Query. + */ + get(): Promise; + + /** + * Attaches a listener for QuerySnapshot events. You may either pass + * individual `onNext` and `onError` callbacks or pass a single observer + * object with `next` and `error` callbacks. + * + * NOTE: Although an `onCompletion` callback can be provided, it will + * never be called because the snapshot stream is never-ending. + * + * @param options Options controlling the listen behavior. + * @param onNext A callback to be called every time a new `QuerySnapshot` + * is available. + * @param onError A callback to be called if the listen fails or is + * cancelled. No further callbacks will occur. + * @param observer A single object containing `next` and `error` callbacks. + * @return An unsubscribe function that can be called to cancel + * the snapshot listener. + */ + onSnapshot(observer: { + next?: (snapshot: QuerySnapshot) => void; + error?: (error: Error) => void; + complete?: () => void; + }): () => void; + onSnapshot( + options: QueryListenOptions, + observer: { + next?: (snapshot: QuerySnapshot) => void; + error?: (error: Error) => void; + complete?: () => void; + } + ): () => void; + onSnapshot( + onNext: (snapshot: QuerySnapshot) => void, + onError?: (error: Error) => void, + onCompletion?: () => void + ): () => void; + onSnapshot( + options: QueryListenOptions, + onNext: (snapshot: QuerySnapshot) => void, + onError?: (error: Error) => void, + onCompletion?: () => void + ): () => void; + } + + /** + * A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects + * representing the results of a query. The documents can be accessed as an + * array via the `docs` property or enumerated using the `forEach` method. The + * number of documents can be determined via the `empty` and `size` + * properties. + */ + export class QuerySnapshot { + private constructor(); + + /** + * The query on which you called `get` or `onSnapshot` in order to get this + * `QuerySnapshot`. + */ + readonly query: Query; + /** + * Metadata about this snapshot, concerning its source and if it has local + * modifications. + */ + readonly metadata: SnapshotMetadata; + /** + * An array of the documents that changed since the last snapshot. If this + * is the first snapshot, all documents will be in the list as added + * changes. + */ + readonly docChanges: DocumentChange[]; + + /** An array of all the documents in the QuerySnapshot. */ + readonly docs: DocumentSnapshot[]; + + /** The number of documents in the QuerySnapshot. */ + readonly size: number; + + /** True if there are no documents in the QuerySnapshot. */ + readonly empty: boolean; + + /** + * Enumerates all of the documents in the QuerySnapshot. + * + * @param callback A callback to be called with a `DocumentSnapshot` for + * each document in the snapshot. + * @param thisArg The `this` binding for the callback. + */ + forEach(callback: (result: DocumentSnapshot) => void, thisArg?: any): void; + } + + /** + * The type of of a `DocumentChange` may be 'added', 'removed', or 'modified'. + */ + export type DocumentChangeType = 'added' | 'removed' | 'modified'; + + /** + * A `DocumentChange` represents a change to the documents matching a query. + * It contains the document affected and the type of change that occurred. + */ + export interface DocumentChange { + /** The type of change ('added', 'modified', or 'removed'). */ + readonly type: DocumentChangeType; + + /** The document affected by this change. */ + readonly doc: DocumentSnapshot; + + /** + * The index of the changed document in the result set immediately prior to + * this DocumentChange (i.e. supposing that all prior DocumentChange objects + * have been applied). Is -1 for 'added' events. + */ + readonly oldIndex: number; + + /** + * The index of the changed document in the result set immediately after + * this DocumentChange (i.e. supposing that all prior DocumentChange + * objects and the current DocumentChange object have been applied). + * Is -1 for 'removed' events. + */ + readonly newIndex: number; + } + + /** + * A `CollectionReference` object can be used for adding documents, getting + * document references, and querying for documents (using the methods + * inherited from `Query`). + */ + export class CollectionReference extends Query { + private constructor(); + + /** The identifier of the collection. */ + readonly id: string; + + /** + * A reference to the containing Document if this is a subcollection, else + * null. + */ + readonly parent: DocumentReference | null; + + /** + * A string representing the path of the referenced collection (relative + * to the root of the database). + */ + readonly path: string; + + /** + * Get a `DocumentReference` for the document within the collection at the + * specified path. If no path is specified, an automatically-generated + * unique ID will be used for the returned DocumentReference. + * + * @param documentPath A slash-separated path to a document. + * @return The `DocumentReference` instance. + */ + doc(documentPath?: string): DocumentReference; + + /** + * Add a new document to this collection with the specified data, assigning + * it a document ID automatically. + * + * @param data An Object containing the data for the new document. + * @return A Promise resolved with a `DocumentReference` pointing to the + * newly created document after it has been written to the backend. + */ + add(data: DocumentData): Promise; + } + + /** + * Sentinel values that can be used when writing document fields with set() + * or update(). + */ + export class FieldValue { + private constructor(); + + /** + * Returns a sentinel used with set() or update() to include a + * server-generated timestamp in the written data. + */ + static serverTimestamp(): FieldValue; + + /** + * Returns a sentinel for use with update() to mark a field for deletion. + */ + static delete(): FieldValue; + } + + /** + * A FieldPath refers to a field in a document. The path may consist of a + * single field name (referring to a top-level field in the document), or a + * list of field names (referring to a nested field in the document). + */ + export class FieldPath { + /** + * Creates a FieldPath from the provided field names. If more than one field + * name is provided, the path will point to a nested field in a document. + * + * @param fieldNames A list of field names. + */ + constructor(...fieldNames: string[]); + + /** + * Returns a special sentinel FieldPath to refer to the ID of a document. + * It can be used in queries to sort or filter by the document ID. + */ + static documentId(): FieldPath; + } + + /** + * The set of Firestore status codes. The codes are the same at the ones + * exposed by gRPC here: + * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md + * + * Possible values: + * - 'cancelled': The operation was cancelled (typically by the caller). + * - 'unknown': Unknown error or an error from a different error domain. + * - 'invalid-argument': Client specified an invalid argument. Note that this + * differs from 'failed-precondition'. 'invalid-argument' indicates + * arguments that are problematic regardless of the state of the system + * (e.g. an invalid field name). + * - 'deadline-exceeded': Deadline expired before operation could complete. + * For operations that change the state of the system, this error may be + * returned even if the operation has completed successfully. For example, + * a successful response from a server could have been delayed long enough + * for the deadline to expire. + * - 'not-found': Some requested document was not found. + * - 'already-exists': Some document that we attempted to create already + * exists. + * - 'permission-denied': The caller does not have permission to execute the + * specified operation. + * - 'resource-exhausted': Some resource has been exhausted, perhaps a + * per-user quota, or perhaps the entire file system is out of space. + * - 'failed-precondition': Operation was rejected because the system is not + * in a state required for the operation's execution. + * - 'aborted': The operation was aborted, typically due to a concurrency + * issue like transaction aborts, etc. + * - 'out-of-range': Operation was attempted past the valid range. + * - 'unimplemented': Operation is not implemented or not supported/enabled. + * - 'internal': Internal errors. Means some invariants expected by + * underlying system has been broken. If you see one of these errors, + * something is very broken. + * - 'unavailable': The service is currently unavailable. This is most likely + * a transient condition and may be corrected by retrying with a backoff. + * - 'data-loss': Unrecoverable data loss or corruption. + * - 'unauthenticated': The request does not have valid authentication + * credentials for the operation. + */ + export type FirestoreErrorCode = + | 'cancelled' + | 'unknown' + | 'invalid-argument' + | 'deadline-exceeded' + | 'not-found' + | 'already-exists' + | 'permission-denied' + | 'resource-exhausted' + | 'failed-precondition' + | 'aborted' + | 'out-of-range' + | 'unimplemented' + | 'internal' + | 'unavailable' + | 'data-loss' + | 'unauthenticated'; + + /** An error returned by a Firestore operation. */ + // TODO(b/63008957): FirestoreError should extend firebase.FirebaseError + export interface FirestoreError { + code: FirestoreErrorCode; + message: string; + name: string; + stack?: string; + } +} -import firebase from '@firebase/app'; -import '@firebase/auth'; -import '@firebase/database'; -import '@firebase/messaging'; -import '@firebase/storage'; export = firebase; diff --git a/packages/firebase/index.node.d.ts b/packages/firebase/index.node.d.ts deleted file mode 100644 index 94f897d24ce..00000000000 --- a/packages/firebase/index.node.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright 2017 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import firebase from '@firebase/app'; -import '@firebase/auth'; -import '@firebase/database'; -export = firebase; diff --git a/packages/firebase/index.react-native.d.ts b/packages/firebase/index.react-native.d.ts deleted file mode 100644 index bc5a4e5ee55..00000000000 --- a/packages/firebase/index.react-native.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2017 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import firebase from '@firebase/app'; -import '@firebase/auth'; -import '@firebase/database'; -import '@firebase/storage'; -export = firebase; diff --git a/packages/firebase/messaging/index.d.ts b/packages/firebase/messaging/index.d.ts deleted file mode 100644 index 43d65f2dcce..00000000000 --- a/packages/firebase/messaging/index.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright 2017 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import '@firebase/messaging'; diff --git a/packages/firebase/storage/index.d.ts b/packages/firebase/storage/index.d.ts deleted file mode 100644 index 20c3ed67328..00000000000 --- a/packages/firebase/storage/index.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright 2017 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import '@firebase/storage'; From a4b804e8094c21c871a25b6090c596dbc97dbe1d Mon Sep 17 00:00:00 2001 From: Josh Crowther Date: Tue, 26 Dec 2017 14:56:52 -1000 Subject: [PATCH 2/9] Add helper to setup links to all packages --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index a6567809fc8..eaa8f683599 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "dev": "lerna run --parallel --scope @firebase/* --scope firebase dev", "prepare": "lerna run --scope @firebase/* --scope firebase prepare", "prepush": "node tools/gitHooks/prepush.js", + "link:packages": "lerna exec --scope @firebase/* --scope firebase -- yarn link", "stage:packages": "./scripts/prepublish.sh", "prepublish:packages": "./scripts/prepublish.sh --prod", "publish:packages": "./scripts/publish.sh", From 043f22b84c6797c17a6abce71a232f8d68c66768 Mon Sep 17 00:00:00 2001 From: Josh Crowther Date: Tue, 26 Dec 2017 15:01:02 -1000 Subject: [PATCH 3/9] [AUTOMATED]: Prettier Code Styling --- packages/firebase/app/index.d.ts | 6 +++--- packages/firebase/index.d.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/firebase/app/index.d.ts b/packages/firebase/app/index.d.ts index a870d29173b..ae88956c94c 100644 --- a/packages/firebase/app/index.d.ts +++ b/packages/firebase/app/index.d.ts @@ -124,7 +124,7 @@ declare namespace firebase.app { } declare namespace firebase.auth { - interface ActionCodeInfo { } + interface ActionCodeInfo {} type ActionCodeSettings = { android?: { @@ -285,7 +285,7 @@ declare namespace firebase.auth { ): Promise; } - class RecaptchaVerifier extends RecaptchaVerifier_Instance { } + class RecaptchaVerifier extends RecaptchaVerifier_Instance {} class RecaptchaVerifier_Instance implements firebase.auth.ApplicationVerifier { constructor( @@ -449,7 +449,7 @@ declare namespace firebase.database { interface ThenableReference extends firebase.database.Reference, - PromiseLike { } + PromiseLike {} function enableLogging( logger?: boolean | ((a: string) => any), diff --git a/packages/firebase/index.d.ts b/packages/firebase/index.d.ts index a870d29173b..ae88956c94c 100644 --- a/packages/firebase/index.d.ts +++ b/packages/firebase/index.d.ts @@ -124,7 +124,7 @@ declare namespace firebase.app { } declare namespace firebase.auth { - interface ActionCodeInfo { } + interface ActionCodeInfo {} type ActionCodeSettings = { android?: { @@ -285,7 +285,7 @@ declare namespace firebase.auth { ): Promise; } - class RecaptchaVerifier extends RecaptchaVerifier_Instance { } + class RecaptchaVerifier extends RecaptchaVerifier_Instance {} class RecaptchaVerifier_Instance implements firebase.auth.ApplicationVerifier { constructor( @@ -449,7 +449,7 @@ declare namespace firebase.database { interface ThenableReference extends firebase.database.Reference, - PromiseLike { } + PromiseLike {} function enableLogging( logger?: boolean | ((a: string) => any), From aa4b65c2cbe1886ccdf54dae9284d20f4cc994ba Mon Sep 17 00:00:00 2001 From: Josh Crowther Date: Tue, 26 Dec 2017 16:41:38 -1000 Subject: [PATCH 4/9] Add a simple test to validate that the typings are properly exported --- integration/firebase-typings/index.ts | 12 ++++++++++++ integration/firebase-typings/package.json | 14 ++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 integration/firebase-typings/index.ts create mode 100644 integration/firebase-typings/package.json diff --git a/integration/firebase-typings/index.ts b/integration/firebase-typings/index.ts new file mode 100644 index 00000000000..6d444c63d50 --- /dev/null +++ b/integration/firebase-typings/index.ts @@ -0,0 +1,12 @@ +import * as firebase from "firebase"; + +/** + * Verifying the namespace types are properly exposed from the `firebase` + * package + */ +let app: firebase.app.App; +let database: firebase.database.Database; +let firestore: firebase.firestore.Firestore; +let messaging: firebase.messaging.Messaging; +let storage: firebase.storage.Storage; + diff --git a/integration/firebase-typings/package.json b/integration/firebase-typings/package.json new file mode 100644 index 00000000000..4a61e632222 --- /dev/null +++ b/integration/firebase-typings/package.json @@ -0,0 +1,14 @@ +{ + "name": "firebase-package-typings-test", + "private": true, + "version": "0.1.0", + "scripts": { + "test": "tsc index.ts --outDir dist" + }, + "dependencies": { + "firebase": "4.8.1" + }, + "devDependencies": { + "typescript": "^2.4.2" + } +} \ No newline at end of file From ac991e92a502eaf0fadea2be88c8e07e109063f4 Mon Sep 17 00:00:00 2001 From: Josh Crowther Date: Tue, 26 Dec 2017 16:42:29 -1000 Subject: [PATCH 5/9] [AUTOMATED]: Prettier Code Styling --- integration/firebase-typings/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/integration/firebase-typings/index.ts b/integration/firebase-typings/index.ts index 6d444c63d50..0dd32bb3c9b 100644 --- a/integration/firebase-typings/index.ts +++ b/integration/firebase-typings/index.ts @@ -1,4 +1,4 @@ -import * as firebase from "firebase"; +import * as firebase from 'firebase'; /** * Verifying the namespace types are properly exposed from the `firebase` @@ -9,4 +9,3 @@ let database: firebase.database.Database; let firestore: firebase.firestore.Firestore; let messaging: firebase.messaging.Messaging; let storage: firebase.storage.Storage; - From a74e1fc8cd6ed6d5cd7fec106b09d9b0d4c432f3 Mon Sep 17 00:00:00 2001 From: Josh Crowther Date: Tue, 26 Dec 2017 16:42:29 -1000 Subject: [PATCH 6/9] [AUTOMATED]: License Headers --- integration/firebase-typings/index.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/integration/firebase-typings/index.ts b/integration/firebase-typings/index.ts index 0dd32bb3c9b..631cd339b33 100644 --- a/integration/firebase-typings/index.ts +++ b/integration/firebase-typings/index.ts @@ -1,3 +1,19 @@ +/** + * Copyright 2017 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import * as firebase from 'firebase'; /** From b9f9b3eee4b8287c2ceb47cfde4d5b7df29374e2 Mon Sep 17 00:00:00 2001 From: Josh Crowther Date: Wed, 27 Dec 2017 10:49:17 -0800 Subject: [PATCH 7/9] Fix database typings issue --- packages/database-types/test/default.test.ts | 2 ++ packages/database/index.node.ts | 1 + packages/database/index.ts | 1 + 3 files changed, 4 insertions(+) diff --git a/packages/database-types/test/default.test.ts b/packages/database-types/test/default.test.ts index 1a72e957536..948bfdb4e73 100644 --- a/packages/database-types/test/default.test.ts +++ b/packages/database-types/test/default.test.ts @@ -16,3 +16,5 @@ import { firebase } from '@firebase/app'; import '@firebase/database'; + +firebase.database.Database; diff --git a/packages/database/index.node.ts b/packages/database/index.node.ts index 9c8b9512596..8e4485ea388 100644 --- a/packages/database/index.node.ts +++ b/packages/database/index.node.ts @@ -91,6 +91,7 @@ declare module '@firebase/app-types' { (app?: FirebaseApp): types.FirebaseDatabase; enableLogging: typeof types.enableLogging; ServerValue: types.ServerValue; + Database: typeof types.FirebaseDatabase }; } interface FirebaseApp { diff --git a/packages/database/index.ts b/packages/database/index.ts index 9f39bf2a1f4..1d4b9019406 100644 --- a/packages/database/index.ts +++ b/packages/database/index.ts @@ -67,6 +67,7 @@ declare module '@firebase/app-types' { (app?: FirebaseApp): types.FirebaseDatabase; enableLogging: typeof types.enableLogging; ServerValue: types.ServerValue; + Database: typeof types.FirebaseDatabase }; } interface FirebaseApp { From de3ddd25e7916513c8ef0abea0b1e20004af2b4a Mon Sep 17 00:00:00 2001 From: Josh Crowther Date: Wed, 27 Dec 2017 10:49:45 -0800 Subject: [PATCH 8/9] [AUTOMATED]: Prettier Code Styling --- packages/database/index.node.ts | 2 +- packages/database/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/database/index.node.ts b/packages/database/index.node.ts index 8e4485ea388..06fed094c08 100644 --- a/packages/database/index.node.ts +++ b/packages/database/index.node.ts @@ -91,7 +91,7 @@ declare module '@firebase/app-types' { (app?: FirebaseApp): types.FirebaseDatabase; enableLogging: typeof types.enableLogging; ServerValue: types.ServerValue; - Database: typeof types.FirebaseDatabase + Database: typeof types.FirebaseDatabase; }; } interface FirebaseApp { diff --git a/packages/database/index.ts b/packages/database/index.ts index 1d4b9019406..273195973bf 100644 --- a/packages/database/index.ts +++ b/packages/database/index.ts @@ -67,7 +67,7 @@ declare module '@firebase/app-types' { (app?: FirebaseApp): types.FirebaseDatabase; enableLogging: typeof types.enableLogging; ServerValue: types.ServerValue; - Database: typeof types.FirebaseDatabase + Database: typeof types.FirebaseDatabase; }; } interface FirebaseApp { From db087acb6c3ed4c1a473a441e5b5a57645114bc8 Mon Sep 17 00:00:00 2001 From: Josh Crowther Date: Mon, 8 Jan 2018 10:31:57 -0800 Subject: [PATCH 9/9] Fixing nit from @hiranya911 --- integration/firebase-typings/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/firebase-typings/package.json b/integration/firebase-typings/package.json index 4a61e632222..139240a1a5d 100644 --- a/integration/firebase-typings/package.json +++ b/integration/firebase-typings/package.json @@ -11,4 +11,4 @@ "devDependencies": { "typescript": "^2.4.2" } -} \ No newline at end of file +}