index.d.ts 76 KB

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