UNPKG

@firebase/firestore

Version:

The Cloud Firestore component of the Firebase JS SDK.

151 lines (150 loc) 6.14 kB
/** * @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 { SnapshotVersion } from '../core/snapshot_version'; import { DocumentKey } from './document_key'; import { ObjectValue } from './object_value'; import { FieldPath } from './path'; /** * Represents a document in Firestore with a key, version, data and whether the * data has local mutations applied to it. */ export interface Document { /** The key for this document */ readonly key: DocumentKey; /** * The version of this document if it exists or a version at which this * document was guaranteed to not exist. */ readonly version: SnapshotVersion; /** * The timestamp at which this document was read from the remote server. Uses * `SnapshotVersion.min()` for documents created by the user. */ readonly readTime: SnapshotVersion; /** * The timestamp at which the document was created. This value increases * monotonically when a document is deleted then recreated. It can also be * compared to `createTime` of other documents and the `readTime` of a query. */ readonly createTime: SnapshotVersion; /** The underlying data of this document or an empty value if no data exists. */ readonly data: ObjectValue; /** Returns whether local mutations were applied via the mutation queue. */ readonly hasLocalMutations: boolean; /** Returns whether mutations were applied based on a write acknowledgment. */ readonly hasCommittedMutations: boolean; /** * Whether this document had a local mutation applied that has not yet been * acknowledged by Watch. */ readonly hasPendingWrites: boolean; /** * Returns whether this document is valid (i.e. it is an entry in the * RemoteDocumentCache, was created by a mutation or read from the backend). */ isValidDocument(): boolean; /** * Returns whether the document exists and its data is known at the current * version. */ isFoundDocument(): boolean; /** * Returns whether the document is known to not exist at the current version. */ isNoDocument(): boolean; /** * Returns whether the document exists and its data is unknown at the current * version. */ isUnknownDocument(): boolean; isEqual(other: Document | null | undefined): boolean; /** Creates a mutable copy of this document. */ mutableCopy(): MutableDocument; toString(): string; } /** * Represents a document in Firestore with a key, version, data and whether it * has local mutations applied to it. * * Documents can transition between states via `convertToFoundDocument()`, * `convertToNoDocument()` and `convertToUnknownDocument()`. If a document does * not transition to one of these states even after all mutations have been * applied, `isValidDocument()` returns false and the document should be removed * from all views. */ export declare class MutableDocument implements Document { readonly key: DocumentKey; private documentType; version: SnapshotVersion; readTime: SnapshotVersion; createTime: SnapshotVersion; data: ObjectValue; private documentState; private constructor(); /** * Creates a document with no known version or data, but which can serve as * base document for mutations. */ static newInvalidDocument(documentKey: DocumentKey): MutableDocument; /** * Creates a new document that is known to exist with the given data at the * given version. */ static newFoundDocument(documentKey: DocumentKey, version: SnapshotVersion, createTime: SnapshotVersion, value: ObjectValue): MutableDocument; /** Creates a new document that is known to not exist at the given version. */ static newNoDocument(documentKey: DocumentKey, version: SnapshotVersion): MutableDocument; /** * Creates a new document that is known to exist at the given version but * whose data is not known (e.g. a document that was updated without a known * base document). */ static newUnknownDocument(documentKey: DocumentKey, version: SnapshotVersion): MutableDocument; /** * Changes the document type to indicate that it exists and that its version * and data are known. */ convertToFoundDocument(version: SnapshotVersion, value: ObjectValue): MutableDocument; /** * Changes the document type to indicate that it doesn't exist at the given * version. */ convertToNoDocument(version: SnapshotVersion): MutableDocument; /** * Changes the document type to indicate that it exists at a given version but * that its data is not known (e.g. a document that was updated without a known * base document). */ convertToUnknownDocument(version: SnapshotVersion): MutableDocument; setHasCommittedMutations(): MutableDocument; setHasLocalMutations(): MutableDocument; setReadTime(readTime: SnapshotVersion): MutableDocument; get hasLocalMutations(): boolean; get hasCommittedMutations(): boolean; get hasPendingWrites(): boolean; isValidDocument(): boolean; isFoundDocument(): boolean; isNoDocument(): boolean; isUnknownDocument(): boolean; isEqual(other: Document | null | undefined): boolean; mutableCopy(): MutableDocument; toString(): string; } /** * Compares the value for field `field` in the provided documents. Throws if * the field does not exist in both documents. */ export declare function compareDocumentsByField(field: FieldPath, d1: Document, d2: Document): number;