Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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