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