public.d.ts 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  1. /**
  2. * Firebase Realtime Database
  3. *
  4. * @packageDocumentation
  5. */
  6. import { FirebaseApp } from '@firebase/app';
  7. import { EmulatorMockTokenOptions } from '@firebase/util';
  8. /**
  9. * Gets a `Reference` for the location at the specified relative path.
  10. *
  11. * The relative path can either be a simple child name (for example, "ada") or
  12. * a deeper slash-separated path (for example, "ada/name/first").
  13. *
  14. * @param parent - The parent location.
  15. * @param path - A relative path from this location to the desired child
  16. * location.
  17. * @returns The specified child location.
  18. */
  19. export declare function child(parent: DatabaseReference, path: string): DatabaseReference;
  20. /**
  21. * Modify the provided instance to communicate with the Realtime Database
  22. * emulator.
  23. *
  24. * <p>Note: This method must be called before performing any other operation.
  25. *
  26. * @param db - The instance to modify.
  27. * @param host - The emulator host (ex: localhost)
  28. * @param port - The emulator port (ex: 8080)
  29. * @param options.mockUserToken - the mock auth token to use for unit testing Security Rules
  30. */
  31. export declare function connectDatabaseEmulator(db: Database, host: string, port: number, options?: {
  32. mockUserToken?: EmulatorMockTokenOptions | string;
  33. }): void;
  34. /**
  35. * Class representing a Firebase Realtime Database.
  36. */
  37. export declare class Database {
  38. /** The {@link @firebase/app#FirebaseApp} associated with this Realtime Database instance. */
  39. readonly app: FirebaseApp;
  40. /** Represents a `Database` instance. */
  41. readonly 'type' = "database";
  42. private constructor();
  43. }
  44. /**
  45. * A `DatabaseReference` represents a specific location in your Database and can be used
  46. * for reading or writing data to that Database location.
  47. *
  48. * You can reference the root or child location in your Database by calling
  49. * `ref()` or `ref("child/path")`.
  50. *
  51. * Writing is done with the `set()` method and reading can be done with the
  52. * `on*()` method. See {@link
  53. * https://firebase.google.com/docs/database/web/read-and-write}
  54. */
  55. export declare interface DatabaseReference extends Query {
  56. /**
  57. * The last part of the `DatabaseReference`'s path.
  58. *
  59. * For example, `"ada"` is the key for
  60. * `https://<DATABASE_NAME>.firebaseio.com/users/ada`.
  61. *
  62. * The key of a root `DatabaseReference` is `null`.
  63. */
  64. readonly key: string | null;
  65. /**
  66. * The parent location of a `DatabaseReference`.
  67. *
  68. * The parent of a root `DatabaseReference` is `null`.
  69. */
  70. readonly parent: DatabaseReference | null;
  71. /** The root `DatabaseReference` of the Database. */
  72. readonly root: DatabaseReference;
  73. }
  74. /**
  75. * A `DataSnapshot` contains data from a Database location.
  76. *
  77. * Any time you read data from the Database, you receive the data as a
  78. * `DataSnapshot`. A `DataSnapshot` is passed to the event callbacks you attach
  79. * with `on()` or `once()`. You can extract the contents of the snapshot as a
  80. * JavaScript object by calling the `val()` method. Alternatively, you can
  81. * traverse into the snapshot by calling `child()` to return child snapshots
  82. * (which you could then call `val()` on).
  83. *
  84. * A `DataSnapshot` is an efficiently generated, immutable copy of the data at
  85. * a Database location. It cannot be modified and will never change (to modify
  86. * data, you always call the `set()` method on a `Reference` directly).
  87. */
  88. export declare class DataSnapshot {
  89. /**
  90. * The location of this DataSnapshot.
  91. */
  92. readonly ref: DatabaseReference;
  93. private constructor();
  94. /**
  95. * Gets the priority value of the data in this `DataSnapshot`.
  96. *
  97. * Applications need not use priority but can order collections by
  98. * ordinary properties (see
  99. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data |Sorting and filtering data}
  100. * ).
  101. */
  102. get priority(): string | number | null;
  103. /**
  104. * The key (last part of the path) of the location of this `DataSnapshot`.
  105. *
  106. * The last token in a Database location is considered its key. For example,
  107. * "ada" is the key for the /users/ada/ node. Accessing the key on any
  108. * `DataSnapshot` will return the key for the location that generated it.
  109. * However, accessing the key on the root URL of a Database will return
  110. * `null`.
  111. */
  112. get key(): string | null;
  113. /** Returns the number of child properties of this `DataSnapshot`. */
  114. get size(): number;
  115. /**
  116. * Gets another `DataSnapshot` for the location at the specified relative path.
  117. *
  118. * Passing a relative path to the `child()` method of a DataSnapshot returns
  119. * another `DataSnapshot` for the location at the specified relative path. The
  120. * relative path can either be a simple child name (for example, "ada") or a
  121. * deeper, slash-separated path (for example, "ada/name/first"). If the child
  122. * location has no data, an empty `DataSnapshot` (that is, a `DataSnapshot`
  123. * whose value is `null`) is returned.
  124. *
  125. * @param path - A relative path to the location of child data.
  126. */
  127. child(path: string): DataSnapshot;
  128. /**
  129. * Returns true if this `DataSnapshot` contains any data. It is slightly more
  130. * efficient than using `snapshot.val() !== null`.
  131. */
  132. exists(): boolean;
  133. /**
  134. * Exports the entire contents of the DataSnapshot as a JavaScript object.
  135. *
  136. * The `exportVal()` method is similar to `val()`, except priority information
  137. * is included (if available), making it suitable for backing up your data.
  138. *
  139. * @returns The DataSnapshot's contents as a JavaScript value (Object,
  140. * Array, string, number, boolean, or `null`).
  141. */
  142. exportVal(): any;
  143. /**
  144. * Enumerates the top-level children in the `IteratedDataSnapshot`.
  145. *
  146. * Because of the way JavaScript objects work, the ordering of data in the
  147. * JavaScript object returned by `val()` is not guaranteed to match the
  148. * ordering on the server nor the ordering of `onChildAdded()` events. That is
  149. * where `forEach()` comes in handy. It guarantees the children of a
  150. * `DataSnapshot` will be iterated in their query order.
  151. *
  152. * If no explicit `orderBy*()` method is used, results are returned
  153. * ordered by key (unless priorities are used, in which case, results are
  154. * returned by priority).
  155. *
  156. * @param action - A function that will be called for each child DataSnapshot.
  157. * The callback can return true to cancel further enumeration.
  158. * @returns true if enumeration was canceled due to your callback returning
  159. * true.
  160. */
  161. forEach(action: (child: IteratedDataSnapshot) => boolean | void): boolean;
  162. /**
  163. * Returns true if the specified child path has (non-null) data.
  164. *
  165. * @param path - A relative path to the location of a potential child.
  166. * @returns `true` if data exists at the specified child path; else
  167. * `false`.
  168. */
  169. hasChild(path: string): boolean;
  170. /**
  171. * Returns whether or not the `DataSnapshot` has any non-`null` child
  172. * properties.
  173. *
  174. * You can use `hasChildren()` to determine if a `DataSnapshot` has any
  175. * children. If it does, you can enumerate them using `forEach()`. If it
  176. * doesn't, then either this snapshot contains a primitive value (which can be
  177. * retrieved with `val()`) or it is empty (in which case, `val()` will return
  178. * `null`).
  179. *
  180. * @returns true if this snapshot has any children; else false.
  181. */
  182. hasChildren(): boolean;
  183. /**
  184. * Returns a JSON-serializable representation of this object.
  185. */
  186. toJSON(): object | null;
  187. /**
  188. * Extracts a JavaScript value from a `DataSnapshot`.
  189. *
  190. * Depending on the data in a `DataSnapshot`, the `val()` method may return a
  191. * scalar type (string, number, or boolean), an array, or an object. It may
  192. * also return null, indicating that the `DataSnapshot` is empty (contains no
  193. * data).
  194. *
  195. * @returns The DataSnapshot's contents as a JavaScript value (Object,
  196. * Array, string, number, boolean, or `null`).
  197. */
  198. val(): any;
  199. }
  200. export { EmulatorMockTokenOptions };
  201. /**
  202. * Logs debugging information to the console.
  203. *
  204. * @param enabled - Enables logging if `true`, disables logging if `false`.
  205. * @param persistent - Remembers the logging state between page refreshes if
  206. * `true`.
  207. */
  208. export declare function enableLogging(enabled: boolean, persistent?: boolean): any;
  209. /**
  210. * Logs debugging information to the console.
  211. *
  212. * @param logger - A custom logger function to control how things get logged.
  213. */
  214. export declare function enableLogging(logger: (message: string) => unknown): any;
  215. /**
  216. * Creates a `QueryConstraint` with the specified ending point.
  217. *
  218. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  219. * allows you to choose arbitrary starting and ending points for your queries.
  220. *
  221. * The ending point is inclusive, so children with exactly the specified value
  222. * will be included in the query. The optional key argument can be used to
  223. * further limit the range of the query. If it is specified, then children that
  224. * have exactly the specified value must also have a key name less than or equal
  225. * to the specified key.
  226. *
  227. * You can read more about `endAt()` in
  228. * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
  229. *
  230. * @param value - The value to end at. The argument type depends on which
  231. * `orderBy*()` function was used in this query. Specify a value that matches
  232. * the `orderBy*()` type. When used in combination with `orderByKey()`, the
  233. * value must be a string.
  234. * @param key - The child key to end at, among the children with the previously
  235. * specified priority. This argument is only allowed if ordering by child,
  236. * value, or priority.
  237. */
  238. export declare function endAt(value: number | string | boolean | null, key?: string): QueryConstraint;
  239. /**
  240. * Creates a `QueryConstraint` with the specified ending point (exclusive).
  241. *
  242. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  243. * allows you to choose arbitrary starting and ending points for your queries.
  244. *
  245. * The ending point is exclusive. If only a value is provided, children
  246. * with a value less than the specified value will be included in the query.
  247. * If a key is specified, then children must have a value less than or equal
  248. * to the specified value and a key name less than the specified key.
  249. *
  250. * @param value - The value to end before. The argument type depends on which
  251. * `orderBy*()` function was used in this query. Specify a value that matches
  252. * the `orderBy*()` type. When used in combination with `orderByKey()`, the
  253. * value must be a string.
  254. * @param key - The child key to end before, among the children with the
  255. * previously specified priority. This argument is only allowed if ordering by
  256. * child, value, or priority.
  257. */
  258. export declare function endBefore(value: number | string | boolean | null, key?: string): QueryConstraint;
  259. /**
  260. * Creates a `QueryConstraint` that includes children that match the specified
  261. * value.
  262. *
  263. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  264. * allows you to choose arbitrary starting and ending points for your queries.
  265. *
  266. * The optional key argument can be used to further limit the range of the
  267. * query. If it is specified, then children that have exactly the specified
  268. * value must also have exactly the specified key as their key name. This can be
  269. * used to filter result sets with many matches for the same value.
  270. *
  271. * You can read more about `equalTo()` in
  272. * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
  273. *
  274. * @param value - The value to match for. The argument type depends on which
  275. * `orderBy*()` function was used in this query. Specify a value that matches
  276. * the `orderBy*()` type. When used in combination with `orderByKey()`, the
  277. * value must be a string.
  278. * @param key - The child key to start at, among the children with the
  279. * previously specified priority. This argument is only allowed if ordering by
  280. * child, value, or priority.
  281. */
  282. export declare function equalTo(value: number | string | boolean | null, key?: string): QueryConstraint;
  283. /**
  284. * One of the following strings: "value", "child_added", "child_changed",
  285. * "child_removed", or "child_moved."
  286. */
  287. export declare type EventType = 'value' | 'child_added' | 'child_changed' | 'child_moved' | 'child_removed';
  288. /* Excluded from this release type: _FirebaseService */
  289. /**
  290. * Force the use of longPolling instead of websockets. This will be ignored if websocket protocol is used in databaseURL.
  291. */
  292. export declare function forceLongPolling(): void;
  293. /**
  294. * Force the use of websockets instead of longPolling.
  295. */
  296. export declare function forceWebSockets(): void;
  297. /**
  298. * Gets the most up-to-date result for this query.
  299. *
  300. * @param query - The query to run.
  301. * @returns A `Promise` which resolves to the resulting DataSnapshot if a value is
  302. * available, or rejects if the client is unable to return a value (e.g., if the
  303. * server is unreachable and there is nothing cached).
  304. */
  305. export declare function get(query: Query): Promise<DataSnapshot>;
  306. /**
  307. * Returns the instance of the Realtime Database SDK that is associated with the provided
  308. * {@link @firebase/app#FirebaseApp}. Initializes a new instance with default settings if
  309. * no instance exists or if the existing instance uses a custom database URL.
  310. *
  311. * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned Realtime
  312. * Database instance is associated with.
  313. * @param url - The URL of the Realtime Database instance to connect to. If not
  314. * provided, the SDK connects to the default instance of the Firebase App.
  315. * @returns The `Database` instance of the provided app.
  316. */
  317. export declare function getDatabase(app?: FirebaseApp, url?: string): Database;
  318. /**
  319. * Disconnects from the server (all Database operations will be completed
  320. * offline).
  321. *
  322. * The client automatically maintains a persistent connection to the Database
  323. * server, which will remain active indefinitely and reconnect when
  324. * disconnected. However, the `goOffline()` and `goOnline()` methods may be used
  325. * to control the client connection in cases where a persistent connection is
  326. * undesirable.
  327. *
  328. * While offline, the client will no longer receive data updates from the
  329. * Database. However, all Database operations performed locally will continue to
  330. * immediately fire events, allowing your application to continue behaving
  331. * normally. Additionally, each operation performed locally will automatically
  332. * be queued and retried upon reconnection to the Database server.
  333. *
  334. * To reconnect to the Database and begin receiving remote events, see
  335. * `goOnline()`.
  336. *
  337. * @param db - The instance to disconnect.
  338. */
  339. export declare function goOffline(db: Database): void;
  340. /**
  341. * Reconnects to the server and synchronizes the offline Database state
  342. * with the server state.
  343. *
  344. * This method should be used after disabling the active connection with
  345. * `goOffline()`. Once reconnected, the client will transmit the proper data
  346. * and fire the appropriate events so that your client "catches up"
  347. * automatically.
  348. *
  349. * @param db - The instance to reconnect.
  350. */
  351. export declare function goOnline(db: Database): void;
  352. /**
  353. * Returns a placeholder value that can be used to atomically increment the
  354. * current database value by the provided delta.
  355. *
  356. * @param delta - the amount to modify the current value atomically.
  357. * @returns A placeholder value for modifying data atomically server-side.
  358. */
  359. export declare function increment(delta: number): object;
  360. /* Excluded from this release type: _initStandalone */
  361. /**
  362. * Represents a child snapshot of a `Reference` that is being iterated over. The key will never be undefined.
  363. */
  364. export declare interface IteratedDataSnapshot extends DataSnapshot {
  365. key: string;
  366. }
  367. /**
  368. * Creates a new `QueryConstraint` that if limited to the first specific number
  369. * of children.
  370. *
  371. * The `limitToFirst()` method is used to set a maximum number of children to be
  372. * synced for a given callback. If we set a limit of 100, we will initially only
  373. * receive up to 100 `child_added` events. If we have fewer than 100 messages
  374. * stored in our Database, a `child_added` event will fire for each message.
  375. * However, if we have over 100 messages, we will only receive a `child_added`
  376. * event for the first 100 ordered messages. As items change, we will receive
  377. * `child_removed` events for each item that drops out of the active list so
  378. * that the total number stays at 100.
  379. *
  380. * You can read more about `limitToFirst()` in
  381. * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
  382. *
  383. * @param limit - The maximum number of nodes to include in this query.
  384. */
  385. export declare function limitToFirst(limit: number): QueryConstraint;
  386. /**
  387. * Creates a new `QueryConstraint` that is limited to return only the last
  388. * specified number of children.
  389. *
  390. * The `limitToLast()` method is used to set a maximum number of children to be
  391. * synced for a given callback. If we set a limit of 100, we will initially only
  392. * receive up to 100 `child_added` events. If we have fewer than 100 messages
  393. * stored in our Database, a `child_added` event will fire for each message.
  394. * However, if we have over 100 messages, we will only receive a `child_added`
  395. * event for the last 100 ordered messages. As items change, we will receive
  396. * `child_removed` events for each item that drops out of the active list so
  397. * that the total number stays at 100.
  398. *
  399. * You can read more about `limitToLast()` in
  400. * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
  401. *
  402. * @param limit - The maximum number of nodes to include in this query.
  403. */
  404. export declare function limitToLast(limit: number): QueryConstraint;
  405. /** An options objects that can be used to customize a listener. */
  406. export declare interface ListenOptions {
  407. /** Whether to remove the listener after its first invocation. */
  408. readonly onlyOnce?: boolean;
  409. }
  410. /**
  411. * Detaches a callback previously attached with the corresponding `on*()` (`onValue`, `onChildAdded`) listener.
  412. * Note: This is not the recommended way to remove a listener. Instead, please use the returned callback function from
  413. * the respective `on*` callbacks.
  414. *
  415. * Detach a callback previously attached with `on*()`. Calling `off()` on a parent listener
  416. * will not automatically remove listeners registered on child nodes, `off()`
  417. * must also be called on any child listeners to remove the callback.
  418. *
  419. * If a callback is not specified, all callbacks for the specified eventType
  420. * will be removed. Similarly, if no eventType is specified, all callbacks
  421. * for the `Reference` will be removed.
  422. *
  423. * Individual listeners can also be removed by invoking their unsubscribe
  424. * callbacks.
  425. *
  426. * @param query - The query that the listener was registered with.
  427. * @param eventType - One of the following strings: "value", "child_added",
  428. * "child_changed", "child_removed", or "child_moved." If omitted, all callbacks
  429. * for the `Reference` will be removed.
  430. * @param callback - The callback function that was passed to `on()` or
  431. * `undefined` to remove all callbacks.
  432. */
  433. export declare function off(query: Query, eventType?: EventType, callback?: (snapshot: DataSnapshot, previousChildName?: string | null) => unknown): void;
  434. /**
  435. * Listens for data changes at a particular location.
  436. *
  437. * This is the primary way to read data from a Database. Your callback
  438. * will be triggered for the initial data and again whenever the data changes.
  439. * Invoke the returned unsubscribe callback to stop receiving updates. See
  440. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  441. * for more details.
  442. *
  443. * An `onChildAdded` event will be triggered once for each initial child at this
  444. * location, and it will be triggered again every time a new child is added. The
  445. * `DataSnapshot` passed into the callback will reflect the data for the
  446. * relevant child. For ordering purposes, it is passed a second argument which
  447. * is a string containing the key of the previous sibling child by sort order,
  448. * or `null` if it is the first child.
  449. *
  450. * @param query - The query to run.
  451. * @param callback - A callback that fires when the specified event occurs.
  452. * The callback will be passed a DataSnapshot and a string containing the key of
  453. * the previous child, by sort order, or `null` if it is the first child.
  454. * @param cancelCallback - An optional callback that will be notified if your
  455. * event subscription is ever canceled because your client does not have
  456. * permission to read this data (or it had permission but has now lost it).
  457. * This callback will be passed an `Error` object indicating why the failure
  458. * occurred.
  459. * @returns A function that can be invoked to remove the listener.
  460. */
  461. export declare function onChildAdded(query: Query, callback: (snapshot: DataSnapshot, previousChildName?: string | null) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
  462. /**
  463. * Listens for data changes at a particular location.
  464. *
  465. * This is the primary way to read data from a Database. Your callback
  466. * will be triggered for the initial data and again whenever the data changes.
  467. * Invoke the returned unsubscribe callback to stop receiving updates. See
  468. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  469. * for more details.
  470. *
  471. * An `onChildAdded` event will be triggered once for each initial child at this
  472. * location, and it will be triggered again every time a new child is added. The
  473. * `DataSnapshot` passed into the callback will reflect the data for the
  474. * relevant child. For ordering purposes, it is passed a second argument which
  475. * is a string containing the key of the previous sibling child by sort order,
  476. * or `null` if it is the first child.
  477. *
  478. * @param query - The query to run.
  479. * @param callback - A callback that fires when the specified event occurs.
  480. * The callback will be passed a DataSnapshot and a string containing the key of
  481. * the previous child, by sort order, or `null` if it is the first child.
  482. * @param options - An object that can be used to configure `onlyOnce`, which
  483. * then removes the listener after its first invocation.
  484. * @returns A function that can be invoked to remove the listener.
  485. */
  486. export declare function onChildAdded(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, options: ListenOptions): Unsubscribe;
  487. /**
  488. * Listens for data changes at a particular location.
  489. *
  490. * This is the primary way to read data from a Database. Your callback
  491. * will be triggered for the initial data and again whenever the data changes.
  492. * Invoke the returned unsubscribe callback to stop receiving updates. See
  493. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  494. * for more details.
  495. *
  496. * An `onChildAdded` event will be triggered once for each initial child at this
  497. * location, and it will be triggered again every time a new child is added. The
  498. * `DataSnapshot` passed into the callback will reflect the data for the
  499. * relevant child. For ordering purposes, it is passed a second argument which
  500. * is a string containing the key of the previous sibling child by sort order,
  501. * or `null` if it is the first child.
  502. *
  503. * @param query - The query to run.
  504. * @param callback - A callback that fires when the specified event occurs.
  505. * The callback will be passed a DataSnapshot and a string containing the key of
  506. * the previous child, by sort order, or `null` if it is the first child.
  507. * @param cancelCallback - An optional callback that will be notified if your
  508. * event subscription is ever canceled because your client does not have
  509. * permission to read this data (or it had permission but has now lost it).
  510. * This callback will be passed an `Error` object indicating why the failure
  511. * occurred.
  512. * @param options - An object that can be used to configure `onlyOnce`, which
  513. * then removes the listener after its first invocation.
  514. * @returns A function that can be invoked to remove the listener.
  515. */
  516. export declare function onChildAdded(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
  517. /**
  518. * Listens for data changes at a particular location.
  519. *
  520. * This is the primary way to read data from a Database. Your callback
  521. * will be triggered for the initial data and again whenever the data changes.
  522. * Invoke the returned unsubscribe callback to stop receiving updates. See
  523. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  524. * for more details.
  525. *
  526. * An `onChildChanged` event will be triggered when the data stored in a child
  527. * (or any of its descendants) changes. Note that a single `child_changed` event
  528. * may represent multiple changes to the child. The `DataSnapshot` passed to the
  529. * callback will contain the new child contents. For ordering purposes, the
  530. * callback is also passed a second argument which is a string containing the
  531. * key of the previous sibling child by sort order, or `null` if it is the first
  532. * child.
  533. *
  534. * @param query - The query to run.
  535. * @param callback - A callback that fires when the specified event occurs.
  536. * The callback will be passed a DataSnapshot and a string containing the key of
  537. * the previous child, by sort order, or `null` if it is the first child.
  538. * @param cancelCallback - An optional callback that will be notified if your
  539. * event subscription is ever canceled because your client does not have
  540. * permission to read this data (or it had permission but has now lost it).
  541. * This callback will be passed an `Error` object indicating why the failure
  542. * occurred.
  543. * @returns A function that can be invoked to remove the listener.
  544. */
  545. export declare function onChildChanged(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
  546. /**
  547. * Listens for data changes at a particular location.
  548. *
  549. * This is the primary way to read data from a Database. Your callback
  550. * will be triggered for the initial data and again whenever the data changes.
  551. * Invoke the returned unsubscribe callback to stop receiving updates. See
  552. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  553. * for more details.
  554. *
  555. * An `onChildChanged` event will be triggered when the data stored in a child
  556. * (or any of its descendants) changes. Note that a single `child_changed` event
  557. * may represent multiple changes to the child. The `DataSnapshot` passed to the
  558. * callback will contain the new child contents. For ordering purposes, the
  559. * callback is also passed a second argument which is a string containing the
  560. * key of the previous sibling child by sort order, or `null` if it is the first
  561. * child.
  562. *
  563. * @param query - The query to run.
  564. * @param callback - A callback that fires when the specified event occurs.
  565. * The callback will be passed a DataSnapshot and a string containing the key of
  566. * the previous child, by sort order, or `null` if it is the first child.
  567. * @param options - An object that can be used to configure `onlyOnce`, which
  568. * then removes the listener after its first invocation.
  569. * @returns A function that can be invoked to remove the listener.
  570. */
  571. export declare function onChildChanged(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, options: ListenOptions): Unsubscribe;
  572. /**
  573. * Listens for data changes at a particular location.
  574. *
  575. * This is the primary way to read data from a Database. Your callback
  576. * will be triggered for the initial data and again whenever the data changes.
  577. * Invoke the returned unsubscribe callback to stop receiving updates. See
  578. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  579. * for more details.
  580. *
  581. * An `onChildChanged` event will be triggered when the data stored in a child
  582. * (or any of its descendants) changes. Note that a single `child_changed` event
  583. * may represent multiple changes to the child. The `DataSnapshot` passed to the
  584. * callback will contain the new child contents. For ordering purposes, the
  585. * callback is also passed a second argument which is a string containing the
  586. * key of the previous sibling child by sort order, or `null` if it is the first
  587. * child.
  588. *
  589. * @param query - The query to run.
  590. * @param callback - A callback that fires when the specified event occurs.
  591. * The callback will be passed a DataSnapshot and a string containing the key of
  592. * the previous child, by sort order, or `null` if it is the first child.
  593. * @param cancelCallback - An optional callback that will be notified if your
  594. * event subscription is ever canceled because your client does not have
  595. * permission to read this data (or it had permission but has now lost it).
  596. * This callback will be passed an `Error` object indicating why the failure
  597. * occurred.
  598. * @param options - An object that can be used to configure `onlyOnce`, which
  599. * then removes the listener after its first invocation.
  600. * @returns A function that can be invoked to remove the listener.
  601. */
  602. export declare function onChildChanged(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
  603. /**
  604. * Listens for data changes at a particular location.
  605. *
  606. * This is the primary way to read data from a Database. Your callback
  607. * will be triggered for the initial data and again whenever the data changes.
  608. * Invoke the returned unsubscribe callback to stop receiving updates. See
  609. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  610. * for more details.
  611. *
  612. * An `onChildMoved` event will be triggered when a child's sort order changes
  613. * such that its position relative to its siblings changes. The `DataSnapshot`
  614. * passed to the callback will be for the data of the child that has moved. It
  615. * is also passed a second argument which is a string containing the key of the
  616. * previous sibling child by sort order, or `null` if it is the first child.
  617. *
  618. * @param query - The query to run.
  619. * @param callback - A callback that fires when the specified event occurs.
  620. * The callback will be passed a DataSnapshot and a string containing the key of
  621. * the previous child, by sort order, or `null` if it is the first child.
  622. * @param cancelCallback - An optional callback that will be notified if your
  623. * event subscription is ever canceled because your client does not have
  624. * permission to read this data (or it had permission but has now lost it).
  625. * This callback will be passed an `Error` object indicating why the failure
  626. * occurred.
  627. * @returns A function that can be invoked to remove the listener.
  628. */
  629. export declare function onChildMoved(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
  630. /**
  631. * Listens for data changes at a particular location.
  632. *
  633. * This is the primary way to read data from a Database. Your callback
  634. * will be triggered for the initial data and again whenever the data changes.
  635. * Invoke the returned unsubscribe callback to stop receiving updates. See
  636. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  637. * for more details.
  638. *
  639. * An `onChildMoved` event will be triggered when a child's sort order changes
  640. * such that its position relative to its siblings changes. The `DataSnapshot`
  641. * passed to the callback will be for the data of the child that has moved. It
  642. * is also passed a second argument which is a string containing the key of the
  643. * previous sibling child by sort order, or `null` if it is the first child.
  644. *
  645. * @param query - The query to run.
  646. * @param callback - A callback that fires when the specified event occurs.
  647. * The callback will be passed a DataSnapshot and a string containing the key of
  648. * the previous child, by sort order, or `null` if it is the first child.
  649. * @param options - An object that can be used to configure `onlyOnce`, which
  650. * then removes the listener after its first invocation.
  651. * @returns A function that can be invoked to remove the listener.
  652. */
  653. export declare function onChildMoved(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, options: ListenOptions): Unsubscribe;
  654. /**
  655. * Listens for data changes at a particular location.
  656. *
  657. * This is the primary way to read data from a Database. Your callback
  658. * will be triggered for the initial data and again whenever the data changes.
  659. * Invoke the returned unsubscribe callback to stop receiving updates. See
  660. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  661. * for more details.
  662. *
  663. * An `onChildMoved` event will be triggered when a child's sort order changes
  664. * such that its position relative to its siblings changes. The `DataSnapshot`
  665. * passed to the callback will be for the data of the child that has moved. It
  666. * is also passed a second argument which is a string containing the key of the
  667. * previous sibling child by sort order, or `null` if it is the first child.
  668. *
  669. * @param query - The query to run.
  670. * @param callback - A callback that fires when the specified event occurs.
  671. * The callback will be passed a DataSnapshot and a string containing the key of
  672. * the previous child, by sort order, or `null` if it is the first child.
  673. * @param cancelCallback - An optional callback that will be notified if your
  674. * event subscription is ever canceled because your client does not have
  675. * permission to read this data (or it had permission but has now lost it).
  676. * This callback will be passed an `Error` object indicating why the failure
  677. * occurred.
  678. * @param options - An object that can be used to configure `onlyOnce`, which
  679. * then removes the listener after its first invocation.
  680. * @returns A function that can be invoked to remove the listener.
  681. */
  682. export declare function onChildMoved(query: Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
  683. /**
  684. * Listens for data changes at a particular location.
  685. *
  686. * This is the primary way to read data from a Database. Your callback
  687. * will be triggered for the initial data and again whenever the data changes.
  688. * Invoke the returned unsubscribe callback to stop receiving updates. See
  689. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  690. * for more details.
  691. *
  692. * An `onChildRemoved` event will be triggered once every time a child is
  693. * removed. The `DataSnapshot` passed into the callback will be the old data for
  694. * the child that was removed. A child will get removed when either:
  695. *
  696. * - a client explicitly calls `remove()` on that child or one of its ancestors
  697. * - a client calls `set(null)` on that child or one of its ancestors
  698. * - that child has all of its children removed
  699. * - there is a query in effect which now filters out the child (because it's
  700. * sort order changed or the max limit was hit)
  701. *
  702. * @param query - The query to run.
  703. * @param callback - A callback that fires when the specified event occurs.
  704. * The callback will be passed a DataSnapshot and a string containing the key of
  705. * the previous child, by sort order, or `null` if it is the first child.
  706. * @param cancelCallback - An optional callback that will be notified if your
  707. * event subscription is ever canceled because your client does not have
  708. * permission to read this data (or it had permission but has now lost it).
  709. * This callback will be passed an `Error` object indicating why the failure
  710. * occurred.
  711. * @returns A function that can be invoked to remove the listener.
  712. */
  713. export declare function onChildRemoved(query: Query, callback: (snapshot: DataSnapshot) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
  714. /**
  715. * Listens for data changes at a particular location.
  716. *
  717. * This is the primary way to read data from a Database. Your callback
  718. * will be triggered for the initial data and again whenever the data changes.
  719. * Invoke the returned unsubscribe callback to stop receiving updates. See
  720. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  721. * for more details.
  722. *
  723. * An `onChildRemoved` event will be triggered once every time a child is
  724. * removed. The `DataSnapshot` passed into the callback will be the old data for
  725. * the child that was removed. A child will get removed when either:
  726. *
  727. * - a client explicitly calls `remove()` on that child or one of its ancestors
  728. * - a client calls `set(null)` on that child or one of its ancestors
  729. * - that child has all of its children removed
  730. * - there is a query in effect which now filters out the child (because it's
  731. * sort order changed or the max limit was hit)
  732. *
  733. * @param query - The query to run.
  734. * @param callback - A callback that fires when the specified event occurs.
  735. * The callback will be passed a DataSnapshot and a string containing the key of
  736. * the previous child, by sort order, or `null` if it is the first child.
  737. * @param options - An object that can be used to configure `onlyOnce`, which
  738. * then removes the listener after its first invocation.
  739. * @returns A function that can be invoked to remove the listener.
  740. */
  741. export declare function onChildRemoved(query: Query, callback: (snapshot: DataSnapshot) => unknown, options: ListenOptions): Unsubscribe;
  742. /**
  743. * Listens for data changes at a particular location.
  744. *
  745. * This is the primary way to read data from a Database. Your callback
  746. * will be triggered for the initial data and again whenever the data changes.
  747. * Invoke the returned unsubscribe callback to stop receiving updates. See
  748. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  749. * for more details.
  750. *
  751. * An `onChildRemoved` event will be triggered once every time a child is
  752. * removed. The `DataSnapshot` passed into the callback will be the old data for
  753. * the child that was removed. A child will get removed when either:
  754. *
  755. * - a client explicitly calls `remove()` on that child or one of its ancestors
  756. * - a client calls `set(null)` on that child or one of its ancestors
  757. * - that child has all of its children removed
  758. * - there is a query in effect which now filters out the child (because it's
  759. * sort order changed or the max limit was hit)
  760. *
  761. * @param query - The query to run.
  762. * @param callback - A callback that fires when the specified event occurs.
  763. * The callback will be passed a DataSnapshot and a string containing the key of
  764. * the previous child, by sort order, or `null` if it is the first child.
  765. * @param cancelCallback - An optional callback that will be notified if your
  766. * event subscription is ever canceled because your client does not have
  767. * permission to read this data (or it had permission but has now lost it).
  768. * This callback will be passed an `Error` object indicating why the failure
  769. * occurred.
  770. * @param options - An object that can be used to configure `onlyOnce`, which
  771. * then removes the listener after its first invocation.
  772. * @returns A function that can be invoked to remove the listener.
  773. */
  774. export declare function onChildRemoved(query: Query, callback: (snapshot: DataSnapshot) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
  775. /**
  776. * The `onDisconnect` class allows you to write or clear data when your client
  777. * disconnects from the Database server. These updates occur whether your
  778. * client disconnects cleanly or not, so you can rely on them to clean up data
  779. * even if a connection is dropped or a client crashes.
  780. *
  781. * The `onDisconnect` class is most commonly used to manage presence in
  782. * applications where it is useful to detect how many clients are connected and
  783. * when other clients disconnect. See
  784. * {@link https://firebase.google.com/docs/database/web/offline-capabilities | Enabling Offline Capabilities in JavaScript}
  785. * for more information.
  786. *
  787. * To avoid problems when a connection is dropped before the requests can be
  788. * transferred to the Database server, these functions should be called before
  789. * writing any data.
  790. *
  791. * Note that `onDisconnect` operations are only triggered once. If you want an
  792. * operation to occur each time a disconnect occurs, you'll need to re-establish
  793. * the `onDisconnect` operations each time you reconnect.
  794. */
  795. export declare class OnDisconnect {
  796. private constructor();
  797. /**
  798. * Cancels all previously queued `onDisconnect()` set or update events for this
  799. * location and all children.
  800. *
  801. * If a write has been queued for this location via a `set()` or `update()` at a
  802. * parent location, the write at this location will be canceled, though writes
  803. * to sibling locations will still occur.
  804. *
  805. * @returns Resolves when synchronization to the server is complete.
  806. */
  807. cancel(): Promise<void>;
  808. /**
  809. * Ensures the data at this location is deleted when the client is disconnected
  810. * (due to closing the browser, navigating to a new page, or network issues).
  811. *
  812. * @returns Resolves when synchronization to the server is complete.
  813. */
  814. remove(): Promise<void>;
  815. /**
  816. * Ensures the data at this location is set to the specified value when the
  817. * client is disconnected (due to closing the browser, navigating to a new page,
  818. * or network issues).
  819. *
  820. * `set()` is especially useful for implementing "presence" systems, where a
  821. * value should be changed or cleared when a user disconnects so that they
  822. * appear "offline" to other users. See
  823. * {@link https://firebase.google.com/docs/database/web/offline-capabilities | Enabling Offline Capabilities in JavaScript}
  824. * for more information.
  825. *
  826. * Note that `onDisconnect` operations are only triggered once. If you want an
  827. * operation to occur each time a disconnect occurs, you'll need to re-establish
  828. * the `onDisconnect` operations each time.
  829. *
  830. * @param value - The value to be written to this location on disconnect (can
  831. * be an object, array, string, number, boolean, or null).
  832. * @returns Resolves when synchronization to the Database is complete.
  833. */
  834. set(value: unknown): Promise<void>;
  835. /**
  836. * Ensures the data at this location is set to the specified value and priority
  837. * when the client is disconnected (due to closing the browser, navigating to a
  838. * new page, or network issues).
  839. *
  840. * @param value - The value to be written to this location on disconnect (can
  841. * be an object, array, string, number, boolean, or null).
  842. * @param priority - The priority to be written (string, number, or null).
  843. * @returns Resolves when synchronization to the Database is complete.
  844. */
  845. setWithPriority(value: unknown, priority: number | string | null): Promise<void>;
  846. /**
  847. * Writes multiple values at this location when the client is disconnected (due
  848. * to closing the browser, navigating to a new page, or network issues).
  849. *
  850. * The `values` argument contains multiple property-value pairs that will be
  851. * written to the Database together. Each child property can either be a simple
  852. * property (for example, "name") or a relative path (for example, "name/first")
  853. * from the current location to the data to update.
  854. *
  855. * As opposed to the `set()` method, `update()` can be use to selectively update
  856. * only the referenced properties at the current location (instead of replacing
  857. * all the child properties at the current location).
  858. *
  859. * @param values - Object containing multiple values.
  860. * @returns Resolves when synchronization to the Database is complete.
  861. */
  862. update(values: object): Promise<void>;
  863. }
  864. /**
  865. * Returns an `OnDisconnect` object - see
  866. * {@link https://firebase.google.com/docs/database/web/offline-capabilities | Enabling Offline Capabilities in JavaScript}
  867. * for more information on how to use it.
  868. *
  869. * @param ref - The reference to add OnDisconnect triggers for.
  870. */
  871. export declare function onDisconnect(ref: DatabaseReference): OnDisconnect;
  872. /**
  873. * Listens for data changes at a particular location.
  874. *
  875. * This is the primary way to read data from a Database. Your callback
  876. * will be triggered for the initial data and again whenever the data changes.
  877. * Invoke the returned unsubscribe callback to stop receiving updates. See
  878. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  879. * for more details.
  880. *
  881. * An `onValue` event will trigger once with the initial data stored at this
  882. * location, and then trigger again each time the data changes. The
  883. * `DataSnapshot` passed to the callback will be for the location at which
  884. * `on()` was called. It won't trigger until the entire contents has been
  885. * synchronized. If the location has no data, it will be triggered with an empty
  886. * `DataSnapshot` (`val()` will return `null`).
  887. *
  888. * @param query - The query to run.
  889. * @param callback - A callback that fires when the specified event occurs. The
  890. * callback will be passed a DataSnapshot.
  891. * @param cancelCallback - An optional callback that will be notified if your
  892. * event subscription is ever canceled because your client does not have
  893. * permission to read this data (or it had permission but has now lost it).
  894. * This callback will be passed an `Error` object indicating why the failure
  895. * occurred.
  896. * @returns A function that can be invoked to remove the listener.
  897. */
  898. export declare function onValue(query: Query, callback: (snapshot: DataSnapshot) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
  899. /**
  900. * Listens for data changes at a particular location.
  901. *
  902. * This is the primary way to read data from a Database. Your callback
  903. * will be triggered for the initial data and again whenever the data changes.
  904. * Invoke the returned unsubscribe callback to stop receiving updates. See
  905. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  906. * for more details.
  907. *
  908. * An `onValue` event will trigger once with the initial data stored at this
  909. * location, and then trigger again each time the data changes. The
  910. * `DataSnapshot` passed to the callback will be for the location at which
  911. * `on()` was called. It won't trigger until the entire contents has been
  912. * synchronized. If the location has no data, it will be triggered with an empty
  913. * `DataSnapshot` (`val()` will return `null`).
  914. *
  915. * @param query - The query to run.
  916. * @param callback - A callback that fires when the specified event occurs. The
  917. * callback will be passed a DataSnapshot.
  918. * @param options - An object that can be used to configure `onlyOnce`, which
  919. * then removes the listener after its first invocation.
  920. * @returns A function that can be invoked to remove the listener.
  921. */
  922. export declare function onValue(query: Query, callback: (snapshot: DataSnapshot) => unknown, options: ListenOptions): Unsubscribe;
  923. /**
  924. * Listens for data changes at a particular location.
  925. *
  926. * This is the primary way to read data from a Database. Your callback
  927. * will be triggered for the initial data and again whenever the data changes.
  928. * Invoke the returned unsubscribe callback to stop receiving updates. See
  929. * {@link https://firebase.google.com/docs/database/web/retrieve-data | Retrieve Data on the Web}
  930. * for more details.
  931. *
  932. * An `onValue` event will trigger once with the initial data stored at this
  933. * location, and then trigger again each time the data changes. The
  934. * `DataSnapshot` passed to the callback will be for the location at which
  935. * `on()` was called. It won't trigger until the entire contents has been
  936. * synchronized. If the location has no data, it will be triggered with an empty
  937. * `DataSnapshot` (`val()` will return `null`).
  938. *
  939. * @param query - The query to run.
  940. * @param callback - A callback that fires when the specified event occurs. The
  941. * callback will be passed a DataSnapshot.
  942. * @param cancelCallback - An optional callback that will be notified if your
  943. * event subscription is ever canceled because your client does not have
  944. * permission to read this data (or it had permission but has now lost it).
  945. * This callback will be passed an `Error` object indicating why the failure
  946. * occurred.
  947. * @param options - An object that can be used to configure `onlyOnce`, which
  948. * then removes the listener after its first invocation.
  949. * @returns A function that can be invoked to remove the listener.
  950. */
  951. export declare function onValue(query: Query, callback: (snapshot: DataSnapshot) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
  952. /**
  953. * Creates a new `QueryConstraint` that orders by the specified child key.
  954. *
  955. * Queries can only order by one key at a time. Calling `orderByChild()`
  956. * multiple times on the same query is an error.
  957. *
  958. * Firebase queries allow you to order your data by any child key on the fly.
  959. * However, if you know in advance what your indexes will be, you can define
  960. * them via the .indexOn rule in your Security Rules for better performance. See
  961. * the{@link https://firebase.google.com/docs/database/security/indexing-data}
  962. * rule for more information.
  963. *
  964. * You can read more about `orderByChild()` in
  965. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sort_data | Sort data}.
  966. *
  967. * @param path - The path to order by.
  968. */
  969. export declare function orderByChild(path: string): QueryConstraint;
  970. /**
  971. * Creates a new `QueryConstraint` that orders by the key.
  972. *
  973. * Sorts the results of a query by their (ascending) key values.
  974. *
  975. * You can read more about `orderByKey()` in
  976. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sort_data | Sort data}.
  977. */
  978. export declare function orderByKey(): QueryConstraint;
  979. /**
  980. * Creates a new `QueryConstraint` that orders by priority.
  981. *
  982. * Applications need not use priority but can order collections by
  983. * ordinary properties (see
  984. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sort_data | Sort data}
  985. * for alternatives to priority.
  986. */
  987. export declare function orderByPriority(): QueryConstraint;
  988. /**
  989. * Creates a new `QueryConstraint` that orders by value.
  990. *
  991. * If the children of a query are all scalar values (string, number, or
  992. * boolean), you can order the results by their (ascending) values.
  993. *
  994. * You can read more about `orderByValue()` in
  995. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sort_data | Sort data}.
  996. */
  997. export declare function orderByValue(): QueryConstraint;
  998. /**
  999. * Generates a new child location using a unique key and returns its
  1000. * `Reference`.
  1001. *
  1002. * This is the most common pattern for adding data to a collection of items.
  1003. *
  1004. * If you provide a value to `push()`, the value is written to the
  1005. * generated location. If you don't pass a value, nothing is written to the
  1006. * database and the child remains empty (but you can use the `Reference`
  1007. * elsewhere).
  1008. *
  1009. * The unique keys generated by `push()` are ordered by the current time, so the
  1010. * resulting list of items is chronologically sorted. The keys are also
  1011. * designed to be unguessable (they contain 72 random bits of entropy).
  1012. *
  1013. * See {@link https://firebase.google.com/docs/database/web/lists-of-data#append_to_a_list_of_data | Append to a list of data}.
  1014. * See {@link https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html | The 2^120 Ways to Ensure Unique Identifiers}.
  1015. *
  1016. * @param parent - The parent location.
  1017. * @param value - Optional value to be written at the generated location.
  1018. * @returns Combined `Promise` and `Reference`; resolves when write is complete,
  1019. * but can be used immediately as the `Reference` to the child location.
  1020. */
  1021. export declare function push(parent: DatabaseReference, value?: unknown): ThenableReference;
  1022. /**
  1023. * @license
  1024. * Copyright 2021 Google LLC
  1025. *
  1026. * Licensed under the Apache License, Version 2.0 (the "License");
  1027. * you may not use this file except in compliance with the License.
  1028. * You may obtain a copy of the License at
  1029. *
  1030. * http://www.apache.org/licenses/LICENSE-2.0
  1031. *
  1032. * Unless required by applicable law or agreed to in writing, software
  1033. * distributed under the License is distributed on an "AS IS" BASIS,
  1034. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1035. * See the License for the specific language governing permissions and
  1036. * limitations under the License.
  1037. */
  1038. /**
  1039. * A `Query` sorts and filters the data at a Database location so only a subset
  1040. * of the child data is included. This can be used to order a collection of
  1041. * data by some attribute (for example, height of dinosaurs) as well as to
  1042. * restrict a large list of items (for example, chat messages) down to a number
  1043. * suitable for synchronizing to the client. Queries are created by chaining
  1044. * together one or more of the filter methods defined here.
  1045. *
  1046. * Just as with a `DatabaseReference`, you can receive data from a `Query` by using the
  1047. * `on*()` methods. You will only receive events and `DataSnapshot`s for the
  1048. * subset of the data that matches your query.
  1049. *
  1050. * See {@link https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data}
  1051. * for more information.
  1052. */
  1053. export declare interface Query {
  1054. /** The `DatabaseReference` for the `Query`'s location. */
  1055. readonly ref: DatabaseReference;
  1056. /**
  1057. * Returns whether or not the current and provided queries represent the same
  1058. * location, have the same query parameters, and are from the same instance of
  1059. * `FirebaseApp`.
  1060. *
  1061. * Two `DatabaseReference` objects are equivalent if they represent the same location
  1062. * and are from the same instance of `FirebaseApp`.
  1063. *
  1064. * Two `Query` objects are equivalent if they represent the same location,
  1065. * have the same query parameters, and are from the same instance of
  1066. * `FirebaseApp`. Equivalent queries share the same sort order, limits, and
  1067. * starting and ending points.
  1068. *
  1069. * @param other - The query to compare against.
  1070. * @returns Whether or not the current and provided queries are equivalent.
  1071. */
  1072. isEqual(other: Query | null): boolean;
  1073. /**
  1074. * Returns a JSON-serializable representation of this object.
  1075. *
  1076. * @returns A JSON-serializable representation of this object.
  1077. */
  1078. toJSON(): string;
  1079. /**
  1080. * Gets the absolute URL for this location.
  1081. *
  1082. * The `toString()` method returns a URL that is ready to be put into a
  1083. * browser, curl command, or a `refFromURL()` call. Since all of those expect
  1084. * the URL to be url-encoded, `toString()` returns an encoded URL.
  1085. *
  1086. * Append '.json' to the returned URL when typed into a browser to download
  1087. * JSON-formatted data. If the location is secured (that is, not publicly
  1088. * readable), you will get a permission-denied error.
  1089. *
  1090. * @returns The absolute URL for this location.
  1091. */
  1092. toString(): string;
  1093. }
  1094. /**
  1095. * Creates a new immutable instance of `Query` that is extended to also include
  1096. * additional query constraints.
  1097. *
  1098. * @param query - The Query instance to use as a base for the new constraints.
  1099. * @param queryConstraints - The list of `QueryConstraint`s to apply.
  1100. * @throws if any of the provided query constraints cannot be combined with the
  1101. * existing or new constraints.
  1102. */
  1103. export declare function query(query: Query, ...queryConstraints: QueryConstraint[]): Query;
  1104. /**
  1105. * A `QueryConstraint` is used to narrow the set of documents returned by a
  1106. * Database query. `QueryConstraint`s are created by invoking {@link endAt},
  1107. * {@link endBefore}, {@link startAt}, {@link startAfter}, {@link
  1108. * limitToFirst}, {@link limitToLast}, {@link orderByChild},
  1109. * {@link orderByChild}, {@link orderByKey} , {@link orderByPriority} ,
  1110. * {@link orderByValue} or {@link equalTo} and
  1111. * can then be passed to {@link query} to create a new query instance that
  1112. * also contains this `QueryConstraint`.
  1113. */
  1114. export declare abstract class QueryConstraint {
  1115. /** The type of this query constraints */
  1116. abstract readonly type: QueryConstraintType;
  1117. }
  1118. /** Describes the different query constraints available in this SDK. */
  1119. export declare type QueryConstraintType = 'endAt' | 'endBefore' | 'startAt' | 'startAfter' | 'limitToFirst' | 'limitToLast' | 'orderByChild' | 'orderByKey' | 'orderByPriority' | 'orderByValue' | 'equalTo';
  1120. /* Excluded from this release type: _QueryImpl */
  1121. /* Excluded from this release type: _QueryParams */
  1122. /**
  1123. *
  1124. * Returns a `Reference` representing the location in the Database
  1125. * corresponding to the provided path. If no path is provided, the `Reference`
  1126. * will point to the root of the Database.
  1127. *
  1128. * @param db - The database instance to obtain a reference for.
  1129. * @param path - Optional path representing the location the returned
  1130. * `Reference` will point. If not provided, the returned `Reference` will
  1131. * point to the root of the Database.
  1132. * @returns If a path is provided, a `Reference`
  1133. * pointing to the provided path. Otherwise, a `Reference` pointing to the
  1134. * root of the Database.
  1135. */
  1136. export declare function ref(db: Database, path?: string): DatabaseReference;
  1137. /* Excluded from this release type: _ReferenceImpl */
  1138. /**
  1139. * Returns a `Reference` representing the location in the Database
  1140. * corresponding to the provided Firebase URL.
  1141. *
  1142. * An exception is thrown if the URL is not a valid Firebase Database URL or it
  1143. * has a different domain than the current `Database` instance.
  1144. *
  1145. * Note that all query parameters (`orderBy`, `limitToLast`, etc.) are ignored
  1146. * and are not applied to the returned `Reference`.
  1147. *
  1148. * @param db - The database instance to obtain a reference for.
  1149. * @param url - The Firebase URL at which the returned `Reference` will
  1150. * point.
  1151. * @returns A `Reference` pointing to the provided
  1152. * Firebase URL.
  1153. */
  1154. export declare function refFromURL(db: Database, url: string): DatabaseReference;
  1155. /**
  1156. * Removes the data at this Database location.
  1157. *
  1158. * Any data at child locations will also be deleted.
  1159. *
  1160. * The effect of the remove will be visible immediately and the corresponding
  1161. * event 'value' will be triggered. Synchronization of the remove to the
  1162. * Firebase servers will also be started, and the returned Promise will resolve
  1163. * when complete. If provided, the onComplete callback will be called
  1164. * asynchronously after synchronization has finished.
  1165. *
  1166. * @param ref - The location to remove.
  1167. * @returns Resolves when remove on server is complete.
  1168. */
  1169. export declare function remove(ref: DatabaseReference): Promise<void>;
  1170. /* Excluded from this release type: _repoManagerDatabaseFromApp */
  1171. /**
  1172. * Atomically modifies the data at this location.
  1173. *
  1174. * Atomically modify the data at this location. Unlike a normal `set()`, which
  1175. * just overwrites the data regardless of its previous value, `runTransaction()` is
  1176. * used to modify the existing value to a new value, ensuring there are no
  1177. * conflicts with other clients writing to the same location at the same time.
  1178. *
  1179. * To accomplish this, you pass `runTransaction()` an update function which is
  1180. * used to transform the current value into a new value. If another client
  1181. * writes to the location before your new value is successfully written, your
  1182. * update function will be called again with the new current value, and the
  1183. * write will be retried. This will happen repeatedly until your write succeeds
  1184. * without conflict or you abort the transaction by not returning a value from
  1185. * your update function.
  1186. *
  1187. * Note: Modifying data with `set()` will cancel any pending transactions at
  1188. * that location, so extreme care should be taken if mixing `set()` and
  1189. * `runTransaction()` to update the same data.
  1190. *
  1191. * Note: When using transactions with Security and Firebase Rules in place, be
  1192. * aware that a client needs `.read` access in addition to `.write` access in
  1193. * order to perform a transaction. This is because the client-side nature of
  1194. * transactions requires the client to read the data in order to transactionally
  1195. * update it.
  1196. *
  1197. * @param ref - The location to atomically modify.
  1198. * @param transactionUpdate - A developer-supplied function which will be passed
  1199. * the current data stored at this location (as a JavaScript object). The
  1200. * function should return the new value it would like written (as a JavaScript
  1201. * object). If `undefined` is returned (i.e. you return with no arguments) the
  1202. * transaction will be aborted and the data at this location will not be
  1203. * modified.
  1204. * @param options - An options object to configure transactions.
  1205. * @returns A `Promise` that can optionally be used instead of the `onComplete`
  1206. * callback to handle success and failure.
  1207. */
  1208. export declare function runTransaction(ref: DatabaseReference, transactionUpdate: (currentData: any) => unknown, options?: TransactionOptions): Promise<TransactionResult>;
  1209. /**
  1210. * @license
  1211. * Copyright 2020 Google LLC
  1212. *
  1213. * Licensed under the Apache License, Version 2.0 (the "License");
  1214. * you may not use this file except in compliance with the License.
  1215. * You may obtain a copy of the License at
  1216. *
  1217. * http://www.apache.org/licenses/LICENSE-2.0
  1218. *
  1219. * Unless required by applicable law or agreed to in writing, software
  1220. * distributed under the License is distributed on an "AS IS" BASIS,
  1221. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1222. * See the License for the specific language governing permissions and
  1223. * limitations under the License.
  1224. */
  1225. /**
  1226. * Returns a placeholder value for auto-populating the current timestamp (time
  1227. * since the Unix epoch, in milliseconds) as determined by the Firebase
  1228. * servers.
  1229. */
  1230. export declare function serverTimestamp(): object;
  1231. /**
  1232. * Writes data to this Database location.
  1233. *
  1234. * This will overwrite any data at this location and all child locations.
  1235. *
  1236. * The effect of the write will be visible immediately, and the corresponding
  1237. * events ("value", "child_added", etc.) will be triggered. Synchronization of
  1238. * the data to the Firebase servers will also be started, and the returned
  1239. * Promise will resolve when complete. If provided, the `onComplete` callback
  1240. * will be called asynchronously after synchronization has finished.
  1241. *
  1242. * Passing `null` for the new value is equivalent to calling `remove()`; namely,
  1243. * all data at this location and all child locations will be deleted.
  1244. *
  1245. * `set()` will remove any priority stored at this location, so if priority is
  1246. * meant to be preserved, you need to use `setWithPriority()` instead.
  1247. *
  1248. * Note that modifying data with `set()` will cancel any pending transactions
  1249. * at that location, so extreme care should be taken if mixing `set()` and
  1250. * `transaction()` to modify the same data.
  1251. *
  1252. * A single `set()` will generate a single "value" event at the location where
  1253. * the `set()` was performed.
  1254. *
  1255. * @param ref - The location to write to.
  1256. * @param value - The value to be written (string, number, boolean, object,
  1257. * array, or null).
  1258. * @returns Resolves when write to server is complete.
  1259. */
  1260. export declare function set(ref: DatabaseReference, value: unknown): Promise<void>;
  1261. /**
  1262. * Sets a priority for the data at this Database location.
  1263. *
  1264. * Applications need not use priority but can order collections by
  1265. * ordinary properties (see
  1266. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data | Sorting and filtering data}
  1267. * ).
  1268. *
  1269. * @param ref - The location to write to.
  1270. * @param priority - The priority to be written (string, number, or null).
  1271. * @returns Resolves when write to server is complete.
  1272. */
  1273. export declare function setPriority(ref: DatabaseReference, priority: string | number | null): Promise<void>;
  1274. /* Excluded from this release type: _setSDKVersion */
  1275. /**
  1276. * Writes data the Database location. Like `set()` but also specifies the
  1277. * priority for that data.
  1278. *
  1279. * Applications need not use priority but can order collections by
  1280. * ordinary properties (see
  1281. * {@link https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data | Sorting and filtering data}
  1282. * ).
  1283. *
  1284. * @param ref - The location to write to.
  1285. * @param value - The value to be written (string, number, boolean, object,
  1286. * array, or null).
  1287. * @param priority - The priority to be written (string, number, or null).
  1288. * @returns Resolves when write to server is complete.
  1289. */
  1290. export declare function setWithPriority(ref: DatabaseReference, value: unknown, priority: string | number | null): Promise<void>;
  1291. /**
  1292. * Creates a `QueryConstraint` with the specified starting point (exclusive).
  1293. *
  1294. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  1295. * allows you to choose arbitrary starting and ending points for your queries.
  1296. *
  1297. * The starting point is exclusive. If only a value is provided, children
  1298. * with a value greater than the specified value will be included in the query.
  1299. * If a key is specified, then children must have a value greater than or equal
  1300. * to the specified value and a a key name greater than the specified key.
  1301. *
  1302. * @param value - The value to start after. The argument type depends on which
  1303. * `orderBy*()` function was used in this query. Specify a value that matches
  1304. * the `orderBy*()` type. When used in combination with `orderByKey()`, the
  1305. * value must be a string.
  1306. * @param key - The child key to start after. This argument is only allowed if
  1307. * ordering by child, value, or priority.
  1308. */
  1309. export declare function startAfter(value: number | string | boolean | null, key?: string): QueryConstraint;
  1310. /**
  1311. * Creates a `QueryConstraint` with the specified starting point.
  1312. *
  1313. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  1314. * allows you to choose arbitrary starting and ending points for your queries.
  1315. *
  1316. * The starting point is inclusive, so children with exactly the specified value
  1317. * will be included in the query. The optional key argument can be used to
  1318. * further limit the range of the query. If it is specified, then children that
  1319. * have exactly the specified value must also have a key name greater than or
  1320. * equal to the specified key.
  1321. *
  1322. * You can read more about `startAt()` in
  1323. * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
  1324. *
  1325. * @param value - The value to start at. The argument type depends on which
  1326. * `orderBy*()` function was used in this query. Specify a value that matches
  1327. * the `orderBy*()` type. When used in combination with `orderByKey()`, the
  1328. * value must be a string.
  1329. * @param key - The child key to start at. This argument is only allowed if
  1330. * ordering by child, value, or priority.
  1331. */
  1332. export declare function startAt(value?: number | string | boolean | null, key?: string): QueryConstraint;
  1333. /* Excluded from this release type: _TEST_ACCESS_forceRestClient */
  1334. /* Excluded from this release type: _TEST_ACCESS_hijackHash */
  1335. /**
  1336. * A `Promise` that can also act as a `DatabaseReference` when returned by
  1337. * {@link push}. The reference is available immediately and the `Promise` resolves
  1338. * as the write to the backend completes.
  1339. */
  1340. export declare interface ThenableReference extends DatabaseReference, Pick<Promise<DatabaseReference>, 'then' | 'catch'> {
  1341. }
  1342. /** An options object to configure transactions. */
  1343. export declare interface TransactionOptions {
  1344. /**
  1345. * By default, events are raised each time the transaction update function
  1346. * runs. So if it is run multiple times, you may see intermediate states. You
  1347. * can set this to false to suppress these intermediate states and instead
  1348. * wait until the transaction has completed before events are raised.
  1349. */
  1350. readonly applyLocally?: boolean;
  1351. }
  1352. /**
  1353. * A type for the resolve value of {@link runTransaction}.
  1354. */
  1355. export declare class TransactionResult {
  1356. /** Whether the transaction was successfully committed. */
  1357. readonly committed: boolean;
  1358. /** The resulting data snapshot. */
  1359. readonly snapshot: DataSnapshot;
  1360. private constructor();
  1361. /** Returns a JSON-serializable representation of this object. */
  1362. toJSON(): object;
  1363. }
  1364. /** A callback that can invoked to remove a listener. */
  1365. export declare type Unsubscribe = () => void;
  1366. /**
  1367. * Writes multiple values to the Database at once.
  1368. *
  1369. * The `values` argument contains multiple property-value pairs that will be
  1370. * written to the Database together. Each child property can either be a simple
  1371. * property (for example, "name") or a relative path (for example,
  1372. * "name/first") from the current location to the data to update.
  1373. *
  1374. * As opposed to the `set()` method, `update()` can be use to selectively update
  1375. * only the referenced properties at the current location (instead of replacing
  1376. * all the child properties at the current location).
  1377. *
  1378. * The effect of the write will be visible immediately, and the corresponding
  1379. * events ('value', 'child_added', etc.) will be triggered. Synchronization of
  1380. * the data to the Firebase servers will also be started, and the returned
  1381. * Promise will resolve when complete. If provided, the `onComplete` callback
  1382. * will be called asynchronously after synchronization has finished.
  1383. *
  1384. * A single `update()` will generate a single "value" event at the location
  1385. * where the `update()` was performed, regardless of how many children were
  1386. * modified.
  1387. *
  1388. * Note that modifying data with `update()` will cancel any pending
  1389. * transactions at that location, so extreme care should be taken if mixing
  1390. * `update()` and `transaction()` to modify the same data.
  1391. *
  1392. * Passing `null` to `update()` will remove the data at this location.
  1393. *
  1394. * See
  1395. * {@link https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html | Introducing multi-location updates and more}.
  1396. *
  1397. * @param ref - The location to write to.
  1398. * @param values - Object containing multiple values.
  1399. * @returns Resolves when update on server is complete.
  1400. */
  1401. export declare function update(ref: DatabaseReference, values: object): Promise<void>;
  1402. export {};