Açıklama Yok
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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849
  1. /**
  2. * Firebase Realtime Database
  3. *
  4. * @packageDocumentation
  5. */
  6. import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
  7. import { AppCheckTokenListener } from '@firebase/app-check-interop-types';
  8. import { AppCheckTokenResult } from '@firebase/app-check-interop-types';
  9. import { EmulatorMockTokenOptions } from '@firebase/util';
  10. import { FirebaseApp } from '@firebase/app';
  11. import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
  12. import { FirebaseAuthTokenData } from '@firebase/app-types/private';
  13. import { Provider } from '@firebase/component';
  14. /**
  15. * Abstraction around AppCheck's token fetching capabilities.
  16. */
  17. declare class AppCheckTokenProvider {
  18. private appName_;
  19. private appCheckProvider?;
  20. private appCheck?;
  21. constructor(appName_: string, appCheckProvider?: Provider<AppCheckInternalComponentName>);
  22. getToken(forceRefresh?: boolean): Promise<AppCheckTokenResult>;
  23. addTokenChangeListener(listener: AppCheckTokenListener): void;
  24. notifyForInvalidToken(): void;
  25. }
  26. declare interface AuthTokenProvider {
  27. getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData>;
  28. addTokenChangeListener(listener: (token: string | null) => void): void;
  29. removeTokenChangeListener(listener: (token: string | null) => void): void;
  30. notifyForInvalidToken(): void;
  31. }
  32. /**
  33. * A cache node only stores complete children. Additionally it holds a flag whether the node can be considered fully
  34. * initialized in the sense that we know at one point in time this represented a valid state of the world, e.g.
  35. * initialized with data from the server, or a complete overwrite by the client. The filtered flag also tracks
  36. * whether a node potentially had children removed due to a filter.
  37. */
  38. declare class CacheNode {
  39. private node_;
  40. private fullyInitialized_;
  41. private filtered_;
  42. constructor(node_: Node_2, fullyInitialized_: boolean, filtered_: boolean);
  43. /**
  44. * Returns whether this node was fully initialized with either server data or a complete overwrite by the client
  45. */
  46. isFullyInitialized(): boolean;
  47. /**
  48. * Returns whether this node is potentially missing children due to a filter applied to the node
  49. */
  50. isFiltered(): boolean;
  51. isCompleteForPath(path: Path): boolean;
  52. isCompleteForChild(key: string): boolean;
  53. getNode(): Node_2;
  54. }
  55. declare class CancelEvent implements Event_2 {
  56. eventRegistration: EventRegistration;
  57. error: Error;
  58. path: Path;
  59. constructor(eventRegistration: EventRegistration, error: Error, path: Path);
  60. getPath(): Path;
  61. getEventType(): string;
  62. getEventRunner(): () => void;
  63. toString(): string;
  64. }
  65. declare interface Change {
  66. /** @param type - The event type */
  67. type: ChangeType;
  68. /** @param snapshotNode - The data */
  69. snapshotNode: Node_2;
  70. /** @param childName - The name for this child, if it's a child even */
  71. childName?: string;
  72. /** @param oldSnap - Used for intermediate processing of child changed events */
  73. oldSnap?: Node_2;
  74. /** * @param prevName - The name for the previous child, if applicable */
  75. prevName?: string | null;
  76. }
  77. declare const enum ChangeType {
  78. /** Event type for a child added */
  79. CHILD_ADDED = "child_added",
  80. /** Event type for a child removed */
  81. CHILD_REMOVED = "child_removed",
  82. /** Event type for a child changed */
  83. CHILD_CHANGED = "child_changed",
  84. /** Event type for a child moved */
  85. CHILD_MOVED = "child_moved",
  86. /** Event type for a value change */
  87. VALUE = "value"
  88. }
  89. /**
  90. * Gets a `Reference` for the location at the specified relative path.
  91. *
  92. * The relative path can either be a simple child name (for example, "ada") or
  93. * a deeper slash-separated path (for example, "ada/name/first").
  94. *
  95. * @param parent - The parent location.
  96. * @param path - A relative path from this location to the desired child
  97. * location.
  98. * @returns The specified child location.
  99. */
  100. export declare function child(parent: DatabaseReference, path: string): DatabaseReference;
  101. declare class ChildChangeAccumulator {
  102. private readonly changeMap;
  103. trackChildChange(change: Change): void;
  104. getChanges(): Change[];
  105. }
  106. /**
  107. * @license
  108. * Copyright 2017 Google LLC
  109. *
  110. * Licensed under the Apache License, Version 2.0 (the "License");
  111. * you may not use this file except in compliance with the License.
  112. * You may obtain a copy of the License at
  113. *
  114. * http://www.apache.org/licenses/LICENSE-2.0
  115. *
  116. * Unless required by applicable law or agreed to in writing, software
  117. * distributed under the License is distributed on an "AS IS" BASIS,
  118. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  119. * See the License for the specific language governing permissions and
  120. * limitations under the License.
  121. */
  122. /**
  123. * @fileoverview Implementation of an immutable SortedMap using a Left-leaning
  124. * Red-Black Tree, adapted from the implementation in Mugs
  125. * (http://mads379.github.com/mugs/) by Mads Hartmann Jensen
  126. * (mads379\@gmail.com).
  127. *
  128. * Original paper on Left-leaning Red-Black Trees:
  129. * http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf
  130. *
  131. * Invariant 1: No red node has a red child
  132. * Invariant 2: Every leaf path has the same number of black nodes
  133. * Invariant 3: Only the left child can be red (left leaning)
  134. */
  135. declare type Comparator<K> = (key1: K, key2: K) => number;
  136. /**
  137. * Since updates to filtered nodes might require nodes to be pulled in from "outside" the node, this interface
  138. * can help to get complete children that can be pulled in.
  139. * A class implementing this interface takes potentially multiple sources (e.g. user writes, server data from
  140. * other views etc.) to try it's best to get a complete child that might be useful in pulling into the view.
  141. *
  142. * @interface
  143. */
  144. declare interface CompleteChildSource {
  145. getCompleteChild(childKey: string): Node_2 | null;
  146. getChildAfterChild(index: Index, child: NamedNode, reverse: boolean): NamedNode | null;
  147. }
  148. /**
  149. * This class holds a collection of writes that can be applied to nodes in unison. It abstracts away the logic with
  150. * dealing with priority writes and multiple nested writes. At any given path there is only allowed to be one write
  151. * modifying that path. Any write to an existing path or shadowing an existing path will modify that existing write
  152. * to reflect the write added.
  153. */
  154. declare class CompoundWrite {
  155. writeTree_: ImmutableTree<Node_2>;
  156. constructor(writeTree_: ImmutableTree<Node_2>);
  157. static empty(): CompoundWrite;
  158. }
  159. /**
  160. * Modify the provided instance to communicate with the Realtime Database
  161. * emulator.
  162. *
  163. * <p>Note: This method must be called before performing any other operation.
  164. *
  165. * @param db - The instance to modify.
  166. * @param host - The emulator host (ex: localhost)
  167. * @param port - The emulator port (ex: 8080)
  168. * @param options.mockUserToken - the mock auth token to use for unit testing Security Rules
  169. */
  170. export declare function connectDatabaseEmulator(db: Database, host: string, port: number, options?: {
  171. mockUserToken?: EmulatorMockTokenOptions | string;
  172. }): void;
  173. /**
  174. * Class representing a Firebase Realtime Database.
  175. */
  176. export declare class Database implements _FirebaseService {
  177. _repoInternal: Repo;
  178. /** The {@link @firebase/app#FirebaseApp} associated with this Realtime Database instance. */
  179. readonly app: FirebaseApp;
  180. /** Represents a `Database` instance. */
  181. readonly 'type' = "database";
  182. /** Track if the instance has been used (root or repo accessed) */
  183. _instanceStarted: boolean;
  184. /** Backing state for root_ */
  185. private _rootInternal?;
  186. /** @hideconstructor */
  187. constructor(_repoInternal: Repo,
  188. /** The {@link @firebase/app#FirebaseApp} associated with this Realtime Database instance. */
  189. app: FirebaseApp);
  190. get _repo(): Repo;
  191. get _root(): _ReferenceImpl;
  192. _delete(): Promise<void>;
  193. _checkNotDeleted(apiName: string): void;
  194. }
  195. /**
  196. * A `DatabaseReference` represents a specific location in your Database and can be used
  197. * for reading or writing data to that Database location.
  198. *
  199. * You can reference the root or child location in your Database by calling
  200. * `ref()` or `ref("child/path")`.
  201. *
  202. * Writing is done with the `set()` method and reading can be done with the
  203. * `on*()` method. See {@link
  204. * https://firebase.google.com/docs/database/web/read-and-write}
  205. */
  206. export declare interface DatabaseReference extends Query {
  207. /**
  208. * The last part of the `DatabaseReference`'s path.
  209. *
  210. * For example, `"ada"` is the key for
  211. * `https://<DATABASE_NAME>.firebaseio.com/users/ada`.
  212. *
  213. * The key of a root `DatabaseReference` is `null`.
  214. */
  215. readonly key: string | null;
  216. /**
  217. * The parent location of a `DatabaseReference`.
  218. *
  219. * The parent of a root `DatabaseReference` is `null`.
  220. */
  221. readonly parent: DatabaseReference | null;
  222. /** The root `DatabaseReference` of the Database. */
  223. readonly root: DatabaseReference;
  224. }
  225. /**
  226. * A `DataSnapshot` contains data from a Database location.
  227. *
  228. * Any time you read data from the Database, you receive the data as a
  229. * `DataSnapshot`. A `DataSnapshot` is passed to the event callbacks you attach
  230. * with `on()` or `once()`. You can extract the contents of the snapshot as a
  231. * JavaScript object by calling the `val()` method. Alternatively, you can
  232. * traverse into the snapshot by calling `child()` to return child snapshots
  233. * (which you could then call `val()` on).
  234. *
  235. * A `DataSnapshot` is an efficiently generated, immutable copy of the data at
  236. * a Database location. It cannot be modified and will never change (to modify
  237. * data, you always call the `set()` method on a `Reference` directly).
  238. */
  239. export declare class DataSnapshot {
  240. readonly _node: Node_2;
  241. /**
  242. * The location of this DataSnapshot.
  243. */
  244. readonly ref: DatabaseReference;
  245. readonly _index: Index;
  246. /**
  247. * @param _node - A SnapshotNode to wrap.
  248. * @param ref - The location this snapshot came from.
  249. * @param _index - The iteration order for this snapshot
  250. * @hideconstructor
  251. */
  252. constructor(_node: Node_2,
  253. /**
  254. * The location of this DataSnapshot.
  255. */
  256. ref: DatabaseReference, _index: Index);
  257. /**
  258. * Gets the priority value of the data in this `DataSnapshot`.
  259. *
  260. * Applications need not use priority but can order collections by
  261. * ordinary properties (see
  262. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data |Sorting and filtering data}
  263. * ).
  264. */
  265. get priority(): string | number | null;
  266. /**
  267. * The key (last part of the path) of the location of this `DataSnapshot`.
  268. *
  269. * The last token in a Database location is considered its key. For example,
  270. * "ada" is the key for the /users/ada/ node. Accessing the key on any
  271. * `DataSnapshot` will return the key for the location that generated it.
  272. * However, accessing the key on the root URL of a Database will return
  273. * `null`.
  274. */
  275. get key(): string | null;
  276. /** Returns the number of child properties of this `DataSnapshot`. */
  277. get size(): number;
  278. /**
  279. * Gets another `DataSnapshot` for the location at the specified relative path.
  280. *
  281. * Passing a relative path to the `child()` method of a DataSnapshot returns
  282. * another `DataSnapshot` for the location at the specified relative path. The
  283. * relative path can either be a simple child name (for example, "ada") or a
  284. * deeper, slash-separated path (for example, "ada/name/first"). If the child
  285. * location has no data, an empty `DataSnapshot` (that is, a `DataSnapshot`
  286. * whose value is `null`) is returned.
  287. *
  288. * @param path - A relative path to the location of child data.
  289. */
  290. child(path: string): DataSnapshot;
  291. /**
  292. * Returns true if this `DataSnapshot` contains any data. It is slightly more
  293. * efficient than using `snapshot.val() !== null`.
  294. */
  295. exists(): boolean;
  296. /**
  297. * Exports the entire contents of the DataSnapshot as a JavaScript object.
  298. *
  299. * The `exportVal()` method is similar to `val()`, except priority information
  300. * is included (if available), making it suitable for backing up your data.
  301. *
  302. * @returns The DataSnapshot's contents as a JavaScript value (Object,
  303. * Array, string, number, boolean, or `null`).
  304. */
  305. exportVal(): any;
  306. /**
  307. * Enumerates the top-level children in the `DataSnapshot`.
  308. *
  309. * Because of the way JavaScript objects work, the ordering of data in the
  310. * JavaScript object returned by `val()` is not guaranteed to match the
  311. * ordering on the server nor the ordering of `onChildAdded()` events. That is
  312. * where `forEach()` comes in handy. It guarantees the children of a
  313. * `DataSnapshot` will be iterated in their query order.
  314. *
  315. * If no explicit `orderBy*()` method is used, results are returned
  316. * ordered by key (unless priorities are used, in which case, results are
  317. * returned by priority).
  318. *
  319. * @param action - A function that will be called for each child DataSnapshot.
  320. * The callback can return true to cancel further enumeration.
  321. * @returns true if enumeration was canceled due to your callback returning
  322. * true.
  323. */
  324. forEach(action: (child: DataSnapshot) => boolean | void): boolean;
  325. /**
  326. * Returns true if the specified child path has (non-null) data.
  327. *
  328. * @param path - A relative path to the location of a potential child.
  329. * @returns `true` if data exists at the specified child path; else
  330. * `false`.
  331. */
  332. hasChild(path: string): boolean;
  333. /**
  334. * Returns whether or not the `DataSnapshot` has any non-`null` child
  335. * properties.
  336. *
  337. * You can use `hasChildren()` to determine if a `DataSnapshot` has any
  338. * children. If it does, you can enumerate them using `forEach()`. If it
  339. * doesn't, then either this snapshot contains a primitive value (which can be
  340. * retrieved with `val()`) or it is empty (in which case, `val()` will return
  341. * `null`).
  342. *
  343. * @returns true if this snapshot has any children; else false.
  344. */
  345. hasChildren(): boolean;
  346. /**
  347. * Returns a JSON-serializable representation of this object.
  348. */
  349. toJSON(): object | null;
  350. /**
  351. * Extracts a JavaScript value from a `DataSnapshot`.
  352. *
  353. * Depending on the data in a `DataSnapshot`, the `val()` method may return a
  354. * scalar type (string, number, or boolean), an array, or an object. It may
  355. * also return null, indicating that the `DataSnapshot` is empty (contains no
  356. * data).
  357. *
  358. * @returns The DataSnapshot's contents as a JavaScript value (Object,
  359. * Array, string, number, boolean, or `null`).
  360. */
  361. val(): any;
  362. }
  363. export { EmulatorMockTokenOptions }
  364. /**
  365. * Logs debugging information to the console.
  366. *
  367. * @param enabled - Enables logging if `true`, disables logging if `false`.
  368. * @param persistent - Remembers the logging state between page refreshes if
  369. * `true`.
  370. */
  371. export declare function enableLogging(enabled: boolean, persistent?: boolean): any;
  372. /**
  373. * Logs debugging information to the console.
  374. *
  375. * @param logger - A custom logger function to control how things get logged.
  376. */
  377. export declare function enableLogging(logger: (message: string) => unknown): any;
  378. /**
  379. * Creates a `QueryConstraint` with the specified ending point.
  380. *
  381. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  382. * allows you to choose arbitrary starting and ending points for your queries.
  383. *
  384. * The ending point is inclusive, so children with exactly the specified value
  385. * will be included in the query. The optional key argument can be used to
  386. * further limit the range of the query. If it is specified, then children that
  387. * have exactly the specified value must also have a key name less than or equal
  388. * to the specified key.
  389. *
  390. * You can read more about `endAt()` in
  391. * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
  392. *
  393. * @param value - The value to end at. The argument type depends on which
  394. * `orderBy*()` function was used in this query. Specify a value that matches
  395. * the `orderBy*()` type. When used in combination with `orderByKey()`, the
  396. * value must be a string.
  397. * @param key - The child key to end at, among the children with the previously
  398. * specified priority. This argument is only allowed if ordering by child,
  399. * value, or priority.
  400. */
  401. export declare function endAt(value: number | string | boolean | null, key?: string): QueryConstraint;
  402. /**
  403. * Creates a `QueryConstraint` with the specified ending point (exclusive).
  404. *
  405. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  406. * allows you to choose arbitrary starting and ending points for your queries.
  407. *
  408. * The ending point is exclusive. If only a value is provided, children
  409. * with a value less than the specified value will be included in the query.
  410. * If a key is specified, then children must have a value less than or equal
  411. * to the specified value and a key name less than the specified key.
  412. *
  413. * @param value - The value to end before. The argument type depends on which
  414. * `orderBy*()` function was used in this query. Specify a value that matches
  415. * the `orderBy*()` type. When used in combination with `orderByKey()`, the
  416. * value must be a string.
  417. * @param key - The child key to end before, among the children with the
  418. * previously specified priority. This argument is only allowed if ordering by
  419. * child, value, or priority.
  420. */
  421. export declare function endBefore(value: number | string | boolean | null, key?: string): QueryConstraint;
  422. /**
  423. * Creates a `QueryConstraint` that includes children that match the specified
  424. * value.
  425. *
  426. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  427. * allows you to choose arbitrary starting and ending points for your queries.
  428. *
  429. * The optional key argument can be used to further limit the range of the
  430. * query. If it is specified, then children that have exactly the specified
  431. * value must also have exactly the specified key as their key name. This can be
  432. * used to filter result sets with many matches for the same value.
  433. *
  434. * You can read more about `equalTo()` in
  435. * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
  436. *
  437. * @param value - The value to match for. The argument type depends on which
  438. * `orderBy*()` function was used in this query. Specify a value that matches
  439. * the `orderBy*()` type. When used in combination with `orderByKey()`, the
  440. * value must be a string.
  441. * @param key - The child key to start at, among the children with the
  442. * previously specified priority. This argument is only allowed if ordering by
  443. * child, value, or priority.
  444. */
  445. export declare function equalTo(value: number | string | boolean | null, key?: string): QueryConstraint;
  446. /**
  447. * Encapsulates the data needed to raise an event
  448. * @interface
  449. */
  450. declare interface Event_2 {
  451. getPath(): Path;
  452. getEventType(): string;
  453. getEventRunner(): () => void;
  454. toString(): string;
  455. }
  456. /**
  457. * An EventGenerator is used to convert "raw" changes (Change) as computed by the
  458. * CacheDiffer into actual events (Event) that can be raised. See generateEventsForChanges()
  459. * for details.
  460. *
  461. */
  462. declare class EventGenerator {
  463. query_: QueryContext;
  464. index_: Index;
  465. constructor(query_: QueryContext);
  466. }
  467. declare interface EventList {
  468. events: Event_2[];
  469. path: Path;
  470. }
  471. /**
  472. * The event queue serves a few purposes:
  473. * 1. It ensures we maintain event order in the face of event callbacks doing operations that result in more
  474. * events being queued.
  475. * 2. raiseQueuedEvents() handles being called reentrantly nicely. That is, if in the course of raising events,
  476. * raiseQueuedEvents() is called again, the "inner" call will pick up raising events where the "outer" call
  477. * left off, ensuring that the events are still raised synchronously and in order.
  478. * 3. You can use raiseEventsAtPath and raiseEventsForChangedPath to ensure only relevant previously-queued
  479. * events are raised synchronously.
  480. *
  481. * NOTE: This can all go away if/when we move to async events.
  482. *
  483. */
  484. declare class EventQueue {
  485. eventLists_: EventList[];
  486. /**
  487. * Tracks recursion depth of raiseQueuedEvents_, for debugging purposes.
  488. */
  489. recursionDepth_: number;
  490. }
  491. /**
  492. * An EventRegistration is basically an event type ('value', 'child_added', etc.) and a callback
  493. * to be notified of that type of event.
  494. *
  495. * That said, it can also contain a cancel callback to be notified if the event is canceled. And
  496. * currently, this code is organized around the idea that you would register multiple child_ callbacks
  497. * together, as a single EventRegistration. Though currently we don't do that.
  498. */
  499. declare interface EventRegistration {
  500. /**
  501. * True if this container has a callback to trigger for this event type
  502. */
  503. respondsTo(eventType: string): boolean;
  504. createEvent(change: Change, query: QueryContext): Event_2;
  505. /**
  506. * Given event data, return a function to trigger the user's callback
  507. */
  508. getEventRunner(eventData: Event_2): () => void;
  509. createCancelEvent(error: Error, path: Path): CancelEvent | null;
  510. matches(other: EventRegistration): boolean;
  511. /**
  512. * False basically means this is a "dummy" callback container being used as a sentinel
  513. * to remove all callback containers of a particular type. (e.g. if the user does
  514. * ref.off('value') without specifying a specific callback).
  515. *
  516. * (TODO: Rework this, since it's hacky)
  517. *
  518. */
  519. hasAnyCallback(): boolean;
  520. }
  521. /**
  522. * One of the following strings: "value", "child_added", "child_changed",
  523. * "child_removed", or "child_moved."
  524. */
  525. export declare type EventType = 'value' | 'child_added' | 'child_changed' | 'child_moved' | 'child_removed';
  526. /* Excluded from this release type: _FirebaseService */
  527. /**
  528. * Force the use of longPolling instead of websockets. This will be ignored if websocket protocol is used in databaseURL.
  529. */
  530. export declare function forceLongPolling(): void;
  531. /**
  532. * Force the use of websockets instead of longPolling.
  533. */
  534. export declare function forceWebSockets(): void;
  535. /**
  536. * Gets the most up-to-date result for this query.
  537. *
  538. * @param query - The query to run.
  539. * @returns A `Promise` which resolves to the resulting DataSnapshot if a value is
  540. * available, or rejects if the client is unable to return a value (e.g., if the
  541. * server is unreachable and there is nothing cached).
  542. */
  543. export declare function get(query: Query): Promise<DataSnapshot>;
  544. /**
  545. * Returns the instance of the Realtime Database SDK that is associated
  546. * with the provided {@link @firebase/app#FirebaseApp}. Initializes a new instance with
  547. * with default settings if no instance exists or if the existing instance uses
  548. * a custom database URL.
  549. *
  550. * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned Realtime
  551. * Database instance is associated with.
  552. * @param url - The URL of the Realtime Database instance to connect to. If not
  553. * provided, the SDK connects to the default instance of the Firebase App.
  554. * @returns The `Database` instance of the provided app.
  555. */
  556. export declare function getDatabase(app?: FirebaseApp, url?: string): Database;
  557. /**
  558. * Disconnects from the server (all Database operations will be completed
  559. * offline).
  560. *
  561. * The client automatically maintains a persistent connection to the Database
  562. * server, which will remain active indefinitely and reconnect when
  563. * disconnected. However, the `goOffline()` and `goOnline()` methods may be used
  564. * to control the client connection in cases where a persistent connection is
  565. * undesirable.
  566. *
  567. * While offline, the client will no longer receive data updates from the
  568. * Database. However, all Database operations performed locally will continue to
  569. * immediately fire events, allowing your application to continue behaving
  570. * normally. Additionally, each operation performed locally will automatically
  571. * be queued and retried upon reconnection to the Database server.
  572. *
  573. * To reconnect to the Database and begin receiving remote events, see
  574. * `goOnline()`.
  575. *
  576. * @param db - The instance to disconnect.
  577. */
  578. export declare function goOffline(db: Database): void;
  579. /**
  580. * Reconnects to the server and synchronizes the offline Database state
  581. * with the server state.
  582. *
  583. * This method should be used after disabling the active connection with
  584. * `goOffline()`. Once reconnected, the client will transmit the proper data
  585. * and fire the appropriate events so that your client "catches up"
  586. * automatically.
  587. *
  588. * @param db - The instance to reconnect.
  589. */
  590. export declare function goOnline(db: Database): void;
  591. /**
  592. * A tree with immutable elements.
  593. */
  594. declare class ImmutableTree<T> {
  595. readonly value: T | null;
  596. readonly children: SortedMap<string, ImmutableTree<T>>;
  597. static fromObject<T>(obj: {
  598. [k: string]: T;
  599. }): ImmutableTree<T>;
  600. constructor(value: T | null, children?: SortedMap<string, ImmutableTree<T>>);
  601. /**
  602. * True if the value is empty and there are no children
  603. */
  604. isEmpty(): boolean;
  605. /**
  606. * Given a path and predicate, return the first node and the path to that node
  607. * where the predicate returns true.
  608. *
  609. * TODO Do a perf test -- If we're creating a bunch of `{path: value:}`
  610. * objects on the way back out, it may be better to pass down a pathSoFar obj.
  611. *
  612. * @param relativePath - The remainder of the path
  613. * @param predicate - The predicate to satisfy to return a node
  614. */
  615. findRootMostMatchingPathAndValue(relativePath: Path, predicate: (a: T) => boolean): {
  616. path: Path;
  617. value: T;
  618. } | null;
  619. /**
  620. * Find, if it exists, the shortest subpath of the given path that points a defined
  621. * value in the tree
  622. */
  623. findRootMostValueAndPath(relativePath: Path): {
  624. path: Path;
  625. value: T;
  626. } | null;
  627. /**
  628. * @returns The subtree at the given path
  629. */
  630. subtree(relativePath: Path): ImmutableTree<T>;
  631. /**
  632. * Sets a value at the specified path.
  633. *
  634. * @param relativePath - Path to set value at.
  635. * @param toSet - Value to set.
  636. * @returns Resulting tree.
  637. */
  638. set(relativePath: Path, toSet: T | null): ImmutableTree<T>;
  639. /**
  640. * Removes the value at the specified path.
  641. *
  642. * @param relativePath - Path to value to remove.
  643. * @returns Resulting tree.
  644. */
  645. remove(relativePath: Path): ImmutableTree<T>;
  646. /**
  647. * Gets a value from the tree.
  648. *
  649. * @param relativePath - Path to get value for.
  650. * @returns Value at path, or null.
  651. */
  652. get(relativePath: Path): T | null;
  653. /**
  654. * Replace the subtree at the specified path with the given new tree.
  655. *
  656. * @param relativePath - Path to replace subtree for.
  657. * @param newTree - New tree.
  658. * @returns Resulting tree.
  659. */
  660. setTree(relativePath: Path, newTree: ImmutableTree<T>): ImmutableTree<T>;
  661. /**
  662. * Performs a depth first fold on this tree. Transforms a tree into a single
  663. * value, given a function that operates on the path to a node, an optional
  664. * current value, and a map of child names to folded subtrees
  665. */
  666. fold<V>(fn: (path: Path, value: T, children: {
  667. [k: string]: V;
  668. }) => V): V;
  669. /**
  670. * Recursive helper for public-facing fold() method
  671. */
  672. private fold_;
  673. /**
  674. * Find the first matching value on the given path. Return the result of applying f to it.
  675. */
  676. findOnPath<V>(path: Path, f: (path: Path, value: T) => V | null): V | null;
  677. private findOnPath_;
  678. foreachOnPath(path: Path, f: (path: Path, value: T) => void): ImmutableTree<T>;
  679. private foreachOnPath_;
  680. /**
  681. * Calls the given function for each node in the tree that has a value.
  682. *
  683. * @param f - A function to be called with the path from the root of the tree to
  684. * a node, and the value at that node. Called in depth-first order.
  685. */
  686. foreach(f: (path: Path, value: T) => void): void;
  687. private foreach_;
  688. foreachChild(f: (name: string, value: T) => void): void;
  689. }
  690. /**
  691. * Returns a placeholder value that can be used to atomically increment the
  692. * current database value by the provided delta.
  693. *
  694. * @param delta - the amount to modify the current value atomically.
  695. * @returns A placeholder value for modifying data atomically server-side.
  696. */
  697. export declare function increment(delta: number): object;
  698. declare abstract class Index {
  699. abstract compare(a: NamedNode, b: NamedNode): number;
  700. abstract isDefinedOn(node: Node_2): boolean;
  701. /**
  702. * @returns A standalone comparison function for
  703. * this index
  704. */
  705. getCompare(): Comparator<NamedNode>;
  706. /**
  707. * Given a before and after value for a node, determine if the indexed value has changed. Even if they are different,
  708. * it's possible that the changes are isolated to parts of the snapshot that are not indexed.
  709. *
  710. *
  711. * @returns True if the portion of the snapshot being indexed changed between oldNode and newNode
  712. */
  713. indexedValueChanged(oldNode: Node_2, newNode: Node_2): boolean;
  714. /**
  715. * @returns a node wrapper that will sort equal to or less than
  716. * any other node wrapper, using this index
  717. */
  718. minPost(): NamedNode;
  719. /**
  720. * @returns a node wrapper that will sort greater than or equal to
  721. * any other node wrapper, using this index
  722. */
  723. abstract maxPost(): NamedNode;
  724. abstract makePost(indexValue: unknown, name: string): NamedNode;
  725. /**
  726. * @returns String representation for inclusion in a query spec
  727. */
  728. abstract toString(): string;
  729. }
  730. /**
  731. * Creates a new `QueryConstraint` that if limited to the first specific number
  732. * of children.
  733. *
  734. * The `limitToFirst()` method is used to set a maximum number of children to be
  735. * synced for a given callback. If we set a limit of 100, we will initially only
  736. * receive up to 100 `child_added` events. If we have fewer than 100 messages
  737. * stored in our Database, a `child_added` event will fire for each message.
  738. * However, if we have over 100 messages, we will only receive a `child_added`
  739. * event for the first 100 ordered messages. As items change, we will receive
  740. * `child_removed` events for each item that drops out of the active list so
  741. * that the total number stays at 100.
  742. *
  743. * You can read more about `limitToFirst()` in
  744. * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
  745. *
  746. * @param limit - The maximum number of nodes to include in this query.
  747. */
  748. export declare function limitToFirst(limit: number): QueryConstraint;
  749. /**
  750. * Creates a new `QueryConstraint` that is limited to return only the last
  751. * specified number of children.
  752. *
  753. * The `limitToLast()` method is used to set a maximum number of children to be
  754. * synced for a given callback. If we set a limit of 100, we will initially only
  755. * receive up to 100 `child_added` events. If we have fewer than 100 messages
  756. * stored in our Database, a `child_added` event will fire for each message.
  757. * However, if we have over 100 messages, we will only receive a `child_added`
  758. * event for the last 100 ordered messages. As items change, we will receive
  759. * `child_removed` events for each item that drops out of the active list so
  760. * that the total number stays at 100.
  761. *
  762. * You can read more about `limitToLast()` in
  763. * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
  764. *
  765. * @param limit - The maximum number of nodes to include in this query.
  766. */
  767. export declare function limitToLast(limit: number): QueryConstraint;
  768. /** An options objects that can be used to customize a listener. */
  769. export declare interface ListenOptions {
  770. /** Whether to remove the listener after its first invocation. */
  771. readonly onlyOnce?: boolean;
  772. }
  773. declare interface ListenProvider {
  774. startListening(query: QueryContext, tag: number | null, hashFn: () => string, onComplete: (a: string, b?: unknown) => Event_2[]): Event_2[];
  775. stopListening(a: QueryContext, b: number | null): void;
  776. }
  777. /**
  778. * Represents an empty node (a leaf node in the Red-Black Tree).
  779. */
  780. declare class LLRBEmptyNode<K, V> {
  781. key: K;
  782. value: V;
  783. left: LLRBNode<K, V> | LLRBEmptyNode<K, V>;
  784. right: LLRBNode<K, V> | LLRBEmptyNode<K, V>;
  785. color: boolean;
  786. /**
  787. * Returns a copy of the current node.
  788. *
  789. * @returns The node copy.
  790. */
  791. copy(key: K | null, value: V | null, color: boolean | null, left: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null, right: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null): LLRBEmptyNode<K, V>;
  792. /**
  793. * Returns a copy of the tree, with the specified key/value added.
  794. *
  795. * @param key - Key to be added.
  796. * @param value - Value to be added.
  797. * @param comparator - Comparator.
  798. * @returns New tree, with item added.
  799. */
  800. insert(key: K, value: V, comparator: Comparator<K>): LLRBNode<K, V>;
  801. /**
  802. * Returns a copy of the tree, with the specified key removed.
  803. *
  804. * @param key - The key to remove.
  805. * @param comparator - Comparator.
  806. * @returns New tree, with item removed.
  807. */
  808. remove(key: K, comparator: Comparator<K>): LLRBEmptyNode<K, V>;
  809. /**
  810. * @returns The total number of nodes in the tree.
  811. */
  812. count(): number;
  813. /**
  814. * @returns True if the tree is empty.
  815. */
  816. isEmpty(): boolean;
  817. /**
  818. * Traverses the tree in key order and calls the specified action function
  819. * for each node.
  820. *
  821. * @param action - Callback function to be called for each
  822. * node. If it returns true, traversal is aborted.
  823. * @returns True if traversal was aborted.
  824. */
  825. inorderTraversal(action: (k: K, v: V) => unknown): boolean;
  826. /**
  827. * Traverses the tree in reverse key order and calls the specified action function
  828. * for each node.
  829. *
  830. * @param action - Callback function to be called for each
  831. * node. If it returns true, traversal is aborted.
  832. * @returns True if traversal was aborted.
  833. */
  834. reverseTraversal(action: (k: K, v: V) => void): boolean;
  835. minKey(): null;
  836. maxKey(): null;
  837. check_(): number;
  838. /**
  839. * @returns Whether this node is red.
  840. */
  841. isRed_(): boolean;
  842. }
  843. /**
  844. * Represents a node in a Left-leaning Red-Black tree.
  845. */
  846. declare class LLRBNode<K, V> {
  847. key: K;
  848. value: V;
  849. color: boolean;
  850. left: LLRBNode<K, V> | LLRBEmptyNode<K, V>;
  851. right: LLRBNode<K, V> | LLRBEmptyNode<K, V>;
  852. /**
  853. * @param key - Key associated with this node.
  854. * @param value - Value associated with this node.
  855. * @param color - Whether this node is red.
  856. * @param left - Left child.
  857. * @param right - Right child.
  858. */
  859. constructor(key: K, value: V, color: boolean | null, left?: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null, right?: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null);
  860. static RED: boolean;
  861. static BLACK: boolean;
  862. /**
  863. * Returns a copy of the current node, optionally replacing pieces of it.
  864. *
  865. * @param key - New key for the node, or null.
  866. * @param value - New value for the node, or null.
  867. * @param color - New color for the node, or null.
  868. * @param left - New left child for the node, or null.
  869. * @param right - New right child for the node, or null.
  870. * @returns The node copy.
  871. */
  872. copy(key: K | null, value: V | null, color: boolean | null, left: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null, right: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null): LLRBNode<K, V>;
  873. /**
  874. * @returns The total number of nodes in the tree.
  875. */
  876. count(): number;
  877. /**
  878. * @returns True if the tree is empty.
  879. */
  880. isEmpty(): boolean;
  881. /**
  882. * Traverses the tree in key order and calls the specified action function
  883. * for each node.
  884. *
  885. * @param action - Callback function to be called for each
  886. * node. If it returns true, traversal is aborted.
  887. * @returns The first truthy value returned by action, or the last falsey
  888. * value returned by action
  889. */
  890. inorderTraversal(action: (k: K, v: V) => unknown): boolean;
  891. /**
  892. * Traverses the tree in reverse key order and calls the specified action function
  893. * for each node.
  894. *
  895. * @param action - Callback function to be called for each
  896. * node. If it returns true, traversal is aborted.
  897. * @returns True if traversal was aborted.
  898. */
  899. reverseTraversal(action: (k: K, v: V) => void): boolean;
  900. /**
  901. * @returns The minimum node in the tree.
  902. */
  903. private min_;
  904. /**
  905. * @returns The maximum key in the tree.
  906. */
  907. minKey(): K;
  908. /**
  909. * @returns The maximum key in the tree.
  910. */
  911. maxKey(): K;
  912. /**
  913. * @param key - Key to insert.
  914. * @param value - Value to insert.
  915. * @param comparator - Comparator.
  916. * @returns New tree, with the key/value added.
  917. */
  918. insert(key: K, value: V, comparator: Comparator<K>): LLRBNode<K, V>;
  919. /**
  920. * @returns New tree, with the minimum key removed.
  921. */
  922. private removeMin_;
  923. /**
  924. * @param key - The key of the item to remove.
  925. * @param comparator - Comparator.
  926. * @returns New tree, with the specified item removed.
  927. */
  928. remove(key: K, comparator: Comparator<K>): LLRBNode<K, V> | LLRBEmptyNode<K, V>;
  929. /**
  930. * @returns Whether this is a RED node.
  931. */
  932. isRed_(): boolean;
  933. /**
  934. * @returns New tree after performing any needed rotations.
  935. */
  936. private fixUp_;
  937. /**
  938. * @returns New tree, after moveRedLeft.
  939. */
  940. private moveRedLeft_;
  941. /**
  942. * @returns New tree, after moveRedRight.
  943. */
  944. private moveRedRight_;
  945. /**
  946. * @returns New tree, after rotateLeft.
  947. */
  948. private rotateLeft_;
  949. /**
  950. * @returns New tree, after rotateRight.
  951. */
  952. private rotateRight_;
  953. /**
  954. * @returns Newt ree, after colorFlip.
  955. */
  956. private colorFlip_;
  957. /**
  958. * For testing.
  959. *
  960. * @returns True if all is well.
  961. */
  962. private checkMaxDepth_;
  963. check_(): number;
  964. }
  965. declare class NamedNode {
  966. name: string;
  967. node: Node_2;
  968. constructor(name: string, node: Node_2);
  969. static Wrap(name: string, node: Node_2): NamedNode;
  970. }
  971. /**
  972. * Node is an interface defining the common functionality for nodes in
  973. * a DataSnapshot.
  974. *
  975. * @interface
  976. */
  977. declare interface Node_2 {
  978. /**
  979. * Whether this node is a leaf node.
  980. * @returns Whether this is a leaf node.
  981. */
  982. isLeafNode(): boolean;
  983. /**
  984. * Gets the priority of the node.
  985. * @returns The priority of the node.
  986. */
  987. getPriority(): Node_2;
  988. /**
  989. * Returns a duplicate node with the new priority.
  990. * @param newPriorityNode - New priority to set for the node.
  991. * @returns Node with new priority.
  992. */
  993. updatePriority(newPriorityNode: Node_2): Node_2;
  994. /**
  995. * Returns the specified immediate child, or null if it doesn't exist.
  996. * @param childName - The name of the child to retrieve.
  997. * @returns The retrieved child, or an empty node.
  998. */
  999. getImmediateChild(childName: string): Node_2;
  1000. /**
  1001. * Returns a child by path, or null if it doesn't exist.
  1002. * @param path - The path of the child to retrieve.
  1003. * @returns The retrieved child or an empty node.
  1004. */
  1005. getChild(path: Path): Node_2;
  1006. /**
  1007. * Returns the name of the child immediately prior to the specified childNode, or null.
  1008. * @param childName - The name of the child to find the predecessor of.
  1009. * @param childNode - The node to find the predecessor of.
  1010. * @param index - The index to use to determine the predecessor
  1011. * @returns The name of the predecessor child, or null if childNode is the first child.
  1012. */
  1013. getPredecessorChildName(childName: string, childNode: Node_2, index: Index): string | null;
  1014. /**
  1015. * Returns a duplicate node, with the specified immediate child updated.
  1016. * Any value in the node will be removed.
  1017. * @param childName - The name of the child to update.
  1018. * @param newChildNode - The new child node
  1019. * @returns The updated node.
  1020. */
  1021. updateImmediateChild(childName: string, newChildNode: Node_2): Node_2;
  1022. /**
  1023. * Returns a duplicate node, with the specified child updated. Any value will
  1024. * be removed.
  1025. * @param path - The path of the child to update.
  1026. * @param newChildNode - The new child node, which may be an empty node
  1027. * @returns The updated node.
  1028. */
  1029. updateChild(path: Path, newChildNode: Node_2): Node_2;
  1030. /**
  1031. * True if the immediate child specified exists
  1032. */
  1033. hasChild(childName: string): boolean;
  1034. /**
  1035. * @returns True if this node has no value or children.
  1036. */
  1037. isEmpty(): boolean;
  1038. /**
  1039. * @returns The number of children of this node.
  1040. */
  1041. numChildren(): number;
  1042. /**
  1043. * Calls action for each child.
  1044. * @param action - Action to be called for
  1045. * each child. It's passed the child name and the child node.
  1046. * @returns The first truthy value return by action, or the last falsey one
  1047. */
  1048. forEachChild(index: Index, action: (a: string, b: Node_2) => void): unknown;
  1049. /**
  1050. * @param exportFormat - True for export format (also wire protocol format).
  1051. * @returns Value of this node as JSON.
  1052. */
  1053. val(exportFormat?: boolean): unknown;
  1054. /**
  1055. * @returns hash representing the node contents.
  1056. */
  1057. hash(): string;
  1058. /**
  1059. * @param other - Another node
  1060. * @returns -1 for less than, 0 for equal, 1 for greater than other
  1061. */
  1062. compareTo(other: Node_2): number;
  1063. /**
  1064. * @returns Whether or not this snapshot equals other
  1065. */
  1066. equals(other: Node_2): boolean;
  1067. /**
  1068. * @returns This node, with the specified index now available
  1069. */
  1070. withIndex(indexDefinition: Index): Node_2;
  1071. isIndexed(indexDefinition: Index): boolean;
  1072. }
  1073. /**
  1074. * NodeFilter is used to update nodes and complete children of nodes while applying queries on the fly and keeping
  1075. * track of any child changes. This class does not track value changes as value changes depend on more
  1076. * than just the node itself. Different kind of queries require different kind of implementations of this interface.
  1077. * @interface
  1078. */
  1079. declare interface NodeFilter_2 {
  1080. /**
  1081. * Update a single complete child in the snap. If the child equals the old child in the snap, this is a no-op.
  1082. * The method expects an indexed snap.
  1083. */
  1084. updateChild(snap: Node_2, key: string, newChild: Node_2, affectedPath: Path, source: CompleteChildSource, optChangeAccumulator: ChildChangeAccumulator | null): Node_2;
  1085. /**
  1086. * Update a node in full and output any resulting change from this complete update.
  1087. */
  1088. updateFullNode(oldSnap: Node_2, newSnap: Node_2, optChangeAccumulator: ChildChangeAccumulator | null): Node_2;
  1089. /**
  1090. * Update the priority of the root node
  1091. */
  1092. updatePriority(oldSnap: Node_2, newPriority: Node_2): Node_2;
  1093. /**
  1094. * Returns true if children might be filtered due to query criteria
  1095. */
  1096. filtersNodes(): boolean;
  1097. /**
  1098. * Returns the index filter that this filter uses to get a NodeFilter that doesn't filter any children.
  1099. */
  1100. getIndexedFilter(): NodeFilter_2;
  1101. /**
  1102. * Returns the index that this filter uses
  1103. */
  1104. getIndex(): Index;
  1105. }
  1106. /**
  1107. * Detaches a callback previously attached with the corresponding `on*()` (`onValue`, `onChildAdded`) listener.
  1108. * Note: This is not the recommended way to remove a listener. Instead, please use the returned callback function from
  1109. * the respective `on*` callbacks.
  1110. *
  1111. * Detach a callback previously attached with `on*()`. Calling `off()` on a parent listener
  1112. * will not automatically remove listeners registered on child nodes, `off()`
  1113. * must also be called on any child listeners to remove the callback.
  1114. *
  1115. * If a callback is not specified, all callbacks for the specified eventType
  1116. * will be removed. Similarly, if no eventType is specified, all callbacks
  1117. * for the `Reference` will be removed.
  1118. *
  1119. * Individual listeners can also be removed by invoking their unsubscribe
  1120. * callbacks.
  1121. *
  1122. * @param query - The query that the listener was registered with.
  1123. * @param eventType - One of the following strings: "value", "child_added",
  1124. * "child_changed", "child_removed", or "child_moved." If omitted, all callbacks
  1125. * for the `Reference` will be removed.
  1126. * @param callback - The callback function that was passed to `on()` or
  1127. * `undefined` to remove all callbacks.
  1128. */
  1129. export declare function off(query: Query, eventType?: EventType, callback?: (snapshot: DataSnapshot, previousChildName?: string | null) => unknown): void;
  1130. /**
  1131. * Listens for data changes at a particular location.
  1132. *
  1133. * This is the primary way to read data from a Database. Your callback
  1134. * will be triggered for the initial data and again whenever the data changes.
  1135. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1136. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1137. * for more details.
  1138. *
  1139. * An `onChildAdded` event will be triggered once for each initial child at this
  1140. * location, and it will be triggered again every time a new child is added. The
  1141. * `DataSnapshot` passed into the callback will reflect the data for the
  1142. * relevant child. For ordering purposes, it is passed a second argument which
  1143. * is a string containing the key of the previous sibling child by sort order,
  1144. * or `null` if it is the first child.
  1145. *
  1146. * @param query - The query to run.
  1147. * @param callback - A callback that fires when the specified event occurs.
  1148. * The callback will be passed a DataSnapshot and a string containing the key of
  1149. * the previous child, by sort order, or `null` if it is the first child.
  1150. * @param cancelCallback - An optional callback that will be notified if your
  1151. * event subscription is ever canceled because your client does not have
  1152. * permission to read this data (or it had permission but has now lost it).
  1153. * This callback will be passed an `Error` object indicating why the failure
  1154. * occurred.
  1155. * @returns A function that can be invoked to remove the listener.
  1156. */
  1157. export declare function onChildAdded(query: Query, callback: (snapshot: DataSnapshot, previousChildName?: string | null) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
  1158. /**
  1159. * Listens for data changes at a particular location.
  1160. *
  1161. * This is the primary way to read data from a Database. Your callback
  1162. * will be triggered for the initial data and again whenever the data changes.
  1163. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1164. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1165. * for more details.
  1166. *
  1167. * An `onChildAdded` event will be triggered once for each initial child at this
  1168. * location, and it will be triggered again every time a new child is added. The
  1169. * `DataSnapshot` passed into the callback will reflect the data for the
  1170. * relevant child. For ordering purposes, it is passed a second argument which
  1171. * is a string containing the key of the previous sibling child by sort order,
  1172. * or `null` if it is the first child.
  1173. *
  1174. * @param query - The query to run.
  1175. * @param callback - A callback that fires when the specified event occurs.
  1176. * The callback will be passed a DataSnapshot and a string containing the key of
  1177. * the previous child, by sort order, or `null` if it is the first child.
  1178. * @param options - An object that can be used to configure `onlyOnce`, which
  1179. * then removes the listener after its first invocation.
  1180. * @returns A function that can be invoked to remove the listener.
  1181. */
  1182. export declare function onChildAdded(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, options: ListenOptions): Unsubscribe;
  1183. /**
  1184. * Listens for data changes at a particular location.
  1185. *
  1186. * This is the primary way to read data from a Database. Your callback
  1187. * will be triggered for the initial data and again whenever the data changes.
  1188. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1189. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1190. * for more details.
  1191. *
  1192. * An `onChildAdded` event will be triggered once for each initial child at this
  1193. * location, and it will be triggered again every time a new child is added. The
  1194. * `DataSnapshot` passed into the callback will reflect the data for the
  1195. * relevant child. For ordering purposes, it is passed a second argument which
  1196. * is a string containing the key of the previous sibling child by sort order,
  1197. * or `null` if it is the first child.
  1198. *
  1199. * @param query - The query to run.
  1200. * @param callback - A callback that fires when the specified event occurs.
  1201. * The callback will be passed a DataSnapshot and a string containing the key of
  1202. * the previous child, by sort order, or `null` if it is the first child.
  1203. * @param cancelCallback - An optional callback that will be notified if your
  1204. * event subscription is ever canceled because your client does not have
  1205. * permission to read this data (or it had permission but has now lost it).
  1206. * This callback will be passed an `Error` object indicating why the failure
  1207. * occurred.
  1208. * @param options - An object that can be used to configure `onlyOnce`, which
  1209. * then removes the listener after its first invocation.
  1210. * @returns A function that can be invoked to remove the listener.
  1211. */
  1212. export declare function onChildAdded(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
  1213. /**
  1214. * Listens for data changes at a particular location.
  1215. *
  1216. * This is the primary way to read data from a Database. Your callback
  1217. * will be triggered for the initial data and again whenever the data changes.
  1218. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1219. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1220. * for more details.
  1221. *
  1222. * An `onChildChanged` event will be triggered when the data stored in a child
  1223. * (or any of its descendants) changes. Note that a single `child_changed` event
  1224. * may represent multiple changes to the child. The `DataSnapshot` passed to the
  1225. * callback will contain the new child contents. For ordering purposes, the
  1226. * callback is also passed a second argument which is a string containing the
  1227. * key of the previous sibling child by sort order, or `null` if it is the first
  1228. * child.
  1229. *
  1230. * @param query - The query to run.
  1231. * @param callback - A callback that fires when the specified event occurs.
  1232. * The callback will be passed a DataSnapshot and a string containing the key of
  1233. * the previous child, by sort order, or `null` if it is the first child.
  1234. * @param cancelCallback - An optional callback that will be notified if your
  1235. * event subscription is ever canceled because your client does not have
  1236. * permission to read this data (or it had permission but has now lost it).
  1237. * This callback will be passed an `Error` object indicating why the failure
  1238. * occurred.
  1239. * @returns A function that can be invoked to remove the listener.
  1240. */
  1241. export declare function onChildChanged(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
  1242. /**
  1243. * Listens for data changes at a particular location.
  1244. *
  1245. * This is the primary way to read data from a Database. Your callback
  1246. * will be triggered for the initial data and again whenever the data changes.
  1247. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1248. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1249. * for more details.
  1250. *
  1251. * An `onChildChanged` event will be triggered when the data stored in a child
  1252. * (or any of its descendants) changes. Note that a single `child_changed` event
  1253. * may represent multiple changes to the child. The `DataSnapshot` passed to the
  1254. * callback will contain the new child contents. For ordering purposes, the
  1255. * callback is also passed a second argument which is a string containing the
  1256. * key of the previous sibling child by sort order, or `null` if it is the first
  1257. * child.
  1258. *
  1259. * @param query - The query to run.
  1260. * @param callback - A callback that fires when the specified event occurs.
  1261. * The callback will be passed a DataSnapshot and a string containing the key of
  1262. * the previous child, by sort order, or `null` if it is the first child.
  1263. * @param options - An object that can be used to configure `onlyOnce`, which
  1264. * then removes the listener after its first invocation.
  1265. * @returns A function that can be invoked to remove the listener.
  1266. */
  1267. export declare function onChildChanged(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, options: ListenOptions): Unsubscribe;
  1268. /**
  1269. * Listens for data changes at a particular location.
  1270. *
  1271. * This is the primary way to read data from a Database. Your callback
  1272. * will be triggered for the initial data and again whenever the data changes.
  1273. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1274. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1275. * for more details.
  1276. *
  1277. * An `onChildChanged` event will be triggered when the data stored in a child
  1278. * (or any of its descendants) changes. Note that a single `child_changed` event
  1279. * may represent multiple changes to the child. The `DataSnapshot` passed to the
  1280. * callback will contain the new child contents. For ordering purposes, the
  1281. * callback is also passed a second argument which is a string containing the
  1282. * key of the previous sibling child by sort order, or `null` if it is the first
  1283. * child.
  1284. *
  1285. * @param query - The query to run.
  1286. * @param callback - A callback that fires when the specified event occurs.
  1287. * The callback will be passed a DataSnapshot and a string containing the key of
  1288. * the previous child, by sort order, or `null` if it is the first child.
  1289. * @param cancelCallback - An optional callback that will be notified if your
  1290. * event subscription is ever canceled because your client does not have
  1291. * permission to read this data (or it had permission but has now lost it).
  1292. * This callback will be passed an `Error` object indicating why the failure
  1293. * occurred.
  1294. * @param options - An object that can be used to configure `onlyOnce`, which
  1295. * then removes the listener after its first invocation.
  1296. * @returns A function that can be invoked to remove the listener.
  1297. */
  1298. export declare function onChildChanged(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
  1299. /**
  1300. * Listens for data changes at a particular location.
  1301. *
  1302. * This is the primary way to read data from a Database. Your callback
  1303. * will be triggered for the initial data and again whenever the data changes.
  1304. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1305. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1306. * for more details.
  1307. *
  1308. * An `onChildMoved` event will be triggered when a child's sort order changes
  1309. * such that its position relative to its siblings changes. The `DataSnapshot`
  1310. * passed to the callback will be for the data of the child that has moved. It
  1311. * is also passed a second argument which is a string containing the key of the
  1312. * previous sibling child by sort order, or `null` if it is the first child.
  1313. *
  1314. * @param query - The query to run.
  1315. * @param callback - A callback that fires when the specified event occurs.
  1316. * The callback will be passed a DataSnapshot and a string containing the key of
  1317. * the previous child, by sort order, or `null` if it is the first child.
  1318. * @param cancelCallback - An optional callback that will be notified if your
  1319. * event subscription is ever canceled because your client does not have
  1320. * permission to read this data (or it had permission but has now lost it).
  1321. * This callback will be passed an `Error` object indicating why the failure
  1322. * occurred.
  1323. * @returns A function that can be invoked to remove the listener.
  1324. */
  1325. export declare function onChildMoved(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
  1326. /**
  1327. * Listens for data changes at a particular location.
  1328. *
  1329. * This is the primary way to read data from a Database. Your callback
  1330. * will be triggered for the initial data and again whenever the data changes.
  1331. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1332. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1333. * for more details.
  1334. *
  1335. * An `onChildMoved` event will be triggered when a child's sort order changes
  1336. * such that its position relative to its siblings changes. The `DataSnapshot`
  1337. * passed to the callback will be for the data of the child that has moved. It
  1338. * is also passed a second argument which is a string containing the key of the
  1339. * previous sibling child by sort order, or `null` if it is the first child.
  1340. *
  1341. * @param query - The query to run.
  1342. * @param callback - A callback that fires when the specified event occurs.
  1343. * The callback will be passed a DataSnapshot and a string containing the key of
  1344. * the previous child, by sort order, or `null` if it is the first child.
  1345. * @param options - An object that can be used to configure `onlyOnce`, which
  1346. * then removes the listener after its first invocation.
  1347. * @returns A function that can be invoked to remove the listener.
  1348. */
  1349. export declare function onChildMoved(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, options: ListenOptions): Unsubscribe;
  1350. /**
  1351. * Listens for data changes at a particular location.
  1352. *
  1353. * This is the primary way to read data from a Database. Your callback
  1354. * will be triggered for the initial data and again whenever the data changes.
  1355. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1356. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1357. * for more details.
  1358. *
  1359. * An `onChildMoved` event will be triggered when a child's sort order changes
  1360. * such that its position relative to its siblings changes. The `DataSnapshot`
  1361. * passed to the callback will be for the data of the child that has moved. It
  1362. * is also passed a second argument which is a string containing the key of the
  1363. * previous sibling child by sort order, or `null` if it is the first child.
  1364. *
  1365. * @param query - The query to run.
  1366. * @param callback - A callback that fires when the specified event occurs.
  1367. * The callback will be passed a DataSnapshot and a string containing the key of
  1368. * the previous child, by sort order, or `null` if it is the first child.
  1369. * @param cancelCallback - An optional callback that will be notified if your
  1370. * event subscription is ever canceled because your client does not have
  1371. * permission to read this data (or it had permission but has now lost it).
  1372. * This callback will be passed an `Error` object indicating why the failure
  1373. * occurred.
  1374. * @param options - An object that can be used to configure `onlyOnce`, which
  1375. * then removes the listener after its first invocation.
  1376. * @returns A function that can be invoked to remove the listener.
  1377. */
  1378. export declare function onChildMoved(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
  1379. /**
  1380. * Listens for data changes at a particular location.
  1381. *
  1382. * This is the primary way to read data from a Database. Your callback
  1383. * will be triggered for the initial data and again whenever the data changes.
  1384. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1385. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1386. * for more details.
  1387. *
  1388. * An `onChildRemoved` event will be triggered once every time a child is
  1389. * removed. The `DataSnapshot` passed into the callback will be the old data for
  1390. * the child that was removed. A child will get removed when either:
  1391. *
  1392. * - a client explicitly calls `remove()` on that child or one of its ancestors
  1393. * - a client calls `set(null)` on that child or one of its ancestors
  1394. * - that child has all of its children removed
  1395. * - there is a query in effect which now filters out the child (because it's
  1396. * sort order changed or the max limit was hit)
  1397. *
  1398. * @param query - The query to run.
  1399. * @param callback - A callback that fires when the specified event occurs.
  1400. * The callback will be passed a DataSnapshot and a string containing the key of
  1401. * the previous child, by sort order, or `null` if it is the first child.
  1402. * @param cancelCallback - An optional callback that will be notified if your
  1403. * event subscription is ever canceled because your client does not have
  1404. * permission to read this data (or it had permission but has now lost it).
  1405. * This callback will be passed an `Error` object indicating why the failure
  1406. * occurred.
  1407. * @returns A function that can be invoked to remove the listener.
  1408. */
  1409. export declare function onChildRemoved(query: Query, callback: (snapshot: DataSnapshot) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
  1410. /**
  1411. * Listens for data changes at a particular location.
  1412. *
  1413. * This is the primary way to read data from a Database. Your callback
  1414. * will be triggered for the initial data and again whenever the data changes.
  1415. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1416. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1417. * for more details.
  1418. *
  1419. * An `onChildRemoved` event will be triggered once every time a child is
  1420. * removed. The `DataSnapshot` passed into the callback will be the old data for
  1421. * the child that was removed. A child will get removed when either:
  1422. *
  1423. * - a client explicitly calls `remove()` on that child or one of its ancestors
  1424. * - a client calls `set(null)` on that child or one of its ancestors
  1425. * - that child has all of its children removed
  1426. * - there is a query in effect which now filters out the child (because it's
  1427. * sort order changed or the max limit was hit)
  1428. *
  1429. * @param query - The query to run.
  1430. * @param callback - A callback that fires when the specified event occurs.
  1431. * The callback will be passed a DataSnapshot and a string containing the key of
  1432. * the previous child, by sort order, or `null` if it is the first child.
  1433. * @param options - An object that can be used to configure `onlyOnce`, which
  1434. * then removes the listener after its first invocation.
  1435. * @returns A function that can be invoked to remove the listener.
  1436. */
  1437. export declare function onChildRemoved(query: Query, callback: (snapshot: DataSnapshot) => unknown, options: ListenOptions): Unsubscribe;
  1438. /**
  1439. * Listens for data changes at a particular location.
  1440. *
  1441. * This is the primary way to read data from a Database. Your callback
  1442. * will be triggered for the initial data and again whenever the data changes.
  1443. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1444. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1445. * for more details.
  1446. *
  1447. * An `onChildRemoved` event will be triggered once every time a child is
  1448. * removed. The `DataSnapshot` passed into the callback will be the old data for
  1449. * the child that was removed. A child will get removed when either:
  1450. *
  1451. * - a client explicitly calls `remove()` on that child or one of its ancestors
  1452. * - a client calls `set(null)` on that child or one of its ancestors
  1453. * - that child has all of its children removed
  1454. * - there is a query in effect which now filters out the child (because it's
  1455. * sort order changed or the max limit was hit)
  1456. *
  1457. * @param query - The query to run.
  1458. * @param callback - A callback that fires when the specified event occurs.
  1459. * The callback will be passed a DataSnapshot and a string containing the key of
  1460. * the previous child, by sort order, or `null` if it is the first child.
  1461. * @param cancelCallback - An optional callback that will be notified if your
  1462. * event subscription is ever canceled because your client does not have
  1463. * permission to read this data (or it had permission but has now lost it).
  1464. * This callback will be passed an `Error` object indicating why the failure
  1465. * occurred.
  1466. * @param options - An object that can be used to configure `onlyOnce`, which
  1467. * then removes the listener after its first invocation.
  1468. * @returns A function that can be invoked to remove the listener.
  1469. */
  1470. export declare function onChildRemoved(query: Query, callback: (snapshot: DataSnapshot) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
  1471. /**
  1472. * The `onDisconnect` class allows you to write or clear data when your client
  1473. * disconnects from the Database server. These updates occur whether your
  1474. * client disconnects cleanly or not, so you can rely on them to clean up data
  1475. * even if a connection is dropped or a client crashes.
  1476. *
  1477. * The `onDisconnect` class is most commonly used to manage presence in
  1478. * applications where it is useful to detect how many clients are connected and
  1479. * when other clients disconnect. See
  1480. * {@link https://firebase.google.com/docs/database/web/offline-capabilities | Enabling Offline Capabilities in JavaScript}
  1481. * for more information.
  1482. *
  1483. * To avoid problems when a connection is dropped before the requests can be
  1484. * transferred to the Database server, these functions should be called before
  1485. * writing any data.
  1486. *
  1487. * Note that `onDisconnect` operations are only triggered once. If you want an
  1488. * operation to occur each time a disconnect occurs, you'll need to re-establish
  1489. * the `onDisconnect` operations each time you reconnect.
  1490. */
  1491. export declare class OnDisconnect {
  1492. private _repo;
  1493. private _path;
  1494. /** @hideconstructor */
  1495. constructor(_repo: Repo, _path: Path);
  1496. /**
  1497. * Cancels all previously queued `onDisconnect()` set or update events for this
  1498. * location and all children.
  1499. *
  1500. * If a write has been queued for this location via a `set()` or `update()` at a
  1501. * parent location, the write at this location will be canceled, though writes
  1502. * to sibling locations will still occur.
  1503. *
  1504. * @returns Resolves when synchronization to the server is complete.
  1505. */
  1506. cancel(): Promise<void>;
  1507. /**
  1508. * Ensures the data at this location is deleted when the client is disconnected
  1509. * (due to closing the browser, navigating to a new page, or network issues).
  1510. *
  1511. * @returns Resolves when synchronization to the server is complete.
  1512. */
  1513. remove(): Promise<void>;
  1514. /**
  1515. * Ensures the data at this location is set to the specified value when the
  1516. * client is disconnected (due to closing the browser, navigating to a new page,
  1517. * or network issues).
  1518. *
  1519. * `set()` is especially useful for implementing "presence" systems, where a
  1520. * value should be changed or cleared when a user disconnects so that they
  1521. * appear "offline" to other users. See
  1522. * {@link https://firebase.google.com/docs/database/web/offline-capabilities | Enabling Offline Capabilities in JavaScript}
  1523. * for more information.
  1524. *
  1525. * Note that `onDisconnect` operations are only triggered once. If you want an
  1526. * operation to occur each time a disconnect occurs, you'll need to re-establish
  1527. * the `onDisconnect` operations each time.
  1528. *
  1529. * @param value - The value to be written to this location on disconnect (can
  1530. * be an object, array, string, number, boolean, or null).
  1531. * @returns Resolves when synchronization to the Database is complete.
  1532. */
  1533. set(value: unknown): Promise<void>;
  1534. /**
  1535. * Ensures the data at this location is set to the specified value and priority
  1536. * when the client is disconnected (due to closing the browser, navigating to a
  1537. * new page, or network issues).
  1538. *
  1539. * @param value - The value to be written to this location on disconnect (can
  1540. * be an object, array, string, number, boolean, or null).
  1541. * @param priority - The priority to be written (string, number, or null).
  1542. * @returns Resolves when synchronization to the Database is complete.
  1543. */
  1544. setWithPriority(value: unknown, priority: number | string | null): Promise<void>;
  1545. /**
  1546. * Writes multiple values at this location when the client is disconnected (due
  1547. * to closing the browser, navigating to a new page, or network issues).
  1548. *
  1549. * The `values` argument contains multiple property-value pairs that will be
  1550. * written to the Database together. Each child property can either be a simple
  1551. * property (for example, "name") or a relative path (for example, "name/first")
  1552. * from the current location to the data to update.
  1553. *
  1554. * As opposed to the `set()` method, `update()` can be use to selectively update
  1555. * only the referenced properties at the current location (instead of replacing
  1556. * all the child properties at the current location).
  1557. *
  1558. * @param values - Object containing multiple values.
  1559. * @returns Resolves when synchronization to the Database is complete.
  1560. */
  1561. update(values: object): Promise<void>;
  1562. }
  1563. /**
  1564. * Returns an `OnDisconnect` object - see
  1565. * {@link https://firebase.google.com/docs/database/web/offline-capabilities | Enabling Offline Capabilities in JavaScript}
  1566. * for more information on how to use it.
  1567. *
  1568. * @param ref - The reference to add OnDisconnect triggers for.
  1569. */
  1570. export declare function onDisconnect(ref: DatabaseReference): OnDisconnect;
  1571. /**
  1572. * Listens for data changes at a particular location.
  1573. *
  1574. * This is the primary way to read data from a Database. Your callback
  1575. * will be triggered for the initial data and again whenever the data changes.
  1576. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1577. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1578. * for more details.
  1579. *
  1580. * An `onValue` event will trigger once with the initial data stored at this
  1581. * location, and then trigger again each time the data changes. The
  1582. * `DataSnapshot` passed to the callback will be for the location at which
  1583. * `on()` was called. It won't trigger until the entire contents has been
  1584. * synchronized. If the location has no data, it will be triggered with an empty
  1585. * `DataSnapshot` (`val()` will return `null`).
  1586. *
  1587. * @param query - The query to run.
  1588. * @param callback - A callback that fires when the specified event occurs. The
  1589. * callback will be passed a DataSnapshot.
  1590. * @param cancelCallback - An optional callback that will be notified if your
  1591. * event subscription is ever canceled because your client does not have
  1592. * permission to read this data (or it had permission but has now lost it).
  1593. * This callback will be passed an `Error` object indicating why the failure
  1594. * occurred.
  1595. * @returns A function that can be invoked to remove the listener.
  1596. */
  1597. export declare function onValue(query: Query, callback: (snapshot: DataSnapshot) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
  1598. /**
  1599. * Listens for data changes at a particular location.
  1600. *
  1601. * This is the primary way to read data from a Database. Your callback
  1602. * will be triggered for the initial data and again whenever the data changes.
  1603. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1604. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1605. * for more details.
  1606. *
  1607. * An `onValue` event will trigger once with the initial data stored at this
  1608. * location, and then trigger again each time the data changes. The
  1609. * `DataSnapshot` passed to the callback will be for the location at which
  1610. * `on()` was called. It won't trigger until the entire contents has been
  1611. * synchronized. If the location has no data, it will be triggered with an empty
  1612. * `DataSnapshot` (`val()` will return `null`).
  1613. *
  1614. * @param query - The query to run.
  1615. * @param callback - A callback that fires when the specified event occurs. The
  1616. * callback will be passed a DataSnapshot.
  1617. * @param options - An object that can be used to configure `onlyOnce`, which
  1618. * then removes the listener after its first invocation.
  1619. * @returns A function that can be invoked to remove the listener.
  1620. */
  1621. export declare function onValue(query: Query, callback: (snapshot: DataSnapshot) => unknown, options: ListenOptions): Unsubscribe;
  1622. /**
  1623. * Listens for data changes at a particular location.
  1624. *
  1625. * This is the primary way to read data from a Database. Your callback
  1626. * will be triggered for the initial data and again whenever the data changes.
  1627. * Invoke the returned unsubscribe callback to stop receiving updates. See
  1628. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  1629. * for more details.
  1630. *
  1631. * An `onValue` event will trigger once with the initial data stored at this
  1632. * location, and then trigger again each time the data changes. The
  1633. * `DataSnapshot` passed to the callback will be for the location at which
  1634. * `on()` was called. It won't trigger until the entire contents has been
  1635. * synchronized. If the location has no data, it will be triggered with an empty
  1636. * `DataSnapshot` (`val()` will return `null`).
  1637. *
  1638. * @param query - The query to run.
  1639. * @param callback - A callback that fires when the specified event occurs. The
  1640. * callback will be passed a DataSnapshot.
  1641. * @param cancelCallback - An optional callback that will be notified if your
  1642. * event subscription is ever canceled because your client does not have
  1643. * permission to read this data (or it had permission but has now lost it).
  1644. * This callback will be passed an `Error` object indicating why the failure
  1645. * occurred.
  1646. * @param options - An object that can be used to configure `onlyOnce`, which
  1647. * then removes the listener after its first invocation.
  1648. * @returns A function that can be invoked to remove the listener.
  1649. */
  1650. export declare function onValue(query: Query, callback: (snapshot: DataSnapshot) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
  1651. /**
  1652. * Creates a new `QueryConstraint` that orders by the specified child key.
  1653. *
  1654. * Queries can only order by one key at a time. Calling `orderByChild()`
  1655. * multiple times on the same query is an error.
  1656. *
  1657. * Firebase queries allow you to order your data by any child key on the fly.
  1658. * However, if you know in advance what your indexes will be, you can define
  1659. * them via the .indexOn rule in your Security Rules for better performance. See
  1660. * the{@link https://firebase.google.com/docs/database/security/indexing-data}
  1661. * rule for more information.
  1662. *
  1663. * You can read more about `orderByChild()` in
  1664. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sort_data | Sort data}.
  1665. *
  1666. * @param path - The path to order by.
  1667. */
  1668. export declare function orderByChild(path: string): QueryConstraint;
  1669. /**
  1670. * Creates a new `QueryConstraint` that orders by the key.
  1671. *
  1672. * Sorts the results of a query by their (ascending) key values.
  1673. *
  1674. * You can read more about `orderByKey()` in
  1675. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sort_data | Sort data}.
  1676. */
  1677. export declare function orderByKey(): QueryConstraint;
  1678. /**
  1679. * Creates a new `QueryConstraint` that orders by priority.
  1680. *
  1681. * Applications need not use priority but can order collections by
  1682. * ordinary properties (see
  1683. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sort_data | Sort data}
  1684. * for alternatives to priority.
  1685. */
  1686. export declare function orderByPriority(): QueryConstraint;
  1687. /**
  1688. * Creates a new `QueryConstraint` that orders by value.
  1689. *
  1690. * If the children of a query are all scalar values (string, number, or
  1691. * boolean), you can order the results by their (ascending) values.
  1692. *
  1693. * You can read more about `orderByValue()` in
  1694. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sort_data | Sort data}.
  1695. */
  1696. export declare function orderByValue(): QueryConstraint;
  1697. /**
  1698. * @license
  1699. * Copyright 2017 Google LLC
  1700. *
  1701. * Licensed under the Apache License, Version 2.0 (the "License");
  1702. * you may not use this file except in compliance with the License.
  1703. * You may obtain a copy of the License at
  1704. *
  1705. * http://www.apache.org/licenses/LICENSE-2.0
  1706. *
  1707. * Unless required by applicable law or agreed to in writing, software
  1708. * distributed under the License is distributed on an "AS IS" BASIS,
  1709. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1710. * See the License for the specific language governing permissions and
  1711. * limitations under the License.
  1712. */
  1713. /**
  1714. * An immutable object representing a parsed path. It's immutable so that you
  1715. * can pass them around to other functions without worrying about them changing
  1716. * it.
  1717. */
  1718. declare class Path {
  1719. pieces_: string[];
  1720. pieceNum_: number;
  1721. /**
  1722. * @param pathOrString - Path string to parse, or another path, or the raw
  1723. * tokens array
  1724. */
  1725. constructor(pathOrString: string | string[], pieceNum?: number);
  1726. toString(): string;
  1727. }
  1728. /**
  1729. * Firebase connection. Abstracts wire protocol and handles reconnecting.
  1730. *
  1731. * NOTE: All JSON objects sent to the realtime connection must have property names enclosed
  1732. * in quotes to make sure the closure compiler does not minify them.
  1733. */
  1734. declare class PersistentConnection extends ServerActions {
  1735. private repoInfo_;
  1736. private applicationId_;
  1737. private onDataUpdate_;
  1738. private onConnectStatus_;
  1739. private onServerInfoUpdate_;
  1740. private authTokenProvider_;
  1741. private appCheckTokenProvider_;
  1742. private authOverride_?;
  1743. id: number;
  1744. private log_;
  1745. private interruptReasons_;
  1746. private readonly listens;
  1747. private outstandingPuts_;
  1748. private outstandingGets_;
  1749. private outstandingPutCount_;
  1750. private outstandingGetCount_;
  1751. private onDisconnectRequestQueue_;
  1752. private connected_;
  1753. private reconnectDelay_;
  1754. private maxReconnectDelay_;
  1755. private securityDebugCallback_;
  1756. lastSessionId: string | null;
  1757. private establishConnectionTimer_;
  1758. private visible_;
  1759. private requestCBHash_;
  1760. private requestNumber_;
  1761. private realtime_;
  1762. private authToken_;
  1763. private appCheckToken_;
  1764. private forceTokenRefresh_;
  1765. private invalidAuthTokenCount_;
  1766. private invalidAppCheckTokenCount_;
  1767. private firstConnection_;
  1768. private lastConnectionAttemptTime_;
  1769. private lastConnectionEstablishedTime_;
  1770. private static nextPersistentConnectionId_;
  1771. /**
  1772. * Counter for number of connections created. Mainly used for tagging in the logs
  1773. */
  1774. private static nextConnectionId_;
  1775. /**
  1776. * @param repoInfo_ - Data about the namespace we are connecting to
  1777. * @param applicationId_ - The Firebase App ID for this project
  1778. * @param onDataUpdate_ - A callback for new data from the server
  1779. */
  1780. constructor(repoInfo_: RepoInfo, applicationId_: string, onDataUpdate_: (a: string, b: unknown, c: boolean, d: number | null) => void, onConnectStatus_: (a: boolean) => void, onServerInfoUpdate_: (a: unknown) => void, authTokenProvider_: AuthTokenProvider, appCheckTokenProvider_: AppCheckTokenProvider, authOverride_?: object | null);
  1781. protected sendRequest(action: string, body: unknown, onResponse?: (a: unknown) => void): void;
  1782. get(query: QueryContext): Promise<string>;
  1783. listen(query: QueryContext, currentHashFn: () => string, tag: number | null, onComplete: (a: string, b: unknown) => void): void;
  1784. private sendGet_;
  1785. private sendListen_;
  1786. private static warnOnListenWarnings_;
  1787. refreshAuthToken(token: string): void;
  1788. private reduceReconnectDelayIfAdminCredential_;
  1789. refreshAppCheckToken(token: string | null): void;
  1790. /**
  1791. * Attempts to authenticate with the given credentials. If the authentication attempt fails, it's triggered like
  1792. * a auth revoked (the connection is closed).
  1793. */
  1794. tryAuth(): void;
  1795. /**
  1796. * Attempts to authenticate with the given token. If the authentication
  1797. * attempt fails, it's triggered like the token was revoked (the connection is
  1798. * closed).
  1799. */
  1800. tryAppCheck(): void;
  1801. /**
  1802. * @inheritDoc
  1803. */
  1804. unlisten(query: QueryContext, tag: number | null): void;
  1805. private sendUnlisten_;
  1806. onDisconnectPut(pathString: string, data: unknown, onComplete?: (a: string, b: string) => void): void;
  1807. onDisconnectMerge(pathString: string, data: unknown, onComplete?: (a: string, b: string) => void): void;
  1808. onDisconnectCancel(pathString: string, onComplete?: (a: string, b: string) => void): void;
  1809. private sendOnDisconnect_;
  1810. put(pathString: string, data: unknown, onComplete?: (a: string, b: string) => void, hash?: string): void;
  1811. merge(pathString: string, data: unknown, onComplete: (a: string, b: string | null) => void, hash?: string): void;
  1812. putInternal(action: string, pathString: string, data: unknown, onComplete: (a: string, b: string | null) => void, hash?: string): void;
  1813. private sendPut_;
  1814. reportStats(stats: {
  1815. [k: string]: unknown;
  1816. }): void;
  1817. private onDataMessage_;
  1818. private onDataPush_;
  1819. private onReady_;
  1820. private scheduleConnect_;
  1821. private initConnection_;
  1822. private onVisible_;
  1823. private onOnline_;
  1824. private onRealtimeDisconnect_;
  1825. private establishConnection_;
  1826. interrupt(reason: string): void;
  1827. resume(reason: string): void;
  1828. private handleTimestamp_;
  1829. private cancelSentTransactions_;
  1830. private onListenRevoked_;
  1831. private removeListen_;
  1832. private onAuthRevoked_;
  1833. private onAppCheckRevoked_;
  1834. private onSecurityDebugPacket_;
  1835. private restoreState_;
  1836. /**
  1837. * Sends client stats for first connection
  1838. */
  1839. private sendConnectStats_;
  1840. private shouldReconnect_;
  1841. }
  1842. declare class PriorityIndex extends Index {
  1843. compare(a: NamedNode, b: NamedNode): number;
  1844. isDefinedOn(node: Node_2): boolean;
  1845. indexedValueChanged(oldNode: Node_2, newNode: Node_2): boolean;
  1846. minPost(): NamedNode;
  1847. maxPost(): NamedNode;
  1848. makePost(indexValue: unknown, name: string): NamedNode;
  1849. /**
  1850. * @returns String representation for inclusion in a query spec
  1851. */
  1852. toString(): string;
  1853. }
  1854. /**
  1855. * Generates a new child location using a unique key and returns its
  1856. * `Reference`.
  1857. *
  1858. * This is the most common pattern for adding data to a collection of items.
  1859. *
  1860. * If you provide a value to `push()`, the value is written to the
  1861. * generated location. If you don't pass a value, nothing is written to the
  1862. * database and the child remains empty (but you can use the `Reference`
  1863. * elsewhere).
  1864. *
  1865. * The unique keys generated by `push()` are ordered by the current time, so the
  1866. * resulting list of items is chronologically sorted. The keys are also
  1867. * designed to be unguessable (they contain 72 random bits of entropy).
  1868. *
  1869. * See {@link https://firebase.google.com/docs/database/web/lists-of-data#append_to_a_list_of_data | Append to a list of data}.
  1870. * See {@link https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html | The 2^120 Ways to Ensure Unique Identifiers}.
  1871. *
  1872. * @param parent - The parent location.
  1873. * @param value - Optional value to be written at the generated location.
  1874. * @returns Combined `Promise` and `Reference`; resolves when write is complete,
  1875. * but can be used immediately as the `Reference` to the child location.
  1876. */
  1877. export declare function push(parent: DatabaseReference, value?: unknown): ThenableReference;
  1878. /**
  1879. * @license
  1880. * Copyright 2021 Google LLC
  1881. *
  1882. * Licensed under the Apache License, Version 2.0 (the "License");
  1883. * you may not use this file except in compliance with the License.
  1884. * You may obtain a copy of the License at
  1885. *
  1886. * http://www.apache.org/licenses/LICENSE-2.0
  1887. *
  1888. * Unless required by applicable law or agreed to in writing, software
  1889. * distributed under the License is distributed on an "AS IS" BASIS,
  1890. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1891. * See the License for the specific language governing permissions and
  1892. * limitations under the License.
  1893. */
  1894. /**
  1895. * A `Query` sorts and filters the data at a Database location so only a subset
  1896. * of the child data is included. This can be used to order a collection of
  1897. * data by some attribute (for example, height of dinosaurs) as well as to
  1898. * restrict a large list of items (for example, chat messages) down to a number
  1899. * suitable for synchronizing to the client. Queries are created by chaining
  1900. * together one or more of the filter methods defined here.
  1901. *
  1902. * Just as with a `DatabaseReference`, you can receive data from a `Query` by using the
  1903. * `on*()` methods. You will only receive events and `DataSnapshot`s for the
  1904. * subset of the data that matches your query.
  1905. *
  1906. * See {@link https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data}
  1907. * for more information.
  1908. */
  1909. export declare interface Query extends QueryContext {
  1910. /** The `DatabaseReference` for the `Query`'s location. */
  1911. readonly ref: DatabaseReference;
  1912. /**
  1913. * Returns whether or not the current and provided queries represent the same
  1914. * location, have the same query parameters, and are from the same instance of
  1915. * `FirebaseApp`.
  1916. *
  1917. * Two `DatabaseReference` objects are equivalent if they represent the same location
  1918. * and are from the same instance of `FirebaseApp`.
  1919. *
  1920. * Two `Query` objects are equivalent if they represent the same location,
  1921. * have the same query parameters, and are from the same instance of
  1922. * `FirebaseApp`. Equivalent queries share the same sort order, limits, and
  1923. * starting and ending points.
  1924. *
  1925. * @param other - The query to compare against.
  1926. * @returns Whether or not the current and provided queries are equivalent.
  1927. */
  1928. isEqual(other: Query | null): boolean;
  1929. /**
  1930. * Returns a JSON-serializable representation of this object.
  1931. *
  1932. * @returns A JSON-serializable representation of this object.
  1933. */
  1934. toJSON(): string;
  1935. /**
  1936. * Gets the absolute URL for this location.
  1937. *
  1938. * The `toString()` method returns a URL that is ready to be put into a
  1939. * browser, curl command, or a `refFromURL()` call. Since all of those expect
  1940. * the URL to be url-encoded, `toString()` returns an encoded URL.
  1941. *
  1942. * Append '.json' to the returned URL when typed into a browser to download
  1943. * JSON-formatted data. If the location is secured (that is, not publicly
  1944. * readable), you will get a permission-denied error.
  1945. *
  1946. * @returns The absolute URL for this location.
  1947. */
  1948. toString(): string;
  1949. }
  1950. /**
  1951. * Creates a new immutable instance of `Query` that is extended to also include
  1952. * additional query constraints.
  1953. *
  1954. * @param query - The Query instance to use as a base for the new constraints.
  1955. * @param queryConstraints - The list of `QueryConstraint`s to apply.
  1956. * @throws if any of the provided query constraints cannot be combined with the
  1957. * existing or new constraints.
  1958. */
  1959. export declare function query(query: Query, ...queryConstraints: QueryConstraint[]): Query;
  1960. /**
  1961. * A `QueryConstraint` is used to narrow the set of documents returned by a
  1962. * Database query. `QueryConstraint`s are created by invoking {@link endAt},
  1963. * {@link endBefore}, {@link startAt}, {@link startAfter}, {@link
  1964. * limitToFirst}, {@link limitToLast}, {@link orderByChild},
  1965. * {@link orderByChild}, {@link orderByKey} , {@link orderByPriority} ,
  1966. * {@link orderByValue} or {@link equalTo} and
  1967. * can then be passed to {@link query} to create a new query instance that
  1968. * also contains this `QueryConstraint`.
  1969. */
  1970. export declare abstract class QueryConstraint {
  1971. /** The type of this query constraints */
  1972. abstract readonly type: QueryConstraintType;
  1973. /**
  1974. * Takes the provided `Query` and returns a copy of the `Query` with this
  1975. * `QueryConstraint` applied.
  1976. */
  1977. abstract _apply<T>(query: _QueryImpl): _QueryImpl;
  1978. }
  1979. /** Describes the different query constraints available in this SDK. */
  1980. export declare type QueryConstraintType = 'endAt' | 'endBefore' | 'startAt' | 'startAfter' | 'limitToFirst' | 'limitToLast' | 'orderByChild' | 'orderByKey' | 'orderByPriority' | 'orderByValue' | 'equalTo';
  1981. declare interface QueryContext {
  1982. readonly _queryIdentifier: string;
  1983. readonly _queryObject: object;
  1984. readonly _repo: Repo;
  1985. readonly _path: Path;
  1986. readonly _queryParams: _QueryParams;
  1987. }
  1988. /* Excluded from this release type: _QueryImpl */
  1989. /* Excluded from this release type: _QueryParams */
  1990. /**
  1991. *
  1992. * Returns a `Reference` representing the location in the Database
  1993. * corresponding to the provided path. If no path is provided, the `Reference`
  1994. * will point to the root of the Database.
  1995. *
  1996. * @param db - The database instance to obtain a reference for.
  1997. * @param path - Optional path representing the location the returned
  1998. * `Reference` will point. If not provided, the returned `Reference` will
  1999. * point to the root of the Database.
  2000. * @returns If a path is provided, a `Reference`
  2001. * pointing to the provided path. Otherwise, a `Reference` pointing to the
  2002. * root of the Database.
  2003. */
  2004. export declare function ref(db: Database, path?: string): DatabaseReference;
  2005. /* Excluded from this release type: _ReferenceImpl */
  2006. /**
  2007. * Returns a `Reference` representing the location in the Database
  2008. * corresponding to the provided Firebase URL.
  2009. *
  2010. * An exception is thrown if the URL is not a valid Firebase Database URL or it
  2011. * has a different domain than the current `Database` instance.
  2012. *
  2013. * Note that all query parameters (`orderBy`, `limitToLast`, etc.) are ignored
  2014. * and are not applied to the returned `Reference`.
  2015. *
  2016. * @param db - The database instance to obtain a reference for.
  2017. * @param url - The Firebase URL at which the returned `Reference` will
  2018. * point.
  2019. * @returns A `Reference` pointing to the provided
  2020. * Firebase URL.
  2021. */
  2022. export declare function refFromURL(db: Database, url: string): DatabaseReference;
  2023. /**
  2024. * Removes the data at this Database location.
  2025. *
  2026. * Any data at child locations will also be deleted.
  2027. *
  2028. * The effect of the remove will be visible immediately and the corresponding
  2029. * event 'value' will be triggered. Synchronization of the remove to the
  2030. * Firebase servers will also be started, and the returned Promise will resolve
  2031. * when complete. If provided, the onComplete callback will be called
  2032. * asynchronously after synchronization has finished.
  2033. *
  2034. * @param ref - The location to remove.
  2035. * @returns Resolves when remove on server is complete.
  2036. */
  2037. export declare function remove(ref: DatabaseReference): Promise<void>;
  2038. /**
  2039. * A connection to a single data repository.
  2040. */
  2041. declare class Repo {
  2042. repoInfo_: RepoInfo;
  2043. forceRestClient_: boolean;
  2044. authTokenProvider_: AuthTokenProvider;
  2045. appCheckProvider_: AppCheckTokenProvider;
  2046. /** Key for uniquely identifying this repo, used in RepoManager */
  2047. readonly key: string;
  2048. dataUpdateCount: number;
  2049. infoSyncTree_: SyncTree;
  2050. serverSyncTree_: SyncTree;
  2051. stats_: StatsCollection;
  2052. statsListener_: StatsListener | null;
  2053. eventQueue_: EventQueue;
  2054. nextWriteId_: number;
  2055. server_: ServerActions;
  2056. statsReporter_: StatsReporter;
  2057. infoData_: SnapshotHolder;
  2058. interceptServerDataCallback_: ((a: string, b: unknown) => void) | null;
  2059. /** A list of data pieces and paths to be set when this client disconnects. */
  2060. onDisconnect_: SparseSnapshotTree;
  2061. /** Stores queues of outstanding transactions for Firebase locations. */
  2062. transactionQueueTree_: Tree<Transaction[]>;
  2063. persistentConnection_: PersistentConnection | null;
  2064. constructor(repoInfo_: RepoInfo, forceRestClient_: boolean, authTokenProvider_: AuthTokenProvider, appCheckProvider_: AppCheckTokenProvider);
  2065. /**
  2066. * @returns The URL corresponding to the root of this Firebase.
  2067. */
  2068. toString(): string;
  2069. }
  2070. /**
  2071. * @license
  2072. * Copyright 2017 Google LLC
  2073. *
  2074. * Licensed under the Apache License, Version 2.0 (the "License");
  2075. * you may not use this file except in compliance with the License.
  2076. * You may obtain a copy of the License at
  2077. *
  2078. * http://www.apache.org/licenses/LICENSE-2.0
  2079. *
  2080. * Unless required by applicable law or agreed to in writing, software
  2081. * distributed under the License is distributed on an "AS IS" BASIS,
  2082. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2083. * See the License for the specific language governing permissions and
  2084. * limitations under the License.
  2085. */
  2086. /**
  2087. * A class that holds metadata about a Repo object
  2088. */
  2089. declare class RepoInfo {
  2090. readonly secure: boolean;
  2091. readonly namespace: string;
  2092. readonly webSocketOnly: boolean;
  2093. readonly nodeAdmin: boolean;
  2094. readonly persistenceKey: string;
  2095. readonly includeNamespaceInQueryParams: boolean;
  2096. private _host;
  2097. private _domain;
  2098. internalHost: string;
  2099. /**
  2100. * @param host - Hostname portion of the url for the repo
  2101. * @param secure - Whether or not this repo is accessed over ssl
  2102. * @param namespace - The namespace represented by the repo
  2103. * @param webSocketOnly - Whether to prefer websockets over all other transports (used by Nest).
  2104. * @param nodeAdmin - Whether this instance uses Admin SDK credentials
  2105. * @param persistenceKey - Override the default session persistence storage key
  2106. */
  2107. constructor(host: string, secure: boolean, namespace: string, webSocketOnly: boolean, nodeAdmin?: boolean, persistenceKey?: string, includeNamespaceInQueryParams?: boolean);
  2108. isCacheableHost(): boolean;
  2109. isCustomHost(): boolean;
  2110. get host(): string;
  2111. set host(newHost: string);
  2112. toString(): string;
  2113. toURLString(): string;
  2114. }
  2115. /* Excluded from this release type: _repoManagerDatabaseFromApp */
  2116. /**
  2117. * Atomically modifies the data at this location.
  2118. *
  2119. * Atomically modify the data at this location. Unlike a normal `set()`, which
  2120. * just overwrites the data regardless of its previous value, `runTransaction()` is
  2121. * used to modify the existing value to a new value, ensuring there are no
  2122. * conflicts with other clients writing to the same location at the same time.
  2123. *
  2124. * To accomplish this, you pass `runTransaction()` an update function which is
  2125. * used to transform the current value into a new value. If another client
  2126. * writes to the location before your new value is successfully written, your
  2127. * update function will be called again with the new current value, and the
  2128. * write will be retried. This will happen repeatedly until your write succeeds
  2129. * without conflict or you abort the transaction by not returning a value from
  2130. * your update function.
  2131. *
  2132. * Note: Modifying data with `set()` will cancel any pending transactions at
  2133. * that location, so extreme care should be taken if mixing `set()` and
  2134. * `runTransaction()` to update the same data.
  2135. *
  2136. * Note: When using transactions with Security and Firebase Rules in place, be
  2137. * aware that a client needs `.read` access in addition to `.write` access in
  2138. * order to perform a transaction. This is because the client-side nature of
  2139. * transactions requires the client to read the data in order to transactionally
  2140. * update it.
  2141. *
  2142. * @param ref - The location to atomically modify.
  2143. * @param transactionUpdate - A developer-supplied function which will be passed
  2144. * the current data stored at this location (as a JavaScript object). The
  2145. * function should return the new value it would like written (as a JavaScript
  2146. * object). If `undefined` is returned (i.e. you return with no arguments) the
  2147. * transaction will be aborted and the data at this location will not be
  2148. * modified.
  2149. * @param options - An options object to configure transactions.
  2150. * @returns A `Promise` that can optionally be used instead of the `onComplete`
  2151. * callback to handle success and failure.
  2152. */
  2153. export declare function runTransaction(ref: DatabaseReference, transactionUpdate: (currentData: any) => unknown, options?: TransactionOptions): Promise<TransactionResult>;
  2154. /**
  2155. * Interface defining the set of actions that can be performed against the Firebase server
  2156. * (basically corresponds to our wire protocol).
  2157. *
  2158. * @interface
  2159. */
  2160. declare abstract class ServerActions {
  2161. abstract listen(query: QueryContext, currentHashFn: () => string, tag: number | null, onComplete: (a: string, b: unknown) => void): void;
  2162. /**
  2163. * Remove a listen.
  2164. */
  2165. abstract unlisten(query: QueryContext, tag: number | null): void;
  2166. /**
  2167. * Get the server value satisfying this query.
  2168. */
  2169. abstract get(query: QueryContext): Promise<string>;
  2170. put(pathString: string, data: unknown, onComplete?: (a: string, b: string) => void, hash?: string): void;
  2171. merge(pathString: string, data: unknown, onComplete: (a: string, b: string | null) => void, hash?: string): void;
  2172. /**
  2173. * Refreshes the auth token for the current connection.
  2174. * @param token - The authentication token
  2175. */
  2176. refreshAuthToken(token: string): void;
  2177. /**
  2178. * Refreshes the app check token for the current connection.
  2179. * @param token The app check token
  2180. */
  2181. refreshAppCheckToken(token: string): void;
  2182. onDisconnectPut(pathString: string, data: unknown, onComplete?: (a: string, b: string) => void): void;
  2183. onDisconnectMerge(pathString: string, data: unknown, onComplete?: (a: string, b: string) => void): void;
  2184. onDisconnectCancel(pathString: string, onComplete?: (a: string, b: string) => void): void;
  2185. reportStats(stats: {
  2186. [k: string]: unknown;
  2187. }): void;
  2188. }
  2189. /**
  2190. * @license
  2191. * Copyright 2020 Google LLC
  2192. *
  2193. * Licensed under the Apache License, Version 2.0 (the "License");
  2194. * you may not use this file except in compliance with the License.
  2195. * You may obtain a copy of the License at
  2196. *
  2197. * http://www.apache.org/licenses/LICENSE-2.0
  2198. *
  2199. * Unless required by applicable law or agreed to in writing, software
  2200. * distributed under the License is distributed on an "AS IS" BASIS,
  2201. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2202. * See the License for the specific language governing permissions and
  2203. * limitations under the License.
  2204. */
  2205. /**
  2206. * Returns a placeholder value for auto-populating the current timestamp (time
  2207. * since the Unix epoch, in milliseconds) as determined by the Firebase
  2208. * servers.
  2209. */
  2210. export declare function serverTimestamp(): object;
  2211. /**
  2212. * Writes data to this Database location.
  2213. *
  2214. * This will overwrite any data at this location and all child locations.
  2215. *
  2216. * The effect of the write will be visible immediately, and the corresponding
  2217. * events ("value", "child_added", etc.) will be triggered. Synchronization of
  2218. * the data to the Firebase servers will also be started, and the returned
  2219. * Promise will resolve when complete. If provided, the `onComplete` callback
  2220. * will be called asynchronously after synchronization has finished.
  2221. *
  2222. * Passing `null` for the new value is equivalent to calling `remove()`; namely,
  2223. * all data at this location and all child locations will be deleted.
  2224. *
  2225. * `set()` will remove any priority stored at this location, so if priority is
  2226. * meant to be preserved, you need to use `setWithPriority()` instead.
  2227. *
  2228. * Note that modifying data with `set()` will cancel any pending transactions
  2229. * at that location, so extreme care should be taken if mixing `set()` and
  2230. * `transaction()` to modify the same data.
  2231. *
  2232. * A single `set()` will generate a single "value" event at the location where
  2233. * the `set()` was performed.
  2234. *
  2235. * @param ref - The location to write to.
  2236. * @param value - The value to be written (string, number, boolean, object,
  2237. * array, or null).
  2238. * @returns Resolves when write to server is complete.
  2239. */
  2240. export declare function set(ref: DatabaseReference, value: unknown): Promise<void>;
  2241. /**
  2242. * Sets a priority for the data at this Database location.
  2243. *
  2244. * Applications need not use priority but can order collections by
  2245. * ordinary properties (see
  2246. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data | Sorting and filtering data}
  2247. * ).
  2248. *
  2249. * @param ref - The location to write to.
  2250. * @param priority - The priority to be written (string, number, or null).
  2251. * @returns Resolves when write to server is complete.
  2252. */
  2253. export declare function setPriority(ref: DatabaseReference, priority: string | number | null): Promise<void>;
  2254. /* Excluded from this release type: _setSDKVersion */
  2255. /**
  2256. * Writes data the Database location. Like `set()` but also specifies the
  2257. * priority for that data.
  2258. *
  2259. * Applications need not use priority but can order collections by
  2260. * ordinary properties (see
  2261. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data | Sorting and filtering data}
  2262. * ).
  2263. *
  2264. * @param ref - The location to write to.
  2265. * @param value - The value to be written (string, number, boolean, object,
  2266. * array, or null).
  2267. * @param priority - The priority to be written (string, number, or null).
  2268. * @returns Resolves when write to server is complete.
  2269. */
  2270. export declare function setWithPriority(ref: DatabaseReference, value: unknown, priority: string | number | null): Promise<void>;
  2271. /**
  2272. * Mutable object which basically just stores a reference to the "latest" immutable snapshot.
  2273. */
  2274. declare class SnapshotHolder {
  2275. private rootNode_;
  2276. getNode(path: Path): Node_2;
  2277. updateSnapshot(path: Path, newSnapshotNode: Node_2): void;
  2278. }
  2279. /**
  2280. * An immutable sorted map implementation, based on a Left-leaning Red-Black
  2281. * tree.
  2282. */
  2283. declare class SortedMap<K, V> {
  2284. private comparator_;
  2285. private root_;
  2286. /**
  2287. * Always use the same empty node, to reduce memory.
  2288. */
  2289. static EMPTY_NODE: LLRBEmptyNode<unknown, unknown>;
  2290. /**
  2291. * @param comparator_ - Key comparator.
  2292. * @param root_ - Optional root node for the map.
  2293. */
  2294. constructor(comparator_: Comparator<K>, root_?: LLRBNode<K, V> | LLRBEmptyNode<K, V>);
  2295. /**
  2296. * Returns a copy of the map, with the specified key/value added or replaced.
  2297. * (TODO: We should perhaps rename this method to 'put')
  2298. *
  2299. * @param key - Key to be added.
  2300. * @param value - Value to be added.
  2301. * @returns New map, with item added.
  2302. */
  2303. insert(key: K, value: V): SortedMap<K, V>;
  2304. /**
  2305. * Returns a copy of the map, with the specified key removed.
  2306. *
  2307. * @param key - The key to remove.
  2308. * @returns New map, with item removed.
  2309. */
  2310. remove(key: K): SortedMap<K, V>;
  2311. /**
  2312. * Returns the value of the node with the given key, or null.
  2313. *
  2314. * @param key - The key to look up.
  2315. * @returns The value of the node with the given key, or null if the
  2316. * key doesn't exist.
  2317. */
  2318. get(key: K): V | null;
  2319. /**
  2320. * Returns the key of the item *before* the specified key, or null if key is the first item.
  2321. * @param key - The key to find the predecessor of
  2322. * @returns The predecessor key.
  2323. */
  2324. getPredecessorKey(key: K): K | null;
  2325. /**
  2326. * @returns True if the map is empty.
  2327. */
  2328. isEmpty(): boolean;
  2329. /**
  2330. * @returns The total number of nodes in the map.
  2331. */
  2332. count(): number;
  2333. /**
  2334. * @returns The minimum key in the map.
  2335. */
  2336. minKey(): K | null;
  2337. /**
  2338. * @returns The maximum key in the map.
  2339. */
  2340. maxKey(): K | null;
  2341. /**
  2342. * Traverses the map in key order and calls the specified action function
  2343. * for each key/value pair.
  2344. *
  2345. * @param action - Callback function to be called
  2346. * for each key/value pair. If action returns true, traversal is aborted.
  2347. * @returns The first truthy value returned by action, or the last falsey
  2348. * value returned by action
  2349. */
  2350. inorderTraversal(action: (k: K, v: V) => unknown): boolean;
  2351. /**
  2352. * Traverses the map in reverse key order and calls the specified action function
  2353. * for each key/value pair.
  2354. *
  2355. * @param action - Callback function to be called
  2356. * for each key/value pair. If action returns true, traversal is aborted.
  2357. * @returns True if the traversal was aborted.
  2358. */
  2359. reverseTraversal(action: (k: K, v: V) => void): boolean;
  2360. /**
  2361. * Returns an iterator over the SortedMap.
  2362. * @returns The iterator.
  2363. */
  2364. getIterator<T>(resultGenerator?: (k: K, v: V) => T): SortedMapIterator<K, V, T>;
  2365. getIteratorFrom<T>(key: K, resultGenerator?: (k: K, v: V) => T): SortedMapIterator<K, V, T>;
  2366. getReverseIteratorFrom<T>(key: K, resultGenerator?: (k: K, v: V) => T): SortedMapIterator<K, V, T>;
  2367. getReverseIterator<T>(resultGenerator?: (k: K, v: V) => T): SortedMapIterator<K, V, T>;
  2368. }
  2369. /**
  2370. * An iterator over an LLRBNode.
  2371. */
  2372. declare class SortedMapIterator<K, V, T> {
  2373. private isReverse_;
  2374. private resultGenerator_;
  2375. private nodeStack_;
  2376. /**
  2377. * @param node - Node to iterate.
  2378. * @param isReverse_ - Whether or not to iterate in reverse
  2379. */
  2380. constructor(node: LLRBNode<K, V> | LLRBEmptyNode<K, V>, startKey: K | null, comparator: Comparator<K>, isReverse_: boolean, resultGenerator_?: ((k: K, v: V) => T) | null);
  2381. getNext(): T;
  2382. hasNext(): boolean;
  2383. peek(): T;
  2384. }
  2385. /**
  2386. * Helper class to store a sparse set of snapshots.
  2387. */
  2388. declare interface SparseSnapshotTree {
  2389. value: Node_2 | null;
  2390. readonly children: Map<string, SparseSnapshotTree>;
  2391. }
  2392. /**
  2393. * Creates a `QueryConstraint` with the specified starting point (exclusive).
  2394. *
  2395. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  2396. * allows you to choose arbitrary starting and ending points for your queries.
  2397. *
  2398. * The starting point is exclusive. If only a value is provided, children
  2399. * with a value greater than the specified value will be included in the query.
  2400. * If a key is specified, then children must have a value greater than or equal
  2401. * to the specified value and a a key name greater than the specified key.
  2402. *
  2403. * @param value - The value to start after. The argument type depends on which
  2404. * `orderBy*()` function was used in this query. Specify a value that matches
  2405. * the `orderBy*()` type. When used in combination with `orderByKey()`, the
  2406. * value must be a string.
  2407. * @param key - The child key to start after. This argument is only allowed if
  2408. * ordering by child, value, or priority.
  2409. */
  2410. export declare function startAfter(value: number | string | boolean | null, key?: string): QueryConstraint;
  2411. /**
  2412. * Creates a `QueryConstraint` with the specified starting point.
  2413. *
  2414. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  2415. * allows you to choose arbitrary starting and ending points for your queries.
  2416. *
  2417. * The starting point is inclusive, so children with exactly the specified value
  2418. * will be included in the query. The optional key argument can be used to
  2419. * further limit the range of the query. If it is specified, then children that
  2420. * have exactly the specified value must also have a key name greater than or
  2421. * equal to the specified key.
  2422. *
  2423. * You can read more about `startAt()` in
  2424. * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
  2425. *
  2426. * @param value - The value to start at. The argument type depends on which
  2427. * `orderBy*()` function was used in this query. Specify a value that matches
  2428. * the `orderBy*()` type. When used in combination with `orderByKey()`, the
  2429. * value must be a string.
  2430. * @param key - The child key to start at. This argument is only allowed if
  2431. * ordering by child, value, or priority.
  2432. */
  2433. export declare function startAt(value?: number | string | boolean | null, key?: string): QueryConstraint;
  2434. /**
  2435. * @license
  2436. * Copyright 2017 Google LLC
  2437. *
  2438. * Licensed under the Apache License, Version 2.0 (the "License");
  2439. * you may not use this file except in compliance with the License.
  2440. * You may obtain a copy of the License at
  2441. *
  2442. * http://www.apache.org/licenses/LICENSE-2.0
  2443. *
  2444. * Unless required by applicable law or agreed to in writing, software
  2445. * distributed under the License is distributed on an "AS IS" BASIS,
  2446. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2447. * See the License for the specific language governing permissions and
  2448. * limitations under the License.
  2449. */
  2450. /**
  2451. * Tracks a collection of stats.
  2452. */
  2453. declare class StatsCollection {
  2454. private counters_;
  2455. incrementCounter(name: string, amount?: number): void;
  2456. get(): {
  2457. [k: string]: number;
  2458. };
  2459. }
  2460. /**
  2461. * Returns the delta from the previous call to get stats.
  2462. *
  2463. * @param collection_ - The collection to "listen" to.
  2464. */
  2465. declare class StatsListener {
  2466. private collection_;
  2467. private last_;
  2468. constructor(collection_: StatsCollection);
  2469. get(): {
  2470. [k: string]: number;
  2471. };
  2472. }
  2473. declare class StatsReporter {
  2474. private server_;
  2475. private statsListener_;
  2476. statsToReport_: {
  2477. [k: string]: boolean;
  2478. };
  2479. constructor(collection: StatsCollection, server_: ServerActions);
  2480. private reportStats_;
  2481. }
  2482. /**
  2483. * SyncPoint represents a single location in a SyncTree with 1 or more event registrations, meaning we need to
  2484. * maintain 1 or more Views at this location to cache server data and raise appropriate events for server changes
  2485. * and user writes (set, transaction, update).
  2486. *
  2487. * It's responsible for:
  2488. * - Maintaining the set of 1 or more views necessary at this location (a SyncPoint with 0 views should be removed).
  2489. * - Proxying user / server operations to the views as appropriate (i.e. applyServerOverwrite,
  2490. * applyUserOverwrite, etc.)
  2491. */
  2492. declare class SyncPoint {
  2493. /**
  2494. * The Views being tracked at this location in the tree, stored as a map where the key is a
  2495. * queryId and the value is the View for that query.
  2496. *
  2497. * NOTE: This list will be quite small (usually 1, but perhaps 2 or 3; any more is an odd use case).
  2498. */
  2499. readonly views: Map<string, View>;
  2500. }
  2501. /**
  2502. * SyncTree is the central class for managing event callback registration, data caching, views
  2503. * (query processing), and event generation. There are typically two SyncTree instances for
  2504. * each Repo, one for the normal Firebase data, and one for the .info data.
  2505. *
  2506. * It has a number of responsibilities, including:
  2507. * - Tracking all user event callbacks (registered via addEventRegistration() and removeEventRegistration()).
  2508. * - Applying and caching data changes for user set(), transaction(), and update() calls
  2509. * (applyUserOverwrite(), applyUserMerge()).
  2510. * - Applying and caching data changes for server data changes (applyServerOverwrite(),
  2511. * applyServerMerge()).
  2512. * - Generating user-facing events for server and user changes (all of the apply* methods
  2513. * return the set of events that need to be raised as a result).
  2514. * - Maintaining the appropriate set of server listens to ensure we are always subscribed
  2515. * to the correct set of paths and queries to satisfy the current set of user event
  2516. * callbacks (listens are started/stopped using the provided listenProvider).
  2517. *
  2518. * NOTE: Although SyncTree tracks event callbacks and calculates events to raise, the actual
  2519. * events are returned to the caller rather than raised synchronously.
  2520. *
  2521. */
  2522. declare class SyncTree {
  2523. listenProvider_: ListenProvider;
  2524. /**
  2525. * Tree of SyncPoints. There's a SyncPoint at any location that has 1 or more views.
  2526. */
  2527. syncPointTree_: ImmutableTree<SyncPoint>;
  2528. /**
  2529. * A tree of all pending user writes (user-initiated set()'s, transaction()'s, update()'s, etc.).
  2530. */
  2531. pendingWriteTree_: WriteTree;
  2532. readonly tagToQueryMap: Map<number, string>;
  2533. readonly queryToTagMap: Map<string, number>;
  2534. /**
  2535. * @param listenProvider_ - Used by SyncTree to start / stop listening
  2536. * to server data.
  2537. */
  2538. constructor(listenProvider_: ListenProvider);
  2539. }
  2540. /* Excluded from this release type: _TEST_ACCESS_forceRestClient */
  2541. /* Excluded from this release type: _TEST_ACCESS_hijackHash */
  2542. /**
  2543. * A `Promise` that can also act as a `DatabaseReference` when returned by
  2544. * {@link push}. The reference is available immediately and the `Promise` resolves
  2545. * as the write to the backend completes.
  2546. */
  2547. export declare interface ThenableReference extends DatabaseReference, Pick<Promise<DatabaseReference>, 'then' | 'catch'> {
  2548. }
  2549. declare interface Transaction {
  2550. path: Path;
  2551. update: (a: unknown) => unknown;
  2552. onComplete: (error: Error | null, committed: boolean, node: Node_2 | null) => void;
  2553. status: TransactionStatus;
  2554. order: number;
  2555. applyLocally: boolean;
  2556. retryCount: number;
  2557. unwatcher: () => void;
  2558. abortReason: string | null;
  2559. currentWriteId: number;
  2560. currentInputSnapshot: Node_2 | null;
  2561. currentOutputSnapshotRaw: Node_2 | null;
  2562. currentOutputSnapshotResolved: Node_2 | null;
  2563. }
  2564. /** An options object to configure transactions. */
  2565. export declare interface TransactionOptions {
  2566. /**
  2567. * By default, events are raised each time the transaction update function
  2568. * runs. So if it is run multiple times, you may see intermediate states. You
  2569. * can set this to false to suppress these intermediate states and instead
  2570. * wait until the transaction has completed before events are raised.
  2571. */
  2572. readonly applyLocally?: boolean;
  2573. }
  2574. /**
  2575. * A type for the resolve value of {@link runTransaction}.
  2576. */
  2577. export declare class TransactionResult {
  2578. /** Whether the transaction was successfully committed. */
  2579. readonly committed: boolean;
  2580. /** The resulting data snapshot. */
  2581. readonly snapshot: DataSnapshot;
  2582. /** @hideconstructor */
  2583. constructor(
  2584. /** Whether the transaction was successfully committed. */
  2585. committed: boolean,
  2586. /** The resulting data snapshot. */
  2587. snapshot: DataSnapshot);
  2588. /** Returns a JSON-serializable representation of this object. */
  2589. toJSON(): object;
  2590. }
  2591. declare const enum TransactionStatus {
  2592. RUN = 0,
  2593. SENT = 1,
  2594. COMPLETED = 2,
  2595. SENT_NEEDS_ABORT = 3,
  2596. NEEDS_ABORT = 4
  2597. }
  2598. /**
  2599. * A light-weight tree, traversable by path. Nodes can have both values and children.
  2600. * Nodes are not enumerated (by forEachChild) unless they have a value or non-empty
  2601. * children.
  2602. */
  2603. declare class Tree<T> {
  2604. readonly name: string;
  2605. readonly parent: Tree<T> | null;
  2606. node: TreeNode<T>;
  2607. /**
  2608. * @param name - Optional name of the node.
  2609. * @param parent - Optional parent node.
  2610. * @param node - Optional node to wrap.
  2611. */
  2612. constructor(name?: string, parent?: Tree<T> | null, node?: TreeNode<T>);
  2613. }
  2614. /**
  2615. * Node in a Tree.
  2616. */
  2617. declare interface TreeNode<T> {
  2618. children: Record<string, TreeNode<T>>;
  2619. childCount: number;
  2620. value?: T;
  2621. }
  2622. /** A callback that can invoked to remove a listener. */
  2623. export declare type Unsubscribe = () => void;
  2624. /**
  2625. * Writes multiple values to the Database at once.
  2626. *
  2627. * The `values` argument contains multiple property-value pairs that will be
  2628. * written to the Database together. Each child property can either be a simple
  2629. * property (for example, "name") or a relative path (for example,
  2630. * "name/first") from the current location to the data to update.
  2631. *
  2632. * As opposed to the `set()` method, `update()` can be use to selectively update
  2633. * only the referenced properties at the current location (instead of replacing
  2634. * all the child properties at the current location).
  2635. *
  2636. * The effect of the write will be visible immediately, and the corresponding
  2637. * events ('value', 'child_added', etc.) will be triggered. Synchronization of
  2638. * the data to the Firebase servers will also be started, and the returned
  2639. * Promise will resolve when complete. If provided, the `onComplete` callback
  2640. * will be called asynchronously after synchronization has finished.
  2641. *
  2642. * A single `update()` will generate a single "value" event at the location
  2643. * where the `update()` was performed, regardless of how many children were
  2644. * modified.
  2645. *
  2646. * Note that modifying data with `update()` will cancel any pending
  2647. * transactions at that location, so extreme care should be taken if mixing
  2648. * `update()` and `transaction()` to modify the same data.
  2649. *
  2650. * Passing `null` to `update()` will remove the data at this location.
  2651. *
  2652. * See
  2653. * {@link https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html | Introducing multi-location updates and more}.
  2654. *
  2655. * @param ref - The location to write to.
  2656. * @param values - Object containing multiple values.
  2657. * @returns Resolves when update on server is complete.
  2658. */
  2659. export declare function update(ref: DatabaseReference, values: object): Promise<void>;
  2660. /* Excluded from this release type: _UserCallback */
  2661. /* Excluded from this release type: _validatePathString */
  2662. /* Excluded from this release type: _validateWritablePath */
  2663. /**
  2664. * A view represents a specific location and query that has 1 or more event registrations.
  2665. *
  2666. * It does several things:
  2667. * - Maintains the list of event registrations for this location/query.
  2668. * - Maintains a cache of the data visible for this location/query.
  2669. * - Applies new operations (via applyOperation), updates the cache, and based on the event
  2670. * registrations returns the set of events to be raised.
  2671. */
  2672. declare class View {
  2673. private query_;
  2674. processor_: ViewProcessor;
  2675. viewCache_: ViewCache;
  2676. eventRegistrations_: EventRegistration[];
  2677. eventGenerator_: EventGenerator;
  2678. constructor(query_: QueryContext, initialViewCache: ViewCache);
  2679. get query(): QueryContext;
  2680. }
  2681. /**
  2682. * Stores the data we have cached for a view.
  2683. *
  2684. * serverSnap is the cached server data, eventSnap is the cached event data (server data plus any local writes).
  2685. */
  2686. declare interface ViewCache {
  2687. readonly eventCache: CacheNode;
  2688. readonly serverCache: CacheNode;
  2689. }
  2690. declare interface ViewProcessor {
  2691. readonly filter: NodeFilter_2;
  2692. }
  2693. /**
  2694. * Defines a single user-initiated write operation. May be the result of a set(), transaction(), or update() call. In
  2695. * the case of a set() or transaction, snap wil be non-null. In the case of an update(), children will be non-null.
  2696. */
  2697. declare interface WriteRecord {
  2698. writeId: number;
  2699. path: Path;
  2700. snap?: Node_2 | null;
  2701. children?: {
  2702. [k: string]: Node_2;
  2703. } | null;
  2704. visible: boolean;
  2705. }
  2706. /**
  2707. * WriteTree tracks all pending user-initiated writes and has methods to calculate the result of merging them
  2708. * with underlying server data (to create "event cache" data). Pending writes are added with addOverwrite()
  2709. * and addMerge(), and removed with removeWrite().
  2710. */
  2711. declare interface WriteTree {
  2712. /**
  2713. * A tree tracking the result of applying all visible writes. This does not include transactions with
  2714. * applyLocally=false or writes that are completely shadowed by other writes.
  2715. */
  2716. visibleWrites: CompoundWrite;
  2717. /**
  2718. * A list of all pending writes, regardless of visibility and shadowed-ness. Used to calculate arbitrary
  2719. * sets of the changed data, such as hidden writes (from transactions) or changes with certain writes excluded (also
  2720. * used by transactions).
  2721. */
  2722. allWrites: WriteRecord[];
  2723. lastWriteId: number;
  2724. }
  2725. export { }