UNPKG

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