/* * Copyright (c) 2016-present Invertase Limited & Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this library 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 type { DocumentSnapshot, DocumentData, DocumentReference, FirestoreError, Query, QuerySnapshot, SnapshotListenOptions, Unsubscribe, } from '../types/firestore'; import type { ReferenceIsEqualInternal, ReferenceWithOnSnapshotInternal } from '../types/internal'; export { default as DocumentSnapshot } from '../FirestoreDocumentSnapshot'; export { default as QuerySnapshot } from '../FirestoreQuerySnapshot'; export { default as SnapshotMetadata } from '../FirestoreSnapshotMetadata'; export function onSnapshot< AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, >( reference: DocumentReference, observer: { next?: (snapshot: DocumentSnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }, ): Unsubscribe; export function onSnapshot< AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, >( reference: DocumentReference, options: SnapshotListenOptions, observer: { next?: (snapshot: DocumentSnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }, ): Unsubscribe; export function onSnapshot< AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, >( reference: DocumentReference, onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void, ): Unsubscribe; export function onSnapshot< AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, >( reference: DocumentReference, options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void, ): Unsubscribe; export function onSnapshot< AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, >( query: Query, observer: { next?: (snapshot: QuerySnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }, ): Unsubscribe; export function onSnapshot< AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, >( query: Query, options: SnapshotListenOptions, observer: { next?: (snapshot: QuerySnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }, ): Unsubscribe; export function onSnapshot< AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, >( query: Query, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void, ): Unsubscribe; export function onSnapshot< AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, >( query: Query, options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void, ): Unsubscribe; export function onSnapshot< AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, >( reference: Query | DocumentReference, ...args: unknown[] ): Unsubscribe { const onSnapshotMethod = (reference as unknown as ReferenceWithOnSnapshotInternal).onSnapshot; return onSnapshotMethod.call(reference, ...args); } export function snapshotEqual( left: DocumentSnapshot | QuerySnapshot, right: DocumentSnapshot | QuerySnapshot, ): boolean { const isEqual = (left as unknown as ReferenceIsEqualInternal).isEqual; return isEqual.call(left, right); }