No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.d.ts 72KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  1. /**
  2. * Firestore Lite
  3. *
  4. * @remarks Firestore Lite is a small online-only SDK that allows read
  5. * and write access to your Firestore database. All operations connect
  6. * directly to the backend, and `onSnapshot()` APIs are not supported.
  7. * @packageDocumentation
  8. */
  9. import { FirebaseApp } from '@firebase/app';
  10. import { LogLevelString as LogLevel } from '@firebase/logger';
  11. import { EmulatorMockTokenOptions } from '@firebase/util';
  12. import { FirebaseError } from '@firebase/util';
  13. /* Excluded from this release type: AbstractUserDataWriter */
  14. /**
  15. * Add a new document to specified `CollectionReference` with the given data,
  16. * assigning it a document ID automatically.
  17. *
  18. * The result of this write will only be reflected in document reads that occur
  19. * after the returned promise resolves. If the client is offline, the
  20. * write fails. If you would like to see local modifications or buffer writes
  21. * until the client is online, use the full Firestore SDK.
  22. *
  23. * @param reference - A reference to the collection to add this document to.
  24. * @param data - An Object containing the data for the new document.
  25. * @throws Error - If the provided input is not a valid Firestore document.
  26. * @returns A `Promise` resolved with a `DocumentReference` pointing to the
  27. * newly created document after it has been written to the backend.
  28. */
  29. export declare function addDoc<T>(reference: CollectionReference<T>, data: WithFieldValue<T>): Promise<DocumentReference<T>>;
  30. /**
  31. * Returns a new map where every key is prefixed with the outer key appended
  32. * to a dot.
  33. */
  34. export declare type AddPrefixToKeys<Prefix extends string, T extends Record<string, unknown>> = {
  35. [K in keyof T & string as `${Prefix}.${K}`]+?: T[K];
  36. };
  37. /**
  38. * Represents an aggregation that can be performed by Firestore.
  39. */
  40. export declare class AggregateField<T> {
  41. /** A type string to uniquely identify instances of this class. */
  42. type: string;
  43. }
  44. /**
  45. * The union of all `AggregateField` types that are supported by Firestore.
  46. */
  47. export declare type AggregateFieldType = AggregateField<number>;
  48. /**
  49. * The results of executing an aggregation query.
  50. */
  51. export declare class AggregateQuerySnapshot<T extends AggregateSpec> {
  52. /** A type string to uniquely identify instances of this class. */
  53. readonly type = "AggregateQuerySnapshot";
  54. /**
  55. * The underlying query over which the aggregations recorded in this
  56. * `AggregateQuerySnapshot` were performed.
  57. */
  58. readonly query: Query<unknown>;
  59. private constructor();
  60. /**
  61. * Returns the results of the aggregations performed over the underlying
  62. * query.
  63. *
  64. * The keys of the returned object will be the same as those of the
  65. * `AggregateSpec` object specified to the aggregation method, and the values
  66. * will be the corresponding aggregation result.
  67. *
  68. * @returns The results of the aggregations performed over the underlying
  69. * query.
  70. */
  71. data(): AggregateSpecData<T>;
  72. }
  73. /**
  74. * Compares two `AggregateQuerySnapshot` instances for equality.
  75. *
  76. * Two `AggregateQuerySnapshot` instances are considered "equal" if they have
  77. * underlying queries that compare equal, and the same data.
  78. *
  79. * @param left - The first `AggregateQuerySnapshot` to compare.
  80. * @param right - The second `AggregateQuerySnapshot` to compare.
  81. *
  82. * @returns `true` if the objects are "equal", as defined above, or `false`
  83. * otherwise.
  84. */
  85. export declare function aggregateQuerySnapshotEqual<T extends AggregateSpec>(left: AggregateQuerySnapshot<T>, right: AggregateQuerySnapshot<T>): boolean;
  86. /**
  87. * A type whose property values are all `AggregateField` objects.
  88. */
  89. export declare interface AggregateSpec {
  90. [field: string]: AggregateFieldType;
  91. }
  92. /**
  93. * A type whose keys are taken from an `AggregateSpec`, and whose values are the
  94. * result of the aggregation performed by the corresponding `AggregateField`
  95. * from the input `AggregateSpec`.
  96. */
  97. export declare type AggregateSpecData<T extends AggregateSpec> = {
  98. [P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
  99. };
  100. /**
  101. * Returns a special value that can be used with {@link (setDoc:1)} or {@link
  102. * updateDoc:1} that tells the server to remove the given elements from any
  103. * array value that already exists on the server. All instances of each element
  104. * specified will be removed from the array. If the field being modified is not
  105. * already an array it will be overwritten with an empty array.
  106. *
  107. * @param elements - The elements to remove from the array.
  108. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  109. * `updateDoc()`
  110. */
  111. export declare function arrayRemove(...elements: unknown[]): FieldValue;
  112. /**
  113. * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link
  114. * @firebase/firestore/lite#(updateDoc:1)} that tells the server to union the given elements with any array
  115. * value that already exists on the server. Each specified element that doesn't
  116. * already exist in the array will be added to the end. If the field being
  117. * modified is not already an array it will be overwritten with an array
  118. * containing exactly the specified elements.
  119. *
  120. * @param elements - The elements to union into the array.
  121. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  122. * `updateDoc()`.
  123. */
  124. export declare function arrayUnion(...elements: unknown[]): FieldValue;
  125. /**
  126. * An immutable object representing an array of bytes.
  127. */
  128. export declare class Bytes {
  129. private constructor();
  130. /**
  131. * Creates a new `Bytes` object from the given Base64 string, converting it to
  132. * bytes.
  133. *
  134. * @param base64 - The Base64 string used to create the `Bytes` object.
  135. */
  136. static fromBase64String(base64: string): Bytes;
  137. /**
  138. * Creates a new `Bytes` object from the given Uint8Array.
  139. *
  140. * @param array - The Uint8Array used to create the `Bytes` object.
  141. */
  142. static fromUint8Array(array: Uint8Array): Bytes;
  143. /**
  144. * Returns the underlying bytes as a Base64-encoded string.
  145. *
  146. * @returns The Base64-encoded string created from the `Bytes` object.
  147. */
  148. toBase64(): string;
  149. /**
  150. * Returns the underlying bytes in a new `Uint8Array`.
  151. *
  152. * @returns The Uint8Array created from the `Bytes` object.
  153. */
  154. toUint8Array(): Uint8Array;
  155. /**
  156. * Returns a string representation of the `Bytes` object.
  157. *
  158. * @returns A string representation of the `Bytes` object.
  159. */
  160. toString(): string;
  161. /**
  162. * Returns true if this `Bytes` object is equal to the provided one.
  163. *
  164. * @param other - The `Bytes` object to compare against.
  165. * @returns true if this `Bytes` object is equal to the provided one.
  166. */
  167. isEqual(other: Bytes): boolean;
  168. }
  169. /* Excluded from this release type: ByteString */
  170. /**
  171. * Helper for calculating the nested fields for a given type T1. This is needed
  172. * to distribute union types such as `undefined | {...}` (happens for optional
  173. * props) or `{a: A} | {b: B}`.
  174. *
  175. * In this use case, `V` is used to distribute the union types of `T[K]` on
  176. * `Record`, since `T[K]` is evaluated as an expression and not distributed.
  177. *
  178. * See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types
  179. */
  180. export declare type ChildUpdateFields<K extends string, V> = V extends Record<string, unknown> ? AddPrefixToKeys<K, UpdateData<V>> : never;
  181. /**
  182. * Gets a `CollectionReference` instance that refers to the collection at
  183. * the specified absolute path.
  184. *
  185. * @param firestore - A reference to the root `Firestore` instance.
  186. * @param path - A slash-separated path to a collection.
  187. * @param pathSegments - Additional path segments to apply relative to the first
  188. * argument.
  189. * @throws If the final path has an even number of segments and does not point
  190. * to a collection.
  191. * @returns The `CollectionReference` instance.
  192. */
  193. export declare function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
  194. /**
  195. * Gets a `CollectionReference` instance that refers to a subcollection of
  196. * `reference` at the the specified relative path.
  197. *
  198. * @param reference - A reference to a collection.
  199. * @param path - A slash-separated path to a collection.
  200. * @param pathSegments - Additional path segments to apply relative to the first
  201. * argument.
  202. * @throws If the final path has an even number of segments and does not point
  203. * to a collection.
  204. * @returns The `CollectionReference` instance.
  205. */
  206. export declare function collection(reference: CollectionReference<unknown>, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
  207. /**
  208. * Gets a `CollectionReference` instance that refers to a subcollection of
  209. * `reference` at the the specified relative path.
  210. *
  211. * @param reference - A reference to a Firestore document.
  212. * @param path - A slash-separated path to a collection.
  213. * @param pathSegments - Additional path segments that will be applied relative
  214. * to the first argument.
  215. * @throws If the final path has an even number of segments and does not point
  216. * to a collection.
  217. * @returns The `CollectionReference` instance.
  218. */
  219. export declare function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
  220. /**
  221. * Creates and returns a new `Query` instance that includes all documents in the
  222. * database that are contained in a collection or subcollection with the
  223. * given `collectionId`.
  224. *
  225. * @param firestore - A reference to the root `Firestore` instance.
  226. * @param collectionId - Identifies the collections to query over. Every
  227. * collection or subcollection with this ID as the last segment of its path
  228. * will be included. Cannot contain a slash.
  229. * @returns The created `Query`.
  230. */
  231. export declare function collectionGroup(firestore: Firestore, collectionId: string): Query<DocumentData>;
  232. /**
  233. * A `CollectionReference` object can be used for adding documents, getting
  234. * document references, and querying for documents (using {@link query}).
  235. */
  236. export declare class CollectionReference<T = DocumentData> extends Query<T> {
  237. /** The type of this Firestore reference. */
  238. readonly type = "collection";
  239. private constructor();
  240. /** The collection's identifier. */
  241. get id(): string;
  242. /**
  243. * A string representing the path of the referenced collection (relative
  244. * to the root of the database).
  245. */
  246. get path(): string;
  247. /**
  248. * A reference to the containing `DocumentReference` if this is a
  249. * subcollection. If this isn't a subcollection, the reference is null.
  250. */
  251. get parent(): DocumentReference<DocumentData> | null;
  252. /**
  253. * Applies a custom data converter to this `CollectionReference`, allowing you
  254. * to use your own custom model objects with Firestore. When you call {@link
  255. * addDoc} with the returned `CollectionReference` instance, the provided
  256. * converter will convert between Firestore data and your custom type `U`.
  257. *
  258. * @param converter - Converts objects to and from Firestore.
  259. * @returns A `CollectionReference<U>` that uses the provided converter.
  260. */
  261. withConverter<U>(converter: FirestoreDataConverter<U>): CollectionReference<U>;
  262. /**
  263. * Removes the current converter.
  264. *
  265. * @param converter - `null` removes the current converter.
  266. * @returns A `CollectionReference<DocumentData>` that does not use a
  267. * converter.
  268. */
  269. withConverter(converter: null): CollectionReference<DocumentData>;
  270. }
  271. /**
  272. * Modify this instance to communicate with the Cloud Firestore emulator.
  273. *
  274. * Note: This must be called before this instance has been used to do any
  275. * operations.
  276. *
  277. * @param firestore - The `Firestore` instance to configure to connect to the
  278. * emulator.
  279. * @param host - the emulator host (ex: localhost).
  280. * @param port - the emulator port (ex: 9000).
  281. * @param options.mockUserToken - the mock auth token to use for unit testing
  282. * Security Rules.
  283. */
  284. export declare function connectFirestoreEmulator(firestore: Firestore, host: string, port: number, options?: {
  285. mockUserToken?: EmulatorMockTokenOptions | string;
  286. }): void;
  287. /**
  288. * Deletes the document referred to by the specified `DocumentReference`.
  289. *
  290. * The deletion will only be reflected in document reads that occur after the
  291. * returned promise resolves. If the client is offline, the
  292. * delete fails. If you would like to see local modifications or buffer writes
  293. * until the client is online, use the full Firestore SDK.
  294. *
  295. * @param reference - A reference to the document to delete.
  296. * @returns A `Promise` resolved once the document has been successfully
  297. * deleted from the backend.
  298. */
  299. export declare function deleteDoc(reference: DocumentReference<unknown>): Promise<void>;
  300. /**
  301. * Returns a sentinel for use with {@link @firebase/firestore/lite#(updateDoc:1)} or
  302. * {@link @firebase/firestore/lite#(setDoc:1)} with `{merge: true}` to mark a field for deletion.
  303. */
  304. export declare function deleteField(): FieldValue;
  305. /**
  306. * Gets a `DocumentReference` instance that refers to the document at the
  307. * specified absolute path.
  308. *
  309. * @param firestore - A reference to the root `Firestore` instance.
  310. * @param path - A slash-separated path to a document.
  311. * @param pathSegments - Additional path segments that will be applied relative
  312. * to the first argument.
  313. * @throws If the final path has an odd number of segments and does not point to
  314. * a document.
  315. * @returns The `DocumentReference` instance.
  316. */
  317. export declare function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>;
  318. /**
  319. * Gets a `DocumentReference` instance that refers to a document within
  320. * `reference` at the specified relative path. If no path is specified, an
  321. * automatically-generated unique ID will be used for the returned
  322. * `DocumentReference`.
  323. *
  324. * @param reference - A reference to a collection.
  325. * @param path - A slash-separated path to a document. Has to be omitted to use
  326. * auto-genrated IDs.
  327. * @param pathSegments - Additional path segments that will be applied relative
  328. * to the first argument.
  329. * @throws If the final path has an odd number of segments and does not point to
  330. * a document.
  331. * @returns The `DocumentReference` instance.
  332. */
  333. export declare function doc<T>(reference: CollectionReference<T>, path?: string, ...pathSegments: string[]): DocumentReference<T>;
  334. /**
  335. * Gets a `DocumentReference` instance that refers to a document within
  336. * `reference` at the specified relative path.
  337. *
  338. * @param reference - A reference to a Firestore document.
  339. * @param path - A slash-separated path to a document.
  340. * @param pathSegments - Additional path segments that will be applied relative
  341. * to the first argument.
  342. * @throws If the final path has an odd number of segments and does not point to
  343. * a document.
  344. * @returns The `DocumentReference` instance.
  345. */
  346. export declare function doc(reference: DocumentReference<unknown>, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>;
  347. /**
  348. * Document data (for use with {@link @firebase/firestore/lite#(setDoc:1)}) consists of fields mapped to
  349. * values.
  350. */
  351. export declare interface DocumentData {
  352. /** A mapping between a field and its value. */
  353. [field: string]: any;
  354. }
  355. /**
  356. * Returns a special sentinel `FieldPath` to refer to the ID of a document.
  357. * It can be used in queries to sort or filter by the document ID.
  358. */
  359. export declare function documentId(): FieldPath;
  360. /* Excluded from this release type: DocumentKey */
  361. /**
  362. * A `DocumentReference` refers to a document location in a Firestore database
  363. * and can be used to write, read, or listen to the location. The document at
  364. * the referenced location may or may not exist.
  365. */
  366. export declare class DocumentReference<T = DocumentData> {
  367. /**
  368. * If provided, the `FirestoreDataConverter` associated with this instance.
  369. */
  370. readonly converter: FirestoreDataConverter<T> | null;
  371. /** The type of this Firestore reference. */
  372. readonly type = "document";
  373. /**
  374. * The {@link Firestore} instance the document is in.
  375. * This is useful for performing transactions, for example.
  376. */
  377. readonly firestore: Firestore;
  378. private constructor();
  379. /**
  380. * The document's identifier within its collection.
  381. */
  382. get id(): string;
  383. /**
  384. * A string representing the path of the referenced document (relative
  385. * to the root of the database).
  386. */
  387. get path(): string;
  388. /**
  389. * The collection this `DocumentReference` belongs to.
  390. */
  391. get parent(): CollectionReference<T>;
  392. /**
  393. * Applies a custom data converter to this `DocumentReference`, allowing you
  394. * to use your own custom model objects with Firestore. When you call {@link
  395. * @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#getDoc}, etc. with the returned `DocumentReference`
  396. * instance, the provided converter will convert between Firestore data and
  397. * your custom type `U`.
  398. *
  399. * @param converter - Converts objects to and from Firestore.
  400. * @returns A `DocumentReference<U>` that uses the provided converter.
  401. */
  402. withConverter<U>(converter: FirestoreDataConverter<U>): DocumentReference<U>;
  403. /**
  404. * Removes the current converter.
  405. *
  406. * @param converter - `null` removes the current converter.
  407. * @returns A `DocumentReference<DocumentData>` that does not use a converter.
  408. */
  409. withConverter(converter: null): DocumentReference<DocumentData>;
  410. }
  411. /**
  412. * A `DocumentSnapshot` contains data read from a document in your Firestore
  413. * database. The data can be extracted with `.data()` or `.get(<field>)` to
  414. * get a specific field.
  415. *
  416. * For a `DocumentSnapshot` that points to a non-existing document, any data
  417. * access will return 'undefined'. You can use the `exists()` method to
  418. * explicitly verify a document's existence.
  419. */
  420. export declare class DocumentSnapshot<T = DocumentData> {
  421. protected constructor();
  422. /** Property of the `DocumentSnapshot` that provides the document's ID. */
  423. get id(): string;
  424. /**
  425. * The `DocumentReference` for the document included in the `DocumentSnapshot`.
  426. */
  427. get ref(): DocumentReference<T>;
  428. /**
  429. * Signals whether or not the document at the snapshot's location exists.
  430. *
  431. * @returns true if the document exists.
  432. */
  433. exists(): this is QueryDocumentSnapshot<T>;
  434. /**
  435. * Retrieves all fields in the document as an `Object`. Returns `undefined` if
  436. * the document doesn't exist.
  437. *
  438. * @returns An `Object` containing all fields in the document or `undefined`
  439. * if the document doesn't exist.
  440. */
  441. data(): T | undefined;
  442. /**
  443. * Retrieves the field specified by `fieldPath`. Returns `undefined` if the
  444. * document or field doesn't exist.
  445. *
  446. * @param fieldPath - The path (for example 'foo' or 'foo.bar') to a specific
  447. * field.
  448. * @returns The data at the specified field location or undefined if no such
  449. * field exists in the document.
  450. */
  451. get(fieldPath: string | FieldPath): any;
  452. }
  453. export { EmulatorMockTokenOptions };
  454. /**
  455. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end at
  456. * the provided document (inclusive). The end position is relative to the order
  457. * of the query. The document must contain all of the fields provided in the
  458. * orderBy of the query.
  459. *
  460. * @param snapshot - The snapshot of the document to end at.
  461. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  462. */
  463. export declare function endAt(snapshot: DocumentSnapshot<unknown>): QueryEndAtConstraint;
  464. /**
  465. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end at
  466. * the provided fields relative to the order of the query. The order of the field
  467. * values must match the order of the order by clauses of the query.
  468. *
  469. * @param fieldValues - The field values to end this query at, in order
  470. * of the query's order by.
  471. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  472. */
  473. export declare function endAt(...fieldValues: unknown[]): QueryEndAtConstraint;
  474. /**
  475. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end
  476. * before the provided document (exclusive). The end position is relative to the
  477. * order of the query. The document must contain all of the fields provided in
  478. * the orderBy of the query.
  479. *
  480. * @param snapshot - The snapshot of the document to end before.
  481. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  482. */
  483. export declare function endBefore(snapshot: DocumentSnapshot<unknown>): QueryEndAtConstraint;
  484. /**
  485. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end
  486. * before the provided fields relative to the order of the query. The order of
  487. * the field values must match the order of the order by clauses of the query.
  488. *
  489. * @param fieldValues - The field values to end this query before, in order
  490. * of the query's order by.
  491. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  492. */
  493. export declare function endBefore(...fieldValues: unknown[]): QueryEndAtConstraint;
  494. /**
  495. * A `FieldPath` refers to a field in a document. The path may consist of a
  496. * single field name (referring to a top-level field in the document), or a
  497. * list of field names (referring to a nested field in the document).
  498. *
  499. * Create a `FieldPath` by providing field names. If more than one field
  500. * name is provided, the path will point to a nested field in a document.
  501. */
  502. export declare class FieldPath {
  503. /**
  504. * Creates a `FieldPath` from the provided field names. If more than one field
  505. * name is provided, the path will point to a nested field in a document.
  506. *
  507. * @param fieldNames - A list of field names.
  508. */
  509. constructor(...fieldNames: string[]);
  510. /**
  511. * Returns true if this `FieldPath` is equal to the provided one.
  512. *
  513. * @param other - The `FieldPath` to compare against.
  514. * @returns true if this `FieldPath` is equal to the provided one.
  515. */
  516. isEqual(other: FieldPath): boolean;
  517. }
  518. /**
  519. * Sentinel values that can be used when writing document fields with `set()`
  520. * or `update()`.
  521. */
  522. export declare abstract class FieldValue {
  523. private constructor();
  524. /** Compares `FieldValue`s for equality. */
  525. abstract isEqual(other: FieldValue): boolean;
  526. }
  527. /* Excluded from this release type: _FirebaseService */
  528. /**
  529. * The Cloud Firestore service interface.
  530. *
  531. * Do not call this constructor directly. Instead, use {@link (getFirestore:1)}.
  532. */
  533. export declare class Firestore {
  534. /**
  535. * Whether it's a Firestore or Firestore Lite instance.
  536. */
  537. type: 'firestore-lite' | 'firestore';
  538. private constructor();
  539. /**
  540. * The {@link @firebase/app#FirebaseApp} associated with this `Firestore` service
  541. * instance.
  542. */
  543. get app(): FirebaseApp;
  544. /** Returns a JSON-serializable representation of this `Firestore` instance. */
  545. toJSON(): object;
  546. }
  547. /**
  548. * Converter used by `withConverter()` to transform user objects of type `T`
  549. * into Firestore data.
  550. *
  551. * Using the converter allows you to specify generic type arguments when
  552. * storing and retrieving objects from Firestore.
  553. *
  554. * @example
  555. * ```typescript
  556. * class Post {
  557. * constructor(readonly title: string, readonly author: string) {}
  558. *
  559. * toString(): string {
  560. * return this.title + ', by ' + this.author;
  561. * }
  562. * }
  563. *
  564. * const postConverter = {
  565. * toFirestore(post: WithFieldValue<Post>): DocumentData {
  566. * return {title: post.title, author: post.author};
  567. * },
  568. * fromFirestore(snapshot: QueryDocumentSnapshot): Post {
  569. * const data = snapshot.data(options)!;
  570. * return new Post(data.title, data.author);
  571. * }
  572. * };
  573. *
  574. * const postSnap = await firebase.firestore()
  575. * .collection('posts')
  576. * .withConverter(postConverter)
  577. * .doc().get();
  578. * const post = postSnap.data();
  579. * if (post !== undefined) {
  580. * post.title; // string
  581. * post.toString(); // Should be defined
  582. * post.someNonExistentProperty; // TS error
  583. * }
  584. * ```
  585. */
  586. export declare interface FirestoreDataConverter<T> {
  587. /**
  588. * Called by the Firestore SDK to convert a custom model object of type `T`
  589. * into a plain Javascript object (suitable for writing directly to the
  590. * Firestore database). Used with {@link @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#(WriteBatch.set:1)}
  591. * and {@link @firebase/firestore/lite#(Transaction.set:1)}.
  592. *
  593. * The `WithFieldValue<T>` type extends `T` to also allow FieldValues such as
  594. * {@link (deleteField:1)} to be used as property values.
  595. */
  596. toFirestore(modelObject: WithFieldValue<T>): DocumentData;
  597. /**
  598. * Called by the Firestore SDK to convert a custom model object of type `T`
  599. * into a plain Javascript object (suitable for writing directly to the
  600. * Firestore database). Used with {@link @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#(WriteBatch.set:1)}
  601. * and {@link @firebase/firestore/lite#(Transaction.set:1)} with `merge:true` or `mergeFields`.
  602. *
  603. * The `PartialWithFieldValue<T>` type extends `Partial<T>` to allow
  604. * FieldValues such as {@link (arrayUnion:1)} to be used as property values.
  605. * It also supports nested `Partial` by allowing nested fields to be
  606. * omitted.
  607. */
  608. toFirestore(modelObject: PartialWithFieldValue<T>, options: SetOptions): DocumentData;
  609. /**
  610. * Called by the Firestore SDK to convert Firestore data into an object of
  611. * type T. You can access your data by calling: `snapshot.data()`.
  612. *
  613. * @param snapshot - A `QueryDocumentSnapshot` containing your data and
  614. * metadata.
  615. */
  616. fromFirestore(snapshot: QueryDocumentSnapshot<DocumentData>): T;
  617. }
  618. /** An error returned by a Firestore operation. */
  619. export declare class FirestoreError extends FirebaseError {
  620. /**
  621. * The backend error code associated with this error.
  622. */
  623. readonly code: FirestoreErrorCode;
  624. /**
  625. * A custom error description.
  626. */
  627. readonly message: string;
  628. /** The stack of the error. */
  629. readonly stack?: string;
  630. private constructor();
  631. }
  632. /**
  633. * The set of Firestore status codes. The codes are the same at the ones
  634. * exposed by gRPC here:
  635. * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
  636. *
  637. * Possible values:
  638. * - 'cancelled': The operation was cancelled (typically by the caller).
  639. * - 'unknown': Unknown error or an error from a different error domain.
  640. * - 'invalid-argument': Client specified an invalid argument. Note that this
  641. * differs from 'failed-precondition'. 'invalid-argument' indicates
  642. * arguments that are problematic regardless of the state of the system
  643. * (e.g. an invalid field name).
  644. * - 'deadline-exceeded': Deadline expired before operation could complete.
  645. * For operations that change the state of the system, this error may be
  646. * returned even if the operation has completed successfully. For example,
  647. * a successful response from a server could have been delayed long enough
  648. * for the deadline to expire.
  649. * - 'not-found': Some requested document was not found.
  650. * - 'already-exists': Some document that we attempted to create already
  651. * exists.
  652. * - 'permission-denied': The caller does not have permission to execute the
  653. * specified operation.
  654. * - 'resource-exhausted': Some resource has been exhausted, perhaps a
  655. * per-user quota, or perhaps the entire file system is out of space.
  656. * - 'failed-precondition': Operation was rejected because the system is not
  657. * in a state required for the operation's execution.
  658. * - 'aborted': The operation was aborted, typically due to a concurrency
  659. * issue like transaction aborts, etc.
  660. * - 'out-of-range': Operation was attempted past the valid range.
  661. * - 'unimplemented': Operation is not implemented or not supported/enabled.
  662. * - 'internal': Internal errors. Means some invariants expected by
  663. * underlying system has been broken. If you see one of these errors,
  664. * something is very broken.
  665. * - 'unavailable': The service is currently unavailable. This is most likely
  666. * a transient condition and may be corrected by retrying with a backoff.
  667. * - 'data-loss': Unrecoverable data loss or corruption.
  668. * - 'unauthenticated': The request does not have valid authentication
  669. * credentials for the operation.
  670. */
  671. 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';
  672. /**
  673. * @license
  674. * Copyright 2017 Google LLC
  675. *
  676. * Licensed under the Apache License, Version 2.0 (the "License");
  677. * you may not use this file except in compliance with the License.
  678. * You may obtain a copy of the License at
  679. *
  680. * http://www.apache.org/licenses/LICENSE-2.0
  681. *
  682. * Unless required by applicable law or agreed to in writing, software
  683. * distributed under the License is distributed on an "AS IS" BASIS,
  684. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  685. * See the License for the specific language governing permissions and
  686. * limitations under the License.
  687. */
  688. /**
  689. * An immutable object representing a geographic location in Firestore. The
  690. * location is represented as latitude/longitude pair.
  691. *
  692. * Latitude values are in the range of [-90, 90].
  693. * Longitude values are in the range of [-180, 180].
  694. */
  695. export declare class GeoPoint {
  696. /**
  697. * Creates a new immutable `GeoPoint` object with the provided latitude and
  698. * longitude values.
  699. * @param latitude - The latitude as number between -90 and 90.
  700. * @param longitude - The longitude as number between -180 and 180.
  701. */
  702. constructor(latitude: number, longitude: number);
  703. /**
  704. * The latitude of this `GeoPoint` instance.
  705. */
  706. get latitude(): number;
  707. /**
  708. * The longitude of this `GeoPoint` instance.
  709. */
  710. get longitude(): number;
  711. /**
  712. * Returns true if this `GeoPoint` is equal to the provided one.
  713. *
  714. * @param other - The `GeoPoint` to compare against.
  715. * @returns true if this `GeoPoint` is equal to the provided one.
  716. */
  717. isEqual(other: GeoPoint): boolean;
  718. /** Returns a JSON-serializable representation of this GeoPoint. */
  719. toJSON(): {
  720. latitude: number;
  721. longitude: number;
  722. };
  723. }
  724. /**
  725. * Calculates the number of documents in the result set of the given query,
  726. * without actually downloading the documents.
  727. *
  728. * Using this function to count the documents is efficient because only the
  729. * final count, not the documents' data, is downloaded. This function can even
  730. * count the documents if the result set would be prohibitively large to
  731. * download entirely (e.g. thousands of documents).
  732. *
  733. * @param query - The query whose result set size to calculate.
  734. * @returns A Promise that will be resolved with the count; the count can be
  735. * retrieved from `snapshot.data().count`, where `snapshot` is the
  736. * `AggregateQuerySnapshot` to which the returned Promise resolves.
  737. */
  738. export declare function getCount(query: Query<unknown>): Promise<AggregateQuerySnapshot<{
  739. count: AggregateField<number>;
  740. }>>;
  741. /**
  742. * Reads the document referred to by the specified document reference.
  743. *
  744. * All documents are directly fetched from the server, even if the document was
  745. * previously read or modified. Recent modifications are only reflected in the
  746. * retrieved `DocumentSnapshot` if they have already been applied by the
  747. * backend. If the client is offline, the read fails. If you like to use
  748. * caching or see local modifications, please use the full Firestore SDK.
  749. *
  750. * @param reference - The reference of the document to fetch.
  751. * @returns A Promise resolved with a `DocumentSnapshot` containing the current
  752. * document contents.
  753. */
  754. export declare function getDoc<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
  755. /**
  756. * Executes the query and returns the results as a {@link QuerySnapshot}.
  757. *
  758. * All queries are executed directly by the server, even if the the query was
  759. * previously executed. Recent modifications are only reflected in the retrieved
  760. * results if they have already been applied by the backend. If the client is
  761. * offline, the operation fails. To see previously cached result and local
  762. * modifications, use the full Firestore SDK.
  763. *
  764. * @param query - The `Query` to execute.
  765. * @returns A Promise that will be resolved with the results of the query.
  766. */
  767. export declare function getDocs<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
  768. /**
  769. * Returns the existing default {@link Firestore} instance that is associated with the
  770. * default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
  771. * instance with default settings.
  772. *
  773. * @returns The {@link Firestore} instance of the provided app.
  774. */
  775. export declare function getFirestore(): Firestore;
  776. /**
  777. * Returns the existing default {@link Firestore} instance that is associated with the
  778. * provided {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
  779. * instance with default settings.
  780. *
  781. * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned {@link Firestore}
  782. * instance is associated with.
  783. * @returns The {@link Firestore} instance of the provided app.
  784. */
  785. export declare function getFirestore(app: FirebaseApp): Firestore;
  786. /* Excluded declaration from this release type: getFirestore */
  787. /* Excluded declaration from this release type: getFirestore */
  788. /**
  789. * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link
  790. * @firebase/firestore/lite#(updateDoc:1)} that tells the server to increment the field's current value by
  791. * the given value.
  792. *
  793. * If either the operand or the current field value uses floating point
  794. * precision, all arithmetic follows IEEE 754 semantics. If both values are
  795. * integers, values outside of JavaScript's safe number range
  796. * (`Number.MIN_SAFE_INTEGER` to `Number.MAX_SAFE_INTEGER`) are also subject to
  797. * precision loss. Furthermore, once processed by the Firestore backend, all
  798. * integer operations are capped between -2^63 and 2^63-1.
  799. *
  800. * If the current field value is not of type `number`, or if the field does not
  801. * yet exist, the transformation sets the field to the given value.
  802. *
  803. * @param n - The value to increment by.
  804. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  805. * `updateDoc()`
  806. */
  807. export declare function increment(n: number): FieldValue;
  808. /**
  809. * Initializes a new instance of Cloud Firestore with the provided settings.
  810. * Can only be called before any other functions, including
  811. * {@link (getFirestore:1)}. If the custom settings are empty, this function is
  812. * equivalent to calling {@link (getFirestore:1)}.
  813. *
  814. * @param app - The {@link @firebase/app#FirebaseApp} with which the `Firestore` instance will
  815. * be associated.
  816. * @param settings - A settings object to configure the `Firestore` instance.
  817. * @returns A newly initialized `Firestore` instance.
  818. */
  819. export declare function initializeFirestore(app: FirebaseApp, settings: Settings): Firestore;
  820. /* Excluded declaration from this release type: initializeFirestore */
  821. /**
  822. * Creates a {@link QueryLimitConstraint} that only returns the first matching
  823. * documents.
  824. *
  825. * @param limit - The maximum number of items to return.
  826. * @returns The created {@link QueryLimitConstraint}.
  827. */
  828. export declare function limit(limit: number): QueryLimitConstraint;
  829. /**
  830. * Creates a {@link QueryLimitConstraint} that only returns the last matching
  831. * documents.
  832. *
  833. * You must specify at least one `orderBy` clause for `limitToLast` queries,
  834. * otherwise an exception will be thrown during execution.
  835. *
  836. * @param limit - The maximum number of items to return.
  837. * @returns The created {@link QueryLimitConstraint}.
  838. */
  839. export declare function limitToLast(limit: number): QueryLimitConstraint;
  840. export { LogLevel };
  841. /**
  842. * For each field (e.g. 'bar'), find all nested keys (e.g. {'bar.baz': T1,
  843. * 'bar.qux': T2}). Intersect them together to make a single map containing
  844. * all possible keys that are all marked as optional
  845. */
  846. export declare type NestedUpdateFields<T extends Record<string, unknown>> = UnionToIntersection<{
  847. [K in keyof T & string]: ChildUpdateFields<K, T[K]>;
  848. }[keyof T & string]>;
  849. /**
  850. * Creates a {@link QueryOrderByConstraint} that sorts the query result by the
  851. * specified field, optionally in descending order instead of ascending.
  852. *
  853. * Note: Documents that do not contain the specified field will not be present
  854. * in the query result.
  855. *
  856. * @param fieldPath - The field to sort by.
  857. * @param directionStr - Optional direction to sort by ('asc' or 'desc'). If
  858. * not specified, order will be ascending.
  859. * @returns The created {@link QueryOrderByConstraint}.
  860. */
  861. export declare function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryOrderByConstraint;
  862. /**
  863. * The direction of a {@link orderBy} clause is specified as 'desc' or 'asc'
  864. * (descending or ascending).
  865. */
  866. export declare type OrderByDirection = 'desc' | 'asc';
  867. /**
  868. * Similar to Typescript's `Partial<T>`, but allows nested fields to be
  869. * omitted and FieldValues to be passed in as property values.
  870. */
  871. export declare type PartialWithFieldValue<T> = Partial<T> | (T extends Primitive ? T : T extends {} ? {
  872. [K in keyof T]?: PartialWithFieldValue<T[K]> | FieldValue;
  873. } : never);
  874. /**
  875. * These types primarily exist to support the `UpdateData`,
  876. * `WithFieldValue`, and `PartialWithFieldValue` types and are not consumed
  877. * directly by the end developer.
  878. */
  879. /** Primitive types. */
  880. export declare type Primitive = string | number | boolean | undefined | null;
  881. /**
  882. * A `Query` refers to a query which you can read or listen to. You can also
  883. * construct refined `Query` objects by adding filters and ordering.
  884. */
  885. export declare class Query<T = DocumentData> {
  886. /**
  887. * If provided, the `FirestoreDataConverter` associated with this instance.
  888. */
  889. readonly converter: FirestoreDataConverter<T> | null;
  890. /** The type of this Firestore reference. */
  891. readonly type: 'query' | 'collection';
  892. /**
  893. * The `Firestore` instance for the Firestore database (useful for performing
  894. * transactions, etc.).
  895. */
  896. readonly firestore: Firestore;
  897. protected constructor();
  898. /**
  899. * Removes the current converter.
  900. *
  901. * @param converter - `null` removes the current converter.
  902. * @returns A `Query<DocumentData>` that does not use a converter.
  903. */
  904. withConverter(converter: null): Query<DocumentData>;
  905. /**
  906. * Applies a custom data converter to this query, allowing you to use your own
  907. * custom model objects with Firestore. When you call {@link getDocs} with
  908. * the returned query, the provided converter will convert between Firestore
  909. * data and your custom type `U`.
  910. *
  911. * @param converter - Converts objects to and from Firestore.
  912. * @returns A `Query<U>` that uses the provided converter.
  913. */
  914. withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
  915. }
  916. /* Excluded declaration from this release type: query */
  917. /**
  918. * Creates a new immutable instance of {@link Query} that is extended to also
  919. * include additional query constraints.
  920. *
  921. * @param query - The {@link Query} instance to use as a base for the new
  922. * constraints.
  923. * @param queryConstraints - The list of {@link QueryConstraint}s to apply.
  924. * @throws if any of the provided query constraints cannot be combined with the
  925. * existing or new constraints.
  926. */
  927. export declare function query<T>(query: Query<T>, ...queryConstraints: QueryConstraint[]): Query<T>;
  928. /* Excluded from this release type: QueryCompositeFilterConstraint */
  929. /**
  930. * A `QueryConstraint` is used to narrow the set of documents returned by a
  931. * Firestore query. `QueryConstraint`s are created by invoking {@link where},
  932. * {@link orderBy}, {@link startAt}, {@link startAfter}, {@link
  933. * endBefore}, {@link endAt}, {@link limit}, {@link limitToLast} and
  934. * can then be passed to {@link query} to create a new query instance that
  935. * also contains this `QueryConstraint`.
  936. */
  937. export declare abstract class QueryConstraint {
  938. /** The type of this query constraint */
  939. abstract readonly type: QueryConstraintType;
  940. }
  941. /** Describes the different query constraints available in this SDK. */
  942. export declare type QueryConstraintType = 'where' | 'orderBy' | 'limit' | 'limitToLast' | 'startAt' | 'startAfter' | 'endAt' | 'endBefore';
  943. /**
  944. * A `QueryDocumentSnapshot` contains data read from a document in your
  945. * Firestore database as part of a query. The document is guaranteed to exist
  946. * and its data can be extracted with `.data()` or `.get(<field>)` to get a
  947. * specific field.
  948. *
  949. * A `QueryDocumentSnapshot` offers the same API surface as a
  950. * `DocumentSnapshot`. Since query results contain only existing documents, the
  951. * `exists` property will always be true and `data()` will never return
  952. * 'undefined'.
  953. */
  954. export declare class QueryDocumentSnapshot<T = DocumentData> extends DocumentSnapshot<T> {
  955. /**
  956. * Retrieves all fields in the document as an `Object`.
  957. *
  958. * @override
  959. * @returns An `Object` containing all fields in the document.
  960. */
  961. data(): T;
  962. }
  963. /**
  964. * A `QueryEndAtConstraint` is used to exclude documents from the end of a
  965. * result set returned by a Firestore query.
  966. * `QueryEndAtConstraint`s are created by invoking {@link (endAt:1)} or
  967. * {@link (endBefore:1)} and can then be passed to {@link query} to create a new
  968. * query instance that also contains this `QueryEndAtConstraint`.
  969. */
  970. export declare class QueryEndAtConstraint extends QueryConstraint {
  971. /** The type of this query constraint */
  972. readonly type: 'endBefore' | 'endAt';
  973. }
  974. /**
  975. * Returns true if the provided queries point to the same collection and apply
  976. * the same constraints.
  977. *
  978. * @param left - A `Query` to compare.
  979. * @param right - A `Query` to compare.
  980. * @returns true if the references point to the same location in the same
  981. * Firestore database.
  982. */
  983. export declare function queryEqual<T>(left: Query<T>, right: Query<T>): boolean;
  984. /**
  985. * A `QueryFieldFilterConstraint` is used to narrow the set of documents returned by
  986. * a Firestore query by filtering on one or more document fields.
  987. * `QueryFieldFilterConstraint`s are created by invoking {@link where} and can then
  988. * be passed to {@link query} to create a new query instance that also contains
  989. * this `QueryFieldFilterConstraint`.
  990. */
  991. export declare class QueryFieldFilterConstraint extends QueryConstraint {
  992. /** The type of this query constraint */
  993. readonly type = "where";
  994. }
  995. /* Excluded from this release type: QueryFilterConstraint */
  996. /**
  997. * A `QueryLimitConstraint` is used to limit the number of documents returned by
  998. * a Firestore query.
  999. * `QueryLimitConstraint`s are created by invoking {@link limit} or
  1000. * {@link limitToLast} and can then be passed to {@link query} to create a new
  1001. * query instance that also contains this `QueryLimitConstraint`.
  1002. */
  1003. export declare class QueryLimitConstraint extends QueryConstraint {
  1004. /** The type of this query constraint */
  1005. readonly type: 'limit' | 'limitToLast';
  1006. }
  1007. /**
  1008. * `QueryNonFilterConstraint` is a helper union type that represents
  1009. * QueryConstraints which are used to narrow or order the set of documents,
  1010. * but that do not explicitly filter on a document field.
  1011. * `QueryNonFilterConstraint`s are created by invoking {@link orderBy},
  1012. * {@link startAt}, {@link startAfter}, {@link endBefore}, {@link endAt},
  1013. * {@link limit} or {@link limitToLast} and can then be passed to {@link query}
  1014. * to create a new query instance that also contains the `QueryConstraint`.
  1015. */
  1016. export declare type QueryNonFilterConstraint = QueryOrderByConstraint | QueryLimitConstraint | QueryStartAtConstraint | QueryEndAtConstraint;
  1017. /**
  1018. * A `QueryOrderByConstraint` is used to sort the set of documents returned by a
  1019. * Firestore query. `QueryOrderByConstraint`s are created by invoking
  1020. * {@link orderBy} and can then be passed to {@link query} to create a new query
  1021. * instance that also contains this `QueryOrderByConstraint`.
  1022. *
  1023. * Note: Documents that do not contain the orderBy field will not be present in
  1024. * the query result.
  1025. */
  1026. export declare class QueryOrderByConstraint extends QueryConstraint {
  1027. /** The type of this query constraint */
  1028. readonly type = "orderBy";
  1029. }
  1030. /**
  1031. * A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects
  1032. * representing the results of a query. The documents can be accessed as an
  1033. * array via the `docs` property or enumerated using the `forEach` method. The
  1034. * number of documents can be determined via the `empty` and `size`
  1035. * properties.
  1036. */
  1037. export declare class QuerySnapshot<T = DocumentData> {
  1038. /**
  1039. * The query on which you called {@link getDocs} in order to get this
  1040. * `QuerySnapshot`.
  1041. */
  1042. readonly query: Query<T>;
  1043. private constructor();
  1044. /** An array of all the documents in the `QuerySnapshot`. */
  1045. get docs(): Array<QueryDocumentSnapshot<T>>;
  1046. /** The number of documents in the `QuerySnapshot`. */
  1047. get size(): number;
  1048. /** True if there are no documents in the `QuerySnapshot`. */
  1049. get empty(): boolean;
  1050. /**
  1051. * Enumerates all of the documents in the `QuerySnapshot`.
  1052. *
  1053. * @param callback - A callback to be called with a `QueryDocumentSnapshot` for
  1054. * each document in the snapshot.
  1055. * @param thisArg - The `this` binding for the callback.
  1056. */
  1057. forEach(callback: (result: QueryDocumentSnapshot<T>) => void, thisArg?: unknown): void;
  1058. }
  1059. /**
  1060. * A `QueryStartAtConstraint` is used to exclude documents from the start of a
  1061. * result set returned by a Firestore query.
  1062. * `QueryStartAtConstraint`s are created by invoking {@link (startAt:1)} or
  1063. * {@link (startAfter:1)} and can then be passed to {@link query} to create a
  1064. * new query instance that also contains this `QueryStartAtConstraint`.
  1065. */
  1066. export declare class QueryStartAtConstraint extends QueryConstraint {
  1067. /** The type of this query constraint */
  1068. readonly type: 'startAt' | 'startAfter';
  1069. }
  1070. /**
  1071. * Returns true if the provided references are equal.
  1072. *
  1073. * @param left - A reference to compare.
  1074. * @param right - A reference to compare.
  1075. * @returns true if the references point to the same location in the same
  1076. * Firestore database.
  1077. */
  1078. export declare function refEqual<T>(left: DocumentReference<T> | CollectionReference<T>, right: DocumentReference<T> | CollectionReference<T>): boolean;
  1079. /* Excluded from this release type: ResourcePath */
  1080. /**
  1081. * Executes the given `updateFunction` and then attempts to commit the changes
  1082. * applied within the transaction. If any document read within the transaction
  1083. * has changed, Cloud Firestore retries the `updateFunction`. If it fails to
  1084. * commit after 5 attempts, the transaction fails.
  1085. *
  1086. * The maximum number of writes allowed in a single transaction is 500.
  1087. *
  1088. * @param firestore - A reference to the Firestore database to run this
  1089. * transaction against.
  1090. * @param updateFunction - The function to execute within the transaction
  1091. * context.
  1092. * @param options - An options object to configure maximum number of attempts to
  1093. * commit.
  1094. * @returns If the transaction completed successfully or was explicitly aborted
  1095. * (the `updateFunction` returned a failed promise), the promise returned by the
  1096. * `updateFunction `is returned here. Otherwise, if the transaction failed, a
  1097. * rejected promise with the corresponding failure error is returned.
  1098. */
  1099. export declare function runTransaction<T>(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
  1100. /**
  1101. * Returns a sentinel used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link @firebase/firestore/lite#(updateDoc:1)} to
  1102. * include a server-generated timestamp in the written data.
  1103. */
  1104. export declare function serverTimestamp(): FieldValue;
  1105. /**
  1106. * Writes to the document referred to by the specified `DocumentReference`. If
  1107. * the document does not yet exist, it will be created.
  1108. *
  1109. * The result of this write will only be reflected in document reads that occur
  1110. * after the returned promise resolves. If the client is offline, the
  1111. * write fails. If you would like to see local modifications or buffer writes
  1112. * until the client is online, use the full Firestore SDK.
  1113. *
  1114. * @param reference - A reference to the document to write.
  1115. * @param data - A map of the fields and values for the document.
  1116. * @throws Error - If the provided input is not a valid Firestore document.
  1117. * @returns A `Promise` resolved once the data has been successfully written
  1118. * to the backend.
  1119. */
  1120. export declare function setDoc<T>(reference: DocumentReference<T>, data: WithFieldValue<T>): Promise<void>;
  1121. /**
  1122. * Writes to the document referred to by the specified `DocumentReference`. If
  1123. * the document does not yet exist, it will be created. If you provide `merge`
  1124. * or `mergeFields`, the provided data can be merged into an existing document.
  1125. *
  1126. * The result of this write will only be reflected in document reads that occur
  1127. * after the returned promise resolves. If the client is offline, the
  1128. * write fails. If you would like to see local modifications or buffer writes
  1129. * until the client is online, use the full Firestore SDK.
  1130. *
  1131. * @param reference - A reference to the document to write.
  1132. * @param data - A map of the fields and values for the document.
  1133. * @param options - An object to configure the set behavior.
  1134. * @throws Error - If the provided input is not a valid Firestore document.
  1135. * @returns A `Promise` resolved once the data has been successfully written
  1136. * to the backend.
  1137. */
  1138. export declare function setDoc<T>(reference: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): Promise<void>;
  1139. /**
  1140. * Sets the verbosity of Cloud Firestore logs (debug, error, or silent).
  1141. *
  1142. * @param logLevel - The verbosity you set for activity and error logging. Can
  1143. * be any of the following values:
  1144. *
  1145. * <ul>
  1146. * <li>`debug` for the most verbose logging level, primarily for
  1147. * debugging.</li>
  1148. * <li>`error` to log errors only.</li>
  1149. * <li><code>`silent` to turn off logging.</li>
  1150. * </ul>
  1151. */
  1152. export declare function setLogLevel(logLevel: LogLevel): void;
  1153. /**
  1154. * An options object that configures the behavior of {@link @firebase/firestore/lite#(setDoc:1)}, {@link
  1155. * @firebase/firestore/lite#(WriteBatch.set:1)} and {@link @firebase/firestore/lite#(Transaction.set:1)} calls. These calls can be
  1156. * configured to perform granular merges instead of overwriting the target
  1157. * documents in their entirety by providing a `SetOptions` with `merge: true`.
  1158. *
  1159. * @param merge - Changes the behavior of a `setDoc()` call to only replace the
  1160. * values specified in its data argument. Fields omitted from the `setDoc()`
  1161. * call remain untouched. If your input sets any field to an empty map, all
  1162. * nested fields are overwritten.
  1163. * @param mergeFields - Changes the behavior of `setDoc()` calls to only replace
  1164. * the specified field paths. Any field path that is not specified is ignored
  1165. * and remains untouched. If your input sets any field to an empty map, all
  1166. * nested fields are overwritten.
  1167. */
  1168. export declare type SetOptions = {
  1169. readonly merge?: boolean;
  1170. } | {
  1171. readonly mergeFields?: Array<string | FieldPath>;
  1172. };
  1173. /**
  1174. * Specifies custom configurations for your Cloud Firestore instance.
  1175. * You must set these before invoking any other methods.
  1176. */
  1177. export declare interface Settings {
  1178. /** The hostname to connect to. */
  1179. host?: string;
  1180. /** Whether to use SSL when connecting. */
  1181. ssl?: boolean;
  1182. /**
  1183. * Whether to skip nested properties that are set to `undefined` during
  1184. * object serialization. If set to `true`, these properties are skipped
  1185. * and not written to Firestore. If set to `false` or omitted, the SDK
  1186. * throws an exception when it encounters properties of type `undefined`.
  1187. */
  1188. ignoreUndefinedProperties?: boolean;
  1189. }
  1190. /**
  1191. * Returns true if the provided snapshots are equal.
  1192. *
  1193. * @param left - A snapshot to compare.
  1194. * @param right - A snapshot to compare.
  1195. * @returns true if the snapshots are equal.
  1196. */
  1197. export declare function snapshotEqual<T>(left: DocumentSnapshot<T> | QuerySnapshot<T>, right: DocumentSnapshot<T> | QuerySnapshot<T>): boolean;
  1198. /**
  1199. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  1200. * start after the provided document (exclusive). The starting position is
  1201. * relative to the order of the query. The document must contain all of the
  1202. * fields provided in the orderBy of the query.
  1203. *
  1204. * @param snapshot - The snapshot of the document to start after.
  1205. * @returns A {@link QueryStartAtConstraint} to pass to `query()`
  1206. */
  1207. export declare function startAfter(snapshot: DocumentSnapshot<unknown>): QueryStartAtConstraint;
  1208. /**
  1209. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  1210. * start after the provided fields relative to the order of the query. The order
  1211. * of the field values must match the order of the order by clauses of the query.
  1212. *
  1213. * @param fieldValues - The field values to start this query after, in order
  1214. * of the query's order by.
  1215. * @returns A {@link QueryStartAtConstraint} to pass to `query()`
  1216. */
  1217. export declare function startAfter(...fieldValues: unknown[]): QueryStartAtConstraint;
  1218. /**
  1219. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  1220. * start at the provided document (inclusive). The starting position is relative
  1221. * to the order of the query. The document must contain all of the fields
  1222. * provided in the `orderBy` of this query.
  1223. *
  1224. * @param snapshot - The snapshot of the document to start at.
  1225. * @returns A {@link QueryStartAtConstraint} to pass to `query()`.
  1226. */
  1227. export declare function startAt(snapshot: DocumentSnapshot<unknown>): QueryStartAtConstraint;
  1228. /**
  1229. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  1230. * start at the provided fields relative to the order of the query. The order of
  1231. * the field values must match the order of the order by clauses of the query.
  1232. *
  1233. * @param fieldValues - The field values to start this query at, in order
  1234. * of the query's order by.
  1235. * @returns A {@link QueryStartAtConstraint} to pass to `query()`.
  1236. */
  1237. export declare function startAt(...fieldValues: unknown[]): QueryStartAtConstraint;
  1238. /**
  1239. * Terminates the provided `Firestore` instance.
  1240. *
  1241. * After calling `terminate()` only the `clearIndexedDbPersistence()` functions
  1242. * may be used. Any other function will throw a `FirestoreError`. Termination
  1243. * does not cancel any pending writes, and any promises that are awaiting a
  1244. * response from the server will not be resolved.
  1245. *
  1246. * To restart after termination, create a new instance of `Firestore` with
  1247. * {@link (getFirestore:1)}.
  1248. *
  1249. * Note: Under normal circumstances, calling `terminate()` is not required. This
  1250. * function is useful only when you want to force this instance to release all of
  1251. * its resources or in combination with {@link clearIndexedDbPersistence} to
  1252. * ensure that all local state is destroyed between test runs.
  1253. *
  1254. * @param firestore - The `Firestore` instance to terminate.
  1255. * @returns A `Promise` that is resolved when the instance has been successfully
  1256. * terminated.
  1257. */
  1258. export declare function terminate(firestore: Firestore): Promise<void>;
  1259. /**
  1260. * @license
  1261. * Copyright 2017 Google LLC
  1262. *
  1263. * Licensed under the Apache License, Version 2.0 (the "License");
  1264. * you may not use this file except in compliance with the License.
  1265. * You may obtain a copy of the License at
  1266. *
  1267. * http://www.apache.org/licenses/LICENSE-2.0
  1268. *
  1269. * Unless required by applicable law or agreed to in writing, software
  1270. * distributed under the License is distributed on an "AS IS" BASIS,
  1271. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1272. * See the License for the specific language governing permissions and
  1273. * limitations under the License.
  1274. */
  1275. /**
  1276. * A `Timestamp` represents a point in time independent of any time zone or
  1277. * calendar, represented as seconds and fractions of seconds at nanosecond
  1278. * resolution in UTC Epoch time.
  1279. *
  1280. * It is encoded using the Proleptic Gregorian Calendar which extends the
  1281. * Gregorian calendar backwards to year one. It is encoded assuming all minutes
  1282. * are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second
  1283. * table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to
  1284. * 9999-12-31T23:59:59.999999999Z.
  1285. *
  1286. * For examples and further specifications, refer to the
  1287. * {@link https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto | Timestamp definition}.
  1288. */
  1289. export declare class Timestamp {
  1290. /**
  1291. * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
  1292. */
  1293. readonly seconds: number;
  1294. /**
  1295. * The fractions of a second at nanosecond resolution.*
  1296. */
  1297. readonly nanoseconds: number;
  1298. /**
  1299. * Creates a new timestamp with the current date, with millisecond precision.
  1300. *
  1301. * @returns a new timestamp representing the current date.
  1302. */
  1303. static now(): Timestamp;
  1304. /**
  1305. * Creates a new timestamp from the given date.
  1306. *
  1307. * @param date - The date to initialize the `Timestamp` from.
  1308. * @returns A new `Timestamp` representing the same point in time as the given
  1309. * date.
  1310. */
  1311. static fromDate(date: Date): Timestamp;
  1312. /**
  1313. * Creates a new timestamp from the given number of milliseconds.
  1314. *
  1315. * @param milliseconds - Number of milliseconds since Unix epoch
  1316. * 1970-01-01T00:00:00Z.
  1317. * @returns A new `Timestamp` representing the same point in time as the given
  1318. * number of milliseconds.
  1319. */
  1320. static fromMillis(milliseconds: number): Timestamp;
  1321. /**
  1322. * Creates a new timestamp.
  1323. *
  1324. * @param seconds - The number of seconds of UTC time since Unix epoch
  1325. * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
  1326. * 9999-12-31T23:59:59Z inclusive.
  1327. * @param nanoseconds - The non-negative fractions of a second at nanosecond
  1328. * resolution. Negative second values with fractions must still have
  1329. * non-negative nanoseconds values that count forward in time. Must be
  1330. * from 0 to 999,999,999 inclusive.
  1331. */
  1332. constructor(
  1333. /**
  1334. * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
  1335. */
  1336. seconds: number,
  1337. /**
  1338. * The fractions of a second at nanosecond resolution.*
  1339. */
  1340. nanoseconds: number);
  1341. /**
  1342. * Converts a `Timestamp` to a JavaScript `Date` object. This conversion
  1343. * causes a loss of precision since `Date` objects only support millisecond
  1344. * precision.
  1345. *
  1346. * @returns JavaScript `Date` object representing the same point in time as
  1347. * this `Timestamp`, with millisecond precision.
  1348. */
  1349. toDate(): Date;
  1350. /**
  1351. * Converts a `Timestamp` to a numeric timestamp (in milliseconds since
  1352. * epoch). This operation causes a loss of precision.
  1353. *
  1354. * @returns The point in time corresponding to this timestamp, represented as
  1355. * the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
  1356. */
  1357. toMillis(): number;
  1358. /**
  1359. * Returns true if this `Timestamp` is equal to the provided one.
  1360. *
  1361. * @param other - The `Timestamp` to compare against.
  1362. * @returns true if this `Timestamp` is equal to the provided one.
  1363. */
  1364. isEqual(other: Timestamp): boolean;
  1365. /** Returns a textual representation of this `Timestamp`. */
  1366. toString(): string;
  1367. /** Returns a JSON-serializable representation of this `Timestamp`. */
  1368. toJSON(): {
  1369. seconds: number;
  1370. nanoseconds: number;
  1371. };
  1372. /**
  1373. * Converts this object to a primitive string, which allows `Timestamp` objects
  1374. * to be compared using the `>`, `<=`, `>=` and `>` operators.
  1375. */
  1376. valueOf(): string;
  1377. }
  1378. /**
  1379. * A reference to a transaction.
  1380. *
  1381. * The `Transaction` object passed to a transaction's `updateFunction` provides
  1382. * the methods to read and write data within the transaction context. See
  1383. * {@link runTransaction}.
  1384. */
  1385. export declare class Transaction {
  1386. private constructor();
  1387. /**
  1388. * Reads the document referenced by the provided {@link DocumentReference}.
  1389. *
  1390. * @param documentRef - A reference to the document to be read.
  1391. * @returns A `DocumentSnapshot` with the read data.
  1392. */
  1393. get<T>(documentRef: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
  1394. /**
  1395. * Writes to the document referred to by the provided {@link
  1396. * DocumentReference}. If the document does not exist yet, it will be created.
  1397. *
  1398. * @param documentRef - A reference to the document to be set.
  1399. * @param data - An object of the fields and values for the document.
  1400. * @throws Error - If the provided input is not a valid Firestore document.
  1401. * @returns This `Transaction` instance. Used for chaining method calls.
  1402. */
  1403. set<T>(documentRef: DocumentReference<T>, data: WithFieldValue<T>): this;
  1404. /**
  1405. * Writes to the document referred to by the provided {@link
  1406. * DocumentReference}. If the document does not exist yet, it will be created.
  1407. * If you provide `merge` or `mergeFields`, the provided data can be merged
  1408. * into an existing document.
  1409. *
  1410. * @param documentRef - A reference to the document to be set.
  1411. * @param data - An object of the fields and values for the document.
  1412. * @param options - An object to configure the set behavior.
  1413. * @throws Error - If the provided input is not a valid Firestore document.
  1414. * @returns This `Transaction` instance. Used for chaining method calls.
  1415. */
  1416. set<T>(documentRef: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): this;
  1417. /**
  1418. * Updates fields in the document referred to by the provided {@link
  1419. * DocumentReference}. The update will fail if applied to a document that does
  1420. * not exist.
  1421. *
  1422. * @param documentRef - A reference to the document to be updated.
  1423. * @param data - An object containing the fields and values with which to
  1424. * update the document. Fields can contain dots to reference nested fields
  1425. * within the document.
  1426. * @throws Error - If the provided input is not valid Firestore data.
  1427. * @returns This `Transaction` instance. Used for chaining method calls.
  1428. */
  1429. update<T>(documentRef: DocumentReference<T>, data: UpdateData<T>): this;
  1430. /**
  1431. * Updates fields in the document referred to by the provided {@link
  1432. * DocumentReference}. The update will fail if applied to a document that does
  1433. * not exist.
  1434. *
  1435. * Nested fields can be updated by providing dot-separated field path
  1436. * strings or by providing `FieldPath` objects.
  1437. *
  1438. * @param documentRef - A reference to the document to be updated.
  1439. * @param field - The first field to update.
  1440. * @param value - The first value.
  1441. * @param moreFieldsAndValues - Additional key/value pairs.
  1442. * @throws Error - If the provided input is not valid Firestore data.
  1443. * @returns This `Transaction` instance. Used for chaining method calls.
  1444. */
  1445. update(documentRef: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this;
  1446. /**
  1447. * Deletes the document referred to by the provided {@link DocumentReference}.
  1448. *
  1449. * @param documentRef - A reference to the document to be deleted.
  1450. * @returns This `Transaction` instance. Used for chaining method calls.
  1451. */
  1452. delete(documentRef: DocumentReference<unknown>): this;
  1453. }
  1454. /**
  1455. * @license
  1456. * Copyright 2022 Google LLC
  1457. *
  1458. * Licensed under the Apache License, Version 2.0 (the "License");
  1459. * you may not use this file except in compliance with the License.
  1460. * You may obtain a copy of the License at
  1461. *
  1462. * http://www.apache.org/licenses/LICENSE-2.0
  1463. *
  1464. * Unless required by applicable law or agreed to in writing, software
  1465. * distributed under the License is distributed on an "AS IS" BASIS,
  1466. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1467. * See the License for the specific language governing permissions and
  1468. * limitations under the License.
  1469. */
  1470. /**
  1471. * Options to customize transaction behavior.
  1472. */
  1473. export declare interface TransactionOptions {
  1474. /** Maximum number of attempts to commit, after which transaction fails. Default is 5. */
  1475. readonly maxAttempts?: number;
  1476. }
  1477. /**
  1478. * Given a union type `U = T1 | T2 | ...`, returns an intersected type
  1479. * `(T1 & T2 & ...)`.
  1480. *
  1481. * Uses distributive conditional types and inference from conditional types.
  1482. * This works because multiple candidates for the same type variable in
  1483. * contra-variant positions causes an intersection type to be inferred.
  1484. * https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-inference-in-conditional-types
  1485. * https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
  1486. */
  1487. export declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
  1488. /**
  1489. * Update data (for use with {@link (updateDoc:1)}) that consists of field paths
  1490. * (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots
  1491. * reference nested fields within the document. FieldValues can be passed in
  1492. * as property values.
  1493. */
  1494. export declare type UpdateData<T> = T extends Primitive ? T : T extends {} ? {
  1495. [K in keyof T]?: UpdateData<T[K]> | FieldValue;
  1496. } & NestedUpdateFields<T> : Partial<T>;
  1497. /**
  1498. * Updates fields in the document referred to by the specified
  1499. * `DocumentReference`. The update will fail if applied to a document that does
  1500. * not exist.
  1501. *
  1502. * The result of this update will only be reflected in document reads that occur
  1503. * after the returned promise resolves. If the client is offline, the
  1504. * update fails. If you would like to see local modifications or buffer writes
  1505. * until the client is online, use the full Firestore SDK.
  1506. *
  1507. * @param reference - A reference to the document to update.
  1508. * @param data - An object containing the fields and values with which to
  1509. * update the document. Fields can contain dots to reference nested fields
  1510. * within the document.
  1511. * @throws Error - If the provided input is not valid Firestore data.
  1512. * @returns A `Promise` resolved once the data has been successfully written
  1513. * to the backend.
  1514. */
  1515. export declare function updateDoc<T>(reference: DocumentReference<T>, data: UpdateData<T>): Promise<void>;
  1516. /**
  1517. * Updates fields in the document referred to by the specified
  1518. * `DocumentReference` The update will fail if applied to a document that does
  1519. * not exist.
  1520. *
  1521. * Nested fields can be updated by providing dot-separated field path
  1522. * strings or by providing `FieldPath` objects.
  1523. *
  1524. * The result of this update will only be reflected in document reads that occur
  1525. * after the returned promise resolves. If the client is offline, the
  1526. * update fails. If you would like to see local modifications or buffer writes
  1527. * until the client is online, use the full Firestore SDK.
  1528. *
  1529. * @param reference - A reference to the document to update.
  1530. * @param field - The first field to update.
  1531. * @param value - The first value.
  1532. * @param moreFieldsAndValues - Additional key value pairs.
  1533. * @throws Error - If the provided input is not valid Firestore data.
  1534. * @returns A `Promise` resolved once the data has been successfully written
  1535. * to the backend.
  1536. */
  1537. export declare function updateDoc(reference: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise<void>;
  1538. /**
  1539. * Creates a {@link QueryFieldFilterConstraint} that enforces that documents
  1540. * must contain the specified field and that the value should satisfy the
  1541. * relation constraint provided.
  1542. *
  1543. * @param fieldPath - The path to compare
  1544. * @param opStr - The operation string (e.g "&lt;", "&lt;=", "==", "&lt;",
  1545. * "&lt;=", "!=").
  1546. * @param value - The value for comparison
  1547. * @returns The created {@link QueryFieldFilterConstraint}.
  1548. */
  1549. export declare function where(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown): QueryFieldFilterConstraint;
  1550. /**
  1551. * Filter conditions in a {@link where} clause are specified using the
  1552. * strings '&lt;', '&lt;=', '==', '!=', '&gt;=', '&gt;', 'array-contains', 'in',
  1553. * 'array-contains-any', and 'not-in'.
  1554. */
  1555. export declare type WhereFilterOp = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any' | 'not-in';
  1556. /**
  1557. * Allows FieldValues to be passed in as a property value while maintaining
  1558. * type safety.
  1559. */
  1560. export declare type WithFieldValue<T> = T | (T extends Primitive ? T : T extends {} ? {
  1561. [K in keyof T]: WithFieldValue<T[K]> | FieldValue;
  1562. } : never);
  1563. /**
  1564. * A write batch, used to perform multiple writes as a single atomic unit.
  1565. *
  1566. * A `WriteBatch` object can be acquired by calling {@link writeBatch}. It
  1567. * provides methods for adding writes to the write batch. None of the writes
  1568. * will be committed (or visible locally) until {@link WriteBatch.commit} is
  1569. * called.
  1570. */
  1571. export declare class WriteBatch {
  1572. private constructor();
  1573. /**
  1574. * Writes to the document referred to by the provided {@link
  1575. * DocumentReference}. If the document does not exist yet, it will be created.
  1576. *
  1577. * @param documentRef - A reference to the document to be set.
  1578. * @param data - An object of the fields and values for the document.
  1579. * @returns This `WriteBatch` instance. Used for chaining method calls.
  1580. */
  1581. set<T>(documentRef: DocumentReference<T>, data: WithFieldValue<T>): WriteBatch;
  1582. /**
  1583. * Writes to the document referred to by the provided {@link
  1584. * DocumentReference}. If the document does not exist yet, it will be created.
  1585. * If you provide `merge` or `mergeFields`, the provided data can be merged
  1586. * into an existing document.
  1587. *
  1588. * @param documentRef - A reference to the document to be set.
  1589. * @param data - An object of the fields and values for the document.
  1590. * @param options - An object to configure the set behavior.
  1591. * @throws Error - If the provided input is not a valid Firestore document.
  1592. * @returns This `WriteBatch` instance. Used for chaining method calls.
  1593. */
  1594. set<T>(documentRef: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): WriteBatch;
  1595. /**
  1596. * Updates fields in the document referred to by the provided {@link
  1597. * DocumentReference}. The update will fail if applied to a document that does
  1598. * not exist.
  1599. *
  1600. * @param documentRef - A reference to the document to be updated.
  1601. * @param data - An object containing the fields and values with which to
  1602. * update the document. Fields can contain dots to reference nested fields
  1603. * within the document.
  1604. * @throws Error - If the provided input is not valid Firestore data.
  1605. * @returns This `WriteBatch` instance. Used for chaining method calls.
  1606. */
  1607. update<T>(documentRef: DocumentReference<T>, data: UpdateData<T>): WriteBatch;
  1608. /**
  1609. * Updates fields in the document referred to by this {@link
  1610. * DocumentReference}. The update will fail if applied to a document that does
  1611. * not exist.
  1612. *
  1613. * Nested fields can be update by providing dot-separated field path strings
  1614. * or by providing `FieldPath` objects.
  1615. *
  1616. * @param documentRef - A reference to the document to be updated.
  1617. * @param field - The first field to update.
  1618. * @param value - The first value.
  1619. * @param moreFieldsAndValues - Additional key value pairs.
  1620. * @throws Error - If the provided input is not valid Firestore data.
  1621. * @returns This `WriteBatch` instance. Used for chaining method calls.
  1622. */
  1623. update(documentRef: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch;
  1624. /**
  1625. * Deletes the document referred to by the provided {@link DocumentReference}.
  1626. *
  1627. * @param documentRef - A reference to the document to be deleted.
  1628. * @returns This `WriteBatch` instance. Used for chaining method calls.
  1629. */
  1630. delete(documentRef: DocumentReference<unknown>): WriteBatch;
  1631. /**
  1632. * Commits all of the writes in this write batch as a single atomic unit.
  1633. *
  1634. * The result of these writes will only be reflected in document reads that
  1635. * occur after the returned promise resolves. If the client is offline, the
  1636. * write fails. If you would like to see local modifications or buffer writes
  1637. * until the client is online, use the full Firestore SDK.
  1638. *
  1639. * @returns A `Promise` resolved once all of the writes in the batch have been
  1640. * successfully written to the backend as an atomic unit (note that it won't
  1641. * resolve while you're offline).
  1642. */
  1643. commit(): Promise<void>;
  1644. }
  1645. /**
  1646. * Creates a write batch, used for performing multiple writes as a single
  1647. * atomic operation. The maximum number of writes allowed in a single WriteBatch
  1648. * is 500.
  1649. *
  1650. * The result of these writes will only be reflected in document reads that
  1651. * occur after the returned promise resolves. If the client is offline, the
  1652. * write fails. If you would like to see local modifications or buffer writes
  1653. * until the client is online, use the full Firestore SDK.
  1654. *
  1655. * @returns A `WriteBatch` that can be used to atomically execute multiple
  1656. * writes.
  1657. */
  1658. export declare function writeBatch(firestore: Firestore): WriteBatch;
  1659. export {};