@firebase/firestore

功能

功能描述
函數(應用程序,...)
取得Firestore(應用程式)傳回與提供的FirebaseApp關聯的現有預設Firestore實例。如果不存在實例,則使用預設設定初始化新實例。
getFirestore(應用程序,資料庫Id) (測試版)傳回與提供的FirebaseApp關聯的現有命名Firestore實例。如果不存在實例,則使用預設設定初始化新實例。
初始化Firestore(應用程序,設置,databaseId)使用提供的設定初始化Firestore的新實例。只能在任何其他函數之前調用,包括getFirestore() 。如果自訂設定為空,則函數相當於呼叫getFirestore()
函數(firestore,...)
清除IndexedDbPersistence(firestore)清除持久性儲存。這包括掛起的寫入和快取的文檔。必須在Firestore實例未啟動時(應用程式終止後或應用程式首次初始化時)呼叫。啟動時,必須在其他函數( initializeFirestore()getFirestore()除外)之前呼叫此函數))。如果Firestore實例仍在運行,則 Promise 將被拒絕,錯誤代碼為failed-precondition注意: clearIndexedDbPersistence()主要旨在協助編寫使用 Cloud Firestore 的可靠測試。它使用有效的機制來刪除現有數據,但不會嘗試安全地覆蓋或以其他方式使快取的數據無法恢復。對於對用戶會話之間緩存資料的洩露敏感的應用程序,我們強烈建議根本不要啟用持久性。
集合(firestore、路徑、pathSegments)取得引用指定絕對路徑處的集合CollectionReference實例。
集合組(firestore,集合Id)建立並傳回一個新的Query實例,其中包含資料庫中具有給定collectionId集合或子集合中包含的所有文件。
connectFirestoreEmulator(firestore、主機、連接埠、選項)修改此實例以與 Cloud Firestore 模擬器進行通訊。注意:必須在使用該實例執行任何操作之前呼叫此方法。
禁用網路(firestore)停用此實例的網路使用。可以透過enableNetwork()重新啟用它。當網路被停用時,任何快照偵聽器、 getDoc()getDocs()呼叫都會從快取傳回結果,並且任何寫入操作都會排隊,直到網路復原。
文檔(firestore、路徑、pathSegments)取得引用指定絕對路徑處的文件的DocumentReference實例。
啟用IndexedDbPersistence(firestore,persistenceSettings)如果可能,請嘗試啟用持久性儲存。如果失敗, enableIndexedDbPersistence()將拒絕承諾或拋出例外。失敗的原因有很多,可以透過錯誤code來識別。 * 失敗前提條件:應用程式已在另一個瀏覽器標籤中開啟。 * 未實作:瀏覽器與離線持久化實作不相容。請注意,即使發生故障, Firestore執行個體仍將可用,但離線持久度將會停用。注意: enableIndexedDbPersistence()必須在任何其他函數( initializeFirestore()除外)之前調用getFirestore()clearIndexedDbPersistence()持久性不能在 Node.js 環境中使用。
啟用MultiTabIndexedDbPersistence(firestore)如果可能,請嘗試啟用多選項卡持久性儲存。如果在所有選項卡上啟用,則所有操作共用對本機持久性的訪問,包括跨所有連接的實例共用查詢執行和延遲補償本機文件更新。如果失敗, enableMultiTabIndexedDbPersistence()將拒絕承諾或拋出例外。失敗的原因有很多,可以透過錯誤code來識別。 * 失敗前提條件:應用程式已在另一個瀏覽器標籤中打開,並且未啟用多選項卡。 * 未實作:瀏覽器與離線持久化實作不相容。請注意,即使發生故障, Firestore執行個體仍將可用,但離線持久度將會停用。
啟用網路(firestore)在先前呼叫disableNetwork()後重新啟用此Firestore實例的網路使用
取得持久性快取索引管理器(firestore)傳回給定Firestore物件使用的 PercientCache 索引管理員。 PersistentCacheIndexManager實例,如果未使用本機持久性存儲,則為null
loadBundle(firestore,bundleData)將 Firestore 捆綁包載入到本機快取中。
命名查詢(firestore,名稱)從本機快取讀取由給定名稱標識的 Firestore查詢命名查詢在伺服器端打包成捆綁包(以及產生的文件),並使用loadBundle載入到本機快取。進入本機快取後,使用此方法按名稱提取查詢
onSnapshotsInSync(firestore,觀察者)附加快照同步事件的偵聽器。 snapshots-in-sync 事件表示受給定變更影響的所有偵聽器均已觸發,即使單一伺服器產生的變更會影響多個偵聽器。注意:snapshots-in-sync 事件僅指示偵聽器彼此同步,但與這些快照是否與伺服器同步無關。在各個偵聽器中使用 SnapshotMetadata 來決定快照是來自快取還是來自伺服器。
onSnapshotsInSync(firestore,onSync)附加快照同步事件的偵聽器。 snapshots-in-sync 事件表示受給定變更影響的所有偵聽器均已觸發,即使單一伺服器產生的變更會影響多個偵聽器。注意:snapshots-in-sync 事件僅指示偵聽器彼此同步,但與這些快照是否與伺服器同步無關。在各個偵聽器中使用SnapshotMetadata來決定快照是來自快取還是來自伺服器。
runTransaction(firestore,updateFunction,選項)執行給定的updateFunction ,然後嘗試提交交易中應用的變更。如果在事務中讀取的任何文件發生更改,Cloud Firestore 會重試updateFunction 。如果5次嘗試後仍無法提交,則交易失敗。單一事務允許的最大寫入次數為 500。
setIndexConfiguration(firestore,配置) (測試版)配置本地查詢執行的索引。任何先前的索引配置都將被覆寫。一旦索引配置被持久化, Promise就會解析。索引條目本身是非同步建立的。即使索引尚不可用,您也可以繼續使用需要索引的查詢。一旦寫入索引條目,查詢執行將自動開始使用索引。僅 IndexedDb 持久性支援索引。如果未啟用 IndexedDb,則任何索引配置都會被忽略。
setIndexConfiguration(firestore,json) (測試版)配置本地查詢執行的索引。任何先前的索引配置都將被覆寫。一旦索引配置被持久化, Promise就會解析。索引條目本身是非同步建立的。即使索引尚不可用,您也可以繼續使用需要索引的查詢。一旦寫入索引條目,查詢執行將自動開始使用索引。僅 IndexedDb 持久性支援索引。在設定索引配置之前呼叫enableIndexedDbPersistence()enableMultiTabIndexedDbPersistence() 。如果未啟用 IndexedDb,則任何索引配置都會被忽略。此方法接受 Firebase CLI ( firebase firestore:indexes ) 匯出的 JSON 格式。如果 JSON 格式無效,此方法將引發錯誤。
終止(火存儲)終止提供的Firestore實例。呼叫terminate()後,只能使用clearIndexedDbPersistence()函數。任何其他函數都會拋出FirestoreError若要在終止後重新啟動,請使用getFirestore()建立 FirebaseFirestore 的新實例終止不會取消任何掛起的寫入,並且任何等待伺服器回應的承諾都不會解決。如果您啟用了持久性,則下次啟動此實例時,它將繼續將這些寫入傳送到伺服器。注意:一般情況下,不需要呼叫terminate() 。只有當您想要強制此實例釋放其所有資源或與clearIndexedDbPersistence()結合使用以確保在測試運行之間銷毀所有本地狀態時,此函數才有用。
waitForPendingWrites(firestore)等待,直到後端確認活動用戶的所有目前掛起的寫入。如果沒有未完成的寫入,則返回的承諾將立即解決。否則,promise 將等待所有先前發出的寫入(包括在先前應用程式會話中寫入的寫入),但它不會等待呼叫函數後新增的寫入。如果您想等待其他寫入,請再次呼叫waitForPendingWrites()在使用者變更期間,任何未完成的waitForPendingWrites()承諾都會被拒絕。
writeBatch(火災存儲)建立一個寫入批次處理,用於將多個寫入作為單一原子操作執行。單一WriteBatch中允許的最大寫入次數為 500。與事務不同,寫入批次會離線保存,因此當您不需要根據讀取資料調整寫入時更可取。
功能()
數數()建立一個 AggregateField 對象,該對象可用於計算查詢結果集中的文件計數。
刪除字段()傳回一個哨兵,與帶有{merge: true}updateDoc()setDoc()一起使用,以標記要刪除的欄位。
文檔ID()傳回一個特殊的哨兵FieldPath來引用文檔的 ID。它可用於在查詢中按文檔 ID 排序或過濾。
取得Firestore()傳回與預設FirebaseApp關聯的現有預設Firestore實例。如果不存在實例,則使用預設設定初始化新實例。
記憶體EagerGarbageCollector()建立MemoryEagerGarbageCollector的實例。這也是預設的垃圾收集器,除非另有明確指定。
持久化多個選項卡管理器()建立PersistentMultipleTabManager的實例。
伺服器時間戳()傳回與setDoc()updateDoc()一起使用的哨兵,以在寫入的資料中包含伺服器產生的時間戳記。
函數(資料庫ID,...)
getFirestore(資料庫ID) (測試版)傳回與預設FirebaseApp關聯的現有命名Firestore實例。如果不存在實例,則使用預設設定初始化新實例。
函數(元素,...)
數組刪除(元素)傳回一個可以與setDoc()一起使用的特殊值,或告訴伺服器從伺服器上已存在的任何陣列值中刪除給定元素。指定的每個元素的所有實例將從數組中刪除。如果正在修改的欄位還不是數組,它將被空數組覆蓋。
數組聯合(元素)傳回一個可以與setDoc()updateDoc()一起使用的特殊值,該值告訴伺服器將給定元素與伺服器上已存在的任何陣列值聯合起來。數組中尚不存在的每個指定元素都將添加到末尾。如果正在修改的欄位還不是數組,它將被包含確切指定元素的數組覆寫。
函數(字段,...)
平均(場)建立一個 AggregateField 對象,該對象可用於計算查詢結果集中一系列文件中指定欄位的平均值。
總和(字段)建立一個 AggregateField 對象,該對象可用於計算查詢結果集中一系列文件的指定欄位的總和。
函數(字段路徑,...)
orderBy(fieldPath, 方向Str)建立一個QueryOrderByConstraint ,按指定欄位對查詢結果進行排序,可以選擇按降序而不是升序。注意:不包含指定欄位的文件不會出現在查詢結果中。
其中(欄位路徑、opStr、值)建立一個QueryFieldFilterConstraint ,強製文件必須包含指定欄位且該值應滿足提供的關係限制。
函數(字段值,...)
結束於(字段值)建立一個QueryEndAtConstraint ,它將結果集修改為相對於查詢順序在提供的欄位處結束。欄位值的順序必須與查詢的 order by 子句的順序相符。
結束之前(欄位值)建立一個QueryEndAtConstraint ,將結果集修改為相對於查詢順序在提供的欄位之前結束。欄位值的順序必須與查詢的 order by 子句的順序相符。
開始之後(欄位值)建立一個QueryStartAtConstraint ,它將結果集修改為相對於查詢順序在提供的欄位之後開始。欄位值的順序必須與查詢的 order by 子句的順序相符。
開始於(字段值)建立一個QueryStartAtConstraint ,它將結果集修改為從相對於查詢順序提供的欄位開始。欄位值的順序必須與查詢的 order by 子句的順序相符。
函數(索引管理器,...)
刪除所有持久性快取索引(indexManager)刪除所有持久性快取索引。請注意,此函數也會刪除由setIndexConfiguration()產生的索引,該索引已被棄用。
停用PersistentCacheIndexAutoCreation(indexManager)停止自動為本機查詢執行建立持久性快取索引。透過呼叫enablePersistentCacheIndexAutoCreation()所建立的索引仍然有效。
啟用持久性快取索引自動建立(indexManager)當 SDK 認為快取索引有助於提高效能時,使 SDK 能夠自動為本機查詢執行建立持久快取索引。預設情況下停用此功能。
函數(左,...)
聚合字段等於(左,右)比較兩個“AggregateField” ` 平等的實例。
聚合查詢快照等於(左,右)比較兩個AggregateQuerySnapshot實例是否相等。如果兩個AggregateQuerySnapshot實例具有比較相等且資料相同的基礎查詢,則它們被視為「相等」。
查詢等於(左,右)如果提供的查詢指向同一集合並套用相同的約束,則傳回 true。
refEqual(左,右)如果提供的引用相等,則傳回 true。
快照等於(左,右)如果提供的快照相等,則傳回 true。
函數(極限,...)
限制(限制)建立一個僅傳回第一個符合文件的QueryLimitConstraint
限製到最後(限制)建立一個僅傳回最後符合文件的QueryLimitConstraint limitToLast查詢必須至少指定一個orderBy子句,否則執行過程中會拋出例外。
函數(日誌級別,...)
設定日誌等級(日誌等級)設定 Cloud Firestore 日誌的詳細程度(偵錯、錯誤或靜默)。
函數(n,...)
增量(n)傳回一個特殊值,可與setDoc()updateDoc()一起使用,告訴伺服器將欄位的目前值增加給定值。如果操作數或目前欄位值使用浮點精確度,則所有算術都遵循 IEEE 754 語意。如果兩個值都是整數,則超出 JavaScript 安全數字範圍( Number.MIN_SAFE_INTEGERNumber.MAX_SAFE_INTEGER )的值也會受到精確度損失的影響。此外,一旦由 Firestore 後端處理,所有整數運算都限制在 -2^63 和 2^63-1 之間。如果目前欄位值不是number類型,或者該欄位尚不存在,則轉換會將該欄位設為給定值。
函數(查詢,...)
getAggregateFromServer(查詢,aggregateSpec)計算給定查詢結果集中文件的指定聚合,而無需實際下載文件。使用此函數執行聚合非常高效,因為僅下載最終聚合值,而不下載文件資料。當結果集太大而無法完全下載(數千個文件)時,此函數可以執行文件聚合。從伺服器接收的結果將保持不變,不考慮任何本地狀態。也就是說,不考慮本地快取中的文檔,也不考慮尚未與伺服器同步的本地修改。不使用先前下載的結果(如果有)。該函數的每次呼叫都必然涉及到伺服器的往返。
從伺服器取得計數(查詢)計算給定查詢的結果集中的文件數,而無需實際下載文件。使用此功能對文件進行計數非常高效,因為只下載最終計數,而不下載文件資料。當結果集太大而無法完全下載(數千個文件)時,此函數可以對文件進行計數。從伺服器接收的結果將保持不變,不考慮任何本地狀態。也就是說,不考慮本地快取中的文檔,也不考慮尚未與伺服器同步的本地修改。不使用先前下載的結果(如果有)。該函數的每次呼叫都必然涉及到伺服器的往返。
取得文件(查詢)執行查詢並將結果作為QuerySnapshot回傳。注意: getDocs()嘗試透過等待來自伺服器的資料來提供最新數據,但如果您處於離線狀態並且無法存取伺服器,它可能會傳回快取的資料或失敗。若要指定此行為,請呼叫getDocsFromCache()getDocsFromServer()
從快取中取得文件(查詢)執行查詢並從快取中以QuerySnapshot形式傳回結果。如果目前沒有快取與查詢相符的文檔,則傳回空結果集。
從伺服器取得文件(查詢)執行查詢並將結果作為QuerySnapshot從伺服器傳回。如果網路不可用,則傳回錯誤。
onSnapshot(查詢,觀察者)附加QuerySnapshot事件的偵聽器。您可以傳遞單獨的onNextonError回調,也可以傳遞具有nexterror回呼的單一觀察者物件。可以透過呼叫onSnapshot時傳回的函數來取消監聽。注意:雖然可以提供onCompletion回調,但它永遠不會被調用,因為快照流是永無止境的。
onSnapshot(查詢、選項、觀察者)附加QuerySnapshot事件的偵聽器。您可以傳遞單獨的onNextonError回調,也可以傳遞具有nexterror回呼的單一觀察者物件。可以透過呼叫onSnapshot時傳回的函數來取消監聽。注意:雖然可以提供onCompletion回調,但它永遠不會被調用,因為快照流是永無止境的。
onSnapshot(查詢、onNext、onError、onCompletion)附加QuerySnapshot事件的偵聽器。您可以傳遞單獨的onNextonError回調,也可以傳遞具有nexterror回呼的單一觀察者物件。可以透過呼叫onSnapshot時傳回的函數來取消監聽。注意:雖然可以提供onCompletion回調,但它永遠不會被調用,因為快照流是永無止境的。
onSnapshot(查詢、選項、onNext、onError、onCompletion)附加QuerySnapshot事件的偵聽器。您可以傳遞單獨的onNextonError回調,也可以傳遞具有nexterror回呼的單一觀察者物件。可以透過呼叫onSnapshot時傳回的函數來取消監聽。注意:雖然可以提供onCompletion回調,但它永遠不會被調用,因為快照流是永無止境的。
查詢(查詢、複合過濾器、查詢約束)建立一個新的非可變Query實例,該實例已擴展為還包含其他查詢約束。
查詢(查詢,查詢約束)建立一個新的非可變Query實例,該實例已擴展為還包含其他查詢約束。
函數(查詢約束,...)
和(查詢約束)建立一個新的QueryCompositeFilterConstraint ,它是給定過濾器約束的結合。如果合取過濾器滿足所有給定過濾器,則該文件包含該文件。
或(查詢約束)建立一個新的QueryCompositeFilterConstraint ,它是給定過濾器約束的析取。如果析取過濾器滿足任何給定過濾器,則該文件包含該文件。
函數(參考,...)
addDoc(參考,數據)使用給定資料將新文件新增至指定的CollectionReference ,並自動為其指派文件 ID。
集合(參考、路徑、pathSegments)取得一個CollectionReference實例,該實例引用指定相對路徑處的reference子集合。
集合(參考、路徑、pathSegments)取得一個CollectionReference實例,該實例引用指定相對路徑處的reference子集合。
刪除文件(參考)刪除指定DocumentReference引用的文件。
文件(參考、路徑、路徑段)取得一個DocumentReference實例,該實例引用指定相對路徑處的reference內的文件。如果未指定路徑,則傳回的DocumentReference將使用自動產生的唯一 ID。
文件(參考、路徑、路徑段)取得一個DocumentReference實例,該實例引用指定相對路徑處的reference內的文件。
取得文件(參考)讀取此DocumentReference引用的文件。注意: getDoc()嘗試透過等待來自伺服器的資料來提供最新數據,但如果您處於離線狀態並且無法存取伺服器,它可能會傳回快取的資料或失敗。若要指定此行為,請呼叫getDocFromCache()getDocFromServer()
getDocFromCache(參考)從快取中讀取此DocumentReference引用的文件。如果當前未快取文檔,則傳回錯誤。
從伺服器取得文件(參考)從伺服器讀取此DocumentReference引用的文件。如果網路不可用,則傳回錯誤。
onSnapshot(參考,觀察者)附加DocumentSnapshot事件的偵聽器。您可以傳遞單獨的onNextonError回調,也可以傳遞具有nexterror回呼的單一觀察者物件。注意:雖然可以提供onCompletion回調,但它永遠不會被調用,因為快照流是永無止境的。
onSnapshot(參考,選項,觀察者)附加DocumentSnapshot事件的偵聽器。您可以傳遞單獨的onNextonError回調,也可以傳遞具有nexterror回呼的單一觀察者物件。注意:雖然可以提供onCompletion回調,但它永遠不會被調用,因為快照流是永無止境的。
onSnapshot(參考、onNext、onError、onCompletion)附加DocumentSnapshot事件的偵聽器。您可以傳遞單獨的onNextonError回調,也可以傳遞具有nexterror回呼的單一觀察者物件。注意:雖然可以提供onCompletion回調,但它永遠不會被調用,因為快照流是永無止境的。
onSnapshot(參考,選項,onNext,onError,onCompletion)附加DocumentSnapshot事件的偵聽器。您可以傳遞單獨的onNextonError回調,也可以傳遞具有nexterror回呼的單一觀察者物件。注意:雖然可以提供onCompletion回調,但它永遠不會被調用,因為快照流是永無止境的。
setDoc(參考,數據)寫入此DocumentReference引用的文件。如果該文件尚不存在,則會建立該文件。
setDoc(參考、數據、選項)寫入指定DocumentReference引用的文件。如果該文件尚不存在,則會建立該文件。如果您提供mergemergeFields ,則提供的資料可以合併到現有文件中。
updateDoc(參考,數據)更新指定DocumentReference引用的文件中的欄位。如果套用於不存在的文檔,更新將會失敗。
updateDoc(參考、欄位、值、moreFieldsAndValues)更新指定DocumentReference引用的文檔中的欄位 如果套用於不存在的文檔,更新將會失敗。可以透過提供點分隔的欄位路徑字串或提供FieldPath物件來更新巢狀欄位。
功能(設置,...)
記憶體本地快取(設定)建立MemoryLocalCache的實例。這個實例可以設定為FirestoreSettings.cache來告訴 SDK 使用哪個快取層。
記憶體LruGarbageCollector(設定)建立MemoryLruGarbageCollector的實例。目標尺寸可以指定為設定參數的一部分。一旦快取大小超過給定大小,收集器將開始刪除文件。預設快取大小為 40MB(40 * 1024 * 1024 位元組)。
持久性本地快取(設定)建立PersistentLocalCache的實例。這個實例可以設定為FirestoreSettings.cache來告訴 SDK 使用哪個快取層。持久性快取不能在 Node.js 環境中使用。
持久性單標籤管理器(設定)建立PersistentSingleTabManager的實例。
函數(快照,...)
結束時間(快照)建立一個QueryEndAtConstraint ,將結果集修改為以提供的文件(包含)結束。結束位置與查詢的順序有關。該文件必須包含查詢的 orderBy 中提供的所有欄位。
結束前(快照)建立一個QueryEndAtConstraint ,將結果集修改為在提供的文件之前結束(不包括)。結束位置與查詢的順序有關。該文件必須包含查詢的 orderBy 中提供的所有欄位。
開始之後(快照)建立一個QueryStartAtConstraint ,將結果集修改為在提供的文件之後開始(不包括)。起始位置與查詢的順序相關。該文件必須包含查詢的 orderBy 中提供的所有欄位。
開始時間(快照)建立一個QueryStartAtConstraint ,它將結果集修改為從提供的文件(包括)開始。起始位置與查詢的順序相關。該文件必須包含此查詢的orderBy中提供的所有欄位。

課程

班級描述
聚合字段表示可由 Firestore 執行的聚合。
聚合查詢快照執行聚合查詢的結果。
位元組表示位元組數組的不可變物件。
收藏參考CollectionReference物件可用於新增文件、取得文件參考和查詢文件(使用query() )。
文件參考DocumentReference是指 Firestore 資料庫中的文件位置,可用於寫入、讀取或偵聽該位置。引用位置處的文件可能存在,也可能不存在。
文件快照DocumentSnapshot包含從 Firestore 資料庫中的文件讀取的資料。可以使用.data().get(<field>)提取資料以取得特定欄位。對於指向不存在文件的DocumentSnapshot ,任何資料存取都會傳回「未定義」。您可以使用exists()方法明確驗證文件是否存在。
字段路徑FieldPath指的是文件中的欄位。此路徑可以由單一欄位名稱(指文件中的頂層欄位)或欄位名稱清單(指文件中的嵌套欄位)組成。透過提供欄位名稱建立FieldPath 。如果提供多個欄位名稱,則路徑將指向文件中的巢狀欄位。
欄位值使用set()update()寫入文件欄位時可以使用的哨兵值。
火庫Cloud Firestore 服務介面。不要直接呼叫此構造函數。相反,使用getFirestore()
Firestore錯誤Firestore 操作傳回的錯誤。
地理點表示 Firestore 中地理位置的不可變物件。該位置以緯度/經度對錶示。緯度值的範圍是 [-90, 90]。經度值的範圍為 [-180, 180]。
載入Bundle任務表示載入 Firestore 捆綁包的任務。它提供套件載入的進度,以及任務完成和錯誤事件。此 API 與Promise<LoadBundleTaskProgress>相容。
持久性快取索引管理器PersistentCacheIndexManager ,用於設定用於本機查詢執行的持久性快取索引。使用時,呼叫getPersistentCacheIndexManager()來取得一個實例。
詢問Query是指您可以閱讀或聆聽的查詢。您也可以透過新增篩選器和排序來建構精煉的Query物件。
查詢複合過濾器約束QueryCompositeFilterConstraint用於透過執行多個QueryFieldFilterConstraint的邏輯 OR 或 AND 來縮小 Firestore 查詢傳回的文件集s 或QueryCompositeFilterConstraint s。 QueryCompositeFilterConstraint透過呼叫or()and()創建,然後可以傳遞給query()以建立也包含QueryCompositeFilterConstraint的新查詢實例。
查詢約束QueryConstraint用於縮小 Firestore 查詢傳回的文件集。 QueryConstraint透過呼叫where()來創建, orderBy() ,開始處() ,開始之後() ,結束之前() ,結束 ()限制()limitToLast()然後可以傳遞給query()以建立一個也包含此QueryConstraint的新查詢實例。
查詢文件快照QueryDocumentSnapshot包含作為查詢的一部分從 Firestore 資料庫中的文件讀取的資料。此文件保證存在,並且可以使用.data().get(<field>)提取其資料以取得特定欄位。 QueryDocumentSnapshot提供與DocumentSnapshot相同的 API 介面。由於查詢結果僅包含現有文檔, exists屬性將始終為 true,且data()永遠不會返回「未定義」。
查詢結束約束QueryEndAtConstraint用於從 Firestore 查詢傳回的結果集末端排除文件。 QueryEndAtConstraint是透過呼叫endAt()endBefore()建立的,然後可以傳遞給query()以建立也包含此QueryEndAtConstraint的新查詢實例。
查詢字段過濾約束QueryFieldFilterConstraint用於透過篩選一個或多個文件欄位來縮小 Firestore 查詢傳回的文件集。 QueryFieldFilterConstraint是透過呼叫where()來建立的,然後可以傳遞給query()以建立一個也包含此QueryFieldFilterConstraint的新查詢實例。
查詢限制約束QueryLimitConstraint用於限制 Firestore 查詢傳回的文件數量。 QueryLimitConstraint是透過呼叫limit()limitToLast()建立的,然後可以傳遞給query()以建立一個也包含此QueryLimitConstraint的新查詢實例。
按約束查詢順序QueryOrderByConstraint用於對 Firestore 查詢傳回的文件集進行排序。 QueryOrderByConstraint是透過呼叫orderBy()來建立的,然後可以傳遞給query()以建立一個也包含此QueryOrderByConstraint的新查詢實例。注意:不包含 orderBy 欄位的文件不會出現在查詢結果中。
查詢快照QuerySnapshot包含零個或多個表示查詢結果的DocumentSnapshot物件。文件可以透過docs屬性作為數組進行訪問,也可以使用forEach方法進行枚舉。文件的數量可以透過emptysize屬性來決定。
查詢開始約束QueryStartAtConstraint用於從 Firestore 查詢傳回的結果集的開頭排除文件。 QueryStartAtConstraint是透過呼叫startAt()startAfter()建立的,然後可以傳遞給query()以建立一個也包含此QueryStartAtConstraint的新查詢實例。
快照元數據有關快照的元數據,描述快照的狀態。
時間戳Timestamp表示獨立於任何時區或日曆的時間點,以 UTC 紀元時間中奈秒分辨率的秒和秒的分數表示。它使用 Proleptic 公曆進行編碼,將公曆向後延伸到第一年。它的編碼假定所有分鐘都是 60 秒長,即閏秒被“塗抹”,因此不需要閏秒錶來解釋。範圍從 0001-01-01T00:00:00Z 到 9999-12-31T23:59:59.999999999Z。有關範例和更多規範,請參閱時間戳定義
交易對交易的引用。傳遞給交易的updateFunctionTransaction物件提供在事務上下文中讀取和寫入資料的方法。參見runTransaction()
寫批次處理寫入批次處理,用於將多個寫入作為單一原子單元執行。可以透過呼叫writeBatch()來取得WriteBatch對象。它提供了將寫入添加到寫入批次的方法。在呼叫WriteBatch.commit()之前,不會提交任何寫入(或在本地可見)。

介面

介面描述
聚合規格指定一組聚合及其別名。
文件變更DocumentChange表示與查詢相符的文件的變更。它包含受影響的文件以及發生的變更類型。
文件資料文件資料(與setDoc()一起使用) 由對應到值的欄位組成。
實驗性長輪詢選項使用長輪詢時設定 SDK 底層網路傳輸 (WebChannel) 的選項。注意:此介面是“實驗性的”,可能會發生變化。請參閱FirestoreSettings.experimentalAutoDetectLongPollingFirestoreSettings.experimentalForceLongPollingFirestoreSettings.experimentalLongPollingOptions
Firestore資料轉換器withConverter()使用轉換器將AppModelType類型的使用者物件轉換為DbModelType類型的 Firestore 資料。使用轉換器可讓您在從 Firestore 儲存和擷取物件時指定通用類型參數。在這種情況下,「AppModel」是在應用程式中用於將相關資訊和功能打包在一起的類別。例如,這樣的類別可以具有複雜巢狀資料類型的屬性、用於記憶的屬性、Firestore 不支援的類型的屬性(例如symbolbigint )以及執行複合操作的輔助函數。此類類別不適合和/或無法儲存到 Firestore 資料庫中。相反,此類別的實例需要轉換為具有專有原始屬性的「普通舊 JavaScript 物件」(POJO),可能嵌套在其他 POJO 或 POJO 陣列中。在此上下文中,此類型稱為“DbModel”,並且是適合持久保存到 Firestore 中的物件。為了方便起見,應用程式可以實作FirestoreDataConverter並向 Firestore 物件(例如DocumentReferenceQuery註冊轉換器,以便在儲存到 Firestore 時自動將AppModel轉換為DbModel ,並在從 Firestore 擷取時自動將DbModel轉換為AppModel
Firestore設定指定 Cloud Firestore 執行個體的自訂配置。您必須在呼叫任何其他方法之前設定這些。
指數(測試版) Firestore 索引的 SDK 定義。
索引配置(測試版)用於加速本機查詢執行的 Firestore 索引清單。有關索引定義格式的說明,請參閱JSON 格式
索引字段(BETA)索引配置中的單一欄位元素。
載入Bundle任務進度表示載入包的進度更新或最終狀態。
記憶體快取設定用於設定MemoryLocalCache實例的設定物件。
記憶體Eager垃圾收集器只要文件不屬於任何活動查詢,並且沒有附加任何本地突變,垃圾收集器就會刪除它們。此收集器嘗試確保 SDK 的記憶體佔用量最低,但存在文件無法快取以供離線查詢或直接查詢快取的風險。使用工廠函數建立該收集器的實例。
記憶體本地快取為 SDK 提供記憶體快取。除非明確配置,否則這是預設快取。要使用,請使用工廠函數建立實例,然後將該實例設定為FirestoreSettings.cache並使用設定物件呼叫initializeFirestore
記憶體Lru垃圾收集器垃圾收集器會分批刪除最近最少使用的文件。此收集器配置為目標大小,並且只有在快取文件超過目標大小時才執行收集。它避免了對相同查詢或文件重複重複的查詢後端,冒著更大的記憶體足跡的風險。使用工廠功能建立此收集器的實例。
持久化設定可以傳遞的設定enableIndexedDbPersistence()以配置Firestore持久性。持久性不能用於node.js環境中。
持續的塞術設定物件配置PersistentLocalCache實例。持續的快取不能在node.js環境中使用。
持久性本地快取提供一個由索引的持續快取到SDK。要使用,請使用工廠函數建立一個實例,然後將實例設定為FirestoreSettings.cache ,然後使用設定物件呼叫initializeFirestore
PersistentMultipletabManager支援多個選項卡的選項卡管理器。 SDK將使用SDK在所有選項卡上同步查詢和突變。
持久性商人僅支援一個選項卡的選項卡管理器,將不同步在跨選項卡中執行。
持久性屬於managersettings鍵入配置PersistentSingleTabManager實例。
Snapshotlistenoptions可以傳遞到onsnapshot()querysnapshot.docchanges()的選項對象,以控制結果集中包含哪些類型的變更。
快照選項配置如何從DocumentSnapshot檢索資料的選項(例如,尚未將其設定為最終值設定為伺服器時間戳記的所需行為)。
交易選項自訂交易行為的選項。
退訂onSnapshot()傳回的函數,該函數在呼叫時會刪除偵聽器。

變數

多變的描述
cache_size_unlimited用於指示LRU垃圾收集的常數。將此值設定為傳遞給Firestore實例的設定上的cacheSizeBytes

類型別名

類型別名描述
addprefixtokeys傳回一個新的地圖,其中每個鍵都在附加到點的外鍵前綴。
匯總FieldType Firestore支援的所有AggregateField類型的結合。
骨材pecdataAggregateSpec中取得的鍵的類型,其值是由對應的AggregateField從輸入AggregateSpec執行的聚合的結果。
聚合類型代表要執行的聚合類型的聯合類型。
Childupdatefields用於計算給定T1的嵌套欄位的助手。這是分發聯合類型(例如undefined | {...}所需的。 undefined | {...} (用於可選的道具發生)或{a: A} | {b: B}在此用例中, V用於RecordT[K]的聯合類型,因為T[K]被評估為表達式而不是分佈。請參閱https://www.typescriptlang.org/docs/handbook/advanced-types.html#distribnation-conditional-types
DocumentChangeType可以“新增”,“刪除”或“修改”的DocumentChange的類型。
firestoreErrorCode Firestore狀態碼集。 grpc在此處暴露的程式碼是相同的:可能的值: - “取消”:操作已取消(通常由呼叫者)。 - “未知”:未知錯誤或來自其他錯誤域的錯誤。 - “無效 - argument”:客戶端指定了一個無效的參數。請注意,這不同於「失敗至關」。 「無效的題詞」指出了有問題的參數,無論系統狀態如何(例如,欄位名稱無效)。 - 「截止日期」:截止日期在操作完成之前已過期。對於更改系統狀態的操作,即使操作成功完成,也可以傳回此錯誤。例如,伺服器的成功回應可能已經延遲了足夠長的時間,以使截止日期到期。 - 'NOTUNDONG':找不到一些要求的檔案。 - 「已經存在的」:我們嘗試建立的一些文件已經存在。 - 「限制權限」:呼叫者無權執行指定的操作。 - 「資源 - 偏項」:某些資源已經用盡,可能是每個使用者配額,或整個檔案系統都超出了空間。 - 「失敗至上」:操作被拒絕,因為該系統不處於操作執行所需的狀態。 - 「中止」:此操作被中止,通常是由於交易中止等並發問題。-「 Out-range':Operation':操作已超過有效範圍。 - '未完成':未實現或不支援/啟用操作。 - '內部':內部錯誤。意味著某些基本系統預期的不變​​性已被打破。如果您看到這些錯誤之一,那麼某些事情就會非常損壞。 - 「不可用」:該服務目前無法使用。這很可能是瞬態條件,可以透過退縮重試來修正。 - 「資料損失」:無法復原的資料遺失或損壞。 - 「未經驗證」:此要求沒有對操作的有效身份驗證憑證。
firestorelocalcache來自所有支援的SDK快取層的聯合類型。
Liscensource描述詢問來源的來源。設定為default以收聽快取和伺服器變更。設定為cache以收聽快取的變更。
MemoryGarbageCollector所有支援Gabage收集器的聯合類型用於記憶體本地快取。
Nestedupdatefields對於每個欄位(例如'bar'),找到所有巢狀鍵(例如{ 'bar.baz':t1,'bar.qux':t2 } )。將它們相交在一起,製作一個包含所有可能標記為可選的鍵的單一地圖
OrderByDiriend訂單()子句的方向指定為“ desc”或“ asc”(降序或上升)。
partialwithfieldValue類似Typescript的Partial<T> ,但允許省略嵌套字段,並以屬性值的形式傳遞字段值。
PersistentTabManager所有可用標籤經理的組合。
原始原始型別。
QueryConstraintType描述此SDK中可用的不同查詢約束。
QueryFilterConstraint QueryFilterConstraint是一種輔助聯合類型,代表QueryFieldFilterConstraintQueryCompositeFilterConstraint
querynonfilterconstraint QueryNonFilterConstraint是一種輔助聯合類型,代表用於縮小或訂購一組文件的QueryConstraints,但不會在文件欄位上明確過濾。 QueryNonFilterConstraint是透過呼叫Order Boildboint()來建立的startat()startafter()endbefore()endat()limit()limittolast() ,然後可以傳遞到query()建立一個新的查詢實例,該實例也包含QueryConstraint
setOptions配置setDoc()行為的選項對象,並打電話。這些呼叫可以配置為執行顆粒狀合併,而不是透過提供合併的SetOptions merge: true來整體覆蓋目標文件。
TaskState表示捆綁載入任務的狀態。 「錯誤」和「成功」都處於沉沒狀態:任務將中止或完成,並且報告後將不再有更新。
聯合助力給定一個Union Type U = T1 | T2 | ... ,返回相交類型(T1 & T2 & ...)使用有條件類型的分配條件類型和推論。之所以起作用,是因為相反位置中相同類型變數的多個候選物會導致相交類型。 https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-in​​perionpe-perion-inperion-in-conditional-types https://stackoverflow.com/questions/questions /50374908/trans-trans-form-type-type-type-type-type-type-in​​tercection -類型
更新更新資料(用於UpdatedOc() )由映射到值的野外路徑(例如'foo'或'foo.baz')組成。包含DOT的字段參考文檔中的嵌套字段。字段值可以作為屬性值傳遞。
filterop使用字串' lt;','&lt; =','==','!=','&gt; =',','&gt;','array-contains',使用字串'&lt; =','==',',',',',',',',',',',',',',',',',',',',',', ',',',! ,“ in”,“ array-contains-”和“ Not-In”。
與FieldValue在維持類型安全性的同時,允許將現場價值作為屬性值傳遞。

函數(應用程序,...)

取得Firestore(應用程式)

傳回與提供的FirebaseApp關聯的現有預設firestore實例。如果不存在實例,則使用預設設定初始化新實例。

簽名:

export declare function getFirestore(app: FirebaseApp): Firestore;

參數

範圍類型描述
應用程式Firebase應用程式傳回的firestore實例與之關聯的firebaseApp實例。

返回:

火庫

提供的應用程式的預設firestore實例。

getFirestore(應用程序,資料庫Id)

此API是作為開發人員的預覽提供的,可能會根據我們收到的回饋而更改。不要在生產環境中使用此API。

傳回與提供的firebaseApp關聯的現有命名的firestore實例。如果不存在實例,則使用預設設定初始化新實例。

簽名:

export declare function getFirestore(app: FirebaseApp, databaseId: string): Firestore;

參數

範圍類型描述
應用程式Firebase應用程式傳回的firestore實例與之關聯的firebaseApp實例。
資料庫細繩資料庫的名稱。

返回:

火庫

提供的應用程式的命名firestore實例。

InitializeFirestore(應用程序,設置,資料庫)

使用提供的設定初始化Firestore的新實例。只能在任何其他功能之前調用,包括getfirestore() 。如果自訂設為空,則此功能等於呼叫getfirestore()

簽名:

export declare function initializeFirestore(app: FirebaseApp, settings: FirestoreSettings, databaseId?: string): Firestore;

參數

範圍類型描述
應用程式Firebase應用程式Firestore實例相關聯的FirebaseApp
設定Firestore設定設定物件以配置firestore實例。
資料庫細繩資料庫的名稱。

返回:

火庫

新初始化的Firestore實例。

函數(firestore,...)

清除IndexedDbPersistence(firestore)

清除持久性儲存。這包括掛起的寫入和快取的文檔。

必須在Firestore實例未啟動時(應用程式終止後或應用程式首次初始化時)呼叫。在啟動時,必須在其他函數之前呼叫此功能(除了初始化firestore()getfirestore()() ))。如果Firestore實例仍在failed-precondition

簽名:

export declare function clearIndexedDbPersistence(firestore: Firestore): Promise<void>;

參數

範圍類型描述
火庫火庫Firestore執行個體要清除持久性。

返回:

承諾<void>

清除持久性儲存時解決的Promise將得到解決。否則,承諾將被錯誤拒絕。

集合(firestore、路徑、pathSegments)

取得一個CollectionReference實例,該實例指定的絕對路徑處的集合。

簽名:

export declare function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference<DocumentData, DocumentData>;

參數

範圍類型描述
火庫火庫對根Firestore實例的參考。
小路細繩一條分開的藏品路徑。
路徑細繩[]相對於第一個參數適用的其他路徑段。

返回:

收藏參考< DocumentDataDocumentData >

CollectionReference實例。

例外情況

如果最終路徑具有均勻數的段,並且沒有指向集合。

集合組(firestore,集合Id)

建立並傳回一個新的Query實例,其中包含資料庫中包含的所有文檔,該實例包含在集合中或帶有給定collectionId的子集合中

簽名:

export declare function collectionGroup(firestore: Firestore, collectionId: string): Query<DocumentData, DocumentData>;

參數

範圍類型描述
火庫火庫對根Firestore實例的參考。
CollectionID細繩確定要詢問的收藏。將包括該ID的每個集合或子集合作為其路徑的最後一部分。不能包含斜線。

返回:

詢問< DocumentDataDocumentData >

建立的Query

connectFirestoreEmulator(firestore、主機、連接埠、選項)

修改此實例以與 Cloud Firestore 模擬器進行通訊。

簽名:

export declare function connectFirestoreEmulator(firestore: Firestore, host: string, port: number, options?: {
    mockUserToken?: EmulatorMockTokenOptions | string;
}): void;

參數

範圍類型描述
火庫火庫要配置以連接模擬器的Firestore實例。
主持人細繩模擬器主機(例如:localhost)。
港口數位模擬器連接埠(例如:9000)。
選項{oibusertoken?: eMulatorMockTokenOptions |細繩; }

返回:

空白

禁用網路(firestore)

停用此實例的網路使用。它可以透過enablenetwork()重新啟用。在停用網路時,任何快照偵聽器, getDoc()getDocs()呼叫將傳回快取的結果,並且任何寫入操作都會排隊直到恢復網路。

簽名:

export declare function disableNetwork(firestore: Firestore): Promise<void>;

參數

範圍類型描述
火庫火庫

返回:

承諾<void>

一旦網路被停用,就可以解決的Promise

文件(firestore、路徑、pathSegments)

取得一個DocumentReference實例,該實例涉及指定的絕對路徑上的文件。

簽名:

export declare function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData, DocumentData>;

參數

範圍類型描述
火庫火庫對根Firestore實例的參考。
小路細繩文檔分隔的路徑。
路徑細繩[]相對於第一個參數將會套用的其他路徑段。

返回:

DocumentReference < DocumentDataDocumentData >

DocumentReference實例。

例外情況

如果最終路徑具有奇數段,並且沒有指向文件。

啟用IndexedDbPersistence(firestore,persistenceSettings)

此功能將在以後的主要版本中刪除。相反,將FirestoreSettings.localCache設定為PersistentLocalCache的實例,以開啟索引eddb快取。當已經指定了FirestoreSettings.localCache時呼叫此功能會引發異常。

如果可能,請嘗試啟用持久性儲存。

失敗時, enableIndexedDbPersistence()將拒絕承諾或拋出例外。這可能會失敗的原因有幾個,可以在錯誤上透過code識別。

* 失敗前提條件:應用程式已在另一個瀏覽器標籤中開啟。 * 未實作:瀏覽器與離線持久化實作不相容。

請注意,即使發生故障, Firestore執行個體仍將可用,但離線持久度將會停用。

持久性不能用於node.js環境中。

簽名:

export declare function enableIndexedDbPersistence(firestore: Firestore, persistenceSettings?: PersistenceSettings): Promise<void>;

參數

範圍類型描述
火庫火庫firestore實例可以實現持久性。
持久性持久化設定可選設定物件要配置持久性。

返回:

承諾<void>

代表成功實現持久性儲存的Promise

啟用MultiTabIndexedDbPersistence(firestore)

此功能將在以後的主要版本中刪除。相反,將FirestoreSettings.localCache設定為PersistentLocalCache的實例,以開啟索引eddb快取。當已經指定了FirestoreSettings.localCache時呼叫此功能會引發異常。

如果可能,請嘗試啟用多選項卡持久性儲存。如果在所有選項卡中啟用了所有操作,則所有操作共享對本地持久性的訪問,包括查詢的共享執行以及在所有連接實例上均具有延遲補償的本地文檔更新。

失敗時, enableMultiTabIndexedDbPersistence()將拒絕承諾或拋出例外。這可能會失敗的原因有幾個,可以在錯誤上透過code識別。

* 失敗前提條件:應用程式已在另一個瀏覽器標籤中打開,並且未啟用多選項卡。 * 未實作:瀏覽器與離線持久化實作不相容。

請注意,即使發生故障, Firestore執行個體仍將可用,但離線持久度將會停用。

簽名:

export declare function enableMultiTabIndexedDbPersistence(firestore: Firestore): Promise<void>;

參數

範圍類型描述
火庫火庫firestore實例可以實現持久性。

返回:

承諾<void>

代表成功實現持久性儲存的Promise

enablenetwork(firestore)

先前呼叫disablenetwork ()之前,將網路重新使用網路使用該網路。

簽名:

export declare function enableNetwork(firestore: Firestore): Promise<void>;

參數

範圍類型描述
火庫火庫

返回:

承諾<void>

一旦啟用網絡,就可以解決的Promise

取得持久性快取索引管理器(firestore)

傳回給定的Firestore物件使用的PersistentCache索引管理員。

如果未使用本機持久存儲,則PersistentCacheIndexManager實例或null

簽名:

export declare function getPersistentCacheIndexManager(firestore: Firestore): PersistentCacheIndexManager | null;

參數

範圍類型描述
火庫火庫

返回:

PersistentCacheIndexManager |無效的

loadBundle(firestore,bundleData)

將 Firestore 捆綁包載入到本機快取中。

簽名:

export declare function loadBundle(firestore: Firestore, bundleData: ReadableStream<Uint8Array> | ArrayBuffer | string): LoadBundleTask;

參數

範圍類型描述
火庫火庫firestore實例載入捆綁包。
捆綁readableSream <Uint8Array> | ArrayBuffer |細繩代表要載入的捆綁包的物件。有效的物件是ArrayBufferReadableStream<Uint8Array>string

返回:

載入Bundle任務

LoadBundleTask對象,該物件通知呼叫者進行進度更新以及完成或錯誤事件。它可以用作Promise<LoadBundleTaskProgress>

命名查詢(firestore,名稱)

從本機快取讀取由給定名稱標識的 Firestore查詢

命名的查詢被包裝成伺服器端(以及結果文件)的捆綁包,並使用loadBundle載入到本機緩存。進入本機快取後,使用此方法按名稱提取查詢

簽名:

export declare function namedQuery(firestore: Firestore, name: string): Promise<Query | null>;

參數

範圍類型描述
火庫火庫firestore實例以讀取查詢。
姓名細繩查詢的名稱。

返回:

承諾<查詢|空>

透過查詢或null解決的Promise

onSnapshotsInSync(firestore,觀察者)

附加快照同步事件的偵聽器。 snapshots-in-sync 事件表示受給定變更影響的所有偵聽器均已觸發,即使單一伺服器產生的變更會影響多個偵聽器。

注意:snapshots-in-sync 事件僅指示偵聽器彼此同步,但與這些快照是否與伺服器同步無關。在各個偵聽器中使用 SnapshotMetadata 來決定快照是來自快取還是來自伺服器。

簽名:

export declare function onSnapshotsInSync(firestore: Firestore, observer: {
    next?: (value: void) => void;
    error?: (error: FirestoreError) => void;
    complete?: () => void;
}): Unsubscribe;

參數

範圍類型描述
火庫火庫用於同步快照的Firestore實例。
觀察者{next?:(value:void)=> void;錯誤?:(錯誤: firestoreError )=> void;完整?:()=> void; }一個包含next物件和error回調。

返回:

退訂

可呼叫的退訂函數,以取消快照偵聽器。

onSnapshotsInSync(firestore,onSync)

附加快照同步事件的偵聽器。 snapshots-in-sync 事件表示受給定變更影響的所有偵聽器均已觸發,即使單一伺服器產生的變更會影響多個偵聽器。

注意:snapshots-in-sync 事件僅指示偵聽器彼此同步,但與這些快照是否與伺服器同步無關。在各個偵聽器中使用SnapshotMetadata來決定快照是來自快取還是來自伺服器。

簽名:

export declare function onSnapshotsInSync(firestore: Firestore, onSync: () => void): Unsubscribe;

參數

範圍類型描述
火庫火庫用於同步快照的Firestore實例。
Onsync ()=> void每當所有快照聽眾彼此同步時,都會被召喚。

返回:

退訂

可呼叫的退訂函數,以取消快照偵聽器。

runTransaction(firestore,updateFunction,選項)

執行給定的updateFunction ,然後嘗試提交交易中應用的變更。如果交易中的任何文件都updateFunction。如果5次嘗試後仍無法提交,則交易失敗。

單一事務允許的最大寫入次數為 500。

簽名:

export declare function runTransaction<T>(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;

參數

範圍類型描述
火庫火庫對Firestore資料庫進行此交易的引用。
更新功能(交易:交易)=>承諾<t>在事務上下文中執行的功能。
選項交易選項一個選項對象,以配置最大嘗試提交的嘗試數。

返回:

承諾<t>

如果交易成功完成或明確中止了( updateFunction傳回了失敗的承諾),則updateFunction退還的承諾在這裡返回。否則,如果交易失敗,則傳回帶有相應失敗錯誤的拒絕承諾。

setIndexConfiguration(firestore,配置)

此API是作為開發人員的預覽提供的,可能會根據我們收到的回饋而更改。不要在生產環境中使用此API。

而不是手動建立快取索引,而是考慮使用enablePersistentCacheIndexAutoCreation()讓SDK決定是否為本機執行的查詢建立快取索引。

為本機查詢執行配置索引。任何先前的索引配置都將被覆寫。索引配置持續存在後, Promise解決。

索引條目本身是非同步建立的。即使索引尚不可用,您也可以繼續使用需要索引的查詢。一旦寫入索引條目,查詢執行將自動開始使用索引。

僅 IndexedDb 持久性支援索引。如果未啟用 IndexedDb,則任何索引配置都會被忽略。

簽名:

export declare function setIndexConfiguration(firestore: Firestore, configuration: IndexConfiguration): Promise<void>;

參數

範圍類型描述
火庫火庫firestore實例要配置索引。
配置索引配置索引定義。

返回:

承諾<void>

一旦成功配置了所有索引,就Promise解決。

例外情況

如果JSON格式無效,則FirestoreError。

setIndexConfiguration(firestore,json)

此API是作為開發人員的預覽提供的,可能會根據我們收到的回饋而更改。不要在生產環境中使用此API。

而不是手動建立快取索引,而是考慮使用enablePersistentCacheIndexAutoCreation()讓SDK決定是否為本機執行的查詢建立快取索引。

為本機查詢執行配置索引。任何先前的索引配置都將被覆寫。索引配置持續存在後, Promise解決。

索引條目本身是非同步建立的。即使索引尚不可用,您也可以繼續使用需要索引的查詢。一旦寫入索引條目,查詢執行將自動開始使用索引。

僅 IndexedDb 持久性支援索引。在設定索引配置之前,請啟用enableIndexedDbPersistence()enableMultiTabIndexedDbPersistence() 。如果未啟用 IndexedDb,則任何索引配置都會被忽略。

此方法接受Firebase CLI導出的JSON格式( firebase firestore:indexes )。如果 JSON 格式無效,此方法將引發錯誤。

簽名:

export declare function setIndexConfiguration(firestore: Firestore, json: string): Promise<void>;

參數

範圍類型描述
火庫火庫firestore實例要配置索引。
json細繩JSON格式由Firebase CLI導出。

返回:

承諾<void>

一旦成功配置了所有索引,就Promise解決。

例外情況

如果JSON格式無效,則FirestoreError。

終止(火存儲)

終止提供的Firestore實例。

呼叫terminate()之後,只能使用clearIndexedDbPersistence()函數。任何其他功能都會拋出FirestoreError

若要在終止後重新啟動,請使用getfirestore()建立FirebaseFirestore的新實例

終止不會取消任何待處理的寫作,並且無法解決等待伺服器回應的任何承諾。如果您啟用了持久性,下次啟動此實例時,它將恢復將這些寫入傳送給伺服器。

簽名:

export declare function terminate(firestore: Firestore): Promise<void>;

參數

範圍類型描述
火庫火庫

返回:

承諾<void>

實例成功終止時解決的Promise將得到解決。

waitForPendingWrites(firestore)

等待直到目前正在為活躍用戶寫作的所有尚待寫作已被後端承認。

如果沒有出色的寫作,返回的承諾立即解決。否則,承諾等待所有先前發行的寫入(包括上一個應用程式中寫的寫信),但它不等待在調用函數後添加的寫入。如果您想等待其他寫入,請再次致電waitForPendingWrites()

在用戶更改期間,任何出色的waitForPendingWrites()承諾將被拒絕。

簽名:

export declare function waitForPendingWrites(firestore: Firestore): Promise<void>;

參數

範圍類型描述
火庫火庫

返回:

承諾<void>

當前所有待處理的寫作都被後端所承認時,決心的Promise

writeBatch(火災存儲)

建立一個寫入批次,用於執行多個原子操作。單一寫入中允許的最大寫入數為500。

與交易不同,寫入批次持續脫機,因此,當您不需要在讀取資料上進行寫入時,最好是可取的。

簽名:

export declare function writeBatch(firestore: Firestore): WriteBatch;

參數

範圍類型描述
火庫火庫

返回:

寫批次處理

可以用來原子執行多個寫入的寫入批次

功能()

數數()

建立一個聚集的對象,該對象可用於在查詢的結果集中計算文件計數。

簽名:

export declare function count(): AggregateField<number>;

返回:

聚合字段<數字>

刪除字段()

傳回sentinel,供{merge: true}updatedoc()setDoc()一起使用,以標記刪除欄位。

簽名:

export declare function deleteField(): FieldValue;

返回:

欄位值

DocumentID()

傳回一個特殊的哨兵FieldPath ,以參考文檔的ID。它可以在查詢中用於透過文檔ID進行排序或過濾。

簽名:

export declare function documentId(): FieldPath;

返回:

野外路徑

getfirestore()

傳回與預設firbaseApp關聯的現有預設firestore實例。如果不存在實例,則使用預設設定初始化新實例。

簽名:

export declare function getFirestore(): Firestore;

返回:

火庫

預設應用程式的預設firestore實例。

MemoryEagergarbageCollector()

建立一個MemoryEagerGarbageCollector的實例。除非另有明確指定,否則這也是預設垃圾收集器。

簽名:

export declare function memoryEagerGarbageCollector(): MemoryEagerGarbageCollector;

返回:

記憶體Eager垃圾收集器

persistentmultipletabmanager()

建立一個PersistentMultipleTabManager的實例

簽名:

export declare function persistentMultipleTabManager(): PersistentMultipleTabManager;

返回:

PersistentMultipletabManager

Servertimestamp()

傳回與setDoc()updatedoc()一起使用的哨兵,以在書面資料中包含伺服器產生的時間戳記。

簽名:

export declare function serverTimestamp(): FieldValue;

返回:

欄位值

函數(資料庫,...)

getfirestore(資料庫)

此API是作為開發人員的預覽提供的,可能會根據我們收到的回饋而更改。不要在生產環境中使用此API。

傳回與預設firebaseApp關聯的現有命名的firestore實例。如果不存在實例,則使用預設設定初始化新實例。

簽名:

export declare function getFirestore(databaseId: string): Firestore;

參數

範圍類型描述
資料庫細繩資料庫的名稱。

返回:

火庫

預設應用程式的命名firestore實例。

功能(元素,...)

arrayremove(元素)

傳回可以與setDoc()一起使用的特殊值,或告訴伺服器從伺服器上已經存在的任何陣列值中刪除給定元素。指定的每個元素的所有實例將從數組中刪除。如果要修改的欄位還不是一個數組,它將被一個空數組覆蓋。

簽名:

export declare function arrayRemove(...elements: unknown[]): FieldValue;

參數

範圍類型描述
元素未知[]從數組中刪除的元素。

返回:

欄位值

用於呼叫setDoc()updateDoc()FieldValue Sentinel

陣列(元素)

傳回可以與setDoc()updatedoc()一起使用的特殊值,該值告訴伺服器將給定元素與伺服器上已經存在的任何陣列值結合。數組中尚未存在的每個指定元素將添加到末尾。如果要修改的欄位還不是數組,它將被包含指定元素的數組覆寫。

簽名:

export declare function arrayUnion(...elements: unknown[]): FieldValue;

參數

範圍類型描述
元素未知[]將元素變成陣列的要素。

返回:

欄位值

用於呼叫setDoc()updateDoc()FieldValue Sentinel

功能(字段,...)

平均(場)

建立一個聚集的對象,該對象可用於在查詢的結果集中在一系列文件上計算指定欄位的平均值。

簽名:

export declare function average(field: string | FieldPath): AggregateField<number | null>;

參數

範圍類型描述
場地字串|野外路徑在結果集中指定平均的欄位。

返回:

聚合字段<號碼|空>

總和(字段)

建立一個聚集的對象,該對象可用於在查詢結果集中在一系列文件上計算指定欄位的總和。

簽名:

export declare function sum(field: string | FieldPath): AggregateField<number>;

參數

範圍類型描述
場地字串|野外路徑指定在結果集中總和的欄位。

返回:

聚合字段<數字>

功能(fieldpath,...)

Orderby(FieldPath,DirectionSTR)

建立一個QueryOrderByConstraint ,該查詢由指定欄位對查詢產生,可選為降序而不是上升。

簽名:

export declare function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryOrderByConstraint;

參數

範圍類型描述
野外路徑字串|野外路徑要排序的欄位。
DirectionStr OrderByDiriend可選的方向,按(“ ASC”或“ DESC”)排序。如果未指定,訂單將上升。

返回:

按約束查詢順序

創建的QueryOrderByConstraint

其中(fieldpath,opstr,value)

建立一個QueryFieldFilterConstraint ,該構造必須包含指定字段,並且該值應滿足所提供的關係約束。

簽名:

export declare function where(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown): QueryFieldFilterConstraint;

參數

範圍類型描述
野外路徑字串|野外路徑比較的途徑
OPSTR filterop操作字串(例如“&lt;”,“”,“&lt; =”,“ ==”,“”&lt;“,”&lt; =“,”,“!=”)。
價值未知比較值

返回:

查詢字段過濾約束

創建的QueryFieldFilterConstraint

函數(fieldvalues,...)

Endat(fieldvalues)

建立一個QueryEndatConstraint ,可修改結果設定以在提供的欄位相對於查詢的順序結束。欄位值的順序必須與查詢條款的子句相符。

簽名:

export declare function endAt(...fieldValues: unknown[]): QueryEndAtConstraint;

參數

範圍類型描述
現場值未知[]按查詢以查詢順序結束此查詢的欄位值。

返回:

查詢結束約束

QueryEndatConstraint傳遞給query()

EndBefore(fieldvalues)

建立一個QueryEndatConstraint ,將結果修改為在提供的欄位相對於查詢順序之前結束。欄位值的順序必須與查詢條款的子句相符。

簽名:

export declare function endBefore(...fieldValues: unknown[]): QueryEndAtConstraint;

參數

範圍類型描述
現場值未知[]以查詢順序順序結束此查詢之前的欄位值。

返回:

查詢結束約束

QueryEndatConstraint傳遞給query()

startafter(fieldvalues)

建立一個QueryStartatConstraint ,該查詢將修改結果設定在提供的欄位相對於查詢順序之後開始。欄位值的順序必須與查詢條款的子句相符。

簽名:

export declare function startAfter(...fieldValues: unknown[]): QueryStartAtConstraint;

參數

範圍類型描述
現場值未知[]按查詢依查詢順序依序啟動此查詢的欄位值。

返回:

查詢開始約束

QueryStartatConstraint以傳遞到query()

startat(fieldvalues)

建立一個QueryStartAtconstraint ,可修改結果設置,以從提供的欄位開始相對於查詢的順序。欄位值的順序必須與查詢條款的子句相符。

簽名:

export declare function startAt(...fieldValues: unknown[]): QueryStartAtConstraint;

參數

範圍類型描述
現場值未知[]按查詢按查詢順序啟動此查詢的欄位值。

返回:

查詢開始約束

QueryStartatConstraint以傳遞到query()

功能(indexmanager,...)

deleteallpersistentCacheIndexes(indexManager)

刪除所有持續的快取索引。

請注意,此功能也會刪除setIndexConfiguration()產生的索引,棄用。

簽名:

export declare function deleteAllPersistentCacheIndexes(indexManager: PersistentCacheIndexManager): void;

參數

範圍類型描述
indexmanager持久性快取索引管理器

返回:

空白

停用cacheindexautocreation(indexManager)

停止為本機查詢執行而自動建立持久的快取索引。透過呼叫enablePersistentCacheIndexAutoCreation()所建立的索引仍然生效。

簽名:

export declare function disablePersistentCacheIndexAutoCreation(indexManager: PersistentCacheIndexManager): void;

參數

範圍類型描述
indexmanager持久性快取索引管理器

返回:

空白

啟用PasperStentCacheIndexautocreation(IndexManager)

當SDK認為高速緩存索引可以幫助提高效能時,使SDK能夠自動建立持久的快取索引以自動進行本地查詢執行。

預設情況下停用此功能。

簽名:

export declare function enablePersistentCacheIndexAutoCreation(indexManager: PersistentCacheIndexManager): void;

參數

範圍類型描述
indexmanager持久性快取索引管理器

返回:

空白

功能(左...)

骨材

比較兩個'聚集`平等實例。

簽名:

export declare function aggregateFieldEqual(left: AggregateField<unknown>, right: AggregateField<unknown>): boolean;

參數

範圍類型描述
左邊聚合字段<未知>比較right的這個骨材。
正確的聚合字段<未知>比較left的這個聚集體。

返回:

布林值

ExcregateQuerySnapShoteQual(左,右)

比較兩個AggregateQuerySnapshot實例以保持平等。

如果兩個AggregateQuerySnapshot實例具有比較相等的基本查詢和相同資料的基本查詢,則將其視為「相等」。

簽名:

export declare function aggregateQuerySnapshotEqual<AggregateSpecType extends AggregateSpec, AppModelType, DbModelType extends DocumentData>(left: AggregateQuerySnapshot<AggregateSpecType, AppModelType, DbModelType>, right: AggregateQuerySnapshot<AggregateSpecType, AppModelType, DbModelType>): boolean;

參數

範圍類型描述
左邊聚合查詢快照<gentregateSpectype,appmodeltype,dbmodeltype>第一個比較的AggregateQuerySnapshot
正確的聚合查詢快照<gentregateSpectype,appmodeltype,dbmodeltype>第二個要比較的AggregateQuerySnapshot

返回:

布林值

如果物件是「相等」的,則如上所述,或否則false true

QueryEqual(左,右)

如果提供的查詢指向同一集合並套用相同的約束,則傳回為true。

簽名:

export declare function queryEqual<AppModelType, DbModelType extends DocumentData>(left: Query<AppModelType, DbModelType>, right: Query<AppModelType, DbModelType>): boolean;

參數

範圍類型描述
左邊詢問<AppModelType,DBModelType>比較的Query
正確的詢問<AppModelType,DBModelType>比較的Query

返回:

布林值

如果引用指向同一firestore資料庫中的相同位置,則為true。

重新等式(左,右)

如果提供的引用相等,則傳回為true。

簽名:

export declare function refEqual<AppModelType, DbModelType extends DocumentData>(left: DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>, right: DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>): boolean;

參數

範圍類型描述
左邊DocumentReference <AppModelType,dbmodeltype> |收藏參考<AppModelType,DBModelType>參考比較。
正確的DocumentReference <AppModelType,dbmodeltype> |收藏參考<AppModelType,DBModelType>參考比較。

返回:

布林值

如果引用指向同一firestore資料庫中的相同位置,則為true。

Snapshotequal(左,右)

如果提供的快照相等,則傳回true。

簽名:

export declare function snapshotEqual<AppModelType, DbModelType extends DocumentData>(left: DocumentSnapshot<AppModelType, DbModelType> | QuerySnapshot<AppModelType, DbModelType>, right: DocumentSnapshot<AppModelType, DbModelType> | QuerySnapshot<AppModelType, DbModelType>): boolean;

參數

範圍類型描述
左邊文件快照<AppModelType,dbmodeltype> |查詢快照<AppModelType,DBModelType>比較快照。
正確的文件快照<AppModelType,dbmodeltype> |查詢快照<AppModelType,DBModelType>比較快照。

返回:

布林值

如果快照相等,則為是真的。

功能(極限,...)

限制(極限)

建立一個僅傳回第一個符合文件的查詢限制

簽名:

export declare function limit(limit: number): QueryLimitConstraint;

參數

範圍類型描述
限制數位傳回的最大項目數。

返回:

查詢限制約束

建立的查詢限制

Limittolast(極限)

建立一個僅傳回最後一個符合的文件的查詢限制

您必須至少為limitToLast查詢指定至少一個orderBy條款,否則在執行期間將拋出一個例外。

簽名:

export declare function limitToLast(limit: number): QueryLimitConstraint;

參數

範圍類型描述
限制數位傳回的最大項目數。

返回:

查詢限制約束

建立的查詢限制

功能(Loglevel,...)

setLoglevel(loglevel)

設定Cloud Firestore日誌的詳細性(調試,錯誤或無聲)。

簽名:

export declare function setLogLevel(logLevel: LogLevel): void;

參數

範圍類型描述
日誌等級loglevel您設定的活動和錯誤記錄的詳細性。可以是以下任何值:
  • debug大多數詳細的記錄級別,主要用於調試。
  • 僅記錄錯誤的error
  • silent to turn off logging.

返回:

空白

功能(n,...)

增量(n)

傳回可以與setDoc()updatedoc()一起使用的特殊值,該值告訴伺服器透過給定值增加欄位的目前值。

如果操作數或目前場值使用浮點精確度,則所有算術均遵循IEEE 754語意。如果兩個值都是整數,則在JavaScript的安全號碼範圍之外( Number.MIN_SAFE_INTEGERNumber.MAX_SAFE_INTEGER之外的值)也遭受精確損失。此外,一旦透過Firestore後端處理,所有整數操作都限制在-2^63和2^63-1之間。

如果目前欄位值不是類型number ,或者如果欄位尚不存在,則轉換將欄位設為給定值。

簽名:

export declare function increment(n: number): FieldValue;

參數

範圍類型描述
n數位要增加的值。

返回:

欄位值

用於呼叫setDoc()updateDoc()FieldValue Sentinel

功能(查詢,...)

getAggregateFromServer(QUERY,gentregatesPec)

在給定查詢的結果集中計算文件上指定的聚合,而無需實際下載文件。

使用此功能執行聚合是有效的,因為只有最終的聚合值而不是文件的資料。在結果集非常大以完全下載的情況下,此功能可以執行文件的聚合(成千上萬的文檔)。

從伺服器接收的結果是不變的,而無需考慮任何局部狀態。也就是說,未考慮本地快取中的文檔,尚未與伺服器同步的本地修改也不是。未使用先前下載的結果(如果有)。此功能的每個呼叫都必須涉及到伺服器的往返。

簽名:

export declare function getAggregateFromServer<AggregateSpecType extends AggregateSpec, AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, aggregateSpec: AggregateSpecType): Promise<AggregateQuerySnapshot<AggregateSpecType, AppModelType, DbModelType>>;

參數

範圍類型描述
詢問詢問<AppModelType,DBModelType>其結果集的查詢已匯總。
聚集匯總光譜一個指定要在結果集上執行的聚合AggregateSpec件。骨材PEC指定每個骨材的別名,可用來檢索聚合結果。

返回:

Promise < gentregatequerysnapshot <gentregateSpectype,appmodeltype,dbmodeltype >>

例子

const aggregateSnapshot = await getAggregateFromServer(query, {
  countOfDocs: count(),
  totalHours: sum('hours'),
  averageScore: average('score')
});

const countOfDocs: number = aggregateSnapshot.data().countOfDocs;
const totalHours: number = aggregateSnapshot.data().totalHours;
const averageScore: number | null = aggregateSnapshot.data().averageScore;

getCountfromserver(查詢)

在沒有實際下載文件的情況下計算給定查詢結果集中的文件數。

使用此功能來計數文件是有效的,因為只有最終計數(而不是文件的資料)才會下載。在結果集非常大以完全下載的情況下,此功能可以計算文件(成千上萬的文件)。

從伺服器接收的結果是不變的,而無需考慮任何局部狀態。也就是說,未考慮本地快取中的文檔,尚未與伺服器同步的本地修改也不是。未使用先前下載的結果(如果有)。此功能的每個呼叫都必須涉及到伺服器的往返。

簽名:

export declare function getCountFromServer<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>): Promise<AggregateQuerySnapshot<{
    count: AggregateField<number>;
}, AppModelType, DbModelType>>;

參數

範圍類型描述
詢問詢問<AppModelType,DBModelType>計算其結果設定大小的查詢。

返回:

Promise < gentregatequerysnapshot <{count:骨材<數字>; },appModelType,dbmodeltype >>

將透過計數解決的承諾;計數可以從snapshot.data().count檢索,其中snapshot是返回的諾言可以解決的AggregateQuerySnapshot

GetDocs(查詢)

執行查詢並將結果傳回為QuerySnapshot

簽名:

export declare function getDocs<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>): Promise<QuerySnapshot<AppModelType, DbModelType>>;

參數

範圍類型描述
詢問詢問<AppModelType,DBModelType>

返回:

Promise < querysnapshot <AppModelType,dbModelType >>

查詢結果將解決的Promise將解決。

getDocsfromcache(查詢)

執行查詢並將結果傳回作為CACHE的QuerySnapshot 。如果目前沒有符合查詢的文檔,則傳回一個空的結果集。

簽名:

export declare function getDocsFromCache<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>): Promise<QuerySnapshot<AppModelType, DbModelType>>;

參數

範圍類型描述
詢問詢問<AppModelType,DBModelType>

返回:

Promise < querysnapshot <AppModelType, DbModelType>>

A Promise that will be resolved with the results of the query.

getDocsFromServer(query)

Executes the query and returns the results as a QuerySnapshot from the server. Returns an error if the network is not available.

簽名:

export declare function getDocsFromServer<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>): Promise<QuerySnapshot<AppModelType, DbModelType>>;

參數

範圍類型描述
詢問詢問<AppModelType, DbModelType>

返回:

Promise< QuerySnapshot <AppModelType, DbModelType>>

A Promise that will be resolved with the results of the query.

onSnapshot(query, observer)

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. The listener can be cancelled by calling the function that is returned when onSnapshot is called.

NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

簽名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, observer: {
    next?: (snapshot: QuerySnapshot<AppModelType, DbModelType>) => void;
    error?: (error: FirestoreError) => void;
    complete?: () => void;
}): Unsubscribe;

參數

範圍類型描述
詢問詢問<AppModelType, DbModelType> The query to listen to.
觀察者{ next?: (snapshot: QuerySnapshot <AppModelType, DbModelType>) => void; error?: (error: FirestoreError ) => void; complete?: () => void; } A single object containing next and error callbacks.

返回:

退訂

An unsubscribe function that can be called to cancel the snapshot listener.

onSnapshot(query, options, observer)

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. The listener can be cancelled by calling the function that is returned when onSnapshot is called.

NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

簽名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, options: SnapshotListenOptions, observer: {
    next?: (snapshot: QuerySnapshot<AppModelType, DbModelType>) => void;
    error?: (error: FirestoreError) => void;
    complete?: () => void;
}): Unsubscribe;

參數

範圍類型描述
詢問詢問<AppModelType, DbModelType> The query to listen to.
選項SnapshotListenOptions Options controlling the listen behavior.
觀察者{ next?: (snapshot: QuerySnapshot <AppModelType, DbModelType>) => void; error?: (error: FirestoreError ) => void; complete?: () => void; } A single object containing next and error callbacks.

返回:

退訂

An unsubscribe function that can be called to cancel the snapshot listener.

onSnapshot(query, onNext, onError, onCompletion)

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. The listener can be cancelled by calling the function that is returned when onSnapshot is called.

NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

簽名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, onNext: (snapshot: QuerySnapshot<AppModelType, DbModelType>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;

參數

範圍類型描述
詢問詢問<AppModelType, DbModelType> The query to listen to.
onNext (snapshot: QuerySnapshot <AppModelType, DbModelType>) => void A callback to be called every time a new QuerySnapshot is available.
錯誤時(error: FirestoreError )=> void A callback to be called if the listen fails or is cancelled. No further callbacks will occur.
在完成的時候() => void Can be provided, but will not be called since streams are never ending.

返回:

退訂

An unsubscribe function that can be called to cancel the snapshot listener.

onSnapshot(query, options, onNext, onError, onCompletion)

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. The listener can be cancelled by calling the function that is returned when onSnapshot is called.

NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

簽名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot<AppModelType, DbModelType>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;

參數

範圍類型描述
詢問詢問<AppModelType, DbModelType> The query to listen to.
選項SnapshotListenOptions Options controlling the listen behavior.
onNext (snapshot: QuerySnapshot <AppModelType, DbModelType>) => void A callback to be called every time a new QuerySnapshot is available.
錯誤時(error: FirestoreError )=> void A callback to be called if the listen fails or is cancelled. No further callbacks will occur.
在完成的時候() => void Can be provided, but will not be called since streams are never ending.

返回:

退訂

An unsubscribe function that can be called to cancel the snapshot listener.

query(query, compositeFilter, queryConstraints)

Creates a new immutable instance of Query that is extended to also include additional query constraints.

簽名:

export declare function query<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query<AppModelType, DbModelType>;

參數

範圍類型描述
詢問詢問<AppModelType, DbModelType> The Query instance to use as a base for the new constraints.
compositeFilter查詢複合過濾器約束The QueryCompositeFilterConstraint to apply. Create QueryCompositeFilterConstraint using and() or or()
queryConstraints QueryNonFilterConstraint [] Additional QueryNonFilterConstraint s to apply (eg orderBy()限制() )。

返回:

詢問<AppModelType, DbModelType>

例外情況

if any of the provided query constraints cannot be combined with the existing or new constraints.

query(query, queryConstraints)

Creates a new immutable instance of Query that is extended to also include additional query constraints.

簽名:

export declare function query<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, ...queryConstraints: QueryConstraint[]): Query<AppModelType, DbModelType>;

參數

範圍類型描述
詢問詢問<AppModelType, DbModelType> The Query instance to use as a base for the new constraints.
queryConstraints查詢約束[] The list of QueryConstraint s to apply.

返回:

詢問<AppModelType, DbModelType>

例外情況

if any of the provided query constraints cannot be combined with the existing or new constraints.

function(queryConstraints, ...)

and(queryConstraints)

Creates a new QueryCompositeFilterConstraint that is a conjunction of the given filter constraints. A conjunction filter includes a document if it satisfies all of the given filters.

簽名:

export declare function and(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;

參數

範圍類型描述
queryConstraints QueryFilterConstraint []選修的。 The list of QueryFilterConstraint s to perform a conjunction for. These must be created with calls to where()或() , or and()

返回:

查詢複合過濾器約束

The newly created QueryCompositeFilterConstraint

or(queryConstraints)

Creates a new QueryCompositeFilterConstraint that is a disjunction of the given filter constraints. A disjunction filter includes a document if it satisfies any of the given filters.

簽名:

export declare function or(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;

參數

範圍類型描述
queryConstraints QueryFilterConstraint []選修的。 The list of QueryFilterConstraint s to perform a disjunction for. These must be created with calls to where()或() , or and()

返回:

查詢複合過濾器約束

The newly created QueryCompositeFilterConstraint

function(reference, ...)

addDoc(reference, data)

Add a new document to specified CollectionReference with the given data, assigning it a document ID automatically.

簽名:

export declare function addDoc<AppModelType, DbModelType extends DocumentData>(reference: CollectionReference<AppModelType, DbModelType>, data: WithFieldValue<AppModelType>): Promise<DocumentReference<AppModelType, DbModelType>>;

參數

範圍類型描述
參考收藏參考<AppModelType, DbModelType> A reference to the collection to add this document to.
數據WithFieldValue <AppModelType> An Object containing the data for the new document.

返回:

Promise< DocumentReference <AppModelType, DbModelType>>

A Promise resolved with a DocumentReference pointing to the newly created document after it has been written to the backend (Note that it won't resolve while you're offline).

collection(reference, path, pathSegments)

Gets a CollectionReference instance that refers to a subcollection of reference at the the specified relative path.

簽名:

export declare function collection<AppModelType, DbModelType extends DocumentData>(reference: CollectionReference<AppModelType, DbModelType>, path: string, ...pathSegments: string[]): CollectionReference<DocumentData, DocumentData>;

參數

範圍類型描述
參考收藏參考<AppModelType, DbModelType> A reference to a collection.
小路細繩A slash-separated path to a collection.
pathSegments細繩[] Additional path segments to apply relative to the first argument.

返回:

收藏參考< DocumentData , DocumentData >

The CollectionReference instance.

例外情況

If the final path has an even number of segments and does not point to a collection.

collection(reference, path, pathSegments)

Gets a CollectionReference instance that refers to a subcollection of reference at the the specified relative path.

簽名:

export declare function collection<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, path: string, ...pathSegments: string[]): CollectionReference<DocumentData, DocumentData>;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType> A reference to a Firestore document.
小路細繩A slash-separated path to a collection.
pathSegments細繩[] Additional path segments that will be applied relative to the first argument.

返回:

收藏參考< DocumentData , DocumentData >

The CollectionReference instance.

例外情況

If the final path has an even number of segments and does not point to a collection.

deleteDoc(reference)

Deletes the document referred to by the specified DocumentReference

簽名:

export declare function deleteDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>): Promise<void>;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType> A reference to the document to delete.

返回:

Promise<void>

A Promise resolved once the document has been successfully deleted from the backend (note that it won't resolve while you're offline).

doc(reference, path, pathSegments)

Gets a DocumentReference instance that refers to a document within reference at the specified relative path. If no path is specified, an automatically-generated unique ID will be used for the returned DocumentReference

簽名:

export declare function doc<AppModelType, DbModelType extends DocumentData>(reference: CollectionReference<AppModelType, DbModelType>, path?: string, ...pathSegments: string[]): DocumentReference<AppModelType, DbModelType>;

參數

範圍類型描述
參考收藏參考<AppModelType, DbModelType> A reference to a collection.
小路細繩A slash-separated path to a document. Has to be omitted to use auto-genrated IDs.
pathSegments細繩[] Additional path segments that will be applied relative to the first argument.

返回:

DocumentReference <AppModelType, DbModelType>

The DocumentReference instance.

例外情況

If the final path has an odd number of segments and does not point to a document.

doc(reference, path, pathSegments)

Gets a DocumentReference instance that refers to a document within reference at the specified relative path.

簽名:

export declare function doc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, path: string, ...pathSegments: string[]): DocumentReference<DocumentData, DocumentData>;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType> A reference to a Firestore document.
小路細繩A slash-separated path to a document.
pathSegments細繩[] Additional path segments that will be applied relative to the first argument.

返回:

DocumentReference < DocumentData , DocumentData >

The DocumentReference instance.

例外情況

If the final path has an odd number of segments and does not point to a document.

getDoc(reference)

Reads the document referred to by this DocumentReference

簽名:

export declare function getDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>): Promise<DocumentSnapshot<AppModelType, DbModelType>>;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType> The reference of the document to fetch.

返回:

Promise< DocumentSnapshot <AppModelType, DbModelType>>

A Promise resolved with a DocumentSnapshot containing the current document contents.

getDocFromCache(reference)

Reads the document referred to by this DocumentReference from cache. Returns an error if the document is not currently cached.

簽名:

export declare function getDocFromCache<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>): Promise<DocumentSnapshot<AppModelType, DbModelType>>;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType>

返回:

Promise< DocumentSnapshot <AppModelType, DbModelType>>

A Promise resolved with a DocumentSnapshot containing the current document contents.

getDocFromServer(reference)

Reads the document referred to by this DocumentReference from the server. Returns an error if the network is not available.

簽名:

export declare function getDocFromServer<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>): Promise<DocumentSnapshot<AppModelType, DbModelType>>;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType>

返回:

Promise< DocumentSnapshot <AppModelType, DbModelType>>

A Promise resolved with a DocumentSnapshot containing the current document contents.

onSnapshot(reference, observer)

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.

簽名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, observer: {
    next?: (snapshot: DocumentSnapshot<AppModelType, DbModelType>) => void;
    error?: (error: FirestoreError) => void;
    complete?: () => void;
}): Unsubscribe;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType> A reference to the document to listen to.
觀察者{ next?: (snapshot: DocumentSnapshot <AppModelType, DbModelType>) => void; error?: (error: FirestoreError ) => void; complete?: () => void; } A single object containing next and error callbacks.

返回:

退訂

An unsubscribe function that can be called to cancel the snapshot listener.

onSnapshot(reference, options, observer)

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.

簽名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, options: SnapshotListenOptions, observer: {
    next?: (snapshot: DocumentSnapshot<AppModelType, DbModelType>) => void;
    error?: (error: FirestoreError) => void;
    complete?: () => void;
}): Unsubscribe;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType> A reference to the document to listen to.
選項SnapshotListenOptions Options controlling the listen behavior.
觀察者{ next?: (snapshot: DocumentSnapshot <AppModelType, DbModelType>) => void; error?: (error: FirestoreError ) => void; complete?: () => void; } A single object containing next and error callbacks.

返回:

退訂

An unsubscribe function that can be called to cancel the snapshot listener.

onSnapshot(reference, onNext, onError, onCompletion)

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.

簽名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, onNext: (snapshot: DocumentSnapshot<AppModelType, DbModelType>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType> A reference to the document to listen to.
onNext (snapshot: DocumentSnapshot <AppModelType, DbModelType>) => void A callback to be called every time a new DocumentSnapshot is available.
錯誤時(error: FirestoreError )=> void A callback to be called if the listen fails or is cancelled. No further callbacks will occur.
在完成的時候() => void Can be provided, but will not be called since streams are never ending.

返回:

退訂

An unsubscribe function that can be called to cancel the snapshot listener.

onSnapshot(reference, options, onNext, onError, onCompletion)

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.

簽名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot<AppModelType, DbModelType>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType> A reference to the document to listen to.
選項SnapshotListenOptions Options controlling the listen behavior.
onNext (snapshot: DocumentSnapshot <AppModelType, DbModelType>) => void A callback to be called every time a new DocumentSnapshot is available.
錯誤時(error: FirestoreError )=> void A callback to be called if the listen fails or is cancelled. No further callbacks will occur.
在完成的時候() => void Can be provided, but will not be called since streams are never ending.

返回:

退訂

An unsubscribe function that can be called to cancel the snapshot listener.

setDoc(reference, data)

Writes to the document referred to by this DocumentReference 。 If the document does not yet exist, it will be created.

簽名:

export declare function setDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, data: WithFieldValue<AppModelType>): Promise<void>;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType> A reference to the document to write.
數據WithFieldValue <AppModelType> A map of the fields and values for the document.

返回:

Promise<void>

A Promise resolved once the data has been successfully written to the backend (note that it won't resolve while you're offline).

setDoc(reference, data, options)

Writes to the document referred to by the specified DocumentReference 。 If the document does not yet exist, it will be created. If you provide merge or mergeFields , the provided data can be merged into an existing document.

簽名:

export declare function setDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, data: PartialWithFieldValue<AppModelType>, options: SetOptions): Promise<void>;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType> A reference to the document to write.
數據PartialWithFieldValue <AppModelType> A map of the fields and values for the document.
選項SetOptions An object to configure the set behavior.

返回:

Promise<void>

A Promise resolved once the data has been successfully written to the backend (note that it won't resolve while you're offline).

updateDoc(reference, data)

Updates fields in the document referred to by the specified DocumentReference 。 The update will fail if applied to a document that does not exist.

簽名:

export declare function updateDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, data: UpdateData<DbModelType>): Promise<void>;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType> A reference to the document to update.
數據UpdateData <DbModelType> An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document.

返回:

Promise<void>

A Promise resolved once the data has been successfully written to the backend (note that it won't resolve while you're offline).

updateDoc(reference, field, value, moreFieldsAndValues)

Updates fields in the document referred to by the specified 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.

簽名:

export declare function updateDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise<void>;

參數

範圍類型描述
參考DocumentReference <AppModelType, DbModelType> A reference to the document to update.
場地字串| FieldPath The first field to update.
價值未知第一個值。
moreFieldsAndValues未知[] Additional key value pairs.

返回:

Promise<void>

A Promise resolved once the data has been successfully written to the backend (note that it won't resolve while you're offline).

function(settings, ...)

memoryLocalCache(settings)

Creates an instance of MemoryLocalCache 。 The instance can be set to FirestoreSettings.cache to tell the SDK which cache layer to use.

簽名:

export declare function memoryLocalCache(settings?: MemoryCacheSettings): MemoryLocalCache;

參數

範圍類型描述
設定記憶體快取設定

返回:

記憶體本地快取

memoryLruGarbageCollector(settings)

Creates an instance of MemoryLruGarbageCollector

A target size can be specified as part of the setting parameter. The collector will start deleting documents once the cache size exceeds the given size. The default cache size is 40MB (40 * 1024 * 1024 bytes).

簽名:

export declare function memoryLruGarbageCollector(settings?: {
    cacheSizeBytes?: number;
}): MemoryLruGarbageCollector;

參數

範圍類型描述
設定{ cacheSizeBytes?: number; }

返回:

記憶體Lru垃圾收集器

persistentLocalCache(settings)

Creates an instance of PersistentLocalCache 。 The instance can be set to FirestoreSettings.cache to tell the SDK which cache layer to use.

Persistent cache cannot be used in a Node.js environment.

簽名:

export declare function persistentLocalCache(settings?: PersistentCacheSettings): PersistentLocalCache;

參數

範圍類型描述
設定PersistentCacheSettings

返回:

持久性本地快取

persistentSingleTabManager(settings)

Creates an instance of PersistentSingleTabManager

簽名:

export declare function persistentSingleTabManager(settings: PersistentSingleTabManagerSettings | undefined): PersistentSingleTabManager;

參數

範圍類型描述
設定PersistentSingleTabManagerSettings |不明確的Configures the created tab manager.

返回:

PersistentSingleTabManager

function(snapshot, ...)

endAt(snapshot)

Creates a QueryEndAtConstraint that modifies the result set to end 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 the query.

簽名:

export declare function endAt<AppModelType, DbModelType extends DocumentData>(snapshot: DocumentSnapshot<AppModelType, DbModelType>): QueryEndAtConstraint;

參數

範圍類型描述
快照文件快照<AppModelType, DbModelType> The snapshot of the document to end at.

返回:

查詢結束約束

A QueryEndAtConstraint to pass to query()

endBefore(snapshot)

Creates a QueryEndAtConstraint that modifies the result set to end 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 the query.

簽名:

export declare function endBefore<AppModelType, DbModelType extends DocumentData>(snapshot: DocumentSnapshot<AppModelType, DbModelType>): QueryEndAtConstraint;

參數

範圍類型描述
快照文件快照<AppModelType, DbModelType> The snapshot of the document to end before.

返回:

查詢結束約束

A QueryEndAtConstraint to pass to query()

startAfter(snapshot)

Creates a QueryStartAtConstraint that modifies the result set to start 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 the query.

簽名:

export declare function startAfter<AppModelType, DbModelType extends DocumentData>(snapshot: DocumentSnapshot<AppModelType, DbModelType>): QueryStartAtConstraint;

參數

範圍類型描述
快照文件快照<AppModelType, DbModelType> The snapshot of the document to start after.

返回:

查詢開始約束

A QueryStartAtConstraint to pass to query()

startAt(snapshot)

Creates a QueryStartAtConstraint that modifies the result set to start 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.

簽名:

export declare function startAt<AppModelType, DbModelType extends DocumentData>(snapshot: DocumentSnapshot<AppModelType, DbModelType>): QueryStartAtConstraint;

參數

範圍類型描述
快照文件快照<AppModelType, DbModelType> The snapshot of the document to start at.

返回:

查詢開始約束

A QueryStartAtConstraint to pass to query()

CACHE_SIZE_UNLIMITED

Constant used to indicate the LRU garbage collection should be disabled. Set this value as the cacheSizeBytes on the settings passed to the Firestore instance.

簽名:

CACHE_SIZE_UNLIMITED = -1

AddPrefixToKeys

Returns a new map where every key is prefixed with the outer key appended to a dot.

簽名:

export declare type AddPrefixToKeys<Prefix extends string, T extends Record<string, unknown>> = {
    [K in keyof T & string as `${Prefix}.${K}`]+?: string extends K ? any : T[K];
};

AggregateFieldType

The union of all AggregateField types that are supported by Firestore.

簽名:

export declare type AggregateFieldType = ReturnType<typeof sum> | ReturnType<typeof average> | ReturnType<typeof count>;

AggregateSpecData

A type whose keys are taken from an AggregateSpec , and whose values are the result of the aggregation performed by the corresponding AggregateField from the input AggregateSpec

簽名:

export declare type AggregateSpecData<T extends AggregateSpec> = {
    [P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
};

AggregateType

Union type representing the aggregate type to be performed.

簽名:

export declare type AggregateType = 'count' | 'avg' | 'sum';

ChildUpdateFields

Helper for calculating the nested fields for a given type T1. This is needed to distribute union types such as undefined | {...} (happens for optional props) or {a: A} | {b: B}

In this use case, V is used to distribute the union types of T[K] on Record , since T[K] is evaluated as an expression and not distributed.

See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types

簽名:

export declare type ChildUpdateFields<K extends string, V> = V extends Record<string, unknown> ? AddPrefixToKeys<K, UpdateData<V>> : never;

DocumentChangeType

The type of a DocumentChange may be 'added', 'removed', or 'modified'.

簽名:

export declare type DocumentChangeType = 'added' | 'removed' | 'modified';

FirestoreErrorCode

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 (eg 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 declare 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';

FirestoreLocalCache

Union type from all supported SDK cache layer.

簽名:

export declare type FirestoreLocalCache = MemoryLocalCache | PersistentLocalCache;

ListenSource

Describe the source a query listens to.

Set to default to listen to both cache and server changes. Set to cache to listen to changes in cache only.

簽名:

export declare type ListenSource = 'default' | 'cache';

MemoryGarbageCollector

Union type from all support gabage collectors for memory local cache.

簽名:

export declare type MemoryGarbageCollector = MemoryEagerGarbageCollector | MemoryLruGarbageCollector;

NestedUpdateFields

For each field (eg 'bar'), find all nested keys (eg { 'bar.baz': T1, 'bar.qux': T2 } )。 Intersect them together to make a single map containing all possible keys that are all marked as optional

簽名:

export declare type NestedUpdateFields<T extends Record<string, unknown>> = UnionToIntersection<{
    [K in keyof T & string]: ChildUpdateFields<K, T[K]>;
}[keyof T & string]>;

OrderByDirection

The direction of a orderBy() clause is specified as 'desc' or 'asc' (descending or ascending).

簽名:

export declare type OrderByDirection = 'desc' | 'asc';

PartialWithFieldValue

Similar to Typescript's Partial<T> , but allows nested fields to be omitted and FieldValues to be passed in as property values.

簽名:

export declare type PartialWithFieldValue<T> = Partial<T> | (T extends Primitive ? T : T extends {} ? {
    [K in keyof T]?: PartialWithFieldValue<T[K]> | FieldValue;
} : never);

PersistentTabManager

A union of all available tab managers.

簽名:

export declare type PersistentTabManager = PersistentSingleTabManager | PersistentMultipleTabManager;

原始

Primitive types.

簽名:

export declare type Primitive = string | number | boolean | undefined | null;

QueryConstraintType

Describes the different query constraints available in this SDK.

簽名:

export declare type QueryConstraintType = 'where' | 'orderBy' | 'limit' | 'limitToLast' | 'startAt' | 'startAfter' | 'endAt' | 'endBefore';

QueryFilterConstraint

QueryFilterConstraint is a helper union type that represents QueryFieldFilterConstraint and QueryCompositeFilterConstraint

簽名:

export declare type QueryFilterConstraint = QueryFieldFilterConstraint | QueryCompositeFilterConstraint;

QueryNonFilterConstraint

QueryNonFilterConstraint is a helper union type that represents QueryConstraints which are used to narrow or order the set of documents, but that do not explicitly filter on a document field. QueryNonFilterConstraint s are created by invoking orderBy() , startAt() , startAfter() , endBefore() , endAt() , limit() or limitToLast() and can then be passed to query() to create a new query instance that also contains the QueryConstraint

簽名:

export declare type QueryNonFilterConstraint = QueryOrderByConstraint | QueryLimitConstraint | QueryStartAtConstraint | QueryEndAtConstraint;

SetOptions

An options object that configures the behavior of setDoc() , and calls. 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 declare type SetOptions = {
    readonly merge?: boolean;
} | {
    readonly mergeFields?: Array<string | FieldPath>;
};

TaskState

Represents the state of bundle loading tasks.

Both 'Error' and 'Success' are sinking state: task will abort or complete and there will be no more updates after they are reported.

簽名:

export declare type TaskState = 'Error' | 'Running' | 'Success';

UnionToIntersection

Given a union type U = T1 | T2 | ... , returns an intersected type (T1 & T2 & ...)

Uses distributive conditional types and inference from conditional types. This works because multiple candidates for the same type variable in contra-variant positions causes an intersection type to be inferred. https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-in​​ference-in-conditional-types https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection -類型

簽名:

export declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

UpdateData

Update data (for use with updateDoc() ) that consists of field paths (eg 'foo' or 'foo.baz') mapped to values. Fields that contain dots reference nested fields within the document. FieldValues can be passed in as property values.

簽名:

export declare type UpdateData<T> = T extends Primitive ? T : T extends {} ? {
    [K in keyof T]?: UpdateData<T[K]> | FieldValue;
} & NestedUpdateFields<T> : Partial<T>;

WhereFilterOp

Filter conditions in a where() clause are specified using the strings '&lt;', '&lt;=', '==', '!=', '&gt;=', '&gt;', 'array-contains', 'in', 'array-contains-any', and 'not-in'.

簽名:

export declare type WhereFilterOp = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any' | 'not-in';

WithFieldValue

Allows FieldValues to be passed in as a property value while maintaining type safety.

簽名:

export declare type WithFieldValue<T> = T | (T extends Primitive ? T : T extends {} ? {
    [K in keyof T]: WithFieldValue<T[K]> | FieldValue;
} : never);