@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.
- package/CHANGELOG.md +36 -0
- package/dist/module/DatabaseDataSnapshot.js +144 -0
- package/dist/module/DatabaseDataSnapshot.js.map +1 -0
- package/dist/module/DatabaseOnDisconnect.js +84 -0
- package/dist/module/DatabaseOnDisconnect.js.map +1 -0
- package/dist/module/DatabaseQuery.js +298 -0
- package/dist/module/DatabaseQuery.js.map +1 -0
- package/{lib → dist/module}/DatabaseQueryModifiers.js +49 -98
- package/dist/module/DatabaseQueryModifiers.js.map +1 -0
- package/dist/module/DatabaseReference.js +169 -0
- package/dist/module/DatabaseReference.js.map +1 -0
- package/dist/module/DatabaseStatics.js +35 -0
- package/dist/module/DatabaseStatics.js.map +1 -0
- package/{lib → dist/module}/DatabaseSyncTree.js +74 -156
- package/dist/module/DatabaseSyncTree.js.map +1 -0
- package/{lib → dist/module}/DatabaseThenableReference.js +12 -12
- package/dist/module/DatabaseThenableReference.js.map +1 -0
- package/{lib → dist/module}/DatabaseTransaction.js +26 -89
- package/dist/module/DatabaseTransaction.js.map +1 -0
- package/dist/module/index.js +27 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/modular/query.js +138 -0
- package/dist/module/modular/query.js.map +1 -0
- package/dist/module/modular/transaction.js +24 -0
- package/dist/module/modular/transaction.js.map +1 -0
- package/dist/module/modular.js +76 -0
- package/dist/module/modular.js.map +1 -0
- package/dist/module/namespaced.js +147 -0
- package/dist/module/namespaced.js.map +1 -0
- package/dist/module/package.json +1 -0
- package/dist/module/types/database.js +21 -0
- package/dist/module/types/database.js.map +1 -0
- package/dist/module/types/internal.js +4 -0
- package/dist/module/types/internal.js.map +1 -0
- package/dist/module/types/namespaced.js +67 -0
- package/dist/module/types/namespaced.js.map +1 -0
- package/dist/module/version.js +5 -0
- package/dist/module/version.js.map +1 -0
- package/dist/module/web/RNFBDatabaseModule.android.js +6 -0
- package/dist/module/web/RNFBDatabaseModule.android.js.map +1 -0
- package/dist/module/web/RNFBDatabaseModule.ios.js +6 -0
- package/dist/module/web/RNFBDatabaseModule.ios.js.map +1 -0
- package/dist/module/web/RNFBDatabaseModule.js +375 -0
- package/dist/module/web/RNFBDatabaseModule.js.map +1 -0
- package/{lib → dist/module}/web/query.js +19 -24
- package/dist/module/web/query.js.map +1 -0
- package/dist/typescript/lib/DatabaseDataSnapshot.d.ts +20 -0
- package/dist/typescript/lib/DatabaseDataSnapshot.d.ts.map +1 -0
- package/dist/typescript/lib/DatabaseOnDisconnect.d.ts +19 -0
- package/dist/typescript/lib/DatabaseOnDisconnect.d.ts.map +1 -0
- package/dist/typescript/lib/DatabaseQuery.d.ts +32 -0
- package/dist/typescript/lib/DatabaseQuery.d.ts.map +1 -0
- package/dist/typescript/lib/DatabaseQueryModifiers.d.ts +55 -0
- package/dist/typescript/lib/DatabaseQueryModifiers.d.ts.map +1 -0
- package/dist/typescript/lib/DatabaseReference.d.ts +21 -0
- package/dist/typescript/lib/DatabaseReference.d.ts.map +1 -0
- package/dist/typescript/lib/DatabaseStatics.d.ts +10 -0
- package/dist/typescript/lib/DatabaseStatics.d.ts.map +1 -0
- package/dist/typescript/lib/DatabaseSyncTree.d.ts +72 -0
- package/dist/typescript/lib/DatabaseSyncTree.d.ts.map +1 -0
- package/dist/typescript/lib/DatabaseThenableReference.d.ts +13 -0
- package/dist/typescript/lib/DatabaseThenableReference.d.ts.map +1 -0
- package/dist/typescript/lib/DatabaseTransaction.d.ts +15 -0
- package/dist/typescript/lib/DatabaseTransaction.d.ts.map +1 -0
- package/dist/typescript/lib/index.d.ts +6 -0
- package/dist/typescript/lib/index.d.ts.map +1 -0
- package/dist/typescript/lib/modular/query.d.ts +41 -0
- package/dist/typescript/lib/modular/query.d.ts.map +1 -0
- package/dist/typescript/lib/modular/transaction.d.ts +3 -0
- package/dist/typescript/lib/modular/transaction.d.ts.map +1 -0
- package/dist/typescript/lib/modular.d.ts +24 -0
- package/dist/typescript/lib/modular.d.ts.map +1 -0
- package/dist/typescript/lib/namespaced.d.ts +13 -0
- package/dist/typescript/lib/namespaced.d.ts.map +1 -0
- package/dist/typescript/lib/types/database.d.ts +93 -0
- package/dist/typescript/lib/types/database.d.ts.map +1 -0
- package/dist/typescript/lib/types/internal.d.ts +189 -0
- package/dist/typescript/lib/types/internal.d.ts.map +1 -0
- package/dist/typescript/lib/types/namespaced.d.ts +1230 -0
- package/dist/typescript/lib/types/namespaced.d.ts.map +1 -0
- package/dist/typescript/lib/version.d.ts +2 -0
- package/dist/typescript/lib/version.d.ts.map +1 -0
- package/dist/typescript/lib/web/RNFBDatabaseModule.android.d.ts +3 -0
- package/dist/typescript/lib/web/RNFBDatabaseModule.android.d.ts.map +1 -0
- package/dist/typescript/lib/web/RNFBDatabaseModule.d.ts +3 -0
- package/dist/typescript/lib/web/RNFBDatabaseModule.d.ts.map +1 -0
- package/dist/typescript/lib/web/RNFBDatabaseModule.ios.d.ts +3 -0
- package/dist/typescript/lib/web/RNFBDatabaseModule.ios.d.ts.map +1 -0
- package/dist/typescript/lib/web/query.d.ts +13 -0
- package/dist/typescript/lib/web/query.d.ts.map +1 -0
- package/dist/typescript/package.json +1 -0
- package/lib/{DatabaseDataSnapshot.js → DatabaseDataSnapshot.ts} +62 -88
- package/lib/{DatabaseOnDisconnect.js → DatabaseOnDisconnect.ts} +25 -23
- package/lib/{DatabaseQuery.js → DatabaseQuery.ts} +130 -144
- package/lib/DatabaseQueryModifiers.ts +283 -0
- package/lib/{DatabaseReference.js → DatabaseReference.ts} +103 -85
- package/lib/{DatabaseStatics.js → DatabaseStatics.ts} +4 -2
- package/lib/DatabaseSyncTree.ts +390 -0
- package/lib/DatabaseThenableReference.ts +73 -0
- package/lib/DatabaseTransaction.ts +172 -0
- package/lib/index.ts +25 -0
- package/lib/modular/query.ts +410 -0
- package/lib/modular/transaction.ts +34 -0
- package/lib/modular.ts +134 -0
- package/lib/{index.js → namespaced.ts} +91 -90
- package/lib/types/database.ts +144 -0
- package/lib/types/internal.ts +317 -0
- package/lib/{index.d.ts → types/namespaced.ts} +48 -9
- package/lib/version.ts +2 -0
- package/lib/web/RNFBDatabaseModule.android.ts +4 -0
- package/lib/web/RNFBDatabaseModule.ios.ts +4 -0
- package/lib/web/RNFBDatabaseModule.ts +534 -0
- package/lib/web/query.ts +97 -0
- package/package.json +42 -7
- package/tsconfig.json +21 -0
- package/typedoc.json +3 -3
- package/lib/modular/index.d.ts +0 -246
- package/lib/modular/index.js +0 -134
- package/lib/modular/query.d.ts +0 -972
- package/lib/modular/query.js +0 -305
- package/lib/modular/transaction.d.ts +0 -54
- package/lib/modular/transaction.js +0 -24
- package/lib/version.js +0 -2
- package/lib/web/RNFBDatabaseModule.android.js +0 -2
- package/lib/web/RNFBDatabaseModule.ios.js +0 -2
- package/lib/web/RNFBDatabaseModule.js +0 -558
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
|
+
createDeprecationProxy,
|
|
19
20
|
isBoolean,
|
|
20
21
|
isFunction,
|
|
21
22
|
isNull,
|
|
@@ -23,47 +24,87 @@ import {
|
|
|
23
24
|
isObject,
|
|
24
25
|
isString,
|
|
25
26
|
isUndefined,
|
|
27
|
+
MODULAR_DEPRECATION_ARG,
|
|
26
28
|
pathIsEmpty,
|
|
27
29
|
pathToUrlEncodedString,
|
|
28
30
|
ReferenceBase,
|
|
29
|
-
createDeprecationProxy,
|
|
30
|
-
MODULAR_DEPRECATION_ARG,
|
|
31
31
|
} from '@react-native-firebase/app/dist/module/common';
|
|
32
32
|
import DatabaseDataSnapshot from './DatabaseDataSnapshot';
|
|
33
33
|
import DatabaseSyncTree from './DatabaseSyncTree';
|
|
34
|
+
import type DatabaseQueryModifiers from './DatabaseQueryModifiers';
|
|
35
|
+
import type {
|
|
36
|
+
DatabaseChildSnapshotResultInternal,
|
|
37
|
+
DatabaseInternal,
|
|
38
|
+
DatabaseListenPropsInternal,
|
|
39
|
+
} from './types/internal';
|
|
40
|
+
import type { FirebaseDatabaseTypes } from './types/namespaced';
|
|
41
|
+
|
|
42
|
+
const eventTypes = [
|
|
43
|
+
'value',
|
|
44
|
+
'child_added',
|
|
45
|
+
'child_changed',
|
|
46
|
+
'child_moved',
|
|
47
|
+
'child_removed',
|
|
48
|
+
] as const;
|
|
49
|
+
|
|
50
|
+
type DatabaseReferenceConstructor = new (
|
|
51
|
+
database: DatabaseInternal,
|
|
52
|
+
path: string,
|
|
53
|
+
) => FirebaseDatabaseTypes.Reference;
|
|
54
|
+
|
|
55
|
+
type QueryWithDeprecationArgInternal = FirebaseDatabaseTypes.Query & {
|
|
56
|
+
startAt(
|
|
57
|
+
value: number | string | boolean | null,
|
|
58
|
+
key?: string,
|
|
59
|
+
deprecationArg?: string,
|
|
60
|
+
): FirebaseDatabaseTypes.Query;
|
|
61
|
+
endAt(
|
|
62
|
+
value: number | string | boolean | null,
|
|
63
|
+
key?: string,
|
|
64
|
+
deprecationArg?: string,
|
|
65
|
+
): FirebaseDatabaseTypes.Query;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
let DatabaseReferenceClass: DatabaseReferenceConstructor | null = null;
|
|
69
|
+
|
|
70
|
+
export function provideReferenceClass(databaseReference: DatabaseReferenceConstructor): void {
|
|
71
|
+
DatabaseReferenceClass = databaseReference;
|
|
72
|
+
}
|
|
34
73
|
|
|
35
|
-
|
|
74
|
+
function ap(query: FirebaseDatabaseTypes.Query): QueryWithDeprecationArgInternal {
|
|
75
|
+
return query as QueryWithDeprecationArgInternal;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function createReference(
|
|
79
|
+
database: DatabaseInternal,
|
|
80
|
+
path: string,
|
|
81
|
+
): FirebaseDatabaseTypes.Reference {
|
|
82
|
+
if (!DatabaseReferenceClass) {
|
|
83
|
+
throw new Error('DatabaseReference class has not been provided.');
|
|
84
|
+
}
|
|
36
85
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
DatabaseReference = databaseReference;
|
|
86
|
+
return createDeprecationProxy(
|
|
87
|
+
new DatabaseReferenceClass(database, path),
|
|
88
|
+
) as FirebaseDatabaseTypes.Reference;
|
|
41
89
|
}
|
|
42
90
|
|
|
43
|
-
// Internal listener count
|
|
44
91
|
let listeners = 0;
|
|
45
92
|
|
|
46
|
-
export default class DatabaseQuery extends ReferenceBase {
|
|
47
|
-
|
|
93
|
+
export default class DatabaseQuery extends ReferenceBase implements FirebaseDatabaseTypes.Query {
|
|
94
|
+
_database: DatabaseInternal;
|
|
95
|
+
_modifiers: DatabaseQueryModifiers;
|
|
96
|
+
|
|
97
|
+
constructor(database: DatabaseInternal, path: string, modifiers: DatabaseQueryModifiers) {
|
|
48
98
|
super(path);
|
|
49
99
|
this._database = database;
|
|
50
100
|
this._modifiers = modifiers;
|
|
51
101
|
}
|
|
52
102
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*/
|
|
56
|
-
get ref() {
|
|
57
|
-
return createDeprecationProxy(new DatabaseReference(this._database, this.path));
|
|
103
|
+
get ref(): FirebaseDatabaseTypes.Reference {
|
|
104
|
+
return createReference(this._database, this.path);
|
|
58
105
|
}
|
|
59
106
|
|
|
60
|
-
|
|
61
|
-
*
|
|
62
|
-
* @param value
|
|
63
|
-
* @param key
|
|
64
|
-
* @return {DatabaseQuery}
|
|
65
|
-
*/
|
|
66
|
-
endAt(value, key) {
|
|
107
|
+
endAt(value: number | string | boolean | null, key?: string): FirebaseDatabaseTypes.Query {
|
|
67
108
|
if (!isNumber(value) && !isString(value) && !isBoolean(value) && !isNull(value)) {
|
|
68
109
|
throw new Error(
|
|
69
110
|
"firebase.database().ref().endAt(*) 'value' must be a number, string, boolean or null value.",
|
|
@@ -88,13 +129,7 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
88
129
|
return createDeprecationProxy(new DatabaseQuery(this._database, this.path, modifiers));
|
|
89
130
|
}
|
|
90
131
|
|
|
91
|
-
|
|
92
|
-
*
|
|
93
|
-
* @param value
|
|
94
|
-
* @param key
|
|
95
|
-
* @return {DatabaseQuery}
|
|
96
|
-
*/
|
|
97
|
-
equalTo(value, key) {
|
|
132
|
+
equalTo(value: number | string | boolean | null, key?: string): FirebaseDatabaseTypes.Query {
|
|
98
133
|
if (!isNumber(value) && !isString(value) && !isBoolean(value) && !isNull(value)) {
|
|
99
134
|
throw new Error(
|
|
100
135
|
"firebase.database().ref().equalTo(*) 'value' must be a number, string, boolean or null value.",
|
|
@@ -119,18 +154,14 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
119
154
|
);
|
|
120
155
|
}
|
|
121
156
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
157
|
+
return ap(ap(this).startAt.call(this, value, key, MODULAR_DEPRECATION_ARG)).endAt.call(
|
|
158
|
+
this,
|
|
159
|
+
value,
|
|
160
|
+
MODULAR_DEPRECATION_ARG,
|
|
161
|
+
);
|
|
126
162
|
}
|
|
127
163
|
|
|
128
|
-
|
|
129
|
-
*
|
|
130
|
-
* @param other
|
|
131
|
-
* @return {boolean}
|
|
132
|
-
*/
|
|
133
|
-
isEqual(other) {
|
|
164
|
+
isEqual(other: FirebaseDatabaseTypes.Query): boolean {
|
|
134
165
|
if (!(other instanceof DatabaseQuery)) {
|
|
135
166
|
throw new Error("firebase.database().ref().isEqual(*) 'other' must be an instance of Query.");
|
|
136
167
|
}
|
|
@@ -142,12 +173,7 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
142
173
|
return sameApp && sameDatabasePath && sameModifiers;
|
|
143
174
|
}
|
|
144
175
|
|
|
145
|
-
|
|
146
|
-
*
|
|
147
|
-
* @param limit
|
|
148
|
-
* @return {DatabaseQuery}
|
|
149
|
-
*/
|
|
150
|
-
limitToFirst(limit) {
|
|
176
|
+
limitToFirst(limit: number): FirebaseDatabaseTypes.Query {
|
|
151
177
|
if (this._modifiers.isValidLimit(limit)) {
|
|
152
178
|
throw new Error(
|
|
153
179
|
"firebase.database().ref().limitToFirst(*) 'limit' must be a positive integer value.",
|
|
@@ -162,15 +188,10 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
162
188
|
|
|
163
189
|
return createDeprecationProxy(
|
|
164
190
|
new DatabaseQuery(this._database, this.path, this._modifiers._copy().limitToFirst(limit)),
|
|
165
|
-
);
|
|
191
|
+
) as FirebaseDatabaseTypes.Query;
|
|
166
192
|
}
|
|
167
193
|
|
|
168
|
-
|
|
169
|
-
*
|
|
170
|
-
* @param limit
|
|
171
|
-
* @return {DatabaseQuery}
|
|
172
|
-
*/
|
|
173
|
-
limitToLast(limit) {
|
|
194
|
+
limitToLast(limit: number): FirebaseDatabaseTypes.Query {
|
|
174
195
|
if (this._modifiers.isValidLimit(limit)) {
|
|
175
196
|
throw new Error(
|
|
176
197
|
"firebase.database().ref().limitToLast(*) 'limit' must be a positive integer value.",
|
|
@@ -185,24 +206,19 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
185
206
|
|
|
186
207
|
return createDeprecationProxy(
|
|
187
208
|
new DatabaseQuery(this._database, this.path, this._modifiers._copy().limitToLast(limit)),
|
|
188
|
-
);
|
|
209
|
+
) as FirebaseDatabaseTypes.Query;
|
|
189
210
|
}
|
|
190
211
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
* @return {DatabaseQuery}
|
|
197
|
-
*/
|
|
198
|
-
off(eventType, callback, context) {
|
|
199
|
-
//
|
|
212
|
+
off(
|
|
213
|
+
eventType?: FirebaseDatabaseTypes.EventType,
|
|
214
|
+
callback?: (a: FirebaseDatabaseTypes.DataSnapshot, b?: string | null) => void,
|
|
215
|
+
context?: Record<string, any>,
|
|
216
|
+
): void {
|
|
200
217
|
if (arguments.length === 0) {
|
|
201
|
-
|
|
202
|
-
// if no eventType or callback is specified, all callbacks for the Reference will be removed
|
|
203
|
-
return DatabaseSyncTree.removeListenersForRegistrations(
|
|
218
|
+
DatabaseSyncTree.removeListenersForRegistrations(
|
|
204
219
|
DatabaseSyncTree.getRegistrationsByPath(this.path),
|
|
205
220
|
);
|
|
221
|
+
return;
|
|
206
222
|
}
|
|
207
223
|
|
|
208
224
|
if (!isUndefined(eventType) && !eventTypes.includes(eventType)) {
|
|
@@ -219,13 +235,6 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
219
235
|
throw new Error("firebase.database().ref().off(_, _, *) 'context' must be an object.");
|
|
220
236
|
}
|
|
221
237
|
|
|
222
|
-
// Firebase Docs:
|
|
223
|
-
// Note that if on() was called
|
|
224
|
-
// multiple times with the same eventType and callback, the callback will be called
|
|
225
|
-
// multiple times for each event, and off() must be called multiple times to
|
|
226
|
-
// remove the callback.
|
|
227
|
-
|
|
228
|
-
// Remove only a single registration
|
|
229
238
|
if (eventType && callback) {
|
|
230
239
|
const registration = DatabaseSyncTree.getOneByPathEventListener(
|
|
231
240
|
this.path,
|
|
@@ -233,37 +242,30 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
233
242
|
callback,
|
|
234
243
|
);
|
|
235
244
|
if (!registration) {
|
|
236
|
-
return
|
|
245
|
+
return;
|
|
237
246
|
}
|
|
238
247
|
|
|
239
|
-
// remove the paired cancellation registration if any exist
|
|
240
248
|
DatabaseSyncTree.removeListenersForRegistrations([`${registration}$cancelled`]);
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
// call multiple times to remove multiple registrations
|
|
244
|
-
return DatabaseSyncTree.removeListenerRegistrations(callback, [registration]);
|
|
249
|
+
DatabaseSyncTree.removeListenerRegistrations(callback, [registration]);
|
|
250
|
+
return;
|
|
245
251
|
}
|
|
246
252
|
|
|
247
|
-
// Firebase Docs:
|
|
248
|
-
// If a callback is not specified, all callbacks for the specified eventType will be removed.
|
|
249
253
|
const registrations = DatabaseSyncTree.getRegistrationsByPathEvent(this.path, eventType);
|
|
250
254
|
|
|
251
255
|
DatabaseSyncTree.removeListenersForRegistrations(
|
|
252
256
|
DatabaseSyncTree.getRegistrationsByPathEvent(this.path, `${eventType}$cancelled`),
|
|
253
257
|
);
|
|
254
258
|
|
|
255
|
-
|
|
259
|
+
DatabaseSyncTree.removeListenersForRegistrations(registrations);
|
|
260
|
+
return;
|
|
256
261
|
}
|
|
257
262
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
* @return {DatabaseQuery}
|
|
265
|
-
*/
|
|
266
|
-
on(eventType, callback, cancelCallbackOrContext, context) {
|
|
263
|
+
on(
|
|
264
|
+
eventType: FirebaseDatabaseTypes.EventType,
|
|
265
|
+
callback: (data: FirebaseDatabaseTypes.DataSnapshot, previousChildKey?: string | null) => void,
|
|
266
|
+
cancelCallbackOrContext?: ((a: Error) => void) | Record<string, any> | null,
|
|
267
|
+
context?: Record<string, any> | null,
|
|
268
|
+
): (a: FirebaseDatabaseTypes.DataSnapshot | null, b?: string | null) => void {
|
|
267
269
|
if (!eventTypes.includes(eventType)) {
|
|
268
270
|
throw new Error(
|
|
269
271
|
`firebase.database().ref().on(*) 'eventType' must be one of ${eventTypes.join(', ')}.`,
|
|
@@ -291,12 +293,11 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
291
293
|
const queryKey = this._generateQueryKey();
|
|
292
294
|
const eventRegistrationKey = this._generateQueryEventKey(eventType);
|
|
293
295
|
const registrationCancellationKey = `${eventRegistrationKey}$cancelled`;
|
|
294
|
-
const
|
|
296
|
+
const scopedContext =
|
|
295
297
|
cancelCallbackOrContext && !isFunction(cancelCallbackOrContext)
|
|
296
298
|
? cancelCallbackOrContext
|
|
297
299
|
: context;
|
|
298
300
|
|
|
299
|
-
// Add a new SyncTree registration
|
|
300
301
|
DatabaseSyncTree.addRegistration({
|
|
301
302
|
eventType,
|
|
302
303
|
ref: this.ref,
|
|
@@ -305,14 +306,10 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
305
306
|
appName: this._database.app.name,
|
|
306
307
|
dbURL: this._database._customUrlOrRegion,
|
|
307
308
|
eventRegistrationKey,
|
|
308
|
-
listener:
|
|
309
|
+
listener: scopedContext ? callback.bind(scopedContext) : callback,
|
|
309
310
|
});
|
|
310
311
|
|
|
311
312
|
if (cancelCallbackOrContext && isFunction(cancelCallbackOrContext)) {
|
|
312
|
-
// cancellations have their own separate registration
|
|
313
|
-
// as these are one off events, and they're not guaranteed
|
|
314
|
-
// to occur either, only happens on failure to register on native
|
|
315
|
-
|
|
316
313
|
DatabaseSyncTree.addRegistration({
|
|
317
314
|
ref: this.ref,
|
|
318
315
|
once: true,
|
|
@@ -322,38 +319,37 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
322
319
|
dbURL: this._database._customUrlOrRegion,
|
|
323
320
|
eventType: `${eventType}$cancelled`,
|
|
324
321
|
eventRegistrationKey: registrationCancellationKey,
|
|
325
|
-
listener:
|
|
322
|
+
listener: scopedContext
|
|
323
|
+
? cancelCallbackOrContext.bind(scopedContext)
|
|
324
|
+
: cancelCallbackOrContext,
|
|
326
325
|
});
|
|
327
326
|
}
|
|
328
327
|
|
|
329
|
-
|
|
328
|
+
const listenProps: DatabaseListenPropsInternal = {
|
|
330
329
|
eventType,
|
|
331
330
|
path: this.path,
|
|
332
331
|
key: queryKey,
|
|
333
|
-
appName: this._database.app.name,
|
|
334
332
|
modifiers: this._modifiers.toArray(),
|
|
335
|
-
hasCancellationCallback: isFunction(cancelCallbackOrContext),
|
|
336
333
|
registration: {
|
|
337
334
|
eventRegistrationKey,
|
|
338
335
|
key: queryKey,
|
|
339
336
|
registrationCancellationKey,
|
|
340
337
|
},
|
|
341
|
-
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
this._database.native.on(listenProps);
|
|
342
341
|
|
|
343
|
-
// increment number of listeners - just a short way of making
|
|
344
|
-
// every registration unique per .on() call
|
|
345
342
|
listeners += 1;
|
|
346
343
|
|
|
347
|
-
return callback;
|
|
344
|
+
return callback as (a: FirebaseDatabaseTypes.DataSnapshot | null, b?: string | null) => void;
|
|
348
345
|
}
|
|
349
346
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
once(eventType, successCallBack, failureCallbackOrContext, context) {
|
|
347
|
+
once(
|
|
348
|
+
eventType: FirebaseDatabaseTypes.EventType,
|
|
349
|
+
successCallBack?: (a: FirebaseDatabaseTypes.DataSnapshot, b?: string | null) => any,
|
|
350
|
+
failureCallbackOrContext?: ((a: Error) => void) | Record<string, any> | null,
|
|
351
|
+
context?: Record<string, any>,
|
|
352
|
+
): Promise<FirebaseDatabaseTypes.DataSnapshot> {
|
|
357
353
|
if (!eventTypes.includes(eventType)) {
|
|
358
354
|
throw new Error(
|
|
359
355
|
`firebase.database().ref().once(*) 'eventType' must be one of ${eventTypes.join(', ')}.`,
|
|
@@ -385,17 +381,22 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
385
381
|
return this._database.native
|
|
386
382
|
.once(this.path, modifiers, eventType)
|
|
387
383
|
.then(result => {
|
|
388
|
-
let dataSnapshot;
|
|
389
|
-
let previousChildName;
|
|
384
|
+
let dataSnapshot: FirebaseDatabaseTypes.DataSnapshot;
|
|
385
|
+
let previousChildName: string | null | undefined;
|
|
390
386
|
|
|
391
|
-
// Child based events return a previousChildName
|
|
392
387
|
if (eventType === 'value') {
|
|
393
|
-
dataSnapshot = createDeprecationProxy(
|
|
388
|
+
dataSnapshot = createDeprecationProxy(
|
|
389
|
+
new DatabaseDataSnapshot(
|
|
390
|
+
this.ref,
|
|
391
|
+
result as ConstructorParameters<typeof DatabaseDataSnapshot>[1],
|
|
392
|
+
),
|
|
393
|
+
) as FirebaseDatabaseTypes.DataSnapshot;
|
|
394
394
|
} else {
|
|
395
|
+
const childResult = result as DatabaseChildSnapshotResultInternal;
|
|
395
396
|
dataSnapshot = createDeprecationProxy(
|
|
396
|
-
new DatabaseDataSnapshot(this.ref,
|
|
397
|
-
);
|
|
398
|
-
previousChildName =
|
|
397
|
+
new DatabaseDataSnapshot(this.ref, childResult.snapshot),
|
|
398
|
+
) as FirebaseDatabaseTypes.DataSnapshot;
|
|
399
|
+
previousChildName = childResult.previousChildName;
|
|
399
400
|
}
|
|
400
401
|
|
|
401
402
|
if (isFunction(successCallBack)) {
|
|
@@ -418,10 +419,7 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
418
419
|
});
|
|
419
420
|
}
|
|
420
421
|
|
|
421
|
-
|
|
422
|
-
* @url https://firebase.google.com/docs/reference/js/firebase.database.Query.html#orderbychild
|
|
423
|
-
*/
|
|
424
|
-
orderByChild(path) {
|
|
422
|
+
orderByChild(path: string): FirebaseDatabaseTypes.Query {
|
|
425
423
|
if (!isString(path)) {
|
|
426
424
|
throw new Error("firebase.database().ref().orderByChild(*) 'path' must be a string value.");
|
|
427
425
|
}
|
|
@@ -444,10 +442,7 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
444
442
|
return createDeprecationProxy(new DatabaseQuery(this._database, this.path, modifiers));
|
|
445
443
|
}
|
|
446
444
|
|
|
447
|
-
|
|
448
|
-
* @url https://firebase.google.com/docs/reference/js/firebase.database.Query.html#orderbykey
|
|
449
|
-
*/
|
|
450
|
-
orderByKey() {
|
|
445
|
+
orderByKey(): FirebaseDatabaseTypes.Query {
|
|
451
446
|
if (this._modifiers.hasOrderBy()) {
|
|
452
447
|
throw new Error(
|
|
453
448
|
"firebase.database().ref().orderByKey() You can't combine multiple orderBy calls.",
|
|
@@ -460,10 +455,7 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
460
455
|
return createDeprecationProxy(new DatabaseQuery(this._database, this.path, modifiers));
|
|
461
456
|
}
|
|
462
457
|
|
|
463
|
-
|
|
464
|
-
* @url https://firebase.google.com/docs/reference/js/firebase.database.Query.html#orderbypriority
|
|
465
|
-
*/
|
|
466
|
-
orderByPriority() {
|
|
458
|
+
orderByPriority(): FirebaseDatabaseTypes.Query {
|
|
467
459
|
if (this._modifiers.hasOrderBy()) {
|
|
468
460
|
throw new Error(
|
|
469
461
|
"firebase.database().ref().orderByPriority() You can't combine multiple orderBy calls.",
|
|
@@ -476,10 +468,7 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
476
468
|
return createDeprecationProxy(new DatabaseQuery(this._database, this.path, modifiers));
|
|
477
469
|
}
|
|
478
470
|
|
|
479
|
-
|
|
480
|
-
* @url https://firebase.google.com/docs/reference/js/firebase.database.Query.html#orderbyvalue
|
|
481
|
-
*/
|
|
482
|
-
orderByValue() {
|
|
471
|
+
orderByValue(): FirebaseDatabaseTypes.Query {
|
|
483
472
|
if (this._modifiers.hasOrderBy()) {
|
|
484
473
|
throw new Error(
|
|
485
474
|
"firebase.database().ref().orderByValue() You can't combine multiple orderBy calls.",
|
|
@@ -492,7 +481,7 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
492
481
|
return createDeprecationProxy(new DatabaseQuery(this._database, this.path, modifiers));
|
|
493
482
|
}
|
|
494
483
|
|
|
495
|
-
startAt(value, key) {
|
|
484
|
+
startAt(value: number | string | boolean | null, key?: string): FirebaseDatabaseTypes.Query {
|
|
496
485
|
if (!isNumber(value) && !isString(value) && !isBoolean(value) && !isNull(value)) {
|
|
497
486
|
throw new Error(
|
|
498
487
|
"firebase.database().ref().startAt(*) 'value' must be a number, string, boolean or null value.",
|
|
@@ -517,15 +506,15 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
517
506
|
return createDeprecationProxy(new DatabaseQuery(this._database, this.path, modifiers));
|
|
518
507
|
}
|
|
519
508
|
|
|
520
|
-
toJSON() {
|
|
509
|
+
toJSON(): string {
|
|
521
510
|
return this.toString();
|
|
522
511
|
}
|
|
523
512
|
|
|
524
|
-
toString() {
|
|
513
|
+
toString(): string {
|
|
525
514
|
return `${this._database._customUrlOrRegion}${pathToUrlEncodedString(this.path)}`;
|
|
526
515
|
}
|
|
527
516
|
|
|
528
|
-
keepSynced(bool) {
|
|
517
|
+
keepSynced(bool: boolean): Promise<void> {
|
|
529
518
|
if (!isBoolean(bool)) {
|
|
530
519
|
throw new Error(
|
|
531
520
|
"firebase.database().ref().keepSynced(*) 'bool' value must be a boolean value.",
|
|
@@ -540,16 +529,13 @@ export default class DatabaseQuery extends ReferenceBase {
|
|
|
540
529
|
);
|
|
541
530
|
}
|
|
542
531
|
|
|
543
|
-
|
|
544
|
-
// Ensures any queries called in various orders keep the same key
|
|
545
|
-
_generateQueryKey() {
|
|
532
|
+
_generateQueryKey(): string {
|
|
546
533
|
return `$${this._database._customUrlOrRegion}$/${this.path}$${
|
|
547
534
|
this._database.app.name
|
|
548
535
|
}$${this._modifiers.toString()}`;
|
|
549
536
|
}
|
|
550
537
|
|
|
551
|
-
|
|
552
|
-
_generateQueryEventKey(eventType) {
|
|
538
|
+
_generateQueryEventKey(eventType: FirebaseDatabaseTypes.EventType): string {
|
|
553
539
|
return `${this._generateQueryKey()}$${listeners}$${eventType}`;
|
|
554
540
|
}
|
|
555
541
|
}
|