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.

private.d.ts 117KB

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