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

internal.d.ts 128KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346
  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 { DocumentData as DocumentData_2 } from '@firebase/firestore-types';
  10. import { EmulatorMockTokenOptions } from '@firebase/util';
  11. import { FirebaseApp } from '@firebase/app';
  12. import { FirebaseError } from '@firebase/util';
  13. import { _FirebaseService } from '@firebase/app';
  14. import { LogLevelString as LogLevel } from '@firebase/logger';
  15. import { SetOptions as SetOptions_2 } from '@firebase/firestore-types';
  16. /**
  17. * Converts Firestore's internal types to the JavaScript types that we expose
  18. * to the user.
  19. *
  20. * @internal
  21. */
  22. declare abstract class AbstractUserDataWriter {
  23. convertValue(value: Value, serverTimestampBehavior?: ServerTimestampBehavior): unknown;
  24. private convertObject;
  25. private convertGeoPoint;
  26. private convertArray;
  27. private convertServerTimestamp;
  28. private convertTimestamp;
  29. protected convertDocumentKey(name: string, expectedDatabaseId: DatabaseId): DocumentKey;
  30. protected abstract convertReference(name: string): unknown;
  31. protected abstract convertBytes(bytes: ByteString): unknown;
  32. }
  33. /**
  34. * Add a new document to specified `CollectionReference` with the given data,
  35. * assigning it a document ID automatically.
  36. *
  37. * The result of this write will only be reflected in document reads that occur
  38. * after the returned promise resolves. If the client is offline, the
  39. * write fails. If you would like to see local modifications or buffer writes
  40. * until the client is online, use the full Firestore SDK.
  41. *
  42. * @param reference - A reference to the collection to add this document to.
  43. * @param data - An Object containing the data for the new document.
  44. * @throws Error - If the provided input is not a valid Firestore document.
  45. * @returns A `Promise` resolved with a `DocumentReference` pointing to the
  46. * newly created document after it has been written to the backend.
  47. */
  48. export declare function addDoc<T>(reference: CollectionReference<T>, data: WithFieldValue<T>): Promise<DocumentReference<T>>;
  49. /**
  50. * Returns a new map where every key is prefixed with the outer key appended
  51. * to a dot.
  52. */
  53. export declare type AddPrefixToKeys<Prefix extends string, T extends Record<string, unknown>> = {
  54. [K in keyof T & string as `${Prefix}.${K}`]+?: T[K];
  55. };
  56. /**
  57. * Represents an aggregation that can be performed by Firestore.
  58. */
  59. export declare class AggregateField<T> {
  60. /** A type string to uniquely identify instances of this class. */
  61. type: string;
  62. }
  63. /**
  64. * The union of all `AggregateField` types that are supported by Firestore.
  65. */
  66. export declare type AggregateFieldType = AggregateField<number>;
  67. /**
  68. * The results of executing an aggregation query.
  69. */
  70. export declare class AggregateQuerySnapshot<T extends AggregateSpec> {
  71. private readonly _data;
  72. /** A type string to uniquely identify instances of this class. */
  73. readonly type = "AggregateQuerySnapshot";
  74. /**
  75. * The underlying query over which the aggregations recorded in this
  76. * `AggregateQuerySnapshot` were performed.
  77. */
  78. readonly query: Query<unknown>;
  79. /** @hideconstructor */
  80. constructor(query: Query<unknown>, _data: AggregateSpecData<T>);
  81. /**
  82. * Returns the results of the aggregations performed over the underlying
  83. * query.
  84. *
  85. * The keys of the returned object will be the same as those of the
  86. * `AggregateSpec` object specified to the aggregation method, and the values
  87. * will be the corresponding aggregation result.
  88. *
  89. * @returns The results of the aggregations performed over the underlying
  90. * query.
  91. */
  92. data(): AggregateSpecData<T>;
  93. }
  94. /**
  95. * Compares two `AggregateQuerySnapshot` instances for equality.
  96. *
  97. * Two `AggregateQuerySnapshot` instances are considered "equal" if they have
  98. * underlying queries that compare equal, and the same data.
  99. *
  100. * @param left - The first `AggregateQuerySnapshot` to compare.
  101. * @param right - The second `AggregateQuerySnapshot` to compare.
  102. *
  103. * @returns `true` if the objects are "equal", as defined above, or `false`
  104. * otherwise.
  105. */
  106. export declare function aggregateQuerySnapshotEqual<T extends AggregateSpec>(left: AggregateQuerySnapshot<T>, right: AggregateQuerySnapshot<T>): boolean;
  107. /**
  108. * A type whose property values are all `AggregateField` objects.
  109. */
  110. export declare interface AggregateSpec {
  111. [field: string]: AggregateFieldType;
  112. }
  113. /**
  114. * A type whose keys are taken from an `AggregateSpec`, and whose values are the
  115. * result of the aggregation performed by the corresponding `AggregateField`
  116. * from the input `AggregateSpec`.
  117. */
  118. export declare type AggregateSpecData<T extends AggregateSpec> = {
  119. [P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
  120. };
  121. /**
  122. * Creates a new {@link QueryCompositeFilterConstraint} that is a conjunction of
  123. * the given filter constraints. A conjunction filter includes a document if it
  124. * satisfies all of the given filters.
  125. *
  126. * @param queryConstraints - Optional. The list of
  127. * {@link QueryFilterConstraint}s to perform a conjunction for. These must be
  128. * created with calls to {@link where}, {@link or}, or {@link and}.
  129. * @returns The newly created {@link QueryCompositeFilterConstraint}.
  130. * @internal TODO remove this internal tag with OR Query support in the server
  131. */
  132. export declare function and(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;
  133. declare interface ApiClientObjectMap<T> {
  134. [k: string]: T;
  135. }
  136. /**
  137. * An `AppliableConstraint` is an abstraction of a constraint that can be applied
  138. * to a Firestore query.
  139. */
  140. declare abstract class AppliableConstraint {
  141. /**
  142. * Takes the provided {@link Query} and returns a copy of the {@link Query} with this
  143. * {@link AppliableConstraint} applied.
  144. */
  145. abstract _apply<T>(query: Query<T>): Query<T>;
  146. }
  147. /**
  148. * Returns a special value that can be used with {@link (setDoc:1)} or {@link
  149. * updateDoc:1} that tells the server to remove the given elements from any
  150. * array value that already exists on the server. All instances of each element
  151. * specified will be removed from the array. If the field being modified is not
  152. * already an array it will be overwritten with an empty array.
  153. *
  154. * @param elements - The elements to remove from the array.
  155. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  156. * `updateDoc()`
  157. */
  158. export declare function arrayRemove(...elements: unknown[]): FieldValue;
  159. /**
  160. * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link
  161. * @firebase/firestore/lite#(updateDoc:1)} that tells the server to union the given elements with any array
  162. * value that already exists on the server. Each specified element that doesn't
  163. * already exist in the array will be added to the end. If the field being
  164. * modified is not already an array it will be overwritten with an array
  165. * containing exactly the specified elements.
  166. *
  167. * @param elements - The elements to union into the array.
  168. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  169. * `updateDoc()`.
  170. */
  171. export declare function arrayUnion(...elements: unknown[]): FieldValue;
  172. declare interface AsyncQueue {
  173. readonly isShuttingDown: boolean;
  174. /**
  175. * Adds a new operation to the queue without waiting for it to complete (i.e.
  176. * we ignore the Promise result).
  177. */
  178. enqueueAndForget<T extends unknown>(op: () => Promise<T>): void;
  179. /**
  180. * Regardless if the queue has initialized shutdown, adds a new operation to the
  181. * queue without waiting for it to complete (i.e. we ignore the Promise result).
  182. */
  183. enqueueAndForgetEvenWhileRestricted<T extends unknown>(op: () => Promise<T>): void;
  184. /**
  185. * Initialize the shutdown of this queue. Once this method is called, the
  186. * only possible way to request running an operation is through
  187. * `enqueueEvenWhileRestricted()`.
  188. *
  189. * @param purgeExistingTasks Whether already enqueued tasked should be
  190. * rejected (unless enqueued wih `enqueueEvenWhileRestricted()`). Defaults
  191. * to false.
  192. */
  193. enterRestrictedMode(purgeExistingTasks?: boolean): void;
  194. /**
  195. * Adds a new operation to the queue. Returns a promise that will be resolved
  196. * when the promise returned by the new operation is (with its value).
  197. */
  198. enqueue<T extends unknown>(op: () => Promise<T>): Promise<T>;
  199. /**
  200. * Enqueue a retryable operation.
  201. *
  202. * A retryable operation is rescheduled with backoff if it fails with a
  203. * IndexedDbTransactionError (the error type used by SimpleDb). All
  204. * retryable operations are executed in order and only run if all prior
  205. * operations were retried successfully.
  206. */
  207. enqueueRetryable(op: () => Promise<void>): void;
  208. /**
  209. * Schedules an operation to be queued on the AsyncQueue once the specified
  210. * `delayMs` has elapsed. The returned DelayedOperation can be used to cancel
  211. * or fast-forward the operation prior to its running.
  212. */
  213. enqueueAfterDelay<T extends unknown>(timerId: TimerId, delayMs: number, op: () => Promise<T>): DelayedOperation<T>;
  214. /**
  215. * Verifies there's an operation currently in-progress on the AsyncQueue.
  216. * Unfortunately we can't verify that the running code is in the promise chain
  217. * of that operation, so this isn't a foolproof check, but it should be enough
  218. * to catch some bugs.
  219. */
  220. verifyOperationInProgress(): void;
  221. }
  222. declare type AuthTokenFactory = () => string;
  223. /**
  224. * Path represents an ordered sequence of string segments.
  225. */
  226. declare abstract class BasePath<B extends BasePath<B>> {
  227. private segments;
  228. private offset;
  229. private len;
  230. constructor(segments: string[], offset?: number, length?: number);
  231. /**
  232. * Abstract constructor method to construct an instance of B with the given
  233. * parameters.
  234. */
  235. protected abstract construct(segments: string[], offset?: number, length?: number): B;
  236. /**
  237. * Returns a String representation.
  238. *
  239. * Implementing classes are required to provide deterministic implementations as
  240. * the String representation is used to obtain canonical Query IDs.
  241. */
  242. abstract toString(): string;
  243. get length(): number;
  244. isEqual(other: B): boolean;
  245. child(nameOrPath: string | B): B;
  246. /** The index of one past the last segment of the path. */
  247. private limit;
  248. popFirst(size?: number): B;
  249. popLast(): B;
  250. firstSegment(): string;
  251. lastSegment(): string;
  252. get(index: number): string;
  253. isEmpty(): boolean;
  254. isPrefixOf(other: this): boolean;
  255. isImmediateParentOf(potentialChild: this): boolean;
  256. forEach(fn: (segment: string) => void): void;
  257. toArray(): string[];
  258. static comparator<T extends BasePath<T>>(p1: BasePath<T>, p2: BasePath<T>): number;
  259. }
  260. /**
  261. * Represents a bound of a query.
  262. *
  263. * The bound is specified with the given components representing a position and
  264. * whether it's just before or just after the position (relative to whatever the
  265. * query order is).
  266. *
  267. * The position represents a logical index position for a query. It's a prefix
  268. * of values for the (potentially implicit) order by clauses of a query.
  269. *
  270. * Bound provides a function to determine whether a document comes before or
  271. * after a bound. This is influenced by whether the position is just before or
  272. * just after the provided values.
  273. */
  274. declare class Bound {
  275. readonly position: Value[];
  276. readonly inclusive: boolean;
  277. constructor(position: Value[], inclusive: boolean);
  278. }
  279. /**
  280. * An immutable object representing an array of bytes.
  281. */
  282. export declare class Bytes {
  283. _byteString: ByteString;
  284. /** @hideconstructor */
  285. constructor(byteString: ByteString);
  286. /**
  287. * Creates a new `Bytes` object from the given Base64 string, converting it to
  288. * bytes.
  289. *
  290. * @param base64 - The Base64 string used to create the `Bytes` object.
  291. */
  292. static fromBase64String(base64: string): Bytes;
  293. /**
  294. * Creates a new `Bytes` object from the given Uint8Array.
  295. *
  296. * @param array - The Uint8Array used to create the `Bytes` object.
  297. */
  298. static fromUint8Array(array: Uint8Array): Bytes;
  299. /**
  300. * Returns the underlying bytes as a Base64-encoded string.
  301. *
  302. * @returns The Base64-encoded string created from the `Bytes` object.
  303. */
  304. toBase64(): string;
  305. /**
  306. * Returns the underlying bytes in a new `Uint8Array`.
  307. *
  308. * @returns The Uint8Array created from the `Bytes` object.
  309. */
  310. toUint8Array(): Uint8Array;
  311. /**
  312. * Returns a string representation of the `Bytes` object.
  313. *
  314. * @returns A string representation of the `Bytes` object.
  315. */
  316. toString(): string;
  317. /**
  318. * Returns true if this `Bytes` object is equal to the provided one.
  319. *
  320. * @param other - The `Bytes` object to compare against.
  321. * @returns true if this `Bytes` object is equal to the provided one.
  322. */
  323. isEqual(other: Bytes): boolean;
  324. }
  325. /**
  326. * @license
  327. * Copyright 2020 Google LLC
  328. *
  329. * Licensed under the Apache License, Version 2.0 (the "License");
  330. * you may not use this file except in compliance with the License.
  331. * You may obtain a copy of the License at
  332. *
  333. * http://www.apache.org/licenses/LICENSE-2.0
  334. *
  335. * Unless required by applicable law or agreed to in writing, software
  336. * distributed under the License is distributed on an "AS IS" BASIS,
  337. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  338. * See the License for the specific language governing permissions and
  339. * limitations under the License.
  340. */
  341. /**
  342. * Immutable class that represents a "proto" byte string.
  343. *
  344. * Proto byte strings can either be Base64-encoded strings or Uint8Arrays when
  345. * sent on the wire. This class abstracts away this differentiation by holding
  346. * the proto byte string in a common class that must be converted into a string
  347. * before being sent as a proto.
  348. * @internal
  349. */
  350. declare class ByteString {
  351. private readonly binaryString;
  352. static readonly EMPTY_BYTE_STRING: ByteString;
  353. private constructor();
  354. static fromBase64String(base64: string): ByteString;
  355. static fromUint8Array(array: Uint8Array): ByteString;
  356. [Symbol.iterator](): Iterator<number>;
  357. toBase64(): string;
  358. toUint8Array(): Uint8Array;
  359. approximateByteSize(): number;
  360. compareTo(other: ByteString): number;
  361. isEqual(other: ByteString): boolean;
  362. }
  363. /**
  364. * Helper for calculating the nested fields for a given type T1. This is needed
  365. * to distribute union types such as `undefined | {...}` (happens for optional
  366. * props) or `{a: A} | {b: B}`.
  367. *
  368. * In this use case, `V` is used to distribute the union types of `T[K]` on
  369. * `Record`, since `T[K]` is evaluated as an expression and not distributed.
  370. *
  371. * See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types
  372. */
  373. export declare type ChildUpdateFields<K extends string, V> = V extends Record<string, unknown> ? AddPrefixToKeys<K, UpdateData<V>> : never;
  374. /**
  375. * Gets a `CollectionReference` instance that refers to the collection at
  376. * the specified absolute path.
  377. *
  378. * @param firestore - A reference to the root `Firestore` instance.
  379. * @param path - A slash-separated path to a collection.
  380. * @param pathSegments - Additional path segments to apply relative to the first
  381. * argument.
  382. * @throws If the final path has an even number of segments and does not point
  383. * to a collection.
  384. * @returns The `CollectionReference` instance.
  385. */
  386. export declare function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
  387. /**
  388. * Gets a `CollectionReference` instance that refers to a subcollection of
  389. * `reference` at the the specified relative path.
  390. *
  391. * @param reference - A reference to a collection.
  392. * @param path - A slash-separated path to a collection.
  393. * @param pathSegments - Additional path segments to apply relative to the first
  394. * argument.
  395. * @throws If the final path has an even number of segments and does not point
  396. * to a collection.
  397. * @returns The `CollectionReference` instance.
  398. */
  399. export declare function collection(reference: CollectionReference<unknown>, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
  400. /**
  401. * Gets a `CollectionReference` instance that refers to a subcollection of
  402. * `reference` at the the specified relative path.
  403. *
  404. * @param reference - A reference to a Firestore document.
  405. * @param path - A slash-separated path to a collection.
  406. * @param pathSegments - Additional path segments that will be applied relative
  407. * to the first argument.
  408. * @throws If the final path has an even number of segments and does not point
  409. * to a collection.
  410. * @returns The `CollectionReference` instance.
  411. */
  412. export declare function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
  413. /**
  414. * Creates and returns a new `Query` instance that includes all documents in the
  415. * database that are contained in a collection or subcollection with the
  416. * given `collectionId`.
  417. *
  418. * @param firestore - A reference to the root `Firestore` instance.
  419. * @param collectionId - Identifies the collections to query over. Every
  420. * collection or subcollection with this ID as the last segment of its path
  421. * will be included. Cannot contain a slash.
  422. * @returns The created `Query`.
  423. */
  424. export declare function collectionGroup(firestore: Firestore, collectionId: string): Query<DocumentData>;
  425. /**
  426. * A `CollectionReference` object can be used for adding documents, getting
  427. * document references, and querying for documents (using {@link query}).
  428. */
  429. export declare class CollectionReference<T = DocumentData> extends Query<T> {
  430. readonly _path: ResourcePath;
  431. /** The type of this Firestore reference. */
  432. readonly type = "collection";
  433. /** @hideconstructor */
  434. constructor(firestore: Firestore, converter: FirestoreDataConverter<T> | null, _path: ResourcePath);
  435. /** The collection's identifier. */
  436. get id(): string;
  437. /**
  438. * A string representing the path of the referenced collection (relative
  439. * to the root of the database).
  440. */
  441. get path(): string;
  442. /**
  443. * A reference to the containing `DocumentReference` if this is a
  444. * subcollection. If this isn't a subcollection, the reference is null.
  445. */
  446. get parent(): DocumentReference<DocumentData> | null;
  447. /**
  448. * Applies a custom data converter to this `CollectionReference`, allowing you
  449. * to use your own custom model objects with Firestore. When you call {@link
  450. * addDoc} with the returned `CollectionReference` instance, the provided
  451. * converter will convert between Firestore data and your custom type `U`.
  452. *
  453. * @param converter - Converts objects to and from Firestore.
  454. * @returns A `CollectionReference<U>` that uses the provided converter.
  455. */
  456. withConverter<U>(converter: FirestoreDataConverter<U>): CollectionReference<U>;
  457. /**
  458. * Removes the current converter.
  459. *
  460. * @param converter - `null` removes the current converter.
  461. * @returns A `CollectionReference<DocumentData>` that does not use a
  462. * converter.
  463. */
  464. withConverter(converter: null): CollectionReference<DocumentData>;
  465. }
  466. declare type CompositeFilterOp = 'OPERATOR_UNSPECIFIED' | 'AND' | 'OR';
  467. declare const enum CompositeOperator {
  468. OR = "or",
  469. AND = "and"
  470. }
  471. /**
  472. * Modify this instance to communicate with the Cloud Firestore emulator.
  473. *
  474. * Note: This must be called before this instance has been used to do any
  475. * operations.
  476. *
  477. * @param firestore - The `Firestore` instance to configure to connect to the
  478. * emulator.
  479. * @param host - the emulator host (ex: localhost).
  480. * @param port - the emulator port (ex: 9000).
  481. * @param options.mockUserToken - the mock auth token to use for unit testing
  482. * Security Rules.
  483. */
  484. export declare function connectFirestoreEmulator(firestore: Firestore, host: string, port: number, options?: {
  485. mockUserToken?: EmulatorMockTokenOptions | string;
  486. }): void;
  487. /**
  488. * A Listener for credential change events. The listener should fetch a new
  489. * token and may need to invalidate other state if the current user has also
  490. * changed.
  491. */
  492. declare type CredentialChangeListener<T> = (credential: T) => Promise<void>;
  493. /**
  494. * Provides methods for getting the uid and token for the current user and
  495. * listening for changes.
  496. */
  497. declare interface CredentialsProvider<T> {
  498. /**
  499. * Starts the credentials provider and specifies a listener to be notified of
  500. * credential changes (sign-in / sign-out, token changes). It is immediately
  501. * called once with the initial user.
  502. *
  503. * The change listener is invoked on the provided AsyncQueue.
  504. */
  505. start(asyncQueue: AsyncQueue, changeListener: CredentialChangeListener<T>): void;
  506. /** Requests a token for the current user. */
  507. getToken(): Promise<Token | null>;
  508. /**
  509. * Marks the last retrieved token as invalid, making the next GetToken request
  510. * force-refresh the token.
  511. */
  512. invalidateToken(): void;
  513. shutdown(): void;
  514. }
  515. /** Settings for private credentials */
  516. declare type CredentialsSettings = FirstPartyCredentialsSettings | ProviderCredentialsSettings;
  517. /**
  518. * Represents the database ID a Firestore client is associated with.
  519. * @internal
  520. */
  521. declare class DatabaseId {
  522. readonly projectId: string;
  523. readonly database: string;
  524. constructor(projectId: string, database?: string);
  525. static empty(): DatabaseId;
  526. get isDefaultDatabase(): boolean;
  527. isEqual(other: {}): boolean;
  528. }
  529. /**
  530. * Datastore and its related methods are a wrapper around the external Google
  531. * Cloud Datastore grpc API, which provides an interface that is more convenient
  532. * for the rest of the client SDK architecture to consume.
  533. */
  534. declare abstract class Datastore {
  535. abstract terminate(): void;
  536. }
  537. /**
  538. * Represents an operation scheduled to be run in the future on an AsyncQueue.
  539. *
  540. * It is created via DelayedOperation.createAndSchedule().
  541. *
  542. * Supports cancellation (via cancel()) and early execution (via skipDelay()).
  543. *
  544. * Note: We implement `PromiseLike` instead of `Promise`, as the `Promise` type
  545. * in newer versions of TypeScript defines `finally`, which is not available in
  546. * IE.
  547. */
  548. declare class DelayedOperation<T extends unknown> implements PromiseLike<T> {
  549. private readonly asyncQueue;
  550. readonly timerId: TimerId;
  551. readonly targetTimeMs: number;
  552. private readonly op;
  553. private readonly removalCallback;
  554. private timerHandle;
  555. private readonly deferred;
  556. private constructor();
  557. /**
  558. * Creates and returns a DelayedOperation that has been scheduled to be
  559. * executed on the provided asyncQueue after the provided delayMs.
  560. *
  561. * @param asyncQueue - The queue to schedule the operation on.
  562. * @param id - A Timer ID identifying the type of operation this is.
  563. * @param delayMs - The delay (ms) before the operation should be scheduled.
  564. * @param op - The operation to run.
  565. * @param removalCallback - A callback to be called synchronously once the
  566. * operation is executed or canceled, notifying the AsyncQueue to remove it
  567. * from its delayedOperations list.
  568. * PORTING NOTE: This exists to prevent making removeDelayedOperation() and
  569. * the DelayedOperation class public.
  570. */
  571. static createAndSchedule<R extends unknown>(asyncQueue: AsyncQueue, timerId: TimerId, delayMs: number, op: () => Promise<R>, removalCallback: (op: DelayedOperation<R>) => void): DelayedOperation<R>;
  572. /**
  573. * Starts the timer. This is called immediately after construction by
  574. * createAndSchedule().
  575. */
  576. private start;
  577. /**
  578. * Queues the operation to run immediately (if it hasn't already been run or
  579. * canceled).
  580. */
  581. skipDelay(): void;
  582. /**
  583. * Cancels the operation if it hasn't already been executed or canceled. The
  584. * promise will be rejected.
  585. *
  586. * As long as the operation has not yet been run, calling cancel() provides a
  587. * guarantee that the operation will not be run.
  588. */
  589. cancel(reason?: string): void;
  590. then: <TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<TResult1 | TResult2>;
  591. private handleDelayElapsed;
  592. private clearTimeout;
  593. }
  594. /**
  595. * Deletes the document referred to by the specified `DocumentReference`.
  596. *
  597. * The deletion will only be reflected in document reads that occur after the
  598. * returned promise resolves. If the client is offline, the
  599. * delete fails. If you would like to see local modifications or buffer writes
  600. * until the client is online, use the full Firestore SDK.
  601. *
  602. * @param reference - A reference to the document to delete.
  603. * @returns A `Promise` resolved once the document has been successfully
  604. * deleted from the backend.
  605. */
  606. export declare function deleteDoc(reference: DocumentReference<unknown>): Promise<void>;
  607. /**
  608. * Returns a sentinel for use with {@link @firebase/firestore/lite#(updateDoc:1)} or
  609. * {@link @firebase/firestore/lite#(setDoc:1)} with `{merge: true}` to mark a field for deletion.
  610. */
  611. export declare function deleteField(): FieldValue;
  612. /**
  613. * The direction of sorting in an order by.
  614. */
  615. declare const enum Direction {
  616. ASCENDING = "asc",
  617. DESCENDING = "desc"
  618. }
  619. /**
  620. * Gets a `DocumentReference` instance that refers to the document at the
  621. * specified absolute path.
  622. *
  623. * @param firestore - A reference to the root `Firestore` instance.
  624. * @param path - A slash-separated path to a document.
  625. * @param pathSegments - Additional path segments that will be applied relative
  626. * to the first argument.
  627. * @throws If the final path has an odd number of segments and does not point to
  628. * a document.
  629. * @returns The `DocumentReference` instance.
  630. */
  631. export declare function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>;
  632. /**
  633. * Gets a `DocumentReference` instance that refers to a document within
  634. * `reference` at the specified relative path. If no path is specified, an
  635. * automatically-generated unique ID will be used for the returned
  636. * `DocumentReference`.
  637. *
  638. * @param reference - A reference to a collection.
  639. * @param path - A slash-separated path to a document. Has to be omitted to use
  640. * auto-genrated IDs.
  641. * @param pathSegments - Additional path segments that will be applied relative
  642. * to the first argument.
  643. * @throws If the final path has an odd number of segments and does not point to
  644. * a document.
  645. * @returns The `DocumentReference` instance.
  646. */
  647. export declare function doc<T>(reference: CollectionReference<T>, path?: string, ...pathSegments: string[]): DocumentReference<T>;
  648. /**
  649. * Gets a `DocumentReference` instance that refers to a document within
  650. * `reference` at the specified relative path.
  651. *
  652. * @param reference - A reference to a Firestore document.
  653. * @param path - A slash-separated path to a document.
  654. * @param pathSegments - Additional path segments that will be applied relative
  655. * to the first argument.
  656. * @throws If the final path has an odd number of segments and does not point to
  657. * a document.
  658. * @returns The `DocumentReference` instance.
  659. */
  660. export declare function doc(reference: DocumentReference<unknown>, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>;
  661. /**
  662. * Represents a document in Firestore with a key, version, data and whether the
  663. * data has local mutations applied to it.
  664. */
  665. declare interface Document_2 {
  666. /** The key for this document */
  667. readonly key: DocumentKey;
  668. /**
  669. * The version of this document if it exists or a version at which this
  670. * document was guaranteed to not exist.
  671. */
  672. readonly version: SnapshotVersion;
  673. /**
  674. * The timestamp at which this document was read from the remote server. Uses
  675. * `SnapshotVersion.min()` for documents created by the user.
  676. */
  677. readonly readTime: SnapshotVersion;
  678. /**
  679. * The timestamp at which the document was created. This value increases
  680. * monotonically when a document is deleted then recreated. It can also be
  681. * compared to `createTime` of other documents and the `readTime` of a query.
  682. */
  683. readonly createTime: SnapshotVersion;
  684. /** The underlying data of this document or an empty value if no data exists. */
  685. readonly data: ObjectValue;
  686. /** Returns whether local mutations were applied via the mutation queue. */
  687. readonly hasLocalMutations: boolean;
  688. /** Returns whether mutations were applied based on a write acknowledgment. */
  689. readonly hasCommittedMutations: boolean;
  690. /**
  691. * Whether this document had a local mutation applied that has not yet been
  692. * acknowledged by Watch.
  693. */
  694. readonly hasPendingWrites: boolean;
  695. /**
  696. * Returns whether this document is valid (i.e. it is an entry in the
  697. * RemoteDocumentCache, was created by a mutation or read from the backend).
  698. */
  699. isValidDocument(): boolean;
  700. /**
  701. * Returns whether the document exists and its data is known at the current
  702. * version.
  703. */
  704. isFoundDocument(): boolean;
  705. /**
  706. * Returns whether the document is known to not exist at the current version.
  707. */
  708. isNoDocument(): boolean;
  709. /**
  710. * Returns whether the document exists and its data is unknown at the current
  711. * version.
  712. */
  713. isUnknownDocument(): boolean;
  714. isEqual(other: Document_2 | null | undefined): boolean;
  715. /** Creates a mutable copy of this document. */
  716. mutableCopy(): MutableDocument;
  717. toString(): string;
  718. }
  719. /**
  720. * Document data (for use with {@link @firebase/firestore/lite#(setDoc:1)}) consists of fields mapped to
  721. * values.
  722. */
  723. export declare interface DocumentData {
  724. /** A mapping between a field and its value. */
  725. [field: string]: any;
  726. }
  727. /**
  728. * Returns a special sentinel `FieldPath` to refer to the ID of a document.
  729. * It can be used in queries to sort or filter by the document ID.
  730. */
  731. export declare function documentId(): FieldPath;
  732. /**
  733. * @internal
  734. */
  735. declare class DocumentKey {
  736. readonly path: ResourcePath;
  737. constructor(path: ResourcePath);
  738. static fromPath(path: string): DocumentKey;
  739. static fromName(name: string): DocumentKey;
  740. static empty(): DocumentKey;
  741. get collectionGroup(): string;
  742. /** Returns true if the document is in the specified collectionId. */
  743. hasCollectionId(collectionId: string): boolean;
  744. /** Returns the collection group (i.e. the name of the parent collection) for this key. */
  745. getCollectionGroup(): string;
  746. /** Returns the fully qualified path to the parent collection. */
  747. getCollectionPath(): ResourcePath;
  748. isEqual(other: DocumentKey | null): boolean;
  749. toString(): string;
  750. static comparator(k1: DocumentKey, k2: DocumentKey): number;
  751. static isDocumentKey(path: ResourcePath): boolean;
  752. /**
  753. * Creates and returns a new document key with the given segments.
  754. *
  755. * @param segments - The segments of the path to the document
  756. * @returns A new instance of DocumentKey
  757. */
  758. static fromSegments(segments: string[]): DocumentKey;
  759. }
  760. /**
  761. * A `DocumentReference` refers to a document location in a Firestore database
  762. * and can be used to write, read, or listen to the location. The document at
  763. * the referenced location may or may not exist.
  764. */
  765. export declare class DocumentReference<T = DocumentData> {
  766. /**
  767. * If provided, the `FirestoreDataConverter` associated with this instance.
  768. */
  769. readonly converter: FirestoreDataConverter<T> | null;
  770. readonly _key: DocumentKey;
  771. /** The type of this Firestore reference. */
  772. readonly type = "document";
  773. /**
  774. * The {@link Firestore} instance the document is in.
  775. * This is useful for performing transactions, for example.
  776. */
  777. readonly firestore: Firestore;
  778. /** @hideconstructor */
  779. constructor(firestore: Firestore,
  780. /**
  781. * If provided, the `FirestoreDataConverter` associated with this instance.
  782. */
  783. converter: FirestoreDataConverter<T> | null, _key: DocumentKey);
  784. get _path(): ResourcePath;
  785. /**
  786. * The document's identifier within its collection.
  787. */
  788. get id(): string;
  789. /**
  790. * A string representing the path of the referenced document (relative
  791. * to the root of the database).
  792. */
  793. get path(): string;
  794. /**
  795. * The collection this `DocumentReference` belongs to.
  796. */
  797. get parent(): CollectionReference<T>;
  798. /**
  799. * Applies a custom data converter to this `DocumentReference`, allowing you
  800. * to use your own custom model objects with Firestore. When you call {@link
  801. * @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#getDoc}, etc. with the returned `DocumentReference`
  802. * instance, the provided converter will convert between Firestore data and
  803. * your custom type `U`.
  804. *
  805. * @param converter - Converts objects to and from Firestore.
  806. * @returns A `DocumentReference<U>` that uses the provided converter.
  807. */
  808. withConverter<U>(converter: FirestoreDataConverter<U>): DocumentReference<U>;
  809. /**
  810. * Removes the current converter.
  811. *
  812. * @param converter - `null` removes the current converter.
  813. * @returns A `DocumentReference<DocumentData>` that does not use a converter.
  814. */
  815. withConverter(converter: null): DocumentReference<DocumentData>;
  816. }
  817. /**
  818. * A `DocumentSnapshot` contains data read from a document in your Firestore
  819. * database. The data can be extracted with `.data()` or `.get(<field>)` to
  820. * get a specific field.
  821. *
  822. * For a `DocumentSnapshot` that points to a non-existing document, any data
  823. * access will return 'undefined'. You can use the `exists()` method to
  824. * explicitly verify a document's existence.
  825. */
  826. export declare class DocumentSnapshot<T = DocumentData> {
  827. _firestore: Firestore;
  828. _userDataWriter: AbstractUserDataWriter;
  829. _key: DocumentKey;
  830. _document: Document_2 | null;
  831. _converter: UntypedFirestoreDataConverter<T> | null;
  832. /** @hideconstructor protected */
  833. constructor(_firestore: Firestore, _userDataWriter: AbstractUserDataWriter, _key: DocumentKey, _document: Document_2 | null, _converter: UntypedFirestoreDataConverter<T> | null);
  834. /** Property of the `DocumentSnapshot` that provides the document's ID. */
  835. get id(): string;
  836. /**
  837. * The `DocumentReference` for the document included in the `DocumentSnapshot`.
  838. */
  839. get ref(): DocumentReference<T>;
  840. /**
  841. * Signals whether or not the document at the snapshot's location exists.
  842. *
  843. * @returns true if the document exists.
  844. */
  845. exists(): this is QueryDocumentSnapshot<T>;
  846. /**
  847. * Retrieves all fields in the document as an `Object`. Returns `undefined` if
  848. * the document doesn't exist.
  849. *
  850. * @returns An `Object` containing all fields in the document or `undefined`
  851. * if the document doesn't exist.
  852. */
  853. data(): T | undefined;
  854. /**
  855. * Retrieves the field specified by `fieldPath`. Returns `undefined` if the
  856. * document or field doesn't exist.
  857. *
  858. * @param fieldPath - The path (for example 'foo' or 'foo.bar') to a specific
  859. * field.
  860. * @returns The data at the specified field location or undefined if no such
  861. * field exists in the document.
  862. */
  863. get(fieldPath: string | FieldPath): any;
  864. }
  865. export { EmulatorMockTokenOptions }
  866. /**
  867. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end at
  868. * the provided document (inclusive). The end position is relative to the order
  869. * of the query. The document must contain all of the fields provided in the
  870. * orderBy of the query.
  871. *
  872. * @param snapshot - The snapshot of the document to end at.
  873. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  874. */
  875. export declare function endAt(snapshot: DocumentSnapshot<unknown>): QueryEndAtConstraint;
  876. /**
  877. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end at
  878. * the provided fields relative to the order of the query. The order of the field
  879. * values must match the order of the order by clauses of the query.
  880. *
  881. * @param fieldValues - The field values to end this query at, in order
  882. * of the query's order by.
  883. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  884. */
  885. export declare function endAt(...fieldValues: unknown[]): QueryEndAtConstraint;
  886. /**
  887. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end
  888. * before the provided document (exclusive). The end position is relative to the
  889. * order of the query. The document must contain all of the fields provided in
  890. * the orderBy of the query.
  891. *
  892. * @param snapshot - The snapshot of the document to end before.
  893. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  894. */
  895. export declare function endBefore(snapshot: DocumentSnapshot<unknown>): QueryEndAtConstraint;
  896. /**
  897. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end
  898. * before the provided fields relative to the order of the query. The order of
  899. * the field values must match the order of the order by clauses of the query.
  900. *
  901. * @param fieldValues - The field values to end this query before, in order
  902. * of the query's order by.
  903. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  904. */
  905. export declare function endBefore(...fieldValues: unknown[]): QueryEndAtConstraint;
  906. declare class FieldFilter extends Filter {
  907. readonly field: FieldPath_2;
  908. readonly op: Operator;
  909. readonly value: Value;
  910. protected constructor(field: FieldPath_2, op: Operator, value: Value);
  911. /**
  912. * Creates a filter based on the provided arguments.
  913. */
  914. static create(field: FieldPath_2, op: Operator, value: Value): FieldFilter;
  915. private static createKeyFieldInFilter;
  916. matches(doc: Document_2): boolean;
  917. protected matchesComparison(comparison: number): boolean;
  918. isInequality(): boolean;
  919. getFlattenedFilters(): readonly FieldFilter[];
  920. getFilters(): Filter[];
  921. getFirstInequalityField(): FieldPath_2 | null;
  922. }
  923. declare type FieldFilterOp = 'OPERATOR_UNSPECIFIED' | 'LESS_THAN' | 'LESS_THAN_OR_EQUAL' | 'GREATER_THAN' | 'GREATER_THAN_OR_EQUAL' | 'EQUAL' | 'NOT_EQUAL' | 'ARRAY_CONTAINS' | 'IN' | 'ARRAY_CONTAINS_ANY' | 'NOT_IN';
  924. /**
  925. * Provides a set of fields that can be used to partially patch a document.
  926. * FieldMask is used in conjunction with ObjectValue.
  927. * Examples:
  928. * foo - Overwrites foo entirely with the provided value. If foo is not
  929. * present in the companion ObjectValue, the field is deleted.
  930. * foo.bar - Overwrites only the field bar of the object foo.
  931. * If foo is not an object, foo is replaced with an object
  932. * containing foo
  933. */
  934. declare class FieldMask {
  935. readonly fields: FieldPath_2[];
  936. constructor(fields: FieldPath_2[]);
  937. static empty(): FieldMask;
  938. /**
  939. * Returns a new FieldMask object that is the result of adding all the given
  940. * fields paths to this field mask.
  941. */
  942. unionWith(extraFields: FieldPath_2[]): FieldMask;
  943. /**
  944. * Verifies that `fieldPath` is included by at least one field in this field
  945. * mask.
  946. *
  947. * This is an O(n) operation, where `n` is the size of the field mask.
  948. */
  949. covers(fieldPath: FieldPath_2): boolean;
  950. isEqual(other: FieldMask): boolean;
  951. }
  952. /**
  953. * A `FieldPath` refers to a field in a document. The path may consist of a
  954. * single field name (referring to a top-level field in the document), or a
  955. * list of field names (referring to a nested field in the document).
  956. *
  957. * Create a `FieldPath` by providing field names. If more than one field
  958. * name is provided, the path will point to a nested field in a document.
  959. */
  960. export declare class FieldPath {
  961. /** Internal representation of a Firestore field path. */
  962. readonly _internalPath: FieldPath_2;
  963. /**
  964. * Creates a `FieldPath` from the provided field names. If more than one field
  965. * name is provided, the path will point to a nested field in a document.
  966. *
  967. * @param fieldNames - A list of field names.
  968. */
  969. constructor(...fieldNames: string[]);
  970. /**
  971. * Returns true if this `FieldPath` is equal to the provided one.
  972. *
  973. * @param other - The `FieldPath` to compare against.
  974. * @returns true if this `FieldPath` is equal to the provided one.
  975. */
  976. isEqual(other: FieldPath): boolean;
  977. }
  978. /**
  979. * A dot-separated path for navigating sub-objects within a document.
  980. * @internal
  981. */
  982. declare class FieldPath_2 extends BasePath<FieldPath_2> {
  983. protected construct(segments: string[], offset?: number, length?: number): FieldPath_2;
  984. /**
  985. * Returns true if the string could be used as a segment in a field path
  986. * without escaping.
  987. */
  988. private static isValidIdentifier;
  989. canonicalString(): string;
  990. toString(): string;
  991. /**
  992. * Returns true if this field references the key of a document.
  993. */
  994. isKeyField(): boolean;
  995. /**
  996. * The field designating the key of a document.
  997. */
  998. static keyField(): FieldPath_2;
  999. /**
  1000. * Parses a field string from the given server-formatted string.
  1001. *
  1002. * - Splitting the empty string is not allowed (for now at least).
  1003. * - Empty segments within the string (e.g. if there are two consecutive
  1004. * separators) are not allowed.
  1005. *
  1006. * TODO(b/37244157): we should make this more strict. Right now, it allows
  1007. * non-identifier path components, even if they aren't escaped.
  1008. */
  1009. static fromServerFormat(path: string): FieldPath_2;
  1010. static emptyPath(): FieldPath_2;
  1011. }
  1012. /** A field path and the TransformOperation to perform upon it. */
  1013. declare class FieldTransform {
  1014. readonly field: FieldPath_2;
  1015. readonly transform: TransformOperation;
  1016. constructor(field: FieldPath_2, transform: TransformOperation);
  1017. }
  1018. declare type FieldTransformSetToServerValue = 'SERVER_VALUE_UNSPECIFIED' | 'REQUEST_TIME';
  1019. /**
  1020. * Sentinel values that can be used when writing document fields with `set()`
  1021. * or `update()`.
  1022. */
  1023. export declare abstract class FieldValue {
  1024. _methodName: string;
  1025. /**
  1026. * @param _methodName - The public API endpoint that returns this class.
  1027. * @hideconstructor
  1028. */
  1029. constructor(_methodName: string);
  1030. /** Compares `FieldValue`s for equality. */
  1031. abstract isEqual(other: FieldValue): boolean;
  1032. abstract _toFieldTransform(context: ParseContext): FieldTransform | null;
  1033. }
  1034. declare abstract class Filter {
  1035. abstract matches(doc: Document_2): boolean;
  1036. abstract getFlattenedFilters(): readonly FieldFilter[];
  1037. abstract getFilters(): Filter[];
  1038. abstract getFirstInequalityField(): FieldPath_2 | null;
  1039. }
  1040. /**
  1041. * The Cloud Firestore service interface.
  1042. *
  1043. * Do not call this constructor directly. Instead, use {@link (getFirestore:1)}.
  1044. */
  1045. export declare class Firestore implements FirestoreService {
  1046. _authCredentials: CredentialsProvider<User>;
  1047. _appCheckCredentials: CredentialsProvider<string>;
  1048. readonly _databaseId: DatabaseId;
  1049. readonly _app?: FirebaseApp | undefined;
  1050. /**
  1051. * Whether it's a Firestore or Firestore Lite instance.
  1052. */
  1053. type: 'firestore-lite' | 'firestore';
  1054. readonly _persistenceKey: string;
  1055. private _settings;
  1056. private _settingsFrozen;
  1057. private _terminateTask?;
  1058. /** @hideconstructor */
  1059. constructor(_authCredentials: CredentialsProvider<User>, _appCheckCredentials: CredentialsProvider<string>, _databaseId: DatabaseId, _app?: FirebaseApp | undefined);
  1060. /**
  1061. * The {@link @firebase/app#FirebaseApp} associated with this `Firestore` service
  1062. * instance.
  1063. */
  1064. get app(): FirebaseApp;
  1065. get _initialized(): boolean;
  1066. get _terminated(): boolean;
  1067. _setSettings(settings: PrivateSettings): void;
  1068. _getSettings(): FirestoreSettingsImpl;
  1069. _freezeSettings(): FirestoreSettingsImpl;
  1070. _delete(): Promise<void>;
  1071. /** Returns a JSON-serializable representation of this `Firestore` instance. */
  1072. toJSON(): object;
  1073. /**
  1074. * Terminates all components used by this client. Subclasses can override
  1075. * this method to clean up their own dependencies, but must also call this
  1076. * method.
  1077. *
  1078. * Only ever called once.
  1079. */
  1080. protected _terminate(): Promise<void>;
  1081. }
  1082. /**
  1083. * Converter used by `withConverter()` to transform user objects of type `T`
  1084. * into Firestore data.
  1085. *
  1086. * Using the converter allows you to specify generic type arguments when
  1087. * storing and retrieving objects from Firestore.
  1088. *
  1089. * @example
  1090. * ```typescript
  1091. * class Post {
  1092. * constructor(readonly title: string, readonly author: string) {}
  1093. *
  1094. * toString(): string {
  1095. * return this.title + ', by ' + this.author;
  1096. * }
  1097. * }
  1098. *
  1099. * const postConverter = {
  1100. * toFirestore(post: WithFieldValue<Post>): DocumentData {
  1101. * return {title: post.title, author: post.author};
  1102. * },
  1103. * fromFirestore(snapshot: QueryDocumentSnapshot): Post {
  1104. * const data = snapshot.data(options)!;
  1105. * return new Post(data.title, data.author);
  1106. * }
  1107. * };
  1108. *
  1109. * const postSnap = await firebase.firestore()
  1110. * .collection('posts')
  1111. * .withConverter(postConverter)
  1112. * .doc().get();
  1113. * const post = postSnap.data();
  1114. * if (post !== undefined) {
  1115. * post.title; // string
  1116. * post.toString(); // Should be defined
  1117. * post.someNonExistentProperty; // TS error
  1118. * }
  1119. * ```
  1120. */
  1121. export declare interface FirestoreDataConverter<T> {
  1122. /**
  1123. * Called by the Firestore SDK to convert a custom model object of type `T`
  1124. * into a plain Javascript object (suitable for writing directly to the
  1125. * Firestore database). Used with {@link @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#(WriteBatch.set:1)}
  1126. * and {@link @firebase/firestore/lite#(Transaction.set:1)}.
  1127. *
  1128. * The `WithFieldValue<T>` type extends `T` to also allow FieldValues such as
  1129. * {@link (deleteField:1)} to be used as property values.
  1130. */
  1131. toFirestore(modelObject: WithFieldValue<T>): DocumentData;
  1132. /**
  1133. * Called by the Firestore SDK to convert a custom model object of type `T`
  1134. * into a plain Javascript object (suitable for writing directly to the
  1135. * Firestore database). Used with {@link @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#(WriteBatch.set:1)}
  1136. * and {@link @firebase/firestore/lite#(Transaction.set:1)} with `merge:true` or `mergeFields`.
  1137. *
  1138. * The `PartialWithFieldValue<T>` type extends `Partial<T>` to allow
  1139. * FieldValues such as {@link (arrayUnion:1)} to be used as property values.
  1140. * It also supports nested `Partial` by allowing nested fields to be
  1141. * omitted.
  1142. */
  1143. toFirestore(modelObject: PartialWithFieldValue<T>, options: SetOptions): DocumentData;
  1144. /**
  1145. * Called by the Firestore SDK to convert Firestore data into an object of
  1146. * type T. You can access your data by calling: `snapshot.data()`.
  1147. *
  1148. * @param snapshot - A `QueryDocumentSnapshot` containing your data and
  1149. * metadata.
  1150. */
  1151. fromFirestore(snapshot: QueryDocumentSnapshot<DocumentData>): T;
  1152. }
  1153. /** An error returned by a Firestore operation. */
  1154. export declare class FirestoreError extends FirebaseError {
  1155. /**
  1156. * The backend error code associated with this error.
  1157. */
  1158. readonly code: FirestoreErrorCode;
  1159. /**
  1160. * A custom error description.
  1161. */
  1162. readonly message: string;
  1163. /** The stack of the error. */
  1164. readonly stack?: string;
  1165. /** @hideconstructor */
  1166. constructor(
  1167. /**
  1168. * The backend error code associated with this error.
  1169. */
  1170. code: FirestoreErrorCode,
  1171. /**
  1172. * A custom error description.
  1173. */
  1174. message: string);
  1175. }
  1176. /**
  1177. * The set of Firestore status codes. The codes are the same at the ones
  1178. * exposed by gRPC here:
  1179. * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
  1180. *
  1181. * Possible values:
  1182. * - 'cancelled': The operation was cancelled (typically by the caller).
  1183. * - 'unknown': Unknown error or an error from a different error domain.
  1184. * - 'invalid-argument': Client specified an invalid argument. Note that this
  1185. * differs from 'failed-precondition'. 'invalid-argument' indicates
  1186. * arguments that are problematic regardless of the state of the system
  1187. * (e.g. an invalid field name).
  1188. * - 'deadline-exceeded': Deadline expired before operation could complete.
  1189. * For operations that change the state of the system, this error may be
  1190. * returned even if the operation has completed successfully. For example,
  1191. * a successful response from a server could have been delayed long enough
  1192. * for the deadline to expire.
  1193. * - 'not-found': Some requested document was not found.
  1194. * - 'already-exists': Some document that we attempted to create already
  1195. * exists.
  1196. * - 'permission-denied': The caller does not have permission to execute the
  1197. * specified operation.
  1198. * - 'resource-exhausted': Some resource has been exhausted, perhaps a
  1199. * per-user quota, or perhaps the entire file system is out of space.
  1200. * - 'failed-precondition': Operation was rejected because the system is not
  1201. * in a state required for the operation's execution.
  1202. * - 'aborted': The operation was aborted, typically due to a concurrency
  1203. * issue like transaction aborts, etc.
  1204. * - 'out-of-range': Operation was attempted past the valid range.
  1205. * - 'unimplemented': Operation is not implemented or not supported/enabled.
  1206. * - 'internal': Internal errors. Means some invariants expected by
  1207. * underlying system has been broken. If you see one of these errors,
  1208. * something is very broken.
  1209. * - 'unavailable': The service is currently unavailable. This is most likely
  1210. * a transient condition and may be corrected by retrying with a backoff.
  1211. * - 'data-loss': Unrecoverable data loss or corruption.
  1212. * - 'unauthenticated': The request does not have valid authentication
  1213. * credentials for the operation.
  1214. */
  1215. 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';
  1216. /**
  1217. * An interface implemented by FirebaseFirestore that provides compatibility
  1218. * with the usage in this file.
  1219. *
  1220. * This interface mainly exists to remove a cyclic dependency.
  1221. */
  1222. declare interface FirestoreService extends _FirebaseService {
  1223. _authCredentials: CredentialsProvider<User>;
  1224. _appCheckCredentials: CredentialsProvider<string>;
  1225. _persistenceKey: string;
  1226. _databaseId: DatabaseId;
  1227. _terminated: boolean;
  1228. _freezeSettings(): FirestoreSettingsImpl;
  1229. }
  1230. /**
  1231. * A concrete type describing all the values that can be applied via a
  1232. * user-supplied `FirestoreSettings` object. This is a separate type so that
  1233. * defaults can be supplied and the value can be checked for equality.
  1234. */
  1235. declare class FirestoreSettingsImpl {
  1236. /** The hostname to connect to. */
  1237. readonly host: string;
  1238. /** Whether to use SSL when connecting. */
  1239. readonly ssl: boolean;
  1240. readonly cacheSizeBytes: number;
  1241. readonly experimentalForceLongPolling: boolean;
  1242. readonly experimentalAutoDetectLongPolling: boolean;
  1243. readonly ignoreUndefinedProperties: boolean;
  1244. readonly useFetchStreams: boolean;
  1245. credentials?: any;
  1246. constructor(settings: PrivateSettings);
  1247. isEqual(other: FirestoreSettingsImpl): boolean;
  1248. }
  1249. declare namespace firestoreV1ApiClientInterfaces {
  1250. interface ArrayValue {
  1251. values?: Value[];
  1252. }
  1253. interface BatchGetDocumentsRequest {
  1254. database?: string;
  1255. documents?: string[];
  1256. mask?: DocumentMask;
  1257. transaction?: string;
  1258. newTransaction?: TransactionOptions;
  1259. readTime?: string;
  1260. }
  1261. interface BatchGetDocumentsResponse {
  1262. found?: Document;
  1263. missing?: string;
  1264. transaction?: string;
  1265. readTime?: string;
  1266. }
  1267. interface BeginTransactionRequest {
  1268. options?: TransactionOptions;
  1269. }
  1270. interface BeginTransactionResponse {
  1271. transaction?: string;
  1272. }
  1273. interface CollectionSelector {
  1274. collectionId?: string;
  1275. allDescendants?: boolean;
  1276. }
  1277. interface CommitRequest {
  1278. database?: string;
  1279. writes?: Write[];
  1280. transaction?: string;
  1281. }
  1282. interface CommitResponse {
  1283. writeResults?: WriteResult[];
  1284. commitTime?: string;
  1285. }
  1286. interface CompositeFilter {
  1287. op?: CompositeFilterOp;
  1288. filters?: Filter[];
  1289. }
  1290. interface Cursor {
  1291. values?: Value[];
  1292. before?: boolean;
  1293. }
  1294. interface Document {
  1295. name?: string;
  1296. fields?: ApiClientObjectMap<Value>;
  1297. createTime?: Timestamp_2;
  1298. updateTime?: Timestamp_2;
  1299. }
  1300. interface DocumentChange {
  1301. document?: Document;
  1302. targetIds?: number[];
  1303. removedTargetIds?: number[];
  1304. }
  1305. interface DocumentDelete {
  1306. document?: string;
  1307. removedTargetIds?: number[];
  1308. readTime?: Timestamp_2;
  1309. }
  1310. interface DocumentMask {
  1311. fieldPaths?: string[];
  1312. }
  1313. interface DocumentRemove {
  1314. document?: string;
  1315. removedTargetIds?: number[];
  1316. readTime?: string;
  1317. }
  1318. interface DocumentTransform {
  1319. document?: string;
  1320. fieldTransforms?: FieldTransform[];
  1321. }
  1322. interface DocumentsTarget {
  1323. documents?: string[];
  1324. }
  1325. interface Empty {
  1326. }
  1327. interface ExistenceFilter {
  1328. targetId?: number;
  1329. count?: number;
  1330. }
  1331. interface FieldFilter {
  1332. field?: FieldReference;
  1333. op?: FieldFilterOp;
  1334. value?: Value;
  1335. }
  1336. interface FieldReference {
  1337. fieldPath?: string;
  1338. }
  1339. interface FieldTransform {
  1340. fieldPath?: string;
  1341. setToServerValue?: FieldTransformSetToServerValue;
  1342. appendMissingElements?: ArrayValue;
  1343. removeAllFromArray?: ArrayValue;
  1344. increment?: Value;
  1345. }
  1346. interface Filter {
  1347. compositeFilter?: CompositeFilter;
  1348. fieldFilter?: FieldFilter;
  1349. unaryFilter?: UnaryFilter;
  1350. }
  1351. interface Index {
  1352. name?: string;
  1353. collectionId?: string;
  1354. fields?: IndexField[];
  1355. state?: IndexState;
  1356. }
  1357. interface IndexField {
  1358. fieldPath?: string;
  1359. mode?: IndexFieldMode;
  1360. }
  1361. interface LatLng {
  1362. latitude?: number;
  1363. longitude?: number;
  1364. }
  1365. interface ListCollectionIdsRequest {
  1366. pageSize?: number;
  1367. pageToken?: string;
  1368. }
  1369. interface ListCollectionIdsResponse {
  1370. collectionIds?: string[];
  1371. nextPageToken?: string;
  1372. }
  1373. interface ListDocumentsResponse {
  1374. documents?: Document[];
  1375. nextPageToken?: string;
  1376. }
  1377. interface ListIndexesResponse {
  1378. indexes?: Index[];
  1379. nextPageToken?: string;
  1380. }
  1381. interface ListenRequest {
  1382. addTarget?: Target;
  1383. removeTarget?: number;
  1384. labels?: ApiClientObjectMap<string>;
  1385. }
  1386. interface ListenResponse {
  1387. targetChange?: TargetChange;
  1388. documentChange?: DocumentChange;
  1389. documentDelete?: DocumentDelete;
  1390. documentRemove?: DocumentRemove;
  1391. filter?: ExistenceFilter;
  1392. }
  1393. interface MapValue {
  1394. fields?: ApiClientObjectMap<Value>;
  1395. }
  1396. interface Operation {
  1397. name?: string;
  1398. metadata?: ApiClientObjectMap<any>;
  1399. done?: boolean;
  1400. error?: Status;
  1401. response?: ApiClientObjectMap<any>;
  1402. }
  1403. interface Order {
  1404. field?: FieldReference;
  1405. direction?: OrderDirection;
  1406. }
  1407. interface Precondition {
  1408. exists?: boolean;
  1409. updateTime?: Timestamp_2;
  1410. }
  1411. interface Projection {
  1412. fields?: FieldReference[];
  1413. }
  1414. interface QueryTarget {
  1415. parent?: string;
  1416. structuredQuery?: StructuredQuery;
  1417. }
  1418. interface ReadOnly {
  1419. readTime?: string;
  1420. }
  1421. interface ReadWrite {
  1422. retryTransaction?: string;
  1423. }
  1424. interface RollbackRequest {
  1425. transaction?: string;
  1426. }
  1427. interface RunQueryRequest {
  1428. parent?: string;
  1429. structuredQuery?: StructuredQuery;
  1430. transaction?: string;
  1431. newTransaction?: TransactionOptions;
  1432. readTime?: string;
  1433. }
  1434. interface RunQueryResponse {
  1435. transaction?: string;
  1436. document?: Document;
  1437. readTime?: string;
  1438. skippedResults?: number;
  1439. }
  1440. interface RunAggregationQueryRequest {
  1441. parent?: string;
  1442. structuredAggregationQuery?: StructuredAggregationQuery;
  1443. transaction?: string;
  1444. newTransaction?: TransactionOptions;
  1445. readTime?: string;
  1446. }
  1447. interface RunAggregationQueryResponse {
  1448. result?: AggregationResult;
  1449. transaction?: string;
  1450. readTime?: string;
  1451. }
  1452. interface AggregationResult {
  1453. aggregateFields?: ApiClientObjectMap<Value>;
  1454. }
  1455. interface StructuredAggregationQuery {
  1456. structuredQuery?: StructuredQuery;
  1457. aggregations?: Aggregation[];
  1458. }
  1459. interface Aggregation {
  1460. count?: Count;
  1461. alias?: string;
  1462. }
  1463. interface Count {
  1464. upTo?: number;
  1465. }
  1466. interface Status {
  1467. code?: number;
  1468. message?: string;
  1469. details?: Array<ApiClientObjectMap<any>>;
  1470. }
  1471. interface StructuredQuery {
  1472. select?: Projection;
  1473. from?: CollectionSelector[];
  1474. where?: Filter;
  1475. orderBy?: Order[];
  1476. startAt?: Cursor;
  1477. endAt?: Cursor;
  1478. offset?: number;
  1479. limit?: number | {
  1480. value: number;
  1481. };
  1482. }
  1483. interface Target {
  1484. query?: QueryTarget;
  1485. documents?: DocumentsTarget;
  1486. resumeToken?: string | Uint8Array;
  1487. readTime?: Timestamp_2;
  1488. targetId?: number;
  1489. once?: boolean;
  1490. }
  1491. interface TargetChange {
  1492. targetChangeType?: TargetChangeTargetChangeType;
  1493. targetIds?: number[];
  1494. cause?: Status;
  1495. resumeToken?: string | Uint8Array;
  1496. readTime?: Timestamp_2;
  1497. }
  1498. interface TransactionOptions {
  1499. readOnly?: ReadOnly;
  1500. readWrite?: ReadWrite;
  1501. }
  1502. interface UnaryFilter {
  1503. op?: UnaryFilterOp;
  1504. field?: FieldReference;
  1505. }
  1506. interface Value {
  1507. nullValue?: ValueNullValue;
  1508. booleanValue?: boolean;
  1509. integerValue?: string | number;
  1510. doubleValue?: string | number;
  1511. timestampValue?: Timestamp_2;
  1512. stringValue?: string;
  1513. bytesValue?: string | Uint8Array;
  1514. referenceValue?: string;
  1515. geoPointValue?: LatLng;
  1516. arrayValue?: ArrayValue;
  1517. mapValue?: MapValue;
  1518. }
  1519. interface Write {
  1520. update?: Document;
  1521. delete?: string;
  1522. verify?: string;
  1523. transform?: DocumentTransform;
  1524. updateMask?: DocumentMask;
  1525. updateTransforms?: FieldTransform[];
  1526. currentDocument?: Precondition;
  1527. }
  1528. interface WriteRequest {
  1529. streamId?: string;
  1530. writes?: Write[];
  1531. streamToken?: string | Uint8Array;
  1532. labels?: ApiClientObjectMap<string>;
  1533. }
  1534. interface WriteResponse {
  1535. streamId?: string;
  1536. streamToken?: string | Uint8Array;
  1537. writeResults?: WriteResult[];
  1538. commitTime?: Timestamp_2;
  1539. }
  1540. interface WriteResult {
  1541. updateTime?: Timestamp_2;
  1542. transformResults?: Value[];
  1543. }
  1544. }
  1545. declare interface FirstPartyCredentialsSettings {
  1546. ['type']: 'gapi';
  1547. ['client']: unknown;
  1548. ['sessionIndex']: string;
  1549. ['iamToken']: string | null;
  1550. ['authTokenFactory']: AuthTokenFactory | null;
  1551. }
  1552. /**
  1553. * @license
  1554. * Copyright 2017 Google LLC
  1555. *
  1556. * Licensed under the Apache License, Version 2.0 (the "License");
  1557. * you may not use this file except in compliance with the License.
  1558. * You may obtain a copy of the License at
  1559. *
  1560. * http://www.apache.org/licenses/LICENSE-2.0
  1561. *
  1562. * Unless required by applicable law or agreed to in writing, software
  1563. * distributed under the License is distributed on an "AS IS" BASIS,
  1564. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1565. * See the License for the specific language governing permissions and
  1566. * limitations under the License.
  1567. */
  1568. /**
  1569. * An immutable object representing a geographic location in Firestore. The
  1570. * location is represented as latitude/longitude pair.
  1571. *
  1572. * Latitude values are in the range of [-90, 90].
  1573. * Longitude values are in the range of [-180, 180].
  1574. */
  1575. export declare class GeoPoint {
  1576. private _lat;
  1577. private _long;
  1578. /**
  1579. * Creates a new immutable `GeoPoint` object with the provided latitude and
  1580. * longitude values.
  1581. * @param latitude - The latitude as number between -90 and 90.
  1582. * @param longitude - The longitude as number between -180 and 180.
  1583. */
  1584. constructor(latitude: number, longitude: number);
  1585. /**
  1586. * The latitude of this `GeoPoint` instance.
  1587. */
  1588. get latitude(): number;
  1589. /**
  1590. * The longitude of this `GeoPoint` instance.
  1591. */
  1592. get longitude(): number;
  1593. /**
  1594. * Returns true if this `GeoPoint` is equal to the provided one.
  1595. *
  1596. * @param other - The `GeoPoint` to compare against.
  1597. * @returns true if this `GeoPoint` is equal to the provided one.
  1598. */
  1599. isEqual(other: GeoPoint): boolean;
  1600. /** Returns a JSON-serializable representation of this GeoPoint. */
  1601. toJSON(): {
  1602. latitude: number;
  1603. longitude: number;
  1604. };
  1605. /**
  1606. * Actually private to JS consumers of our API, so this function is prefixed
  1607. * with an underscore.
  1608. */
  1609. _compareTo(other: GeoPoint): number;
  1610. }
  1611. /**
  1612. * Calculates the number of documents in the result set of the given query,
  1613. * without actually downloading the documents.
  1614. *
  1615. * Using this function to count the documents is efficient because only the
  1616. * final count, not the documents' data, is downloaded. This function can even
  1617. * count the documents if the result set would be prohibitively large to
  1618. * download entirely (e.g. thousands of documents).
  1619. *
  1620. * @param query - The query whose result set size to calculate.
  1621. * @returns A Promise that will be resolved with the count; the count can be
  1622. * retrieved from `snapshot.data().count`, where `snapshot` is the
  1623. * `AggregateQuerySnapshot` to which the returned Promise resolves.
  1624. */
  1625. export declare function getCount(query: Query<unknown>): Promise<AggregateQuerySnapshot<{
  1626. count: AggregateField<number>;
  1627. }>>;
  1628. /**
  1629. * Reads the document referred to by the specified document reference.
  1630. *
  1631. * All documents are directly fetched from the server, even if the document was
  1632. * previously read or modified. Recent modifications are only reflected in the
  1633. * retrieved `DocumentSnapshot` if they have already been applied by the
  1634. * backend. If the client is offline, the read fails. If you like to use
  1635. * caching or see local modifications, please use the full Firestore SDK.
  1636. *
  1637. * @param reference - The reference of the document to fetch.
  1638. * @returns A Promise resolved with a `DocumentSnapshot` containing the current
  1639. * document contents.
  1640. */
  1641. export declare function getDoc<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
  1642. /**
  1643. * Executes the query and returns the results as a {@link QuerySnapshot}.
  1644. *
  1645. * All queries are executed directly by the server, even if the the query was
  1646. * previously executed. Recent modifications are only reflected in the retrieved
  1647. * results if they have already been applied by the backend. If the client is
  1648. * offline, the operation fails. To see previously cached result and local
  1649. * modifications, use the full Firestore SDK.
  1650. *
  1651. * @param query - The `Query` to execute.
  1652. * @returns A Promise that will be resolved with the results of the query.
  1653. */
  1654. export declare function getDocs<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
  1655. /**
  1656. * Returns the existing default {@link Firestore} instance that is associated with the
  1657. * default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
  1658. * instance with default settings.
  1659. *
  1660. * @returns The {@link Firestore} instance of the provided app.
  1661. */
  1662. export declare function getFirestore(): Firestore;
  1663. /**
  1664. * Returns the existing default {@link Firestore} instance that is associated with the
  1665. * provided {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
  1666. * instance with default settings.
  1667. *
  1668. * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned {@link Firestore}
  1669. * instance is associated with.
  1670. * @returns The {@link Firestore} instance of the provided app.
  1671. */
  1672. export declare function getFirestore(app: FirebaseApp): Firestore;
  1673. /**
  1674. * Returns the existing {@link Firestore} instance that is associated with the
  1675. * default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
  1676. * instance with default settings.
  1677. *
  1678. * @param databaseId - The name of database.
  1679. * @returns The {@link Firestore} instance of the provided app.
  1680. * @internal
  1681. */
  1682. export declare function getFirestore(databaseId: string): Firestore;
  1683. /**
  1684. * Returns the existing {@link Firestore} instance that is associated with the
  1685. * provided {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
  1686. * instance with default settings.
  1687. *
  1688. * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned {@link Firestore}
  1689. * instance is associated with.
  1690. * @param databaseId - The name of database.
  1691. * @returns The {@link Firestore} instance of the provided app.
  1692. * @internal
  1693. */
  1694. export declare function getFirestore(app: FirebaseApp, databaseId: string): Firestore;
  1695. /**
  1696. * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link
  1697. * @firebase/firestore/lite#(updateDoc:1)} that tells the server to increment the field's current value by
  1698. * the given value.
  1699. *
  1700. * If either the operand or the current field value uses floating point
  1701. * precision, all arithmetic follows IEEE 754 semantics. If both values are
  1702. * integers, values outside of JavaScript's safe number range
  1703. * (`Number.MIN_SAFE_INTEGER` to `Number.MAX_SAFE_INTEGER`) are also subject to
  1704. * precision loss. Furthermore, once processed by the Firestore backend, all
  1705. * integer operations are capped between -2^63 and 2^63-1.
  1706. *
  1707. * If the current field value is not of type `number`, or if the field does not
  1708. * yet exist, the transformation sets the field to the given value.
  1709. *
  1710. * @param n - The value to increment by.
  1711. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  1712. * `updateDoc()`
  1713. */
  1714. export declare function increment(n: number): FieldValue;
  1715. declare type IndexFieldMode = 'MODE_UNSPECIFIED' | 'ASCENDING' | 'DESCENDING';
  1716. declare type IndexState = 'STATE_UNSPECIFIED' | 'CREATING' | 'READY' | 'ERROR';
  1717. /**
  1718. * Initializes a new instance of Cloud Firestore with the provided settings.
  1719. * Can only be called before any other functions, including
  1720. * {@link (getFirestore:1)}. If the custom settings are empty, this function is
  1721. * equivalent to calling {@link (getFirestore:1)}.
  1722. *
  1723. * @param app - The {@link @firebase/app#FirebaseApp} with which the `Firestore` instance will
  1724. * be associated.
  1725. * @param settings - A settings object to configure the `Firestore` instance.
  1726. * @returns A newly initialized `Firestore` instance.
  1727. */
  1728. export declare function initializeFirestore(app: FirebaseApp, settings: Settings): Firestore;
  1729. /**
  1730. * Initializes a new instance of Cloud Firestore with the provided settings.
  1731. * Can only be called before any other functions, including
  1732. * {@link (getFirestore:1)}. If the custom settings are empty, this function is
  1733. * equivalent to calling {@link (getFirestore:1)}.
  1734. *
  1735. * @param app - The {@link @firebase/app#FirebaseApp} with which the `Firestore` instance will
  1736. * be associated.
  1737. * @param settings - A settings object to configure the `Firestore` instance.
  1738. * @param databaseId - The name of database.
  1739. * @returns A newly initialized `Firestore` instance.
  1740. * @internal
  1741. */
  1742. export declare function initializeFirestore(app: FirebaseApp, settings: Settings, databaseId?: string): Firestore;
  1743. /**
  1744. * Creates a {@link QueryLimitConstraint} that only returns the first matching
  1745. * documents.
  1746. *
  1747. * @param limit - The maximum number of items to return.
  1748. * @returns The created {@link QueryLimitConstraint}.
  1749. */
  1750. export declare function limit(limit: number): QueryLimitConstraint;
  1751. /**
  1752. * Creates a {@link QueryLimitConstraint} that only returns the last matching
  1753. * documents.
  1754. *
  1755. * You must specify at least one `orderBy` clause for `limitToLast` queries,
  1756. * otherwise an exception will be thrown during execution.
  1757. *
  1758. * @param limit - The maximum number of items to return.
  1759. * @returns The created {@link QueryLimitConstraint}.
  1760. */
  1761. export declare function limitToLast(limit: number): QueryLimitConstraint;
  1762. declare const enum LimitType {
  1763. First = "F",
  1764. Last = "L"
  1765. }
  1766. export { LogLevel }
  1767. declare type MapValue = firestoreV1ApiClientInterfaces.MapValue;
  1768. /**
  1769. * Represents a document in Firestore with a key, version, data and whether it
  1770. * has local mutations applied to it.
  1771. *
  1772. * Documents can transition between states via `convertToFoundDocument()`,
  1773. * `convertToNoDocument()` and `convertToUnknownDocument()`. If a document does
  1774. * not transition to one of these states even after all mutations have been
  1775. * applied, `isValidDocument()` returns false and the document should be removed
  1776. * from all views.
  1777. */
  1778. declare class MutableDocument implements Document_2 {
  1779. readonly key: DocumentKey;
  1780. private documentType;
  1781. version: SnapshotVersion;
  1782. readTime: SnapshotVersion;
  1783. createTime: SnapshotVersion;
  1784. data: ObjectValue;
  1785. private documentState;
  1786. private constructor();
  1787. /**
  1788. * Creates a document with no known version or data, but which can serve as
  1789. * base document for mutations.
  1790. */
  1791. static newInvalidDocument(documentKey: DocumentKey): MutableDocument;
  1792. /**
  1793. * Creates a new document that is known to exist with the given data at the
  1794. * given version.
  1795. */
  1796. static newFoundDocument(documentKey: DocumentKey, version: SnapshotVersion, createTime: SnapshotVersion, value: ObjectValue): MutableDocument;
  1797. /** Creates a new document that is known to not exist at the given version. */
  1798. static newNoDocument(documentKey: DocumentKey, version: SnapshotVersion): MutableDocument;
  1799. /**
  1800. * Creates a new document that is known to exist at the given version but
  1801. * whose data is not known (e.g. a document that was updated without a known
  1802. * base document).
  1803. */
  1804. static newUnknownDocument(documentKey: DocumentKey, version: SnapshotVersion): MutableDocument;
  1805. /**
  1806. * Changes the document type to indicate that it exists and that its version
  1807. * and data are known.
  1808. */
  1809. convertToFoundDocument(version: SnapshotVersion, value: ObjectValue): MutableDocument;
  1810. /**
  1811. * Changes the document type to indicate that it doesn't exist at the given
  1812. * version.
  1813. */
  1814. convertToNoDocument(version: SnapshotVersion): MutableDocument;
  1815. /**
  1816. * Changes the document type to indicate that it exists at a given version but
  1817. * that its data is not known (e.g. a document that was updated without a known
  1818. * base document).
  1819. */
  1820. convertToUnknownDocument(version: SnapshotVersion): MutableDocument;
  1821. setHasCommittedMutations(): MutableDocument;
  1822. setHasLocalMutations(): MutableDocument;
  1823. setReadTime(readTime: SnapshotVersion): MutableDocument;
  1824. get hasLocalMutations(): boolean;
  1825. get hasCommittedMutations(): boolean;
  1826. get hasPendingWrites(): boolean;
  1827. isValidDocument(): boolean;
  1828. isFoundDocument(): boolean;
  1829. isNoDocument(): boolean;
  1830. isUnknownDocument(): boolean;
  1831. isEqual(other: Document_2 | null | undefined): boolean;
  1832. mutableCopy(): MutableDocument;
  1833. toString(): string;
  1834. }
  1835. /**
  1836. * A mutation describes a self-contained change to a document. Mutations can
  1837. * create, replace, delete, and update subsets of documents.
  1838. *
  1839. * Mutations not only act on the value of the document but also its version.
  1840. *
  1841. * For local mutations (mutations that haven't been committed yet), we preserve
  1842. * the existing version for Set and Patch mutations. For Delete mutations, we
  1843. * reset the version to 0.
  1844. *
  1845. * Here's the expected transition table.
  1846. *
  1847. * MUTATION APPLIED TO RESULTS IN
  1848. *
  1849. * SetMutation Document(v3) Document(v3)
  1850. * SetMutation NoDocument(v3) Document(v0)
  1851. * SetMutation InvalidDocument(v0) Document(v0)
  1852. * PatchMutation Document(v3) Document(v3)
  1853. * PatchMutation NoDocument(v3) NoDocument(v3)
  1854. * PatchMutation InvalidDocument(v0) UnknownDocument(v3)
  1855. * DeleteMutation Document(v3) NoDocument(v0)
  1856. * DeleteMutation NoDocument(v3) NoDocument(v0)
  1857. * DeleteMutation InvalidDocument(v0) NoDocument(v0)
  1858. *
  1859. * For acknowledged mutations, we use the updateTime of the WriteResponse as
  1860. * the resulting version for Set and Patch mutations. As deletes have no
  1861. * explicit update time, we use the commitTime of the WriteResponse for
  1862. * Delete mutations.
  1863. *
  1864. * If a mutation is acknowledged by the backend but fails the precondition check
  1865. * locally, we transition to an `UnknownDocument` and rely on Watch to send us
  1866. * the updated version.
  1867. *
  1868. * Field transforms are used only with Patch and Set Mutations. We use the
  1869. * `updateTransforms` message to store transforms, rather than the `transforms`s
  1870. * messages.
  1871. *
  1872. * ## Subclassing Notes
  1873. *
  1874. * Every type of mutation needs to implement its own applyToRemoteDocument() and
  1875. * applyToLocalView() to implement the actual behavior of applying the mutation
  1876. * to some source document (see `setMutationApplyToRemoteDocument()` for an
  1877. * example).
  1878. */
  1879. declare abstract class Mutation {
  1880. abstract readonly type: MutationType;
  1881. abstract readonly key: DocumentKey;
  1882. abstract readonly precondition: Precondition;
  1883. abstract readonly fieldTransforms: FieldTransform[];
  1884. /**
  1885. * Returns a `FieldMask` representing the fields that will be changed by
  1886. * applying this mutation. Returns `null` if the mutation will overwrite the
  1887. * entire document.
  1888. */
  1889. abstract getFieldMask(): FieldMask | null;
  1890. }
  1891. declare const enum MutationType {
  1892. Set = 0,
  1893. Patch = 1,
  1894. Delete = 2,
  1895. Verify = 3
  1896. }
  1897. /**
  1898. * For each field (e.g. 'bar'), find all nested keys (e.g. {'bar.baz': T1,
  1899. * 'bar.qux': T2}). Intersect them together to make a single map containing
  1900. * all possible keys that are all marked as optional
  1901. */
  1902. export declare type NestedUpdateFields<T extends Record<string, unknown>> = UnionToIntersection<{
  1903. [K in keyof T & string]: ChildUpdateFields<K, T[K]>;
  1904. }[keyof T & string]>;
  1905. /**
  1906. * An ObjectValue represents a MapValue in the Firestore Proto and offers the
  1907. * ability to add and remove fields (via the ObjectValueBuilder).
  1908. */
  1909. declare class ObjectValue {
  1910. readonly value: {
  1911. mapValue: MapValue;
  1912. };
  1913. constructor(value: {
  1914. mapValue: MapValue;
  1915. });
  1916. static empty(): ObjectValue;
  1917. /**
  1918. * Returns the value at the given path or null.
  1919. *
  1920. * @param path - the path to search
  1921. * @returns The value at the path or null if the path is not set.
  1922. */
  1923. field(path: FieldPath_2): Value | null;
  1924. /**
  1925. * Sets the field to the provided value.
  1926. *
  1927. * @param path - The field path to set.
  1928. * @param value - The value to set.
  1929. */
  1930. set(path: FieldPath_2, value: Value): void;
  1931. /**
  1932. * Sets the provided fields to the provided values.
  1933. *
  1934. * @param data - A map of fields to values (or null for deletes).
  1935. */
  1936. setAll(data: Map<FieldPath_2, Value | null>): void;
  1937. /**
  1938. * Removes the field at the specified path. If there is no field at the
  1939. * specified path, nothing is changed.
  1940. *
  1941. * @param path - The field path to remove.
  1942. */
  1943. delete(path: FieldPath_2): void;
  1944. isEqual(other: ObjectValue): boolean;
  1945. /**
  1946. * Returns the map that contains the leaf element of `path`. If the parent
  1947. * entry does not yet exist, or if it is not a map, a new map will be created.
  1948. */
  1949. private getFieldsMap;
  1950. /**
  1951. * Modifies `fieldsMap` by adding, replacing or deleting the specified
  1952. * entries.
  1953. */
  1954. private applyChanges;
  1955. clone(): ObjectValue;
  1956. }
  1957. declare const enum Operator {
  1958. LESS_THAN = "<",
  1959. LESS_THAN_OR_EQUAL = "<=",
  1960. EQUAL = "==",
  1961. NOT_EQUAL = "!=",
  1962. GREATER_THAN = ">",
  1963. GREATER_THAN_OR_EQUAL = ">=",
  1964. ARRAY_CONTAINS = "array-contains",
  1965. IN = "in",
  1966. NOT_IN = "not-in",
  1967. ARRAY_CONTAINS_ANY = "array-contains-any"
  1968. }
  1969. /**
  1970. * Creates a new {@link QueryCompositeFilterConstraint} that is a disjunction of
  1971. * the given filter constraints. A disjunction filter includes a document if it
  1972. * satisfies any of the given filters.
  1973. *
  1974. * @param queryConstraints - Optional. The list of
  1975. * {@link QueryFilterConstraint}s to perform a disjunction for. These must be
  1976. * created with calls to {@link where}, {@link or}, or {@link and}.
  1977. * @returns The newly created {@link QueryCompositeFilterConstraint}.
  1978. * @internal TODO remove this internal tag with OR Query support in the server
  1979. */
  1980. export declare function or(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;
  1981. /**
  1982. * An ordering on a field, in some Direction. Direction defaults to ASCENDING.
  1983. */
  1984. declare class OrderBy {
  1985. readonly field: FieldPath_2;
  1986. readonly dir: Direction;
  1987. constructor(field: FieldPath_2, dir?: Direction);
  1988. }
  1989. /**
  1990. * Creates a {@link QueryOrderByConstraint} that sorts the query result by the
  1991. * specified field, optionally in descending order instead of ascending.
  1992. *
  1993. * Note: Documents that do not contain the specified field will not be present
  1994. * in the query result.
  1995. *
  1996. * @param fieldPath - The field to sort by.
  1997. * @param directionStr - Optional direction to sort by ('asc' or 'desc'). If
  1998. * not specified, order will be ascending.
  1999. * @returns The created {@link QueryOrderByConstraint}.
  2000. */
  2001. export declare function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryOrderByConstraint;
  2002. /**
  2003. * The direction of a {@link orderBy} clause is specified as 'desc' or 'asc'
  2004. * (descending or ascending).
  2005. */
  2006. export declare type OrderByDirection = 'desc' | 'asc';
  2007. declare type OrderDirection = 'DIRECTION_UNSPECIFIED' | 'ASCENDING' | 'DESCENDING';
  2008. declare interface ParseContext {
  2009. readonly databaseId: DatabaseId;
  2010. readonly ignoreUndefinedProperties: boolean;
  2011. }
  2012. /** The result of parsing document data (e.g. for a setData call). */
  2013. declare class ParsedSetData {
  2014. readonly data: ObjectValue;
  2015. readonly fieldMask: FieldMask | null;
  2016. readonly fieldTransforms: FieldTransform[];
  2017. constructor(data: ObjectValue, fieldMask: FieldMask | null, fieldTransforms: FieldTransform[]);
  2018. toMutation(key: DocumentKey, precondition: Precondition): Mutation;
  2019. }
  2020. /** The result of parsing "update" data (i.e. for an updateData call). */
  2021. declare class ParsedUpdateData {
  2022. readonly data: ObjectValue;
  2023. readonly fieldMask: FieldMask;
  2024. readonly fieldTransforms: FieldTransform[];
  2025. constructor(data: ObjectValue, fieldMask: FieldMask, fieldTransforms: FieldTransform[]);
  2026. toMutation(key: DocumentKey, precondition: Precondition): Mutation;
  2027. }
  2028. /**
  2029. * Similar to Typescript's `Partial<T>`, but allows nested fields to be
  2030. * omitted and FieldValues to be passed in as property values.
  2031. */
  2032. export declare type PartialWithFieldValue<T> = Partial<T> | (T extends Primitive ? T : T extends {} ? {
  2033. [K in keyof T]?: PartialWithFieldValue<T[K]> | FieldValue;
  2034. } : never);
  2035. /**
  2036. * Encodes a precondition for a mutation. This follows the model that the
  2037. * backend accepts with the special case of an explicit "empty" precondition
  2038. * (meaning no precondition).
  2039. */
  2040. declare class Precondition {
  2041. readonly updateTime?: SnapshotVersion | undefined;
  2042. readonly exists?: boolean | undefined;
  2043. private constructor();
  2044. /** Creates a new empty Precondition. */
  2045. static none(): Precondition;
  2046. /** Creates a new Precondition with an exists flag. */
  2047. static exists(exists: boolean): Precondition;
  2048. /** Creates a new Precondition based on a version a document exists at. */
  2049. static updateTime(version: SnapshotVersion): Precondition;
  2050. /** Returns whether this Precondition is empty. */
  2051. get isNone(): boolean;
  2052. isEqual(other: Precondition): boolean;
  2053. }
  2054. /**
  2055. * These types primarily exist to support the `UpdateData`,
  2056. * `WithFieldValue`, and `PartialWithFieldValue` types and are not consumed
  2057. * directly by the end developer.
  2058. */
  2059. /** Primitive types. */
  2060. export declare type Primitive = string | number | boolean | undefined | null;
  2061. /** Undocumented, private additional settings not exposed in our public API. */
  2062. declare interface PrivateSettings extends Settings {
  2063. credentials?: CredentialsSettings;
  2064. cacheSizeBytes?: number;
  2065. experimentalForceLongPolling?: boolean;
  2066. experimentalAutoDetectLongPolling?: boolean;
  2067. useFetchStreams?: boolean;
  2068. }
  2069. declare interface ProviderCredentialsSettings {
  2070. ['type']: 'provider';
  2071. ['client']: CredentialsProvider<User>;
  2072. }
  2073. /**
  2074. * A `Query` refers to a query which you can read or listen to. You can also
  2075. * construct refined `Query` objects by adding filters and ordering.
  2076. */
  2077. export declare class Query<T = DocumentData> {
  2078. /**
  2079. * If provided, the `FirestoreDataConverter` associated with this instance.
  2080. */
  2081. readonly converter: FirestoreDataConverter<T> | null;
  2082. readonly _query: Query_2;
  2083. /** The type of this Firestore reference. */
  2084. readonly type: 'query' | 'collection';
  2085. /**
  2086. * The `Firestore` instance for the Firestore database (useful for performing
  2087. * transactions, etc.).
  2088. */
  2089. readonly firestore: Firestore;
  2090. /** @hideconstructor protected */
  2091. constructor(firestore: Firestore,
  2092. /**
  2093. * If provided, the `FirestoreDataConverter` associated with this instance.
  2094. */
  2095. converter: FirestoreDataConverter<T> | null, _query: Query_2);
  2096. /**
  2097. * Removes the current converter.
  2098. *
  2099. * @param converter - `null` removes the current converter.
  2100. * @returns A `Query<DocumentData>` that does not use a converter.
  2101. */
  2102. withConverter(converter: null): Query<DocumentData>;
  2103. /**
  2104. * Applies a custom data converter to this query, allowing you to use your own
  2105. * custom model objects with Firestore. When you call {@link getDocs} with
  2106. * the returned query, the provided converter will convert between Firestore
  2107. * data and your custom type `U`.
  2108. *
  2109. * @param converter - Converts objects to and from Firestore.
  2110. * @returns A `Query<U>` that uses the provided converter.
  2111. */
  2112. withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
  2113. }
  2114. /**
  2115. * Creates a new immutable instance of {@link Query} that is extended to also
  2116. * include additional query constraints.
  2117. *
  2118. * @param query - The {@link Query} instance to use as a base for the new
  2119. * constraints.
  2120. * @param compositeFilter - The {@link QueryCompositeFilterConstraint} to
  2121. * apply. Create {@link QueryCompositeFilterConstraint} using {@link and} or
  2122. * {@link or}.
  2123. * @param queryConstraints - Additional {@link QueryNonFilterConstraint}s to
  2124. * apply (e.g. {@link orderBy}, {@link limit}).
  2125. * @throws if any of the provided query constraints cannot be combined with the
  2126. * existing or new constraints.
  2127. * @internal TODO remove this internal tag with OR Query support in the server
  2128. */
  2129. export declare function query<T>(query: Query<T>, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query<T>;
  2130. /**
  2131. * Creates a new immutable instance of {@link Query} that is extended to also
  2132. * include additional query constraints.
  2133. *
  2134. * @param query - The {@link Query} instance to use as a base for the new
  2135. * constraints.
  2136. * @param queryConstraints - The list of {@link QueryConstraint}s to apply.
  2137. * @throws if any of the provided query constraints cannot be combined with the
  2138. * existing or new constraints.
  2139. */
  2140. export declare function query<T>(query: Query<T>, ...queryConstraints: QueryConstraint[]): Query<T>;
  2141. /**
  2142. * The Query interface defines all external properties of a query.
  2143. *
  2144. * QueryImpl implements this interface to provide memoization for `queryOrderBy`
  2145. * and `queryToTarget`.
  2146. */
  2147. declare interface Query_2 {
  2148. readonly path: ResourcePath;
  2149. readonly collectionGroup: string | null;
  2150. readonly explicitOrderBy: OrderBy[];
  2151. readonly filters: Filter[];
  2152. readonly limit: number | null;
  2153. readonly limitType: LimitType;
  2154. readonly startAt: Bound | null;
  2155. readonly endAt: Bound | null;
  2156. }
  2157. /**
  2158. * A `QueryCompositeFilterConstraint` is used to narrow the set of documents
  2159. * returned by a Firestore query by performing the logical OR or AND of multiple
  2160. * {@link QueryFieldFilterConstraint}s or {@link QueryCompositeFilterConstraint}s.
  2161. * `QueryCompositeFilterConstraint`s are created by invoking {@link or} or
  2162. * {@link and} and can then be passed to {@link query} to create a new query
  2163. * instance that also contains the `QueryCompositeFilterConstraint`.
  2164. * @internal TODO remove this internal tag with OR Query support in the server
  2165. */
  2166. export declare class QueryCompositeFilterConstraint extends AppliableConstraint {
  2167. /** The type of this query constraint */
  2168. readonly type: 'or' | 'and';
  2169. private readonly _queryConstraints;
  2170. /**
  2171. * @internal
  2172. */
  2173. protected constructor(
  2174. /** The type of this query constraint */
  2175. type: 'or' | 'and', _queryConstraints: QueryFilterConstraint[]);
  2176. static _create(type: 'or' | 'and', _queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;
  2177. _parse<T>(query: Query<T>): Filter;
  2178. _apply<T>(query: Query<T>): Query<T>;
  2179. _getQueryConstraints(): readonly AppliableConstraint[];
  2180. _getOperator(): CompositeOperator;
  2181. }
  2182. /**
  2183. * A `QueryConstraint` is used to narrow the set of documents returned by a
  2184. * Firestore query. `QueryConstraint`s are created by invoking {@link where},
  2185. * {@link orderBy}, {@link startAt}, {@link startAfter}, {@link
  2186. * endBefore}, {@link endAt}, {@link limit}, {@link limitToLast} and
  2187. * can then be passed to {@link query} to create a new query instance that
  2188. * also contains this `QueryConstraint`.
  2189. */
  2190. export declare abstract class QueryConstraint extends AppliableConstraint {
  2191. /** The type of this query constraint */
  2192. abstract readonly type: QueryConstraintType;
  2193. /**
  2194. * Takes the provided {@link Query} and returns a copy of the {@link Query} with this
  2195. * {@link AppliableConstraint} applied.
  2196. */
  2197. abstract _apply<T>(query: Query<T>): Query<T>;
  2198. }
  2199. /** Describes the different query constraints available in this SDK. */
  2200. export declare type QueryConstraintType = 'where' | 'orderBy' | 'limit' | 'limitToLast' | 'startAt' | 'startAfter' | 'endAt' | 'endBefore';
  2201. /**
  2202. * A `QueryDocumentSnapshot` contains data read from a document in your
  2203. * Firestore database as part of a query. The document is guaranteed to exist
  2204. * and its data can be extracted with `.data()` or `.get(<field>)` to get a
  2205. * specific field.
  2206. *
  2207. * A `QueryDocumentSnapshot` offers the same API surface as a
  2208. * `DocumentSnapshot`. Since query results contain only existing documents, the
  2209. * `exists` property will always be true and `data()` will never return
  2210. * 'undefined'.
  2211. */
  2212. export declare class QueryDocumentSnapshot<T = DocumentData> extends DocumentSnapshot<T> {
  2213. /**
  2214. * Retrieves all fields in the document as an `Object`.
  2215. *
  2216. * @override
  2217. * @returns An `Object` containing all fields in the document.
  2218. */
  2219. data(): T;
  2220. }
  2221. /**
  2222. * A `QueryEndAtConstraint` is used to exclude documents from the end of a
  2223. * result set returned by a Firestore query.
  2224. * `QueryEndAtConstraint`s are created by invoking {@link (endAt:1)} or
  2225. * {@link (endBefore:1)} and can then be passed to {@link query} to create a new
  2226. * query instance that also contains this `QueryEndAtConstraint`.
  2227. */
  2228. export declare class QueryEndAtConstraint extends QueryConstraint {
  2229. /** The type of this query constraint */
  2230. readonly type: 'endBefore' | 'endAt';
  2231. private readonly _docOrFields;
  2232. private readonly _inclusive;
  2233. /**
  2234. * @internal
  2235. */
  2236. protected constructor(
  2237. /** The type of this query constraint */
  2238. type: 'endBefore' | 'endAt', _docOrFields: Array<unknown | DocumentSnapshot<unknown>>, _inclusive: boolean);
  2239. static _create(type: 'endBefore' | 'endAt', _docOrFields: Array<unknown | DocumentSnapshot<unknown>>, _inclusive: boolean): QueryEndAtConstraint;
  2240. _apply<T>(query: Query<T>): Query<T>;
  2241. }
  2242. /**
  2243. * Returns true if the provided queries point to the same collection and apply
  2244. * the same constraints.
  2245. *
  2246. * @param left - A `Query` to compare.
  2247. * @param right - A `Query` to compare.
  2248. * @returns true if the references point to the same location in the same
  2249. * Firestore database.
  2250. */
  2251. export declare function queryEqual<T>(left: Query<T>, right: Query<T>): boolean;
  2252. /**
  2253. * A `QueryFieldFilterConstraint` is used to narrow the set of documents returned by
  2254. * a Firestore query by filtering on one or more document fields.
  2255. * `QueryFieldFilterConstraint`s are created by invoking {@link where} and can then
  2256. * be passed to {@link query} to create a new query instance that also contains
  2257. * this `QueryFieldFilterConstraint`.
  2258. */
  2259. export declare class QueryFieldFilterConstraint extends QueryConstraint {
  2260. private readonly _field;
  2261. private _op;
  2262. private _value;
  2263. /** The type of this query constraint */
  2264. readonly type = "where";
  2265. /**
  2266. * @internal
  2267. */
  2268. protected constructor(_field: FieldPath_2, _op: Operator, _value: unknown);
  2269. static _create(_field: FieldPath_2, _op: Operator, _value: unknown): QueryFieldFilterConstraint;
  2270. _apply<T>(query: Query<T>): Query<T>;
  2271. _parse<T>(query: Query<T>): FieldFilter;
  2272. }
  2273. /**
  2274. * `QueryFilterConstraint` is a helper union type that represents
  2275. * {@link QueryFieldFilterConstraint} and {@link QueryCompositeFilterConstraint}.
  2276. * `QueryFilterConstraint`s are created by invoking {@link or} or {@link and}
  2277. * and can then be passed to {@link query} to create a new query instance that
  2278. * also contains the `QueryConstraint`.
  2279. * @internal TODO remove this internal tag with OR Query support in the server
  2280. */
  2281. export declare type QueryFilterConstraint = QueryFieldFilterConstraint | QueryCompositeFilterConstraint;
  2282. /**
  2283. * A `QueryLimitConstraint` is used to limit the number of documents returned by
  2284. * a Firestore query.
  2285. * `QueryLimitConstraint`s are created by invoking {@link limit} or
  2286. * {@link limitToLast} and can then be passed to {@link query} to create a new
  2287. * query instance that also contains this `QueryLimitConstraint`.
  2288. */
  2289. export declare class QueryLimitConstraint extends QueryConstraint {
  2290. /** The type of this query constraint */
  2291. readonly type: 'limit' | 'limitToLast';
  2292. private readonly _limit;
  2293. private readonly _limitType;
  2294. /**
  2295. * @internal
  2296. */
  2297. protected constructor(
  2298. /** The type of this query constraint */
  2299. type: 'limit' | 'limitToLast', _limit: number, _limitType: LimitType);
  2300. static _create(type: 'limit' | 'limitToLast', _limit: number, _limitType: LimitType): QueryLimitConstraint;
  2301. _apply<T>(query: Query<T>): Query<T>;
  2302. }
  2303. /**
  2304. * `QueryNonFilterConstraint` is a helper union type that represents
  2305. * QueryConstraints which are used to narrow or order the set of documents,
  2306. * but that do not explicitly filter on a document field.
  2307. * `QueryNonFilterConstraint`s are created by invoking {@link orderBy},
  2308. * {@link startAt}, {@link startAfter}, {@link endBefore}, {@link endAt},
  2309. * {@link limit} or {@link limitToLast} and can then be passed to {@link query}
  2310. * to create a new query instance that also contains the `QueryConstraint`.
  2311. */
  2312. export declare type QueryNonFilterConstraint = QueryOrderByConstraint | QueryLimitConstraint | QueryStartAtConstraint | QueryEndAtConstraint;
  2313. /**
  2314. * A `QueryOrderByConstraint` is used to sort the set of documents returned by a
  2315. * Firestore query. `QueryOrderByConstraint`s are created by invoking
  2316. * {@link orderBy} and can then be passed to {@link query} to create a new query
  2317. * instance that also contains this `QueryOrderByConstraint`.
  2318. *
  2319. * Note: Documents that do not contain the orderBy field will not be present in
  2320. * the query result.
  2321. */
  2322. export declare class QueryOrderByConstraint extends QueryConstraint {
  2323. private readonly _field;
  2324. private _direction;
  2325. /** The type of this query constraint */
  2326. readonly type = "orderBy";
  2327. /**
  2328. * @internal
  2329. */
  2330. protected constructor(_field: FieldPath_2, _direction: Direction);
  2331. static _create(_field: FieldPath_2, _direction: Direction): QueryOrderByConstraint;
  2332. _apply<T>(query: Query<T>): Query<T>;
  2333. }
  2334. /**
  2335. * A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects
  2336. * representing the results of a query. The documents can be accessed as an
  2337. * array via the `docs` property or enumerated using the `forEach` method. The
  2338. * number of documents can be determined via the `empty` and `size`
  2339. * properties.
  2340. */
  2341. export declare class QuerySnapshot<T = DocumentData> {
  2342. readonly _docs: Array<QueryDocumentSnapshot<T>>;
  2343. /**
  2344. * The query on which you called {@link getDocs} in order to get this
  2345. * `QuerySnapshot`.
  2346. */
  2347. readonly query: Query<T>;
  2348. /** @hideconstructor */
  2349. constructor(_query: Query<T>, _docs: Array<QueryDocumentSnapshot<T>>);
  2350. /** An array of all the documents in the `QuerySnapshot`. */
  2351. get docs(): Array<QueryDocumentSnapshot<T>>;
  2352. /** The number of documents in the `QuerySnapshot`. */
  2353. get size(): number;
  2354. /** True if there are no documents in the `QuerySnapshot`. */
  2355. get empty(): boolean;
  2356. /**
  2357. * Enumerates all of the documents in the `QuerySnapshot`.
  2358. *
  2359. * @param callback - A callback to be called with a `QueryDocumentSnapshot` for
  2360. * each document in the snapshot.
  2361. * @param thisArg - The `this` binding for the callback.
  2362. */
  2363. forEach(callback: (result: QueryDocumentSnapshot<T>) => void, thisArg?: unknown): void;
  2364. }
  2365. /**
  2366. * A `QueryStartAtConstraint` is used to exclude documents from the start of a
  2367. * result set returned by a Firestore query.
  2368. * `QueryStartAtConstraint`s are created by invoking {@link (startAt:1)} or
  2369. * {@link (startAfter:1)} and can then be passed to {@link query} to create a
  2370. * new query instance that also contains this `QueryStartAtConstraint`.
  2371. */
  2372. export declare class QueryStartAtConstraint extends QueryConstraint {
  2373. /** The type of this query constraint */
  2374. readonly type: 'startAt' | 'startAfter';
  2375. private readonly _docOrFields;
  2376. private readonly _inclusive;
  2377. /**
  2378. * @internal
  2379. */
  2380. protected constructor(
  2381. /** The type of this query constraint */
  2382. type: 'startAt' | 'startAfter', _docOrFields: Array<unknown | DocumentSnapshot<unknown>>, _inclusive: boolean);
  2383. static _create(type: 'startAt' | 'startAfter', _docOrFields: Array<unknown | DocumentSnapshot<unknown>>, _inclusive: boolean): QueryStartAtConstraint;
  2384. _apply<T>(query: Query<T>): Query<T>;
  2385. }
  2386. /**
  2387. * Returns true if the provided references are equal.
  2388. *
  2389. * @param left - A reference to compare.
  2390. * @param right - A reference to compare.
  2391. * @returns true if the references point to the same location in the same
  2392. * Firestore database.
  2393. */
  2394. export declare function refEqual<T>(left: DocumentReference<T> | CollectionReference<T>, right: DocumentReference<T> | CollectionReference<T>): boolean;
  2395. /**
  2396. * A slash-separated path for navigating resources (documents and collections)
  2397. * within Firestore.
  2398. *
  2399. * @internal
  2400. */
  2401. declare class ResourcePath extends BasePath<ResourcePath> {
  2402. protected construct(segments: string[], offset?: number, length?: number): ResourcePath;
  2403. canonicalString(): string;
  2404. toString(): string;
  2405. /**
  2406. * Creates a resource path from the given slash-delimited string. If multiple
  2407. * arguments are provided, all components are combined. Leading and trailing
  2408. * slashes from all components are ignored.
  2409. */
  2410. static fromString(...pathComponents: string[]): ResourcePath;
  2411. static emptyPath(): ResourcePath;
  2412. }
  2413. /**
  2414. * Executes the given `updateFunction` and then attempts to commit the changes
  2415. * applied within the transaction. If any document read within the transaction
  2416. * has changed, Cloud Firestore retries the `updateFunction`. If it fails to
  2417. * commit after 5 attempts, the transaction fails.
  2418. *
  2419. * The maximum number of writes allowed in a single transaction is 500.
  2420. *
  2421. * @param firestore - A reference to the Firestore database to run this
  2422. * transaction against.
  2423. * @param updateFunction - The function to execute within the transaction
  2424. * context.
  2425. * @param options - An options object to configure maximum number of attempts to
  2426. * commit.
  2427. * @returns If the transaction completed successfully or was explicitly aborted
  2428. * (the `updateFunction` returned a failed promise), the promise returned by the
  2429. * `updateFunction `is returned here. Otherwise, if the transaction failed, a
  2430. * rejected promise with the corresponding failure error is returned.
  2431. */
  2432. export declare function runTransaction<T>(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
  2433. /**
  2434. * Returns a sentinel used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link @firebase/firestore/lite#(updateDoc:1)} to
  2435. * include a server-generated timestamp in the written data.
  2436. */
  2437. export declare function serverTimestamp(): FieldValue;
  2438. declare type ServerTimestampBehavior = 'estimate' | 'previous' | 'none';
  2439. /**
  2440. * Writes to the document referred to by the specified `DocumentReference`. If
  2441. * the document does not yet exist, it will be created.
  2442. *
  2443. * The result of this write will only be reflected in document reads that occur
  2444. * after the returned promise resolves. If the client is offline, the
  2445. * write fails. If you would like to see local modifications or buffer writes
  2446. * until the client is online, use the full Firestore SDK.
  2447. *
  2448. * @param reference - A reference to the document to write.
  2449. * @param data - A map of the fields and values for the document.
  2450. * @throws Error - If the provided input is not a valid Firestore document.
  2451. * @returns A `Promise` resolved once the data has been successfully written
  2452. * to the backend.
  2453. */
  2454. export declare function setDoc<T>(reference: DocumentReference<T>, data: WithFieldValue<T>): Promise<void>;
  2455. /**
  2456. * Writes to the document referred to by the specified `DocumentReference`. If
  2457. * the document does not yet exist, it will be created. If you provide `merge`
  2458. * or `mergeFields`, the provided data can be merged into an existing document.
  2459. *
  2460. * The result of this write will only be reflected in document reads that occur
  2461. * after the returned promise resolves. If the client is offline, the
  2462. * write fails. If you would like to see local modifications or buffer writes
  2463. * until the client is online, use the full Firestore SDK.
  2464. *
  2465. * @param reference - A reference to the document to write.
  2466. * @param data - A map of the fields and values for the document.
  2467. * @param options - An object to configure the set behavior.
  2468. * @throws Error - If the provided input is not a valid Firestore document.
  2469. * @returns A `Promise` resolved once the data has been successfully written
  2470. * to the backend.
  2471. */
  2472. export declare function setDoc<T>(reference: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): Promise<void>;
  2473. /**
  2474. * Sets the verbosity of Cloud Firestore logs (debug, error, or silent).
  2475. *
  2476. * @param logLevel - The verbosity you set for activity and error logging. Can
  2477. * be any of the following values:
  2478. *
  2479. * <ul>
  2480. * <li>`debug` for the most verbose logging level, primarily for
  2481. * debugging.</li>
  2482. * <li>`error` to log errors only.</li>
  2483. * <li><code>`silent` to turn off logging.</li>
  2484. * </ul>
  2485. */
  2486. export declare function setLogLevel(logLevel: LogLevel): void;
  2487. /**
  2488. * An options object that configures the behavior of {@link @firebase/firestore/lite#(setDoc:1)}, {@link
  2489. * @firebase/firestore/lite#(WriteBatch.set:1)} and {@link @firebase/firestore/lite#(Transaction.set:1)} calls. These calls can be
  2490. * configured to perform granular merges instead of overwriting the target
  2491. * documents in their entirety by providing a `SetOptions` with `merge: true`.
  2492. *
  2493. * @param merge - Changes the behavior of a `setDoc()` call to only replace the
  2494. * values specified in its data argument. Fields omitted from the `setDoc()`
  2495. * call remain untouched. If your input sets any field to an empty map, all
  2496. * nested fields are overwritten.
  2497. * @param mergeFields - Changes the behavior of `setDoc()` calls to only replace
  2498. * the specified field paths. Any field path that is not specified is ignored
  2499. * and remains untouched. If your input sets any field to an empty map, all
  2500. * nested fields are overwritten.
  2501. */
  2502. export declare type SetOptions = {
  2503. readonly merge?: boolean;
  2504. } | {
  2505. readonly mergeFields?: Array<string | FieldPath>;
  2506. };
  2507. /**
  2508. * Specifies custom configurations for your Cloud Firestore instance.
  2509. * You must set these before invoking any other methods.
  2510. */
  2511. export declare interface Settings {
  2512. /** The hostname to connect to. */
  2513. host?: string;
  2514. /** Whether to use SSL when connecting. */
  2515. ssl?: boolean;
  2516. /**
  2517. * Whether to skip nested properties that are set to `undefined` during
  2518. * object serialization. If set to `true`, these properties are skipped
  2519. * and not written to Firestore. If set to `false` or omitted, the SDK
  2520. * throws an exception when it encounters properties of type `undefined`.
  2521. */
  2522. ignoreUndefinedProperties?: boolean;
  2523. }
  2524. /**
  2525. * Returns true if the provided snapshots are equal.
  2526. *
  2527. * @param left - A snapshot to compare.
  2528. * @param right - A snapshot to compare.
  2529. * @returns true if the snapshots are equal.
  2530. */
  2531. export declare function snapshotEqual<T>(left: DocumentSnapshot<T> | QuerySnapshot<T>, right: DocumentSnapshot<T> | QuerySnapshot<T>): boolean;
  2532. /**
  2533. * A version of a document in Firestore. This corresponds to the version
  2534. * timestamp, such as update_time or read_time.
  2535. */
  2536. declare class SnapshotVersion {
  2537. private timestamp;
  2538. static fromTimestamp(value: Timestamp): SnapshotVersion;
  2539. static min(): SnapshotVersion;
  2540. static max(): SnapshotVersion;
  2541. private constructor();
  2542. compareTo(other: SnapshotVersion): number;
  2543. isEqual(other: SnapshotVersion): boolean;
  2544. /** Returns a number representation of the version for use in spec tests. */
  2545. toMicroseconds(): number;
  2546. toString(): string;
  2547. toTimestamp(): Timestamp;
  2548. }
  2549. /**
  2550. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  2551. * start after the provided document (exclusive). The starting position is
  2552. * relative to the order of the query. The document must contain all of the
  2553. * fields provided in the orderBy of the query.
  2554. *
  2555. * @param snapshot - The snapshot of the document to start after.
  2556. * @returns A {@link QueryStartAtConstraint} to pass to `query()`
  2557. */
  2558. export declare function startAfter(snapshot: DocumentSnapshot<unknown>): QueryStartAtConstraint;
  2559. /**
  2560. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  2561. * start after the provided fields relative to the order of the query. The order
  2562. * of the field values must match the order of the order by clauses of the query.
  2563. *
  2564. * @param fieldValues - The field values to start this query after, in order
  2565. * of the query's order by.
  2566. * @returns A {@link QueryStartAtConstraint} to pass to `query()`
  2567. */
  2568. export declare function startAfter(...fieldValues: unknown[]): QueryStartAtConstraint;
  2569. /**
  2570. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  2571. * start at the provided document (inclusive). The starting position is relative
  2572. * to the order of the query. The document must contain all of the fields
  2573. * provided in the `orderBy` of this query.
  2574. *
  2575. * @param snapshot - The snapshot of the document to start at.
  2576. * @returns A {@link QueryStartAtConstraint} to pass to `query()`.
  2577. */
  2578. export declare function startAt(snapshot: DocumentSnapshot<unknown>): QueryStartAtConstraint;
  2579. /**
  2580. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  2581. * start at the provided fields relative to the order of the query. The order of
  2582. * the field values must match the order of the order by clauses of the query.
  2583. *
  2584. * @param fieldValues - The field values to start this query at, in order
  2585. * of the query's order by.
  2586. * @returns A {@link QueryStartAtConstraint} to pass to `query()`.
  2587. */
  2588. export declare function startAt(...fieldValues: unknown[]): QueryStartAtConstraint;
  2589. declare type TargetChangeTargetChangeType = 'NO_CHANGE' | 'ADD' | 'REMOVE' | 'CURRENT' | 'RESET';
  2590. /**
  2591. * Terminates the provided `Firestore` instance.
  2592. *
  2593. * After calling `terminate()` only the `clearIndexedDbPersistence()` functions
  2594. * may be used. Any other function will throw a `FirestoreError`. Termination
  2595. * does not cancel any pending writes, and any promises that are awaiting a
  2596. * response from the server will not be resolved.
  2597. *
  2598. * To restart after termination, create a new instance of `Firestore` with
  2599. * {@link (getFirestore:1)}.
  2600. *
  2601. * Note: Under normal circumstances, calling `terminate()` is not required. This
  2602. * function is useful only when you want to force this instance to release all of
  2603. * its resources or in combination with {@link clearIndexedDbPersistence} to
  2604. * ensure that all local state is destroyed between test runs.
  2605. *
  2606. * @param firestore - The `Firestore` instance to terminate.
  2607. * @returns A `Promise` that is resolved when the instance has been successfully
  2608. * terminated.
  2609. */
  2610. export declare function terminate(firestore: Firestore): Promise<void>;
  2611. /**
  2612. * Wellknown "timer" IDs used when scheduling delayed operations on the
  2613. * AsyncQueue. These IDs can then be used from tests to check for the presence
  2614. * of operations or to run them early.
  2615. *
  2616. * The string values are used when encoding these timer IDs in JSON spec tests.
  2617. */
  2618. declare const enum TimerId {
  2619. /** All can be used with runDelayedOperationsEarly() to run all timers. */
  2620. All = "all",
  2621. /**
  2622. * The following 5 timers are used in persistent_stream.ts for the listen and
  2623. * write streams. The "Idle" timer is used to close the stream due to
  2624. * inactivity. The "ConnectionBackoff" timer is used to restart a stream once
  2625. * the appropriate backoff delay has elapsed. The health check is used to mark
  2626. * a stream healthy if it has not received an error during its initial setup.
  2627. */
  2628. ListenStreamIdle = "listen_stream_idle",
  2629. ListenStreamConnectionBackoff = "listen_stream_connection_backoff",
  2630. WriteStreamIdle = "write_stream_idle",
  2631. WriteStreamConnectionBackoff = "write_stream_connection_backoff",
  2632. HealthCheckTimeout = "health_check_timeout",
  2633. /**
  2634. * A timer used in online_state_tracker.ts to transition from
  2635. * OnlineState.Unknown to Offline after a set timeout, rather than waiting
  2636. * indefinitely for success or failure.
  2637. */
  2638. OnlineStateTimeout = "online_state_timeout",
  2639. /**
  2640. * A timer used to update the client metadata in IndexedDb, which is used
  2641. * to determine the primary leaseholder.
  2642. */
  2643. ClientMetadataRefresh = "client_metadata_refresh",
  2644. /** A timer used to periodically attempt LRU Garbage collection */
  2645. LruGarbageCollection = "lru_garbage_collection",
  2646. /**
  2647. * A timer used to retry transactions. Since there can be multiple concurrent
  2648. * transactions, multiple of these may be in the queue at a given time.
  2649. */
  2650. TransactionRetry = "transaction_retry",
  2651. /**
  2652. * A timer used to retry operations scheduled via retryable AsyncQueue
  2653. * operations.
  2654. */
  2655. AsyncQueueRetry = "async_queue_retry",
  2656. /**
  2657. * A timer used to periodically attempt index backfill.
  2658. */
  2659. IndexBackfill = "index_backfill"
  2660. }
  2661. /**
  2662. * @license
  2663. * Copyright 2017 Google LLC
  2664. *
  2665. * Licensed under the Apache License, Version 2.0 (the "License");
  2666. * you may not use this file except in compliance with the License.
  2667. * You may obtain a copy of the License at
  2668. *
  2669. * http://www.apache.org/licenses/LICENSE-2.0
  2670. *
  2671. * Unless required by applicable law or agreed to in writing, software
  2672. * distributed under the License is distributed on an "AS IS" BASIS,
  2673. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2674. * See the License for the specific language governing permissions and
  2675. * limitations under the License.
  2676. */
  2677. /**
  2678. * A `Timestamp` represents a point in time independent of any time zone or
  2679. * calendar, represented as seconds and fractions of seconds at nanosecond
  2680. * resolution in UTC Epoch time.
  2681. *
  2682. * It is encoded using the Proleptic Gregorian Calendar which extends the
  2683. * Gregorian calendar backwards to year one. It is encoded assuming all minutes
  2684. * are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second
  2685. * table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to
  2686. * 9999-12-31T23:59:59.999999999Z.
  2687. *
  2688. * For examples and further specifications, refer to the
  2689. * {@link https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto | Timestamp definition}.
  2690. */
  2691. export declare class Timestamp {
  2692. /**
  2693. * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
  2694. */
  2695. readonly seconds: number;
  2696. /**
  2697. * The fractions of a second at nanosecond resolution.*
  2698. */
  2699. readonly nanoseconds: number;
  2700. /**
  2701. * Creates a new timestamp with the current date, with millisecond precision.
  2702. *
  2703. * @returns a new timestamp representing the current date.
  2704. */
  2705. static now(): Timestamp;
  2706. /**
  2707. * Creates a new timestamp from the given date.
  2708. *
  2709. * @param date - The date to initialize the `Timestamp` from.
  2710. * @returns A new `Timestamp` representing the same point in time as the given
  2711. * date.
  2712. */
  2713. static fromDate(date: Date): Timestamp;
  2714. /**
  2715. * Creates a new timestamp from the given number of milliseconds.
  2716. *
  2717. * @param milliseconds - Number of milliseconds since Unix epoch
  2718. * 1970-01-01T00:00:00Z.
  2719. * @returns A new `Timestamp` representing the same point in time as the given
  2720. * number of milliseconds.
  2721. */
  2722. static fromMillis(milliseconds: number): Timestamp;
  2723. /**
  2724. * Creates a new timestamp.
  2725. *
  2726. * @param seconds - The number of seconds of UTC time since Unix epoch
  2727. * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
  2728. * 9999-12-31T23:59:59Z inclusive.
  2729. * @param nanoseconds - The non-negative fractions of a second at nanosecond
  2730. * resolution. Negative second values with fractions must still have
  2731. * non-negative nanoseconds values that count forward in time. Must be
  2732. * from 0 to 999,999,999 inclusive.
  2733. */
  2734. constructor(
  2735. /**
  2736. * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
  2737. */
  2738. seconds: number,
  2739. /**
  2740. * The fractions of a second at nanosecond resolution.*
  2741. */
  2742. nanoseconds: number);
  2743. /**
  2744. * Converts a `Timestamp` to a JavaScript `Date` object. This conversion
  2745. * causes a loss of precision since `Date` objects only support millisecond
  2746. * precision.
  2747. *
  2748. * @returns JavaScript `Date` object representing the same point in time as
  2749. * this `Timestamp`, with millisecond precision.
  2750. */
  2751. toDate(): Date;
  2752. /**
  2753. * Converts a `Timestamp` to a numeric timestamp (in milliseconds since
  2754. * epoch). This operation causes a loss of precision.
  2755. *
  2756. * @returns The point in time corresponding to this timestamp, represented as
  2757. * the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
  2758. */
  2759. toMillis(): number;
  2760. _compareTo(other: Timestamp): number;
  2761. /**
  2762. * Returns true if this `Timestamp` is equal to the provided one.
  2763. *
  2764. * @param other - The `Timestamp` to compare against.
  2765. * @returns true if this `Timestamp` is equal to the provided one.
  2766. */
  2767. isEqual(other: Timestamp): boolean;
  2768. /** Returns a textual representation of this `Timestamp`. */
  2769. toString(): string;
  2770. /** Returns a JSON-serializable representation of this `Timestamp`. */
  2771. toJSON(): {
  2772. seconds: number;
  2773. nanoseconds: number;
  2774. };
  2775. /**
  2776. * Converts this object to a primitive string, which allows `Timestamp` objects
  2777. * to be compared using the `>`, `<=`, `>=` and `>` operators.
  2778. */
  2779. valueOf(): string;
  2780. }
  2781. declare type Timestamp_2 = string | {
  2782. seconds?: string | number;
  2783. nanos?: number;
  2784. };
  2785. declare interface Token {
  2786. /** Type of token. */
  2787. type: TokenType;
  2788. /**
  2789. * The user with which the token is associated (used for persisting user
  2790. * state on disk, etc.).
  2791. * This will be null for Tokens of the type 'AppCheck'.
  2792. */
  2793. user?: User;
  2794. /** Header values to set for this token */
  2795. headers: Map<string, string>;
  2796. }
  2797. declare type TokenType = 'OAuth' | 'FirstParty' | 'AppCheck';
  2798. /**
  2799. * A reference to a transaction.
  2800. *
  2801. * The `Transaction` object passed to a transaction's `updateFunction` provides
  2802. * the methods to read and write data within the transaction context. See
  2803. * {@link runTransaction}.
  2804. */
  2805. export declare class Transaction {
  2806. protected readonly _firestore: Firestore;
  2807. private readonly _transaction;
  2808. private readonly _dataReader;
  2809. /** @hideconstructor */
  2810. constructor(_firestore: Firestore, _transaction: Transaction_2);
  2811. /**
  2812. * Reads the document referenced by the provided {@link DocumentReference}.
  2813. *
  2814. * @param documentRef - A reference to the document to be read.
  2815. * @returns A `DocumentSnapshot` with the read data.
  2816. */
  2817. get<T>(documentRef: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
  2818. /**
  2819. * Writes to the document referred to by the provided {@link
  2820. * DocumentReference}. If the document does not exist yet, it will be created.
  2821. *
  2822. * @param documentRef - A reference to the document to be set.
  2823. * @param data - An object of the fields and values for the document.
  2824. * @throws Error - If the provided input is not a valid Firestore document.
  2825. * @returns This `Transaction` instance. Used for chaining method calls.
  2826. */
  2827. set<T>(documentRef: DocumentReference<T>, data: WithFieldValue<T>): this;
  2828. /**
  2829. * Writes to the document referred to by the provided {@link
  2830. * DocumentReference}. If the document does not exist yet, it will be created.
  2831. * If you provide `merge` or `mergeFields`, the provided data can be merged
  2832. * into an existing document.
  2833. *
  2834. * @param documentRef - A reference to the document to be set.
  2835. * @param data - An object of the fields and values for the document.
  2836. * @param options - An object to configure the set behavior.
  2837. * @throws Error - If the provided input is not a valid Firestore document.
  2838. * @returns This `Transaction` instance. Used for chaining method calls.
  2839. */
  2840. set<T>(documentRef: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): this;
  2841. /**
  2842. * Updates fields in the document referred to by the provided {@link
  2843. * DocumentReference}. The update will fail if applied to a document that does
  2844. * not exist.
  2845. *
  2846. * @param documentRef - A reference to the document to be updated.
  2847. * @param data - An object containing the fields and values with which to
  2848. * update the document. Fields can contain dots to reference nested fields
  2849. * within the document.
  2850. * @throws Error - If the provided input is not valid Firestore data.
  2851. * @returns This `Transaction` instance. Used for chaining method calls.
  2852. */
  2853. update<T>(documentRef: DocumentReference<T>, data: UpdateData<T>): this;
  2854. /**
  2855. * Updates fields in the document referred to by the provided {@link
  2856. * DocumentReference}. The update will fail if applied to a document that does
  2857. * not exist.
  2858. *
  2859. * Nested fields can be updated by providing dot-separated field path
  2860. * strings or by providing `FieldPath` objects.
  2861. *
  2862. * @param documentRef - A reference to the document to be updated.
  2863. * @param field - The first field to update.
  2864. * @param value - The first value.
  2865. * @param moreFieldsAndValues - Additional key/value pairs.
  2866. * @throws Error - If the provided input is not valid Firestore data.
  2867. * @returns This `Transaction` instance. Used for chaining method calls.
  2868. */
  2869. update(documentRef: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this;
  2870. /**
  2871. * Deletes the document referred to by the provided {@link DocumentReference}.
  2872. *
  2873. * @param documentRef - A reference to the document to be deleted.
  2874. * @returns This `Transaction` instance. Used for chaining method calls.
  2875. */
  2876. delete(documentRef: DocumentReference<unknown>): this;
  2877. }
  2878. /**
  2879. * Internal transaction object responsible for accumulating the mutations to
  2880. * perform and the base versions for any documents read.
  2881. */
  2882. declare class Transaction_2 {
  2883. private datastore;
  2884. private readVersions;
  2885. private mutations;
  2886. private committed;
  2887. /**
  2888. * A deferred usage error that occurred previously in this transaction that
  2889. * will cause the transaction to fail once it actually commits.
  2890. */
  2891. private lastWriteError;
  2892. /**
  2893. * Set of documents that have been written in the transaction.
  2894. *
  2895. * When there's more than one write to the same key in a transaction, any
  2896. * writes after the first are handled differently.
  2897. */
  2898. private writtenDocs;
  2899. constructor(datastore: Datastore);
  2900. lookup(keys: DocumentKey[]): Promise<Document_2[]>;
  2901. set(key: DocumentKey, data: ParsedSetData): void;
  2902. update(key: DocumentKey, data: ParsedUpdateData): void;
  2903. delete(key: DocumentKey): void;
  2904. commit(): Promise<void>;
  2905. private recordVersion;
  2906. /**
  2907. * Returns the version of this document when it was read in this transaction,
  2908. * as a precondition, or no precondition if it was not read.
  2909. */
  2910. private precondition;
  2911. /**
  2912. * Returns the precondition for a document if the operation is an update.
  2913. */
  2914. private preconditionForUpdate;
  2915. private write;
  2916. private ensureCommitNotCalled;
  2917. }
  2918. /**
  2919. * @license
  2920. * Copyright 2022 Google LLC
  2921. *
  2922. * Licensed under the Apache License, Version 2.0 (the "License");
  2923. * you may not use this file except in compliance with the License.
  2924. * You may obtain a copy of the License at
  2925. *
  2926. * http://www.apache.org/licenses/LICENSE-2.0
  2927. *
  2928. * Unless required by applicable law or agreed to in writing, software
  2929. * distributed under the License is distributed on an "AS IS" BASIS,
  2930. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2931. * See the License for the specific language governing permissions and
  2932. * limitations under the License.
  2933. */
  2934. /**
  2935. * Options to customize transaction behavior.
  2936. */
  2937. export declare interface TransactionOptions {
  2938. /** Maximum number of attempts to commit, after which transaction fails. Default is 5. */
  2939. readonly maxAttempts?: number;
  2940. }
  2941. /** Used to represent a field transform on a mutation. */
  2942. declare class TransformOperation {
  2943. private _;
  2944. }
  2945. declare type UnaryFilterOp = 'OPERATOR_UNSPECIFIED' | 'IS_NAN' | 'IS_NULL' | 'IS_NOT_NAN' | 'IS_NOT_NULL';
  2946. /**
  2947. * Given a union type `U = T1 | T2 | ...`, returns an intersected type
  2948. * `(T1 & T2 & ...)`.
  2949. *
  2950. * Uses distributive conditional types and inference from conditional types.
  2951. * This works because multiple candidates for the same type variable in
  2952. * contra-variant positions causes an intersection type to be inferred.
  2953. * https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-inference-in-conditional-types
  2954. * https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
  2955. */
  2956. export declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
  2957. /**
  2958. * An untyped Firestore Data Converter interface that is shared between the
  2959. * lite, firestore-exp and classic SDK.
  2960. */
  2961. declare interface UntypedFirestoreDataConverter<T> {
  2962. toFirestore(modelObject: WithFieldValue<T>): DocumentData_2;
  2963. toFirestore(modelObject: PartialWithFieldValue<T>, options: SetOptions_2): DocumentData_2;
  2964. fromFirestore(snapshot: unknown, options?: unknown): T;
  2965. }
  2966. /**
  2967. * Update data (for use with {@link (updateDoc:1)}) that consists of field paths
  2968. * (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots
  2969. * reference nested fields within the document. FieldValues can be passed in
  2970. * as property values.
  2971. */
  2972. export declare type UpdateData<T> = T extends Primitive ? T : T extends {} ? {
  2973. [K in keyof T]?: UpdateData<T[K]> | FieldValue;
  2974. } & NestedUpdateFields<T> : Partial<T>;
  2975. /**
  2976. * Updates fields in the document referred to by the specified
  2977. * `DocumentReference`. The update will fail if applied to a document that does
  2978. * not exist.
  2979. *
  2980. * The result of this update will only be reflected in document reads that occur
  2981. * after the returned promise resolves. If the client is offline, the
  2982. * update fails. If you would like to see local modifications or buffer writes
  2983. * until the client is online, use the full Firestore SDK.
  2984. *
  2985. * @param reference - A reference to the document to update.
  2986. * @param data - An object containing the fields and values with which to
  2987. * update the document. Fields can contain dots to reference nested fields
  2988. * within the document.
  2989. * @throws Error - If the provided input is not valid Firestore data.
  2990. * @returns A `Promise` resolved once the data has been successfully written
  2991. * to the backend.
  2992. */
  2993. export declare function updateDoc<T>(reference: DocumentReference<T>, data: UpdateData<T>): Promise<void>;
  2994. /**
  2995. * Updates fields in the document referred to by the specified
  2996. * `DocumentReference` The update will fail if applied to a document that does
  2997. * not exist.
  2998. *
  2999. * Nested fields can be updated by providing dot-separated field path
  3000. * strings or by providing `FieldPath` objects.
  3001. *
  3002. * The result of this update will only be reflected in document reads that occur
  3003. * after the returned promise resolves. If the client is offline, the
  3004. * update fails. If you would like to see local modifications or buffer writes
  3005. * until the client is online, use the full Firestore SDK.
  3006. *
  3007. * @param reference - A reference to the document to update.
  3008. * @param field - The first field to update.
  3009. * @param value - The first value.
  3010. * @param moreFieldsAndValues - Additional key value pairs.
  3011. * @throws Error - If the provided input is not valid Firestore data.
  3012. * @returns A `Promise` resolved once the data has been successfully written
  3013. * to the backend.
  3014. */
  3015. export declare function updateDoc(reference: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise<void>;
  3016. /**
  3017. * @license
  3018. * Copyright 2017 Google LLC
  3019. *
  3020. * Licensed under the Apache License, Version 2.0 (the "License");
  3021. * you may not use this file except in compliance with the License.
  3022. * You may obtain a copy of the License at
  3023. *
  3024. * http://www.apache.org/licenses/LICENSE-2.0
  3025. *
  3026. * Unless required by applicable law or agreed to in writing, software
  3027. * distributed under the License is distributed on an "AS IS" BASIS,
  3028. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3029. * See the License for the specific language governing permissions and
  3030. * limitations under the License.
  3031. */
  3032. /**
  3033. * Simple wrapper around a nullable UID. Mostly exists to make code more
  3034. * readable.
  3035. */
  3036. declare class User {
  3037. readonly uid: string | null;
  3038. /** A user with a null UID. */
  3039. static readonly UNAUTHENTICATED: User;
  3040. static readonly GOOGLE_CREDENTIALS: User;
  3041. static readonly FIRST_PARTY: User;
  3042. static readonly MOCK_USER: User;
  3043. constructor(uid: string | null);
  3044. isAuthenticated(): boolean;
  3045. /**
  3046. * Returns a key representing this user, suitable for inclusion in a
  3047. * dictionary.
  3048. */
  3049. toKey(): string;
  3050. isEqual(otherUser: User): boolean;
  3051. }
  3052. declare type Value = firestoreV1ApiClientInterfaces.Value;
  3053. declare type ValueNullValue = 'NULL_VALUE';
  3054. /**
  3055. * Creates a {@link QueryFieldFilterConstraint} that enforces that documents
  3056. * must contain the specified field and that the value should satisfy the
  3057. * relation constraint provided.
  3058. *
  3059. * @param fieldPath - The path to compare
  3060. * @param opStr - The operation string (e.g "&lt;", "&lt;=", "==", "&lt;",
  3061. * "&lt;=", "!=").
  3062. * @param value - The value for comparison
  3063. * @returns The created {@link QueryFieldFilterConstraint}.
  3064. */
  3065. export declare function where(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown): QueryFieldFilterConstraint;
  3066. /**
  3067. * Filter conditions in a {@link where} clause are specified using the
  3068. * strings '&lt;', '&lt;=', '==', '!=', '&gt;=', '&gt;', 'array-contains', 'in',
  3069. * 'array-contains-any', and 'not-in'.
  3070. */
  3071. export declare type WhereFilterOp = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any' | 'not-in';
  3072. /**
  3073. * Allows FieldValues to be passed in as a property value while maintaining
  3074. * type safety.
  3075. */
  3076. export declare type WithFieldValue<T> = T | (T extends Primitive ? T : T extends {} ? {
  3077. [K in keyof T]: WithFieldValue<T[K]> | FieldValue;
  3078. } : never);
  3079. /**
  3080. * A write batch, used to perform multiple writes as a single atomic unit.
  3081. *
  3082. * A `WriteBatch` object can be acquired by calling {@link writeBatch}. It
  3083. * provides methods for adding writes to the write batch. None of the writes
  3084. * will be committed (or visible locally) until {@link WriteBatch.commit} is
  3085. * called.
  3086. */
  3087. export declare class WriteBatch {
  3088. private readonly _firestore;
  3089. private readonly _commitHandler;
  3090. private readonly _dataReader;
  3091. private _mutations;
  3092. private _committed;
  3093. /** @hideconstructor */
  3094. constructor(_firestore: Firestore, _commitHandler: (m: Mutation[]) => Promise<void>);
  3095. /**
  3096. * Writes to the document referred to by the provided {@link
  3097. * DocumentReference}. If the document does not exist yet, it will be created.
  3098. *
  3099. * @param documentRef - A reference to the document to be set.
  3100. * @param data - An object of the fields and values for the document.
  3101. * @returns This `WriteBatch` instance. Used for chaining method calls.
  3102. */
  3103. set<T>(documentRef: DocumentReference<T>, data: WithFieldValue<T>): WriteBatch;
  3104. /**
  3105. * Writes to the document referred to by the provided {@link
  3106. * DocumentReference}. If the document does not exist yet, it will be created.
  3107. * If you provide `merge` or `mergeFields`, the provided data can be merged
  3108. * into an existing document.
  3109. *
  3110. * @param documentRef - A reference to the document to be set.
  3111. * @param data - An object of the fields and values for the document.
  3112. * @param options - An object to configure the set behavior.
  3113. * @throws Error - If the provided input is not a valid Firestore document.
  3114. * @returns This `WriteBatch` instance. Used for chaining method calls.
  3115. */
  3116. set<T>(documentRef: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): WriteBatch;
  3117. /**
  3118. * Updates fields in the document referred to by the provided {@link
  3119. * DocumentReference}. The update will fail if applied to a document that does
  3120. * not exist.
  3121. *
  3122. * @param documentRef - A reference to the document to be updated.
  3123. * @param data - An object containing the fields and values with which to
  3124. * update the document. Fields can contain dots to reference nested fields
  3125. * within the document.
  3126. * @throws Error - If the provided input is not valid Firestore data.
  3127. * @returns This `WriteBatch` instance. Used for chaining method calls.
  3128. */
  3129. update<T>(documentRef: DocumentReference<T>, data: UpdateData<T>): WriteBatch;
  3130. /**
  3131. * Updates fields in the document referred to by this {@link
  3132. * DocumentReference}. The update will fail if applied to a document that does
  3133. * not exist.
  3134. *
  3135. * Nested fields can be update by providing dot-separated field path strings
  3136. * or by providing `FieldPath` objects.
  3137. *
  3138. * @param documentRef - A reference to the document to be updated.
  3139. * @param field - The first field to update.
  3140. * @param value - The first value.
  3141. * @param moreFieldsAndValues - Additional key value pairs.
  3142. * @throws Error - If the provided input is not valid Firestore data.
  3143. * @returns This `WriteBatch` instance. Used for chaining method calls.
  3144. */
  3145. update(documentRef: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch;
  3146. /**
  3147. * Deletes the document referred to by the provided {@link DocumentReference}.
  3148. *
  3149. * @param documentRef - A reference to the document to be deleted.
  3150. * @returns This `WriteBatch` instance. Used for chaining method calls.
  3151. */
  3152. delete(documentRef: DocumentReference<unknown>): WriteBatch;
  3153. /**
  3154. * Commits all of the writes in this write batch as a single atomic unit.
  3155. *
  3156. * The result of these writes will only be reflected in document reads that
  3157. * occur after the returned promise resolves. If the client is offline, the
  3158. * write fails. If you would like to see local modifications or buffer writes
  3159. * until the client is online, use the full Firestore SDK.
  3160. *
  3161. * @returns A `Promise` resolved once all of the writes in the batch have been
  3162. * successfully written to the backend as an atomic unit (note that it won't
  3163. * resolve while you're offline).
  3164. */
  3165. commit(): Promise<void>;
  3166. private _verifyNotCommitted;
  3167. }
  3168. /**
  3169. * Creates a write batch, used for performing multiple writes as a single
  3170. * atomic operation. The maximum number of writes allowed in a single WriteBatch
  3171. * is 500.
  3172. *
  3173. * The result of these writes will only be reflected in document reads that
  3174. * occur after the returned promise resolves. If the client is offline, the
  3175. * write fails. If you would like to see local modifications or buffer writes
  3176. * until the client is online, use the full Firestore SDK.
  3177. *
  3178. * @returns A `WriteBatch` that can be used to atomically execute multiple
  3179. * writes.
  3180. */
  3181. export declare function writeBatch(firestore: Firestore): WriteBatch;
  3182. export { }