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