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