@firebase/firestore
Version:
The Cloud Firestore component of the Firebase JS SDK.
82 lines (81 loc) • 3.73 kB
TypeScript
/**
* @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 { Query } from '../core/query';
import { SnapshotVersion } from '../core/snapshot_version';
import { DocumentKeySet, MutableDocumentMap } from '../model/collections';
import { MutableDocument } from '../model/document';
import { DocumentKey } from '../model/document_key';
import { PersistencePromise } from './persistence_promise';
import { PersistenceTransaction } from './persistence_transaction';
import { RemoteDocumentChangeBuffer } from './remote_document_change_buffer';
/**
* Represents cached documents received from the remote backend.
*
* The cache is keyed by DocumentKey and entries in the cache are
* MutableDocuments, meaning we can cache both actual documents as well as
* documents that are known to not exist.
*/
export interface RemoteDocumentCache {
/**
* Looks up an entry in the cache.
*
* @param documentKey - The key of the entry to look up.*
* @returns The cached document entry. Returns an invalid document if the
* document is not cached.
*/
getEntry(transaction: PersistenceTransaction, documentKey: DocumentKey): PersistencePromise<MutableDocument>;
/**
* Looks up a set of entries in the cache.
*
* @param documentKeys - The keys of the entries to look up.
* @returns The cached document entries indexed by key. If an entry is not
* cached, the corresponding key will be mapped to an invalid document.
*/
getEntries(transaction: PersistenceTransaction, documentKeys: DocumentKeySet): PersistencePromise<MutableDocumentMap>;
/**
* Executes a query against the cached Document entries.
*
* Implementations may return extra documents if convenient. The results
* should be re-filtered by the consumer before presenting them to the user.
*
* Cached NoDocument entries have no bearing on query results.
*
* @param query - The query to match documents against.
* @param sinceReadTime - If not set to SnapshotVersion.min(), return only
* documents that have been read since this snapshot version (exclusive).
* @returns The set of matching documents.
*/
getDocumentsMatchingQuery(transaction: PersistenceTransaction, query: Query, sinceReadTime: SnapshotVersion): PersistencePromise<MutableDocumentMap>;
/**
* Provides access to add or update the contents of the cache. The buffer
* handles proper size accounting for the change.
*
* Multi-Tab Note: This should only be called by the primary client.
*
* @param options - Specify `trackRemovals` to create sentinel entries for
* removed documents, which allows removals to be tracked by
* `getNewDocumentChanges()`.
*/
newChangeBuffer(options?: {
trackRemovals: boolean;
}): RemoteDocumentChangeBuffer;
/**
* Get an estimate of the size of the document cache. Note that for eager
* garbage collection, we don't track sizes so this will return 0.
*/
getSize(transaction: PersistenceTransaction): PersistencePromise<number>;
}