/** * @license * Copyright 2017 Google LLC * * 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 { EmulatorMockTokenOptions } from '@firebase/util'; export type DocumentData = { [field: string]: any }; export type UpdateData = { [fieldPath: string]: any }; export const CACHE_SIZE_UNLIMITED: number; export interface Settings { host?: string; ssl?: boolean; cacheSizeBytes?: number; experimentalForceLongPolling?: boolean; experimentalAutoDetectLongPolling?: boolean; ignoreUndefinedProperties?: boolean; merge?: boolean; } export interface PersistenceSettings { synchronizeTabs?: boolean; experimentalTabSynchronization?: boolean; experimentalForceOwningTab?: boolean; } export type LogLevel = | 'debug' | 'error' | 'silent' | 'warn' | 'info' | 'verbose'; export function setLogLevel(logLevel: LogLevel): void; export interface FirestoreDataConverter { toFirestore(modelObject: T): DocumentData; toFirestore(modelObject: Partial, options: SetOptions): DocumentData; fromFirestore(snapshot: QueryDocumentSnapshot, options: SnapshotOptions): T; } export class FirebaseFirestore { private constructor(); settings(settings: Settings): void; useEmulator( host: string, port: number, options?: { mockUserToken?: EmulatorMockTokenOptions | string; } ): void; enablePersistence(settings?: PersistenceSettings): Promise; collection(collectionPath: string): CollectionReference; doc(documentPath: string): DocumentReference; collectionGroup(collectionId: string): Query; runTransaction( updateFunction: (transaction: Transaction) => Promise ): Promise; batch(): WriteBatch; app: any; clearPersistence(): Promise; enableNetwork(): Promise; disableNetwork(): Promise; waitForPendingWrites(): Promise; onSnapshotsInSync(observer: { next?: (value: void) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): () => void; onSnapshotsInSync(onSync: () => void): () => void; terminate(): Promise; loadBundle( bundleData: ArrayBuffer | ReadableStream | string ): LoadBundleTask; namedQuery(name: string): Promise | null>; INTERNAL: { delete: () => Promise }; } export interface LoadBundleTask extends PromiseLike { onProgress( next?: (progress: LoadBundleTaskProgress) => any, error?: (error: Error) => any, complete?: () => void ): void; then( onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike, onRejected?: (a: Error) => R | PromiseLike ): Promise; catch( onRejected: (a: Error) => R | PromiseLike ): Promise; } export interface LoadBundleTaskProgress { documentsLoaded: number; totalDocuments: number; bytesLoaded: number; totalBytes: number; taskState: TaskState; } export type TaskState = 'Error' | 'Running' | 'Success'; export class GeoPoint { constructor(latitude: number, longitude: number); readonly latitude: number; readonly longitude: number; isEqual(other: GeoPoint): boolean; } export class Timestamp { constructor(seconds: number, nanoseconds: number); static now(): Timestamp; static fromDate(date: Date): Timestamp; static fromMillis(milliseconds: number): Timestamp; readonly seconds: number; readonly nanoseconds: number; toDate(): Date; toMillis(): number; isEqual(other: Timestamp): boolean; valueOf(): string; } export class Blob { private constructor(); static fromBase64String(base64: string): Blob; static fromUint8Array(array: Uint8Array): Blob; public toBase64(): string; public toUint8Array(): Uint8Array; isEqual(other: Blob): boolean; } export class Transaction { private constructor(); get(documentRef: DocumentReference): Promise>; set( documentRef: DocumentReference, data: Partial, options: SetOptions ): Transaction; set(documentRef: DocumentReference, data: T): Transaction; update(documentRef: DocumentReference, data: UpdateData): Transaction; update( documentRef: DocumentReference, field: string | FieldPath, value: any, ...moreFieldsAndValues: any[] ): Transaction; delete(documentRef: DocumentReference): Transaction; } export class WriteBatch { private constructor(); set( documentRef: DocumentReference, data: Partial, options: SetOptions ): WriteBatch; set(documentRef: DocumentReference, data: T): WriteBatch; update(documentRef: DocumentReference, data: UpdateData): WriteBatch; update( documentRef: DocumentReference, field: string | FieldPath, value: any, ...moreFieldsAndValues: any[] ): WriteBatch; delete(documentRef: DocumentReference): WriteBatch; commit(): Promise; } export interface SnapshotListenOptions { readonly includeMetadataChanges?: boolean; } export interface SetOptions { readonly merge?: boolean; readonly mergeFields?: (string | FieldPath)[]; } export interface GetOptions { readonly source?: 'default' | 'server' | 'cache'; } export class DocumentReference< T = DocumentData, T2 extends DocumentData = DocumentData > { private constructor(); readonly id: string; readonly firestore: FirebaseFirestore; readonly parent: CollectionReference; readonly path: string; collection(collectionPath: string): CollectionReference; isEqual(other: DocumentReference): boolean; set(data: Partial, options: SetOptions): Promise; set(data: T): Promise; update(data: UpdateData): Promise; update( field: string | FieldPath, value: any, ...moreFieldsAndValues: any[] ): Promise; delete(): Promise; get(options?: GetOptions): Promise>; onSnapshot(observer: { next?: (snapshot: DocumentSnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): () => void; onSnapshot( options: SnapshotListenOptions, observer: { next?: (snapshot: DocumentSnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; } ): () => void; onSnapshot( onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void ): () => void; onSnapshot( options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void ): () => void; withConverter(converter: null): DocumentReference; withConverter(converter: FirestoreDataConverter): DocumentReference; } export interface SnapshotOptions { readonly serverTimestamps?: 'estimate' | 'previous' | 'none'; } export interface SnapshotMetadata { readonly hasPendingWrites: boolean; readonly fromCache: boolean; isEqual(other: SnapshotMetadata): boolean; } export class DocumentSnapshot< T = DocumentData, T2 extends DocumentData = DocumentData > { protected constructor(); readonly exists: boolean; readonly ref: DocumentReference; readonly id: string; readonly metadata: SnapshotMetadata; data(options?: SnapshotOptions): T | undefined; get(fieldPath: string | FieldPath, options?: SnapshotOptions): any; isEqual(other: DocumentSnapshot): boolean; } export class QueryDocumentSnapshot< T = DocumentData, T2 extends DocumentData = DocumentData > extends DocumentSnapshot { private constructor(); data(options?: SnapshotOptions): T; } export type OrderByDirection = 'desc' | 'asc'; export type WhereFilterOp = | '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any' | 'not-in'; export class Query { protected constructor(); readonly firestore: FirebaseFirestore; where( fieldPath: string | FieldPath, opStr: WhereFilterOp, value: any ): Query; orderBy( fieldPath: string | FieldPath, directionStr?: OrderByDirection ): Query; limit(limit: number): Query; limitToLast(limit: number): Query; startAt(snapshot: DocumentSnapshot): Query; startAt(...fieldValues: any[]): Query; startAfter(snapshot: DocumentSnapshot): Query; startAfter(...fieldValues: any[]): Query; endBefore(snapshot: DocumentSnapshot): Query; endBefore(...fieldValues: any[]): Query; endAt(snapshot: DocumentSnapshot): Query; endAt(...fieldValues: any[]): Query; isEqual(other: Query): boolean; get(options?: GetOptions): Promise>; onSnapshot(observer: { next?: (snapshot: QuerySnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): () => void; onSnapshot( options: SnapshotListenOptions, observer: { next?: (snapshot: QuerySnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; } ): () => void; onSnapshot( onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void ): () => void; onSnapshot( options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void ): () => void; withConverter(converter: null): Query; withConverter(converter: FirestoreDataConverter): Query; } export class QuerySnapshot< T = DocumentData, T2 extends DocumentData = DocumentData > { private constructor(); readonly query: Query; readonly metadata: SnapshotMetadata; readonly docs: Array>; readonly size: number; readonly empty: boolean; docChanges(options?: SnapshotListenOptions): Array>; forEach( callback: (result: QueryDocumentSnapshot) => void, thisArg?: any ): void; isEqual(other: QuerySnapshot): boolean; } export type DocumentChangeType = 'added' | 'removed' | 'modified'; export interface DocumentChange< T = DocumentData, T2 extends DocumentData = DocumentData > { readonly type: DocumentChangeType; readonly doc: QueryDocumentSnapshot; readonly oldIndex: number; readonly newIndex: number; } export class CollectionReference< T = DocumentData, T2 extends DocumentData = DocumentData > extends Query { private constructor(); readonly id: string; readonly parent: DocumentReference | null; readonly path: string; doc(documentPath?: string): DocumentReference; add(data: T): Promise>; isEqual(other: CollectionReference): boolean; withConverter(converter: null): CollectionReference; withConverter( converter: FirestoreDataConverter ): CollectionReference; } export class FieldValue { private constructor(); static serverTimestamp(): FieldValue; static delete(): FieldValue; static arrayUnion(...elements: any[]): FieldValue; static arrayRemove(...elements: any[]): FieldValue; static increment(n: number): FieldValue; isEqual(other: FieldValue): boolean; } export class FieldPath { constructor(...fieldNames: string[]); static documentId(): FieldPath; isEqual(other: FieldPath): boolean; } 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'; export interface FirestoreError { code: FirestoreErrorCode; message: string; name: string; stack?: string; } declare module '@firebase/component' { interface NameServiceMapping { 'firestore-compat': FirebaseFirestore; } }