internal.d.ts 122 KB

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