index.d.ts 115 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649
  1. /**
  2. * Cloud Firestore
  3. *
  4. * @packageDocumentation
  5. */
  6. import { FirebaseApp } from '@firebase/app';
  7. import { LogLevelString as LogLevel } from '@firebase/logger';
  8. import { EmulatorMockTokenOptions } from '@firebase/util';
  9. import { FirebaseError } from '@firebase/util';
  10. /**
  11. * Add a new document to specified `CollectionReference` with the given data,
  12. * assigning it a document ID automatically.
  13. *
  14. * @param reference - A reference to the collection to add this document to.
  15. * @param data - An Object containing the data for the new document.
  16. * @returns A `Promise` resolved with a `DocumentReference` pointing to the
  17. * newly created document after it has been written to the backend (Note that it
  18. * won't resolve while you're offline).
  19. */
  20. export declare function addDoc<T>(reference: CollectionReference<T>, data: WithFieldValue<T>): Promise<DocumentReference<T>>;
  21. /**
  22. * Returns a new map where every key is prefixed with the outer key appended
  23. * to a dot.
  24. */
  25. export declare type AddPrefixToKeys<Prefix extends string, T extends Record<string, unknown>> = {
  26. [K in keyof T & string as `${Prefix}.${K}`]+?: T[K];
  27. };
  28. /**
  29. * Represents an aggregation that can be performed by Firestore.
  30. */
  31. export declare class AggregateField<T> {
  32. /** A type string to uniquely identify instances of this class. */
  33. readonly type = "AggregateField";
  34. }
  35. /* Excluded from this release type: aggregateFieldEqual */
  36. /**
  37. * The union of all `AggregateField` types that are supported by Firestore.
  38. */
  39. export declare type AggregateFieldType = AggregateField<number | null>;
  40. /**
  41. * The results of executing an aggregation query.
  42. */
  43. export declare class AggregateQuerySnapshot<T extends AggregateSpec> {
  44. /** A type string to uniquely identify instances of this class. */
  45. readonly type = "AggregateQuerySnapshot";
  46. /**
  47. * The underlying query over which the aggregations recorded in this
  48. * `AggregateQuerySnapshot` were performed.
  49. */
  50. readonly query: Query<unknown>;
  51. private constructor();
  52. /**
  53. * Returns the results of the aggregations performed over the underlying
  54. * query.
  55. *
  56. * The keys of the returned object will be the same as those of the
  57. * `AggregateSpec` object specified to the aggregation method, and the values
  58. * will be the corresponding aggregation result.
  59. *
  60. * @returns The results of the aggregations performed over the underlying
  61. * query.
  62. */
  63. data(): AggregateSpecData<T>;
  64. }
  65. /**
  66. * Compares two `AggregateQuerySnapshot` instances for equality.
  67. *
  68. * Two `AggregateQuerySnapshot` instances are considered "equal" if they have
  69. * underlying queries that compare equal, and the same data.
  70. *
  71. * @param left - The first `AggregateQuerySnapshot` to compare.
  72. * @param right - The second `AggregateQuerySnapshot` to compare.
  73. *
  74. * @returns `true` if the objects are "equal", as defined above, or `false`
  75. * otherwise.
  76. */
  77. export declare function aggregateQuerySnapshotEqual<T extends AggregateSpec>(left: AggregateQuerySnapshot<T>, right: AggregateQuerySnapshot<T>): boolean;
  78. /**
  79. * Specifies a set of aggregations and their aliases.
  80. */
  81. export declare interface AggregateSpec {
  82. [field: string]: AggregateFieldType;
  83. }
  84. /**
  85. * A type whose keys are taken from an `AggregateSpec`, and whose values are the
  86. * result of the aggregation performed by the corresponding `AggregateField`
  87. * from the input `AggregateSpec`.
  88. */
  89. export declare type AggregateSpecData<T extends AggregateSpec> = {
  90. [P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
  91. };
  92. /* Excluded from this release type: AggregateType */
  93. /**
  94. * Creates a new {@link QueryCompositeFilterConstraint} that is a conjunction of
  95. * the given filter constraints. A conjunction filter includes a document if it
  96. * satisfies all of the given filters.
  97. *
  98. * @param queryConstraints - Optional. The list of
  99. * {@link QueryFilterConstraint}s to perform a conjunction for. These must be
  100. * created with calls to {@link where}, {@link or}, or {@link and}.
  101. * @returns The newly created {@link QueryCompositeFilterConstraint}.
  102. */
  103. export declare function and(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;
  104. /**
  105. * Returns a special value that can be used with {@link (setDoc:1)} or {@link
  106. * updateDoc:1} that tells the server to remove the given elements from any
  107. * array value that already exists on the server. All instances of each element
  108. * specified will be removed from the array. If the field being modified is not
  109. * already an array it will be overwritten with an empty array.
  110. *
  111. * @param elements - The elements to remove from the array.
  112. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  113. * `updateDoc()`
  114. */
  115. export declare function arrayRemove(...elements: unknown[]): FieldValue;
  116. /**
  117. * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link
  118. * @firebase/firestore/lite#(updateDoc:1)} that tells the server to union the given elements with any array
  119. * value that already exists on the server. Each specified element that doesn't
  120. * already exist in the array will be added to the end. If the field being
  121. * modified is not already an array it will be overwritten with an array
  122. * containing exactly the specified elements.
  123. *
  124. * @param elements - The elements to union into the array.
  125. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  126. * `updateDoc()`.
  127. */
  128. export declare function arrayUnion(...elements: unknown[]): FieldValue;
  129. /**
  130. * An immutable object representing an array of bytes.
  131. */
  132. export declare class Bytes {
  133. private constructor();
  134. /**
  135. * Creates a new `Bytes` object from the given Base64 string, converting it to
  136. * bytes.
  137. *
  138. * @param base64 - The Base64 string used to create the `Bytes` object.
  139. */
  140. static fromBase64String(base64: string): Bytes;
  141. /**
  142. * Creates a new `Bytes` object from the given Uint8Array.
  143. *
  144. * @param array - The Uint8Array used to create the `Bytes` object.
  145. */
  146. static fromUint8Array(array: Uint8Array): Bytes;
  147. /**
  148. * Returns the underlying bytes as a Base64-encoded string.
  149. *
  150. * @returns The Base64-encoded string created from the `Bytes` object.
  151. */
  152. toBase64(): string;
  153. /**
  154. * Returns the underlying bytes in a new `Uint8Array`.
  155. *
  156. * @returns The Uint8Array created from the `Bytes` object.
  157. */
  158. toUint8Array(): Uint8Array;
  159. /**
  160. * Returns a string representation of the `Bytes` object.
  161. *
  162. * @returns A string representation of the `Bytes` object.
  163. */
  164. toString(): string;
  165. /**
  166. * Returns true if this `Bytes` object is equal to the provided one.
  167. *
  168. * @param other - The `Bytes` object to compare against.
  169. * @returns true if this `Bytes` object is equal to the provided one.
  170. */
  171. isEqual(other: Bytes): boolean;
  172. }
  173. /* Excluded from this release type: _ByteString */
  174. /**
  175. * Constant used to indicate the LRU garbage collection should be disabled.
  176. * Set this value as the `cacheSizeBytes` on the settings passed to the
  177. * {@link Firestore} instance.
  178. */
  179. export declare const CACHE_SIZE_UNLIMITED = -1;
  180. /**
  181. * Helper for calculating the nested fields for a given type T1. This is needed
  182. * to distribute union types such as `undefined | {...}` (happens for optional
  183. * props) or `{a: A} | {b: B}`.
  184. *
  185. * In this use case, `V` is used to distribute the union types of `T[K]` on
  186. * `Record`, since `T[K]` is evaluated as an expression and not distributed.
  187. *
  188. * See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types
  189. */
  190. export declare type ChildUpdateFields<K extends string, V> = V extends Record<string, unknown> ? AddPrefixToKeys<K, UpdateData<V>> : never;
  191. /**
  192. * Clears the persistent storage. This includes pending writes and cached
  193. * documents.
  194. *
  195. * Must be called while the {@link Firestore} instance is not started (after the app is
  196. * terminated or when the app is first initialized). On startup, this function
  197. * must be called before other functions (other than {@link
  198. * initializeFirestore} or {@link (getFirestore:1)})). If the {@link Firestore}
  199. * instance is still running, the promise will be rejected with the error code
  200. * of `failed-precondition`.
  201. *
  202. * Note: `clearIndexedDbPersistence()` is primarily intended to help write
  203. * reliable tests that use Cloud Firestore. It uses an efficient mechanism for
  204. * dropping existing data but does not attempt to securely overwrite or
  205. * otherwise make cached data unrecoverable. For applications that are sensitive
  206. * to the disclosure of cached data in between user sessions, we strongly
  207. * recommend not enabling persistence at all.
  208. *
  209. * @param firestore - The {@link Firestore} instance to clear persistence for.
  210. * @returns A `Promise` that is resolved when the persistent storage is
  211. * cleared. Otherwise, the promise is rejected with an error.
  212. */
  213. export declare function clearIndexedDbPersistence(firestore: Firestore): Promise<void>;
  214. /**
  215. * Gets a `CollectionReference` instance that refers to the collection at
  216. * the specified absolute path.
  217. *
  218. * @param firestore - A reference to the root `Firestore` instance.
  219. * @param path - A slash-separated path to a collection.
  220. * @param pathSegments - Additional path segments to apply relative to the first
  221. * argument.
  222. * @throws If the final path has an even number of segments and does not point
  223. * to a collection.
  224. * @returns The `CollectionReference` instance.
  225. */
  226. export declare function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
  227. /**
  228. * Gets a `CollectionReference` instance that refers to a subcollection of
  229. * `reference` at the the specified relative path.
  230. *
  231. * @param reference - A reference to a collection.
  232. * @param path - A slash-separated path to a collection.
  233. * @param pathSegments - Additional path segments to apply relative to the first
  234. * argument.
  235. * @throws If the final path has an even number of segments and does not point
  236. * to a collection.
  237. * @returns The `CollectionReference` instance.
  238. */
  239. export declare function collection(reference: CollectionReference<unknown>, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
  240. /**
  241. * Gets a `CollectionReference` instance that refers to a subcollection of
  242. * `reference` at the the specified relative path.
  243. *
  244. * @param reference - A reference to a Firestore document.
  245. * @param path - A slash-separated path to a collection.
  246. * @param pathSegments - Additional path segments that will be applied relative
  247. * to the first argument.
  248. * @throws If the final path has an even number of segments and does not point
  249. * to a collection.
  250. * @returns The `CollectionReference` instance.
  251. */
  252. export declare function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
  253. /**
  254. * Creates and returns a new `Query` instance that includes all documents in the
  255. * database that are contained in a collection or subcollection with the
  256. * given `collectionId`.
  257. *
  258. * @param firestore - A reference to the root `Firestore` instance.
  259. * @param collectionId - Identifies the collections to query over. Every
  260. * collection or subcollection with this ID as the last segment of its path
  261. * will be included. Cannot contain a slash.
  262. * @returns The created `Query`.
  263. */
  264. export declare function collectionGroup(firestore: Firestore, collectionId: string): Query<DocumentData>;
  265. /**
  266. * A `CollectionReference` object can be used for adding documents, getting
  267. * document references, and querying for documents (using {@link (query:1)}).
  268. */
  269. export declare class CollectionReference<T = DocumentData> extends Query<T> {
  270. /** The type of this Firestore reference. */
  271. readonly type = "collection";
  272. private constructor();
  273. /** The collection's identifier. */
  274. get id(): string;
  275. /**
  276. * A string representing the path of the referenced collection (relative
  277. * to the root of the database).
  278. */
  279. get path(): string;
  280. /**
  281. * A reference to the containing `DocumentReference` if this is a
  282. * subcollection. If this isn't a subcollection, the reference is null.
  283. */
  284. get parent(): DocumentReference<DocumentData> | null;
  285. /**
  286. * Applies a custom data converter to this `CollectionReference`, allowing you
  287. * to use your own custom model objects with Firestore. When you call {@link
  288. * addDoc} with the returned `CollectionReference` instance, the provided
  289. * converter will convert between Firestore data and your custom type `U`.
  290. *
  291. * @param converter - Converts objects to and from Firestore.
  292. * @returns A `CollectionReference<U>` that uses the provided converter.
  293. */
  294. withConverter<U>(converter: FirestoreDataConverter<U>): CollectionReference<U>;
  295. /**
  296. * Removes the current converter.
  297. *
  298. * @param converter - `null` removes the current converter.
  299. * @returns A `CollectionReference<DocumentData>` that does not use a
  300. * converter.
  301. */
  302. withConverter(converter: null): CollectionReference<DocumentData>;
  303. }
  304. /**
  305. * Modify this instance to communicate with the Cloud Firestore emulator.
  306. *
  307. * Note: This must be called before this instance has been used to do any
  308. * operations.
  309. *
  310. * @param firestore - The `Firestore` instance to configure to connect to the
  311. * emulator.
  312. * @param host - the emulator host (ex: localhost).
  313. * @param port - the emulator port (ex: 9000).
  314. * @param options.mockUserToken - the mock auth token to use for unit testing
  315. * Security Rules.
  316. */
  317. export declare function connectFirestoreEmulator(firestore: Firestore, host: string, port: number, options?: {
  318. mockUserToken?: EmulatorMockTokenOptions | string;
  319. }): void;
  320. /**
  321. * Deletes the document referred to by the specified `DocumentReference`.
  322. *
  323. * @param reference - A reference to the document to delete.
  324. * @returns A Promise resolved once the document has been successfully
  325. * deleted from the backend (note that it won't resolve while you're offline).
  326. */
  327. export declare function deleteDoc(reference: DocumentReference<unknown>): Promise<void>;
  328. /**
  329. * Returns a sentinel for use with {@link @firebase/firestore/lite#(updateDoc:1)} or
  330. * {@link @firebase/firestore/lite#(setDoc:1)} with `{merge: true}` to mark a field for deletion.
  331. */
  332. export declare function deleteField(): FieldValue;
  333. /**
  334. * Disables network usage for this instance. It can be re-enabled via {@link
  335. * enableNetwork}. While the network is disabled, any snapshot listeners,
  336. * `getDoc()` or `getDocs()` calls will return results from cache, and any write
  337. * operations will be queued until the network is restored.
  338. *
  339. * @returns A `Promise` that is resolved once the network has been disabled.
  340. */
  341. export declare function disableNetwork(firestore: Firestore): Promise<void>;
  342. /**
  343. * Gets a `DocumentReference` instance that refers to the document at the
  344. * specified absolute path.
  345. *
  346. * @param firestore - A reference to the root `Firestore` instance.
  347. * @param path - A slash-separated path to a document.
  348. * @param pathSegments - Additional path segments that will be applied relative
  349. * to the first argument.
  350. * @throws If the final path has an odd number of segments and does not point to
  351. * a document.
  352. * @returns The `DocumentReference` instance.
  353. */
  354. export declare function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>;
  355. /**
  356. * Gets a `DocumentReference` instance that refers to a document within
  357. * `reference` at the specified relative path. If no path is specified, an
  358. * automatically-generated unique ID will be used for the returned
  359. * `DocumentReference`.
  360. *
  361. * @param reference - A reference to a collection.
  362. * @param path - A slash-separated path to a document. Has to be omitted to use
  363. * auto-genrated IDs.
  364. * @param pathSegments - Additional path segments that will be applied relative
  365. * to the first argument.
  366. * @throws If the final path has an odd number of segments and does not point to
  367. * a document.
  368. * @returns The `DocumentReference` instance.
  369. */
  370. export declare function doc<T>(reference: CollectionReference<T>, path?: string, ...pathSegments: string[]): DocumentReference<T>;
  371. /**
  372. * Gets a `DocumentReference` instance that refers to a document within
  373. * `reference` at the specified relative path.
  374. *
  375. * @param reference - A reference to a Firestore document.
  376. * @param path - A slash-separated path to a document.
  377. * @param pathSegments - Additional path segments that will be applied relative
  378. * to the first argument.
  379. * @throws If the final path has an odd number of segments and does not point to
  380. * a document.
  381. * @returns The `DocumentReference` instance.
  382. */
  383. export declare function doc(reference: DocumentReference<unknown>, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>;
  384. /**
  385. * A `DocumentChange` represents a change to the documents matching a query.
  386. * It contains the document affected and the type of change that occurred.
  387. */
  388. export declare interface DocumentChange<T = DocumentData> {
  389. /** The type of change ('added', 'modified', or 'removed'). */
  390. readonly type: DocumentChangeType;
  391. /** The document affected by this change. */
  392. readonly doc: QueryDocumentSnapshot<T>;
  393. /**
  394. * The index of the changed document in the result set immediately prior to
  395. * this `DocumentChange` (i.e. supposing that all prior `DocumentChange` objects
  396. * have been applied). Is `-1` for 'added' events.
  397. */
  398. readonly oldIndex: number;
  399. /**
  400. * The index of the changed document in the result set immediately after
  401. * this `DocumentChange` (i.e. supposing that all prior `DocumentChange`
  402. * objects and the current `DocumentChange` object have been applied).
  403. * Is -1 for 'removed' events.
  404. */
  405. readonly newIndex: number;
  406. }
  407. /**
  408. * The type of a `DocumentChange` may be 'added', 'removed', or 'modified'.
  409. */
  410. export declare type DocumentChangeType = 'added' | 'removed' | 'modified';
  411. /**
  412. * Document data (for use with {@link @firebase/firestore/lite#(setDoc:1)}) consists of fields mapped to
  413. * values.
  414. */
  415. export declare interface DocumentData {
  416. /** A mapping between a field and its value. */
  417. [field: string]: any;
  418. }
  419. /**
  420. * Returns a special sentinel `FieldPath` to refer to the ID of a document.
  421. * It can be used in queries to sort or filter by the document ID.
  422. */
  423. export declare function documentId(): FieldPath;
  424. /**
  425. * A `DocumentReference` refers to a document location in a Firestore database
  426. * and can be used to write, read, or listen to the location. The document at
  427. * the referenced location may or may not exist.
  428. */
  429. export declare class DocumentReference<T = DocumentData> {
  430. /**
  431. * If provided, the `FirestoreDataConverter` associated with this instance.
  432. */
  433. readonly converter: FirestoreDataConverter<T> | null;
  434. /** The type of this Firestore reference. */
  435. readonly type = "document";
  436. /**
  437. * The {@link Firestore} instance the document is in.
  438. * This is useful for performing transactions, for example.
  439. */
  440. readonly firestore: Firestore;
  441. private constructor();
  442. /**
  443. * The document's identifier within its collection.
  444. */
  445. get id(): string;
  446. /**
  447. * A string representing the path of the referenced document (relative
  448. * to the root of the database).
  449. */
  450. get path(): string;
  451. /**
  452. * The collection this `DocumentReference` belongs to.
  453. */
  454. get parent(): CollectionReference<T>;
  455. /**
  456. * Applies a custom data converter to this `DocumentReference`, allowing you
  457. * to use your own custom model objects with Firestore. When you call {@link
  458. * @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#getDoc}, etc. with the returned `DocumentReference`
  459. * instance, the provided converter will convert between Firestore data and
  460. * your custom type `U`.
  461. *
  462. * @param converter - Converts objects to and from Firestore.
  463. * @returns A `DocumentReference<U>` that uses the provided converter.
  464. */
  465. withConverter<U>(converter: FirestoreDataConverter<U>): DocumentReference<U>;
  466. /**
  467. * Removes the current converter.
  468. *
  469. * @param converter - `null` removes the current converter.
  470. * @returns A `DocumentReference<DocumentData>` that does not use a converter.
  471. */
  472. withConverter(converter: null): DocumentReference<DocumentData>;
  473. }
  474. /**
  475. * A `DocumentSnapshot` contains data read from a document in your Firestore
  476. * database. The data can be extracted with `.data()` or `.get(<field>)` to
  477. * get a specific field.
  478. *
  479. * For a `DocumentSnapshot` that points to a non-existing document, any data
  480. * access will return 'undefined'. You can use the `exists()` method to
  481. * explicitly verify a document's existence.
  482. */
  483. export declare class DocumentSnapshot<T = DocumentData> {
  484. /**
  485. * Metadata about the `DocumentSnapshot`, including information about its
  486. * source and local modifications.
  487. */
  488. readonly metadata: SnapshotMetadata;
  489. protected constructor();
  490. /**
  491. * Returns whether or not the data exists. True if the document exists.
  492. */
  493. exists(): this is QueryDocumentSnapshot<T>;
  494. /**
  495. * Retrieves all fields in the document as an `Object`. Returns `undefined` if
  496. * the document doesn't exist.
  497. *
  498. * By default, `serverTimestamp()` values that have not yet been
  499. * set to their final value will be returned as `null`. You can override
  500. * this by passing an options object.
  501. *
  502. * @param options - An options object to configure how data is retrieved from
  503. * the snapshot (for example the desired behavior for server timestamps that
  504. * have not yet been set to their final value).
  505. * @returns An `Object` containing all fields in the document or `undefined` if
  506. * the document doesn't exist.
  507. */
  508. data(options?: SnapshotOptions): T | undefined;
  509. /**
  510. * Retrieves the field specified by `fieldPath`. Returns `undefined` if the
  511. * document or field doesn't exist.
  512. *
  513. * By default, a `serverTimestamp()` that has not yet been set to
  514. * its final value will be returned as `null`. You can override this by
  515. * passing an options object.
  516. *
  517. * @param fieldPath - The path (for example 'foo' or 'foo.bar') to a specific
  518. * field.
  519. * @param options - An options object to configure how the field is retrieved
  520. * from the snapshot (for example the desired behavior for server timestamps
  521. * that have not yet been set to their final value).
  522. * @returns The data at the specified field location or undefined if no such
  523. * field exists in the document.
  524. */
  525. get(fieldPath: string | FieldPath, options?: SnapshotOptions): any;
  526. /**
  527. * Property of the `DocumentSnapshot` that provides the document's ID.
  528. */
  529. get id(): string;
  530. /**
  531. * The `DocumentReference` for the document included in the `DocumentSnapshot`.
  532. */
  533. get ref(): DocumentReference<T>;
  534. }
  535. /* Excluded from this release type: _EmptyAppCheckTokenProvider */
  536. /* Excluded from this release type: _EmptyAuthCredentialsProvider */
  537. export { EmulatorMockTokenOptions };
  538. /**
  539. * Attempts to enable persistent storage, if possible.
  540. *
  541. * Must be called before any other functions (other than
  542. * {@link initializeFirestore}, {@link (getFirestore:1)} or
  543. * {@link clearIndexedDbPersistence}.
  544. *
  545. * If this fails, `enableIndexedDbPersistence()` will reject the promise it
  546. * returns. Note that even after this failure, the {@link Firestore} instance will
  547. * remain usable, however offline persistence will be disabled.
  548. *
  549. * There are several reasons why this can fail, which can be identified by
  550. * the `code` on the error.
  551. *
  552. * * failed-precondition: The app is already open in another browser tab.
  553. * * unimplemented: The browser is incompatible with the offline
  554. * persistence implementation.
  555. *
  556. * Persistence cannot be used in a Node.js environment.
  557. *
  558. * @param firestore - The {@link Firestore} instance to enable persistence for.
  559. * @param persistenceSettings - Optional settings object to configure
  560. * persistence.
  561. * @returns A `Promise` that represents successfully enabling persistent storage.
  562. * @deprecated This function will be removed in a future major release. Instead, set
  563. * `FirestoreSettings.cache` to an instance of `IndexedDbLocalCache` to
  564. * turn on IndexedDb cache. Calling this function when `FirestoreSettings.cache`
  565. * is already specified will throw an exception.
  566. */
  567. export declare function enableIndexedDbPersistence(firestore: Firestore, persistenceSettings?: PersistenceSettings): Promise<void>;
  568. /**
  569. * Attempts to enable multi-tab persistent storage, if possible. If enabled
  570. * across all tabs, all operations share access to local persistence, including
  571. * shared execution of queries and latency-compensated local document updates
  572. * across all connected instances.
  573. *
  574. * If this fails, `enableMultiTabIndexedDbPersistence()` will reject the promise
  575. * it returns. Note that even after this failure, the {@link Firestore} instance will
  576. * remain usable, however offline persistence will be disabled.
  577. *
  578. * There are several reasons why this can fail, which can be identified by
  579. * the `code` on the error.
  580. *
  581. * * failed-precondition: The app is already open in another browser tab and
  582. * multi-tab is not enabled.
  583. * * unimplemented: The browser is incompatible with the offline
  584. * persistence implementation.
  585. *
  586. * @param firestore - The {@link Firestore} instance to enable persistence for.
  587. * @returns A `Promise` that represents successfully enabling persistent
  588. * storage.
  589. * @deprecated This function will be removed in a future major release. Instead, set
  590. * `FirestoreSettings.cache` to an instance of `IndexedDbLocalCache` to
  591. * turn on indexeddb cache. Calling this function when `FirestoreSettings.cache`
  592. * is already specified will throw an exception.
  593. */
  594. export declare function enableMultiTabIndexedDbPersistence(firestore: Firestore): Promise<void>;
  595. /**
  596. * Re-enables use of the network for this {@link Firestore} instance after a prior
  597. * call to {@link disableNetwork}.
  598. *
  599. * @returns A `Promise` that is resolved once the network has been enabled.
  600. */
  601. export declare function enableNetwork(firestore: Firestore): Promise<void>;
  602. /**
  603. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end at
  604. * the provided document (inclusive). The end position is relative to the order
  605. * of the query. The document must contain all of the fields provided in the
  606. * orderBy of the query.
  607. *
  608. * @param snapshot - The snapshot of the document to end at.
  609. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  610. */
  611. export declare function endAt(snapshot: DocumentSnapshot<unknown>): QueryEndAtConstraint;
  612. /**
  613. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end at
  614. * the provided fields relative to the order of the query. The order of the field
  615. * values must match the order of the order by clauses of the query.
  616. *
  617. * @param fieldValues - The field values to end this query at, in order
  618. * of the query's order by.
  619. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  620. */
  621. export declare function endAt(...fieldValues: unknown[]): QueryEndAtConstraint;
  622. /**
  623. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end
  624. * before the provided document (exclusive). The end position is relative to the
  625. * order of the query. The document must contain all of the fields provided in
  626. * the orderBy of the query.
  627. *
  628. * @param snapshot - The snapshot of the document to end before.
  629. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  630. */
  631. export declare function endBefore(snapshot: DocumentSnapshot<unknown>): QueryEndAtConstraint;
  632. /**
  633. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end
  634. * before the provided fields relative to the order of the query. The order of
  635. * the field values must match the order of the order by clauses of the query.
  636. *
  637. * @param fieldValues - The field values to end this query before, in order
  638. * of the query's order by.
  639. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  640. */
  641. export declare function endBefore(...fieldValues: unknown[]): QueryEndAtConstraint;
  642. /**
  643. * @license
  644. * Copyright 2023 Google LLC
  645. *
  646. * Licensed under the Apache License, Version 2.0 (the "License");
  647. * you may not use this file except in compliance with the License.
  648. * You may obtain a copy of the License at
  649. *
  650. * http://www.apache.org/licenses/LICENSE-2.0
  651. *
  652. * Unless required by applicable law or agreed to in writing, software
  653. * distributed under the License is distributed on an "AS IS" BASIS,
  654. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  655. * See the License for the specific language governing permissions and
  656. * limitations under the License.
  657. */
  658. /**
  659. * Options that configure the SDK’s underlying network transport (WebChannel)
  660. * when long-polling is used.
  661. *
  662. * Note: This interface is "experimental" and is subject to change.
  663. *
  664. * See `FirestoreSettings.experimentalAutoDetectLongPolling`,
  665. * `FirestoreSettings.experimentalForceLongPolling`, and
  666. * `FirestoreSettings.experimentalLongPollingOptions`.
  667. */
  668. export declare interface ExperimentalLongPollingOptions {
  669. /**
  670. * The desired maximum timeout interval, in seconds, to complete a
  671. * long-polling GET response. Valid values are between 5 and 30, inclusive.
  672. * Floating point values are allowed and will be rounded to the nearest
  673. * millisecond.
  674. *
  675. * By default, when long-polling is used the "hanging GET" request sent by
  676. * the client times out after 30 seconds. To request a different timeout
  677. * from the server, set this setting with the desired timeout.
  678. *
  679. * Changing the default timeout may be useful, for example, if the buffering
  680. * proxy that necessitated enabling long-polling in the first place has a
  681. * shorter timeout for hanging GET requests, in which case setting the
  682. * long-polling timeout to a shorter value, such as 25 seconds, may fix
  683. * prematurely-closed hanging GET requests.
  684. * For example, see https://github.com/firebase/firebase-js-sdk/issues/6987.
  685. */
  686. timeoutSeconds?: number;
  687. }
  688. /**
  689. * A `FieldPath` refers to a field in a document. The path may consist of a
  690. * single field name (referring to a top-level field in the document), or a
  691. * list of field names (referring to a nested field in the document).
  692. *
  693. * Create a `FieldPath` by providing field names. If more than one field
  694. * name is provided, the path will point to a nested field in a document.
  695. */
  696. export declare class FieldPath {
  697. /**
  698. * Creates a `FieldPath` from the provided field names. If more than one field
  699. * name is provided, the path will point to a nested field in a document.
  700. *
  701. * @param fieldNames - A list of field names.
  702. */
  703. constructor(...fieldNames: string[]);
  704. /**
  705. * Returns true if this `FieldPath` is equal to the provided one.
  706. *
  707. * @param other - The `FieldPath` to compare against.
  708. * @returns true if this `FieldPath` is equal to the provided one.
  709. */
  710. isEqual(other: FieldPath): boolean;
  711. }
  712. /**
  713. * Sentinel values that can be used when writing document fields with `set()`
  714. * or `update()`.
  715. */
  716. export declare abstract class FieldValue {
  717. private constructor();
  718. /** Compares `FieldValue`s for equality. */
  719. abstract isEqual(other: FieldValue): boolean;
  720. }
  721. /* Excluded from this release type: _FirebaseService */
  722. /**
  723. * The Cloud Firestore service interface.
  724. *
  725. * Do not call this constructor directly. Instead, use {@link (getFirestore:1)}.
  726. */
  727. export declare class Firestore {
  728. /**
  729. * Whether it's a {@link Firestore} or Firestore Lite instance.
  730. */
  731. type: 'firestore-lite' | 'firestore';
  732. private constructor();
  733. /**
  734. * The {@link @firebase/app#FirebaseApp} associated with this `Firestore` service
  735. * instance.
  736. */
  737. get app(): FirebaseApp;
  738. /**
  739. * Returns a JSON-serializable representation of this `Firestore` instance.
  740. */
  741. toJSON(): object;
  742. }
  743. /**
  744. * Converter used by `withConverter()` to transform user objects of type `T`
  745. * into Firestore data.
  746. *
  747. * Using the converter allows you to specify generic type arguments when
  748. * storing and retrieving objects from Firestore.
  749. *
  750. * @example
  751. * ```typescript
  752. * class Post {
  753. * constructor(readonly title: string, readonly author: string) {}
  754. *
  755. * toString(): string {
  756. * return this.title + ', by ' + this.author;
  757. * }
  758. * }
  759. *
  760. * const postConverter = {
  761. * toFirestore(post: WithFieldValue<Post>): DocumentData {
  762. * return {title: post.title, author: post.author};
  763. * },
  764. * fromFirestore(
  765. * snapshot: QueryDocumentSnapshot,
  766. * options: SnapshotOptions
  767. * ): Post {
  768. * const data = snapshot.data(options)!;
  769. * return new Post(data.title, data.author);
  770. * }
  771. * };
  772. *
  773. * const postSnap = await firebase.firestore()
  774. * .collection('posts')
  775. * .withConverter(postConverter)
  776. * .doc().get();
  777. * const post = postSnap.data();
  778. * if (post !== undefined) {
  779. * post.title; // string
  780. * post.toString(); // Should be defined
  781. * post.someNonExistentProperty; // TS error
  782. * }
  783. * ```
  784. */
  785. export declare interface FirestoreDataConverter<T> {
  786. /**
  787. * Called by the Firestore SDK to convert a custom model object of type `T`
  788. * into a plain JavaScript object (suitable for writing directly to the
  789. * Firestore database). To use `set()` with `merge` and `mergeFields`,
  790. * `toFirestore()` must be defined with `PartialWithFieldValue<T>`.
  791. *
  792. * The `WithFieldValue<T>` type extends `T` to also allow FieldValues such as
  793. * {@link (deleteField:1)} to be used as property values.
  794. */
  795. toFirestore(modelObject: WithFieldValue<T>): DocumentData;
  796. /**
  797. * Called by the Firestore SDK to convert a custom model object of type `T`
  798. * into a plain JavaScript object (suitable for writing directly to the
  799. * Firestore database). Used with {@link (setDoc:1)}, {@link (WriteBatch.set:1)}
  800. * and {@link (Transaction.set:1)} with `merge:true` or `mergeFields`.
  801. *
  802. * The `PartialWithFieldValue<T>` type extends `Partial<T>` to allow
  803. * FieldValues such as {@link (arrayUnion:1)} to be used as property values.
  804. * It also supports nested `Partial` by allowing nested fields to be
  805. * omitted.
  806. */
  807. toFirestore(modelObject: PartialWithFieldValue<T>, options: SetOptions): DocumentData;
  808. /**
  809. * Called by the Firestore SDK to convert Firestore data into an object of
  810. * type T. You can access your data by calling: `snapshot.data(options)`.
  811. *
  812. * @param snapshot - A `QueryDocumentSnapshot` containing your data and metadata.
  813. * @param options - The `SnapshotOptions` from the initial call to `data()`.
  814. */
  815. fromFirestore(snapshot: QueryDocumentSnapshot<DocumentData>, options?: SnapshotOptions): T;
  816. }
  817. /** An error returned by a Firestore operation. */
  818. export declare class FirestoreError extends FirebaseError {
  819. /**
  820. * The backend error code associated with this error.
  821. */
  822. readonly code: FirestoreErrorCode;
  823. /**
  824. * A custom error description.
  825. */
  826. readonly message: string;
  827. /** The stack of the error. */
  828. readonly stack?: string;
  829. private constructor();
  830. }
  831. /**
  832. * The set of Firestore status codes. The codes are the same at the ones
  833. * exposed by gRPC here:
  834. * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
  835. *
  836. * Possible values:
  837. * - 'cancelled': The operation was cancelled (typically by the caller).
  838. * - 'unknown': Unknown error or an error from a different error domain.
  839. * - 'invalid-argument': Client specified an invalid argument. Note that this
  840. * differs from 'failed-precondition'. 'invalid-argument' indicates
  841. * arguments that are problematic regardless of the state of the system
  842. * (e.g. an invalid field name).
  843. * - 'deadline-exceeded': Deadline expired before operation could complete.
  844. * For operations that change the state of the system, this error may be
  845. * returned even if the operation has completed successfully. For example,
  846. * a successful response from a server could have been delayed long enough
  847. * for the deadline to expire.
  848. * - 'not-found': Some requested document was not found.
  849. * - 'already-exists': Some document that we attempted to create already
  850. * exists.
  851. * - 'permission-denied': The caller does not have permission to execute the
  852. * specified operation.
  853. * - 'resource-exhausted': Some resource has been exhausted, perhaps a
  854. * per-user quota, or perhaps the entire file system is out of space.
  855. * - 'failed-precondition': Operation was rejected because the system is not
  856. * in a state required for the operation's execution.
  857. * - 'aborted': The operation was aborted, typically due to a concurrency
  858. * issue like transaction aborts, etc.
  859. * - 'out-of-range': Operation was attempted past the valid range.
  860. * - 'unimplemented': Operation is not implemented or not supported/enabled.
  861. * - 'internal': Internal errors. Means some invariants expected by
  862. * underlying system has been broken. If you see one of these errors,
  863. * something is very broken.
  864. * - 'unavailable': The service is currently unavailable. This is most likely
  865. * a transient condition and may be corrected by retrying with a backoff.
  866. * - 'data-loss': Unrecoverable data loss or corruption.
  867. * - 'unauthenticated': The request does not have valid authentication
  868. * credentials for the operation.
  869. */
  870. 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';
  871. /**
  872. * Union type from all supported SDK cache layer.
  873. */
  874. export declare type FirestoreLocalCache = MemoryLocalCache | PersistentLocalCache;
  875. /**
  876. * Specifies custom configurations for your Cloud Firestore instance.
  877. * You must set these before invoking any other methods.
  878. */
  879. export declare interface FirestoreSettings {
  880. /**
  881. * NOTE: This field will be deprecated in a future major release. Use `cache` field
  882. * instead to specify cache size, and other cache configurations.
  883. *
  884. * An approximate cache size threshold for the on-disk data. If the cache
  885. * grows beyond this size, Firestore will start removing data that hasn't been
  886. * recently used. The size is not a guarantee that the cache will stay below
  887. * that size, only that if the cache exceeds the given size, cleanup will be
  888. * attempted.
  889. *
  890. * The default value is 40 MB. The threshold must be set to at least 1 MB, and
  891. * can be set to `CACHE_SIZE_UNLIMITED` to disable garbage collection.
  892. */
  893. cacheSizeBytes?: number;
  894. /**
  895. * Specifies the cache used by the SDK. Available options are `MemoryLocalCache`
  896. * and `IndexedDbLocalCache`, each with different configuration options.
  897. *
  898. * When unspecified, `MemoryLocalCache` will be used by default.
  899. *
  900. * NOTE: setting this field and `cacheSizeBytes` at the same time will throw
  901. * exception during SDK initialization. Instead, using the configuration in
  902. * the `FirestoreLocalCache` object to specify the cache size.
  903. */
  904. localCache?: FirestoreLocalCache;
  905. /**
  906. * Forces the SDK’s underlying network transport (WebChannel) to use
  907. * long-polling. Each response from the backend will be closed immediately
  908. * after the backend sends data (by default responses are kept open in
  909. * case the backend has more data to send). This avoids incompatibility
  910. * issues with certain proxies, antivirus software, etc. that incorrectly
  911. * buffer traffic indefinitely. Use of this option will cause some
  912. * performance degradation though.
  913. *
  914. * This setting cannot be used with `experimentalAutoDetectLongPolling` and
  915. * may be removed in a future release. If you find yourself using it to
  916. * work around a specific network reliability issue, please tell us about
  917. * it in https://github.com/firebase/firebase-js-sdk/issues/1674.
  918. *
  919. * This setting cannot be used in a Node.js environment.
  920. */
  921. experimentalForceLongPolling?: boolean;
  922. /**
  923. * Configures the SDK's underlying transport (WebChannel) to automatically
  924. * detect if long-polling should be used. This is very similar to
  925. * `experimentalForceLongPolling`, but only uses long-polling if required.
  926. *
  927. * After having had a default value of `false` since its inception in 2019,
  928. * the default value of this setting was changed in May 2023 to `true` in
  929. * v9.22.0 of the Firebase JavaScript SDK. That is, auto-detection of long
  930. * polling is now enabled by default. To disable it, set this setting to
  931. * `false`, and please open a GitHub issue to share the problems that
  932. * motivated you disabling long-polling auto-detection.
  933. *
  934. * This setting cannot be used in a Node.js environment.
  935. */
  936. experimentalAutoDetectLongPolling?: boolean;
  937. /**
  938. * Options that configure the SDK’s underlying network transport (WebChannel)
  939. * when long-polling is used.
  940. *
  941. * These options are only used if `experimentalForceLongPolling` is true or if
  942. * `experimentalAutoDetectLongPolling` is true and the auto-detection
  943. * determined that long-polling was needed. Otherwise, these options have no
  944. * effect.
  945. */
  946. experimentalLongPollingOptions?: ExperimentalLongPollingOptions;
  947. /**
  948. * The hostname to connect to.
  949. */
  950. host?: string;
  951. /**
  952. * Whether to use SSL when connecting.
  953. */
  954. ssl?: boolean;
  955. /**
  956. * Whether to skip nested properties that are set to `undefined` during
  957. * object serialization. If set to `true`, these properties are skipped
  958. * and not written to Firestore. If set to `false` or omitted, the SDK
  959. * throws an exception when it encounters properties of type `undefined`.
  960. */
  961. ignoreUndefinedProperties?: boolean;
  962. }
  963. /**
  964. * @license
  965. * Copyright 2017 Google LLC
  966. *
  967. * Licensed under the Apache License, Version 2.0 (the "License");
  968. * you may not use this file except in compliance with the License.
  969. * You may obtain a copy of the License at
  970. *
  971. * http://www.apache.org/licenses/LICENSE-2.0
  972. *
  973. * Unless required by applicable law or agreed to in writing, software
  974. * distributed under the License is distributed on an "AS IS" BASIS,
  975. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  976. * See the License for the specific language governing permissions and
  977. * limitations under the License.
  978. */
  979. /**
  980. * An immutable object representing a geographic location in Firestore. The
  981. * location is represented as latitude/longitude pair.
  982. *
  983. * Latitude values are in the range of [-90, 90].
  984. * Longitude values are in the range of [-180, 180].
  985. */
  986. export declare class GeoPoint {
  987. /**
  988. * Creates a new immutable `GeoPoint` object with the provided latitude and
  989. * longitude values.
  990. * @param latitude - The latitude as number between -90 and 90.
  991. * @param longitude - The longitude as number between -180 and 180.
  992. */
  993. constructor(latitude: number, longitude: number);
  994. /**
  995. * The latitude of this `GeoPoint` instance.
  996. */
  997. get latitude(): number;
  998. /**
  999. * The longitude of this `GeoPoint` instance.
  1000. */
  1001. get longitude(): number;
  1002. /**
  1003. * Returns true if this `GeoPoint` is equal to the provided one.
  1004. *
  1005. * @param other - The `GeoPoint` to compare against.
  1006. * @returns true if this `GeoPoint` is equal to the provided one.
  1007. */
  1008. isEqual(other: GeoPoint): boolean;
  1009. /** Returns a JSON-serializable representation of this GeoPoint. */
  1010. toJSON(): {
  1011. latitude: number;
  1012. longitude: number;
  1013. };
  1014. }
  1015. /* Excluded from this release type: getAggregateFromServer */
  1016. /**
  1017. * Calculates the number of documents in the result set of the given query,
  1018. * without actually downloading the documents.
  1019. *
  1020. * Using this function to count the documents is efficient because only the
  1021. * final count, not the documents' data, is downloaded. This function can even
  1022. * count the documents if the result set would be prohibitively large to
  1023. * download entirely (e.g. thousands of documents).
  1024. *
  1025. * The result received from the server is presented, unaltered, without
  1026. * considering any local state. That is, documents in the local cache are not
  1027. * taken into consideration, neither are local modifications not yet
  1028. * synchronized with the server. Previously-downloaded results, if any, are not
  1029. * used: every request using this source necessarily involves a round trip to
  1030. * the server.
  1031. *
  1032. * @param query - The query whose result set size to calculate.
  1033. * @returns A Promise that will be resolved with the count; the count can be
  1034. * retrieved from `snapshot.data().count`, where `snapshot` is the
  1035. * `AggregateQuerySnapshot` to which the returned Promise resolves.
  1036. */
  1037. export declare function getCountFromServer(query: Query<unknown>): Promise<AggregateQuerySnapshot<{
  1038. count: AggregateField<number>;
  1039. }>>;
  1040. /**
  1041. * Reads the document referred to by this `DocumentReference`.
  1042. *
  1043. * Note: `getDoc()` attempts to provide up-to-date data when possible by waiting
  1044. * for data from the server, but it may return cached data or fail if you are
  1045. * offline and the server cannot be reached. To specify this behavior, invoke
  1046. * {@link getDocFromCache} or {@link getDocFromServer}.
  1047. *
  1048. * @param reference - The reference of the document to fetch.
  1049. * @returns A Promise resolved with a `DocumentSnapshot` containing the
  1050. * current document contents.
  1051. */
  1052. export declare function getDoc<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
  1053. /**
  1054. * Reads the document referred to by this `DocumentReference` from cache.
  1055. * Returns an error if the document is not currently cached.
  1056. *
  1057. * @returns A `Promise` resolved with a `DocumentSnapshot` containing the
  1058. * current document contents.
  1059. */
  1060. export declare function getDocFromCache<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
  1061. /**
  1062. * Reads the document referred to by this `DocumentReference` from the server.
  1063. * Returns an error if the network is not available.
  1064. *
  1065. * @returns A `Promise` resolved with a `DocumentSnapshot` containing the
  1066. * current document contents.
  1067. */
  1068. export declare function getDocFromServer<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
  1069. /**
  1070. * Executes the query and returns the results as a `QuerySnapshot`.
  1071. *
  1072. * Note: `getDocs()` attempts to provide up-to-date data when possible by
  1073. * waiting for data from the server, but it may return cached data or fail if
  1074. * you are offline and the server cannot be reached. To specify this behavior,
  1075. * invoke {@link getDocsFromCache} or {@link getDocsFromServer}.
  1076. *
  1077. * @returns A `Promise` that will be resolved with the results of the query.
  1078. */
  1079. export declare function getDocs<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
  1080. /**
  1081. * Executes the query and returns the results as a `QuerySnapshot` from cache.
  1082. * Returns an empty result set if no documents matching the query are currently
  1083. * cached.
  1084. *
  1085. * @returns A `Promise` that will be resolved with the results of the query.
  1086. */
  1087. export declare function getDocsFromCache<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
  1088. /**
  1089. * Executes the query and returns the results as a `QuerySnapshot` from the
  1090. * server. Returns an error if the network is not available.
  1091. *
  1092. * @returns A `Promise` that will be resolved with the results of the query.
  1093. */
  1094. export declare function getDocsFromServer<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
  1095. /**
  1096. * Returns the existing default {@link Firestore} instance that is associated with the
  1097. * provided {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
  1098. * instance with default settings.
  1099. *
  1100. * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned {@link Firestore}
  1101. * instance is associated with.
  1102. * @returns The {@link Firestore} instance of the provided app.
  1103. */
  1104. export declare function getFirestore(app: FirebaseApp): Firestore;
  1105. /**
  1106. * Returns the existing {@link Firestore} instance that is associated with the
  1107. * default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
  1108. * instance with default settings.
  1109. *
  1110. * @param databaseId - The name of the database.
  1111. * @returns The {@link Firestore} instance of the provided app.
  1112. * @beta
  1113. */
  1114. export declare function getFirestore(databaseId: string): Firestore;
  1115. /**
  1116. * Returns the existing default {@link Firestore} instance that is associated with the
  1117. * default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
  1118. * instance with default settings.
  1119. *
  1120. * @returns The {@link Firestore} instance of the provided app.
  1121. */
  1122. export declare function getFirestore(): Firestore;
  1123. /**
  1124. * Returns the existing default {@link Firestore} instance that is associated with the
  1125. * provided {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
  1126. * instance with default settings.
  1127. *
  1128. * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned {@link Firestore}
  1129. * instance is associated with.
  1130. * @param databaseId - The name of the database.
  1131. * @returns The {@link Firestore} instance of the provided app.
  1132. * @beta
  1133. */
  1134. export declare function getFirestore(app: FirebaseApp, databaseId: string): Firestore;
  1135. /**
  1136. * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link
  1137. * @firebase/firestore/lite#(updateDoc:1)} that tells the server to increment the field's current value by
  1138. * the given value.
  1139. *
  1140. * If either the operand or the current field value uses floating point
  1141. * precision, all arithmetic follows IEEE 754 semantics. If both values are
  1142. * integers, values outside of JavaScript's safe number range
  1143. * (`Number.MIN_SAFE_INTEGER` to `Number.MAX_SAFE_INTEGER`) are also subject to
  1144. * precision loss. Furthermore, once processed by the Firestore backend, all
  1145. * integer operations are capped between -2^63 and 2^63-1.
  1146. *
  1147. * If the current field value is not of type `number`, or if the field does not
  1148. * yet exist, the transformation sets the field to the given value.
  1149. *
  1150. * @param n - The value to increment by.
  1151. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  1152. * `updateDoc()`
  1153. */
  1154. export declare function increment(n: number): FieldValue;
  1155. /**
  1156. * The SDK definition of a Firestore index.
  1157. * @beta
  1158. */
  1159. export declare interface Index {
  1160. /** The ID of the collection to index. */
  1161. readonly collectionGroup: string;
  1162. /** A list of fields to index. */
  1163. readonly fields?: IndexField[];
  1164. [key: string]: unknown;
  1165. }
  1166. /**
  1167. * A list of Firestore indexes to speed up local query execution.
  1168. *
  1169. * See {@link https://firebase.google.com/docs/reference/firestore/indexes/#json_format | JSON Format}
  1170. * for a description of the format of the index definition.
  1171. * @beta
  1172. */
  1173. export declare interface IndexConfiguration {
  1174. /** A list of all Firestore indexes. */
  1175. readonly indexes?: Index[];
  1176. [key: string]: unknown;
  1177. }
  1178. /**
  1179. * A single field element in an index configuration.
  1180. * @beta
  1181. */
  1182. export declare interface IndexField {
  1183. /** The field path to index. */
  1184. readonly fieldPath: string;
  1185. /**
  1186. * What type of array index to create. Set to `CONTAINS` for `array-contains`
  1187. * and `array-contains-any` indexes.
  1188. *
  1189. * Only one of `arrayConfig` or `order` should be set;
  1190. */
  1191. readonly arrayConfig?: 'CONTAINS';
  1192. /**
  1193. * What type of array index to create. Set to `ASCENDING` or 'DESCENDING` for
  1194. * `==`, `!=`, `<=`, `<=`, `in` and `not-in` filters.
  1195. *
  1196. * Only one of `arrayConfig` or `order` should be set.
  1197. */
  1198. readonly order?: 'ASCENDING' | 'DESCENDING';
  1199. [key: string]: unknown;
  1200. }
  1201. /**
  1202. * Initializes a new instance of {@link Firestore} with the provided settings.
  1203. * Can only be called before any other function, including
  1204. * {@link (getFirestore:1)}. If the custom settings are empty, this function is
  1205. * equivalent to calling {@link (getFirestore:1)}.
  1206. *
  1207. * @param app - The {@link @firebase/app#FirebaseApp} with which the {@link Firestore} instance will
  1208. * be associated.
  1209. * @param settings - A settings object to configure the {@link Firestore} instance.
  1210. * @param databaseId - The name of the database.
  1211. * @returns A newly initialized {@link Firestore} instance.
  1212. */
  1213. export declare function initializeFirestore(app: FirebaseApp, settings: FirestoreSettings, databaseId?: string): Firestore;
  1214. /**
  1215. * Creates a {@link QueryLimitConstraint} that only returns the first matching
  1216. * documents.
  1217. *
  1218. * @param limit - The maximum number of items to return.
  1219. * @returns The created {@link QueryLimitConstraint}.
  1220. */
  1221. export declare function limit(limit: number): QueryLimitConstraint;
  1222. /**
  1223. * Creates a {@link QueryLimitConstraint} that only returns the last matching
  1224. * documents.
  1225. *
  1226. * You must specify at least one `orderBy` clause for `limitToLast` queries,
  1227. * otherwise an exception will be thrown during execution.
  1228. *
  1229. * @param limit - The maximum number of items to return.
  1230. * @returns The created {@link QueryLimitConstraint}.
  1231. */
  1232. export declare function limitToLast(limit: number): QueryLimitConstraint;
  1233. /**
  1234. * Loads a Firestore bundle into the local cache.
  1235. *
  1236. * @param firestore - The {@link Firestore} instance to load bundles for.
  1237. * @param bundleData - An object representing the bundle to be loaded. Valid
  1238. * objects are `ArrayBuffer`, `ReadableStream<Uint8Array>` or `string`.
  1239. *
  1240. * @returns A `LoadBundleTask` object, which notifies callers with progress
  1241. * updates, and completion or error events. It can be used as a
  1242. * `Promise<LoadBundleTaskProgress>`.
  1243. */
  1244. export declare function loadBundle(firestore: Firestore, bundleData: ReadableStream<Uint8Array> | ArrayBuffer | string): LoadBundleTask;
  1245. /**
  1246. * Represents the task of loading a Firestore bundle. It provides progress of bundle
  1247. * loading, as well as task completion and error events.
  1248. *
  1249. * The API is compatible with `Promise<LoadBundleTaskProgress>`.
  1250. */
  1251. export declare class LoadBundleTask implements PromiseLike<LoadBundleTaskProgress> {
  1252. /**
  1253. * Registers functions to listen to bundle loading progress events.
  1254. * @param next - Called when there is a progress update from bundle loading. Typically `next` calls occur
  1255. * each time a Firestore document is loaded from the bundle.
  1256. * @param error - Called when an error occurs during bundle loading. The task aborts after reporting the
  1257. * error, and there should be no more updates after this.
  1258. * @param complete - Called when the loading task is complete.
  1259. */
  1260. onProgress(next?: (progress: LoadBundleTaskProgress) => unknown, error?: (err: Error) => unknown, complete?: () => void): void;
  1261. /**
  1262. * Implements the `Promise<LoadBundleTaskProgress>.catch` interface.
  1263. *
  1264. * @param onRejected - Called when an error occurs during bundle loading.
  1265. */
  1266. catch<R>(onRejected: (a: Error) => R | PromiseLike<R>): Promise<R | LoadBundleTaskProgress>;
  1267. /**
  1268. * Implements the `Promise<LoadBundleTaskProgress>.then` interface.
  1269. *
  1270. * @param onFulfilled - Called on the completion of the loading task with a final `LoadBundleTaskProgress` update.
  1271. * The update will always have its `taskState` set to `"Success"`.
  1272. * @param onRejected - Called when an error occurs during bundle loading.
  1273. */
  1274. then<T, R>(onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>, onRejected?: (a: Error) => R | PromiseLike<R>): Promise<T | R>;
  1275. }
  1276. /**
  1277. * Represents a progress update or a final state from loading bundles.
  1278. */
  1279. export declare interface LoadBundleTaskProgress {
  1280. /** How many documents have been loaded. */
  1281. documentsLoaded: number;
  1282. /** How many documents are in the bundle being loaded. */
  1283. totalDocuments: number;
  1284. /** How many bytes have been loaded. */
  1285. bytesLoaded: number;
  1286. /** How many bytes are in the bundle being loaded. */
  1287. totalBytes: number;
  1288. /** Current task state. */
  1289. taskState: TaskState;
  1290. }
  1291. export { LogLevel };
  1292. /**
  1293. * An settings object to configure an `MemoryLocalCache` instance.
  1294. */
  1295. export declare interface MemoryCacheSettings {
  1296. /**
  1297. * The garbage collector to use, for the memory cache layer.
  1298. * A `MemoryEagerGarbageCollector` is used when this is undefined.
  1299. */
  1300. garbageCollector?: MemoryGarbageCollector;
  1301. }
  1302. /**
  1303. * A garbage collector deletes documents whenever they are not part of any
  1304. * active queries, and have no local mutations attached to them.
  1305. *
  1306. * This collector tries to ensure lowest memory footprints from the SDK,
  1307. * at the risk of documents not being cached for offline queries or for
  1308. * direct queries to the cache.
  1309. *
  1310. * Use factory function {@link memoryEagerGarbageCollector()} to create an
  1311. * instance of this collector.
  1312. */
  1313. export declare interface MemoryEagerGarbageCollector {
  1314. kind: 'memoryEager';
  1315. }
  1316. /**
  1317. * Creates an instance of `MemoryEagerGarbageCollector`. This is also the
  1318. * default garbage collector unless it is explicitly specified otherwise.
  1319. */
  1320. export declare function memoryEagerGarbageCollector(): MemoryEagerGarbageCollector;
  1321. /**
  1322. * Union type from all support gabage collectors for memory local cache.
  1323. */
  1324. export declare type MemoryGarbageCollector = MemoryEagerGarbageCollector | MemoryLruGarbageCollector;
  1325. /**
  1326. * Provides an in-memory cache to the SDK. This is the default cache unless explicitly
  1327. * configured otherwise.
  1328. *
  1329. * To use, create an instance using the factory function {@link memoryLocalCache()}, then
  1330. * set the instance to `FirestoreSettings.cache` and call `initializeFirestore` using
  1331. * the settings object.
  1332. */
  1333. export declare interface MemoryLocalCache {
  1334. kind: 'memory';
  1335. }
  1336. /**
  1337. * Creates an instance of `MemoryLocalCache`. The instance can be set to
  1338. * `FirestoreSettings.cache` to tell the SDK which cache layer to use.
  1339. */
  1340. export declare function memoryLocalCache(settings?: MemoryCacheSettings): MemoryLocalCache;
  1341. /**
  1342. * A garbage collector deletes Least-Recently-Used documents in multiple
  1343. * batches.
  1344. *
  1345. * This collector is configured with a target size, and will only perform
  1346. * collection when the cached documents exceed the target size. It avoids
  1347. * querying backend repeated for the same query or document, at the risk
  1348. * of having a larger memory footprint.
  1349. *
  1350. * Use factory function {@link memoryLruGarbageCollector()} to create a
  1351. * instance of this collector.
  1352. */
  1353. export declare interface MemoryLruGarbageCollector {
  1354. kind: 'memoryLru';
  1355. }
  1356. /**
  1357. * Creates an instance of `MemoryLruGarbageCollector`.
  1358. *
  1359. * A target size can be specified as part of the setting parameter. The
  1360. * collector will start deleting documents once the cache size exceeds
  1361. * the given size. The default cache size is 40MB (40 * 1024 * 1024 bytes).
  1362. */
  1363. export declare function memoryLruGarbageCollector(settings?: {
  1364. cacheSizeBytes?: number;
  1365. }): MemoryLruGarbageCollector;
  1366. /**
  1367. * Reads a Firestore {@link Query} from local cache, identified by the given
  1368. * name.
  1369. *
  1370. * The named queries are packaged into bundles on the server side (along
  1371. * with resulting documents), and loaded to local cache using `loadBundle`. Once
  1372. * in local cache, use this method to extract a {@link Query} by name.
  1373. *
  1374. * @param firestore - The {@link Firestore} instance to read the query from.
  1375. * @param name - The name of the query.
  1376. * @returns A `Promise` that is resolved with the Query or `null`.
  1377. */
  1378. export declare function namedQuery(firestore: Firestore, name: string): Promise<Query | null>;
  1379. /**
  1380. * For each field (e.g. 'bar'), find all nested keys (e.g. {'bar.baz': T1,
  1381. * 'bar.qux': T2}). Intersect them together to make a single map containing
  1382. * all possible keys that are all marked as optional
  1383. */
  1384. export declare type NestedUpdateFields<T extends Record<string, unknown>> = UnionToIntersection<{
  1385. [K in keyof T & string]: ChildUpdateFields<K, T[K]>;
  1386. }[keyof T & string]>;
  1387. /**
  1388. * Attaches a listener for `DocumentSnapshot` events. You may either pass
  1389. * individual `onNext` and `onError` callbacks or pass a single observer
  1390. * object with `next` and `error` callbacks.
  1391. *
  1392. * NOTE: Although an `onCompletion` callback can be provided, it will
  1393. * never be called because the snapshot stream is never-ending.
  1394. *
  1395. * @param reference - A reference to the document to listen to.
  1396. * @param observer - A single object containing `next` and `error` callbacks.
  1397. * @returns An unsubscribe function that can be called to cancel
  1398. * the snapshot listener.
  1399. */
  1400. export declare function onSnapshot<T>(reference: DocumentReference<T>, observer: {
  1401. next?: (snapshot: DocumentSnapshot<T>) => void;
  1402. error?: (error: FirestoreError) => void;
  1403. complete?: () => void;
  1404. }): Unsubscribe;
  1405. /**
  1406. * Attaches a listener for `DocumentSnapshot` events. You may either pass
  1407. * individual `onNext` and `onError` callbacks or pass a single observer
  1408. * object with `next` and `error` callbacks.
  1409. *
  1410. * NOTE: Although an `onCompletion` callback can be provided, it will
  1411. * never be called because the snapshot stream is never-ending.
  1412. *
  1413. * @param reference - A reference to the document to listen to.
  1414. * @param options - Options controlling the listen behavior.
  1415. * @param observer - A single object containing `next` and `error` callbacks.
  1416. * @returns An unsubscribe function that can be called to cancel
  1417. * the snapshot listener.
  1418. */
  1419. export declare function onSnapshot<T>(reference: DocumentReference<T>, options: SnapshotListenOptions, observer: {
  1420. next?: (snapshot: DocumentSnapshot<T>) => void;
  1421. error?: (error: FirestoreError) => void;
  1422. complete?: () => void;
  1423. }): Unsubscribe;
  1424. /**
  1425. * Attaches a listener for `DocumentSnapshot` events. You may either pass
  1426. * individual `onNext` and `onError` callbacks or pass a single observer
  1427. * object with `next` and `error` callbacks.
  1428. *
  1429. * NOTE: Although an `onCompletion` callback can be provided, it will
  1430. * never be called because the snapshot stream is never-ending.
  1431. *
  1432. * @param reference - A reference to the document to listen to.
  1433. * @param onNext - A callback to be called every time a new `DocumentSnapshot`
  1434. * is available.
  1435. * @param onError - A callback to be called if the listen fails or is
  1436. * cancelled. No further callbacks will occur.
  1437. * @param onCompletion - Can be provided, but will not be called since streams are
  1438. * never ending.
  1439. * @returns An unsubscribe function that can be called to cancel
  1440. * the snapshot listener.
  1441. */
  1442. export declare function onSnapshot<T>(reference: DocumentReference<T>, onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;
  1443. /**
  1444. * Attaches a listener for `DocumentSnapshot` events. You may either pass
  1445. * individual `onNext` and `onError` callbacks or pass a single observer
  1446. * object with `next` and `error` callbacks.
  1447. *
  1448. * NOTE: Although an `onCompletion` callback can be provided, it will
  1449. * never be called because the snapshot stream is never-ending.
  1450. *
  1451. * @param reference - A reference to the document to listen to.
  1452. * @param options - Options controlling the listen behavior.
  1453. * @param onNext - A callback to be called every time a new `DocumentSnapshot`
  1454. * is available.
  1455. * @param onError - A callback to be called if the listen fails or is
  1456. * cancelled. No further callbacks will occur.
  1457. * @param onCompletion - Can be provided, but will not be called since streams are
  1458. * never ending.
  1459. * @returns An unsubscribe function that can be called to cancel
  1460. * the snapshot listener.
  1461. */
  1462. export declare function onSnapshot<T>(reference: DocumentReference<T>, options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;
  1463. /**
  1464. * Attaches a listener for `QuerySnapshot` events. You may either pass
  1465. * individual `onNext` and `onError` callbacks or pass a single observer
  1466. * object with `next` and `error` callbacks. The listener can be cancelled by
  1467. * calling the function that is returned when `onSnapshot` is called.
  1468. *
  1469. * NOTE: Although an `onCompletion` callback can be provided, it will
  1470. * never be called because the snapshot stream is never-ending.
  1471. *
  1472. * @param query - The query to listen to.
  1473. * @param observer - A single object containing `next` and `error` callbacks.
  1474. * @returns An unsubscribe function that can be called to cancel
  1475. * the snapshot listener.
  1476. */
  1477. export declare function onSnapshot<T>(query: Query<T>, observer: {
  1478. next?: (snapshot: QuerySnapshot<T>) => void;
  1479. error?: (error: FirestoreError) => void;
  1480. complete?: () => void;
  1481. }): Unsubscribe;
  1482. /**
  1483. * Attaches a listener for `QuerySnapshot` events. You may either pass
  1484. * individual `onNext` and `onError` callbacks or pass a single observer
  1485. * object with `next` and `error` callbacks. The listener can be cancelled by
  1486. * calling the function that is returned when `onSnapshot` is called.
  1487. *
  1488. * NOTE: Although an `onCompletion` callback can be provided, it will
  1489. * never be called because the snapshot stream is never-ending.
  1490. *
  1491. * @param query - The query to listen to.
  1492. * @param options - Options controlling the listen behavior.
  1493. * @param observer - A single object containing `next` and `error` callbacks.
  1494. * @returns An unsubscribe function that can be called to cancel
  1495. * the snapshot listener.
  1496. */
  1497. export declare function onSnapshot<T>(query: Query<T>, options: SnapshotListenOptions, observer: {
  1498. next?: (snapshot: QuerySnapshot<T>) => void;
  1499. error?: (error: FirestoreError) => void;
  1500. complete?: () => void;
  1501. }): Unsubscribe;
  1502. /**
  1503. * Attaches a listener for `QuerySnapshot` events. You may either pass
  1504. * individual `onNext` and `onError` callbacks or pass a single observer
  1505. * object with `next` and `error` callbacks. The listener can be cancelled by
  1506. * calling the function that is returned when `onSnapshot` is called.
  1507. *
  1508. * NOTE: Although an `onCompletion` callback can be provided, it will
  1509. * never be called because the snapshot stream is never-ending.
  1510. *
  1511. * @param query - The query to listen to.
  1512. * @param onNext - A callback to be called every time a new `QuerySnapshot`
  1513. * is available.
  1514. * @param onCompletion - Can be provided, but will not be called since streams are
  1515. * never ending.
  1516. * @param onError - A callback to be called if the listen fails or is
  1517. * cancelled. No further callbacks will occur.
  1518. * @returns An unsubscribe function that can be called to cancel
  1519. * the snapshot listener.
  1520. */
  1521. export declare function onSnapshot<T>(query: Query<T>, onNext: (snapshot: QuerySnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;
  1522. /**
  1523. * Attaches a listener for `QuerySnapshot` events. You may either pass
  1524. * individual `onNext` and `onError` callbacks or pass a single observer
  1525. * object with `next` and `error` callbacks. The listener can be cancelled by
  1526. * calling the function that is returned when `onSnapshot` is called.
  1527. *
  1528. * NOTE: Although an `onCompletion` callback can be provided, it will
  1529. * never be called because the snapshot stream is never-ending.
  1530. *
  1531. * @param query - The query to listen to.
  1532. * @param options - Options controlling the listen behavior.
  1533. * @param onNext - A callback to be called every time a new `QuerySnapshot`
  1534. * is available.
  1535. * @param onCompletion - Can be provided, but will not be called since streams are
  1536. * never ending.
  1537. * @param onError - A callback to be called if the listen fails or is
  1538. * cancelled. No further callbacks will occur.
  1539. * @returns An unsubscribe function that can be called to cancel
  1540. * the snapshot listener.
  1541. */
  1542. export declare function onSnapshot<T>(query: Query<T>, options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;
  1543. /**
  1544. * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync
  1545. * event indicates that all listeners affected by a given change have fired,
  1546. * even if a single server-generated change affects multiple listeners.
  1547. *
  1548. * NOTE: The snapshots-in-sync event only indicates that listeners are in sync
  1549. * with each other, but does not relate to whether those snapshots are in sync
  1550. * with the server. Use SnapshotMetadata in the individual listeners to
  1551. * determine if a snapshot is from the cache or the server.
  1552. *
  1553. * @param firestore - The instance of Firestore for synchronizing snapshots.
  1554. * @param observer - A single object containing `next` and `error` callbacks.
  1555. * @returns An unsubscribe function that can be called to cancel the snapshot
  1556. * listener.
  1557. */
  1558. export declare function onSnapshotsInSync(firestore: Firestore, observer: {
  1559. next?: (value: void) => void;
  1560. error?: (error: FirestoreError) => void;
  1561. complete?: () => void;
  1562. }): Unsubscribe;
  1563. /**
  1564. * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync
  1565. * event indicates that all listeners affected by a given change have fired,
  1566. * even if a single server-generated change affects multiple listeners.
  1567. *
  1568. * NOTE: The snapshots-in-sync event only indicates that listeners are in sync
  1569. * with each other, but does not relate to whether those snapshots are in sync
  1570. * with the server. Use `SnapshotMetadata` in the individual listeners to
  1571. * determine if a snapshot is from the cache or the server.
  1572. *
  1573. * @param firestore - The `Firestore` instance for synchronizing snapshots.
  1574. * @param onSync - A callback to be called every time all snapshot listeners are
  1575. * in sync with each other.
  1576. * @returns An unsubscribe function that can be called to cancel the snapshot
  1577. * listener.
  1578. */
  1579. export declare function onSnapshotsInSync(firestore: Firestore, onSync: () => void): Unsubscribe;
  1580. /**
  1581. * Creates a new {@link QueryCompositeFilterConstraint} that is a disjunction of
  1582. * the given filter constraints. A disjunction filter includes a document if it
  1583. * satisfies any of the given filters.
  1584. *
  1585. * @param queryConstraints - Optional. The list of
  1586. * {@link QueryFilterConstraint}s to perform a disjunction for. These must be
  1587. * created with calls to {@link where}, {@link or}, or {@link and}.
  1588. * @returns The newly created {@link QueryCompositeFilterConstraint}.
  1589. */
  1590. export declare function or(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;
  1591. /**
  1592. * Creates a {@link QueryOrderByConstraint} that sorts the query result by the
  1593. * specified field, optionally in descending order instead of ascending.
  1594. *
  1595. * Note: Documents that do not contain the specified field will not be present
  1596. * in the query result.
  1597. *
  1598. * @param fieldPath - The field to sort by.
  1599. * @param directionStr - Optional direction to sort by ('asc' or 'desc'). If
  1600. * not specified, order will be ascending.
  1601. * @returns The created {@link QueryOrderByConstraint}.
  1602. */
  1603. export declare function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryOrderByConstraint;
  1604. /**
  1605. * The direction of a {@link orderBy} clause is specified as 'desc' or 'asc'
  1606. * (descending or ascending).
  1607. */
  1608. export declare type OrderByDirection = 'desc' | 'asc';
  1609. /**
  1610. * Similar to Typescript's `Partial<T>`, but allows nested fields to be
  1611. * omitted and FieldValues to be passed in as property values.
  1612. */
  1613. export declare type PartialWithFieldValue<T> = Partial<T> | (T extends Primitive ? T : T extends {} ? {
  1614. [K in keyof T]?: PartialWithFieldValue<T[K]> | FieldValue;
  1615. } : never);
  1616. /**
  1617. * Settings that can be passed to `enableIndexedDbPersistence()` to configure
  1618. * Firestore persistence.
  1619. *
  1620. * Persistence cannot be used in a Node.js environment.
  1621. */
  1622. export declare interface PersistenceSettings {
  1623. /**
  1624. * Whether to force enable persistence for the client. This cannot be used
  1625. * with multi-tab synchronization and is primarily intended for use with Web
  1626. * Workers. Setting this to `true` will enable persistence, but cause other
  1627. * tabs using persistence to fail.
  1628. */
  1629. forceOwnership?: boolean;
  1630. }
  1631. /**
  1632. * An settings object to configure an `PersistentLocalCache` instance.
  1633. *
  1634. * Persistent cache cannot be used in a Node.js environment.
  1635. */
  1636. export declare interface PersistentCacheSettings {
  1637. /**
  1638. * An approximate cache size threshold for the on-disk data. If the cache
  1639. * grows beyond this size, Firestore will start removing data that hasn't been
  1640. * recently used. The SDK does not guarantee that the cache will stay below
  1641. * that size, only that if the cache exceeds the given size, cleanup will be
  1642. * attempted.
  1643. *
  1644. * The default value is 40 MB. The threshold must be set to at least 1 MB, and
  1645. * can be set to `CACHE_SIZE_UNLIMITED` to disable garbage collection.
  1646. */
  1647. cacheSizeBytes?: number;
  1648. /**
  1649. * Specifies how multiple tabs/windows will be managed by the SDK.
  1650. */
  1651. tabManager?: PersistentTabManager;
  1652. }
  1653. /**
  1654. * Provides a persistent cache backed by IndexedDb to the SDK.
  1655. *
  1656. * To use, create an instance using the factory function {@link persistentLocalCache()}, then
  1657. * set the instance to `FirestoreSettings.cache` and call `initializeFirestore` using
  1658. * the settings object.
  1659. */
  1660. export declare interface PersistentLocalCache {
  1661. kind: 'persistent';
  1662. }
  1663. /**
  1664. * Creates an instance of `PersistentLocalCache`. The instance can be set to
  1665. * `FirestoreSettings.cache` to tell the SDK which cache layer to use.
  1666. *
  1667. * Persistent cache cannot be used in a Node.js environment.
  1668. */
  1669. export declare function persistentLocalCache(settings?: PersistentCacheSettings): PersistentLocalCache;
  1670. /**
  1671. * A tab manager supporting multiple tabs. SDK will synchronize queries and
  1672. * mutations done across all tabs using the SDK.
  1673. */
  1674. export declare interface PersistentMultipleTabManager {
  1675. kind: 'PersistentMultipleTab';
  1676. }
  1677. /**
  1678. * Creates an instance of `PersistentMultipleTabManager`.
  1679. */
  1680. export declare function persistentMultipleTabManager(): PersistentMultipleTabManager;
  1681. /**
  1682. * A tab manager supportting only one tab, no synchronization will be
  1683. * performed across tabs.
  1684. */
  1685. export declare interface PersistentSingleTabManager {
  1686. kind: 'persistentSingleTab';
  1687. }
  1688. /**
  1689. * Creates an instance of `PersistentSingleTabManager`.
  1690. *
  1691. * @param settings Configures the created tab manager.
  1692. */
  1693. export declare function persistentSingleTabManager(settings: PersistentSingleTabManagerSettings | undefined): PersistentSingleTabManager;
  1694. /**
  1695. * Type to configure an `PersistentSingleTabManager` instance.
  1696. */
  1697. export declare interface PersistentSingleTabManagerSettings {
  1698. /**
  1699. * Whether to force-enable persistent (IndexedDB) cache for the client. This
  1700. * cannot be used with multi-tab synchronization and is primarily intended for
  1701. * use with Web Workers. Setting this to `true` will enable IndexedDB, but cause
  1702. * other tabs using IndexedDB cache to fail.
  1703. */
  1704. forceOwnership?: boolean;
  1705. }
  1706. /**
  1707. * A union of all available tab managers.
  1708. */
  1709. export declare type PersistentTabManager = PersistentSingleTabManager | PersistentMultipleTabManager;
  1710. /**
  1711. * These types primarily exist to support the `UpdateData`,
  1712. * `WithFieldValue`, and `PartialWithFieldValue` types and are not consumed
  1713. * directly by the end developer.
  1714. */
  1715. /** Primitive types. */
  1716. export declare type Primitive = string | number | boolean | undefined | null;
  1717. /**
  1718. * A `Query` refers to a query which you can read or listen to. You can also
  1719. * construct refined `Query` objects by adding filters and ordering.
  1720. */
  1721. export declare class Query<T = DocumentData> {
  1722. /**
  1723. * If provided, the `FirestoreDataConverter` associated with this instance.
  1724. */
  1725. readonly converter: FirestoreDataConverter<T> | null;
  1726. /** The type of this Firestore reference. */
  1727. readonly type: 'query' | 'collection';
  1728. /**
  1729. * The `Firestore` instance for the Firestore database (useful for performing
  1730. * transactions, etc.).
  1731. */
  1732. readonly firestore: Firestore;
  1733. protected constructor();
  1734. /**
  1735. * Removes the current converter.
  1736. *
  1737. * @param converter - `null` removes the current converter.
  1738. * @returns A `Query<DocumentData>` that does not use a converter.
  1739. */
  1740. withConverter(converter: null): Query<DocumentData>;
  1741. /**
  1742. * Applies a custom data converter to this query, allowing you to use your own
  1743. * custom model objects with Firestore. When you call {@link getDocs} with
  1744. * the returned query, the provided converter will convert between Firestore
  1745. * data and your custom type `U`.
  1746. *
  1747. * @param converter - Converts objects to and from Firestore.
  1748. * @returns A `Query<U>` that uses the provided converter.
  1749. */
  1750. withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
  1751. }
  1752. /**
  1753. * Creates a new immutable instance of {@link Query} that is extended to also
  1754. * include additional query constraints.
  1755. *
  1756. * @param query - The {@link Query} instance to use as a base for the new
  1757. * constraints.
  1758. * @param compositeFilter - The {@link QueryCompositeFilterConstraint} to
  1759. * apply. Create {@link QueryCompositeFilterConstraint} using {@link and} or
  1760. * {@link or}.
  1761. * @param queryConstraints - Additional {@link QueryNonFilterConstraint}s to
  1762. * apply (e.g. {@link orderBy}, {@link limit}).
  1763. * @throws if any of the provided query constraints cannot be combined with the
  1764. * existing or new constraints.
  1765. */
  1766. export declare function query<T>(query: Query<T>, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query<T>;
  1767. /**
  1768. * Creates a new immutable instance of {@link Query} that is extended to also
  1769. * include additional query constraints.
  1770. *
  1771. * @param query - The {@link Query} instance to use as a base for the new
  1772. * constraints.
  1773. * @param queryConstraints - The list of {@link QueryConstraint}s to apply.
  1774. * @throws if any of the provided query constraints cannot be combined with the
  1775. * existing or new constraints.
  1776. */
  1777. export declare function query<T>(query: Query<T>, ...queryConstraints: QueryConstraint[]): Query<T>;
  1778. /**
  1779. * A `QueryCompositeFilterConstraint` is used to narrow the set of documents
  1780. * returned by a Firestore query by performing the logical OR or AND of multiple
  1781. * {@link QueryFieldFilterConstraint}s or {@link QueryCompositeFilterConstraint}s.
  1782. * `QueryCompositeFilterConstraint`s are created by invoking {@link or} or
  1783. * {@link and} and can then be passed to {@link (query:1)} to create a new query
  1784. * instance that also contains the `QueryCompositeFilterConstraint`.
  1785. */
  1786. export declare class QueryCompositeFilterConstraint {
  1787. /** The type of this query constraint */
  1788. readonly type: 'or' | 'and';
  1789. }
  1790. /**
  1791. * A `QueryConstraint` is used to narrow the set of documents returned by a
  1792. * Firestore query. `QueryConstraint`s are created by invoking {@link where},
  1793. * {@link orderBy}, {@link (startAt:1)}, {@link (startAfter:1)}, {@link
  1794. * (endBefore:1)}, {@link (endAt:1)}, {@link limit}, {@link limitToLast} and
  1795. * can then be passed to {@link (query:1)} to create a new query instance that
  1796. * also contains this `QueryConstraint`.
  1797. */
  1798. export declare abstract class QueryConstraint {
  1799. /** The type of this query constraint */
  1800. abstract readonly type: QueryConstraintType;
  1801. }
  1802. /** Describes the different query constraints available in this SDK. */
  1803. export declare type QueryConstraintType = 'where' | 'orderBy' | 'limit' | 'limitToLast' | 'startAt' | 'startAfter' | 'endAt' | 'endBefore';
  1804. /**
  1805. * A `QueryDocumentSnapshot` contains data read from a document in your
  1806. * Firestore database as part of a query. The document is guaranteed to exist
  1807. * and its data can be extracted with `.data()` or `.get(<field>)` to get a
  1808. * specific field.
  1809. *
  1810. * A `QueryDocumentSnapshot` offers the same API surface as a
  1811. * `DocumentSnapshot`. Since query results contain only existing documents, the
  1812. * `exists` property will always be true and `data()` will never return
  1813. * 'undefined'.
  1814. */
  1815. export declare class QueryDocumentSnapshot<T = DocumentData> extends DocumentSnapshot<T> {
  1816. /**
  1817. * Retrieves all fields in the document as an `Object`.
  1818. *
  1819. * By default, `serverTimestamp()` values that have not yet been
  1820. * set to their final value will be returned as `null`. You can override
  1821. * this by passing an options object.
  1822. *
  1823. * @override
  1824. * @param options - An options object to configure how data is retrieved from
  1825. * the snapshot (for example the desired behavior for server timestamps that
  1826. * have not yet been set to their final value).
  1827. * @returns An `Object` containing all fields in the document.
  1828. */
  1829. data(options?: SnapshotOptions): T;
  1830. }
  1831. /**
  1832. * A `QueryEndAtConstraint` is used to exclude documents from the end of a
  1833. * result set returned by a Firestore query.
  1834. * `QueryEndAtConstraint`s are created by invoking {@link (endAt:1)} or
  1835. * {@link (endBefore:1)} and can then be passed to {@link (query:1)} to create a new
  1836. * query instance that also contains this `QueryEndAtConstraint`.
  1837. */
  1838. export declare class QueryEndAtConstraint extends QueryConstraint {
  1839. /** The type of this query constraint */
  1840. readonly type: 'endBefore' | 'endAt';
  1841. }
  1842. /**
  1843. * Returns true if the provided queries point to the same collection and apply
  1844. * the same constraints.
  1845. *
  1846. * @param left - A `Query` to compare.
  1847. * @param right - A `Query` to compare.
  1848. * @returns true if the references point to the same location in the same
  1849. * Firestore database.
  1850. */
  1851. export declare function queryEqual<T>(left: Query<T>, right: Query<T>): boolean;
  1852. /**
  1853. * A `QueryFieldFilterConstraint` is used to narrow the set of documents returned by
  1854. * a Firestore query by filtering on one or more document fields.
  1855. * `QueryFieldFilterConstraint`s are created by invoking {@link where} and can then
  1856. * be passed to {@link (query:1)} to create a new query instance that also contains
  1857. * this `QueryFieldFilterConstraint`.
  1858. */
  1859. export declare class QueryFieldFilterConstraint extends QueryConstraint {
  1860. /** The type of this query constraint */
  1861. readonly type = "where";
  1862. }
  1863. /**
  1864. * `QueryFilterConstraint` is a helper union type that represents
  1865. * {@link QueryFieldFilterConstraint} and {@link QueryCompositeFilterConstraint}.
  1866. */
  1867. export declare type QueryFilterConstraint = QueryFieldFilterConstraint | QueryCompositeFilterConstraint;
  1868. /**
  1869. * A `QueryLimitConstraint` is used to limit the number of documents returned by
  1870. * a Firestore query.
  1871. * `QueryLimitConstraint`s are created by invoking {@link limit} or
  1872. * {@link limitToLast} and can then be passed to {@link (query:1)} to create a new
  1873. * query instance that also contains this `QueryLimitConstraint`.
  1874. */
  1875. export declare class QueryLimitConstraint extends QueryConstraint {
  1876. /** The type of this query constraint */
  1877. readonly type: 'limit' | 'limitToLast';
  1878. }
  1879. /**
  1880. * `QueryNonFilterConstraint` is a helper union type that represents
  1881. * QueryConstraints which are used to narrow or order the set of documents,
  1882. * but that do not explicitly filter on a document field.
  1883. * `QueryNonFilterConstraint`s are created by invoking {@link orderBy},
  1884. * {@link (startAt:1)}, {@link (startAfter:1)}, {@link (endBefore:1)}, {@link (endAt:1)},
  1885. * {@link limit} or {@link limitToLast} and can then be passed to {@link (query:1)}
  1886. * to create a new query instance that also contains the `QueryConstraint`.
  1887. */
  1888. export declare type QueryNonFilterConstraint = QueryOrderByConstraint | QueryLimitConstraint | QueryStartAtConstraint | QueryEndAtConstraint;
  1889. /**
  1890. * A `QueryOrderByConstraint` is used to sort the set of documents returned by a
  1891. * Firestore query. `QueryOrderByConstraint`s are created by invoking
  1892. * {@link orderBy} and can then be passed to {@link (query:1)} to create a new query
  1893. * instance that also contains this `QueryOrderByConstraint`.
  1894. *
  1895. * Note: Documents that do not contain the orderBy field will not be present in
  1896. * the query result.
  1897. */
  1898. export declare class QueryOrderByConstraint extends QueryConstraint {
  1899. /** The type of this query constraint */
  1900. readonly type = "orderBy";
  1901. }
  1902. /**
  1903. * A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects
  1904. * representing the results of a query. The documents can be accessed as an
  1905. * array via the `docs` property or enumerated using the `forEach` method. The
  1906. * number of documents can be determined via the `empty` and `size`
  1907. * properties.
  1908. */
  1909. export declare class QuerySnapshot<T = DocumentData> {
  1910. /**
  1911. * Metadata about this snapshot, concerning its source and if it has local
  1912. * modifications.
  1913. */
  1914. readonly metadata: SnapshotMetadata;
  1915. /**
  1916. * The query on which you called `get` or `onSnapshot` in order to get this
  1917. * `QuerySnapshot`.
  1918. */
  1919. readonly query: Query<T>;
  1920. private constructor();
  1921. /** An array of all the documents in the `QuerySnapshot`. */
  1922. get docs(): Array<QueryDocumentSnapshot<T>>;
  1923. /** The number of documents in the `QuerySnapshot`. */
  1924. get size(): number;
  1925. /** True if there are no documents in the `QuerySnapshot`. */
  1926. get empty(): boolean;
  1927. /**
  1928. * Enumerates all of the documents in the `QuerySnapshot`.
  1929. *
  1930. * @param callback - A callback to be called with a `QueryDocumentSnapshot` for
  1931. * each document in the snapshot.
  1932. * @param thisArg - The `this` binding for the callback.
  1933. */
  1934. forEach(callback: (result: QueryDocumentSnapshot<T>) => void, thisArg?: unknown): void;
  1935. /**
  1936. * Returns an array of the documents changes since the last snapshot. If this
  1937. * is the first snapshot, all documents will be in the list as 'added'
  1938. * changes.
  1939. *
  1940. * @param options - `SnapshotListenOptions` that control whether metadata-only
  1941. * changes (i.e. only `DocumentSnapshot.metadata` changed) should trigger
  1942. * snapshot events.
  1943. */
  1944. docChanges(options?: SnapshotListenOptions): Array<DocumentChange<T>>;
  1945. }
  1946. /**
  1947. * A `QueryStartAtConstraint` is used to exclude documents from the start of a
  1948. * result set returned by a Firestore query.
  1949. * `QueryStartAtConstraint`s are created by invoking {@link (startAt:1)} or
  1950. * {@link (startAfter:1)} and can then be passed to {@link (query:1)} to create a
  1951. * new query instance that also contains this `QueryStartAtConstraint`.
  1952. */
  1953. export declare class QueryStartAtConstraint extends QueryConstraint {
  1954. /** The type of this query constraint */
  1955. readonly type: 'startAt' | 'startAfter';
  1956. }
  1957. /**
  1958. * Returns true if the provided references are equal.
  1959. *
  1960. * @param left - A reference to compare.
  1961. * @param right - A reference to compare.
  1962. * @returns true if the references point to the same location in the same
  1963. * Firestore database.
  1964. */
  1965. export declare function refEqual<T>(left: DocumentReference<T> | CollectionReference<T>, right: DocumentReference<T> | CollectionReference<T>): boolean;
  1966. /* Excluded from this release type: _ResourcePath */
  1967. /**
  1968. * Executes the given `updateFunction` and then attempts to commit the changes
  1969. * applied within the transaction. If any document read within the transaction
  1970. * has changed, Cloud Firestore retries the `updateFunction`. If it fails to
  1971. * commit after 5 attempts, the transaction fails.
  1972. *
  1973. * The maximum number of writes allowed in a single transaction is 500.
  1974. *
  1975. * @param firestore - A reference to the Firestore database to run this
  1976. * transaction against.
  1977. * @param updateFunction - The function to execute within the transaction
  1978. * context.
  1979. * @param options - An options object to configure maximum number of attempts to
  1980. * commit.
  1981. * @returns If the transaction completed successfully or was explicitly aborted
  1982. * (the `updateFunction` returned a failed promise), the promise returned by the
  1983. * `updateFunction `is returned here. Otherwise, if the transaction failed, a
  1984. * rejected promise with the corresponding failure error is returned.
  1985. */
  1986. export declare function runTransaction<T>(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
  1987. /**
  1988. * Returns a sentinel used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link @firebase/firestore/lite#(updateDoc:1)} to
  1989. * include a server-generated timestamp in the written data.
  1990. */
  1991. export declare function serverTimestamp(): FieldValue;
  1992. /**
  1993. * Writes to the document referred to by this `DocumentReference`. If the
  1994. * document does not yet exist, it will be created.
  1995. *
  1996. * @param reference - A reference to the document to write.
  1997. * @param data - A map of the fields and values for the document.
  1998. * @returns A `Promise` resolved once the data has been successfully written
  1999. * to the backend (note that it won't resolve while you're offline).
  2000. */
  2001. export declare function setDoc<T>(reference: DocumentReference<T>, data: WithFieldValue<T>): Promise<void>;
  2002. /**
  2003. * Writes to the document referred to by the specified `DocumentReference`. If
  2004. * the document does not yet exist, it will be created. If you provide `merge`
  2005. * or `mergeFields`, the provided data can be merged into an existing document.
  2006. *
  2007. * @param reference - A reference to the document to write.
  2008. * @param data - A map of the fields and values for the document.
  2009. * @param options - An object to configure the set behavior.
  2010. * @returns A Promise resolved once the data has been successfully written
  2011. * to the backend (note that it won't resolve while you're offline).
  2012. */
  2013. export declare function setDoc<T>(reference: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): Promise<void>;
  2014. /**
  2015. * Configures indexing for local query execution. Any previous index
  2016. * configuration is overridden. The `Promise` resolves once the index
  2017. * configuration has been persisted.
  2018. *
  2019. * The index entries themselves are created asynchronously. You can continue to
  2020. * use queries that require indexing even if the indices are not yet available.
  2021. * Query execution will automatically start using the index once the index
  2022. * entries have been written.
  2023. *
  2024. * Indexes are only supported with IndexedDb persistence. If IndexedDb is not
  2025. * enabled, any index configuration is ignored.
  2026. *
  2027. * @param firestore - The {@link Firestore} instance to configure indexes for.
  2028. * @param configuration -The index definition.
  2029. * @throws FirestoreError if the JSON format is invalid.
  2030. * @returns A `Promise` that resolves once all indices are successfully
  2031. * configured.
  2032. * @beta
  2033. */
  2034. export declare function setIndexConfiguration(firestore: Firestore, configuration: IndexConfiguration): Promise<void>;
  2035. /**
  2036. * Configures indexing for local query execution. Any previous index
  2037. * configuration is overridden. The `Promise` resolves once the index
  2038. * configuration has been persisted.
  2039. *
  2040. * The index entries themselves are created asynchronously. You can continue to
  2041. * use queries that require indexing even if the indices are not yet available.
  2042. * Query execution will automatically start using the index once the index
  2043. * entries have been written.
  2044. *
  2045. * Indexes are only supported with IndexedDb persistence. Invoke either
  2046. * `enableIndexedDbPersistence()` or `enableMultiTabIndexedDbPersistence()`
  2047. * before setting an index configuration. If IndexedDb is not enabled, any
  2048. * index configuration is ignored.
  2049. *
  2050. * The method accepts the JSON format exported by the Firebase CLI (`firebase
  2051. * firestore:indexes`). If the JSON format is invalid, this method throws an
  2052. * error.
  2053. *
  2054. * @param firestore - The {@link Firestore} instance to configure indexes for.
  2055. * @param json -The JSON format exported by the Firebase CLI.
  2056. * @throws FirestoreError if the JSON format is invalid.
  2057. * @returns A `Promise` that resolves once all indices are successfully
  2058. * configured.
  2059. * @beta
  2060. */
  2061. export declare function setIndexConfiguration(firestore: Firestore, json: string): Promise<void>;
  2062. /**
  2063. * Sets the verbosity of Cloud Firestore logs (debug, error, or silent).
  2064. *
  2065. * @param logLevel - The verbosity you set for activity and error logging. Can
  2066. * be any of the following values:
  2067. *
  2068. * <ul>
  2069. * <li>`debug` for the most verbose logging level, primarily for
  2070. * debugging.</li>
  2071. * <li>`error` to log errors only.</li>
  2072. * <li><code>`silent` to turn off logging.</li>
  2073. * </ul>
  2074. */
  2075. export declare function setLogLevel(logLevel: LogLevel): void;
  2076. /**
  2077. * An options object that configures the behavior of {@link @firebase/firestore/lite#(setDoc:1)}, {@link
  2078. * @firebase/firestore/lite#(WriteBatch.set:1)} and {@link @firebase/firestore/lite#(Transaction.set:1)} calls. These calls can be
  2079. * configured to perform granular merges instead of overwriting the target
  2080. * documents in their entirety by providing a `SetOptions` with `merge: true`.
  2081. *
  2082. * @param merge - Changes the behavior of a `setDoc()` call to only replace the
  2083. * values specified in its data argument. Fields omitted from the `setDoc()`
  2084. * call remain untouched. If your input sets any field to an empty map, all
  2085. * nested fields are overwritten.
  2086. * @param mergeFields - Changes the behavior of `setDoc()` calls to only replace
  2087. * the specified field paths. Any field path that is not specified is ignored
  2088. * and remains untouched. If your input sets any field to an empty map, all
  2089. * nested fields are overwritten.
  2090. */
  2091. export declare type SetOptions = {
  2092. readonly merge?: boolean;
  2093. } | {
  2094. readonly mergeFields?: Array<string | FieldPath>;
  2095. };
  2096. /**
  2097. * Returns true if the provided snapshots are equal.
  2098. *
  2099. * @param left - A snapshot to compare.
  2100. * @param right - A snapshot to compare.
  2101. * @returns true if the snapshots are equal.
  2102. */
  2103. export declare function snapshotEqual<T>(left: DocumentSnapshot<T> | QuerySnapshot<T>, right: DocumentSnapshot<T> | QuerySnapshot<T>): boolean;
  2104. /**
  2105. * An options object that can be passed to {@link (onSnapshot:1)} and {@link
  2106. * QuerySnapshot.docChanges} to control which types of changes to include in the
  2107. * result set.
  2108. */
  2109. export declare interface SnapshotListenOptions {
  2110. /**
  2111. * Include a change even if only the metadata of the query or of a document
  2112. * changed. Default is false.
  2113. */
  2114. readonly includeMetadataChanges?: boolean;
  2115. }
  2116. /**
  2117. * Metadata about a snapshot, describing the state of the snapshot.
  2118. */
  2119. export declare class SnapshotMetadata {
  2120. /**
  2121. * True if the snapshot contains the result of local writes (for example
  2122. * `set()` or `update()` calls) that have not yet been committed to the
  2123. * backend. If your listener has opted into metadata updates (via
  2124. * `SnapshotListenOptions`) you will receive another snapshot with
  2125. * `hasPendingWrites` equal to false once the writes have been committed to
  2126. * the backend.
  2127. */
  2128. readonly hasPendingWrites: boolean;
  2129. /**
  2130. * True if the snapshot was created from cached data rather than guaranteed
  2131. * up-to-date server data. If your listener has opted into metadata updates
  2132. * (via `SnapshotListenOptions`) you will receive another snapshot with
  2133. * `fromCache` set to false once the client has received up-to-date data from
  2134. * the backend.
  2135. */
  2136. readonly fromCache: boolean;
  2137. private constructor();
  2138. /**
  2139. * Returns true if this `SnapshotMetadata` is equal to the provided one.
  2140. *
  2141. * @param other - The `SnapshotMetadata` to compare against.
  2142. * @returns true if this `SnapshotMetadata` is equal to the provided one.
  2143. */
  2144. isEqual(other: SnapshotMetadata): boolean;
  2145. }
  2146. /**
  2147. * Options that configure how data is retrieved from a `DocumentSnapshot` (for
  2148. * example the desired behavior for server timestamps that have not yet been set
  2149. * to their final value).
  2150. */
  2151. export declare interface SnapshotOptions {
  2152. /**
  2153. * If set, controls the return value for server timestamps that have not yet
  2154. * been set to their final value.
  2155. *
  2156. * By specifying 'estimate', pending server timestamps return an estimate
  2157. * based on the local clock. This estimate will differ from the final value
  2158. * and cause these values to change once the server result becomes available.
  2159. *
  2160. * By specifying 'previous', pending timestamps will be ignored and return
  2161. * their previous value instead.
  2162. *
  2163. * If omitted or set to 'none', `null` will be returned by default until the
  2164. * server value becomes available.
  2165. */
  2166. readonly serverTimestamps?: 'estimate' | 'previous' | 'none';
  2167. }
  2168. /**
  2169. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  2170. * start after the provided document (exclusive). The starting position is
  2171. * relative to the order of the query. The document must contain all of the
  2172. * fields provided in the orderBy of the query.
  2173. *
  2174. * @param snapshot - The snapshot of the document to start after.
  2175. * @returns A {@link QueryStartAtConstraint} to pass to `query()`
  2176. */
  2177. export declare function startAfter(snapshot: DocumentSnapshot<unknown>): QueryStartAtConstraint;
  2178. /**
  2179. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  2180. * start after the provided fields relative to the order of the query. The order
  2181. * of the field values must match the order of the order by clauses of the query.
  2182. *
  2183. * @param fieldValues - The field values to start this query after, in order
  2184. * of the query's order by.
  2185. * @returns A {@link QueryStartAtConstraint} to pass to `query()`
  2186. */
  2187. export declare function startAfter(...fieldValues: unknown[]): QueryStartAtConstraint;
  2188. /**
  2189. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  2190. * start at the provided document (inclusive). The starting position is relative
  2191. * to the order of the query. The document must contain all of the fields
  2192. * provided in the `orderBy` of this query.
  2193. *
  2194. * @param snapshot - The snapshot of the document to start at.
  2195. * @returns A {@link QueryStartAtConstraint} to pass to `query()`.
  2196. */
  2197. export declare function startAt(snapshot: DocumentSnapshot<unknown>): QueryStartAtConstraint;
  2198. /**
  2199. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  2200. * start at the provided fields relative to the order of the query. The order of
  2201. * the field values must match the order of the order by clauses of the query.
  2202. *
  2203. * @param fieldValues - The field values to start this query at, in order
  2204. * of the query's order by.
  2205. * @returns A {@link QueryStartAtConstraint} to pass to `query()`.
  2206. */
  2207. export declare function startAt(...fieldValues: unknown[]): QueryStartAtConstraint;
  2208. /**
  2209. * Represents the state of bundle loading tasks.
  2210. *
  2211. * Both 'Error' and 'Success' are sinking state: task will abort or complete and there will
  2212. * be no more updates after they are reported.
  2213. */
  2214. export declare type TaskState = 'Error' | 'Running' | 'Success';
  2215. /**
  2216. * Terminates the provided {@link Firestore} instance.
  2217. *
  2218. * After calling `terminate()` only the `clearIndexedDbPersistence()` function
  2219. * may be used. Any other function will throw a `FirestoreError`.
  2220. *
  2221. * To restart after termination, create a new instance of FirebaseFirestore with
  2222. * {@link (getFirestore:1)}.
  2223. *
  2224. * Termination does not cancel any pending writes, and any promises that are
  2225. * awaiting a response from the server will not be resolved. If you have
  2226. * persistence enabled, the next time you start this instance, it will resume
  2227. * sending these writes to the server.
  2228. *
  2229. * Note: Under normal circumstances, calling `terminate()` is not required. This
  2230. * function is useful only when you want to force this instance to release all
  2231. * of its resources or in combination with `clearIndexedDbPersistence()` to
  2232. * ensure that all local state is destroyed between test runs.
  2233. *
  2234. * @returns A `Promise` that is resolved when the instance has been successfully
  2235. * terminated.
  2236. */
  2237. export declare function terminate(firestore: Firestore): Promise<void>;
  2238. /**
  2239. * @license
  2240. * Copyright 2017 Google LLC
  2241. *
  2242. * Licensed under the Apache License, Version 2.0 (the "License");
  2243. * you may not use this file except in compliance with the License.
  2244. * You may obtain a copy of the License at
  2245. *
  2246. * http://www.apache.org/licenses/LICENSE-2.0
  2247. *
  2248. * Unless required by applicable law or agreed to in writing, software
  2249. * distributed under the License is distributed on an "AS IS" BASIS,
  2250. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2251. * See the License for the specific language governing permissions and
  2252. * limitations under the License.
  2253. */
  2254. /**
  2255. * A `Timestamp` represents a point in time independent of any time zone or
  2256. * calendar, represented as seconds and fractions of seconds at nanosecond
  2257. * resolution in UTC Epoch time.
  2258. *
  2259. * It is encoded using the Proleptic Gregorian Calendar which extends the
  2260. * Gregorian calendar backwards to year one. It is encoded assuming all minutes
  2261. * are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second
  2262. * table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to
  2263. * 9999-12-31T23:59:59.999999999Z.
  2264. *
  2265. * For examples and further specifications, refer to the
  2266. * {@link https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto | Timestamp definition}.
  2267. */
  2268. export declare class Timestamp {
  2269. /**
  2270. * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
  2271. */
  2272. readonly seconds: number;
  2273. /**
  2274. * The fractions of a second at nanosecond resolution.*
  2275. */
  2276. readonly nanoseconds: number;
  2277. /**
  2278. * Creates a new timestamp with the current date, with millisecond precision.
  2279. *
  2280. * @returns a new timestamp representing the current date.
  2281. */
  2282. static now(): Timestamp;
  2283. /**
  2284. * Creates a new timestamp from the given date.
  2285. *
  2286. * @param date - The date to initialize the `Timestamp` from.
  2287. * @returns A new `Timestamp` representing the same point in time as the given
  2288. * date.
  2289. */
  2290. static fromDate(date: Date): Timestamp;
  2291. /**
  2292. * Creates a new timestamp from the given number of milliseconds.
  2293. *
  2294. * @param milliseconds - Number of milliseconds since Unix epoch
  2295. * 1970-01-01T00:00:00Z.
  2296. * @returns A new `Timestamp` representing the same point in time as the given
  2297. * number of milliseconds.
  2298. */
  2299. static fromMillis(milliseconds: number): Timestamp;
  2300. /**
  2301. * Creates a new timestamp.
  2302. *
  2303. * @param seconds - The number of seconds of UTC time since Unix epoch
  2304. * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
  2305. * 9999-12-31T23:59:59Z inclusive.
  2306. * @param nanoseconds - The non-negative fractions of a second at nanosecond
  2307. * resolution. Negative second values with fractions must still have
  2308. * non-negative nanoseconds values that count forward in time. Must be
  2309. * from 0 to 999,999,999 inclusive.
  2310. */
  2311. constructor(
  2312. /**
  2313. * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
  2314. */
  2315. seconds: number,
  2316. /**
  2317. * The fractions of a second at nanosecond resolution.*
  2318. */
  2319. nanoseconds: number);
  2320. /**
  2321. * Converts a `Timestamp` to a JavaScript `Date` object. This conversion
  2322. * causes a loss of precision since `Date` objects only support millisecond
  2323. * precision.
  2324. *
  2325. * @returns JavaScript `Date` object representing the same point in time as
  2326. * this `Timestamp`, with millisecond precision.
  2327. */
  2328. toDate(): Date;
  2329. /**
  2330. * Converts a `Timestamp` to a numeric timestamp (in milliseconds since
  2331. * epoch). This operation causes a loss of precision.
  2332. *
  2333. * @returns The point in time corresponding to this timestamp, represented as
  2334. * the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
  2335. */
  2336. toMillis(): number;
  2337. /**
  2338. * Returns true if this `Timestamp` is equal to the provided one.
  2339. *
  2340. * @param other - The `Timestamp` to compare against.
  2341. * @returns true if this `Timestamp` is equal to the provided one.
  2342. */
  2343. isEqual(other: Timestamp): boolean;
  2344. /** Returns a textual representation of this `Timestamp`. */
  2345. toString(): string;
  2346. /** Returns a JSON-serializable representation of this `Timestamp`. */
  2347. toJSON(): {
  2348. seconds: number;
  2349. nanoseconds: number;
  2350. };
  2351. /**
  2352. * Converts this object to a primitive string, which allows `Timestamp` objects
  2353. * to be compared using the `>`, `<=`, `>=` and `>` operators.
  2354. */
  2355. valueOf(): string;
  2356. }
  2357. /**
  2358. * A reference to a transaction.
  2359. *
  2360. * The `Transaction` object passed to a transaction's `updateFunction` provides
  2361. * the methods to read and write data within the transaction context. See
  2362. * {@link runTransaction}.
  2363. */
  2364. export declare class Transaction {
  2365. private constructor();
  2366. /**
  2367. * Reads the document referenced by the provided {@link DocumentReference}.
  2368. *
  2369. * @param documentRef - A reference to the document to be read.
  2370. * @returns A `DocumentSnapshot` with the read data.
  2371. */
  2372. get<T>(documentRef: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
  2373. /**
  2374. * Writes to the document referred to by the provided {@link
  2375. * DocumentReference}. If the document does not exist yet, it will be created.
  2376. *
  2377. * @param documentRef - A reference to the document to be set.
  2378. * @param data - An object of the fields and values for the document.
  2379. * @throws Error - If the provided input is not a valid Firestore document.
  2380. * @returns This `Transaction` instance. Used for chaining method calls.
  2381. */
  2382. set<T>(documentRef: DocumentReference<T>, data: WithFieldValue<T>): this;
  2383. /**
  2384. * Writes to the document referred to by the provided {@link
  2385. * DocumentReference}. If the document does not exist yet, it will be created.
  2386. * If you provide `merge` or `mergeFields`, the provided data can be merged
  2387. * into an existing document.
  2388. *
  2389. * @param documentRef - A reference to the document to be set.
  2390. * @param data - An object of the fields and values for the document.
  2391. * @param options - An object to configure the set behavior.
  2392. * @throws Error - If the provided input is not a valid Firestore document.
  2393. * @returns This `Transaction` instance. Used for chaining method calls.
  2394. */
  2395. set<T>(documentRef: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): this;
  2396. /**
  2397. * Updates fields in the document referred to by the provided {@link
  2398. * DocumentReference}. The update will fail if applied to a document that does
  2399. * not exist.
  2400. *
  2401. * @param documentRef - A reference to the document to be updated.
  2402. * @param data - An object containing the fields and values with which to
  2403. update the document. Fields can contain dots to reference nested fields
  2404. within the document.
  2405. * @throws Error - If the provided input is not valid Firestore data.
  2406. * @returns This `Transaction` instance. Used for chaining method calls.
  2407. */
  2408. update<T>(documentRef: DocumentReference<T>, data: UpdateData<T>): this;
  2409. /**
  2410. * Updates fields in the document referred to by the provided {@link
  2411. * DocumentReference}. The update will fail if applied to a document that does
  2412. * not exist.
  2413. *
  2414. * Nested fields can be updated by providing dot-separated field path
  2415. * strings or by providing `FieldPath` objects.
  2416. *
  2417. * @param documentRef - A reference to the document to be updated.
  2418. * @param field - The first field to update.
  2419. * @param value - The first value.
  2420. * @param moreFieldsAndValues - Additional key/value pairs.
  2421. * @throws Error - If the provided input is not valid Firestore data.
  2422. * @returns This `Transaction` instance. Used for chaining method calls.
  2423. */
  2424. update(documentRef: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this;
  2425. /**
  2426. * Deletes the document referred to by the provided {@link DocumentReference}.
  2427. *
  2428. * @param documentRef - A reference to the document to be deleted.
  2429. * @returns This `Transaction` instance. Used for chaining method calls.
  2430. */
  2431. delete(documentRef: DocumentReference<unknown>): this;
  2432. }
  2433. /**
  2434. * @license
  2435. * Copyright 2022 Google LLC
  2436. *
  2437. * Licensed under the Apache License, Version 2.0 (the "License");
  2438. * you may not use this file except in compliance with the License.
  2439. * You may obtain a copy of the License at
  2440. *
  2441. * http://www.apache.org/licenses/LICENSE-2.0
  2442. *
  2443. * Unless required by applicable law or agreed to in writing, software
  2444. * distributed under the License is distributed on an "AS IS" BASIS,
  2445. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2446. * See the License for the specific language governing permissions and
  2447. * limitations under the License.
  2448. */
  2449. /**
  2450. * Options to customize transaction behavior.
  2451. */
  2452. export declare interface TransactionOptions {
  2453. /** Maximum number of attempts to commit, after which transaction fails. Default is 5. */
  2454. readonly maxAttempts?: number;
  2455. }
  2456. /**
  2457. * Given a union type `U = T1 | T2 | ...`, returns an intersected type
  2458. * `(T1 & T2 & ...)`.
  2459. *
  2460. * Uses distributive conditional types and inference from conditional types.
  2461. * This works because multiple candidates for the same type variable in
  2462. * contra-variant positions causes an intersection type to be inferred.
  2463. * https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-inference-in-conditional-types
  2464. * https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
  2465. */
  2466. export declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
  2467. /**
  2468. * A function returned by `onSnapshot()` that removes the listener when invoked.
  2469. */
  2470. export declare interface Unsubscribe {
  2471. /** Removes the listener when invoked. */
  2472. (): void;
  2473. }
  2474. /**
  2475. * Update data (for use with {@link (updateDoc:1)}) that consists of field paths
  2476. * (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots
  2477. * reference nested fields within the document. FieldValues can be passed in
  2478. * as property values.
  2479. */
  2480. export declare type UpdateData<T> = T extends Primitive ? T : T extends {} ? {
  2481. [K in keyof T]?: UpdateData<T[K]> | FieldValue;
  2482. } & NestedUpdateFields<T> : Partial<T>;
  2483. /**
  2484. * Updates fields in the document referred to by the specified
  2485. * `DocumentReference`. The update will fail if applied to a document that does
  2486. * not exist.
  2487. *
  2488. * @param reference - A reference to the document to update.
  2489. * @param data - An object containing the fields and values with which to
  2490. * update the document. Fields can contain dots to reference nested fields
  2491. * within the document.
  2492. * @returns A `Promise` resolved once the data has been successfully written
  2493. * to the backend (note that it won't resolve while you're offline).
  2494. */
  2495. export declare function updateDoc<T>(reference: DocumentReference<T>, data: UpdateData<T>): Promise<void>;
  2496. /**
  2497. * Updates fields in the document referred to by the specified
  2498. * `DocumentReference` The update will fail if applied to a document that does
  2499. * not exist.
  2500. *
  2501. * Nested fields can be updated by providing dot-separated field path
  2502. * strings or by providing `FieldPath` objects.
  2503. *
  2504. * @param reference - A reference to the document to update.
  2505. * @param field - The first field to update.
  2506. * @param value - The first value.
  2507. * @param moreFieldsAndValues - Additional key value pairs.
  2508. * @returns A `Promise` resolved once the data has been successfully written
  2509. * to the backend (note that it won't resolve while you're offline).
  2510. */
  2511. export declare function updateDoc(reference: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise<void>;
  2512. /**
  2513. * Waits until all currently pending writes for the active user have been
  2514. * acknowledged by the backend.
  2515. *
  2516. * The returned promise resolves immediately if there are no outstanding writes.
  2517. * Otherwise, the promise waits for all previously issued writes (including
  2518. * those written in a previous app session), but it does not wait for writes
  2519. * that were added after the function is called. If you want to wait for
  2520. * additional writes, call `waitForPendingWrites()` again.
  2521. *
  2522. * Any outstanding `waitForPendingWrites()` promises are rejected during user
  2523. * changes.
  2524. *
  2525. * @returns A `Promise` which resolves when all currently pending writes have been
  2526. * acknowledged by the backend.
  2527. */
  2528. export declare function waitForPendingWrites(firestore: Firestore): Promise<void>;
  2529. /**
  2530. * Creates a {@link QueryFieldFilterConstraint} that enforces that documents
  2531. * must contain the specified field and that the value should satisfy the
  2532. * relation constraint provided.
  2533. *
  2534. * @param fieldPath - The path to compare
  2535. * @param opStr - The operation string (e.g "&lt;", "&lt;=", "==", "&lt;",
  2536. * "&lt;=", "!=").
  2537. * @param value - The value for comparison
  2538. * @returns The created {@link QueryFieldFilterConstraint}.
  2539. */
  2540. export declare function where(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown): QueryFieldFilterConstraint;
  2541. /**
  2542. * Filter conditions in a {@link where} clause are specified using the
  2543. * strings '&lt;', '&lt;=', '==', '!=', '&gt;=', '&gt;', 'array-contains', 'in',
  2544. * 'array-contains-any', and 'not-in'.
  2545. */
  2546. export declare type WhereFilterOp = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any' | 'not-in';
  2547. /**
  2548. * Allows FieldValues to be passed in as a property value while maintaining
  2549. * type safety.
  2550. */
  2551. export declare type WithFieldValue<T> = T | (T extends Primitive ? T : T extends {} ? {
  2552. [K in keyof T]: WithFieldValue<T[K]> | FieldValue;
  2553. } : never);
  2554. /**
  2555. * A write batch, used to perform multiple writes as a single atomic unit.
  2556. *
  2557. * A `WriteBatch` object can be acquired by calling {@link writeBatch}. It
  2558. * provides methods for adding writes to the write batch. None of the writes
  2559. * will be committed (or visible locally) until {@link WriteBatch.commit} is
  2560. * called.
  2561. */
  2562. export declare class WriteBatch {
  2563. private constructor();
  2564. /**
  2565. * Writes to the document referred to by the provided {@link
  2566. * DocumentReference}. If the document does not exist yet, it will be created.
  2567. *
  2568. * @param documentRef - A reference to the document to be set.
  2569. * @param data - An object of the fields and values for the document.
  2570. * @returns This `WriteBatch` instance. Used for chaining method calls.
  2571. */
  2572. set<T>(documentRef: DocumentReference<T>, data: WithFieldValue<T>): WriteBatch;
  2573. /**
  2574. * Writes to the document referred to by the provided {@link
  2575. * DocumentReference}. If the document does not exist yet, it will be created.
  2576. * If you provide `merge` or `mergeFields`, the provided data can be merged
  2577. * into an existing document.
  2578. *
  2579. * @param documentRef - A reference to the document to be set.
  2580. * @param data - An object of the fields and values for the document.
  2581. * @param options - An object to configure the set behavior.
  2582. * @throws Error - If the provided input is not a valid Firestore document.
  2583. * @returns This `WriteBatch` instance. Used for chaining method calls.
  2584. */
  2585. set<T>(documentRef: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): WriteBatch;
  2586. /**
  2587. * Updates fields in the document referred to by the provided {@link
  2588. * DocumentReference}. The update will fail if applied to a document that does
  2589. * not exist.
  2590. *
  2591. * @param documentRef - A reference to the document to be updated.
  2592. * @param data - An object containing the fields and values with which to
  2593. * update the document. Fields can contain dots to reference nested fields
  2594. * within the document.
  2595. * @throws Error - If the provided input is not valid Firestore data.
  2596. * @returns This `WriteBatch` instance. Used for chaining method calls.
  2597. */
  2598. update<T>(documentRef: DocumentReference<T>, data: UpdateData<T>): WriteBatch;
  2599. /**
  2600. * Updates fields in the document referred to by this {@link
  2601. * DocumentReference}. The update will fail if applied to a document that does
  2602. * not exist.
  2603. *
  2604. * Nested fields can be update by providing dot-separated field path strings
  2605. * or by providing `FieldPath` objects.
  2606. *
  2607. * @param documentRef - A reference to the document to be updated.
  2608. * @param field - The first field to update.
  2609. * @param value - The first value.
  2610. * @param moreFieldsAndValues - Additional key value pairs.
  2611. * @throws Error - If the provided input is not valid Firestore data.
  2612. * @returns This `WriteBatch` instance. Used for chaining method calls.
  2613. */
  2614. update(documentRef: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch;
  2615. /**
  2616. * Deletes the document referred to by the provided {@link DocumentReference}.
  2617. *
  2618. * @param documentRef - A reference to the document to be deleted.
  2619. * @returns This `WriteBatch` instance. Used for chaining method calls.
  2620. */
  2621. delete(documentRef: DocumentReference<unknown>): WriteBatch;
  2622. /**
  2623. * Commits all of the writes in this write batch as a single atomic unit.
  2624. *
  2625. * The result of these writes will only be reflected in document reads that
  2626. * occur after the returned promise resolves. If the client is offline, the
  2627. * write fails. If you would like to see local modifications or buffer writes
  2628. * until the client is online, use the full Firestore SDK.
  2629. *
  2630. * @returns A `Promise` resolved once all of the writes in the batch have been
  2631. * successfully written to the backend as an atomic unit (note that it won't
  2632. * resolve while you're offline).
  2633. */
  2634. commit(): Promise<void>;
  2635. }
  2636. /**
  2637. * Creates a write batch, used for performing multiple writes as a single
  2638. * atomic operation. The maximum number of writes allowed in a single {@link WriteBatch}
  2639. * is 500.
  2640. *
  2641. * Unlike transactions, write batches are persisted offline and therefore are
  2642. * preferable when you don't need to condition your writes on read data.
  2643. *
  2644. * @returns A {@link WriteBatch} that can be used to atomically execute multiple
  2645. * writes.
  2646. */
  2647. export declare function writeBatch(firestore: Firestore): WriteBatch;
  2648. export {};