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