No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

public.d.ts 69KB

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