UNPKG

123 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 { _FirebaseService } from '@firebase/app';
15import { Provider } from '@firebase/component';
16
17/**
18 * Abstraction around AppCheck's token fetching capabilities.
19 */
20declare class AppCheckTokenProvider {
21 private appName_;
22 private appCheckProvider?;
23 private appCheck?;
24 constructor(appName_: string, appCheckProvider?: Provider<AppCheckInternalComponentName>);
25 getToken(forceRefresh?: boolean): Promise<AppCheckTokenResult>;
26 addTokenChangeListener(listener: AppCheckTokenListener): void;
27 notifyForInvalidToken(): void;
28}
29
30declare interface AuthTokenProvider {
31 getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData>;
32 addTokenChangeListener(listener: (token: string | null) => void): void;
33 removeTokenChangeListener(listener: (token: string | null) => void): void;
34 notifyForInvalidToken(): void;
35}
36
37/**
38 * A cache node only stores complete children. Additionally it holds a flag whether the node can be considered fully
39 * initialized in the sense that we know at one point in time this represented a valid state of the world, e.g.
40 * initialized with data from the server, or a complete overwrite by the client. The filtered flag also tracks
41 * whether a node potentially had children removed due to a filter.
42 */
43declare class CacheNode {
44 private node_;
45 private fullyInitialized_;
46 private filtered_;
47 constructor(node_: Node_2, fullyInitialized_: boolean, filtered_: boolean);
48 /**
49 * Returns whether this node was fully initialized with either server data or a complete overwrite by the client
50 */
51 isFullyInitialized(): boolean;
52 /**
53 * Returns whether this node is potentially missing children due to a filter applied to the node
54 */
55 isFiltered(): boolean;
56 isCompleteForPath(path: Path): boolean;
57 isCompleteForChild(key: string): boolean;
58 getNode(): Node_2;
59}
60
61declare class CancelEvent implements Event_2 {
62 eventRegistration: EventRegistration;
63 error: Error;
64 path: Path;
65 constructor(eventRegistration: EventRegistration, error: Error, path: Path);
66 getPath(): Path;
67 getEventType(): string;
68 getEventRunner(): () => void;
69 toString(): string;
70}
71
72declare interface Change {
73 /** @param type - The event type */
74 type: ChangeType;
75 /** @param snapshotNode - The data */
76 snapshotNode: Node_2;
77 /** @param childName - The name for this child, if it's a child even */
78 childName?: string;
79 /** @param oldSnap - Used for intermediate processing of child changed events */
80 oldSnap?: Node_2;
81 /** * @param prevName - The name for the previous child, if applicable */
82 prevName?: string | null;
83}
84
85declare const enum ChangeType {
86 /** Event type for a child added */
87 CHILD_ADDED = "child_added",
88 /** Event type for a child removed */
89 CHILD_REMOVED = "child_removed",
90 /** Event type for a child changed */
91 CHILD_CHANGED = "child_changed",
92 /** Event type for a child moved */
93 CHILD_MOVED = "child_moved",
94 /** Event type for a value change */
95 VALUE = "value"
96}
97
98/**
99 * Gets a `Reference` for the location at the specified relative path.
100 *
101 * The relative path can either be a simple child name (for example, "ada") or
102 * a deeper slash-separated path (for example, "ada/name/first").
103 *
104 * @param parent - The parent location.
105 * @param path - A relative path from this location to the desired child
106 * location.
107 * @returns The specified child location.
108 */
109export declare function child(parent: DatabaseReference, path: string): DatabaseReference;
110
111declare class ChildChangeAccumulator {
112 private readonly changeMap;
113 trackChildChange(change: Change): void;
114 getChanges(): Change[];
115}
116
117/**
118 * @license
119 * Copyright 2017 Google LLC
120 *
121 * Licensed under the Apache License, Version 2.0 (the "License");
122 * you may not use this file except in compliance with the License.
123 * You may obtain a copy of the License at
124 *
125 * http://www.apache.org/licenses/LICENSE-2.0
126 *
127 * Unless required by applicable law or agreed to in writing, software
128 * distributed under the License is distributed on an "AS IS" BASIS,
129 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130 * See the License for the specific language governing permissions and
131 * limitations under the License.
132 */
133/**
134 * @fileoverview Implementation of an immutable SortedMap using a Left-leaning
135 * Red-Black Tree, adapted from the implementation in Mugs
136 * (http://mads379.github.com/mugs/) by Mads Hartmann Jensen
137 * (mads379\@gmail.com).
138 *
139 * Original paper on Left-leaning Red-Black Trees:
140 * http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf
141 *
142 * Invariant 1: No red node has a red child
143 * Invariant 2: Every leaf path has the same number of black nodes
144 * Invariant 3: Only the left child can be red (left leaning)
145 */
146declare type Comparator<K> = (key1: K, key2: K) => number;
147
148/**
149 * Since updates to filtered nodes might require nodes to be pulled in from "outside" the node, this interface
150 * can help to get complete children that can be pulled in.
151 * A class implementing this interface takes potentially multiple sources (e.g. user writes, server data from
152 * other views etc.) to try it's best to get a complete child that might be useful in pulling into the view.
153 *
154 * @interface
155 */
156declare interface CompleteChildSource {
157 getCompleteChild(childKey: string): Node_2 | null;
158 getChildAfterChild(index: Index, child: NamedNode, reverse: boolean): NamedNode | null;
159}
160
161/**
162 * This class holds a collection of writes that can be applied to nodes in unison. It abstracts away the logic with
163 * dealing with priority writes and multiple nested writes. At any given path there is only allowed to be one write
164 * modifying that path. Any write to an existing path or shadowing an existing path will modify that existing write
165 * to reflect the write added.
166 */
167declare class CompoundWrite {
168 writeTree_: ImmutableTree<Node_2>;
169 constructor(writeTree_: ImmutableTree<Node_2>);
170 static empty(): CompoundWrite;
171}
172
173/**
174 * Modify the provided instance to communicate with the Realtime Database
175 * emulator.
176 *
177 * <p>Note: This method must be called before performing any other operation.
178 *
179 * @param db - The instance to modify.
180 * @param host - The emulator host (ex: localhost)
181 * @param port - The emulator port (ex: 8080)
182 * @param options.mockUserToken - the mock auth token to use for unit testing Security Rules
183 */
184export declare function connectDatabaseEmulator(db: Database, host: string, port: number, options?: {
185 mockUserToken?: EmulatorMockTokenOptions | string;
186}): void;
187
188/**
189 * Class representing a Firebase Realtime Database.
190 */
191export declare class Database implements _FirebaseService {
192 _repoInternal: Repo;
193 /** The {@link @firebase/app#FirebaseApp} associated with this Realtime Database instance. */
194 readonly app: FirebaseApp;
195 /** Represents a `Database` instance. */
196 readonly 'type' = "database";
197 /** Track if the instance has been used (root or repo accessed) */
198 _instanceStarted: boolean;
199 /** Backing state for root_ */
200 private _rootInternal?;
201 /** @hideconstructor */
202 constructor(_repoInternal: Repo,
203 /** The {@link @firebase/app#FirebaseApp} associated with this Realtime Database instance. */
204 app: FirebaseApp);
205 get _repo(): Repo;
206 get _root(): _ReferenceImpl;
207 _delete(): Promise<void>;
208 _checkNotDeleted(apiName: string): void;
209}
210
211/**
212 * A `DatabaseReference` represents a specific location in your Database and can be used
213 * for reading or writing data to that Database location.
214 *
215 * You can reference the root or child location in your Database by calling
216 * `ref()` or `ref("child/path")`.
217 *
218 * Writing is done with the `set()` method and reading can be done with the
219 * `on*()` method. See {@link
220 * https://firebase.google.com/docs/database/web/read-and-write}
221 */
222export declare interface DatabaseReference extends Query {
223 /**
224 * The last part of the `DatabaseReference`'s path.
225 *
226 * For example, `"ada"` is the key for
227 * `https://<DATABASE_NAME>.firebaseio.com/users/ada`.
228 *
229 * The key of a root `DatabaseReference` is `null`.
230 */
231 readonly key: string | null;
232 /**
233 * The parent location of a `DatabaseReference`.
234 *
235 * The parent of a root `DatabaseReference` is `null`.
236 */
237 readonly parent: DatabaseReference | null;
238 /** The root `DatabaseReference` of the Database. */
239 readonly root: DatabaseReference;
240}
241
242/**
243 * A `DataSnapshot` contains data from a Database location.
244 *
245 * Any time you read data from the Database, you receive the data as a
246 * `DataSnapshot`. A `DataSnapshot` is passed to the event callbacks you attach
247 * with `on()` or `once()`. You can extract the contents of the snapshot as a
248 * JavaScript object by calling the `val()` method. Alternatively, you can
249 * traverse into the snapshot by calling `child()` to return child snapshots
250 * (which you could then call `val()` on).
251 *
252 * A `DataSnapshot` is an efficiently generated, immutable copy of the data at
253 * a Database location. It cannot be modified and will never change (to modify
254 * data, you always call the `set()` method on a `Reference` directly).
255 */
256export declare class DataSnapshot {
257 readonly _node: Node_2;
258 /**
259 * The location of this DataSnapshot.
260 */
261 readonly ref: DatabaseReference;
262 readonly _index: Index;
263 /**
264 * @param _node - A SnapshotNode to wrap.
265 * @param ref - The location this snapshot came from.
266 * @param _index - The iteration order for this snapshot
267 * @hideconstructor
268 */
269 constructor(_node: Node_2,
270 /**
271 * The location of this DataSnapshot.
272 */
273 ref: DatabaseReference, _index: Index);
274 /**
275 * Gets the priority value of the data in this `DataSnapshot`.
276 *
277 * Applications need not use priority but can order collections by
278 * ordinary properties (see
279 * {@link https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data |Sorting and filtering data}
280 * ).
281 */
282 get priority(): string | number | null;
283 /**
284 * The key (last part of the path) of the location of this `DataSnapshot`.
285 *
286 * The last token in a Database location is considered its key. For example,
287 * "ada" is the key for the /users/ada/ node. Accessing the key on any
288 * `DataSnapshot` will return the key for the location that generated it.
289 * However, accessing the key on the root URL of a Database will return
290 * `null`.
291 */
292 get key(): string | null;
293 /** Returns the number of child properties of this `DataSnapshot`. */
294 get size(): number;
295 /**
296 * Gets another `DataSnapshot` for the location at the specified relative path.
297 *
298 * Passing a relative path to the `child()` method of a DataSnapshot returns
299 * another `DataSnapshot` for the location at the specified relative path. The
300 * relative path can either be a simple child name (for example, "ada") or a
301 * deeper, slash-separated path (for example, "ada/name/first"). If the child
302 * location has no data, an empty `DataSnapshot` (that is, a `DataSnapshot`
303 * whose value is `null`) is returned.
304 *
305 * @param path - A relative path to the location of child data.
306 */
307 child(path: string): DataSnapshot;
308 /**
309 * Returns true if this `DataSnapshot` contains any data. It is slightly more
310 * efficient than using `snapshot.val() !== null`.
311 */
312 exists(): boolean;
313 /**
314 * Exports the entire contents of the DataSnapshot as a JavaScript object.
315 *
316 * The `exportVal()` method is similar to `val()`, except priority information
317 * is included (if available), making it suitable for backing up your data.
318 *
319 * @returns The DataSnapshot's contents as a JavaScript value (Object,
320 * Array, string, number, boolean, or `null`).
321 */
322 exportVal(): any;
323 /**
324 * Enumerates the top-level children in the `DataSnapshot`.
325 *
326 * Because of the way JavaScript objects work, the ordering of data in the
327 * JavaScript object returned by `val()` is not guaranteed to match the
328 * ordering on the server nor the ordering of `onChildAdded()` events. That is
329 * where `forEach()` comes in handy. It guarantees the children of a
330 * `DataSnapshot` will be iterated in their query order.
331 *
332 * If no explicit `orderBy*()` method is used, results are returned
333 * ordered by key (unless priorities are used, in which case, results are
334 * returned by priority).
335 *
336 * @param action - A function that will be called for each child DataSnapshot.
337 * The callback can return true to cancel further enumeration.
338 * @returns true if enumeration was canceled due to your callback returning
339 * true.
340 */
341 forEach(action: (child: DataSnapshot) => boolean | void): boolean;
342 /**
343 * Returns true if the specified child path has (non-null) data.
344 *
345 * @param path - A relative path to the location of a potential child.
346 * @returns `true` if data exists at the specified child path; else
347 * `false`.
348 */
349 hasChild(path: string): boolean;
350 /**
351 * Returns whether or not the `DataSnapshot` has any non-`null` child
352 * properties.
353 *
354 * You can use `hasChildren()` to determine if a `DataSnapshot` has any
355 * children. If it does, you can enumerate them using `forEach()`. If it
356 * doesn't, then either this snapshot contains a primitive value (which can be
357 * retrieved with `val()`) or it is empty (in which case, `val()` will return
358 * `null`).
359 *
360 * @returns true if this snapshot has any children; else false.
361 */
362 hasChildren(): boolean;
363 /**
364 * Returns a JSON-serializable representation of this object.
365 */
366 toJSON(): object | null;
367 /**
368 * Extracts a JavaScript value from a `DataSnapshot`.
369 *
370 * Depending on the data in a `DataSnapshot`, the `val()` method may return a
371 * scalar type (string, number, or boolean), an array, or an object. It may
372 * also return null, indicating that the `DataSnapshot` is empty (contains no
373 * data).
374 *
375 * @returns The DataSnapshot's contents as a JavaScript value (Object,
376 * Array, string, number, boolean, or `null`).
377 */
378 val(): any;
379}
380export { EmulatorMockTokenOptions }
381
382/**
383 * Logs debugging information to the console.
384 *
385 * @param enabled - Enables logging if `true`, disables logging if `false`.
386 * @param persistent - Remembers the logging state between page refreshes if
387 * `true`.
388 */
389export declare function enableLogging(enabled: boolean, persistent?: boolean): any;
390
391/**
392 * Logs debugging information to the console.
393 *
394 * @param logger - A custom logger function to control how things get logged.
395 */
396export declare function enableLogging(logger: (message: string) => unknown): any;
397
398/**
399 * Creates a `QueryConstraint` with the specified ending point.
400 *
401 * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
402 * allows you to choose arbitrary starting and ending points for your queries.
403 *
404 * The ending point is inclusive, so children with exactly the specified value
405 * will be included in the query. The optional key argument can be used to
406 * further limit the range of the query. If it is specified, then children that
407 * have exactly the specified value must also have a key name less than or equal
408 * to the specified key.
409 *
410 * You can read more about `endAt()` in
411 * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
412 *
413 * @param value - The value to end at. The argument type depends on which
414 * `orderBy*()` function was used in this query. Specify a value that matches
415 * the `orderBy*()` type. When used in combination with `orderByKey()`, the
416 * value must be a string.
417 * @param key - The child key to end at, among the children with the previously
418 * specified priority. This argument is only allowed if ordering by child,
419 * value, or priority.
420 */
421export declare function endAt(value: number | string | boolean | null, key?: string): QueryConstraint;
422
423/**
424 * Creates a `QueryConstraint` with the specified ending point (exclusive).
425 *
426 * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
427 * allows you to choose arbitrary starting and ending points for your queries.
428 *
429 * The ending point is exclusive. If only a value is provided, children
430 * with a value less than the specified value will be included in the query.
431 * If a key is specified, then children must have a value lesss than or equal
432 * to the specified value and a a key name less than the specified key.
433 *
434 * @param value - The value to end before. The argument type depends on which
435 * `orderBy*()` function was used in this query. Specify a value that matches
436 * the `orderBy*()` type. When used in combination with `orderByKey()`, the
437 * value must be a string.
438 * @param key - The child key to end before, among the children with the
439 * previously specified priority. This argument is only allowed if ordering by
440 * child, value, or priority.
441 */
442export declare function endBefore(value: number | string | boolean | null, key?: string): QueryConstraint;
443
444/**
445 * Creates a `QueryConstraint` that includes children that match the specified
446 * value.
447 *
448 * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
449 * allows you to choose arbitrary starting and ending points for your queries.
450 *
451 * The optional key argument can be used to further limit the range of the
452 * query. If it is specified, then children that have exactly the specified
453 * value must also have exactly the specified key as their key name. This can be
454 * used to filter result sets with many matches for the same value.
455 *
456 * You can read more about `equalTo()` in
457 * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
458 *
459 * @param value - The value to match for. The argument type depends on which
460 * `orderBy*()` function was used in this query. Specify a value that matches
461 * the `orderBy*()` type. When used in combination with `orderByKey()`, the
462 * value must be a string.
463 * @param key - The child key to start at, among the children with the
464 * previously specified priority. This argument is only allowed if ordering by
465 * child, value, or priority.
466 */
467export declare function equalTo(value: number | string | boolean | null, key?: string): QueryConstraint;
468
469/**
470 * Encapsulates the data needed to raise an event
471 * @interface
472 */
473declare interface Event_2 {
474 getPath(): Path;
475 getEventType(): string;
476 getEventRunner(): () => void;
477 toString(): string;
478}
479
480/**
481 * An EventGenerator is used to convert "raw" changes (Change) as computed by the
482 * CacheDiffer into actual events (Event) that can be raised. See generateEventsForChanges()
483 * for details.
484 *
485 */
486declare class EventGenerator {
487 query_: QueryContext;
488 index_: Index;
489 constructor(query_: QueryContext);
490}
491
492declare interface EventList {
493 events: Event_2[];
494 path: Path;
495}
496
497/**
498 * The event queue serves a few purposes:
499 * 1. It ensures we maintain event order in the face of event callbacks doing operations that result in more
500 * events being queued.
501 * 2. raiseQueuedEvents() handles being called reentrantly nicely. That is, if in the course of raising events,
502 * raiseQueuedEvents() is called again, the "inner" call will pick up raising events where the "outer" call
503 * left off, ensuring that the events are still raised synchronously and in order.
504 * 3. You can use raiseEventsAtPath and raiseEventsForChangedPath to ensure only relevant previously-queued
505 * events are raised synchronously.
506 *
507 * NOTE: This can all go away if/when we move to async events.
508 *
509 */
510declare class EventQueue {
511 eventLists_: EventList[];
512 /**
513 * Tracks recursion depth of raiseQueuedEvents_, for debugging purposes.
514 */
515 recursionDepth_: number;
516}
517
518/**
519 * An EventRegistration is basically an event type ('value', 'child_added', etc.) and a callback
520 * to be notified of that type of event.
521 *
522 * That said, it can also contain a cancel callback to be notified if the event is canceled. And
523 * currently, this code is organized around the idea that you would register multiple child_ callbacks
524 * together, as a single EventRegistration. Though currently we don't do that.
525 */
526declare interface EventRegistration {
527 /**
528 * True if this container has a callback to trigger for this event type
529 */
530 respondsTo(eventType: string): boolean;
531 createEvent(change: Change, query: QueryContext): Event_2;
532 /**
533 * Given event data, return a function to trigger the user's callback
534 */
535 getEventRunner(eventData: Event_2): () => void;
536 createCancelEvent(error: Error, path: Path): CancelEvent | null;
537 matches(other: EventRegistration): boolean;
538 /**
539 * False basically means this is a "dummy" callback container being used as a sentinel
540 * to remove all callback containers of a particular type. (e.g. if the user does
541 * ref.off('value') without specifying a specific callback).
542 *
543 * (TODO: Rework this, since it's hacky)
544 *
545 */
546 hasAnyCallback(): boolean;
547}
548
549/**
550 * One of the following strings: "value", "child_added", "child_changed",
551 * "child_removed", or "child_moved."
552 */
553export declare type EventType = 'value' | 'child_added' | 'child_changed' | 'child_moved' | 'child_removed';
554
555/**
556 * Force the use of longPolling instead of websockets. This will be ignored if websocket protocol is used in databaseURL.
557 */
558export declare function forceLongPolling(): void;
559
560/**
561 * Force the use of websockets instead of longPolling.
562 */
563export declare function forceWebSockets(): void;
564
565/**
566 * Gets the most up-to-date result for this query.
567 *
568 * @param query - The query to run.
569 * @returns A `Promise` which resolves to the resulting DataSnapshot if a value is
570 * available, or rejects if the client is unable to return a value (e.g., if the
571 * server is unreachable and there is nothing cached).
572 */
573export declare function get(query: Query): Promise<DataSnapshot>;
574
575/**
576 * Returns the instance of the Realtime Database SDK that is associated
577 * with the provided {@link @firebase/app#FirebaseApp}. Initializes a new instance with
578 * with default settings if no instance exists or if the existing instance uses
579 * a custom database URL.
580 *
581 * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned Realtime
582 * Database instance is associated with.
583 * @param url - The URL of the Realtime Database instance to connect to. If not
584 * provided, the SDK connects to the default instance of the Firebase App.
585 * @returns The `Database` instance of the provided app.
586 */
587export declare function getDatabase(app?: FirebaseApp, url?: string): Database;
588
589/**
590 * Disconnects from the server (all Database operations will be completed
591 * offline).
592 *
593 * The client automatically maintains a persistent connection to the Database
594 * server, which will remain active indefinitely and reconnect when
595 * disconnected. However, the `goOffline()` and `goOnline()` methods may be used
596 * to control the client connection in cases where a persistent connection is
597 * undesirable.
598 *
599 * While offline, the client will no longer receive data updates from the
600 * Database. However, all Database operations performed locally will continue to
601 * immediately fire events, allowing your application to continue behaving
602 * normally. Additionally, each operation performed locally will automatically
603 * be queued and retried upon reconnection to the Database server.
604 *
605 * To reconnect to the Database and begin receiving remote events, see
606 * `goOnline()`.
607 *
608 * @param db - The instance to disconnect.
609 */
610export declare function goOffline(db: Database): void;
611
612/**
613 * Reconnects to the server and synchronizes the offline Database state
614 * with the server state.
615 *
616 * This method should be used after disabling the active connection with
617 * `goOffline()`. Once reconnected, the client will transmit the proper data
618 * and fire the appropriate events so that your client "catches up"
619 * automatically.
620 *
621 * @param db - The instance to reconnect.
622 */
623export declare function goOnline(db: Database): void;
624
625/**
626 * A tree with immutable elements.
627 */
628declare class ImmutableTree<T> {
629 readonly value: T | null;
630 readonly children: SortedMap<string, ImmutableTree<T>>;
631 static fromObject<T>(obj: {
632 [k: string]: T;
633 }): ImmutableTree<T>;
634 constructor(value: T | null, children?: SortedMap<string, ImmutableTree<T>>);
635 /**
636 * True if the value is empty and there are no children
637 */
638 isEmpty(): boolean;
639 /**
640 * Given a path and predicate, return the first node and the path to that node
641 * where the predicate returns true.
642 *
643 * TODO Do a perf test -- If we're creating a bunch of `{path: value:}`
644 * objects on the way back out, it may be better to pass down a pathSoFar obj.
645 *
646 * @param relativePath - The remainder of the path
647 * @param predicate - The predicate to satisfy to return a node
648 */
649 findRootMostMatchingPathAndValue(relativePath: Path, predicate: (a: T) => boolean): {
650 path: Path;
651 value: T;
652 } | null;
653 /**
654 * Find, if it exists, the shortest subpath of the given path that points a defined
655 * value in the tree
656 */
657 findRootMostValueAndPath(relativePath: Path): {
658 path: Path;
659 value: T;
660 } | null;
661 /**
662 * @returns The subtree at the given path
663 */
664 subtree(relativePath: Path): ImmutableTree<T>;
665 /**
666 * Sets a value at the specified path.
667 *
668 * @param relativePath - Path to set value at.
669 * @param toSet - Value to set.
670 * @returns Resulting tree.
671 */
672 set(relativePath: Path, toSet: T | null): ImmutableTree<T>;
673 /**
674 * Removes the value at the specified path.
675 *
676 * @param relativePath - Path to value to remove.
677 * @returns Resulting tree.
678 */
679 remove(relativePath: Path): ImmutableTree<T>;
680 /**
681 * Gets a value from the tree.
682 *
683 * @param relativePath - Path to get value for.
684 * @returns Value at path, or null.
685 */
686 get(relativePath: Path): T | null;
687 /**
688 * Replace the subtree at the specified path with the given new tree.
689 *
690 * @param relativePath - Path to replace subtree for.
691 * @param newTree - New tree.
692 * @returns Resulting tree.
693 */
694 setTree(relativePath: Path, newTree: ImmutableTree<T>): ImmutableTree<T>;
695 /**
696 * Performs a depth first fold on this tree. Transforms a tree into a single
697 * value, given a function that operates on the path to a node, an optional
698 * current value, and a map of child names to folded subtrees
699 */
700 fold<V>(fn: (path: Path, value: T, children: {
701 [k: string]: V;
702 }) => V): V;
703 /**
704 * Recursive helper for public-facing fold() method
705 */
706 private fold_;
707 /**
708 * Find the first matching value on the given path. Return the result of applying f to it.
709 */
710 findOnPath<V>(path: Path, f: (path: Path, value: T) => V | null): V | null;
711 private findOnPath_;
712 foreachOnPath(path: Path, f: (path: Path, value: T) => void): ImmutableTree<T>;
713 private foreachOnPath_;
714 /**
715 * Calls the given function for each node in the tree that has a value.
716 *
717 * @param f - A function to be called with the path from the root of the tree to
718 * a node, and the value at that node. Called in depth-first order.
719 */
720 foreach(f: (path: Path, value: T) => void): void;
721 private foreach_;
722 foreachChild(f: (name: string, value: T) => void): void;
723}
724
725/**
726 * Returns a placeholder value that can be used to atomically increment the
727 * current database value by the provided delta.
728 *
729 * @param delta - the amount to modify the current value atomically.
730 * @returns A placeholder value for modifying data atomically server-side.
731 */
732export declare function increment(delta: number): object;
733
734declare abstract class Index {
735 abstract compare(a: NamedNode, b: NamedNode): number;
736 abstract isDefinedOn(node: Node_2): boolean;
737 /**
738 * @returns A standalone comparison function for
739 * this index
740 */
741 getCompare(): Comparator<NamedNode>;
742 /**
743 * Given a before and after value for a node, determine if the indexed value has changed. Even if they are different,
744 * it's possible that the changes are isolated to parts of the snapshot that are not indexed.
745 *
746 *
747 * @returns True if the portion of the snapshot being indexed changed between oldNode and newNode
748 */
749 indexedValueChanged(oldNode: Node_2, newNode: Node_2): boolean;
750 /**
751 * @returns a node wrapper that will sort equal to or less than
752 * any other node wrapper, using this index
753 */
754 minPost(): NamedNode;
755 /**
756 * @returns a node wrapper that will sort greater than or equal to
757 * any other node wrapper, using this index
758 */
759 abstract maxPost(): NamedNode;
760 abstract makePost(indexValue: unknown, name: string): NamedNode;
761 /**
762 * @returns String representation for inclusion in a query spec
763 */
764 abstract toString(): string;
765}
766
767/**
768 * Creates a new `QueryConstraint` that if limited to the first specific number
769 * of children.
770 *
771 * The `limitToFirst()` method is used to set a maximum number of children to be
772 * synced for a given callback. If we set a limit of 100, we will initially only
773 * receive up to 100 `child_added` events. If we have fewer than 100 messages
774 * stored in our Database, a `child_added` event will fire for each message.
775 * However, if we have over 100 messages, we will only receive a `child_added`
776 * event for the first 100 ordered messages. As items change, we will receive
777 * `child_removed` events for each item that drops out of the active list so
778 * that the total number stays at 100.
779 *
780 * You can read more about `limitToFirst()` in
781 * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
782 *
783 * @param limit - The maximum number of nodes to include in this query.
784 */
785export declare function limitToFirst(limit: number): QueryConstraint;
786
787/**
788 * Creates a new `QueryConstraint` that is limited to return only the last
789 * specified number of children.
790 *
791 * The `limitToLast()` method is used to set a maximum number of children to be
792 * synced for a given callback. If we set a limit of 100, we will initially only
793 * receive up to 100 `child_added` events. If we have fewer than 100 messages
794 * stored in our Database, a `child_added` event will fire for each message.
795 * However, if we have over 100 messages, we will only receive a `child_added`
796 * event for the last 100 ordered messages. As items change, we will receive
797 * `child_removed` events for each item that drops out of the active list so
798 * that the total number stays at 100.
799 *
800 * You can read more about `limitToLast()` in
801 * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
802 *
803 * @param limit - The maximum number of nodes to include in this query.
804 */
805export declare function limitToLast(limit: number): QueryConstraint;
806
807/** An options objects that can be used to customize a listener. */
808export declare interface ListenOptions {
809 /** Whether to remove the listener after its first invocation. */
810 readonly onlyOnce?: boolean;
811}
812
813declare interface ListenProvider {
814 startListening(query: QueryContext, tag: number | null, hashFn: () => string, onComplete: (a: string, b?: unknown) => Event_2[]): Event_2[];
815 stopListening(a: QueryContext, b: number | null): void;
816}
817
818/**
819 * Represents an empty node (a leaf node in the Red-Black Tree).
820 */
821declare class LLRBEmptyNode<K, V> {
822 key: K;
823 value: V;
824 left: LLRBNode<K, V> | LLRBEmptyNode<K, V>;
825 right: LLRBNode<K, V> | LLRBEmptyNode<K, V>;
826 color: boolean;
827 /**
828 * Returns a copy of the current node.
829 *
830 * @returns The node copy.
831 */
832 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>;
833 /**
834 * Returns a copy of the tree, with the specified key/value added.
835 *
836 * @param key - Key to be added.
837 * @param value - Value to be added.
838 * @param comparator - Comparator.
839 * @returns New tree, with item added.
840 */
841 insert(key: K, value: V, comparator: Comparator<K>): LLRBNode<K, V>;
842 /**
843 * Returns a copy of the tree, with the specified key removed.
844 *
845 * @param key - The key to remove.
846 * @param comparator - Comparator.
847 * @returns New tree, with item removed.
848 */
849 remove(key: K, comparator: Comparator<K>): LLRBEmptyNode<K, V>;
850 /**
851 * @returns The total number of nodes in the tree.
852 */
853 count(): number;
854 /**
855 * @returns True if the tree is empty.
856 */
857 isEmpty(): boolean;
858 /**
859 * Traverses the tree in key order and calls the specified action function
860 * for each node.
861 *
862 * @param action - Callback function to be called for each
863 * node. If it returns true, traversal is aborted.
864 * @returns True if traversal was aborted.
865 */
866 inorderTraversal(action: (k: K, v: V) => unknown): boolean;
867 /**
868 * Traverses the tree in reverse key order and calls the specified action function
869 * for each node.
870 *
871 * @param action - Callback function to be called for each
872 * node. If it returns true, traversal is aborted.
873 * @returns True if traversal was aborted.
874 */
875 reverseTraversal(action: (k: K, v: V) => void): boolean;
876 minKey(): null;
877 maxKey(): null;
878 check_(): number;
879 /**
880 * @returns Whether this node is red.
881 */
882 isRed_(): boolean;
883}
884
885/**
886 * Represents a node in a Left-leaning Red-Black tree.
887 */
888declare class LLRBNode<K, V> {
889 key: K;
890 value: V;
891 color: boolean;
892 left: LLRBNode<K, V> | LLRBEmptyNode<K, V>;
893 right: LLRBNode<K, V> | LLRBEmptyNode<K, V>;
894 /**
895 * @param key - Key associated with this node.
896 * @param value - Value associated with this node.
897 * @param color - Whether this node is red.
898 * @param left - Left child.
899 * @param right - Right child.
900 */
901 constructor(key: K, value: V, color: boolean | null, left?: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null, right?: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null);
902 static RED: boolean;
903 static BLACK: boolean;
904 /**
905 * Returns a copy of the current node, optionally replacing pieces of it.
906 *
907 * @param key - New key for the node, or null.
908 * @param value - New value for the node, or null.
909 * @param color - New color for the node, or null.
910 * @param left - New left child for the node, or null.
911 * @param right - New right child for the node, or null.
912 * @returns The node copy.
913 */
914 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>;
915 /**
916 * @returns The total number of nodes in the tree.
917 */
918 count(): number;
919 /**
920 * @returns True if the tree is empty.
921 */
922 isEmpty(): boolean;
923 /**
924 * Traverses the tree in key order and calls the specified action function
925 * for each node.
926 *
927 * @param action - Callback function to be called for each
928 * node. If it returns true, traversal is aborted.
929 * @returns The first truthy value returned by action, or the last falsey
930 * value returned by action
931 */
932 inorderTraversal(action: (k: K, v: V) => unknown): boolean;
933 /**
934 * Traverses the tree in reverse key order and calls the specified action function
935 * for each node.
936 *
937 * @param action - Callback function to be called for each
938 * node. If it returns true, traversal is aborted.
939 * @returns True if traversal was aborted.
940 */
941 reverseTraversal(action: (k: K, v: V) => void): boolean;
942 /**
943 * @returns The minimum node in the tree.
944 */
945 private min_;
946 /**
947 * @returns The maximum key in the tree.
948 */
949 minKey(): K;
950 /**
951 * @returns The maximum key in the tree.
952 */
953 maxKey(): K;
954 /**
955 * @param key - Key to insert.
956 * @param value - Value to insert.
957 * @param comparator - Comparator.
958 * @returns New tree, with the key/value added.
959 */
960 insert(key: K, value: V, comparator: Comparator<K>): LLRBNode<K, V>;
961 /**
962 * @returns New tree, with the minimum key removed.
963 */
964 private removeMin_;
965 /**
966 * @param key - The key of the item to remove.
967 * @param comparator - Comparator.
968 * @returns New tree, with the specified item removed.
969 */
970 remove(key: K, comparator: Comparator<K>): LLRBNode<K, V> | LLRBEmptyNode<K, V>;
971 /**
972 * @returns Whether this is a RED node.
973 */
974 isRed_(): boolean;
975 /**
976 * @returns New tree after performing any needed rotations.
977 */
978 private fixUp_;
979 /**
980 * @returns New tree, after moveRedLeft.
981 */
982 private moveRedLeft_;
983 /**
984 * @returns New tree, after moveRedRight.
985 */
986 private moveRedRight_;
987 /**
988 * @returns New tree, after rotateLeft.
989 */
990 private rotateLeft_;
991 /**
992 * @returns New tree, after rotateRight.
993 */
994 private rotateRight_;
995 /**
996 * @returns Newt ree, after colorFlip.
997 */
998 private colorFlip_;
999 /**
1000 * For testing.
1001 *
1002 * @returns True if all is well.
1003 */
1004 private checkMaxDepth_;
1005 check_(): number;
1006}
1007
1008declare class NamedNode {
1009 name: string;
1010 node: Node_2;
1011 constructor(name: string, node: Node_2);
1012 static Wrap(name: string, node: Node_2): NamedNode;
1013}
1014
1015/**
1016 * Node is an interface defining the common functionality for nodes in
1017 * a DataSnapshot.
1018 *
1019 * @interface
1020 */
1021declare interface Node_2 {
1022 /**
1023 * Whether this node is a leaf node.
1024 * @returns Whether this is a leaf node.
1025 */
1026 isLeafNode(): boolean;
1027 /**
1028 * Gets the priority of the node.
1029 * @returns The priority of the node.
1030 */
1031 getPriority(): Node_2;
1032 /**
1033 * Returns a duplicate node with the new priority.
1034 * @param newPriorityNode - New priority to set for the node.
1035 * @returns Node with new priority.
1036 */
1037 updatePriority(newPriorityNode: Node_2): Node_2;
1038 /**
1039 * Returns the specified immediate child, or null if it doesn't exist.
1040 * @param childName - The name of the child to retrieve.
1041 * @returns The retrieved child, or an empty node.
1042 */
1043 getImmediateChild(childName: string): Node_2;
1044 /**
1045 * Returns a child by path, or null if it doesn't exist.
1046 * @param path - The path of the child to retrieve.
1047 * @returns The retrieved child or an empty node.
1048 */
1049 getChild(path: Path): Node_2;
1050 /**
1051 * Returns the name of the child immediately prior to the specified childNode, or null.
1052 * @param childName - The name of the child to find the predecessor of.
1053 * @param childNode - The node to find the predecessor of.
1054 * @param index - The index to use to determine the predecessor
1055 * @returns The name of the predecessor child, or null if childNode is the first child.
1056 */
1057 getPredecessorChildName(childName: string, childNode: Node_2, index: Index): string | null;
1058 /**
1059 * Returns a duplicate node, with the specified immediate child updated.
1060 * Any value in the node will be removed.
1061 * @param childName - The name of the child to update.
1062 * @param newChildNode - The new child node
1063 * @returns The updated node.
1064 */
1065 updateImmediateChild(childName: string, newChildNode: Node_2): Node_2;
1066 /**
1067 * Returns a duplicate node, with the specified child updated. Any value will
1068 * be removed.
1069 * @param path - The path of the child to update.
1070 * @param newChildNode - The new child node, which may be an empty node
1071 * @returns The updated node.
1072 */
1073 updateChild(path: Path, newChildNode: Node_2): Node_2;
1074 /**
1075 * True if the immediate child specified exists
1076 */
1077 hasChild(childName: string): boolean;
1078 /**
1079 * @returns True if this node has no value or children.
1080 */
1081 isEmpty(): boolean;
1082 /**
1083 * @returns The number of children of this node.
1084 */
1085 numChildren(): number;
1086 /**
1087 * Calls action for each child.
1088 * @param action - Action to be called for
1089 * each child. It's passed the child name and the child node.
1090 * @returns The first truthy value return by action, or the last falsey one
1091 */
1092 forEachChild(index: Index, action: (a: string, b: Node_2) => void): unknown;
1093 /**
1094 * @param exportFormat - True for export format (also wire protocol format).
1095 * @returns Value of this node as JSON.
1096 */
1097 val(exportFormat?: boolean): unknown;
1098 /**
1099 * @returns hash representing the node contents.
1100 */
1101 hash(): string;
1102 /**
1103 * @param other - Another node
1104 * @returns -1 for less than, 0 for equal, 1 for greater than other
1105 */
1106 compareTo(other: Node_2): number;
1107 /**
1108 * @returns Whether or not this snapshot equals other
1109 */
1110 equals(other: Node_2): boolean;
1111 /**
1112 * @returns This node, with the specified index now available
1113 */
1114 withIndex(indexDefinition: Index): Node_2;
1115 isIndexed(indexDefinition: Index): boolean;
1116}
1117
1118/**
1119 * NodeFilter is used to update nodes and complete children of nodes while applying queries on the fly and keeping
1120 * track of any child changes. This class does not track value changes as value changes depend on more
1121 * than just the node itself. Different kind of queries require different kind of implementations of this interface.
1122 * @interface
1123 */
1124declare interface NodeFilter_2 {
1125 /**
1126 * Update a single complete child in the snap. If the child equals the old child in the snap, this is a no-op.
1127 * The method expects an indexed snap.
1128 */
1129 updateChild(snap: Node_2, key: string, newChild: Node_2, affectedPath: Path, source: CompleteChildSource, optChangeAccumulator: ChildChangeAccumulator | null): Node_2;
1130 /**
1131 * Update a node in full and output any resulting change from this complete update.
1132 */
1133 updateFullNode(oldSnap: Node_2, newSnap: Node_2, optChangeAccumulator: ChildChangeAccumulator | null): Node_2;
1134 /**
1135 * Update the priority of the root node
1136 */
1137 updatePriority(oldSnap: Node_2, newPriority: Node_2): Node_2;
1138 /**
1139 * Returns true if children might be filtered due to query criteria
1140 */
1141 filtersNodes(): boolean;
1142 /**
1143 * Returns the index filter that this filter uses to get a NodeFilter that doesn't filter any children.
1144 */
1145 getIndexedFilter(): NodeFilter_2;
1146 /**
1147 * Returns the index that this filter uses
1148 */
1149 getIndex(): Index;
1150}
1151
1152/**
1153 * Detaches a callback previously attached with `on()`.
1154 *
1155 * Detach a callback previously attached with `on()`. Note that if `on()` was
1156 * called multiple times with the same eventType and callback, the callback
1157 * will be called multiple times for each event, and `off()` must be called
1158 * multiple times to remove the callback. 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 * </br>See {@link ttps://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/**
2067 * @internal
2068 */
2069export declare class _QueryImpl implements Query, QueryContext {
2070 readonly _repo: Repo;
2071 readonly _path: Path;
2072 readonly _queryParams: _QueryParams;
2073 readonly _orderByCalled: boolean;
2074 /**
2075 * @hideconstructor
2076 */
2077 constructor(_repo: Repo, _path: Path, _queryParams: _QueryParams, _orderByCalled: boolean);
2078 get key(): string | null;
2079 get ref(): DatabaseReference;
2080 get _queryIdentifier(): string;
2081 /**
2082 * An object representation of the query parameters used by this Query.
2083 */
2084 get _queryObject(): object;
2085 isEqual(other: _QueryImpl | null): boolean;
2086 toJSON(): string;
2087 toString(): string;
2088}
2089
2090/**
2091 * This class is an immutable-from-the-public-api struct containing a set of query parameters defining a
2092 * range to be returned for a particular location. It is assumed that validation of parameters is done at the
2093 * user-facing API level, so it is not done here.
2094 *
2095 * @internal
2096 */
2097export declare class _QueryParams {
2098 limitSet_: boolean;
2099 startSet_: boolean;
2100 startNameSet_: boolean;
2101 startAfterSet_: boolean;
2102 endSet_: boolean;
2103 endNameSet_: boolean;
2104 endBeforeSet_: boolean;
2105 limit_: number;
2106 viewFrom_: string;
2107 indexStartValue_: unknown | null;
2108 indexStartName_: string;
2109 indexEndValue_: unknown | null;
2110 indexEndName_: string;
2111 index_: PriorityIndex;
2112 hasStart(): boolean;
2113 hasStartAfter(): boolean;
2114 hasEndBefore(): boolean;
2115 /**
2116 * @returns True if it would return from left.
2117 */
2118 isViewFromLeft(): boolean;
2119 /**
2120 * Only valid to call if hasStart() returns true
2121 */
2122 getIndexStartValue(): unknown;
2123 /**
2124 * Only valid to call if hasStart() returns true.
2125 * Returns the starting key name for the range defined by these query parameters
2126 */
2127 getIndexStartName(): string;
2128 hasEnd(): boolean;
2129 /**
2130 * Only valid to call if hasEnd() returns true.
2131 */
2132 getIndexEndValue(): unknown;
2133 /**
2134 * Only valid to call if hasEnd() returns true.
2135 * Returns the end key name for the range defined by these query parameters
2136 */
2137 getIndexEndName(): string;
2138 hasLimit(): boolean;
2139 /**
2140 * @returns True if a limit has been set and it has been explicitly anchored
2141 */
2142 hasAnchoredLimit(): boolean;
2143 /**
2144 * Only valid to call if hasLimit() returns true
2145 */
2146 getLimit(): number;
2147 getIndex(): Index;
2148 loadsAllData(): boolean;
2149 isDefault(): boolean;
2150 copy(): _QueryParams;
2151}
2152
2153/**
2154 *
2155 * Returns a `Reference` representing the location in the Database
2156 * corresponding to the provided path. If no path is provided, the `Reference`
2157 * will point to the root of the Database.
2158 *
2159 * @param db - The database instance to obtain a reference for.
2160 * @param path - Optional path representing the location the returned
2161 * `Reference` will point. If not provided, the returned `Reference` will
2162 * point to the root of the Database.
2163 * @returns If a path is provided, a `Reference`
2164 * pointing to the provided path. Otherwise, a `Reference` pointing to the
2165 * root of the Database.
2166 */
2167export declare function ref(db: Database, path?: string): DatabaseReference;
2168
2169/**
2170 * @internal
2171 */
2172export declare class _ReferenceImpl extends _QueryImpl implements DatabaseReference {
2173 /** @hideconstructor */
2174 constructor(repo: Repo, path: Path);
2175 get parent(): _ReferenceImpl | null;
2176 get root(): _ReferenceImpl;
2177}
2178
2179/**
2180 * Returns a `Reference` representing the location in the Database
2181 * corresponding to the provided Firebase URL.
2182 *
2183 * An exception is thrown if the URL is not a valid Firebase Database URL or it
2184 * has a different domain than the current `Database` instance.
2185 *
2186 * Note that all query parameters (`orderBy`, `limitToLast`, etc.) are ignored
2187 * and are not applied to the returned `Reference`.
2188 *
2189 * @param db - The database instance to obtain a reference for.
2190 * @param url - The Firebase URL at which the returned `Reference` will
2191 * point.
2192 * @returns A `Reference` pointing to the provided
2193 * Firebase URL.
2194 */
2195export declare function refFromURL(db: Database, url: string): DatabaseReference;
2196
2197/**
2198 * Removes the data at this Database location.
2199 *
2200 * Any data at child locations will also be deleted.
2201 *
2202 * The effect of the remove will be visible immediately and the corresponding
2203 * event 'value' will be triggered. Synchronization of the remove to the
2204 * Firebase servers will also be started, and the returned Promise will resolve
2205 * when complete. If provided, the onComplete callback will be called
2206 * asynchronously after synchronization has finished.
2207 *
2208 * @param ref - The location to remove.
2209 * @returns Resolves when remove on server is complete.
2210 */
2211export declare function remove(ref: DatabaseReference): Promise<void>;
2212
2213/**
2214 * A connection to a single data repository.
2215 */
2216declare class Repo {
2217 repoInfo_: RepoInfo;
2218 forceRestClient_: boolean;
2219 authTokenProvider_: AuthTokenProvider;
2220 appCheckProvider_: AppCheckTokenProvider;
2221 /** Key for uniquely identifying this repo, used in RepoManager */
2222 readonly key: string;
2223 dataUpdateCount: number;
2224 infoSyncTree_: SyncTree;
2225 serverSyncTree_: SyncTree;
2226 stats_: StatsCollection;
2227 statsListener_: StatsListener | null;
2228 eventQueue_: EventQueue;
2229 nextWriteId_: number;
2230 server_: ServerActions;
2231 statsReporter_: StatsReporter;
2232 infoData_: SnapshotHolder;
2233 interceptServerDataCallback_: ((a: string, b: unknown) => void) | null;
2234 /** A list of data pieces and paths to be set when this client disconnects. */
2235 onDisconnect_: SparseSnapshotTree;
2236 /** Stores queues of outstanding transactions for Firebase locations. */
2237 transactionQueueTree_: Tree<Transaction[]>;
2238 persistentConnection_: PersistentConnection | null;
2239 constructor(repoInfo_: RepoInfo, forceRestClient_: boolean, authTokenProvider_: AuthTokenProvider, appCheckProvider_: AppCheckTokenProvider);
2240 /**
2241 * @returns The URL corresponding to the root of this Firebase.
2242 */
2243 toString(): string;
2244}
2245
2246/**
2247 * @license
2248 * Copyright 2017 Google LLC
2249 *
2250 * Licensed under the Apache License, Version 2.0 (the "License");
2251 * you may not use this file except in compliance with the License.
2252 * You may obtain a copy of the License at
2253 *
2254 * http://www.apache.org/licenses/LICENSE-2.0
2255 *
2256 * Unless required by applicable law or agreed to in writing, software
2257 * distributed under the License is distributed on an "AS IS" BASIS,
2258 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2259 * See the License for the specific language governing permissions and
2260 * limitations under the License.
2261 */
2262/**
2263 * A class that holds metadata about a Repo object
2264 */
2265declare class RepoInfo {
2266 readonly secure: boolean;
2267 readonly namespace: string;
2268 readonly webSocketOnly: boolean;
2269 readonly nodeAdmin: boolean;
2270 readonly persistenceKey: string;
2271 readonly includeNamespaceInQueryParams: boolean;
2272 private _host;
2273 private _domain;
2274 internalHost: string;
2275 /**
2276 * @param host - Hostname portion of the url for the repo
2277 * @param secure - Whether or not this repo is accessed over ssl
2278 * @param namespace - The namespace represented by the repo
2279 * @param webSocketOnly - Whether to prefer websockets over all other transports (used by Nest).
2280 * @param nodeAdmin - Whether this instance uses Admin SDK credentials
2281 * @param persistenceKey - Override the default session persistence storage key
2282 */
2283 constructor(host: string, secure: boolean, namespace: string, webSocketOnly: boolean, nodeAdmin?: boolean, persistenceKey?: string, includeNamespaceInQueryParams?: boolean);
2284 isCacheableHost(): boolean;
2285 isCustomHost(): boolean;
2286 get host(): string;
2287 set host(newHost: string);
2288 toString(): string;
2289 toURLString(): string;
2290}
2291
2292/**
2293 * This function should only ever be called to CREATE a new database instance.
2294 * @internal
2295 */
2296export declare function _repoManagerDatabaseFromApp(app: FirebaseApp, authProvider: Provider<FirebaseAuthInternalName>, appCheckProvider?: Provider<AppCheckInternalComponentName>, url?: string, nodeAdmin?: boolean): Database;
2297
2298/**
2299 * Atomically modifies the data at this location.
2300 *
2301 * Atomically modify the data at this location. Unlike a normal `set()`, which
2302 * just overwrites the data regardless of its previous value, `runTransaction()` is
2303 * used to modify the existing value to a new value, ensuring there are no
2304 * conflicts with other clients writing to the same location at the same time.
2305 *
2306 * To accomplish this, you pass `runTransaction()` an update function which is
2307 * used to transform the current value into a new value. If another client
2308 * writes to the location before your new value is successfully written, your
2309 * update function will be called again with the new current value, and the
2310 * write will be retried. This will happen repeatedly until your write succeeds
2311 * without conflict or you abort the transaction by not returning a value from
2312 * your update function.
2313 *
2314 * Note: Modifying data with `set()` will cancel any pending transactions at
2315 * that location, so extreme care should be taken if mixing `set()` and
2316 * `runTransaction()` to update the same data.
2317 *
2318 * Note: When using transactions with Security and Firebase Rules in place, be
2319 * aware that a client needs `.read` access in addition to `.write` access in
2320 * order to perform a transaction. This is because the client-side nature of
2321 * transactions requires the client to read the data in order to transactionally
2322 * update it.
2323 *
2324 * @param ref - The location to atomically modify.
2325 * @param transactionUpdate - A developer-supplied function which will be passed
2326 * the current data stored at this location (as a JavaScript object). The
2327 * function should return the new value it would like written (as a JavaScript
2328 * object). If `undefined` is returned (i.e. you return with no arguments) the
2329 * transaction will be aborted and the data at this location will not be
2330 * modified.
2331 * @param options - An options object to configure transactions.
2332 * @returns A `Promise` that can optionally be used instead of the `onComplete`
2333 * callback to handle success and failure.
2334 */
2335export declare function runTransaction(ref: DatabaseReference, transactionUpdate: (currentData: any) => unknown, options?: TransactionOptions): Promise<TransactionResult>;
2336
2337/**
2338 * Interface defining the set of actions that can be performed against the Firebase server
2339 * (basically corresponds to our wire protocol).
2340 *
2341 * @interface
2342 */
2343declare abstract class ServerActions {
2344 abstract listen(query: QueryContext, currentHashFn: () => string, tag: number | null, onComplete: (a: string, b: unknown) => void): void;
2345 /**
2346 * Remove a listen.
2347 */
2348 abstract unlisten(query: QueryContext, tag: number | null): void;
2349 /**
2350 * Get the server value satisfying this query.
2351 */
2352 abstract get(query: QueryContext): Promise<string>;
2353 put(pathString: string, data: unknown, onComplete?: (a: string, b: string) => void, hash?: string): void;
2354 merge(pathString: string, data: unknown, onComplete: (a: string, b: string | null) => void, hash?: string): void;
2355 /**
2356 * Refreshes the auth token for the current connection.
2357 * @param token - The authentication token
2358 */
2359 refreshAuthToken(token: string): void;
2360 /**
2361 * Refreshes the app check token for the current connection.
2362 * @param token The app check token
2363 */
2364 refreshAppCheckToken(token: string): void;
2365 onDisconnectPut(pathString: string, data: unknown, onComplete?: (a: string, b: string) => void): void;
2366 onDisconnectMerge(pathString: string, data: unknown, onComplete?: (a: string, b: string) => void): void;
2367 onDisconnectCancel(pathString: string, onComplete?: (a: string, b: string) => void): void;
2368 reportStats(stats: {
2369 [k: string]: unknown;
2370 }): void;
2371}
2372
2373/**
2374 * @license
2375 * Copyright 2020 Google LLC
2376 *
2377 * Licensed under the Apache License, Version 2.0 (the "License");
2378 * you may not use this file except in compliance with the License.
2379 * You may obtain a copy of the License at
2380 *
2381 * http://www.apache.org/licenses/LICENSE-2.0
2382 *
2383 * Unless required by applicable law or agreed to in writing, software
2384 * distributed under the License is distributed on an "AS IS" BASIS,
2385 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2386 * See the License for the specific language governing permissions and
2387 * limitations under the License.
2388 */
2389/**
2390 * Returns a placeholder value for auto-populating the current timestamp (time
2391 * since the Unix epoch, in milliseconds) as determined by the Firebase
2392 * servers.
2393 */
2394export declare function serverTimestamp(): object;
2395
2396/**
2397 * Writes data to this Database location.
2398 *
2399 * This will overwrite any data at this location and all child locations.
2400 *
2401 * The effect of the write will be visible immediately, and the corresponding
2402 * events ("value", "child_added", etc.) will be triggered. Synchronization of
2403 * the data to the Firebase servers will also be started, and the returned
2404 * Promise will resolve when complete. If provided, the `onComplete` callback
2405 * will be called asynchronously after synchronization has finished.
2406 *
2407 * Passing `null` for the new value is equivalent to calling `remove()`; namely,
2408 * all data at this location and all child locations will be deleted.
2409 *
2410 * `set()` will remove any priority stored at this location, so if priority is
2411 * meant to be preserved, you need to use `setWithPriority()` instead.
2412 *
2413 * Note that modifying data with `set()` will cancel any pending transactions
2414 * at that location, so extreme care should be taken if mixing `set()` and
2415 * `transaction()` to modify the same data.
2416 *
2417 * A single `set()` will generate a single "value" event at the location where
2418 * the `set()` was performed.
2419 *
2420 * @param ref - The location to write to.
2421 * @param value - The value to be written (string, number, boolean, object,
2422 * array, or null).
2423 * @returns Resolves when write to server is complete.
2424 */
2425export declare function set(ref: DatabaseReference, value: unknown): Promise<void>;
2426
2427/**
2428 * Sets a priority for the data at this Database location.
2429 *
2430 * Applications need not use priority but can order collections by
2431 * ordinary properties (see
2432 * {@link https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data | Sorting and filtering data}
2433 * ).
2434 *
2435 * @param ref - The location to write to.
2436 * @param priority - The priority to be written (string, number, or null).
2437 * @returns Resolves when write to server is complete.
2438 */
2439export declare function setPriority(ref: DatabaseReference, priority: string | number | null): Promise<void>;
2440
2441/**
2442 * SDK_VERSION should be set before any database instance is created
2443 * @internal
2444 */
2445export declare function _setSDKVersion(version: string): void;
2446
2447/**
2448 * Writes data the Database location. Like `set()` but also specifies the
2449 * priority for that data.
2450 *
2451 * Applications need not use priority but can order collections by
2452 * ordinary properties (see
2453 * {@link https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data | Sorting and filtering data}
2454 * ).
2455 *
2456 * @param ref - The location to write to.
2457 * @param value - The value to be written (string, number, boolean, object,
2458 * array, or null).
2459 * @param priority - The priority to be written (string, number, or null).
2460 * @returns Resolves when write to server is complete.
2461 */
2462export declare function setWithPriority(ref: DatabaseReference, value: unknown, priority: string | number | null): Promise<void>;
2463
2464/**
2465 * Mutable object which basically just stores a reference to the "latest" immutable snapshot.
2466 */
2467declare class SnapshotHolder {
2468 private rootNode_;
2469 getNode(path: Path): Node_2;
2470 updateSnapshot(path: Path, newSnapshotNode: Node_2): void;
2471}
2472
2473/**
2474 * An immutable sorted map implementation, based on a Left-leaning Red-Black
2475 * tree.
2476 */
2477declare class SortedMap<K, V> {
2478 private comparator_;
2479 private root_;
2480 /**
2481 * Always use the same empty node, to reduce memory.
2482 */
2483 static EMPTY_NODE: LLRBEmptyNode<unknown, unknown>;
2484 /**
2485 * @param comparator_ - Key comparator.
2486 * @param root_ - Optional root node for the map.
2487 */
2488 constructor(comparator_: Comparator<K>, root_?: LLRBNode<K, V> | LLRBEmptyNode<K, V>);
2489 /**
2490 * Returns a copy of the map, with the specified key/value added or replaced.
2491 * (TODO: We should perhaps rename this method to 'put')
2492 *
2493 * @param key - Key to be added.
2494 * @param value - Value to be added.
2495 * @returns New map, with item added.
2496 */
2497 insert(key: K, value: V): SortedMap<K, V>;
2498 /**
2499 * Returns a copy of the map, with the specified key removed.
2500 *
2501 * @param key - The key to remove.
2502 * @returns New map, with item removed.
2503 */
2504 remove(key: K): SortedMap<K, V>;
2505 /**
2506 * Returns the value of the node with the given key, or null.
2507 *
2508 * @param key - The key to look up.
2509 * @returns The value of the node with the given key, or null if the
2510 * key doesn't exist.
2511 */
2512 get(key: K): V | null;
2513 /**
2514 * Returns the key of the item *before* the specified key, or null if key is the first item.
2515 * @param key - The key to find the predecessor of
2516 * @returns The predecessor key.
2517 */
2518 getPredecessorKey(key: K): K | null;
2519 /**
2520 * @returns True if the map is empty.
2521 */
2522 isEmpty(): boolean;
2523 /**
2524 * @returns The total number of nodes in the map.
2525 */
2526 count(): number;
2527 /**
2528 * @returns The minimum key in the map.
2529 */
2530 minKey(): K | null;
2531 /**
2532 * @returns The maximum key in the map.
2533 */
2534 maxKey(): K | null;
2535 /**
2536 * Traverses the map in key order and calls the specified action function
2537 * for each key/value pair.
2538 *
2539 * @param action - Callback function to be called
2540 * for each key/value pair. If action returns true, traversal is aborted.
2541 * @returns The first truthy value returned by action, or the last falsey
2542 * value returned by action
2543 */
2544 inorderTraversal(action: (k: K, v: V) => unknown): boolean;
2545 /**
2546 * Traverses the map in reverse key order and calls the specified action function
2547 * for each key/value pair.
2548 *
2549 * @param action - Callback function to be called
2550 * for each key/value pair. If action returns true, traversal is aborted.
2551 * @returns True if the traversal was aborted.
2552 */
2553 reverseTraversal(action: (k: K, v: V) => void): boolean;
2554 /**
2555 * Returns an iterator over the SortedMap.
2556 * @returns The iterator.
2557 */
2558 getIterator<T>(resultGenerator?: (k: K, v: V) => T): SortedMapIterator<K, V, T>;
2559 getIteratorFrom<T>(key: K, resultGenerator?: (k: K, v: V) => T): SortedMapIterator<K, V, T>;
2560 getReverseIteratorFrom<T>(key: K, resultGenerator?: (k: K, v: V) => T): SortedMapIterator<K, V, T>;
2561 getReverseIterator<T>(resultGenerator?: (k: K, v: V) => T): SortedMapIterator<K, V, T>;
2562}
2563
2564/**
2565 * An iterator over an LLRBNode.
2566 */
2567declare class SortedMapIterator<K, V, T> {
2568 private isReverse_;
2569 private resultGenerator_;
2570 private nodeStack_;
2571 /**
2572 * @param node - Node to iterate.
2573 * @param isReverse_ - Whether or not to iterate in reverse
2574 */
2575 constructor(node: LLRBNode<K, V> | LLRBEmptyNode<K, V>, startKey: K | null, comparator: Comparator<K>, isReverse_: boolean, resultGenerator_?: ((k: K, v: V) => T) | null);
2576 getNext(): T;
2577 hasNext(): boolean;
2578 peek(): T;
2579}
2580
2581/**
2582 * Helper class to store a sparse set of snapshots.
2583 */
2584declare interface SparseSnapshotTree {
2585 value: Node_2 | null;
2586 readonly children: Map<string, SparseSnapshotTree>;
2587}
2588
2589/**
2590 * Creates a `QueryConstraint` with the specified starting point (exclusive).
2591 *
2592 * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
2593 * allows you to choose arbitrary starting and ending points for your queries.
2594 *
2595 * The starting point is exclusive. If only a value is provided, children
2596 * with a value greater than the specified value will be included in the query.
2597 * If a key is specified, then children must have a value greater than or equal
2598 * to the specified value and a a key name greater than the specified key.
2599 *
2600 * @param value - The value to start after. The argument type depends on which
2601 * `orderBy*()` function was used in this query. Specify a value that matches
2602 * the `orderBy*()` type. When used in combination with `orderByKey()`, the
2603 * value must be a string.
2604 * @param key - The child key to start after. This argument is only allowed if
2605 * ordering by child, value, or priority.
2606 */
2607export declare function startAfter(value: number | string | boolean | null, key?: string): QueryConstraint;
2608
2609/**
2610 * Creates a `QueryConstraint` with the specified starting point.
2611 *
2612 * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
2613 * allows you to choose arbitrary starting and ending points for your queries.
2614 *
2615 * The starting point is inclusive, so children with exactly the specified value
2616 * will be included in the query. The optional key argument can be used to
2617 * further limit the range of the query. If it is specified, then children that
2618 * have exactly the specified value must also have a key name greater than or
2619 * equal to the specified key.
2620 *
2621 * You can read more about `startAt()` in
2622 * {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}.
2623 *
2624 * @param value - The value to start at. The argument type depends on which
2625 * `orderBy*()` function was used in this query. Specify a value that matches
2626 * the `orderBy*()` type. When used in combination with `orderByKey()`, the
2627 * value must be a string.
2628 * @param key - The child key to start at. This argument is only allowed if
2629 * ordering by child, value, or priority.
2630 */
2631export declare function startAt(value?: number | string | boolean | null, key?: string): QueryConstraint;
2632
2633/**
2634 * @license
2635 * Copyright 2017 Google LLC
2636 *
2637 * Licensed under the Apache License, Version 2.0 (the "License");
2638 * you may not use this file except in compliance with the License.
2639 * You may obtain a copy of the License at
2640 *
2641 * http://www.apache.org/licenses/LICENSE-2.0
2642 *
2643 * Unless required by applicable law or agreed to in writing, software
2644 * distributed under the License is distributed on an "AS IS" BASIS,
2645 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2646 * See the License for the specific language governing permissions and
2647 * limitations under the License.
2648 */
2649/**
2650 * Tracks a collection of stats.
2651 */
2652declare class StatsCollection {
2653 private counters_;
2654 incrementCounter(name: string, amount?: number): void;
2655 get(): {
2656 [k: string]: number;
2657 };
2658}
2659
2660/**
2661 * Returns the delta from the previous call to get stats.
2662 *
2663 * @param collection_ - The collection to "listen" to.
2664 */
2665declare class StatsListener {
2666 private collection_;
2667 private last_;
2668 constructor(collection_: StatsCollection);
2669 get(): {
2670 [k: string]: number;
2671 };
2672}
2673
2674declare class StatsReporter {
2675 private server_;
2676 private statsListener_;
2677 statsToReport_: {
2678 [k: string]: boolean;
2679 };
2680 constructor(collection: StatsCollection, server_: ServerActions);
2681 private reportStats_;
2682}
2683
2684/**
2685 * SyncPoint represents a single location in a SyncTree with 1 or more event registrations, meaning we need to
2686 * maintain 1 or more Views at this location to cache server data and raise appropriate events for server changes
2687 * and user writes (set, transaction, update).
2688 *
2689 * It's responsible for:
2690 * - Maintaining the set of 1 or more views necessary at this location (a SyncPoint with 0 views should be removed).
2691 * - Proxying user / server operations to the views as appropriate (i.e. applyServerOverwrite,
2692 * applyUserOverwrite, etc.)
2693 */
2694declare class SyncPoint {
2695 /**
2696 * The Views being tracked at this location in the tree, stored as a map where the key is a
2697 * queryId and the value is the View for that query.
2698 *
2699 * NOTE: This list will be quite small (usually 1, but perhaps 2 or 3; any more is an odd use case).
2700 */
2701 readonly views: Map<string, View>;
2702}
2703
2704/**
2705 * SyncTree is the central class for managing event callback registration, data caching, views
2706 * (query processing), and event generation. There are typically two SyncTree instances for
2707 * each Repo, one for the normal Firebase data, and one for the .info data.
2708 *
2709 * It has a number of responsibilities, including:
2710 * - Tracking all user event callbacks (registered via addEventRegistration() and removeEventRegistration()).
2711 * - Applying and caching data changes for user set(), transaction(), and update() calls
2712 * (applyUserOverwrite(), applyUserMerge()).
2713 * - Applying and caching data changes for server data changes (applyServerOverwrite(),
2714 * applyServerMerge()).
2715 * - Generating user-facing events for server and user changes (all of the apply* methods
2716 * return the set of events that need to be raised as a result).
2717 * - Maintaining the appropriate set of server listens to ensure we are always subscribed
2718 * to the correct set of paths and queries to satisfy the current set of user event
2719 * callbacks (listens are started/stopped using the provided listenProvider).
2720 *
2721 * NOTE: Although SyncTree tracks event callbacks and calculates events to raise, the actual
2722 * events are returned to the caller rather than raised synchronously.
2723 *
2724 */
2725declare class SyncTree {
2726 listenProvider_: ListenProvider;
2727 /**
2728 * Tree of SyncPoints. There's a SyncPoint at any location that has 1 or more views.
2729 */
2730 syncPointTree_: ImmutableTree<SyncPoint>;
2731 /**
2732 * A tree of all pending user writes (user-initiated set()'s, transaction()'s, update()'s, etc.).
2733 */
2734 pendingWriteTree_: WriteTree;
2735 readonly tagToQueryMap: Map<number, string>;
2736 readonly queryToTagMap: Map<string, number>;
2737 /**
2738 * @param listenProvider_ - Used by SyncTree to start / stop listening
2739 * to server data.
2740 */
2741 constructor(listenProvider_: ListenProvider);
2742}
2743
2744/**
2745 * Forces the RepoManager to create Repos that use ReadonlyRestClient instead of PersistentConnection.
2746 * @internal
2747 */
2748export declare const _TEST_ACCESS_forceRestClient: (forceRestClient: boolean) => void;
2749
2750/**
2751 * @internal
2752 */
2753export declare const _TEST_ACCESS_hijackHash: (newHash: () => string) => () => void;
2754
2755/**
2756 * A `Promise` that can also act as a `DatabaseReference` when returned by
2757 * {@link push}. The reference is available immediately and the `Promise` resolves
2758 * as the write to the backend completes.
2759 */
2760export declare interface ThenableReference extends DatabaseReference, Pick<Promise<DatabaseReference>, 'then' | 'catch'> {
2761}
2762
2763declare interface Transaction {
2764 path: Path;
2765 update: (a: unknown) => unknown;
2766 onComplete: (error: Error | null, committed: boolean, node: Node_2 | null) => void;
2767 status: TransactionStatus;
2768 order: number;
2769 applyLocally: boolean;
2770 retryCount: number;
2771 unwatcher: () => void;
2772 abortReason: string | null;
2773 currentWriteId: number;
2774 currentInputSnapshot: Node_2 | null;
2775 currentOutputSnapshotRaw: Node_2 | null;
2776 currentOutputSnapshotResolved: Node_2 | null;
2777}
2778
2779/** An options object to configure transactions. */
2780export declare interface TransactionOptions {
2781 /**
2782 * By default, events are raised each time the transaction update function
2783 * runs. So if it is run multiple times, you may see intermediate states. You
2784 * can set this to false to suppress these intermediate states and instead
2785 * wait until the transaction has completed before events are raised.
2786 */
2787 readonly applyLocally?: boolean;
2788}
2789
2790/**
2791 * A type for the resolve value of {@link runTransaction}.
2792 */
2793export declare class TransactionResult {
2794 /** Whether the transaction was successfully committed. */
2795 readonly committed: boolean;
2796 /** The resulting data snapshot. */
2797 readonly snapshot: DataSnapshot;
2798 /** @hideconstructor */
2799 constructor(
2800 /** Whether the transaction was successfully committed. */
2801 committed: boolean,
2802 /** The resulting data snapshot. */
2803 snapshot: DataSnapshot);
2804 /** Returns a JSON-serializable representation of this object. */
2805 toJSON(): object;
2806}
2807
2808declare const enum TransactionStatus {
2809 RUN = 0,
2810 SENT = 1,
2811 COMPLETED = 2,
2812 SENT_NEEDS_ABORT = 3,
2813 NEEDS_ABORT = 4
2814}
2815
2816/**
2817 * A light-weight tree, traversable by path. Nodes can have both values and children.
2818 * Nodes are not enumerated (by forEachChild) unless they have a value or non-empty
2819 * children.
2820 */
2821declare class Tree<T> {
2822 readonly name: string;
2823 readonly parent: Tree<T> | null;
2824 node: TreeNode<T>;
2825 /**
2826 * @param name - Optional name of the node.
2827 * @param parent - Optional parent node.
2828 * @param node - Optional node to wrap.
2829 */
2830 constructor(name?: string, parent?: Tree<T> | null, node?: TreeNode<T>);
2831}
2832
2833/**
2834 * Node in a Tree.
2835 */
2836declare interface TreeNode<T> {
2837 children: Record<string, TreeNode<T>>;
2838 childCount: number;
2839 value?: T;
2840}
2841
2842/** A callback that can invoked to remove a listener. */
2843export declare type Unsubscribe = () => void;
2844
2845/**
2846 * Writes multiple values to the Database at once.
2847 *
2848 * The `values` argument contains multiple property-value pairs that will be
2849 * written to the Database together. Each child property can either be a simple
2850 * property (for example, "name") or a relative path (for example,
2851 * "name/first") from the current location to the data to update.
2852 *
2853 * As opposed to the `set()` method, `update()` can be use to selectively update
2854 * only the referenced properties at the current location (instead of replacing
2855 * all the child properties at the current location).
2856 *
2857 * The effect of the write will be visible immediately, and the corresponding
2858 * events ('value', 'child_added', etc.) will be triggered. Synchronization of
2859 * the data to the Firebase servers will also be started, and the returned
2860 * Promise will resolve when complete. If provided, the `onComplete` callback
2861 * will be called asynchronously after synchronization has finished.
2862 *
2863 * A single `update()` will generate a single "value" event at the location
2864 * where the `update()` was performed, regardless of how many children were
2865 * modified.
2866 *
2867 * Note that modifying data with `update()` will cancel any pending
2868 * transactions at that location, so extreme care should be taken if mixing
2869 * `update()` and `transaction()` to modify the same data.
2870 *
2871 * Passing `null` to `update()` will remove the data at this location.
2872 *
2873 * See
2874 * {@link https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html | Introducing multi-location updates and more}.
2875 *
2876 * @param ref - The location to write to.
2877 * @param values - Object containing multiple values.
2878 * @returns Resolves when update on server is complete.
2879 */
2880export declare function update(ref: DatabaseReference, values: object): Promise<void>;
2881
2882/**
2883 * A user callback. Callbacks issues from the Legacy SDK maintain references
2884 * to the original user-issued callbacks, which allows equality
2885 * comparison by reference even though this callbacks are wrapped before
2886 * they can be passed to the firebase@exp SDK.
2887 *
2888 * @internal
2889 */
2890export declare interface _UserCallback {
2891 (dataSnapshot: DataSnapshot, previousChildName?: string | null): unknown;
2892 userCallback?: unknown;
2893 context?: object | null;
2894}
2895
2896/**
2897 * @internal
2898 */
2899export declare const _validatePathString: (fnName: string, argumentName: string, pathString: string, optional: boolean) => void;
2900
2901/**
2902 * @internal
2903 */
2904export declare const _validateWritablePath: (fnName: string, path: Path) => void;
2905
2906/**
2907 * A view represents a specific location and query that has 1 or more event registrations.
2908 *
2909 * It does several things:
2910 * - Maintains the list of event registrations for this location/query.
2911 * - Maintains a cache of the data visible for this location/query.
2912 * - Applies new operations (via applyOperation), updates the cache, and based on the event
2913 * registrations returns the set of events to be raised.
2914 */
2915declare class View {
2916 private query_;
2917 processor_: ViewProcessor;
2918 viewCache_: ViewCache;
2919 eventRegistrations_: EventRegistration[];
2920 eventGenerator_: EventGenerator;
2921 constructor(query_: QueryContext, initialViewCache: ViewCache);
2922 get query(): QueryContext;
2923}
2924
2925/**
2926 * Stores the data we have cached for a view.
2927 *
2928 * serverSnap is the cached server data, eventSnap is the cached event data (server data plus any local writes).
2929 */
2930declare interface ViewCache {
2931 readonly eventCache: CacheNode;
2932 readonly serverCache: CacheNode;
2933}
2934
2935declare interface ViewProcessor {
2936 readonly filter: NodeFilter_2;
2937}
2938
2939/**
2940 * Defines a single user-initiated write operation. May be the result of a set(), transaction(), or update() call. In
2941 * the case of a set() or transaction, snap wil be non-null. In the case of an update(), children will be non-null.
2942 */
2943declare interface WriteRecord {
2944 writeId: number;
2945 path: Path;
2946 snap?: Node_2 | null;
2947 children?: {
2948 [k: string]: Node_2;
2949 } | null;
2950 visible: boolean;
2951}
2952
2953/**
2954 * WriteTree tracks all pending user-initiated writes and has methods to calculate the result of merging them
2955 * with underlying server data (to create "event cache" data). Pending writes are added with addOverwrite()
2956 * and addMerge(), and removed with removeWrite().
2957 */
2958declare interface WriteTree {
2959 /**
2960 * A tree tracking the result of applying all visible writes. This does not include transactions with
2961 * applyLocally=false or writes that are completely shadowed by other writes.
2962 */
2963 visibleWrites: CompoundWrite;
2964 /**
2965 * A list of all pending writes, regardless of visibility and shadowed-ness. Used to calculate arbitrary
2966 * sets of the changed data, such as hidden writes (from transactions) or changes with certain writes excluded (also
2967 * used by transactions).
2968 */
2969 allWrites: WriteRecord[];
2970 lastWriteId: number;
2971}
2972
2973export { }
2974
\No newline at end of file