@react-native-firebase/database 24.1.1 → 25.0.1

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 (126) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/module/DatabaseDataSnapshot.js +144 -0
  3. package/dist/module/DatabaseDataSnapshot.js.map +1 -0
  4. package/dist/module/DatabaseOnDisconnect.js +84 -0
  5. package/dist/module/DatabaseOnDisconnect.js.map +1 -0
  6. package/dist/module/DatabaseQuery.js +298 -0
  7. package/dist/module/DatabaseQuery.js.map +1 -0
  8. package/{lib → dist/module}/DatabaseQueryModifiers.js +49 -98
  9. package/dist/module/DatabaseQueryModifiers.js.map +1 -0
  10. package/dist/module/DatabaseReference.js +169 -0
  11. package/dist/module/DatabaseReference.js.map +1 -0
  12. package/dist/module/DatabaseStatics.js +35 -0
  13. package/dist/module/DatabaseStatics.js.map +1 -0
  14. package/{lib → dist/module}/DatabaseSyncTree.js +74 -156
  15. package/dist/module/DatabaseSyncTree.js.map +1 -0
  16. package/{lib → dist/module}/DatabaseThenableReference.js +12 -12
  17. package/dist/module/DatabaseThenableReference.js.map +1 -0
  18. package/{lib → dist/module}/DatabaseTransaction.js +26 -89
  19. package/dist/module/DatabaseTransaction.js.map +1 -0
  20. package/dist/module/index.js +27 -0
  21. package/dist/module/index.js.map +1 -0
  22. package/dist/module/modular/query.js +138 -0
  23. package/dist/module/modular/query.js.map +1 -0
  24. package/dist/module/modular/transaction.js +24 -0
  25. package/dist/module/modular/transaction.js.map +1 -0
  26. package/dist/module/modular.js +76 -0
  27. package/dist/module/modular.js.map +1 -0
  28. package/dist/module/namespaced.js +147 -0
  29. package/dist/module/namespaced.js.map +1 -0
  30. package/dist/module/package.json +1 -0
  31. package/dist/module/types/database.js +21 -0
  32. package/dist/module/types/database.js.map +1 -0
  33. package/dist/module/types/internal.js +4 -0
  34. package/dist/module/types/internal.js.map +1 -0
  35. package/dist/module/types/namespaced.js +67 -0
  36. package/dist/module/types/namespaced.js.map +1 -0
  37. package/dist/module/version.js +5 -0
  38. package/dist/module/version.js.map +1 -0
  39. package/dist/module/web/RNFBDatabaseModule.android.js +6 -0
  40. package/dist/module/web/RNFBDatabaseModule.android.js.map +1 -0
  41. package/dist/module/web/RNFBDatabaseModule.ios.js +6 -0
  42. package/dist/module/web/RNFBDatabaseModule.ios.js.map +1 -0
  43. package/dist/module/web/RNFBDatabaseModule.js +375 -0
  44. package/dist/module/web/RNFBDatabaseModule.js.map +1 -0
  45. package/{lib → dist/module}/web/query.js +19 -24
  46. package/dist/module/web/query.js.map +1 -0
  47. package/dist/typescript/lib/DatabaseDataSnapshot.d.ts +20 -0
  48. package/dist/typescript/lib/DatabaseDataSnapshot.d.ts.map +1 -0
  49. package/dist/typescript/lib/DatabaseOnDisconnect.d.ts +19 -0
  50. package/dist/typescript/lib/DatabaseOnDisconnect.d.ts.map +1 -0
  51. package/dist/typescript/lib/DatabaseQuery.d.ts +32 -0
  52. package/dist/typescript/lib/DatabaseQuery.d.ts.map +1 -0
  53. package/dist/typescript/lib/DatabaseQueryModifiers.d.ts +55 -0
  54. package/dist/typescript/lib/DatabaseQueryModifiers.d.ts.map +1 -0
  55. package/dist/typescript/lib/DatabaseReference.d.ts +21 -0
  56. package/dist/typescript/lib/DatabaseReference.d.ts.map +1 -0
  57. package/dist/typescript/lib/DatabaseStatics.d.ts +10 -0
  58. package/dist/typescript/lib/DatabaseStatics.d.ts.map +1 -0
  59. package/dist/typescript/lib/DatabaseSyncTree.d.ts +72 -0
  60. package/dist/typescript/lib/DatabaseSyncTree.d.ts.map +1 -0
  61. package/dist/typescript/lib/DatabaseThenableReference.d.ts +13 -0
  62. package/dist/typescript/lib/DatabaseThenableReference.d.ts.map +1 -0
  63. package/dist/typescript/lib/DatabaseTransaction.d.ts +15 -0
  64. package/dist/typescript/lib/DatabaseTransaction.d.ts.map +1 -0
  65. package/dist/typescript/lib/index.d.ts +6 -0
  66. package/dist/typescript/lib/index.d.ts.map +1 -0
  67. package/dist/typescript/lib/modular/query.d.ts +41 -0
  68. package/dist/typescript/lib/modular/query.d.ts.map +1 -0
  69. package/dist/typescript/lib/modular/transaction.d.ts +3 -0
  70. package/dist/typescript/lib/modular/transaction.d.ts.map +1 -0
  71. package/dist/typescript/lib/modular.d.ts +24 -0
  72. package/dist/typescript/lib/modular.d.ts.map +1 -0
  73. package/dist/typescript/lib/namespaced.d.ts +13 -0
  74. package/dist/typescript/lib/namespaced.d.ts.map +1 -0
  75. package/dist/typescript/lib/types/database.d.ts +93 -0
  76. package/dist/typescript/lib/types/database.d.ts.map +1 -0
  77. package/dist/typescript/lib/types/internal.d.ts +189 -0
  78. package/dist/typescript/lib/types/internal.d.ts.map +1 -0
  79. package/dist/typescript/lib/types/namespaced.d.ts +1230 -0
  80. package/dist/typescript/lib/types/namespaced.d.ts.map +1 -0
  81. package/dist/typescript/lib/version.d.ts +2 -0
  82. package/dist/typescript/lib/version.d.ts.map +1 -0
  83. package/dist/typescript/lib/web/RNFBDatabaseModule.android.d.ts +3 -0
  84. package/dist/typescript/lib/web/RNFBDatabaseModule.android.d.ts.map +1 -0
  85. package/dist/typescript/lib/web/RNFBDatabaseModule.d.ts +3 -0
  86. package/dist/typescript/lib/web/RNFBDatabaseModule.d.ts.map +1 -0
  87. package/dist/typescript/lib/web/RNFBDatabaseModule.ios.d.ts +3 -0
  88. package/dist/typescript/lib/web/RNFBDatabaseModule.ios.d.ts.map +1 -0
  89. package/dist/typescript/lib/web/query.d.ts +13 -0
  90. package/dist/typescript/lib/web/query.d.ts.map +1 -0
  91. package/dist/typescript/package.json +1 -0
  92. package/lib/{DatabaseDataSnapshot.js → DatabaseDataSnapshot.ts} +62 -88
  93. package/lib/{DatabaseOnDisconnect.js → DatabaseOnDisconnect.ts} +25 -23
  94. package/lib/{DatabaseQuery.js → DatabaseQuery.ts} +130 -144
  95. package/lib/DatabaseQueryModifiers.ts +283 -0
  96. package/lib/{DatabaseReference.js → DatabaseReference.ts} +103 -85
  97. package/lib/{DatabaseStatics.js → DatabaseStatics.ts} +4 -2
  98. package/lib/DatabaseSyncTree.ts +390 -0
  99. package/lib/DatabaseThenableReference.ts +73 -0
  100. package/lib/DatabaseTransaction.ts +172 -0
  101. package/lib/index.ts +25 -0
  102. package/lib/modular/query.ts +410 -0
  103. package/lib/modular/transaction.ts +34 -0
  104. package/lib/modular.ts +134 -0
  105. package/lib/{index.js → namespaced.ts} +91 -90
  106. package/lib/types/database.ts +144 -0
  107. package/lib/types/internal.ts +317 -0
  108. package/lib/{index.d.ts → types/namespaced.ts} +48 -9
  109. package/lib/version.ts +2 -0
  110. package/lib/web/RNFBDatabaseModule.android.ts +4 -0
  111. package/lib/web/RNFBDatabaseModule.ios.ts +4 -0
  112. package/lib/web/RNFBDatabaseModule.ts +534 -0
  113. package/lib/web/query.ts +97 -0
  114. package/package.json +42 -7
  115. package/tsconfig.json +21 -0
  116. package/typedoc.json +3 -3
  117. package/lib/modular/index.d.ts +0 -246
  118. package/lib/modular/index.js +0 -134
  119. package/lib/modular/query.d.ts +0 -972
  120. package/lib/modular/query.js +0 -305
  121. package/lib/modular/transaction.d.ts +0 -54
  122. package/lib/modular/transaction.js +0 -24
  123. package/lib/version.js +0 -2
  124. package/lib/web/RNFBDatabaseModule.android.js +0 -2
  125. package/lib/web/RNFBDatabaseModule.ios.js +0 -2
  126. package/lib/web/RNFBDatabaseModule.js +0 -558
@@ -0,0 +1,1230 @@
1
+ import { ReactNativeFirebase } from '@react-native-firebase/app';
2
+ /**
3
+ * Firebase Database package for React Native.
4
+ *
5
+ * #### Example 1
6
+ *
7
+ * Access the firebase export from the `database` package:
8
+ *
9
+ * ```js
10
+ * import { firebase } from '@react-native-firebase/database';
11
+ *
12
+ * // firebase.database().X
13
+ * ```
14
+ *
15
+ * #### Example 2
16
+ *
17
+ * Using the default export from the `database` package:
18
+ *
19
+ * ```js
20
+ * import database from '@react-native-firebase/database';
21
+ *
22
+ * // database().X
23
+ * ```
24
+ *
25
+ * #### Example 3
26
+ *
27
+ * Using the default export from the `app` package:
28
+ *
29
+ * ```js
30
+ * import firebase from '@react-native-firebase/app';
31
+ * import '@react-native-firebase/database';
32
+ *
33
+ * // firebase.database().X
34
+ * ```
35
+ *
36
+ * @firebase database
37
+ */
38
+ /**
39
+ * @deprecated Use the exported types directly instead.
40
+ * FirebaseDatabaseTypes namespace is kept for backwards compatibility.
41
+ */
42
+ export declare namespace FirebaseDatabaseTypes {
43
+ import FirebaseModule = ReactNativeFirebase.FirebaseModule;
44
+ /**
45
+ * The ServerValue interface provides access to Firebase server values.
46
+ */
47
+ /**
48
+ * @deprecated Use the exported `ServerValue` type instead.
49
+ */
50
+ interface ServerValue {
51
+ /**
52
+ * A placeholder value for auto-populating the current timestamp (time since the Unix epoch,
53
+ * in milliseconds) as determined by the Firebase servers.
54
+ *
55
+ * #### Example
56
+ *
57
+ * ```js
58
+ * firebase.database().ref('sessions').push({
59
+ * startedAt: firebase.database.ServerValue.TIMESTAMP,
60
+ * });
61
+ * ```
62
+ */
63
+ TIMESTAMP: object;
64
+ /**
65
+ * Returns a placeholder value that can be used to atomically increment the current database value by the provided delta.
66
+ *
67
+ * #### Example
68
+ *
69
+ * ```js
70
+ * firebase.database().ref('posts/123').update({
71
+ * likes: firebase.database.ServerValue.increment(1),
72
+ * });
73
+ * ```
74
+ *
75
+ * @param delta The amount to modify the current value atomically.
76
+ */
77
+ increment(delta: number): object;
78
+ }
79
+ /**
80
+ * Realtime Database statics.
81
+ *
82
+ * #### Example
83
+ *
84
+ * ```js
85
+ * firebase.database;
86
+ * ```
87
+ */
88
+ /**
89
+ * @deprecated Use the exported runtime/statics directly instead.
90
+ */
91
+ interface Statics {
92
+ /**
93
+ * Returns server specific values, such as the server timestamp.
94
+ *
95
+ * #### Example
96
+ *
97
+ * ```js
98
+ * firebase.database.ServerValue;
99
+ * ```
100
+ */
101
+ ServerValue: ServerValue;
102
+ SDK_VERSION: string;
103
+ }
104
+ /**
105
+ * @deprecated Use the exported `TransactionResult` type instead.
106
+ */
107
+ interface TransactionResult {
108
+ committed: boolean;
109
+ snapshot: DataSnapshot;
110
+ }
111
+ /**
112
+ * A Reference represents a specific location in your Database and can be used for reading or
113
+ * writing data to that Database location.
114
+ *
115
+ * You can reference the root or child location in your Database by calling `firebase.database().ref()`
116
+ * or `firebase.database().ref("child/path")`.
117
+ */
118
+ /**
119
+ * @deprecated Use the exported `DatabaseReference` type instead.
120
+ */
121
+ interface Reference extends Query {
122
+ /**
123
+ * The parent location of a Reference. The parent of a root Reference is `null`.
124
+ *
125
+ * #### Example
126
+ *
127
+ * ```js
128
+ * firebase.database().ref().parent; // null
129
+ * firebase.database().ref('users/dave').parent; // 'users' reference
130
+ * ```
131
+ */
132
+ parent: Reference | null;
133
+ /**
134
+ * The root Reference of the Database.
135
+ *
136
+ * #### Example
137
+ *
138
+ * ```js
139
+ * firebase.database().ref().root; // '/' reference path
140
+ * firebase.database().ref('users/ada').root; // '/' reference
141
+ * ```
142
+ */
143
+ root: Reference;
144
+ /**
145
+ * Gets a Reference for the location at the specified relative path.
146
+ *
147
+ * The relative path can either be a simple child name (for example, "ada") or a deeper
148
+ * slash-separated path (for example, "ada/name/first").
149
+ *
150
+ * #### Example
151
+ *
152
+ * ```js
153
+ * const usersRef = firebase.database().ref('users');
154
+ * const adaRef = usersRef.child('ada/name/first'); // childRef path is 'users/ada/name/first'
155
+ * ```
156
+ *
157
+ * @param path A relative path from this location to the desired child location.
158
+ */
159
+ child(path: string): Reference;
160
+ /**
161
+ * The last part of the Reference's path.
162
+ * For example, "ada" is the key for https://<DATABASE_NAME>.firebaseio.com/users/ada.
163
+ * The key of a root Reference is null.
164
+ */
165
+ key: string | null;
166
+ /**
167
+ * Writes data to this Database location.
168
+ *
169
+ * This will overwrite any data at this location and all child locations.
170
+ *
171
+ * The effect of the write will be visible immediately, and the corresponding events
172
+ * ("value", "child_added", etc.) will be triggered. Synchronization of the data to the
173
+ * Firebase servers will also be started, and the returned Promise will resolve when
174
+ * complete. If provided, the `onComplete` callback will be called asynchronously after
175
+ * synchronization has finished.
176
+ *
177
+ * Passing `null` for the new value is equivalent to calling `remove();` namely, all data at
178
+ * this location and all child locations will be deleted.
179
+ *
180
+ * `set()` will remove any priority stored at this location, so if priority is meant to be
181
+ * preserved, you need to use `setWithPriority()` instead.
182
+ *
183
+ * Note that modifying data with set() will cancel any pending transactions at that location,
184
+ * so extreme care should be taken if mixing set() and transaction() to modify the same data.
185
+ *
186
+ * A single set() will generate a single "value" event at the location where the set() was performed.
187
+ *
188
+ * #### Example - Setting values
189
+ *
190
+ * ```js
191
+ * const ref = firebase.database().ref('users');
192
+ *
193
+ * // Set a single node value
194
+ * await ref.child('ada/name/first').set('Ada');
195
+ * await ref.child('ada/name/last').set('Lovelace');
196
+ *
197
+ * // Set an object value in a single call
198
+ * await ref.child('ada/name').set({
199
+ * first: 'Ada',
200
+ * last: 'Lovelace',
201
+ * });
202
+ * ```
203
+ *
204
+ * #### Example - On complete listener
205
+ *
206
+ * ```js
207
+ * const ref = firebase.database().ref('users');
208
+ *
209
+ * await ref.child('ada/first/name').set('Ada', (error) => {
210
+ * if (error) console.error(error);
211
+ * });
212
+ * ```
213
+ *
214
+ * @param value The value to be written (string, number, boolean, object, array, or null).
215
+ * @param onComplete Callback called when write to server is complete. Contains the parameters (Error | null).
216
+ */
217
+ set(value: any, onComplete?: (error: Error | null) => void): Promise<void>;
218
+ /**
219
+ * Writes multiple values to the Database at once.
220
+ *
221
+ * The `values` argument contains multiple property-value pairs that will be written to the Database
222
+ * together. Each child property can either be a simple property (for example, "name") or a
223
+ * relative path (for example, "name/first") from the current location to the data to update.
224
+ *
225
+ * As opposed to the `set()` method, `update()` can be use to selectively update only the referenced
226
+ * properties at the current location (instead of replacing all the child properties at the
227
+ * current location).
228
+ *
229
+ * The effect of the write will be visible immediately, and the corresponding events ('value',
230
+ * 'child_added', etc.) will be triggered. Synchronization of the data to the Firebase servers
231
+ * will also be started, and the returned Promise will resolve when complete. If provided, the
232
+ * `onComplete` callback will be called asynchronously after synchronization has finished.
233
+ *
234
+ * A single update() will generate a single "value" event at the location where the update()
235
+ * was performed, regardless of how many children were modified.
236
+ *
237
+ * Note that modifying data with update() will cancel any pending transactions at that location,
238
+ * so extreme care should be taken if mixing update() and transaction() to modify the same data.
239
+ *
240
+ * Passing `null` to `update()` will remove the data at this location.
241
+ *
242
+ * #### Example
243
+ *
244
+ * Modify the 'first' and 'last' properties, but leave other values unchanged at this location.
245
+ *
246
+ * ```js
247
+ * await firebase.database().ref('users/ada/name').update({
248
+ * first: 'Ada',
249
+ * last: 'Lovelace',
250
+ * })
251
+ * ```
252
+ *
253
+ * @param values Object containing multiple values.
254
+ * @param onComplete Callback called when write to server is complete. Contains the parameters (Error | null).
255
+ */
256
+ update(values: {
257
+ [key: string]: any;
258
+ }, onComplete?: (error: Error | null) => void): Promise<void>;
259
+ /**
260
+ * Sets a priority for the data at this Database location. Setting null removes any priority at this location.
261
+ *
262
+ * See {@link Query#orderByPriority} to learn how to use priority values in your query.
263
+ *
264
+ * #### Example
265
+ *
266
+ * ```js
267
+ * await firebase.database().ref('users/ada').setPriority(1, (error) => {
268
+ * if (error) console.error(error);
269
+ * });
270
+ * ```
271
+ *
272
+ * @param priority The priority value.
273
+ * @param onComplete Callback called when write to server is complete. Contains the parameters (Error | null).
274
+ */
275
+ setPriority(priority: string | number | null, onComplete?: (error: Error | null) => void): Promise<void>;
276
+ /**
277
+ * Writes data the Database location. Like `set()` but also specifies the priority for that data.
278
+ *
279
+ * #### Example
280
+ *
281
+ * ```js
282
+ * await firebase.database().ref('users/ada/name')
283
+ * .setWithPriority({
284
+ * first: 'Ada',
285
+ * last: 'Lovelace',
286
+ * }, 1, (error) => {
287
+ * if (error) console.error(error);
288
+ * });
289
+ * ```
290
+ *
291
+ * @param newVal The new value to set.
292
+ * @param newPriority The new priority to set.
293
+ * @param onComplete Callback called when write to server is complete. Contains the parameters (Error | null).
294
+ */
295
+ setWithPriority(newVal: any, newPriority: string | number | null, onComplete?: (error: Error | null) => void): Promise<void>;
296
+ /**
297
+ * Removes the data at this Database location.
298
+ *
299
+ * Any data at child locations will also be deleted.
300
+ *
301
+ * The effect of the remove will be visible immediately and the corresponding event 'value' will be triggered.
302
+ * Synchronization of the remove to the Firebase servers will also be started, and the returned Promise will
303
+ * resolve when complete. If provided, the onComplete callback will be called asynchronously after synchronization
304
+ * has finished.
305
+ *
306
+ * #### Example
307
+ *
308
+ * ```js
309
+ * await firebase.database().ref('users/ada/name')
310
+ * .remove(() => {
311
+ * console.log('Operation Complete');
312
+ * });
313
+ * ```
314
+ *
315
+ * @param onComplete Callback called when write to server is complete. Contains the parameters (Error | null).
316
+ */
317
+ remove(onComplete?: (error: Error | null) => void): Promise<void>;
318
+ /**
319
+ * Atomically modifies the data at this location.
320
+ *
321
+ * Atomically modify the data at this location. Unlike a normal `set()`, which just overwrites
322
+ * the data regardless of its previous value, `transaction()` is used to modify the existing
323
+ * value to a new value, ensuring there are no conflicts with other clients writing to the same
324
+ * location at the same time.
325
+ *
326
+ * To accomplish this, you pass `transaction()` an update function which is used to transform the
327
+ * current value into a new value. If another client writes to the location before your new
328
+ * value is successfully written, your update function will be called again with the new
329
+ * current value, and the write will be retried. This will happen repeatedly until your write
330
+ * succeeds without conflict or you abort the transaction by not returning a value from your
331
+ * update function.
332
+ *
333
+ * Note: Modifying data with `set()` will cancel any pending transactions at that location, so
334
+ * extreme care should be taken if mixing `set()` and `transaction()` to update the same data.
335
+ *
336
+ * Note: When using transactions with Security and Firebase Rules in place, be aware that a
337
+ * client needs `.read` access in addition to `.write` access in order to perform a transaction.
338
+ * This is because the client-side nature of transactions requires the client to read the data
339
+ * in order to transactionally update it.
340
+ *
341
+ * #### Example
342
+ *
343
+ * ```js
344
+ * const userRef = firebase.database().ref('users/ada/profileViews);
345
+ *
346
+ * userRef.transaction((currentViews) => {
347
+ * if (currentViews === null) return 1;
348
+ * return currentViews + 1;
349
+ * });
350
+ * ```
351
+ *
352
+ * @param transactionUpdate A developer-supplied function which will be passed the current data stored at this location (as a JavaScript object). The function should return the new value it would like written (as a JavaScript object). If undefined is returned (i.e. you return with no result) the transaction will be aborted and the data at this location will not be modified.
353
+ * @param onComplete A callback function that will be called when the transaction completes. The callback is passed three arguments: a possibly-null Error, a boolean indicating whether the transaction was committed, and a DataSnapshot indicating the final result. If the transaction failed abnormally, the first argument will be an Error object indicating the failure cause. If the transaction finished normally, but no data was committed because no data was returned from transactionUpdate, then second argument will be false. If the transaction completed and committed data to Firebase, the second argument will be true. Regardless, the third argument will be a DataSnapshot containing the resulting data in this location.
354
+ * @param applyLocally By default, events are raised each time the transaction update function runs. So if it is run multiple times, you may see intermediate states. You can set this to false to suppress these intermediate states and instead wait until the transaction has completed before events are raised.
355
+ */
356
+ transaction(transactionUpdate: (currentData: any) => any | undefined, onComplete?: (error: Error | null, committed: boolean, finalResult: DataSnapshot | null) => void, applyLocally?: boolean): Promise<TransactionResult>;
357
+ /**
358
+ * Generates a new child location using a unique key and returns its `Reference`.
359
+ *
360
+ * This is the most common pattern for adding data to a collection of items.
361
+ *
362
+ * If you provide a value to `push()`, the value will be written to the generated location.
363
+ * If you don't pass a value, nothing will be written to the Database and the child will
364
+ * remain empty (but you can use the `Reference` elsewhere).
365
+ *
366
+ * The unique key generated by push() are ordered by the current time, so the resulting list
367
+ * of items will be chronologically sorted. The keys are also designed to be unguessable
368
+ * (they contain 72 random bits of entropy).
369
+ *
370
+ * #### Example
371
+ *
372
+ * ```js
373
+ * const newUserRef = firebase.database().ref('users').push();
374
+ * console.log('New record key:', newUserRef.key);
375
+ * await newUserRef.set({
376
+ * first: 'Ada',
377
+ * last: 'Lovelace',
378
+ * });
379
+ * ```
380
+ *
381
+ * @param value Optional value to be written at the generated location.
382
+ * @param onComplete Callback called when write to server is complete.
383
+ */
384
+ push(value?: any, onComplete?: (error: Error | null) => void): ThenableReference;
385
+ /**
386
+ * Returns an {@link OnDisconnect} instance.
387
+ *
388
+ * #### Example
389
+ *
390
+ * ```js
391
+ * const userDisconnectRef = firebase.database().ref('users/ada/isOnline').onDisconnect();
392
+ * // When going offline
393
+ * await userDisconnectRef.update(false);
394
+ * ```
395
+ */
396
+ onDisconnect(): OnDisconnect;
397
+ }
398
+ /**
399
+ * @deprecated Use the exported `ThenableReference` type instead.
400
+ */
401
+ interface ThenableReference extends Reference, Pick<Promise<Reference>, 'then' | 'catch'> {
402
+ }
403
+ /**
404
+ * A Query sorts and filters the data at a Database location so only a subset of the child data
405
+ * is included. This can be used to order a collection of data by some attribute (for example,
406
+ * height of dinosaurs) as well as to restrict a large list of items (for example, chat messages)
407
+ * down to a number suitable for synchronizing to the client. Queries are created by chaining
408
+ * together one or more of the filter methods defined here.
409
+ *
410
+ * Just as with a `Reference`, you can receive data from a Query by using the on() method. You will
411
+ * only receive events and `DataSnapshot`s for the subset of the data that matches your query.
412
+ */
413
+ /**
414
+ * @deprecated Use the exported `Query` type instead.
415
+ */
416
+ interface Query {
417
+ /**
418
+ * Returns a Reference to the Query's location.
419
+ */
420
+ ref: Reference;
421
+ /**
422
+ * Creates a Query with the specified ending point.
423
+ *
424
+ * Using `startAt()`, `endAt()`, and `equalTo()` allows you to choose arbitrary starting and
425
+ * ending points for your queries.
426
+ *
427
+ * The ending point is inclusive, so children with exactly the specified value will be included
428
+ * in the query. The optional key argument can be used to further limit the range of the query.
429
+ * If it is specified, then children that have exactly the specified value must also have a key
430
+ * name less than or equal to the specified key.
431
+ *
432
+ * You can read more about endAt() in [Filtering data](https://firebase.google.com/docs/database/web/lists-of-data?authuser=0#filtering_data).
433
+ *
434
+ * #### Example
435
+ *
436
+ * ```js
437
+ * const ref = firebase.database().ref('users');
438
+ * const snapshot = await ref.orderByKey().endAt('Ada Lovelace').once('value');
439
+ * ```
440
+ *
441
+ * @param value The value to end at. The argument type depends on which `orderBy*()` function was used in this query. Specify a value that matches the `orderBy*()` type. When used in combination with `orderByKey()`, the value must be a string.
442
+ * @param key The child key to end at, among the children with the previously specified priority. This argument is only allowed if ordering by child, value, or priority.
443
+ */
444
+ endAt(value: number | string | boolean | null, key?: string): Query;
445
+ /**
446
+ * Creates a Query with the specified ending point.
447
+ *
448
+ * Using `startAt()`, `endAt()`, and `equalTo()` allows you to choose arbitrary starting and
449
+ * ending points for your queries.
450
+ *
451
+ * The optional key argument can be used to further limit the range of the query. If it is
452
+ * specified, then children that have exactly the specified value must also have exactly the
453
+ * specified key as their key name. This can be used to filter result sets with many matches for the same value.
454
+ *
455
+ * You can read more about equalTo() in [Filtering data](https://firebase.google.com/docs/database/web/lists-of-data?authuser=0#filtering_data).
456
+ *
457
+ * #### Example
458
+ *
459
+ * ```js
460
+ * const ref = firebase.database().ref('users');
461
+ * const snapshot = await ref.orderByChild('age').equalTo(30).once('value');
462
+ * ```
463
+ *
464
+ * @param value The value to match for. The argument type depends on which `orderBy*()` function was used in this query. Specify a value that matches the `orderBy*()` type. When used in combination with `orderByKey()`, the value must be a string.
465
+ * @param key The child key to start at, among the children with the previously specified priority. This argument is only allowed if ordering by child, value, or priority.
466
+ */
467
+ equalTo(value: number | string | boolean | null, key?: string): Query;
468
+ /**
469
+ * Returns whether or not the current and provided queries represent the same location, have the same query parameters.
470
+ *
471
+ * Two Reference objects are equivalent if they represent the same location and are from the same instance of
472
+ * {@link @firebase/app!FirebaseApp}. Equivalent queries share the same sort order, limits, and starting and ending points.
473
+ *
474
+ * #### Example
475
+ *
476
+ * ```js
477
+ * const ref1 = firebase.database().ref('users').orderByKey().endAt('Ada Lovelace');
478
+ * const ref2 = firebase.database().ref('users').orderByKey();
479
+ *
480
+ * console.log(ref1.isEqual(ref2)); // false
481
+ * ```
482
+ *
483
+ * #### Example
484
+ *
485
+ * ```js
486
+ * const ref1 = firebase.database().ref('users').orderByKey().endAt('Ada Lovelace');
487
+ * const ref2 = firebase.database().ref('users').endAt('Ada Lovelace').orderByKey();
488
+ *
489
+ * console.log(ref1.isEqual(ref2)); // true
490
+ * ```
491
+ *
492
+ * @param other The query to compare against.
493
+ */
494
+ isEqual(other: Query): boolean;
495
+ /**
496
+ * Generates a new `Query` limited to the first specific number of children.
497
+ *
498
+ * The `limitToFirst()` method is used to set a maximum number of children to be synced for a
499
+ * given callback. If we set a limit of 100, we will initially only receive up to 100 `child_added`
500
+ * events. If we have fewer than 100 messages stored in our Database, a child_added event will
501
+ * fire for each message. However, if we have over 100 messages, we will only receive a `child_added`
502
+ * event for the first 100 ordered messages. As items change, we will receive `child_removed` events
503
+ * for each item that drops out of the active list so that the total number stays at 100.
504
+ *
505
+ * You can read more about `limitToFirst()` in [Filtering data](https://firebase.google.com/docs/database/web/lists-of-data?authuser=0#filtering_data).
506
+ *
507
+ * #### Example
508
+ *
509
+ * ```js
510
+ * const snapshot = firebase.database().ref('users').orderByKey().limitToFirst(2).once('value');
511
+ * console.log(snapshot.numChildren()); // 2
512
+ * ```
513
+ *
514
+ * @param limit The maximum number of nodes to include in this query.
515
+ */
516
+ limitToFirst(limit: number): Query;
517
+ /**
518
+ * Generates a new `Query` object limited to the last specific number of children.
519
+ *
520
+ * The `limitToLast()` method is used to set a maximum number of children to be synced for a given
521
+ * callback. If we set a limit of 100, we will initially only receive up to 100 `child_added` events.
522
+ * If we have fewer than 100 messages stored in our Database, a `child_added` event will fire for
523
+ * each message. However, if we have over 100 messages, we will only receive a `child_added` event
524
+ * for the last 100 ordered messages. As items change, we will receive `child_removed` events for
525
+ * each item that drops out of the active list so that the total number stays at 100.
526
+ *
527
+ * You can read more about `limitToLast()` in [Filtering data](https://firebase.google.com/docs/database/web/lists-of-data?authuser=0#filtering_data).
528
+ *
529
+ * #### Example
530
+ *
531
+ * ```js
532
+ * const snapshot = firebase.database().ref('users').orderByKey().limitToLast(2).once('value');
533
+ * console.log(snapshot.numChildren()); // 2
534
+ * ```
535
+ *
536
+ * @param limit The maximum number of nodes to include in this query.
537
+ */
538
+ limitToLast(limit: number): Query;
539
+ /**
540
+ * Detaches a callback previously attached with `on()`.
541
+ *
542
+ * Detach a callback previously attached with `on()`. Note that if `on()` was called multiple times
543
+ * with the same eventType and callback, the callback will be called multiple times for each
544
+ * event, and `off()` must be called multiple times to remove the callback. Calling `off()` on a parent
545
+ * listener will not automatically remove listeners registered on child nodes, `off()` must also be
546
+ * called on any child listeners to remove the callback.
547
+ *
548
+ * If a callback is not specified, all callbacks for the specified eventType will be removed.
549
+ * Similarly, if no eventType is specified, all callbacks for the `Reference` will be removed.
550
+ *
551
+ * #### Example
552
+ *
553
+ * ```js
554
+ * const ref = firebase.database().ref('settings');
555
+ * const onValueChange = function(snapshot) { ... };
556
+ * const onChildAdded = function(snapshot) { ... };
557
+ *
558
+ * ref.on('value', onValueChange);
559
+ * ref.child('meta-data').on('child_added', onChildAdded);
560
+ * // Sometime later...
561
+ * ref.off('value', onValueChange);
562
+ * ref.child('meta-data').off('child_added', onChildAdded);
563
+ * ```
564
+ *
565
+ * @param eventType One of the following strings: "value", "child_added", "child_changed", "child_removed", or "child_moved." If omitted, all callbacks for the Reference will be removed.
566
+ * @param callback The callback function that was passed to `on()` or `undefined` to remove all callbacks.
567
+ * @param context The context that was passed to `on()`.
568
+ */
569
+ off(eventType?: EventType, callback?: (a: DataSnapshot, b?: string | null) => void, context?: Record<string, any>): void;
570
+ /**
571
+ * Listens for data changes at a particular location.
572
+ *
573
+ * This is the primary way to read data from a Database. Your callback will be triggered for the
574
+ * initial data and again whenever the data changes. Use `off()` to stop receiving updates..
575
+ *
576
+ * **value** event
577
+ *
578
+ * This event will trigger once with the initial data stored at this location, and then trigger
579
+ * again each time the data changes. The `DataSnapshot` passed to the callback will be for the location
580
+ * at which on() was called. It won't trigger until the entire contents has been synchronized.
581
+ * If the location has no data, it will be triggered with an empty `DataSnapshot`
582
+ * (`val()` will return `null`).
583
+ *
584
+ * **child_added** event
585
+ *
586
+ * This event will be triggered once for each initial child at this location, and it will be
587
+ * triggered again every time a new child is added. The `DataSnapshot` passed into the callback
588
+ * will reflect the data for the relevant child. For ordering purposes, it is passed a second argument
589
+ * which is a string containing the key of the previous sibling child by sort order, or `null` if
590
+ * it is the first child.
591
+ *
592
+ * **child_removed** event
593
+ *
594
+ * This event will be triggered once every time a child is removed. The `DataSnapshot` passed into
595
+ * the callback will be the old data for the child that was removed. A child will get removed when either:
596
+ * - a client explicitly calls `remove()` on that child or one of its ancestors
597
+ * - a client calls `set(null)` on that child or one of its ancestors
598
+ * - that child has all of its children removed
599
+ * - there is a query in effect which now filters out the child (because it's sort order changed or the max limit was hit)
600
+ *
601
+ * **child_changed** event
602
+ *
603
+ * This event will be triggered when the data stored in a child (or any of its descendants) changes.
604
+ * Note that a single `child_changed` event may represent multiple changes to the child. The
605
+ * `DataSnapshot` passed to the callback will contain the new child contents. For ordering purposes,
606
+ * the callback is also passed a second argument which is a string containing the key of the previous
607
+ * sibling child by sort order, or `null` if it is the first child.
608
+ *
609
+ * **child_moved** event
610
+ *
611
+ * This event will be triggered when a child's sort order changes such that its position relative
612
+ * to its siblings changes. The `DataSnapshot` passed to the callback will be for the data of the child
613
+ * that has moved. It is also passed a second argument which is a string containing the key of the
614
+ * previous sibling child by sort order, or `null` if it is the first child.
615
+ *
616
+ * @param eventType One of the following strings: "value", "child_added", "child_changed", "child_removed", or "child_moved."
617
+ * @param callback A callback that fires when the specified event occurs. The callback will be passed a DataSnapshot. For ordering purposes, "child_added", "child_changed", and "child_moved" will also be passed a string containing the key of the previous child, by sort order, or `null` if it is the first child.
618
+ * @param cancelCallbackOrContext An optional callback that will be notified if your event subscription is ever canceled because your client does not have permission to read this data (or it had permission but has now lost it). This callback will be passed an `Error` object indicating why the failure occurred.
619
+ * @param context If provided, this object will be used as `this` when calling your callback(s).
620
+ *
621
+ */
622
+ on(eventType: EventType, callback: (data: DataSnapshot, previousChildKey?: string | null) => void, cancelCallbackOrContext?: ((a: Error) => void) | Record<string, any> | null, context?: Record<string, any> | null): (a: DataSnapshot | null, b?: string | null) => void;
623
+ /**
624
+ * Listens for exactly one event of the specified event type, and then stops listening.
625
+ *
626
+ * This is equivalent to calling `on()`, and then calling `off()` inside the callback function. See `on()` for details on the event types.
627
+ *
628
+ * #### Example
629
+ *
630
+ * ```js
631
+ * // Promise
632
+ * const snapshot = await firebase.database().ref('users').once('value');
633
+ * // Callback
634
+ * firebase.database().ref('users).once('value', (snapshot) => {
635
+ * console.log(snapshot.val());
636
+ * });
637
+ * ```
638
+ *
639
+ * @param eventType One of the following strings: "value", "child_added", "child_changed", "child_removed", or "child_moved."
640
+ * @param successCallback A callback that fires when the specified event occurs. The callback will be passed a DataSnapshot. For ordering purposes, "child_added", "child_changed", and "child_moved" will also be passed a string containing the key of the previous child by sort order, or `null` if it is the first child.
641
+ @param failureCallbackContext An optional callback that will be notified if your client does not have permission to read the data. This callback will be passed an Error object indicating why the failure occurred.
642
+ */
643
+ once(eventType: EventType, successCallback?: (a: DataSnapshot, b?: string | null) => any, failureCallbackContext?: ((a: Error) => void) | Record<string, any> | null): Promise<DataSnapshot>;
644
+ /**
645
+ * Generates a new `Query` object ordered by the specified child key.
646
+ *
647
+ * Queries can only order by one key at a time. Calling `orderByChild()` multiple times on the same query is an error.
648
+ *
649
+ * Firebase queries allow you to order your data by any child key on the fly. However, if you know in advance what
650
+ * your indexes will be, you can define them via the [.indexOn](https://firebase.google.com/docs/database/security/indexing-data?authuser=0)
651
+ * rule in your Security Rules for better performance.
652
+ *
653
+ * You can read more about orderByChild() in [Sort data](https://firebase.google.com/docs/database/web/lists-of-data?authuser=0#sort_data).
654
+ *
655
+ * #### Example
656
+ *
657
+ * ```js
658
+ * const snapshot = await firebase.database().ref('users').orderByChild('age').once('value');
659
+ * snapshot.forEach((snapshot) => {
660
+ * console.log('Users age:', snapshot.val().age);
661
+ * });
662
+ * ```
663
+ *
664
+ * @param path The child path node to order by.
665
+ */
666
+ orderByChild(path: string): Query;
667
+ /**
668
+ * Generates a new `Query` object ordered by key.
669
+ *
670
+ * Sorts the results of a query by their (ascending) key values.
671
+ *
672
+ * You can read more about `orderByKey()` in [Sort data](https://firebase.google.com/docs/database/web/lists-of-data?authuser=0#sort_data).
673
+ *
674
+ * #### Example
675
+ *
676
+ * ```js
677
+ * const snapshot = await firebase.database().ref('users').orderByKey().once('value');
678
+ * snapshot.forEach((snapshot) => {
679
+ * console.log('User:', snapshot.val());
680
+ * });
681
+ * ```
682
+ */
683
+ orderByKey(): Query;
684
+ /**
685
+ * Generates a new Query object ordered by priority.
686
+ *
687
+ * Applications need not use priority but can order collections by ordinary properties
688
+ * (see [Sort data](https://firebase.google.com/docs/database/web/lists-of-data?authuser=0#sort_data)
689
+ * for alternatives to priority).
690
+ */
691
+ orderByPriority(): Query;
692
+ /**
693
+ * Generates a new `Query` object ordered by value.
694
+ *
695
+ * If the children of a query are all scalar values (string, number, or boolean), you can order
696
+ * the results by their (ascending) values.
697
+ *
698
+ * You can read more about `orderByValue()` in [Sort data](https://firebase.google.com/docs/database/web/lists-of-data?authuser=0#sort_data).
699
+ *
700
+ * #### Example
701
+ *
702
+ * ```js
703
+ * await firebase.database().ref('scores').orderByValue().once('value');
704
+ * ```
705
+ */
706
+ orderByValue(): Query;
707
+ /**
708
+ * Creates a `Query` with the specified starting point.
709
+ *
710
+ * Using `startAt()`, `endAt()`, and `equalTo()` allows you to choose arbitrary starting and
711
+ * ending points for your queries.
712
+ *
713
+ * The starting point is inclusive, so children with exactly the specified value will be included
714
+ * in the query. The optional key argument can be used to further limit the range of the query.
715
+ * If it is specified, then children that have exactly the specified value must also have a key
716
+ * name greater than or equal to the specified key.
717
+ *
718
+ * You can read more about `startAt()` in [Filtering data](https://firebase.google.com/docs/database/web/lists-of-data?authuser=0#filtering_data).
719
+ *
720
+ * #### Example
721
+ *
722
+ * ```js
723
+ * await firebase.database().ref('users').orderByChild('age').startAt(21).once('value');
724
+ * ```
725
+ *
726
+ * @param value The value to start at. The argument type depends on which `orderBy*()` function was used in this query. Specify a value that matches the `orderBy*()` type. When used in combination with `orderByKey()`, the value must be a string.
727
+ * @param key The child key to start at. This argument is only allowed if ordering by child, value, or priority.
728
+ */
729
+ startAt(value: number | string | boolean | null, key?: string): Query;
730
+ /**
731
+ * Returns a JSON-serializable representation of this object.
732
+ */
733
+ toJSON(): string;
734
+ /**
735
+ * Gets the absolute URL for this location.
736
+ *
737
+ * The `toString()` method returns a URL that is ready to be put into a browser, curl command, or
738
+ * a `firebase.database().refFromURL()` call. Since all of those expect the URL to be url-encoded,
739
+ * `toString()` returns an encoded URL.
740
+ *
741
+ * Append '.json' to the returned URL when typed into a browser to download JSON-formatted data.
742
+ * If the location is secured (that is, not publicly readable), you will get a permission-denied error.
743
+ *
744
+ * #### Example
745
+ *
746
+ * ```js
747
+ * const ref1 = firebase.database().ref();
748
+ * const ref2 = firebase.database().ref('users').orderByValue();
749
+ *
750
+ * ref1.toString(); // https://sample-app.firebaseio.com/
751
+ * ref2.toString(); // https://sample-app.firebaseio.com/users
752
+ * ```
753
+ */
754
+ toString(): string;
755
+ /**
756
+ * By calling `keepSynced(true)` on a location, the data for that location will automatically
757
+ * be downloaded and kept in sync, even when no listeners are attached for that location.
758
+ *
759
+ * #### Example
760
+ *
761
+ * ```js
762
+ * const ref = firebase.database().ref('users');
763
+ * await ref.keepSynced(true);
764
+ * ```
765
+ *
766
+ * @param bool Pass `true` to keep this location synchronized, pass `false` to stop synchronization.
767
+ */
768
+ keepSynced(bool: boolean): Promise<void>;
769
+ }
770
+ /**
771
+ * The `onDisconnect` class allows you to write or clear data when your client disconnects from the Database server.
772
+ * These updates occur whether your client disconnects cleanly or not, so you can rely on them to clean up data
773
+ * even if a connection is dropped or a client crashes.
774
+ *
775
+ * The onDisconnect class is most commonly used to manage presence in applications where it is
776
+ * useful to detect how many clients are connected and when other clients disconnect.
777
+ *
778
+ * To avoid problems when a connection is dropped before the requests can be transferred to the Database
779
+ * server, these functions should be called before writing any data.
780
+ *
781
+ * Note that `onDisconnect` operations are only triggered once. If you want an operation to occur each time a
782
+ * disconnect occurs, you'll need to re-establish the `onDisconnect` operations each time you reconnect.
783
+ */
784
+ /**
785
+ * @deprecated Use the exported `OnDisconnect` type instead.
786
+ */
787
+ interface OnDisconnect {
788
+ /**
789
+ * Cancels all previously queued `onDisconnect()` set or update events for this location and all children.
790
+ *
791
+ * If a write has been queued for this location via a `set()` or `update()` at a parent location,
792
+ * the write at this location will be canceled, though writes to sibling locations will still occur.
793
+ *
794
+ * #### Example
795
+ *
796
+ * ```js
797
+ * const ref = firebase.database().ref('onlineState');
798
+ * await ref.onDisconnect().set(false);
799
+ * // Sometime later...
800
+ * await ref.onDisconnect().cancel();
801
+ * ```
802
+ *
803
+ * @param onComplete An optional callback function that will be called when synchronization to the server has completed. The callback will be passed a single parameter: null for success, or an Error object indicating a failure.
804
+ */
805
+ cancel(onComplete?: (error: Error | null) => void): Promise<void>;
806
+ /**
807
+ * Ensures the data at this location is deleted when the client is disconnected (due to closing the browser, navigating to a new page, or network issues).
808
+ *
809
+ * @param onComplete An optional callback function that will be called when synchronization to the server has completed. The callback will be passed a single parameter: null for success, or an Error object indicating a failure.
810
+ */
811
+ remove(onComplete?: (error: Error | null) => void): Promise<void>;
812
+ /**
813
+ * Ensures the data at this location is set to the specified value when the client is disconnected
814
+ * (due to closing the app, navigating to a new view, or network issues).
815
+ *
816
+ * `set()` is especially useful for implementing "presence" systems, where a value should be changed
817
+ * or cleared when a user disconnects so that they appear "offline" to other users.
818
+ *
819
+ * Note that `onDisconnect` operations are only triggered once. If you want an operation to occur each time a
820
+ * disconnect occurs, you'll need to re-establish the `onDisconnect` operations each time.
821
+ *
822
+ * #### Example
823
+ *
824
+ * ```js
825
+ * var ref = firebase.database().ref('users/ada/status');
826
+ * await ref.onDisconnect().set('I disconnected!');
827
+ * ```
828
+ *
829
+ * @param value The value to be written to this location on disconnect (can be an object, array, string, number, boolean, or null).
830
+ * @param onComplete An optional callback function that will be called when synchronization to the Database server has completed. The callback will be passed a single parameter: null for success, or an Error object indicating a failure.
831
+ */
832
+ set(value: any, onComplete?: (error: Error | null) => void): Promise<void>;
833
+ /**
834
+ * Ensures the data at this location is set to the specified value and priority when the client is disconnected (due to closing the browser, navigating to a new page, or network issues).
835
+ *
836
+ * @param value The value to set.
837
+ * @param priority The priority to set
838
+ * @param onComplete An optional callback function that will be called when synchronization to the Database server has completed. The callback will be passed a single parameter: null for success, or an Error object indicating a failure.
839
+ */
840
+ setWithPriority(value: any, priority: string | number | null, onComplete?: (error: Error | null) => void): Promise<void>;
841
+ /**
842
+ * Writes multiple values at this location when the client is disconnected (due to closing the browser, navigating to a new page, or network issues).
843
+ *
844
+ * The `values` argument contains multiple property-value pairs that will be written to the Database together.
845
+ * Each child property can either be a simple property (for example, "name") or a relative path (for example,
846
+ * "name/first") from the current location to the data to update.
847
+ *
848
+ * As opposed to the `set()` method, `update()` can be use to selectively update only the referenced
849
+ * properties at the current location (instead of replacing all the child properties at the current location).
850
+ *
851
+ * #### Example
852
+ *
853
+ * ```js
854
+ * var ref = firebase.database().ref("users/ada");
855
+ * ref.update({
856
+ * onlineState: true,
857
+ * status: "I'm online."
858
+ * });
859
+ * ref.onDisconnect().update({
860
+ * onlineState: false,
861
+ * status: "I'm offline."
862
+ * });
863
+ * ```
864
+ *
865
+ * @param values Object containing multiple values.
866
+ * @param onComplete An optional callback function that will be called when synchronization to the server has completed. The callback will be passed a single parameter: null for success, or an Error object indicating a failure.
867
+ */
868
+ update(values: {
869
+ [key: string]: any;
870
+ }, onComplete?: (error: Error | null) => void): Promise<void>;
871
+ }
872
+ /**
873
+ * @deprecated Use the exported `EventType` type instead.
874
+ */
875
+ type EventType = 'value' | 'child_added' | 'child_changed' | 'child_moved' | 'child_removed';
876
+ /**
877
+ * A `DataSnapshot` contains data from a Database location.
878
+ *
879
+ * Any time you read data from the Database, you receive the data as a `DataSnapshot`. A `DataSnapshot`
880
+ * is passed to the event callbacks you attach with `on()` or `once()`. You can extract the contents
881
+ * of the snapshot as a JavaScript object by calling the val() method. Alternatively, you can traverse
882
+ * into the snapshot by calling `child()` to return child snapshots (which you could then call `val()` on).
883
+ */
884
+ /**
885
+ * @deprecated Use the exported `DataSnapshot` type instead.
886
+ */
887
+ interface DataSnapshot {
888
+ /**
889
+ * The key (last part of the path) of the location of this `DataSnapshot`.
890
+ *
891
+ * The last token in a Database location is considered its key. For example, "ada" is the key
892
+ * for the /users/ada/ node. Accessing the key on any `DataSnapshot` will return the key for the
893
+ * location that generated it. However, accessing the key on the root URL of a Database will return `null`.
894
+ */
895
+ key: string | null;
896
+ /**
897
+ * The Reference for the location that generated this `DataSnapshot`.
898
+ */
899
+ ref: Reference;
900
+ /**
901
+ * Gets another `DataSnapshot` for the location at the specified relative path.
902
+ *
903
+ * Passing a relative path to the `child()` method of a DataSnapshot returns another `DataSnapshot`
904
+ * for the location at the specified relative path. The relative path can either be a simple child
905
+ * name (for example, "ada") or a deeper, slash-separated path (for example, "ada/name/first").
906
+ * If the child location has no data, an empty `DataSnapshot` (that is, a `DataSnapshot` whose value
907
+ * is `null`) is returned.
908
+ *
909
+ * #### Example
910
+ *
911
+ * ```js
912
+ * const snapshot = await firebase.database().ref('users/ada').once('value');
913
+ * snapshot.child('name').val(); // {first:"Ada",last:"Lovelace"}
914
+ * snapshot.child('name/first').val(); // "Ada"
915
+ * snapshot.child('name/foo').val(); // null
916
+ * ```
917
+ *
918
+ * @param path A relative path to the location of child data.
919
+ */
920
+ child(path: string): DataSnapshot;
921
+ /**
922
+ * Returns true if this `DataSnapshot` contains any data. It is slightly more efficient than using snapshot.val() !== null.
923
+ *
924
+ * #### Example
925
+ *
926
+ * ```js
927
+ * const snapshot = await firebase.database().ref('users/ada').once('value');
928
+ * snapshot.exists(); // true
929
+ * snapshot.child('name/foo').exists(); // false
930
+ * ```
931
+ */
932
+ exists(): boolean;
933
+ /**
934
+ * Exports the entire contents of the DataSnapshot as a JavaScript object.
935
+ *
936
+ * The `exportVal()` method is similar to val(), except priority information is included (if available),
937
+ * making it suitable for backing up your data.
938
+ *
939
+ * #### Example
940
+ *
941
+ * ```js
942
+ * const snapshot = await firebase.database().ref('users/ada').once('value');
943
+ * const data = snapshot.exportVal();
944
+ * console.log(data['.value']); // { ... }
945
+ * console.log(data['.priority']); // null
946
+ * ```
947
+ */
948
+ exportVal(): any;
949
+ /**
950
+ * Enumerates the top-level children in the `DataSnapshot`.
951
+ *
952
+ * Because of the way JavaScript objects work, the ordering of data in the JavaScript object
953
+ * returned by `val()` is not guaranteed to match the ordering on the server nor the ordering
954
+ * of `child_added` events. That is where `forEach()` comes in handy. It guarantees the children of
955
+ * a DataSnapshot will be iterated in their query order.
956
+ *
957
+ * If no explicit `orderBy*()` method is used, results are returned ordered by key (unless priorities are used, in which case, results are returned by priority).
958
+ *
959
+ * @param action A function that will be called for each child DataSnapshot. The callback can return true to cancel further enumeration.
960
+ */
961
+ forEach(action: (child: DataSnapshot) => boolean | void): boolean;
962
+ /**
963
+ * Gets the priority value of the data in this DataSnapshot.
964
+ */
965
+ getPriority(): string | number | null;
966
+ /**
967
+ * Returns true if the specified child path has (non-null) data.
968
+ *
969
+ * #### Example
970
+ *
971
+ * ```js
972
+ * const snapshot = await firebase.database().ref('users/ada').once('value');
973
+ * console.log(snapshot.hasChild('name')); // true
974
+ * console.log(snapshot.hasChild('foo')); // false
975
+ * ```
976
+ *
977
+ * @param path A relative path to the location of a potential child.
978
+ */
979
+ hasChild(path: string): boolean;
980
+ /**
981
+ * Returns whether or not the `DataSnapshot` has any non-null child properties.
982
+ *
983
+ * You can use `hasChildren()` to determine if a `DataSnapshot` has any children. If it does, you
984
+ * can enumerate them using `forEach()`. If it doesn't, then either this snapshot contains a primitive
985
+ * value (which can be retrieved with `val()`) or it is empty (in which case, `val()` will return null).
986
+ *
987
+ * #### Example
988
+ *
989
+ * ```js
990
+ * const snapshot = await firebase.database().ref('users').once('value');
991
+ * console.log(snapshot.hasChildren()); // true
992
+ * ```
993
+ */
994
+ hasChildren(): boolean;
995
+ /**
996
+ * Returns the number of child properties of this DataSnapshot.
997
+ */
998
+ numChildren(): number;
999
+ /**
1000
+ * Returns a JSON-serializable representation of this object.
1001
+ */
1002
+ toJSON(): object | null;
1003
+ /**
1004
+ * Extracts a JavaScript value from a `DataSnapshot`.
1005
+ *
1006
+ * Depending on the data in a DataSnapshot, the `val()` method may return a scalar type (string,
1007
+ * number, or boolean), an array, or an object. It may also return null, indicating that the
1008
+ * `DataSnapshot` is empty (contains no data).
1009
+ *
1010
+ * #### Example
1011
+ *
1012
+ * ```js
1013
+ * const snapshot = await firebase.database().ref('users/ada/last').once('value');
1014
+ * snapshot.val(); // "Lovelace"
1015
+ * ```
1016
+ */
1017
+ val(): any;
1018
+ }
1019
+ /**
1020
+ *
1021
+ * The Firebase Database service is available for the default app or a given app.
1022
+ *
1023
+ * #### Example 1
1024
+ *
1025
+ * Get the database instance for the **default app**:
1026
+ *
1027
+ * ```js
1028
+ * const databaseForDefaultApp = firebase.database();
1029
+ * ```
1030
+ *
1031
+ * #### Example 2
1032
+ *
1033
+ * Get the database instance for a **secondary app**:
1034
+ *
1035
+ * ```js
1036
+ * const otherApp = firebase.app('otherApp');
1037
+ * const databaseForOtherApp = firebase.database(otherApp);
1038
+ * ```
1039
+ *
1040
+ */
1041
+ /**
1042
+ * @deprecated Use the exported `Database` type and modular API instead.
1043
+ */
1044
+ class Module extends FirebaseModule {
1045
+ /**
1046
+ * The current `FirebaseApp` instance for this Firebase service.
1047
+ */
1048
+ app: ReactNativeFirebase.FirebaseApp;
1049
+ /**
1050
+ * Returns the current Firebase Database server time as a JavaScript Date object.
1051
+ */
1052
+ getServerTime(): Date;
1053
+ /**
1054
+ * Returns a `Reference` representing the location in the Database corresponding to the provided path.
1055
+ * If no path is provided, the Reference will point to the root of the Database.
1056
+ *
1057
+ * #### Example
1058
+ *
1059
+ * ```js
1060
+ * // Get a reference to the root of the Database
1061
+ * const rootRef = firebase.database().ref();
1062
+ *
1063
+ * // Get a reference to the /users/ada node
1064
+ * const adaRef = firebase.database().ref("users/ada");
1065
+ * ```
1066
+ *
1067
+ * @param path Optional path representing the location the returned `Reference` will point. If not provided, the returned `Reference` will point to the root of the Database.
1068
+ */
1069
+ ref(path?: string): Reference;
1070
+ /**
1071
+ * Returns a `Reference` representing the location in the Database corresponding to the provided Firebase URL.
1072
+ *
1073
+ * An exception is thrown if the URL is not a valid Firebase Database URL or it has a different domain than the current Database instance.
1074
+ *
1075
+ * Note that all query parameters (orderBy, limitToLast, etc.) are ignored and are not applied to the returned Reference.
1076
+ *
1077
+ * #### Example
1078
+ *
1079
+ * ```js
1080
+ * // Get a reference to the root of the Database
1081
+ * const rootRef = firebase.database().ref("https://<DATABASE_NAME>.firebaseio.com");
1082
+ * ```
1083
+ *
1084
+ * @param url The Firebase URL at which the returned Reference will point.
1085
+ */
1086
+ refFromURL(url: string): Reference;
1087
+ /**
1088
+ * Reconnects to the server and synchronizes the offline Database state with the server state.
1089
+ *
1090
+ * This method should be used after disabling the active connection with `goOffline()`. Once
1091
+ * reconnected, the client will transmit the proper data and fire the appropriate events so that
1092
+ * your client "catches up" automatically.
1093
+ *
1094
+ * #### Example
1095
+ *
1096
+ * ```js
1097
+ * await firebase.database().goOnline();
1098
+ * ```
1099
+ */
1100
+ goOnline(): Promise<void>;
1101
+ /**
1102
+ * Disconnects from the server (all Database operations will be completed offline).
1103
+ *
1104
+ * The client automatically maintains a persistent connection to the Database server, which
1105
+ * will remain active indefinitely and reconnect when disconnected. However, the `goOffline()` and
1106
+ * `goOnline()` methods may be used to control the client connection in cases where a persistent
1107
+ * connection is undesirable.
1108
+ *
1109
+ * While offline, the client will no longer receive data updates from the Database. However,
1110
+ * all Database operations performed locally will continue to immediately fire events, allowing
1111
+ * your application to continue behaving normally. Additionally, each operation performed locally
1112
+ * will automatically be queued and retried upon reconnection to the Database server.
1113
+ *
1114
+ * To reconnect to the Database and begin receiving remote events, see `goOnline()`.
1115
+ *
1116
+ * #### Example
1117
+ *
1118
+ * ```js
1119
+ * await firebase.database().goOnline();
1120
+ * ```
1121
+ */
1122
+ goOffline(): Promise<void>;
1123
+ /**
1124
+ * Sets whether persistence is enabled for all database calls for the current app
1125
+ * instance.
1126
+ *
1127
+ * > Ensure this is called before any database calls are performed, otherwise
1128
+ * persistence will only come into effect when the app is next started.
1129
+ *
1130
+ * #### Example
1131
+ *
1132
+ * ```js
1133
+ * firebase.database().setPersistenceEnabled(true);
1134
+ *
1135
+ * async function bootstrap() {
1136
+ * // Bootstrapping application
1137
+ * const snapshot = await firebase.database().ref('settings').once('value');
1138
+ * }
1139
+ * ```
1140
+ *
1141
+ * @param enabled Whether persistence is enabled for the Database service.
1142
+ */
1143
+ setPersistenceEnabled(enabled: boolean): void;
1144
+ /**
1145
+ * Sets the native logging level for the database module. By default,
1146
+ * only warnings and errors are logged natively. Setting this to true will log all
1147
+ * database events.
1148
+ *
1149
+ * > Ensure logging is disabled for production apps, as excessive logging can cause performance issues.
1150
+ *
1151
+ * #### Example
1152
+ *
1153
+ * ```js
1154
+ * // Set debug logging if developing
1155
+ * if (__DEV__) {
1156
+ * firebase.database().setLoggingEnabled(true);
1157
+ * }
1158
+ * ```
1159
+ *
1160
+ * @param enabled Whether debug logging is enabled.
1161
+ */
1162
+ setLoggingEnabled(enabled: boolean): void;
1163
+ /**
1164
+ * By default Firebase Database will use up to 10MB of disk space to cache data. If the cache grows beyond this size,
1165
+ * Firebase Database will start removing data that hasn't been recently used. If you find that your application
1166
+ * caches too little or too much data, call this method to change the cache size. This method must be called before
1167
+ * creating your first Database reference and only needs to be called once per application.
1168
+ *
1169
+ * Note that the specified cache size is only an approximation and the size on disk may temporarily exceed it at times.
1170
+ * Cache sizes smaller than 1 MB or greater than 100 MB are not supported.
1171
+ *
1172
+ * #### Example
1173
+ *
1174
+ * ```js
1175
+ * firebase.database().setPersistenceEnabled(true);
1176
+ * firebase.database().setPersistenceCacheSizeBytes(2000000); // 2MB
1177
+ *
1178
+ * async function bootstrap() {
1179
+ * // Bootstrapping application
1180
+ * const snapshot = await firebase.database().ref('settings').once('value');
1181
+ * }
1182
+ * ```
1183
+ *
1184
+ * @param bytes The new size of the cache in bytes.
1185
+ */
1186
+ setPersistenceCacheSizeBytes(bytes: number): void;
1187
+ /**
1188
+ * Modify this Database instance to communicate with the Firebase Database emulator.
1189
+ * This must be called synchronously immediately following the first call to firebase.database().
1190
+ * Do not use with production credentials as emulator traffic is not encrypted.
1191
+ *
1192
+ * Note: on android, hosts 'localhost' and '127.0.0.1' are automatically remapped to '10.0.2.2' (the
1193
+ * "host" computer IP address for android emulators) to make the standard development experience easy.
1194
+ * If you want to use the emulator on a real android device, you will need to specify the actual host
1195
+ * computer IP address.
1196
+ *
1197
+ * @param host: emulator host (eg, 'localhost')
1198
+ * @param port: emulator port (eg, 9000)
1199
+ */
1200
+ useEmulator(host: string, port: number): void;
1201
+ }
1202
+ }
1203
+ type DatabaseNamespace = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<FirebaseDatabaseTypes.Module, FirebaseDatabaseTypes.Statics> & {
1204
+ database: ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<FirebaseDatabaseTypes.Module, FirebaseDatabaseTypes.Statics>;
1205
+ firebase: ReactNativeFirebase.Module;
1206
+ app(name?: string): ReactNativeFirebase.FirebaseApp;
1207
+ };
1208
+ declare const defaultExport: DatabaseNamespace;
1209
+ export declare const firebase: ReactNativeFirebase.Module & {
1210
+ database: typeof defaultExport;
1211
+ app(name?: string): ReactNativeFirebase.FirebaseApp & {
1212
+ database(): FirebaseDatabaseTypes.Module;
1213
+ };
1214
+ };
1215
+ export default defaultExport;
1216
+ /**
1217
+ * Attach namespace to `firebase.` and `FirebaseApp.`.
1218
+ */
1219
+ declare module '@react-native-firebase/app' {
1220
+ namespace ReactNativeFirebase {
1221
+ import FirebaseModuleWithStaticsAndApp = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp;
1222
+ interface Module {
1223
+ database: FirebaseModuleWithStaticsAndApp<FirebaseDatabaseTypes.Module, FirebaseDatabaseTypes.Statics>;
1224
+ }
1225
+ interface FirebaseApp {
1226
+ database(databaseUrl?: string): FirebaseDatabaseTypes.Module;
1227
+ }
1228
+ }
1229
+ }
1230
+ //# sourceMappingURL=namespaced.d.ts.map