UNPKG

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