firebase-admin 9.3.0 → 9.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/lib/auth/action-code-settings-builder.js +1 -1
  2. package/lib/auth/auth-api-request.js +98 -25
  3. package/lib/auth/auth-config.js +15 -15
  4. package/lib/auth/auth.js +82 -61
  5. package/lib/auth/identifier.js +3 -2
  6. package/lib/auth/index.d.ts +1868 -0
  7. package/lib/{credential/credential-interfaces.js → auth/index.js} +1 -1
  8. package/lib/auth/tenant-manager.js +1 -1
  9. package/lib/auth/tenant.js +7 -1
  10. package/lib/auth/token-generator.js +6 -4
  11. package/lib/auth/token-verifier.js +32 -36
  12. package/lib/auth/user-import-builder.js +18 -15
  13. package/lib/auth/user-record.js +4 -4
  14. package/lib/credential/credential-internal.js +1 -2
  15. package/lib/credential/credential.js +8 -122
  16. package/lib/credential/index.d.ts +169 -0
  17. package/lib/credential/index.js +5 -17
  18. package/lib/database/database-internal.js +19 -26
  19. package/lib/database/index.d.ts +89 -0
  20. package/lib/database/index.js +12 -28
  21. package/lib/default-namespace.js +2 -1
  22. package/lib/firebase-app.js +26 -48
  23. package/lib/firebase-namespace-api.d.ts +238 -0
  24. package/lib/{firebase-service.js → firebase-namespace-api.js} +2 -2
  25. package/lib/{database/database.js → firebase-namespace.d.ts} +14 -7
  26. package/lib/firebase-namespace.js +22 -92
  27. package/lib/firestore/firestore-internal.js +2 -19
  28. package/lib/firestore/index.d.ts +50 -0
  29. package/lib/firestore/index.js +28 -43
  30. package/lib/index.d.ts +3 -932
  31. package/lib/index.js +2 -1
  32. package/lib/instance-id/index.d.ts +81 -0
  33. package/lib/instance-id/index.js +1 -10
  34. package/lib/instance-id/instance-id-request-internal.js +2 -1
  35. package/lib/instance-id/instance-id.js +1 -19
  36. package/lib/machine-learning/index.d.ts +249 -0
  37. package/lib/{messaging/messaging-types.js → machine-learning/index.js} +2 -2
  38. package/lib/machine-learning/machine-learning-api-client.js +1 -1
  39. package/lib/machine-learning/machine-learning-utils.js +1 -1
  40. package/lib/machine-learning/machine-learning.js +3 -22
  41. package/lib/messaging/batch-request-internal.js +1 -1
  42. package/lib/messaging/index.d.ts +1174 -0
  43. package/lib/messaging/index.js +1 -24
  44. package/lib/messaging/messaging-api-request-internal.js +2 -1
  45. package/lib/messaging/messaging-errors-internal.js +1 -1
  46. package/lib/messaging/messaging-internal.js +1 -1
  47. package/lib/messaging/messaging.js +21 -25
  48. package/lib/project-management/android-app.js +7 -6
  49. package/lib/project-management/index.d.ts +363 -0
  50. package/lib/project-management/index.js +23 -25
  51. package/lib/project-management/ios-app.js +5 -4
  52. package/lib/project-management/project-management-api-request-internal.js +5 -5
  53. package/lib/project-management/project-management.js +9 -26
  54. package/lib/remote-config/index.d.ts +359 -0
  55. package/lib/remote-config/index.js +1 -26
  56. package/lib/remote-config/remote-config-api-client-internal.js +3 -3
  57. package/lib/remote-config/remote-config.js +15 -32
  58. package/lib/security-rules/index.d.ts +216 -0
  59. package/lib/security-rules/index.js +1 -24
  60. package/lib/security-rules/security-rules-api-client-internal.js +1 -1
  61. package/lib/security-rules/security-rules-internal.js +1 -1
  62. package/lib/security-rules/security-rules.js +6 -15
  63. package/lib/storage/index.d.ts +60 -0
  64. package/lib/storage/index.js +1 -10
  65. package/lib/storage/storage.js +2 -19
  66. package/lib/utils/api-request.js +10 -3
  67. package/lib/utils/deep-copy.js +2 -1
  68. package/lib/utils/error.js +2 -1
  69. package/lib/utils/index.js +6 -5
  70. package/lib/utils/validator.js +2 -1
  71. package/package.json +15 -12
  72. package/lib/auth.d.ts +0 -2016
  73. package/lib/credential.d.ts +0 -150
  74. package/lib/database.d.ts +0 -1663
  75. package/lib/instance-id.d.ts +0 -37
  76. package/lib/messaging.d.ts +0 -1341
  77. package/lib/project-management/app-metadata.js +0 -37
  78. package/lib/project-management.d.ts +0 -361
  79. package/lib/remote-config/remote-config-api-client.js +0 -36
  80. package/lib/remote-config.d.ts +0 -350
  81. package/lib/security-rules.d.ts +0 -192
  82. package/lib/storage.d.ts +0 -40
package/lib/database.d.ts DELETED
@@ -1,1663 +0,0 @@
1
- /*! firebase-admin v9.3.0 */
2
- import * as _admin from './index.d';
3
-
4
- /* eslint-disable @typescript-eslint/ban-types */
5
-
6
- export namespace admin.database {
7
-
8
- /**
9
- * The Firebase Realtime Database service interface.
10
- *
11
- * Do not call this constructor directly. Instead, use
12
- * [`admin.database()`](admin.database#database).
13
- *
14
- * See
15
- * {@link
16
- * https://firebase.google.com/docs/database/admin/start/
17
- * Introduction to the Admin Database API}
18
- * for a full guide on how to use the Firebase Realtime Database service.
19
- */
20
- interface Database {
21
- app: _admin.app.App;
22
-
23
- /**
24
- * Disconnects from the server (all Database operations will be completed
25
- * offline).
26
- *
27
- * The client automatically maintains a persistent connection to the Database
28
- * server, which will remain active indefinitely and reconnect when
29
- * disconnected. However, the `goOffline()` and `goOnline()` methods may be used
30
- * to control the client connection in cases where a persistent connection is
31
- * undesirable.
32
- *
33
- * While offline, the client will no longer receive data updates from the
34
- * Database. However, all Database operations performed locally will continue to
35
- * immediately fire events, allowing your application to continue behaving
36
- * normally. Additionally, each operation performed locally will automatically
37
- * be queued and retried upon reconnection to the Database server.
38
- *
39
- * To reconnect to the Database and begin receiving remote events, see
40
- * `goOnline()`.
41
- *
42
- * @example
43
- * ```javascript
44
- * admin.database().goOffline();
45
- * ```
46
- */
47
- goOffline(): void;
48
-
49
- /**
50
- * Reconnects to the server and synchronizes the offline Database state
51
- * with the server state.
52
- *
53
- * This method should be used after disabling the active connection with
54
- * `goOffline()`. Once reconnected, the client will transmit the proper data
55
- * and fire the appropriate events so that your client "catches up"
56
- * automatically.
57
- *
58
- * @example
59
- * ```javascript
60
- * admin.database().goOnline();
61
- * ```
62
- */
63
- goOnline(): void;
64
-
65
- /**
66
- * Returns a `Reference` representing the location in the Database
67
- * corresponding to the provided path. Also can be invoked with an existing
68
- * `Reference` as the argument. In that case returns a new `Reference`
69
- * pointing to the same location. If no path argument is
70
- * provided, returns a `Reference` that represents the root of the Database.
71
- *
72
- * @example
73
- * ```javascript
74
- * // Get a reference to the root of the Database
75
- * var rootRef = admin.database.ref();
76
- * ```
77
- *
78
- * @example
79
- * ```javascript
80
- * // Get a reference to the /users/ada node
81
- * var adaRef = admin.database().ref("users/ada");
82
- * // The above is shorthand for the following operations:
83
- * //var rootRef = admin.database().ref();
84
- * //var adaRef = rootRef.child("users/ada");
85
- * ```
86
- *
87
- * @example
88
- * ```javascript
89
- * var adaRef = admin.database().ref("users/ada");
90
- * // Get a new reference pointing to the same location.
91
- * var anotherAdaRef = admin.database().ref(adaRef);
92
- * ```
93
- *
94
- *
95
- * @param path Optional path representing
96
- * the location the returned `Reference` will point. Alternatively, a
97
- * `Reference` object to copy. If not provided, the returned `Reference` will
98
- * point to the root of the Database.
99
- * @return If a path is provided, a `Reference`
100
- * pointing to the provided path. Otherwise, a `Reference` pointing to the
101
- * root of the Database.
102
- */
103
- ref(path?: string | admin.database.Reference): admin.database.Reference;
104
-
105
- /**
106
- * Returns a `Reference` representing the location in the Database
107
- * corresponding to the provided Firebase URL.
108
- *
109
- * An exception is thrown if the URL is not a valid Firebase Database URL or it
110
- * has a different domain than the current `Database` instance.
111
- *
112
- * Note that all query parameters (`orderBy`, `limitToLast`, etc.) are ignored
113
- * and are not applied to the returned `Reference`.
114
- *
115
- * @example
116
- * ```javascript
117
- * // Get a reference to the root of the Database
118
- * var rootRef = admin.database().ref("https://<DATABASE_NAME>.firebaseio.com");
119
- * ```
120
- *
121
- * @example
122
- * ```javascript
123
- * // Get a reference to the /users/ada node
124
- * var adaRef = admin.database().ref("https://<DATABASE_NAME>.firebaseio.com/users/ada");
125
- * ```
126
- *
127
- * @param url The Firebase URL at which the returned `Reference` will
128
- * point.
129
- * @return A `Reference` pointing to the provided Firebase URL.
130
- */
131
- refFromURL(url: string): admin.database.Reference;
132
-
133
- /**
134
- * Gets the currently applied security rules as a string. The return value consists of
135
- * the rules source including comments.
136
- *
137
- * @return A promise fulfilled with the rules as a raw string.
138
- */
139
- getRules(): Promise<string>;
140
-
141
- /**
142
- * Gets the currently applied security rules as a parsed JSON object. Any comments in
143
- * the original source are stripped away.
144
- *
145
- * @return A promise fulfilled with the parsed rules object.
146
- */
147
- getRulesJSON(): Promise<object>;
148
-
149
- /**
150
- * Sets the specified rules on the Firebase Realtime Database instance. If the rules source is
151
- * specified as a string or a Buffer, it may include comments.
152
- *
153
- * @param source Source of the rules to apply. Must not be `null` or empty.
154
- * @return Resolves when the rules are set on the Realtime Database.
155
- */
156
- setRules(source: string | Buffer | object): Promise<void>;
157
- }
158
-
159
- /**
160
- * A `DataSnapshot` contains data from a Database location.
161
- *
162
- * Any time you read data from the Database, you receive the data as a
163
- * `DataSnapshot`. A `DataSnapshot` is passed to the event callbacks you attach
164
- * with `on()` or `once()`. You can extract the contents of the snapshot as a
165
- * JavaScript object by calling the `val()` method. Alternatively, you can
166
- * traverse into the snapshot by calling `child()` to return child snapshots
167
- * (which you could then call `val()` on).
168
- *
169
- * A `DataSnapshot` is an efficiently generated, immutable copy of the data at
170
- * a Database location. It cannot be modified and will never change (to modify
171
- * data, you always call the `set()` method on a `Reference` directly).
172
- */
173
- interface DataSnapshot {
174
- key: string | null;
175
- ref: admin.database.Reference;
176
-
177
- /**
178
- * Gets another `DataSnapshot` for the location at the specified relative path.
179
- *
180
- * Passing a relative path to the `child()` method of a DataSnapshot returns
181
- * another `DataSnapshot` for the location at the specified relative path. The
182
- * relative path can either be a simple child name (for example, "ada") or a
183
- * deeper, slash-separated path (for example, "ada/name/first"). If the child
184
- * location has no data, an empty `DataSnapshot` (that is, a `DataSnapshot`
185
- * whose value is `null`) is returned.
186
- *
187
- * @example
188
- * ```javascript
189
- * // Assume we have the following data in the Database:
190
- * {
191
- * "name": {
192
- * "first": "Ada",
193
- * "last": "Lovelace"
194
- * }
195
- * }
196
- *
197
- * // Test for the existence of certain keys within a DataSnapshot
198
- * var ref = admin.database().ref("users/ada");
199
- * ref.once("value")
200
- * .then(function(snapshot) {
201
- * var name = snapshot.child("name").val(); // {first:"Ada",last:"Lovelace"}
202
- * var firstName = snapshot.child("name/first").val(); // "Ada"
203
- * var lastName = snapshot.child("name").child("last").val(); // "Lovelace"
204
- * var age = snapshot.child("age").val(); // null
205
- * });
206
- * ```
207
- *
208
- * @param path A relative path to the location of child data.
209
- * @return `DataSnapshot` for the location at the specified relative path.
210
- */
211
- child(path: string): admin.database.DataSnapshot;
212
-
213
- /**
214
- * Returns true if this `DataSnapshot` contains any data. It is slightly more
215
- * efficient than using `snapshot.val() !== null`.
216
- *
217
- * @example
218
- * ```javascript
219
- * // Assume we have the following data in the Database:
220
- * {
221
- * "name": {
222
- * "first": "Ada",
223
- * "last": "Lovelace"
224
- * }
225
- * }
226
- *
227
- * // Test for the existence of certain keys within a DataSnapshot
228
- * var ref = admin.database().ref("users/ada");
229
- * ref.once("value")
230
- * .then(function(snapshot) {
231
- * var a = snapshot.exists(); // true
232
- * var b = snapshot.child("name").exists(); // true
233
- * var c = snapshot.child("name/first").exists(); // true
234
- * var d = snapshot.child("name/middle").exists(); // false
235
- * });
236
- * ```
237
- *
238
- * @return Whether this `DataSnapshot` contains any data.
239
- */
240
- exists(): boolean;
241
-
242
- /**
243
- * Exports the entire contents of the DataSnapshot as a JavaScript object.
244
- *
245
- * The `exportVal()` method is similar to `val()`, except priority information
246
- * is included (if available), making it suitable for backing up your data.
247
- *
248
- * @return The DataSnapshot's contents as a JavaScript value (Object,
249
- * Array, string, number, boolean, or `null`).
250
- */
251
- exportVal(): any;
252
-
253
- /**
254
- * Enumerates the top-level children in the `DataSnapshot`.
255
- *
256
- * Because of the way JavaScript objects work, the ordering of data in the
257
- * JavaScript object returned by `val()` is not guaranteed to match the ordering
258
- * on the server nor the ordering of `child_added` events. That is where
259
- * `forEach()` comes in handy. It guarantees the children of a `DataSnapshot`
260
- * will be iterated in their query order.
261
- *
262
- * If no explicit `orderBy*()` method is used, results are returned
263
- * ordered by key (unless priorities are used, in which case, results are
264
- * returned by priority).
265
- *
266
- * @example
267
- * ```javascript
268
- *
269
- * // Assume we have the following data in the Database:
270
- * {
271
- * "users": {
272
- * "ada": {
273
- * "first": "Ada",
274
- * "last": "Lovelace"
275
- * },
276
- * "alan": {
277
- * "first": "Alan",
278
- * "last": "Turing"
279
- * }
280
- * }
281
- * }
282
- *
283
- * // Loop through users in order with the forEach() method. The callback
284
- * // provided to forEach() will be called synchronously with a DataSnapshot
285
- * // for each child:
286
- * var query = admin.database().ref("users").orderByKey();
287
- * query.once("value")
288
- * .then(function(snapshot) {
289
- * snapshot.forEach(function(childSnapshot) {
290
- * // key will be "ada" the first time and "alan" the second time
291
- * var key = childSnapshot.key;
292
- * // childData will be the actual contents of the child
293
- * var childData = childSnapshot.val();
294
- * });
295
- * });
296
- * ```
297
- *
298
- * @example
299
- * ```javascript
300
- * // You can cancel the enumeration at any point by having your callback
301
- * // function return true. For example, the following code sample will only
302
- * // fire the callback function one time:
303
- * var query = admin.database().ref("users").orderByKey();
304
- * query.once("value")
305
- * .then(function(snapshot) {
306
- * snapshot.forEach(function(childSnapshot) {
307
- * var key = childSnapshot.key; // "ada"
308
- *
309
- * // Cancel enumeration
310
- * return true;
311
- * });
312
- * });
313
- * ```
314
- *
315
- * @param action A function
316
- * that will be called for each child `DataSnapshot`. The callback can return
317
- * true to cancel further enumeration.
318
- * @return True if enumeration was canceled due to your callback
319
- * returning true.
320
- */
321
- forEach(action: (a: admin.database.DataSnapshot) => boolean | void): boolean;
322
-
323
- /**
324
- * Gets the priority value of the data in this `DataSnapshot`.
325
- *
326
- * Applications need not use priority but can order collections by
327
- * ordinary properties (see
328
- * {@link
329
- * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
330
- * Sorting and filtering data}).
331
- *
332
- * @return The the priority value of the data in this `DataSnapshot`.
333
- */
334
- getPriority(): string | number | null;
335
-
336
- /**
337
- * Returns true if the specified child path has (non-null) data.
338
- *
339
- * @example
340
- * ```javascript
341
- * // Assume we have the following data in the Database:
342
- * {
343
- * "name": {
344
- * "first": "Ada",
345
- * "last": "Lovelace"
346
- * }
347
- * }
348
- *
349
- * // Determine which child keys in DataSnapshot have data.
350
- * var ref = admin.database().ref("users/ada");
351
- * ref.once("value")
352
- * .then(function(snapshot) {
353
- * var hasName = snapshot.hasChild("name"); // true
354
- * var hasAge = snapshot.hasChild("age"); // false
355
- * });
356
- * ```
357
- *
358
- * @param path A relative path to the location of a potential child.
359
- * @return `true` if data exists at the specified child path; else
360
- * `false`.
361
- */
362
- hasChild(path: string): boolean;
363
-
364
- /**
365
- * Returns whether or not the `DataSnapshot` has any non-`null` child
366
- * properties.
367
- *
368
- * You can use `hasChildren()` to determine if a `DataSnapshot` has any
369
- * children. If it does, you can enumerate them using `forEach()`. If it
370
- * doesn't, then either this snapshot contains a primitive value (which can be
371
- * retrieved with `val()`) or it is empty (in which case, `val()` will return
372
- * `null`).
373
- *
374
- * @example
375
- * ```javascript
376
- * // Assume we have the following data in the Database:
377
- * {
378
- * "name": {
379
- * "first": "Ada",
380
- * "last": "Lovelace"
381
- * }
382
- * }
383
- *
384
- * var ref = admin.database().ref("users/ada");
385
- * ref.once("value")
386
- * .then(function(snapshot) {
387
- * var a = snapshot.hasChildren(); // true
388
- * var b = snapshot.child("name").hasChildren(); // true
389
- * var c = snapshot.child("name/first").hasChildren(); // false
390
- * });
391
- * ```
392
- *
393
- * @return True if this snapshot has any children; else false.
394
- */
395
- hasChildren(): boolean;
396
-
397
- /**
398
- * Returns the number of child properties of this `DataSnapshot`.
399
- *
400
- * @example
401
- * ```javascript
402
- * // Assume we have the following data in the Database:
403
- * {
404
- * "name": {
405
- * "first": "Ada",
406
- * "last": "Lovelace"
407
- * }
408
- * }
409
- *
410
- * var ref = admin.database().ref("users/ada");
411
- * ref.once("value")
412
- * .then(function(snapshot) {
413
- * var a = snapshot.numChildren(); // 1 ("name")
414
- * var b = snapshot.child("name").numChildren(); // 2 ("first", "last")
415
- * var c = snapshot.child("name/first").numChildren(); // 0
416
- * });
417
- * ```
418
- *
419
- * @return The number of child properties of this `DataSnapshot`.
420
- */
421
- numChildren(): number;
422
-
423
- /**
424
- * @return A JSON-serializable representation of this object.
425
- */
426
- toJSON(): Object | null;
427
-
428
- /**
429
- * Extracts a JavaScript value from a `DataSnapshot`.
430
- *
431
- * Depending on the data in a `DataSnapshot`, the `val()` method may return a
432
- * scalar type (string, number, or boolean), an array, or an object. It may also
433
- * return null, indicating that the `DataSnapshot` is empty (contains no data).
434
- *
435
- * @example
436
- * ```javascript
437
- * // Write and then read back a string from the Database.
438
- * ref.set("hello")
439
- * .then(function() {
440
- * return ref.once("value");
441
- * })
442
- * .then(function(snapshot) {
443
- * var data = snapshot.val(); // data === "hello"
444
- * });
445
- * ```
446
- *
447
- * @example
448
- * ```javascript
449
- * // Write and then read back a JavaScript object from the Database.
450
- * ref.set({ name: "Ada", age: 36 })
451
- * .then(function() {
452
- * return ref.once("value");
453
- * })
454
- * .then(function(snapshot) {
455
- * var data = snapshot.val();
456
- * // data is { "name": "Ada", "age": 36 }
457
- * // data.name === "Ada"
458
- * // data.age === 36
459
- * });
460
- * ```
461
- *
462
- * @return The DataSnapshot's contents as a JavaScript value (Object,
463
- * Array, string, number, boolean, or `null`).
464
- */
465
- val(): any;
466
- }
467
-
468
- /**
469
- * The `onDisconnect` class allows you to write or clear data when your client
470
- * disconnects from the Database server. These updates occur whether your
471
- * client disconnects cleanly or not, so you can rely on them to clean up data
472
- * even if a connection is dropped or a client crashes.
473
- *
474
- * The `onDisconnect` class is most commonly used to manage presence in
475
- * applications where it is useful to detect how many clients are connected and
476
- * when other clients disconnect. See
477
- * {@link
478
- * https://firebase.google.com/docs/database/web/offline-capabilities
479
- * Enabling Offline Capabilities in JavaScript} for more information.
480
- *
481
- * To avoid problems when a connection is dropped before the requests can be
482
- * transferred to the Database server, these functions should be called before
483
- * any data is written.
484
- *
485
- * Note that `onDisconnect` operations are only triggered once. If you want an
486
- * operation to occur each time a disconnect occurs, you'll need to re-establish
487
- * the `onDisconnect` operations each time you reconnect.
488
- */
489
- interface OnDisconnect {
490
-
491
- /**
492
- * Cancels all previously queued `onDisconnect()` set or update events for this
493
- * location and all children.
494
- *
495
- * If a write has been queued for this location via a `set()` or `update()` at a
496
- * parent location, the write at this location will be canceled, though all
497
- * other siblings will still be written.
498
- *
499
- * @example
500
- * ```javascript
501
- * var ref = admin.database().ref("onlineState");
502
- * ref.onDisconnect().set(false);
503
- * // ... sometime later
504
- * ref.onDisconnect().cancel();
505
- * ```
506
- *
507
- * @param onComplete An optional callback function that is
508
- * called when synchronization to the server has completed. The callback
509
- * will be passed a single parameter: null for success, or an Error object
510
- * indicating a failure.
511
- * @return Resolves when synchronization to the server is complete.
512
- */
513
- cancel(onComplete?: (a: Error | null) => any): Promise<void>;
514
-
515
- /**
516
- * Ensures the data at this location is deleted when the client is disconnected
517
- * (due to closing the browser, navigating to a new page, or network issues).
518
- *
519
- * @param onComplete An optional callback function that is
520
- * called when synchronization to the server has completed. The callback
521
- * will be passed a single parameter: null for success, or an Error object
522
- * indicating a failure.
523
- * @return Resolves when synchronization to the server is complete.
524
- */
525
- remove(onComplete?: (a: Error | null) => any): Promise<void>;
526
-
527
- /**
528
- * Ensures the data at this location is set to the specified value when the
529
- * client is disconnected (due to closing the browser, navigating to a new page,
530
- * or network issues).
531
- *
532
- * `set()` is especially useful for implementing "presence" systems, where a
533
- * value should be changed or cleared when a user disconnects so that they
534
- * appear "offline" to other users. See
535
- * {@link
536
- * https://firebase.google.com/docs/database/web/offline-capabilities
537
- * Enabling Offline Capabilities in JavaScript} for more information.
538
- *
539
- * Note that `onDisconnect` operations are only triggered once. If you want an
540
- * operation to occur each time a disconnect occurs, you'll need to re-establish
541
- * the `onDisconnect` operations each time.
542
- *
543
- * @example
544
- * ```javascript
545
- * var ref = admin.database().ref("users/ada/status");
546
- * ref.onDisconnect().set("I disconnected!");
547
- * ```
548
- *
549
- * @param value The value to be written to this location on
550
- * disconnect (can be an object, array, string, number, boolean, or null).
551
- * @param onComplete An optional callback function that
552
- * will be called when synchronization to the database server has completed.
553
- * The callback will be passed a single parameter: null for success, or an
554
- * `Error` object indicating a failure.
555
- * @return A promise that resolves when synchronization to the database is complete.
556
- */
557
- set(value: any, onComplete?: (a: Error | null) => any): Promise<void>;
558
-
559
- /**
560
- * Ensures the data at this location is set to the specified value and priority
561
- * when the client is disconnected (due to closing the browser, navigating to a
562
- * new page, or network issues).
563
- *
564
- * @param value The value to be written to this location on
565
- * disconnect (can be an object, array, string, number, boolean, or null).
566
- * @param priority
567
- * @param onComplete An optional callback function that is
568
- * called when synchronization to the server has completed. The callback
569
- * will be passed a single parameter: null for success, or an Error object
570
- * indicating a failure.
571
- * @return A promise that resolves when synchronization to the database is complete.
572
- */
573
- setWithPriority(
574
- value: any,
575
- priority: number | string | null,
576
- onComplete?: (a: Error | null) => any
577
- ): Promise<void>;
578
-
579
- /**
580
- * Writes multiple values at this location when the client is disconnected (due
581
- * to closing the browser, navigating to a new page, or network issues).
582
- *
583
- * The `values` argument contains multiple property-value pairs that will be
584
- * written to the Database together. Each child property can either be a simple
585
- * property (for example, "name") or a relative path (for example, "name/first")
586
- * from the current location to the data to update.
587
- *
588
- * As opposed to the `set()` method, `update()` can be use to selectively update
589
- * only the referenced properties at the current location (instead of replacing
590
- * all the child properties at the current location).
591
- *
592
- * See {@link https://firebase.google.com/docs/reference/admin/node/admin.database.Reference#update}
593
- * for examples of using the connected version of `update`.
594
- *
595
- * @example
596
- * ```javascript
597
- * var ref = admin.database().ref("users/ada");
598
- * ref.update({
599
- * onlineState: true,
600
- * status: "I'm online."
601
- * });
602
- * ref.onDisconnect().update({
603
- * onlineState: false,
604
- * status: "I'm offline."
605
- * });
606
- * ```
607
- *
608
- * @param values object containing multiple values.
609
- * @param onComplete An optional callback function that will
610
- * be called when synchronization to the server has completed. The
611
- * callback will be passed a single parameter: null for success, or an Error
612
- * object indicating a failure.
613
- * @return Resolves when synchronization to the
614
- * Database is complete.
615
- */
616
- update(values: object, onComplete?: (a: Error | null) => any): Promise<void>;
617
- }
618
-
619
- type EventType = 'value' | 'child_added' | 'child_changed' | 'child_moved' | 'child_removed';
620
-
621
- /**
622
- * A `Query` sorts and filters the data at a Database location so only a subset
623
- * of the child data is included. This can be used to order a collection of
624
- * data by some attribute (for example, height of dinosaurs) as well as to
625
- * restrict a large list of items (for example, chat messages) down to a number
626
- * suitable for synchronizing to the client. Queries are created by chaining
627
- * together one or more of the filter methods defined here.
628
- *
629
- * Just as with a `Reference`, you can receive data from a `Query` by using the
630
- * `on()` method. You will only receive events and `DataSnapshot`s for the
631
- * subset of the data that matches your query.
632
- *
633
- * See
634
- * {@link
635
- * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
636
- * Sorting and filtering data} for more information.
637
- */
638
- interface Query {
639
- ref: admin.database.Reference;
640
-
641
- /**
642
- * Creates a `Query` with the specified ending point.
643
- *
644
- * Using `startAt()`, `endAt()`, and `equalTo()` allows you to choose arbitrary
645
- * starting and ending points for your queries.
646
- *
647
- * The ending point is inclusive, so children with exactly the specified value
648
- * will be included in the query. The optional key argument can be used to
649
- * further limit the range of the query. If it is specified, then children that
650
- * have exactly the specified value must also have a key name less than or equal
651
- * to the specified key.
652
- *
653
- * You can read more about `endAt()` in
654
- * {@link
655
- * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
656
- * Filtering data}.
657
- *
658
- * @example
659
- * ```javascript
660
- * // Find all dinosaurs whose names come before Pterodactyl lexicographically.
661
- * var ref = admin.database().ref("dinosaurs");
662
- * ref.orderByKey().endAt("pterodactyl").on("child_added", function(snapshot) {
663
- * console.log(snapshot.key);
664
- * });
665
- * ```
666
- *
667
- * @param value The value to end at. The argument
668
- * type depends on which `orderBy*()` function was used in this query.
669
- * Specify a value that matches the `orderBy*()` type. When used in
670
- * combination with `orderByKey()`, the value must be a string.
671
- * @param key The child key to end at, among the children with the
672
- * previously specified priority. This argument is only allowed if ordering by
673
- * priority.
674
- * @return A new `Query` object.
675
- */
676
- endAt(value: number | string | boolean | null, key?: string): admin.database.Query;
677
-
678
- /**
679
- * Creates a `Query` that includes children that match the specified value.
680
- *
681
- * Using `startAt()`, `endAt()`, and `equalTo()` allows us to choose arbitrary
682
- * starting and ending points for our queries.
683
- *
684
- * The optional key argument can be used to further limit the range of the
685
- * query. If it is specified, then children that have exactly the specified
686
- * value must also have exactly the specified key as their key name. This can be
687
- * used to filter result sets with many matches for the same value.
688
- *
689
- * You can read more about `equalTo()` in
690
- * {@link
691
- * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
692
- * Filtering data}.
693
- *
694
- * @example
695
- * // Find all dinosaurs whose height is exactly 25 meters.
696
- * var ref = admin.database().ref("dinosaurs");
697
- * ref.orderByChild("height").equalTo(25).on("child_added", function(snapshot) {
698
- * console.log(snapshot.key);
699
- * });
700
- *
701
- * @param value The value to match for. The
702
- * argument type depends on which `orderBy*()` function was used in this
703
- * query. Specify a value that matches the `orderBy*()` type. When used in
704
- * combination with `orderByKey()`, the value must be a string.
705
- * @param key The child key to start at, among the children with the
706
- * previously specified priority. This argument is only allowed if ordering by
707
- * priority.
708
- * @return A new `Query` object.
709
- */
710
- equalTo(value: number | string | boolean | null, key?: string): admin.database.Query;
711
-
712
- /**
713
- * Returns whether or not the current and provided queries represent the same
714
- * location, have the same query parameters, and are from the same instance of
715
- * `admin.app.App`.
716
- *
717
- * Two `Reference` objects are equivalent if they represent the same location
718
- * and are from the same instance of `admin.app.App`.
719
- *
720
- * Two `Query` objects are equivalent if they represent the same location, have
721
- * the same query parameters, and are from the same instance of `admin.app.App`.
722
- * Equivalent queries share the same sort order, limits, and starting and
723
- * ending points.
724
- *
725
- * @example
726
- * ```javascript
727
- * var rootRef = admin.database().ref();
728
- * var usersRef = rootRef.child("users");
729
- *
730
- * usersRef.isEqual(rootRef); // false
731
- * usersRef.isEqual(rootRef.child("users")); // true
732
- * usersRef.parent.isEqual(rootRef); // true
733
- * ```
734
- *
735
- * @example
736
- * ```javascript
737
- * var rootRef = admin.database().ref();
738
- * var usersRef = rootRef.child("users");
739
- * var usersQuery = usersRef.limitToLast(10);
740
- *
741
- * usersQuery.isEqual(usersRef); // false
742
- * usersQuery.isEqual(usersRef.limitToLast(10)); // true
743
- * usersQuery.isEqual(rootRef.limitToLast(10)); // false
744
- * usersQuery.isEqual(usersRef.orderByKey().limitToLast(10)); // false
745
- * ```
746
- *
747
- * @param other The query to compare against.
748
- * @return Whether or not the current and provided queries are
749
- * equivalent.
750
- */
751
- isEqual(other: admin.database.Query | null): boolean;
752
-
753
- /**
754
- * Generates a new `Query` limited to the first specific number of children.
755
- *
756
- * The `limitToFirst()` method is used to set a maximum number of children to be
757
- * synced for a given callback. If we set a limit of 100, we will initially only
758
- * receive up to 100 `child_added` events. If we have fewer than 100 messages
759
- * stored in our Database, a `child_added` event will fire for each message.
760
- * However, if we have over 100 messages, we will only receive a `child_added`
761
- * event for the first 100 ordered messages. As items change, we will receive
762
- * `child_removed` events for each item that drops out of the active list so
763
- * that the total number stays at 100.
764
- *
765
- * You can read more about `limitToFirst()` in
766
- * {@link
767
- * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
768
- * Filtering data}.
769
- *
770
- * @example
771
- * ```javascript
772
- * // Find the two shortest dinosaurs.
773
- * var ref = admin.database().ref("dinosaurs");
774
- * ref.orderByChild("height").limitToFirst(2).on("child_added", function(snapshot) {
775
- * // This will be called exactly two times (unless there are less than two
776
- * // dinosaurs in the Database).
777
- *
778
- * // It will also get fired again if one of the first two dinosaurs is
779
- * // removed from the data set, as a new dinosaur will now be the second
780
- * // shortest.
781
- * console.log(snapshot.key);
782
- * });
783
- * ```
784
- *
785
- * @param limit The maximum number of nodes to include in this query.
786
- * @return A `Query` object.
787
- */
788
- limitToFirst(limit: number): admin.database.Query;
789
-
790
- /**
791
- * Generates a new `Query` object limited to the last specific number of
792
- * children.
793
- *
794
- * The `limitToLast()` method is used to set a maximum number of children to be
795
- * synced for a given callback. If we set a limit of 100, we will initially only
796
- * receive up to 100 `child_added` events. If we have fewer than 100 messages
797
- * stored in our Database, a `child_added` event will fire for each message.
798
- * However, if we have over 100 messages, we will only receive a `child_added`
799
- * event for the last 100 ordered messages. As items change, we will receive
800
- * `child_removed` events for each item that drops out of the active list so
801
- * that the total number stays at 100.
802
- *
803
- * You can read more about `limitToLast()` in
804
- * {@link
805
- * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
806
- * Filtering data}.
807
- *
808
- * @example
809
- * ```javascript
810
- * // Find the two heaviest dinosaurs.
811
- * var ref = admin.database().ref("dinosaurs");
812
- * ref.orderByChild("weight").limitToLast(2).on("child_added", function(snapshot) {
813
- * // This callback will be triggered exactly two times, unless there are
814
- * // fewer than two dinosaurs stored in the Database. It will also get fired
815
- * // for every new, heavier dinosaur that gets added to the data set.
816
- * console.log(snapshot.key);
817
- * });
818
- * ```
819
- *
820
- * @param limit The maximum number of nodes to include in this query.
821
- * @return A `Query` object.
822
- */
823
- limitToLast(limit: number): admin.database.Query;
824
-
825
- /**
826
- * Detaches a callback previously attached with `on()`.
827
- *
828
- * Detach a callback previously attached with `on()`. Note that if `on()` was
829
- * called multiple times with the same eventType and callback, the callback
830
- * will be called multiple times for each event, and `off()` must be called
831
- * multiple times to remove the callback. Calling `off()` on a parent listener
832
- * will not automatically remove listeners registered on child nodes, `off()`
833
- * must also be called on any child listeners to remove the callback.
834
- *
835
- * If a callback is not specified, all callbacks for the specified eventType
836
- * will be removed. Similarly, if no eventType or callback is specified, all
837
- * callbacks for the `Reference` will be removed.
838
- *
839
- * @example
840
- * ```javascript
841
- * var onValueChange = function(dataSnapshot) { ... };
842
- * ref.on('value', onValueChange);
843
- * ref.child('meta-data').on('child_added', onChildAdded);
844
- * // Sometime later...
845
- * ref.off('value', onValueChange);
846
- *
847
- * // You must also call off() for any child listeners on ref
848
- * // to cancel those callbacks
849
- * ref.child('meta-data').off('child_added', onValueAdded);
850
- * ```
851
- *
852
- * @example
853
- * ```javascript
854
- * // Or you can save a line of code by using an inline function
855
- * // and on()'s return value.
856
- * var onValueChange = ref.on('value', function(dataSnapshot) { ... });
857
- * // Sometime later...
858
- * ref.off('value', onValueChange);
859
- * ```
860
- *
861
- * @param eventType One of the following strings: "value",
862
- * "child_added", "child_changed", "child_removed", or "child_moved."
863
- * @param callback The callback function that was passed to `on()`.
864
- * @param context The context that was passed to `on()`.
865
- */
866
- off(
867
- eventType?: admin.database.EventType,
868
- callback?: (a: admin.database.DataSnapshot, b?: string | null) => any,
869
- context?: object | null
870
- ): void;
871
-
872
- /**
873
- * Listens for data changes at a particular location.
874
- *
875
- * This is the primary way to read data from a Database. Your callback
876
- * will be triggered for the initial data and again whenever the data changes.
877
- * Use `off( )` to stop receiving updates. See
878
- * {@link https://firebase.google.com/docs/database/web/retrieve-data
879
- * Retrieve Data on the Web}
880
- * for more details.
881
- *
882
- * <h4>value event</h4>
883
- *
884
- * This event will trigger once with the initial data stored at this location,
885
- * and then trigger again each time the data changes. The `DataSnapshot` passed
886
- * to the callback will be for the location at which `on()` was called. It
887
- * won't trigger until the entire contents has been synchronized. If the
888
- * location has no data, it will be triggered with an empty `DataSnapshot`
889
- * (`val()` will return `null`).
890
- *
891
- * <h4>child_added event</h4>
892
- *
893
- * This event will be triggered once for each initial child at this location,
894
- * and it will be triggered again every time a new child is added. The
895
- * `DataSnapshot` passed into the callback will reflect the data for the
896
- * relevant child. For ordering purposes, it is passed a second argument which
897
- * is a string containing the key of the previous sibling child by sort order
898
- * (or `null` if it is the first child).
899
- *
900
- * <h4>child_removed event</h4>
901
- *
902
- * This event will be triggered once every time a child is removed. The
903
- * `DataSnapshot` passed into the callback will be the old data for the child
904
- * that was removed. A child will get removed when either:
905
- *
906
- * - a client explicitly calls `remove()` on that child or one of its ancestors
907
- * - a client calls `set(null)` on that child or one of its ancestors
908
- * - that child has all of its children removed
909
- * - there is a query in effect which now filters out the child (because it's
910
- * sort order changed or the max limit was hit)
911
- *
912
- * <h4>child_changed event</h4>
913
- *
914
- * This event will be triggered when the data stored in a child (or any of its
915
- * descendants) changes. Note that a single `child_changed` event may represent
916
- * multiple changes to the child. The `DataSnapshot` passed to the callback will
917
- * contain the new child contents. For ordering purposes, the callback is also
918
- * passed a second argument which is a string containing the key of the previous
919
- * sibling child by sort order (or `null` if it is the first child).
920
- *
921
- * <h4>child_moved event</h4>
922
- *
923
- * This event will be triggered when a child's sort order changes such that its
924
- * position relative to its siblings changes. The `DataSnapshot` passed to the
925
- * callback will be for the data of the child that has moved. It is also passed
926
- * a second argument which is a string containing the key of the previous
927
- * sibling child by sort order (or `null` if it is the first child).
928
- *
929
- * @example
930
- * ```javascript
931
- * // Handle a new value.
932
- * ref.on('value', function(dataSnapshot) {
933
- * ...
934
- * });
935
- * ```
936
- *
937
- * @example
938
- * ```javascript
939
- * // Handle a new child.
940
- * ref.on('child_added', function(childSnapshot, prevChildKey) {
941
- * ...
942
- * });
943
- * ```
944
- *
945
- * @example
946
- * ```javascript
947
- * // Handle child removal.
948
- * ref.on('child_removed', function(oldChildSnapshot) {
949
- * ...
950
- * });
951
- * ```
952
- *
953
- * @example
954
- * ```javascript
955
- * // Handle child data changes.
956
- * ref.on('child_changed', function(childSnapshot, prevChildKey) {
957
- * ...
958
- * });
959
- * ```
960
- *
961
- * @example
962
- * ```javascript
963
- * // Handle child ordering changes.
964
- * ref.on('child_moved', function(childSnapshot, prevChildKey) {
965
- * ...
966
- * });
967
- * ```
968
- *
969
- * @param eventType One of the following strings: "value",
970
- * "child_added", "child_changed", "child_removed", or "child_moved."
971
- * @param callback A callback that fires when the specified event occurs. The callback is
972
- * passed a DataSnapshot. For ordering purposes, "child_added",
973
- * "child_changed", and "child_moved" will also be passed a string containing
974
- * the key of the previous child, by sort order (or `null` if it is the
975
- * first child).
976
- * @param cancelCallbackOrContext An optional
977
- * callback that will be notified if your event subscription is ever canceled
978
- * because your client does not have permission to read this data (or it had
979
- * permission but has now lost it). This callback will be passed an `Error`
980
- * object indicating why the failure occurred.
981
- * @param context If provided, this object will be used as `this`
982
- * when calling your callback(s).
983
- * @return The provided
984
- * callback function is returned unmodified. This is just for convenience if
985
- * you want to pass an inline function to `on()`, but store the callback
986
- * function for later passing to `off()`.
987
- */
988
- on(
989
- eventType: admin.database.EventType,
990
- callback: (a: admin.database.DataSnapshot, b?: string | null) => any,
991
- cancelCallbackOrContext?: ((a: Error) => any) | object | null,
992
- context?: object | null
993
- ): (a: admin.database.DataSnapshot | null, b?: string) => any;
994
-
995
- /**
996
- * Listens for exactly one event of the specified event type, and then stops
997
- * listening.
998
- *
999
- * This is equivalent to calling `on()`, and then calling `off()` inside the
1000
- * callback function. See `on()` for details on the event types.
1001
- *
1002
- * @example
1003
- * ```javascript
1004
- * // Basic usage of .once() to read the data located at ref.
1005
- * ref.once('value')
1006
- * .then(function(dataSnapshot) {
1007
- * // handle read data.
1008
- * });
1009
- * ```
1010
- *
1011
- * @param eventType One of the following strings: "value",
1012
- * "child_added", "child_changed", "child_removed", or "child_moved."
1013
- * @param successCallback A callback that fires when the specified event occurs. The callback is
1014
- * passed a `DataSnapshot`. For ordering purposes, "child_added",
1015
- * "child_changed", and "child_moved" will also be passed a string containing
1016
- * the key of the previous child by sort order (or `null` if it is the
1017
- * first child).
1018
- * @param failureCallbackOrContext An optional
1019
- * callback that will be notified if your client does not have permission to
1020
- * read the data. This callback will be passed an `Error` object indicating
1021
- * why the failure occurred.
1022
- * @param context If provided, this object will be used as `this`
1023
- * when calling your callback(s).
1024
- * @return {!Promise<admin.database.DataSnapshot>}
1025
- */
1026
- once(
1027
- eventType: admin.database.EventType,
1028
- successCallback?: (a: admin.database.DataSnapshot, b?: string | null ) => any,
1029
- failureCallbackOrContext?: ((a: Error) => void) | object | null,
1030
- context?: object | null
1031
- ): Promise<admin.database.DataSnapshot>;
1032
-
1033
- /**
1034
- * Generates a new `Query` object ordered by the specified child key.
1035
- *
1036
- * Queries can only order by one key at a time. Calling `orderByChild()`
1037
- * multiple times on the same query is an error.
1038
- *
1039
- * Firebase queries allow you to order your data by any child key on the fly.
1040
- * However, if you know in advance what your indexes will be, you can define
1041
- * them via the .indexOn rule in your Security Rules for better performance. See
1042
- * the {@link https://firebase.google.com/docs/database/security/indexing-data
1043
- * .indexOn} rule for more information.
1044
- *
1045
- * You can read more about `orderByChild()` in
1046
- * {@link
1047
- * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
1048
- * Sort data}.
1049
- *
1050
- * @example
1051
- * ```javascript
1052
- * var ref = admin.database().ref("dinosaurs");
1053
- * ref.orderByChild("height").on("child_added", function(snapshot) {
1054
- * console.log(snapshot.key + " was " + snapshot.val().height + " m tall");
1055
- * });
1056
- * ```
1057
- *
1058
- * @param path
1059
- * @return A new `Query` object.
1060
- */
1061
- orderByChild(path: string): admin.database.Query;
1062
-
1063
- /**
1064
- * Generates a new `Query` object ordered by key.
1065
- *
1066
- * Sorts the results of a query by their (ascending) key values.
1067
- *
1068
- * You can read more about `orderByKey()` in
1069
- * {@link
1070
- * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
1071
- * Sort data}.
1072
- *
1073
- * @example
1074
- * ```javascript
1075
- * var ref = admin.database().ref("dinosaurs");
1076
- * ref.orderByKey().on("child_added", function(snapshot) {
1077
- * console.log(snapshot.key);
1078
- * });
1079
- * ```
1080
- *
1081
- * @return A new `Query` object.
1082
- */
1083
- orderByKey(): admin.database.Query;
1084
-
1085
- /**
1086
- * Generates a new `Query` object ordered by priority.
1087
- *
1088
- * Applications need not use priority but can order collections by
1089
- * ordinary properties (see
1090
- * {@link
1091
- * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
1092
- * Sort data} for alternatives to priority.
1093
- *
1094
- * @return A new `Query` object.
1095
- */
1096
- orderByPriority(): admin.database.Query;
1097
-
1098
- /**
1099
- * Generates a new `Query` object ordered by value.
1100
- *
1101
- * If the children of a query are all scalar values (string, number, or
1102
- * boolean), you can order the results by their (ascending) values.
1103
- *
1104
- * You can read more about `orderByValue()` in
1105
- * {@link
1106
- * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
1107
- * Sort data}.
1108
- *
1109
- * @example
1110
- * ```javascript
1111
- * var scoresRef = admin.database().ref("scores");
1112
- * scoresRef.orderByValue().limitToLast(3).on("value", function(snapshot) {
1113
- * snapshot.forEach(function(data) {
1114
- * console.log("The " + data.key + " score is " + data.val());
1115
- * });
1116
- * });
1117
- * ```
1118
- *
1119
- * @return A new `Query` object.
1120
- */
1121
- orderByValue(): admin.database.Query;
1122
-
1123
- /**
1124
- * Creates a `Query` with the specified starting point.
1125
- *
1126
- * Using `startAt()`, `endAt()`, and `equalTo()` allows you to choose arbitrary
1127
- * starting and ending points for your queries.
1128
- *
1129
- * The starting point is inclusive, so children with exactly the specified value
1130
- * will be included in the query. The optional key argument can be used to
1131
- * further limit the range of the query. If it is specified, then children that
1132
- * have exactly the specified value must also have a key name greater than or
1133
- * equal to the specified key.
1134
- *
1135
- * You can read more about `startAt()` in
1136
- * {@link
1137
- * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
1138
- * Filtering data}.
1139
- *
1140
- * @example
1141
- * ```javascript
1142
- * // Find all dinosaurs that are at least three meters tall.
1143
- * var ref = admin.database().ref("dinosaurs");
1144
- * ref.orderByChild("height").startAt(3).on("child_added", function(snapshot) {
1145
- * console.log(snapshot.key)
1146
- * });
1147
- * ```
1148
- *
1149
- * @param value The value to start at. The argument
1150
- * type depends on which `orderBy*()` function was used in this query.
1151
- * Specify a value that matches the `orderBy*()` type. When used in
1152
- * combination with `orderByKey()`, the value must be a string.
1153
- * @param key The child key to start at. This argument is allowed if
1154
- * ordering by child, value, or priority.
1155
- * @return A new `Query` object.
1156
- */
1157
- startAt(value: number | string | boolean | null, key?: string): admin.database.Query;
1158
-
1159
- /**
1160
- * @return A JSON-serializable representation of this object.
1161
- */
1162
- toJSON(): Object;
1163
-
1164
- /**
1165
- * Gets the absolute URL for this location.
1166
- *
1167
- * The `toString()` method returns a URL that is ready to be put into a browser,
1168
- * curl command, or a `admin.database().refFromURL()` call. Since all of those
1169
- * expect the URL to be url-encoded, `toString()` returns an encoded URL.
1170
- *
1171
- * Append '.json' to the returned URL when typed into a browser to download
1172
- * JSON-formatted data. If the location is secured (that is, not publicly
1173
- * readable), you will get a permission-denied error.
1174
- *
1175
- * @example
1176
- * ```javascript
1177
- * // Calling toString() on a root Firebase reference returns the URL where its
1178
- * // data is stored within the Database:
1179
- * var rootRef = admin.database().ref();
1180
- * var rootUrl = rootRef.toString();
1181
- * // rootUrl === "https://sample-app.firebaseio.com/".
1182
- *
1183
- * // Calling toString() at a deeper Firebase reference returns the URL of that
1184
- * // deep path within the Database:
1185
- * var adaRef = rootRef.child('users/ada');
1186
- * var adaURL = adaRef.toString();
1187
- * // adaURL === "https://sample-app.firebaseio.com/users/ada".
1188
- * ```
1189
- *
1190
- * @return The absolute URL for this location.
1191
- * @override
1192
- */
1193
- toString(): string;
1194
- }
1195
-
1196
- /**
1197
- * A `Reference` represents a specific location in your Database and can be used
1198
- * for reading or writing data to that Database location.
1199
- *
1200
- * You can reference the root or child location in your Database by calling
1201
- * `admin.database().ref()` or `admin.database().ref("child/path")`.
1202
- *
1203
- * Writing is done with the `set()` method and reading can be done with the
1204
- * `on()` method. See
1205
- * {@link
1206
- * https://firebase.google.com/docs/database/web/read-and-write
1207
- * Read and Write Data on the Web}
1208
- */
1209
- interface Reference extends admin.database.Query {
1210
-
1211
- /**
1212
- * The last part of the `Reference`'s path.
1213
- *
1214
- * For example, `"ada"` is the key for
1215
- * `https://<DATABASE_NAME>.firebaseio.com/users/ada`.
1216
- *
1217
- * The key of a root `Reference` is `null`.
1218
- *
1219
- * @example
1220
- * ```javascript
1221
- * // The key of a root reference is null
1222
- * var rootRef = admin.database().ref();
1223
- * var key = rootRef.key; // key === null
1224
- * ```
1225
- *
1226
- * @example
1227
- * ```javascript
1228
- * // The key of any non-root reference is the last token in the path
1229
- * var adaRef = admin.database().ref("users/ada");
1230
- * var key = adaRef.key; // key === "ada"
1231
- * key = adaRef.child("name/last").key; // key === "last"
1232
- * ```
1233
- */
1234
- key: string | null;
1235
-
1236
- /**
1237
- * The parent location of a `Reference`.
1238
- *
1239
- * The parent of a root `Reference` is `null`.
1240
- *
1241
- * @example
1242
- * ```javascript
1243
- * // The parent of a root reference is null
1244
- * var rootRef = admin.database().ref();
1245
- * parent = rootRef.parent; // parent === null
1246
- * ```
1247
- *
1248
- * @example
1249
- * ```javascript
1250
- * // The parent of any non-root reference is the parent location
1251
- * var usersRef = admin.database().ref("users");
1252
- * var adaRef = admin.database().ref("users/ada");
1253
- * // usersRef and adaRef.parent represent the same location
1254
- * ```
1255
- */
1256
- parent: admin.database.Reference | null;
1257
-
1258
- /**
1259
- * The root `Reference` of the Database.
1260
- *
1261
- * @example
1262
- * ```javascript
1263
- * // The root of a root reference is itself
1264
- * var rootRef = admin.database().ref();
1265
- * // rootRef and rootRef.root represent the same location
1266
- * ```
1267
- *
1268
- * @example
1269
- * ```javascript
1270
- * // The root of any non-root reference is the root location
1271
- * var adaRef = admin.database().ref("users/ada");
1272
- * // rootRef and adaRef.root represent the same location
1273
- * ```
1274
- */
1275
- root: admin.database.Reference;
1276
- /** @deprecated Removed in next major release to match Web SDK typings. */
1277
- path: string;
1278
-
1279
- /**
1280
- * Gets a `Reference` for the location at the specified relative path.
1281
- *
1282
- * The relative path can either be a simple child name (for example, "ada") or
1283
- * a deeper slash-separated path (for example, "ada/name/first").
1284
- *
1285
- * @example
1286
- * ```javascript
1287
- * var usersRef = admin.database().ref('users');
1288
- * var adaRef = usersRef.child('ada');
1289
- * var adaFirstNameRef = adaRef.child('name/first');
1290
- * var path = adaFirstNameRef.toString();
1291
- * // path is now 'https://sample-app.firebaseio.com/users/ada/name/first'
1292
- * ```
1293
- *
1294
- * @param path A relative path from this location to the desired child
1295
- * location.
1296
- * @return The specified child location.
1297
- */
1298
- child(path: string): admin.database.Reference;
1299
-
1300
- /**
1301
- * Returns an `OnDisconnect` object - see
1302
- * {@link
1303
- * https://firebase.google.com/docs/database/web/offline-capabilities
1304
- * Enabling Offline Capabilities in JavaScript} for more information on how
1305
- * to use it.
1306
- *
1307
- * @return An `OnDisconnect` object .
1308
- */
1309
- onDisconnect(): admin.database.OnDisconnect;
1310
-
1311
- /**
1312
- * Generates a new child location using a unique key and returns its
1313
- * `Reference`.
1314
- *
1315
- * This is the most common pattern for adding data to a collection of items.
1316
- *
1317
- * If you provide a value to `push()`, the value will be written to the
1318
- * generated location. If you don't pass a value, nothing will be written to the
1319
- * Database and the child will remain empty (but you can use the `Reference`
1320
- * elsewhere).
1321
- *
1322
- * The unique key generated by `push()` are ordered by the current time, so the
1323
- * resulting list of items will be chronologically sorted. The keys are also
1324
- * designed to be unguessable (they contain 72 random bits of entropy).
1325
- *
1326
- *
1327
- * See
1328
- * {@link
1329
- * https://firebase.google.com/docs/database/web/lists-of-data#append_to_a_list_of_data
1330
- * Append to a list of data}
1331
- * </br>See
1332
- * {@link
1333
- * https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html
1334
- * The 2^120 Ways to Ensure Unique Identifiers}
1335
- *
1336
- * @example
1337
- * ```javascript
1338
- * var messageListRef = admin.database().ref('message_list');
1339
- * var newMessageRef = messageListRef.push();
1340
- * newMessageRef.set({
1341
- * user_id: 'ada',
1342
- * text: 'The Analytical Engine weaves algebraical patterns just as the Jacquard loom weaves flowers and leaves.'
1343
- * });
1344
- * // We've appended a new message to the message_list location.
1345
- * var path = newMessageRef.toString();
1346
- * // path will be something like
1347
- * // 'https://sample-app.firebaseio.com/message_list/-IKo28nwJLH0Nc5XeFmj'
1348
- * ```
1349
- *
1350
- * @param value Optional value to be written at the generated location.
1351
- * @param onComplete Callback called when write to server is
1352
- * complete.
1353
- * @return Combined `Promise` and
1354
- * `Reference`; resolves when write is complete, but can be used immediately
1355
- * as the `Reference` to the child location.
1356
- */
1357
- push(value?: any, onComplete?: (a: Error | null) => any): admin.database.ThenableReference;
1358
-
1359
- /**
1360
- * Removes the data at this Database location.
1361
- *
1362
- * Any data at child locations will also be deleted.
1363
- *
1364
- * The effect of the remove will be visible immediately and the corresponding
1365
- * event 'value' will be triggered. Synchronization of the remove to the
1366
- * Firebase servers will also be started, and the returned Promise will resolve
1367
- * when complete. If provided, the onComplete callback will be called
1368
- * asynchronously after synchronization has finished.
1369
- *
1370
- * @example
1371
- * ```javascript
1372
- * var adaRef = admin.database().ref('users/ada');
1373
- * adaRef.remove()
1374
- * .then(function() {
1375
- * console.log("Remove succeeded.")
1376
- * })
1377
- * .catch(function(error) {
1378
- * console.log("Remove failed: " + error.message)
1379
- * });
1380
- * ```
1381
- *
1382
- * @param onComplete Callback called when write to server is
1383
- * complete.
1384
- * @return Resolves when remove on server is complete.
1385
- */
1386
- remove(onComplete?: (a: Error | null) => any): Promise<void>;
1387
-
1388
- /**
1389
- * Writes data to this Database location.
1390
- *
1391
- * This will overwrite any data at this location and all child locations.
1392
- *
1393
- * The effect of the write will be visible immediately, and the corresponding
1394
- * events ("value", "child_added", etc.) will be triggered. Synchronization of
1395
- * the data to the Firebase servers will also be started, and the returned
1396
- * Promise will resolve when complete. If provided, the `onComplete` callback
1397
- * will be called asynchronously after synchronization has finished.
1398
- *
1399
- * Passing `null` for the new value is equivalent to calling `remove()`; namely,
1400
- * all data at this location and all child locations will be deleted.
1401
- *
1402
- * `set()` will remove any priority stored at this location, so if priority is
1403
- * meant to be preserved, you need to use `setWithPriority()` instead.
1404
- *
1405
- * Note that modifying data with `set()` will cancel any pending transactions
1406
- * at that location, so extreme care should be taken if mixing `set()` and
1407
- * `transaction()` to modify the same data.
1408
- *
1409
- * A single `set()` will generate a single "value" event at the location where
1410
- * the `set()` was performed.
1411
- *
1412
- * @example
1413
- * ```javascript
1414
- * var adaNameRef = admin.database().ref('users/ada/name');
1415
- * adaNameRef.child('first').set('Ada');
1416
- * adaNameRef.child('last').set('Lovelace');
1417
- * // We've written 'Ada' to the Database location storing Ada's first name,
1418
- * // and 'Lovelace' to the location storing her last name.
1419
- * ```
1420
- *
1421
- * @example
1422
- * ```javascript
1423
- * adaNameRef.set({ first: 'Ada', last: 'Lovelace' });
1424
- * // Exact same effect as the previous example, except we've written
1425
- * // Ada's first and last name simultaneously.
1426
- * ```
1427
- *
1428
- * @example
1429
- * ```javascript
1430
- * adaNameRef.set({ first: 'Ada', last: 'Lovelace' })
1431
- * .then(function() {
1432
- * console.log('Synchronization succeeded');
1433
- * })
1434
- * .catch(function(error) {
1435
- * console.log('Synchronization failed');
1436
- * });
1437
- * // Same as the previous example, except we will also log a message
1438
- * // when the data has finished synchronizing.
1439
- * ```
1440
- *
1441
- * @param value The value to be written (string, number, boolean, object,
1442
- * array, or null).
1443
- * @param onComplete Callback called when write to server is
1444
- * complete.
1445
- * @return Resolves when write to server is complete.
1446
- */
1447
- set(value: any, onComplete?: (a: Error | null) => any): Promise<void>;
1448
-
1449
- /**
1450
- * Sets a priority for the data at this Database location.
1451
- *
1452
- * Applications need not use priority but can order collections by
1453
- * ordinary properties (see
1454
- * {@link
1455
- * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
1456
- * Sorting and filtering data}).
1457
- *
1458
- * @param priority
1459
- * @param onComplete
1460
- * @return
1461
- */
1462
- setPriority(
1463
- priority: string | number | null,
1464
- onComplete: (a: Error | null) => any
1465
- ): Promise<void>;
1466
-
1467
- /**
1468
- * Writes data the Database location. Like `set()` but also specifies the
1469
- * priority for that data.
1470
- *
1471
- * Applications need not use priority but can order collections by
1472
- * ordinary properties (see
1473
- * {@link
1474
- * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
1475
- * Sorting and filtering data}).
1476
- *
1477
- * @param newVal
1478
- * @param newPriority
1479
- * @param onComplete
1480
- * @return
1481
- */
1482
- setWithPriority(
1483
- newVal: any, newPriority: string | number | null,
1484
- onComplete?: (a: Error | null) => any
1485
- ): Promise<void>;
1486
-
1487
- /**
1488
- * Atomically modifies the data at this location.
1489
- *
1490
- * Atomically modify the data at this location. Unlike a normal `set()`, which
1491
- * just overwrites the data regardless of its previous value, `transaction()` is
1492
- * used to modify the existing value to a new value, ensuring there are no
1493
- * conflicts with other clients writing to the same location at the same time.
1494
- *
1495
- * To accomplish this, you pass `transaction()` an update function which is used
1496
- * to transform the current value into a new value. If another client writes to
1497
- * the location before your new value is successfully written, your update
1498
- * function will be called again with the new current value, and the write will
1499
- * be retried. This will happen repeatedly until your write succeeds without
1500
- * conflict or you abort the transaction by not returning a value from your
1501
- * update function.
1502
- *
1503
- * Note: Modifying data with `set()` will cancel any pending transactions at
1504
- * that location, so extreme care should be taken if mixing `set()` and
1505
- * `transaction()` to update the same data.
1506
- *
1507
- * Note: When using transactions with Security and Firebase Rules in place, be
1508
- * aware that a client needs `.read` access in addition to `.write` access in
1509
- * order to perform a transaction. This is because the client-side nature of
1510
- * transactions requires the client to read the data in order to transactionally
1511
- * update it.
1512
- *
1513
- * @example
1514
- * ```javascript
1515
- * // Increment Ada's rank by 1.
1516
- * var adaRankRef = admin.database().ref('users/ada/rank');
1517
- * adaRankRef.transaction(function(currentRank) {
1518
- * // If users/ada/rank has never been set, currentRank will be `null`.
1519
- * return currentRank + 1;
1520
- * });
1521
- * ```
1522
- *
1523
- * @example
1524
- * ```javascript
1525
- * // Try to create a user for ada, but only if the user id 'ada' isn't
1526
- * // already taken
1527
- * var adaRef = admin.database().ref('users/ada');
1528
- * adaRef.transaction(function(currentData) {
1529
- * if (currentData === null) {
1530
- * return { name: { first: 'Ada', last: 'Lovelace' } };
1531
- * } else {
1532
- * console.log('User ada already exists.');
1533
- * return; // Abort the transaction.
1534
- * }
1535
- * }, function(error, committed, snapshot) {
1536
- * if (error) {
1537
- * console.log('Transaction failed abnormally!', error);
1538
- * } else if (!committed) {
1539
- * console.log('We aborted the transaction (because ada already exists).');
1540
- * } else {
1541
- * console.log('User ada added!');
1542
- * }
1543
- * console.log("Ada's data: ", snapshot.val());
1544
- * });
1545
- * ```
1546
- *
1547
- * @param transactionUpdate A developer-supplied function which
1548
- * will be passed the current data stored at this location (as a JavaScript
1549
- * object). The function should return the new value it would like written (as
1550
- * a JavaScript object). If `undefined` is returned (i.e. you return with no
1551
- * arguments) the transaction will be aborted and the data at this location
1552
- * will not be modified.
1553
- * @param onComplete A callback
1554
- * function that will be called when the transaction completes. The callback
1555
- * is passed three arguments: a possibly-null `Error`, a `boolean` indicating
1556
- * whether the transaction was committed, and a `DataSnapshot` indicating the
1557
- * final result. If the transaction failed abnormally, the first argument will
1558
- * be an `Error` object indicating the failure cause. If the transaction
1559
- * finished normally, but no data was committed because no data was returned
1560
- * from `transactionUpdate`, then second argument will be false. If the
1561
- * transaction completed and committed data to Firebase, the second argument
1562
- * will be true. Regardless, the third argument will be a `DataSnapshot`
1563
- * containing the resulting data in this location.
1564
- * @param applyLocally By default, events are raised each time the
1565
- * transaction update function runs. So if it is run multiple times, you may
1566
- * see intermediate states. You can set this to false to suppress these
1567
- * intermediate states and instead wait until the transaction has completed
1568
- * before events are raised.
1569
- * @return Returns a Promise that can optionally be used instead of the `onComplete`
1570
- * callback to handle success and failure.
1571
- */
1572
- transaction(
1573
- transactionUpdate: (a: any) => any,
1574
- onComplete?: (a: Error | null, b: boolean, c: admin.database.DataSnapshot | null) => any,
1575
- applyLocally?: boolean
1576
- ): Promise<{
1577
- committed: boolean;
1578
- snapshot: admin.database.DataSnapshot | null;
1579
- }>;
1580
-
1581
- /**
1582
- * Writes multiple values to the Database at once.
1583
- *
1584
- * The `values` argument contains multiple property-value pairs that will be
1585
- * written to the Database together. Each child property can either be a simple
1586
- * property (for example, "name") or a relative path (for example,
1587
- * "name/first") from the current location to the data to update.
1588
- *
1589
- * As opposed to the `set()` method, `update()` can be use to selectively update
1590
- * only the referenced properties at the current location (instead of replacing
1591
- * all the child properties at the current location).
1592
- *
1593
- * The effect of the write will be visible immediately, and the corresponding
1594
- * events ('value', 'child_added', etc.) will be triggered. Synchronization of
1595
- * the data to the Firebase servers will also be started, and the returned
1596
- * Promise will resolve when complete. If provided, the `onComplete` callback
1597
- * will be called asynchronously after synchronization has finished.
1598
- *
1599
- * A single `update()` will generate a single "value" event at the location
1600
- * where the `update()` was performed, regardless of how many children were
1601
- * modified.
1602
- *
1603
- * Note that modifying data with `update()` will cancel any pending
1604
- * transactions at that location, so extreme care should be taken if mixing
1605
- * `update()` and `transaction()` to modify the same data.
1606
- *
1607
- * Passing `null` to `update()` will remove the data at this location.
1608
- *
1609
- * See
1610
- * {@link
1611
- * https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html
1612
- * Introducing multi-location updates and more}.
1613
- *
1614
- * @example
1615
- * ```javascript
1616
- * var adaNameRef = admin.database().ref('users/ada/name');
1617
- * // Modify the 'first' and 'last' properties, but leave other data at
1618
- * // adaNameRef unchanged.
1619
- * adaNameRef.update({ first: 'Ada', last: 'Lovelace' });
1620
- * ```
1621
- *
1622
- * @param values object containing multiple values.
1623
- * @param onComplete Callback called when write to server is
1624
- * complete.
1625
- * @return Resolves when update on server is complete.
1626
- */
1627
- update(values: object, onComplete?: (a: Error | null) => any): Promise<void>;
1628
- }
1629
-
1630
- /**
1631
- * @extends {Reference}
1632
- */
1633
- interface ThenableReference extends admin.database.Reference, Promise<admin.database.Reference> { }
1634
-
1635
- function enableLogging(logger?: boolean | ((message: string) => any), persistent?: boolean): any;
1636
- }
1637
-
1638
- export namespace admin.database.ServerValue {
1639
-
1640
- /**
1641
- * A placeholder value for auto-populating the current timestamp (time
1642
- * since the Unix epoch, in milliseconds) as determined by the Firebase
1643
- * servers.
1644
- *
1645
- * @example
1646
- * ```javascript
1647
- * var sessionsRef = firebase.database().ref("sessions");
1648
- * sessionsRef.push({
1649
- * startedAt: firebase.database.ServerValue.TIMESTAMP
1650
- * });
1651
- * ```
1652
- */
1653
- const TIMESTAMP: Object;
1654
-
1655
- /**
1656
- * Returns a placeholder value that can be used to atomically increment the
1657
- * current database value by the provided delta.
1658
- *
1659
- * @param delta the amount to modify the current value atomically.
1660
- * @return a placeholder value for modifying data atomically server-side.
1661
- */
1662
- function increment(delta: number): Object;
1663
- }