@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,410 @@
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 { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/dist/module/common';
19
+ import type {
20
+ DataSnapshot,
21
+ DatabaseReference,
22
+ EventType,
23
+ ListenOptions,
24
+ OnDisconnect,
25
+ Query,
26
+ QueryConstraintType,
27
+ ThenableReference,
28
+ Unsubscribe,
29
+ } from '../types/database';
30
+ import { QueryConstraint } from '../types/database';
31
+ import type {
32
+ DatabaseReferenceWithMethodsInternal,
33
+ QueryConstraintWithApplyInternal,
34
+ QueryWithModifiersInternal,
35
+ QueryWithSubscriptionMethodsInternal,
36
+ } from '../types/internal';
37
+
38
+ class DatabaseQueryConstraint extends QueryConstraint {
39
+ readonly type: QueryConstraintType;
40
+ private readonly args: unknown[];
41
+
42
+ constructor(type: QueryConstraintType, ...args: unknown[]) {
43
+ super();
44
+ this.type = type;
45
+ this.args = args;
46
+ }
47
+
48
+ _apply(query: Query): Query {
49
+ return (query as QueryWithModifiersInternal)[this.type].apply(query, [
50
+ ...this.args,
51
+ MODULAR_DEPRECATION_ARG,
52
+ ]);
53
+ }
54
+ }
55
+
56
+ type SnapshotCallbackInternal =
57
+ | ((snapshot: DataSnapshot) => unknown)
58
+ | ((snapshot: DataSnapshot, previousChildName: string | null) => unknown);
59
+
60
+ export function endAt(value: number | string | boolean | null, key?: string): QueryConstraint {
61
+ return new DatabaseQueryConstraint('endAt', value, key);
62
+ }
63
+
64
+ export function endBefore(value: number | string | boolean | null, key?: string): QueryConstraint {
65
+ return new DatabaseQueryConstraint('endBefore', value, key);
66
+ }
67
+
68
+ export function startAt(value?: number | string | boolean | null, key?: string): QueryConstraint {
69
+ return new DatabaseQueryConstraint('startAt', value, key);
70
+ }
71
+
72
+ export function startAfter(value: number | string | boolean | null, key?: string): QueryConstraint {
73
+ return new DatabaseQueryConstraint('startAfter', value, key);
74
+ }
75
+
76
+ export function limitToFirst(limit: number): QueryConstraint {
77
+ return new DatabaseQueryConstraint('limitToFirst', limit);
78
+ }
79
+
80
+ export function limitToLast(limit: number): QueryConstraint {
81
+ return new DatabaseQueryConstraint('limitToLast', limit);
82
+ }
83
+
84
+ export function orderByChild(path: string): QueryConstraint {
85
+ return new DatabaseQueryConstraint('orderByChild', path);
86
+ }
87
+
88
+ export function orderByKey(): QueryConstraint {
89
+ return new DatabaseQueryConstraint('orderByKey');
90
+ }
91
+
92
+ export function orderByPriority(): QueryConstraint {
93
+ return new DatabaseQueryConstraint('orderByPriority');
94
+ }
95
+
96
+ export function orderByValue(): QueryConstraint {
97
+ return new DatabaseQueryConstraint('orderByValue');
98
+ }
99
+
100
+ export function equalTo(value: number | string | boolean | null, key?: string): QueryConstraint {
101
+ return new DatabaseQueryConstraint('equalTo', value, key);
102
+ }
103
+
104
+ export function query(queryRef: Query, ...queryConstraints: QueryConstraint[]): Query {
105
+ let nextQuery = queryRef;
106
+ for (const queryConstraint of queryConstraints as QueryConstraintWithApplyInternal[]) {
107
+ nextQuery = queryConstraint._apply(nextQuery);
108
+ }
109
+ return nextQuery;
110
+ }
111
+
112
+ function addEventListener(
113
+ queryRef: Query,
114
+ eventType: EventType,
115
+ callback: SnapshotCallbackInternal,
116
+ cancelCallbackOrListenOptions?: ((error: Error) => unknown) | ListenOptions,
117
+ options?: ListenOptions,
118
+ ): Unsubscribe {
119
+ let cancelCallback = cancelCallbackOrListenOptions;
120
+
121
+ if (typeof cancelCallbackOrListenOptions === 'object') {
122
+ cancelCallback = undefined;
123
+ options = cancelCallbackOrListenOptions;
124
+ }
125
+
126
+ const queryWithSubscriptions = queryRef as QueryWithSubscriptionMethodsInternal;
127
+ let listenerCallback = callback;
128
+
129
+ if (options?.onlyOnce) {
130
+ const userCallback = callback;
131
+ listenerCallback = ((snapshot: DataSnapshot, previousChildName?: string | null) => {
132
+ queryWithSubscriptions.off.call(
133
+ queryRef,
134
+ eventType,
135
+ listenerCallback as (snapshot: DataSnapshot, previousChildName?: string | null) => unknown,
136
+ null,
137
+ MODULAR_DEPRECATION_ARG,
138
+ );
139
+
140
+ return (
141
+ userCallback as (snapshot: DataSnapshot, previousChildName?: string | null) => unknown
142
+ )(snapshot, previousChildName);
143
+ }) as SnapshotCallbackInternal;
144
+ }
145
+
146
+ queryWithSubscriptions.on.call(
147
+ queryRef,
148
+ eventType,
149
+ listenerCallback as (snapshot: DataSnapshot, previousChildName?: string | null) => unknown,
150
+ cancelCallback as ((error: Error) => unknown) | undefined,
151
+ null,
152
+ MODULAR_DEPRECATION_ARG,
153
+ );
154
+
155
+ return () =>
156
+ queryWithSubscriptions.off.call(
157
+ queryRef,
158
+ eventType,
159
+ listenerCallback as (snapshot: DataSnapshot, previousChildName?: string | null) => unknown,
160
+ null,
161
+ MODULAR_DEPRECATION_ARG,
162
+ );
163
+ }
164
+
165
+ export function onValue(
166
+ queryRef: Query,
167
+ callback: (snapshot: DataSnapshot) => unknown,
168
+ cancelCallback?: (error: Error) => unknown,
169
+ ): Unsubscribe;
170
+ export function onValue(
171
+ queryRef: Query,
172
+ callback: (snapshot: DataSnapshot) => unknown,
173
+ options: ListenOptions,
174
+ ): Unsubscribe;
175
+ export function onValue(
176
+ queryRef: Query,
177
+ callback: (snapshot: DataSnapshot) => unknown,
178
+ cancelCallback: (error: Error) => unknown,
179
+ options: ListenOptions,
180
+ ): Unsubscribe;
181
+ export function onValue(
182
+ queryRef: Query,
183
+ callback: (snapshot: DataSnapshot) => unknown,
184
+ cancelCallbackOrListenOptions?: ((error: Error) => unknown) | ListenOptions,
185
+ options?: ListenOptions,
186
+ ): Unsubscribe {
187
+ return addEventListener(queryRef, 'value', callback, cancelCallbackOrListenOptions, options);
188
+ }
189
+
190
+ export function onChildAdded(
191
+ queryRef: Query,
192
+ callback: (snapshot: DataSnapshot, previousChildName?: string | null) => unknown,
193
+ cancelCallback?: (error: Error) => unknown,
194
+ ): Unsubscribe;
195
+ export function onChildAdded(
196
+ queryRef: Query,
197
+ callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown,
198
+ options: ListenOptions,
199
+ ): Unsubscribe;
200
+ export function onChildAdded(
201
+ queryRef: Query,
202
+ callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown,
203
+ cancelCallback: (error: Error) => unknown,
204
+ options: ListenOptions,
205
+ ): Unsubscribe;
206
+ export function onChildAdded(
207
+ queryRef: Query,
208
+ callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown,
209
+ cancelCallbackOrListenOptions?: ((error: Error) => unknown) | ListenOptions,
210
+ options?: ListenOptions,
211
+ ): Unsubscribe {
212
+ return addEventListener(
213
+ queryRef,
214
+ 'child_added',
215
+ callback,
216
+ cancelCallbackOrListenOptions,
217
+ options,
218
+ );
219
+ }
220
+
221
+ export function onChildChanged(
222
+ queryRef: Query,
223
+ callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown,
224
+ cancelCallback?: (error: Error) => unknown,
225
+ ): Unsubscribe;
226
+ export function onChildChanged(
227
+ queryRef: Query,
228
+ callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown,
229
+ options: ListenOptions,
230
+ ): Unsubscribe;
231
+ export function onChildChanged(
232
+ queryRef: Query,
233
+ callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown,
234
+ cancelCallback: (error: Error) => unknown,
235
+ options: ListenOptions,
236
+ ): Unsubscribe;
237
+ export function onChildChanged(
238
+ queryRef: Query,
239
+ callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown,
240
+ cancelCallbackOrListenOptions?: ((error: Error) => unknown) | ListenOptions,
241
+ options?: ListenOptions,
242
+ ): Unsubscribe {
243
+ return addEventListener(
244
+ queryRef,
245
+ 'child_changed',
246
+ callback,
247
+ cancelCallbackOrListenOptions,
248
+ options,
249
+ );
250
+ }
251
+
252
+ export function onChildMoved(
253
+ queryRef: Query,
254
+ callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown,
255
+ cancelCallback?: (error: Error) => unknown,
256
+ ): Unsubscribe;
257
+ export function onChildMoved(
258
+ queryRef: Query,
259
+ callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown,
260
+ options: ListenOptions,
261
+ ): Unsubscribe;
262
+ export function onChildMoved(
263
+ queryRef: Query,
264
+ callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown,
265
+ cancelCallback: (error: Error) => unknown,
266
+ options: ListenOptions,
267
+ ): Unsubscribe;
268
+ export function onChildMoved(
269
+ queryRef: Query,
270
+ callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown,
271
+ cancelCallbackOrListenOptions?: ((error: Error) => unknown) | ListenOptions,
272
+ options?: ListenOptions,
273
+ ): Unsubscribe {
274
+ return addEventListener(
275
+ queryRef,
276
+ 'child_moved',
277
+ callback,
278
+ cancelCallbackOrListenOptions,
279
+ options,
280
+ );
281
+ }
282
+
283
+ export function onChildRemoved(
284
+ queryRef: Query,
285
+ callback: (snapshot: DataSnapshot) => unknown,
286
+ cancelCallback?: (error: Error) => unknown,
287
+ ): Unsubscribe;
288
+ export function onChildRemoved(
289
+ queryRef: Query,
290
+ callback: (snapshot: DataSnapshot) => unknown,
291
+ options: ListenOptions,
292
+ ): Unsubscribe;
293
+ export function onChildRemoved(
294
+ queryRef: Query,
295
+ callback: (snapshot: DataSnapshot) => unknown,
296
+ cancelCallback: (error: Error) => unknown,
297
+ options: ListenOptions,
298
+ ): Unsubscribe;
299
+ export function onChildRemoved(
300
+ queryRef: Query,
301
+ callback: (snapshot: DataSnapshot) => unknown,
302
+ cancelCallbackOrListenOptions?: ((error: Error) => unknown) | ListenOptions,
303
+ options?: ListenOptions,
304
+ ): Unsubscribe {
305
+ return addEventListener(
306
+ queryRef,
307
+ 'child_removed',
308
+ callback,
309
+ cancelCallbackOrListenOptions,
310
+ options,
311
+ );
312
+ }
313
+
314
+ export function set(ref: DatabaseReference, value: unknown): Promise<void> {
315
+ return (ref as DatabaseReferenceWithMethodsInternal).set.call(
316
+ ref,
317
+ value,
318
+ () => {},
319
+ MODULAR_DEPRECATION_ARG,
320
+ );
321
+ }
322
+
323
+ export function setPriority(
324
+ ref: DatabaseReference,
325
+ priority: string | number | null,
326
+ ): Promise<void> {
327
+ return (ref as DatabaseReferenceWithMethodsInternal).setPriority.call(
328
+ ref,
329
+ priority,
330
+ () => {},
331
+ MODULAR_DEPRECATION_ARG,
332
+ );
333
+ }
334
+
335
+ export function setWithPriority(
336
+ ref: DatabaseReference,
337
+ value: unknown,
338
+ priority: string | number | null,
339
+ ): Promise<void> {
340
+ return (ref as DatabaseReferenceWithMethodsInternal).setWithPriority.call(
341
+ ref,
342
+ value,
343
+ priority,
344
+ () => {},
345
+ MODULAR_DEPRECATION_ARG,
346
+ );
347
+ }
348
+
349
+ export function get(queryRef: Query): Promise<DataSnapshot> {
350
+ return (queryRef as QueryWithSubscriptionMethodsInternal).once.call(
351
+ queryRef,
352
+ 'value',
353
+ () => {},
354
+ () => {},
355
+ {},
356
+ MODULAR_DEPRECATION_ARG,
357
+ );
358
+ }
359
+
360
+ export function off(
361
+ _query: Query,
362
+ _eventType?: EventType,
363
+ _callback?: (snapshot: DataSnapshot, previousChildName?: string | null) => unknown,
364
+ ): void {
365
+ throw new Error('off() is not implemented - use unsubscriber callback returned when subscribing');
366
+ }
367
+
368
+ export function child(parent: DatabaseReference, path: string): DatabaseReference {
369
+ return (parent as DatabaseReferenceWithMethodsInternal).child.call(
370
+ parent,
371
+ path,
372
+ MODULAR_DEPRECATION_ARG,
373
+ );
374
+ }
375
+
376
+ export function onDisconnect(ref: DatabaseReference): OnDisconnect {
377
+ return (ref as DatabaseReferenceWithMethodsInternal).onDisconnect.call(
378
+ ref,
379
+ MODULAR_DEPRECATION_ARG,
380
+ );
381
+ }
382
+
383
+ export function keepSynced(ref: DatabaseReference, bool: boolean): Promise<void> {
384
+ return (ref as DatabaseReferenceWithMethodsInternal).keepSynced.call(
385
+ ref,
386
+ bool,
387
+ MODULAR_DEPRECATION_ARG,
388
+ );
389
+ }
390
+
391
+ export function push(parent: DatabaseReference, value?: unknown): ThenableReference {
392
+ return (parent as DatabaseReferenceWithMethodsInternal).push.call(
393
+ parent,
394
+ value,
395
+ undefined,
396
+ MODULAR_DEPRECATION_ARG,
397
+ );
398
+ }
399
+
400
+ export function remove(ref: DatabaseReference): Promise<void> {
401
+ return (ref as DatabaseReferenceWithMethodsInternal).remove.call(ref, MODULAR_DEPRECATION_ARG);
402
+ }
403
+
404
+ export function update(ref: DatabaseReference, values: object): Promise<void> {
405
+ return (ref as DatabaseReferenceWithMethodsInternal).update.call(
406
+ ref,
407
+ values,
408
+ MODULAR_DEPRECATION_ARG,
409
+ );
410
+ }
@@ -0,0 +1,34 @@
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 { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/dist/module/common';
19
+ import type { DatabaseReference, TransactionOptions, TransactionResult } from '../types/database';
20
+ import type { DatabaseReferenceWithTransactionInternal } from '../types/internal';
21
+
22
+ export function runTransaction(
23
+ ref: DatabaseReference,
24
+ transactionUpdate: (currentData: any) => unknown,
25
+ options?: TransactionOptions,
26
+ ): Promise<TransactionResult> {
27
+ return (ref as DatabaseReferenceWithTransactionInternal).transaction.call(
28
+ ref,
29
+ transactionUpdate,
30
+ undefined,
31
+ options?.applyLocally,
32
+ MODULAR_DEPRECATION_ARG,
33
+ );
34
+ }
package/lib/modular.ts ADDED
@@ -0,0 +1,134 @@
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 { getApp } from '@react-native-firebase/app';
19
+ import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/dist/module/common';
20
+ import type { ReactNativeFirebase } from '@react-native-firebase/app';
21
+ import DatabaseStatics from './DatabaseStatics';
22
+ import type { Database, DatabaseReference, EmulatorMockTokenOptions } from './types/database';
23
+ import type {
24
+ AppWithDatabaseInternal,
25
+ DatabaseWithMethodsInternal,
26
+ ServerValueStaticInternal,
27
+ } from './types/internal';
28
+
29
+ const { ServerValue } = DatabaseStatics;
30
+
31
+ type FirebaseApp = ReactNativeFirebase.FirebaseApp;
32
+
33
+ export function getDatabase(app?: FirebaseApp, url?: string): Database {
34
+ if (app) {
35
+ return (getApp(app.name) as unknown as AppWithDatabaseInternal).database(
36
+ url,
37
+ ) as unknown as Database;
38
+ }
39
+
40
+ return (getApp() as unknown as AppWithDatabaseInternal).database(url) as unknown as Database;
41
+ }
42
+
43
+ export function connectDatabaseEmulator(
44
+ db: Database,
45
+ host: string,
46
+ port: number,
47
+ options?: {
48
+ mockUserToken?: EmulatorMockTokenOptions | string;
49
+ },
50
+ ): void {
51
+ (db as DatabaseWithMethodsInternal).useEmulator.call(
52
+ db,
53
+ host,
54
+ port,
55
+ options,
56
+ MODULAR_DEPRECATION_ARG,
57
+ );
58
+ }
59
+
60
+ export function goOffline(db: Database): void {
61
+ (db as DatabaseWithMethodsInternal).goOffline.call(db, MODULAR_DEPRECATION_ARG);
62
+ }
63
+
64
+ export function goOnline(db: Database): void {
65
+ (db as DatabaseWithMethodsInternal).goOnline.call(db, MODULAR_DEPRECATION_ARG);
66
+ }
67
+
68
+ export function ref(db: Database, path?: string): DatabaseReference {
69
+ return (db as DatabaseWithMethodsInternal).ref.call(db, path, MODULAR_DEPRECATION_ARG);
70
+ }
71
+
72
+ export function refFromURL(db: Database, url: string): DatabaseReference {
73
+ return (db as DatabaseWithMethodsInternal).refFromURL.call(db, url, MODULAR_DEPRECATION_ARG);
74
+ }
75
+
76
+ export function setPersistenceEnabled(db: Database, enabled: boolean): Promise<void> {
77
+ return (db as DatabaseWithMethodsInternal).setPersistenceEnabled.call(
78
+ db,
79
+ enabled,
80
+ MODULAR_DEPRECATION_ARG,
81
+ ) as Promise<void>;
82
+ }
83
+
84
+ export function setLoggingEnabled(db: Database, enabled: boolean): Promise<void> {
85
+ return (db as DatabaseWithMethodsInternal).setLoggingEnabled.call(
86
+ db,
87
+ enabled,
88
+ MODULAR_DEPRECATION_ARG,
89
+ ) as Promise<void>;
90
+ }
91
+
92
+ export function setPersistenceCacheSizeBytes(db: Database, bytes: number): Promise<void> {
93
+ return (db as DatabaseWithMethodsInternal).setPersistenceCacheSizeBytes.call(
94
+ db,
95
+ bytes,
96
+ MODULAR_DEPRECATION_ARG,
97
+ ) as Promise<void>;
98
+ }
99
+
100
+ export function forceLongPolling(): void {
101
+ throw new Error('forceLongPolling() is not implemented');
102
+ }
103
+
104
+ export function forceWebSockets(): void {
105
+ throw new Error('forceWebSockets() is not implemented');
106
+ }
107
+
108
+ export function serverTimestamp(): object {
109
+ return ServerValue.TIMESTAMP;
110
+ }
111
+
112
+ export function getServerTime(db: Database): Date {
113
+ return (db as DatabaseWithMethodsInternal).getServerTime.call(db, MODULAR_DEPRECATION_ARG);
114
+ }
115
+
116
+ export function increment(delta: number): object {
117
+ return (ServerValue as ServerValueStaticInternal).increment.call(
118
+ ServerValue,
119
+ delta,
120
+ MODULAR_DEPRECATION_ARG,
121
+ );
122
+ }
123
+
124
+ export function enableLogging(enabled: boolean, persistent?: boolean): any;
125
+ export function enableLogging(logger: (message: string) => unknown): any;
126
+ export function enableLogging(
127
+ _enabledOrLogger: boolean | ((message: string) => unknown),
128
+ _persistent?: boolean,
129
+ ): any {
130
+ throw new Error('enableLogging() is not implemented');
131
+ }
132
+
133
+ export * from './modular/query';
134
+ export * from './modular/transaction';