@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
|
@@ -0,0 +1,283 @@
|
|
|
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 { isNull, isNumber, isString } from '@react-native-firebase/app/dist/module/common';
|
|
19
|
+
|
|
20
|
+
const CONSTANTS = {
|
|
21
|
+
VIEW_FROM_LEFT: 'left',
|
|
22
|
+
VIEW_FROM_RIGHT: 'right',
|
|
23
|
+
} as const;
|
|
24
|
+
|
|
25
|
+
type QueryModifierValue = number | string | boolean | null;
|
|
26
|
+
|
|
27
|
+
export interface DatabaseQueryLimitModifier {
|
|
28
|
+
id: string;
|
|
29
|
+
name: 'limitToFirst' | 'limitToLast';
|
|
30
|
+
type: 'limit';
|
|
31
|
+
value: number;
|
|
32
|
+
viewFrom: (typeof CONSTANTS)[keyof typeof CONSTANTS];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface DatabaseQueryOrderByModifier {
|
|
36
|
+
id: string;
|
|
37
|
+
type: 'orderBy';
|
|
38
|
+
name: 'orderByChild' | 'orderByKey' | 'orderByPriority' | 'orderByValue';
|
|
39
|
+
key?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface DatabaseQueryFilterModifier {
|
|
43
|
+
id: string;
|
|
44
|
+
type: 'filter';
|
|
45
|
+
name: 'startAt' | 'endAt';
|
|
46
|
+
value: QueryModifierValue;
|
|
47
|
+
valueType: 'number' | 'string' | 'boolean' | 'object' | 'null';
|
|
48
|
+
key?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type DatabaseQueryModifier =
|
|
52
|
+
| DatabaseQueryLimitModifier
|
|
53
|
+
| DatabaseQueryOrderByModifier
|
|
54
|
+
| DatabaseQueryFilterModifier;
|
|
55
|
+
|
|
56
|
+
function getFilterValueType(value: QueryModifierValue): DatabaseQueryFilterModifier['valueType'] {
|
|
57
|
+
if (value === null) {
|
|
58
|
+
return 'null';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
switch (typeof value) {
|
|
62
|
+
case 'number':
|
|
63
|
+
return 'number';
|
|
64
|
+
case 'string':
|
|
65
|
+
return 'string';
|
|
66
|
+
case 'boolean':
|
|
67
|
+
return 'boolean';
|
|
68
|
+
default:
|
|
69
|
+
return 'object';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default class DatabaseQueryModifiers {
|
|
74
|
+
private _limit: DatabaseQueryLimitModifier | undefined;
|
|
75
|
+
private _orderBy: DatabaseQueryOrderByModifier | undefined;
|
|
76
|
+
private _startAt: DatabaseQueryFilterModifier | undefined;
|
|
77
|
+
private _endAt: DatabaseQueryFilterModifier | undefined;
|
|
78
|
+
private _modifiers: DatabaseQueryModifier[];
|
|
79
|
+
|
|
80
|
+
constructor() {
|
|
81
|
+
this._limit = undefined;
|
|
82
|
+
this._orderBy = undefined;
|
|
83
|
+
this._startAt = undefined;
|
|
84
|
+
this._endAt = undefined;
|
|
85
|
+
this._modifiers = [];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
_copy(): DatabaseQueryModifiers {
|
|
89
|
+
const newInstance = new DatabaseQueryModifiers();
|
|
90
|
+
newInstance._limit = this._limit;
|
|
91
|
+
newInstance._orderBy = this._orderBy;
|
|
92
|
+
newInstance._startAt = this._startAt;
|
|
93
|
+
newInstance._endAt = this._endAt;
|
|
94
|
+
newInstance._modifiers = [...this._modifiers];
|
|
95
|
+
return newInstance;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
hasLimit(): boolean {
|
|
99
|
+
return this._limit !== undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
isValidLimit(limit: number): boolean {
|
|
103
|
+
return !isNumber(limit) || Math.floor(limit) !== limit || limit <= 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
limitToFirst(limit: number): DatabaseQueryModifiers {
|
|
107
|
+
const newLimit: DatabaseQueryLimitModifier = {
|
|
108
|
+
id: `limit-limitToFirst:${limit}`,
|
|
109
|
+
name: 'limitToFirst',
|
|
110
|
+
type: 'limit',
|
|
111
|
+
value: limit,
|
|
112
|
+
viewFrom: CONSTANTS.VIEW_FROM_LEFT,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
this._limit = newLimit;
|
|
116
|
+
this._modifiers.push(newLimit);
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
limitToLast(limit: number): DatabaseQueryModifiers {
|
|
121
|
+
const newLimit: DatabaseQueryLimitModifier = {
|
|
122
|
+
id: `limit-limitToLast:${limit}`,
|
|
123
|
+
name: 'limitToLast',
|
|
124
|
+
type: 'limit',
|
|
125
|
+
value: limit,
|
|
126
|
+
viewFrom: CONSTANTS.VIEW_FROM_RIGHT,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
this._limit = newLimit;
|
|
130
|
+
this._modifiers.push(newLimit);
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
hasOrderBy(): boolean {
|
|
135
|
+
return this._orderBy !== undefined;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
orderByChild(path: string): DatabaseQueryModifiers {
|
|
139
|
+
const newOrder: DatabaseQueryOrderByModifier = {
|
|
140
|
+
id: `order-orderByChild:${path}`,
|
|
141
|
+
type: 'orderBy',
|
|
142
|
+
name: 'orderByChild',
|
|
143
|
+
key: path,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
this._orderBy = newOrder;
|
|
147
|
+
this._modifiers.push(newOrder);
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
orderByKey(): DatabaseQueryModifiers {
|
|
152
|
+
const newOrder: DatabaseQueryOrderByModifier = {
|
|
153
|
+
id: 'order-orderByKey',
|
|
154
|
+
type: 'orderBy',
|
|
155
|
+
name: 'orderByKey',
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
this._orderBy = newOrder;
|
|
159
|
+
this._modifiers.push(newOrder);
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
isValidPriority(priority: QueryModifierValue): boolean {
|
|
164
|
+
return isNumber(priority) || isString(priority) || isNull(priority);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
orderByPriority(): DatabaseQueryModifiers {
|
|
168
|
+
const newOrder: DatabaseQueryOrderByModifier = {
|
|
169
|
+
id: 'order-orderByPriority',
|
|
170
|
+
type: 'orderBy',
|
|
171
|
+
name: 'orderByPriority',
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
this._orderBy = newOrder;
|
|
175
|
+
this._modifiers.push(newOrder);
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
orderByValue(): DatabaseQueryModifiers {
|
|
180
|
+
const newOrder: DatabaseQueryOrderByModifier = {
|
|
181
|
+
id: 'order-orderByValue',
|
|
182
|
+
type: 'orderBy',
|
|
183
|
+
name: 'orderByValue',
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
this._orderBy = newOrder;
|
|
187
|
+
this._modifiers.push(newOrder);
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
hasStartAt(): boolean {
|
|
192
|
+
return this._startAt !== undefined;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
hasEndAt(): boolean {
|
|
196
|
+
return this._endAt !== undefined;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
startAt(value: QueryModifierValue, key?: string): DatabaseQueryModifiers {
|
|
200
|
+
const newStart: DatabaseQueryFilterModifier = {
|
|
201
|
+
id: `filter-startAt:${value}:${key || ''}`,
|
|
202
|
+
type: 'filter',
|
|
203
|
+
name: 'startAt',
|
|
204
|
+
value,
|
|
205
|
+
valueType: getFilterValueType(value),
|
|
206
|
+
key,
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
this._startAt = newStart;
|
|
210
|
+
this._modifiers.push(newStart);
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
endAt(value: QueryModifierValue, key?: string): DatabaseQueryModifiers {
|
|
215
|
+
const newEnd: DatabaseQueryFilterModifier = {
|
|
216
|
+
id: `filter-endAt:${value}:${key || ''}`,
|
|
217
|
+
type: 'filter',
|
|
218
|
+
name: 'endAt',
|
|
219
|
+
value,
|
|
220
|
+
valueType: getFilterValueType(value),
|
|
221
|
+
key,
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
this._endAt = newEnd;
|
|
225
|
+
this._modifiers.push(newEnd);
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
toArray(): DatabaseQueryModifier[] {
|
|
230
|
+
return this._modifiers;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
toString(): string {
|
|
234
|
+
const sorted = [...this._modifiers].sort((a, b) => a.id.localeCompare(b.id));
|
|
235
|
+
let key = '{';
|
|
236
|
+
|
|
237
|
+
for (let index = 0; index < sorted.length; index++) {
|
|
238
|
+
const modifier = sorted[index];
|
|
239
|
+
if (!modifier) {
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (index !== 0) {
|
|
243
|
+
key += ',';
|
|
244
|
+
}
|
|
245
|
+
key += modifier.id;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
key += '}';
|
|
249
|
+
return key;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
validateModifiers(prefix: string): void {
|
|
253
|
+
if (this._orderBy?.name === 'orderByKey') {
|
|
254
|
+
if ((this._startAt && !!this._startAt.key) || (this._endAt && !!this._endAt.key)) {
|
|
255
|
+
throw new Error(
|
|
256
|
+
`${prefix} When ordering by key, you may only pass a value argument to startAt(), endAt(), or equalTo().`,
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (this._orderBy?.name === 'orderByKey') {
|
|
262
|
+
if (
|
|
263
|
+
(this._startAt && this._startAt.valueType !== 'string') ||
|
|
264
|
+
(this._endAt && this._endAt.valueType !== 'string')
|
|
265
|
+
) {
|
|
266
|
+
throw new Error(
|
|
267
|
+
`${prefix} When ordering by key, the value of startAt(), endAt(), or equalTo() must be a string.`,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (this._orderBy?.name === 'orderByPriority') {
|
|
273
|
+
if (
|
|
274
|
+
(this._startAt && !this.isValidPriority(this._startAt.value)) ||
|
|
275
|
+
(this._endAt && !this.isValidPriority(this._endAt.value))
|
|
276
|
+
) {
|
|
277
|
+
throw new Error(
|
|
278
|
+
`${prefix} When ordering by priority, the first value of startAt(), endAt(), or equalTo() must be a valid priority value (null, a number, or a string).`,
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
|
+
createDeprecationProxy,
|
|
19
20
|
generateDatabaseId,
|
|
20
21
|
isBoolean,
|
|
21
22
|
isFunction,
|
|
@@ -25,11 +26,10 @@ import {
|
|
|
25
26
|
isString,
|
|
26
27
|
isUndefined,
|
|
27
28
|
isValidPath,
|
|
29
|
+
MODULAR_DEPRECATION_ARG,
|
|
28
30
|
pathChild,
|
|
29
31
|
pathParent,
|
|
30
32
|
promiseWithOptionalCallback,
|
|
31
|
-
createDeprecationProxy,
|
|
32
|
-
MODULAR_DEPRECATION_ARG,
|
|
33
33
|
} from '@react-native-firebase/app/dist/module/common';
|
|
34
34
|
import DatabaseDataSnapshot from './DatabaseDataSnapshot';
|
|
35
35
|
import DatabaseOnDisconnect from './DatabaseOnDisconnect';
|
|
@@ -40,13 +40,39 @@ import DatabaseQueryModifiers from './DatabaseQueryModifiers';
|
|
|
40
40
|
import DatabaseThenableReference, {
|
|
41
41
|
provideReferenceClass as provideReferenceClassForThenable,
|
|
42
42
|
} from './DatabaseThenableReference';
|
|
43
|
+
import type { DatabaseInternal } from './types/internal';
|
|
44
|
+
import type { FirebaseDatabaseTypes } from './types/namespaced';
|
|
45
|
+
|
|
46
|
+
const internalRefs = ['.info/connected', '.info/serverTimeOffset'] as const;
|
|
47
|
+
|
|
48
|
+
type ReferenceWithChildInternal = FirebaseDatabaseTypes.Reference & {
|
|
49
|
+
child(path: string, deprecationArg?: string): FirebaseDatabaseTypes.Reference;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type ReferenceWithSetInternal = FirebaseDatabaseTypes.Reference & {
|
|
53
|
+
set(
|
|
54
|
+
value: unknown,
|
|
55
|
+
onComplete?: (error: Error | null) => void,
|
|
56
|
+
deprecationArg?: string,
|
|
57
|
+
): Promise<void>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function apChild(reference: FirebaseDatabaseTypes.Reference): ReferenceWithChildInternal {
|
|
61
|
+
return reference as ReferenceWithChildInternal;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function apSet(reference: FirebaseDatabaseTypes.Reference): ReferenceWithSetInternal {
|
|
65
|
+
return reference as ReferenceWithSetInternal;
|
|
66
|
+
}
|
|
43
67
|
|
|
44
|
-
|
|
68
|
+
export default class DatabaseReference
|
|
69
|
+
extends DatabaseQuery
|
|
70
|
+
implements FirebaseDatabaseTypes.Reference
|
|
71
|
+
{
|
|
72
|
+
readonly _database: DatabaseInternal;
|
|
45
73
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// Validate the reference path
|
|
49
|
-
if (!internalRefs.includes(path) && !isValidPath(path)) {
|
|
74
|
+
constructor(database: DatabaseInternal, path: string) {
|
|
75
|
+
if (!internalRefs.includes(path as (typeof internalRefs)[number]) && !isValidPath(path)) {
|
|
50
76
|
throw new Error(
|
|
51
77
|
'firebase.database() Paths must be non-empty strings and can\'t contain ".", "#", "$", "[", or "]"',
|
|
52
78
|
);
|
|
@@ -56,43 +82,32 @@ export default class DatabaseReference extends DatabaseQuery {
|
|
|
56
82
|
this._database = database;
|
|
57
83
|
}
|
|
58
84
|
|
|
59
|
-
|
|
60
|
-
* @url https://firebase.google.com/docs/reference/js/firebase.database.Reference.html#parent
|
|
61
|
-
*/
|
|
62
|
-
get parent() {
|
|
85
|
+
get parent(): FirebaseDatabaseTypes.Reference | null {
|
|
63
86
|
const parentPath = pathParent(this.path);
|
|
64
87
|
if (parentPath === null) {
|
|
65
88
|
return null;
|
|
66
89
|
}
|
|
67
|
-
return createDeprecationProxy(
|
|
90
|
+
return createDeprecationProxy(
|
|
91
|
+
new DatabaseReference(this._database, parentPath),
|
|
92
|
+
) as FirebaseDatabaseTypes.Reference;
|
|
68
93
|
}
|
|
69
94
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return createDeprecationProxy(new DatabaseReference(this._database, '/'));
|
|
95
|
+
get root(): FirebaseDatabaseTypes.Reference {
|
|
96
|
+
return createDeprecationProxy(
|
|
97
|
+
new DatabaseReference(this._database, '/'),
|
|
98
|
+
) as FirebaseDatabaseTypes.Reference;
|
|
75
99
|
}
|
|
76
100
|
|
|
77
|
-
|
|
78
|
-
* @url https://firebase.google.com/docs/reference/js/firebase.database.Reference.html#child
|
|
79
|
-
* @param path
|
|
80
|
-
*/
|
|
81
|
-
child(path) {
|
|
101
|
+
child(path: string): FirebaseDatabaseTypes.Reference {
|
|
82
102
|
if (!isString(path)) {
|
|
83
103
|
throw new Error("firebase.database().ref().child(*) 'path' must be a string value.");
|
|
84
104
|
}
|
|
85
105
|
return createDeprecationProxy(
|
|
86
106
|
new DatabaseReference(this._database, pathChild(this.path, path)),
|
|
87
|
-
);
|
|
107
|
+
) as FirebaseDatabaseTypes.Reference;
|
|
88
108
|
}
|
|
89
109
|
|
|
90
|
-
|
|
91
|
-
* @url https://firebase.google.com/docs/reference/js/firebase.database.Reference.html#set
|
|
92
|
-
* @param value
|
|
93
|
-
* @param onComplete
|
|
94
|
-
*/
|
|
95
|
-
set(value, onComplete) {
|
|
110
|
+
set(value: any, onComplete?: (error: Error | null) => void): Promise<void> {
|
|
96
111
|
if (isUndefined(value)) {
|
|
97
112
|
throw new Error("firebase.database().ref().set(*) 'value' must be defined.");
|
|
98
113
|
}
|
|
@@ -106,12 +121,10 @@ export default class DatabaseReference extends DatabaseQuery {
|
|
|
106
121
|
return promiseWithOptionalCallback(this._database.native.set(this.path, { value }), onComplete);
|
|
107
122
|
}
|
|
108
123
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
*/
|
|
114
|
-
update(values, onComplete) {
|
|
124
|
+
update(
|
|
125
|
+
values: { [key: string]: any },
|
|
126
|
+
onComplete?: (error: Error | null) => void,
|
|
127
|
+
): Promise<void> {
|
|
115
128
|
if (!isObject(values)) {
|
|
116
129
|
throw new Error("firebase.database().ref().update(*) 'values' must be an object.");
|
|
117
130
|
}
|
|
@@ -137,13 +150,11 @@ export default class DatabaseReference extends DatabaseQuery {
|
|
|
137
150
|
);
|
|
138
151
|
}
|
|
139
152
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
*/
|
|
146
|
-
setWithPriority(newVal, newPriority, onComplete) {
|
|
153
|
+
setWithPriority(
|
|
154
|
+
newVal: any,
|
|
155
|
+
newPriority: string | number | null,
|
|
156
|
+
onComplete?: (error: Error | null) => void,
|
|
157
|
+
): Promise<void> {
|
|
147
158
|
if (isUndefined(newVal)) {
|
|
148
159
|
throw new Error("firebase.database().ref().setWithPriority(*) 'newVal' must be defined.");
|
|
149
160
|
}
|
|
@@ -169,11 +180,7 @@ export default class DatabaseReference extends DatabaseQuery {
|
|
|
169
180
|
);
|
|
170
181
|
}
|
|
171
182
|
|
|
172
|
-
|
|
173
|
-
* @url https://firebase.google.com/docs/reference/js/firebase.database.Reference#remove
|
|
174
|
-
* @param onComplete
|
|
175
|
-
*/
|
|
176
|
-
remove(onComplete) {
|
|
183
|
+
remove(onComplete?: (error: Error | null) => void): Promise<void> {
|
|
177
184
|
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
|
|
178
185
|
throw new Error(
|
|
179
186
|
"firebase.database().ref().remove(*) 'onComplete' must be a function if provided.",
|
|
@@ -183,13 +190,15 @@ export default class DatabaseReference extends DatabaseQuery {
|
|
|
183
190
|
return promiseWithOptionalCallback(this._database.native.remove(this.path), onComplete);
|
|
184
191
|
}
|
|
185
192
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
+
transaction(
|
|
194
|
+
transactionUpdate: (currentData: any) => any | undefined,
|
|
195
|
+
onComplete?: (
|
|
196
|
+
error: Error | null,
|
|
197
|
+
committed: boolean,
|
|
198
|
+
finalResult: FirebaseDatabaseTypes.DataSnapshot | null,
|
|
199
|
+
) => void,
|
|
200
|
+
applyLocally?: boolean,
|
|
201
|
+
): Promise<FirebaseDatabaseTypes.TransactionResult> {
|
|
193
202
|
if (!isFunction(transactionUpdate)) {
|
|
194
203
|
throw new Error(
|
|
195
204
|
"firebase.database().ref().transaction(*) 'transactionUpdate' must be a function.",
|
|
@@ -209,7 +218,11 @@ export default class DatabaseReference extends DatabaseQuery {
|
|
|
209
218
|
}
|
|
210
219
|
|
|
211
220
|
return new Promise((resolve, reject) => {
|
|
212
|
-
const onCompleteWrapper = (
|
|
221
|
+
const onCompleteWrapper = (
|
|
222
|
+
error: Error | null,
|
|
223
|
+
committed: boolean,
|
|
224
|
+
snapshotData: unknown | null,
|
|
225
|
+
) => {
|
|
213
226
|
if (isFunction(onComplete)) {
|
|
214
227
|
if (error) {
|
|
215
228
|
onComplete(error, committed, null);
|
|
@@ -217,31 +230,40 @@ export default class DatabaseReference extends DatabaseQuery {
|
|
|
217
230
|
onComplete(
|
|
218
231
|
null,
|
|
219
232
|
committed,
|
|
220
|
-
createDeprecationProxy(
|
|
233
|
+
createDeprecationProxy(
|
|
234
|
+
new DatabaseDataSnapshot(
|
|
235
|
+
this,
|
|
236
|
+
snapshotData as ConstructorParameters<typeof DatabaseDataSnapshot>[1],
|
|
237
|
+
),
|
|
238
|
+
) as FirebaseDatabaseTypes.DataSnapshot,
|
|
221
239
|
);
|
|
222
240
|
}
|
|
223
241
|
}
|
|
224
242
|
|
|
225
243
|
if (error) {
|
|
226
|
-
|
|
244
|
+
reject(error);
|
|
245
|
+
return;
|
|
227
246
|
}
|
|
228
|
-
|
|
247
|
+
|
|
248
|
+
resolve({
|
|
229
249
|
committed,
|
|
230
|
-
snapshot: createDeprecationProxy(
|
|
250
|
+
snapshot: createDeprecationProxy(
|
|
251
|
+
new DatabaseDataSnapshot(
|
|
252
|
+
this,
|
|
253
|
+
snapshotData as ConstructorParameters<typeof DatabaseDataSnapshot>[1],
|
|
254
|
+
),
|
|
255
|
+
) as FirebaseDatabaseTypes.DataSnapshot,
|
|
231
256
|
});
|
|
232
257
|
};
|
|
233
258
|
|
|
234
|
-
// start the transaction natively
|
|
235
259
|
this._database._transaction.add(this, transactionUpdate, onCompleteWrapper, applyLocally);
|
|
236
260
|
});
|
|
237
261
|
}
|
|
238
262
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
*/
|
|
244
|
-
setPriority(priority, onComplete) {
|
|
263
|
+
setPriority(
|
|
264
|
+
priority: string | number | null,
|
|
265
|
+
onComplete?: (error: Error | null) => void,
|
|
266
|
+
): Promise<void> {
|
|
245
267
|
if (!isNumber(priority) && !isString(priority) && !isNull(priority)) {
|
|
246
268
|
throw new Error(
|
|
247
269
|
"firebase.database().ref().setPriority(*) 'priority' must be a number, string or null value.",
|
|
@@ -260,13 +282,10 @@ export default class DatabaseReference extends DatabaseQuery {
|
|
|
260
282
|
);
|
|
261
283
|
}
|
|
262
284
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
* @returns {DatabaseReference}
|
|
268
|
-
*/
|
|
269
|
-
push(value, onComplete) {
|
|
285
|
+
push(
|
|
286
|
+
value?: any,
|
|
287
|
+
onComplete?: (error: Error | null) => void,
|
|
288
|
+
): FirebaseDatabaseTypes.ThenableReference {
|
|
270
289
|
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
|
|
271
290
|
throw new Error(
|
|
272
291
|
"firebase.database().ref().push(_, *) 'onComplete' must be a function if provided.",
|
|
@@ -279,32 +298,31 @@ export default class DatabaseReference extends DatabaseQuery {
|
|
|
279
298
|
return new DatabaseThenableReference(
|
|
280
299
|
this._database,
|
|
281
300
|
pathChild(this.path, id),
|
|
282
|
-
Promise.resolve(this.child.call(this, id, MODULAR_DEPRECATION_ARG)),
|
|
283
|
-
);
|
|
301
|
+
Promise.resolve(apChild(this).child.call(this, id, MODULAR_DEPRECATION_ARG)),
|
|
302
|
+
) as unknown as FirebaseDatabaseTypes.ThenableReference;
|
|
284
303
|
}
|
|
285
304
|
|
|
286
|
-
const pushRef = this.child.call(this, id, MODULAR_DEPRECATION_ARG);
|
|
305
|
+
const pushRef = apChild(this).child.call(this, id, MODULAR_DEPRECATION_ARG);
|
|
287
306
|
|
|
288
|
-
const promise = pushRef
|
|
289
|
-
.call(pushRef, value, onComplete, MODULAR_DEPRECATION_ARG)
|
|
307
|
+
const promise = apSet(pushRef)
|
|
308
|
+
.set.call(pushRef, value, onComplete, MODULAR_DEPRECATION_ARG)
|
|
290
309
|
.then(() => pushRef);
|
|
291
310
|
|
|
292
|
-
// Prevent unhandled promise rejection if onComplete is passed
|
|
293
311
|
if (onComplete) {
|
|
294
312
|
promise.catch(() => {});
|
|
295
313
|
}
|
|
296
314
|
|
|
297
|
-
return new DatabaseThenableReference(
|
|
315
|
+
return new DatabaseThenableReference(
|
|
316
|
+
this._database,
|
|
317
|
+
pathChild(this.path, id),
|
|
318
|
+
promise,
|
|
319
|
+
) as unknown as FirebaseDatabaseTypes.ThenableReference;
|
|
298
320
|
}
|
|
299
321
|
|
|
300
|
-
|
|
301
|
-
* @url https://firebase.google.com/docs/reference/js/firebase.database.Reference#ondisconnect
|
|
302
|
-
*/
|
|
303
|
-
onDisconnect() {
|
|
322
|
+
onDisconnect(): FirebaseDatabaseTypes.OnDisconnect {
|
|
304
323
|
return new DatabaseOnDisconnect(this);
|
|
305
324
|
}
|
|
306
325
|
}
|
|
307
326
|
|
|
308
|
-
// To avoid React Native require cycle warnings
|
|
309
327
|
provideReferenceClassForQuery(DatabaseReference);
|
|
310
328
|
provideReferenceClassForThenable(DatabaseReference);
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const DatabaseStatics = {
|
|
19
19
|
ServerValue: {
|
|
20
20
|
TIMESTAMP: {
|
|
21
21
|
'.sv': 'timestamp',
|
|
22
22
|
},
|
|
23
|
-
increment(delta) {
|
|
23
|
+
increment(delta: number): object {
|
|
24
24
|
return {
|
|
25
25
|
'.sv': {
|
|
26
26
|
increment: delta,
|
|
@@ -29,3 +29,5 @@ export default {
|
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
31
|
};
|
|
32
|
+
|
|
33
|
+
export default DatabaseStatics;
|