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