@depup/firebase__database 1.1.1-depup.0

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