@firebase/database-compat 1.0.8 → 1.0.9-20241017211210
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/dist/index.esm2017.js +1 -1
- package/dist/index.js +226 -279
- package/dist/index.js.map +1 -1
- package/dist/index.standalone.js +3262 -3803
- package/dist/index.standalone.js.map +1 -1
- package/dist/node-esm/index.js +1 -1
- package/package.json +10 -9
- package/dist/index.esm5.js +0 -914
- package/dist/index.esm5.js.map +0 -1
package/dist/index.js
CHANGED
@@ -4,15 +4,14 @@ var firebase = require('@firebase/app-compat');
|
|
4
4
|
var component = require('@firebase/component');
|
5
5
|
var database = require('@firebase/database');
|
6
6
|
var util = require('@firebase/util');
|
7
|
-
var tslib = require('tslib');
|
8
7
|
var logger = require('@firebase/logger');
|
9
8
|
|
10
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
11
10
|
|
12
11
|
var firebase__default = /*#__PURE__*/_interopDefaultLegacy(firebase);
|
13
12
|
|
14
|
-
|
15
|
-
|
13
|
+
const name = "@firebase/database-compat";
|
14
|
+
const version = "1.0.9-20241017211210";
|
16
15
|
|
17
16
|
/**
|
18
17
|
* @license
|
@@ -30,9 +29,9 @@ var version = "1.0.8";
|
|
30
29
|
* See the License for the specific language governing permissions and
|
31
30
|
* limitations under the License.
|
32
31
|
*/
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
const logClient = new logger.Logger('@firebase/database-compat');
|
33
|
+
const warn = function (msg) {
|
34
|
+
const message = 'FIREBASE WARNING: ' + msg;
|
36
35
|
logClient.warn(message);
|
37
36
|
};
|
38
37
|
|
@@ -52,7 +51,7 @@ var warn = function (msg) {
|
|
52
51
|
* See the License for the specific language governing permissions and
|
53
52
|
* limitations under the License.
|
54
53
|
*/
|
55
|
-
|
54
|
+
const validateBoolean = function (fnName, argumentName, bool, optional) {
|
56
55
|
if (optional && bool === undefined) {
|
57
56
|
return;
|
58
57
|
}
|
@@ -60,7 +59,7 @@ var validateBoolean = function (fnName, argumentName, bool, optional) {
|
|
60
59
|
throw new Error(util.errorPrefix(fnName, argumentName) + 'must be a boolean.');
|
61
60
|
}
|
62
61
|
};
|
63
|
-
|
62
|
+
const validateEventType = function (fnName, eventType, optional) {
|
64
63
|
if (optional && eventType === undefined) {
|
65
64
|
return;
|
66
65
|
}
|
@@ -94,51 +93,51 @@ var validateEventType = function (fnName, eventType, optional) {
|
|
94
93
|
* See the License for the specific language governing permissions and
|
95
94
|
* limitations under the License.
|
96
95
|
*/
|
97
|
-
|
98
|
-
|
96
|
+
class OnDisconnect {
|
97
|
+
constructor(_delegate) {
|
99
98
|
this._delegate = _delegate;
|
100
99
|
}
|
101
|
-
|
100
|
+
cancel(onComplete) {
|
102
101
|
util.validateArgCount('OnDisconnect.cancel', 0, 1, arguments.length);
|
103
102
|
util.validateCallback('OnDisconnect.cancel', 'onComplete', onComplete, true);
|
104
|
-
|
103
|
+
const result = this._delegate.cancel();
|
105
104
|
if (onComplete) {
|
106
|
-
result.then(
|
105
|
+
result.then(() => onComplete(null), error => onComplete(error));
|
107
106
|
}
|
108
107
|
return result;
|
109
|
-
}
|
110
|
-
|
108
|
+
}
|
109
|
+
remove(onComplete) {
|
111
110
|
util.validateArgCount('OnDisconnect.remove', 0, 1, arguments.length);
|
112
111
|
util.validateCallback('OnDisconnect.remove', 'onComplete', onComplete, true);
|
113
|
-
|
112
|
+
const result = this._delegate.remove();
|
114
113
|
if (onComplete) {
|
115
|
-
result.then(
|
114
|
+
result.then(() => onComplete(null), error => onComplete(error));
|
116
115
|
}
|
117
116
|
return result;
|
118
|
-
}
|
119
|
-
|
117
|
+
}
|
118
|
+
set(value, onComplete) {
|
120
119
|
util.validateArgCount('OnDisconnect.set', 1, 2, arguments.length);
|
121
120
|
util.validateCallback('OnDisconnect.set', 'onComplete', onComplete, true);
|
122
|
-
|
121
|
+
const result = this._delegate.set(value);
|
123
122
|
if (onComplete) {
|
124
|
-
result.then(
|
123
|
+
result.then(() => onComplete(null), error => onComplete(error));
|
125
124
|
}
|
126
125
|
return result;
|
127
|
-
}
|
128
|
-
|
126
|
+
}
|
127
|
+
setWithPriority(value, priority, onComplete) {
|
129
128
|
util.validateArgCount('OnDisconnect.setWithPriority', 2, 3, arguments.length);
|
130
129
|
util.validateCallback('OnDisconnect.setWithPriority', 'onComplete', onComplete, true);
|
131
|
-
|
130
|
+
const result = this._delegate.setWithPriority(value, priority);
|
132
131
|
if (onComplete) {
|
133
|
-
result.then(
|
132
|
+
result.then(() => onComplete(null), error => onComplete(error));
|
134
133
|
}
|
135
134
|
return result;
|
136
|
-
}
|
137
|
-
|
135
|
+
}
|
136
|
+
update(objectToMerge, onComplete) {
|
138
137
|
util.validateArgCount('OnDisconnect.update', 1, 2, arguments.length);
|
139
138
|
if (Array.isArray(objectToMerge)) {
|
140
|
-
|
141
|
-
for (
|
139
|
+
const newObjectToMerge = {};
|
140
|
+
for (let i = 0; i < objectToMerge.length; ++i) {
|
142
141
|
newObjectToMerge['' + i] = objectToMerge[i];
|
143
142
|
}
|
144
143
|
objectToMerge = newObjectToMerge;
|
@@ -146,14 +145,13 @@ var OnDisconnect = /** @class */ (function () {
|
|
146
145
|
'existing data, or an Object with integer keys if you really do want to only update some of the children.');
|
147
146
|
}
|
148
147
|
util.validateCallback('OnDisconnect.update', 'onComplete', onComplete, true);
|
149
|
-
|
148
|
+
const result = this._delegate.update(objectToMerge);
|
150
149
|
if (onComplete) {
|
151
|
-
result.then(
|
150
|
+
result.then(() => onComplete(null), error => onComplete(error));
|
152
151
|
}
|
153
152
|
return result;
|
154
|
-
}
|
155
|
-
|
156
|
-
}());
|
153
|
+
}
|
154
|
+
}
|
157
155
|
|
158
156
|
/**
|
159
157
|
* @license
|
@@ -171,22 +169,21 @@ var OnDisconnect = /** @class */ (function () {
|
|
171
169
|
* See the License for the specific language governing permissions and
|
172
170
|
* limitations under the License.
|
173
171
|
*/
|
174
|
-
|
172
|
+
class TransactionResult {
|
175
173
|
/**
|
176
174
|
* A type for the resolve value of Firebase.transaction.
|
177
175
|
*/
|
178
|
-
|
176
|
+
constructor(committed, snapshot) {
|
179
177
|
this.committed = committed;
|
180
178
|
this.snapshot = snapshot;
|
181
179
|
}
|
182
180
|
// Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
|
183
181
|
// for end-users
|
184
|
-
|
182
|
+
toJSON() {
|
185
183
|
util.validateArgCount('TransactionResult.toJSON', 0, 1, arguments.length);
|
186
184
|
return { committed: this.committed, snapshot: this.snapshot.toJSON() };
|
187
|
-
}
|
188
|
-
|
189
|
-
}());
|
185
|
+
}
|
186
|
+
}
|
190
187
|
|
191
188
|
/**
|
192
189
|
* @license
|
@@ -208,8 +205,8 @@ var TransactionResult = /** @class */ (function () {
|
|
208
205
|
* Class representing a firebase data snapshot. It wraps a SnapshotNode and
|
209
206
|
* surfaces the public methods (val, forEach, etc.) we want to expose.
|
210
207
|
*/
|
211
|
-
|
212
|
-
|
208
|
+
class DataSnapshot {
|
209
|
+
constructor(_database, _delegate) {
|
213
210
|
this._database = _database;
|
214
211
|
this._delegate = _delegate;
|
215
212
|
}
|
@@ -219,68 +216,68 @@ var DataSnapshot = /** @class */ (function () {
|
|
219
216
|
*
|
220
217
|
* @returns JSON representation of the DataSnapshot contents, or null if empty.
|
221
218
|
*/
|
222
|
-
|
219
|
+
val() {
|
223
220
|
util.validateArgCount('DataSnapshot.val', 0, 0, arguments.length);
|
224
221
|
return this._delegate.val();
|
225
|
-
}
|
222
|
+
}
|
226
223
|
/**
|
227
224
|
* Returns the snapshot contents as JSON, including priorities of node. Suitable for exporting
|
228
225
|
* the entire node contents.
|
229
226
|
* @returns JSON representation of the DataSnapshot contents, or null if empty.
|
230
227
|
*/
|
231
|
-
|
228
|
+
exportVal() {
|
232
229
|
util.validateArgCount('DataSnapshot.exportVal', 0, 0, arguments.length);
|
233
230
|
return this._delegate.exportVal();
|
234
|
-
}
|
231
|
+
}
|
235
232
|
// Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
|
236
233
|
// for end-users
|
237
|
-
|
234
|
+
toJSON() {
|
238
235
|
// Optional spacer argument is unnecessary because we're depending on recursion rather than stringifying the content
|
239
236
|
util.validateArgCount('DataSnapshot.toJSON', 0, 1, arguments.length);
|
240
237
|
return this._delegate.toJSON();
|
241
|
-
}
|
238
|
+
}
|
242
239
|
/**
|
243
240
|
* Returns whether the snapshot contains a non-null value.
|
244
241
|
*
|
245
242
|
* @returns Whether the snapshot contains a non-null value, or is empty.
|
246
243
|
*/
|
247
|
-
|
244
|
+
exists() {
|
248
245
|
util.validateArgCount('DataSnapshot.exists', 0, 0, arguments.length);
|
249
246
|
return this._delegate.exists();
|
250
|
-
}
|
247
|
+
}
|
251
248
|
/**
|
252
249
|
* Returns a DataSnapshot of the specified child node's contents.
|
253
250
|
*
|
254
251
|
* @param path - Path to a child.
|
255
252
|
* @returns DataSnapshot for child node.
|
256
253
|
*/
|
257
|
-
|
254
|
+
child(path) {
|
258
255
|
util.validateArgCount('DataSnapshot.child', 0, 1, arguments.length);
|
259
256
|
// Ensure the childPath is a string (can be a number)
|
260
257
|
path = String(path);
|
261
258
|
database._validatePathString('DataSnapshot.child', 'path', path, false);
|
262
259
|
return new DataSnapshot(this._database, this._delegate.child(path));
|
263
|
-
}
|
260
|
+
}
|
264
261
|
/**
|
265
262
|
* Returns whether the snapshot contains a child at the specified path.
|
266
263
|
*
|
267
264
|
* @param path - Path to a child.
|
268
265
|
* @returns Whether the child exists.
|
269
266
|
*/
|
270
|
-
|
267
|
+
hasChild(path) {
|
271
268
|
util.validateArgCount('DataSnapshot.hasChild', 1, 1, arguments.length);
|
272
269
|
database._validatePathString('DataSnapshot.hasChild', 'path', path, false);
|
273
270
|
return this._delegate.hasChild(path);
|
274
|
-
}
|
271
|
+
}
|
275
272
|
/**
|
276
273
|
* Returns the priority of the object, or null if no priority was set.
|
277
274
|
*
|
278
275
|
* @returns The priority.
|
279
276
|
*/
|
280
|
-
|
277
|
+
getPriority() {
|
281
278
|
util.validateArgCount('DataSnapshot.getPriority', 0, 0, arguments.length);
|
282
279
|
return this._delegate.priority;
|
283
|
-
}
|
280
|
+
}
|
284
281
|
/**
|
285
282
|
* Iterates through child nodes and calls the specified action for each one.
|
286
283
|
*
|
@@ -289,77 +286,64 @@ var DataSnapshot = /** @class */ (function () {
|
|
289
286
|
* @returns True if forEach was canceled by action returning true for
|
290
287
|
* one of the child nodes.
|
291
288
|
*/
|
292
|
-
|
293
|
-
var _this = this;
|
289
|
+
forEach(action) {
|
294
290
|
util.validateArgCount('DataSnapshot.forEach', 1, 1, arguments.length);
|
295
291
|
util.validateCallback('DataSnapshot.forEach', 'action', action, false);
|
296
|
-
return this._delegate.forEach(
|
297
|
-
|
298
|
-
});
|
299
|
-
};
|
292
|
+
return this._delegate.forEach(expDataSnapshot => action(new DataSnapshot(this._database, expDataSnapshot)));
|
293
|
+
}
|
300
294
|
/**
|
301
295
|
* Returns whether this DataSnapshot has children.
|
302
296
|
* @returns True if the DataSnapshot contains 1 or more child nodes.
|
303
297
|
*/
|
304
|
-
|
298
|
+
hasChildren() {
|
305
299
|
util.validateArgCount('DataSnapshot.hasChildren', 0, 0, arguments.length);
|
306
300
|
return this._delegate.hasChildren();
|
307
|
-
}
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
},
|
312
|
-
enumerable: false,
|
313
|
-
configurable: true
|
314
|
-
});
|
301
|
+
}
|
302
|
+
get key() {
|
303
|
+
return this._delegate.key;
|
304
|
+
}
|
315
305
|
/**
|
316
306
|
* Returns the number of children for this DataSnapshot.
|
317
307
|
* @returns The number of children that this DataSnapshot contains.
|
318
308
|
*/
|
319
|
-
|
309
|
+
numChildren() {
|
320
310
|
util.validateArgCount('DataSnapshot.numChildren', 0, 0, arguments.length);
|
321
311
|
return this._delegate.size;
|
322
|
-
}
|
312
|
+
}
|
323
313
|
/**
|
324
314
|
* @returns The Firebase reference for the location this snapshot's data came
|
325
315
|
* from.
|
326
316
|
*/
|
327
|
-
|
317
|
+
getRef() {
|
328
318
|
util.validateArgCount('DataSnapshot.ref', 0, 0, arguments.length);
|
329
319
|
return new Reference(this._database, this._delegate.ref);
|
330
|
-
}
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
enumerable: false,
|
336
|
-
configurable: true
|
337
|
-
});
|
338
|
-
return DataSnapshot;
|
339
|
-
}());
|
320
|
+
}
|
321
|
+
get ref() {
|
322
|
+
return this.getRef();
|
323
|
+
}
|
324
|
+
}
|
340
325
|
/**
|
341
326
|
* A Query represents a filter to be applied to a firebase location. This object purely represents the
|
342
327
|
* query expression (and exposes our public API to build the query). The actual query logic is in ViewBase.js.
|
343
328
|
*
|
344
329
|
* Since every Firebase reference is a query, Firebase inherits from this object.
|
345
330
|
*/
|
346
|
-
|
347
|
-
|
331
|
+
class Query {
|
332
|
+
constructor(database, _delegate) {
|
348
333
|
this.database = database;
|
349
334
|
this._delegate = _delegate;
|
350
335
|
}
|
351
|
-
|
352
|
-
var _this = this;
|
336
|
+
on(eventType, callback, cancelCallbackOrContext, context) {
|
353
337
|
var _a;
|
354
338
|
util.validateArgCount('Query.on', 2, 4, arguments.length);
|
355
339
|
util.validateCallback('Query.on', 'callback', callback, false);
|
356
|
-
|
357
|
-
|
358
|
-
callback.call(ret.context, new DataSnapshot(
|
340
|
+
const ret = Query.getCancelAndContextArgs_('Query.on', cancelCallbackOrContext, context);
|
341
|
+
const valueCallback = (expSnapshot, previousChildName) => {
|
342
|
+
callback.call(ret.context, new DataSnapshot(this.database, expSnapshot), previousChildName);
|
359
343
|
};
|
360
344
|
valueCallback.userCallback = callback;
|
361
345
|
valueCallback.context = ret.context;
|
362
|
-
|
346
|
+
const cancelCallback = (_a = ret.cancel) === null || _a === void 0 ? void 0 : _a.bind(ret.context);
|
363
347
|
switch (eventType) {
|
364
348
|
case 'value':
|
365
349
|
database.onValue(this._delegate, valueCallback, cancelCallback);
|
@@ -381,14 +365,14 @@ var Query = /** @class */ (function () {
|
|
381
365
|
'must be a valid event type = "value", "child_added", "child_removed", ' +
|
382
366
|
'"child_changed", or "child_moved".');
|
383
367
|
}
|
384
|
-
}
|
385
|
-
|
368
|
+
}
|
369
|
+
off(eventType, callback, context) {
|
386
370
|
util.validateArgCount('Query.off', 0, 3, arguments.length);
|
387
371
|
validateEventType('Query.off', eventType, true);
|
388
372
|
util.validateCallback('Query.off', 'callback', callback, true);
|
389
373
|
util.validateContextObject('Query.off', 'context', context, true);
|
390
374
|
if (callback) {
|
391
|
-
|
375
|
+
const valueCallback = () => { };
|
392
376
|
valueCallback.userCallback = callback;
|
393
377
|
valueCallback.context = context;
|
394
378
|
database.off(this._delegate, eventType, valueCallback);
|
@@ -396,27 +380,25 @@ var Query = /** @class */ (function () {
|
|
396
380
|
else {
|
397
381
|
database.off(this._delegate, eventType);
|
398
382
|
}
|
399
|
-
}
|
383
|
+
}
|
400
384
|
/**
|
401
385
|
* Get the server-value for this query, or return a cached value if not connected.
|
402
386
|
*/
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
return new DataSnapshot(_this.database, expSnapshot);
|
387
|
+
get() {
|
388
|
+
return database.get(this._delegate).then(expSnapshot => {
|
389
|
+
return new DataSnapshot(this.database, expSnapshot);
|
407
390
|
});
|
408
|
-
}
|
391
|
+
}
|
409
392
|
/**
|
410
393
|
* Attaches a listener, waits for the first event, and then removes the listener
|
411
394
|
*/
|
412
|
-
|
413
|
-
var _this = this;
|
395
|
+
once(eventType, callback, failureCallbackOrContext, context) {
|
414
396
|
util.validateArgCount('Query.once', 1, 4, arguments.length);
|
415
397
|
util.validateCallback('Query.once', 'callback', callback, true);
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
398
|
+
const ret = Query.getCancelAndContextArgs_('Query.once', failureCallbackOrContext, context);
|
399
|
+
const deferred = new util.Deferred();
|
400
|
+
const valueCallback = (expSnapshot, previousChildName) => {
|
401
|
+
const result = new DataSnapshot(this.database, expSnapshot);
|
420
402
|
if (callback) {
|
421
403
|
callback.call(ret.context, result, previousChildName);
|
422
404
|
}
|
@@ -424,7 +406,7 @@ var Query = /** @class */ (function () {
|
|
424
406
|
};
|
425
407
|
valueCallback.userCallback = callback;
|
426
408
|
valueCallback.context = ret.context;
|
427
|
-
|
409
|
+
const cancelCallback = (error) => {
|
428
410
|
if (ret.cancel) {
|
429
411
|
ret.cancel.call(ret.context, error);
|
430
412
|
}
|
@@ -462,109 +444,105 @@ var Query = /** @class */ (function () {
|
|
462
444
|
'"child_changed", or "child_moved".');
|
463
445
|
}
|
464
446
|
return deferred.promise;
|
465
|
-
}
|
447
|
+
}
|
466
448
|
/**
|
467
449
|
* Set a limit and anchor it to the start of the window.
|
468
450
|
*/
|
469
|
-
|
451
|
+
limitToFirst(limit) {
|
470
452
|
util.validateArgCount('Query.limitToFirst', 1, 1, arguments.length);
|
471
453
|
return new Query(this.database, database.query(this._delegate, database.limitToFirst(limit)));
|
472
|
-
}
|
454
|
+
}
|
473
455
|
/**
|
474
456
|
* Set a limit and anchor it to the end of the window.
|
475
457
|
*/
|
476
|
-
|
458
|
+
limitToLast(limit) {
|
477
459
|
util.validateArgCount('Query.limitToLast', 1, 1, arguments.length);
|
478
460
|
return new Query(this.database, database.query(this._delegate, database.limitToLast(limit)));
|
479
|
-
}
|
461
|
+
}
|
480
462
|
/**
|
481
463
|
* Given a child path, return a new query ordered by the specified grandchild path.
|
482
464
|
*/
|
483
|
-
|
465
|
+
orderByChild(path) {
|
484
466
|
util.validateArgCount('Query.orderByChild', 1, 1, arguments.length);
|
485
467
|
return new Query(this.database, database.query(this._delegate, database.orderByChild(path)));
|
486
|
-
}
|
468
|
+
}
|
487
469
|
/**
|
488
470
|
* Return a new query ordered by the KeyIndex
|
489
471
|
*/
|
490
|
-
|
472
|
+
orderByKey() {
|
491
473
|
util.validateArgCount('Query.orderByKey', 0, 0, arguments.length);
|
492
474
|
return new Query(this.database, database.query(this._delegate, database.orderByKey()));
|
493
|
-
}
|
475
|
+
}
|
494
476
|
/**
|
495
477
|
* Return a new query ordered by the PriorityIndex
|
496
478
|
*/
|
497
|
-
|
479
|
+
orderByPriority() {
|
498
480
|
util.validateArgCount('Query.orderByPriority', 0, 0, arguments.length);
|
499
481
|
return new Query(this.database, database.query(this._delegate, database.orderByPriority()));
|
500
|
-
}
|
482
|
+
}
|
501
483
|
/**
|
502
484
|
* Return a new query ordered by the ValueIndex
|
503
485
|
*/
|
504
|
-
|
486
|
+
orderByValue() {
|
505
487
|
util.validateArgCount('Query.orderByValue', 0, 0, arguments.length);
|
506
488
|
return new Query(this.database, database.query(this._delegate, database.orderByValue()));
|
507
|
-
}
|
508
|
-
|
509
|
-
if (value === void 0) { value = null; }
|
489
|
+
}
|
490
|
+
startAt(value = null, name) {
|
510
491
|
util.validateArgCount('Query.startAt', 0, 2, arguments.length);
|
511
492
|
return new Query(this.database, database.query(this._delegate, database.startAt(value, name)));
|
512
|
-
}
|
513
|
-
|
514
|
-
if (value === void 0) { value = null; }
|
493
|
+
}
|
494
|
+
startAfter(value = null, name) {
|
515
495
|
util.validateArgCount('Query.startAfter', 0, 2, arguments.length);
|
516
496
|
return new Query(this.database, database.query(this._delegate, database.startAfter(value, name)));
|
517
|
-
}
|
518
|
-
|
519
|
-
if (value === void 0) { value = null; }
|
497
|
+
}
|
498
|
+
endAt(value = null, name) {
|
520
499
|
util.validateArgCount('Query.endAt', 0, 2, arguments.length);
|
521
500
|
return new Query(this.database, database.query(this._delegate, database.endAt(value, name)));
|
522
|
-
}
|
523
|
-
|
524
|
-
if (value === void 0) { value = null; }
|
501
|
+
}
|
502
|
+
endBefore(value = null, name) {
|
525
503
|
util.validateArgCount('Query.endBefore', 0, 2, arguments.length);
|
526
504
|
return new Query(this.database, database.query(this._delegate, database.endBefore(value, name)));
|
527
|
-
}
|
505
|
+
}
|
528
506
|
/**
|
529
507
|
* Load the selection of children with exactly the specified value, and, optionally,
|
530
508
|
* the specified name.
|
531
509
|
*/
|
532
|
-
|
510
|
+
equalTo(value, name) {
|
533
511
|
util.validateArgCount('Query.equalTo', 1, 2, arguments.length);
|
534
512
|
return new Query(this.database, database.query(this._delegate, database.equalTo(value, name)));
|
535
|
-
}
|
513
|
+
}
|
536
514
|
/**
|
537
515
|
* @returns URL for this location.
|
538
516
|
*/
|
539
|
-
|
517
|
+
toString() {
|
540
518
|
util.validateArgCount('Query.toString', 0, 0, arguments.length);
|
541
519
|
return this._delegate.toString();
|
542
|
-
}
|
520
|
+
}
|
543
521
|
// Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
|
544
522
|
// for end-users.
|
545
|
-
|
523
|
+
toJSON() {
|
546
524
|
// An optional spacer argument is unnecessary for a string.
|
547
525
|
util.validateArgCount('Query.toJSON', 0, 1, arguments.length);
|
548
526
|
return this._delegate.toJSON();
|
549
|
-
}
|
527
|
+
}
|
550
528
|
/**
|
551
529
|
* Return true if this query and the provided query are equivalent; otherwise, return false.
|
552
530
|
*/
|
553
|
-
|
531
|
+
isEqual(other) {
|
554
532
|
util.validateArgCount('Query.isEqual', 1, 1, arguments.length);
|
555
533
|
if (!(other instanceof Query)) {
|
556
|
-
|
534
|
+
const error = 'Query.isEqual failed: First argument must be an instance of firebase.database.Query.';
|
557
535
|
throw new Error(error);
|
558
536
|
}
|
559
537
|
return this._delegate.isEqual(other._delegate);
|
560
|
-
}
|
538
|
+
}
|
561
539
|
/**
|
562
540
|
* Helper used by .on and .once to extract the context and or cancel arguments.
|
563
541
|
* @param fnName - The function name (on or once)
|
564
542
|
*
|
565
543
|
*/
|
566
|
-
|
567
|
-
|
544
|
+
static getCancelAndContextArgs_(fnName, cancelOrContext, context) {
|
545
|
+
const ret = { cancel: undefined, context: undefined };
|
568
546
|
if (cancelOrContext && context) {
|
569
547
|
ret.cancel = cancelOrContext;
|
570
548
|
util.validateCallback(fnName, 'cancel', ret.cancel, true);
|
@@ -586,18 +564,12 @@ var Query = /** @class */ (function () {
|
|
586
564
|
}
|
587
565
|
}
|
588
566
|
return ret;
|
589
|
-
}
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
configurable: true
|
596
|
-
});
|
597
|
-
return Query;
|
598
|
-
}());
|
599
|
-
var Reference = /** @class */ (function (_super) {
|
600
|
-
tslib.__extends(Reference, _super);
|
567
|
+
}
|
568
|
+
get ref() {
|
569
|
+
return new Reference(this.database, new database._ReferenceImpl(this._delegate._repo, this._delegate._path));
|
570
|
+
}
|
571
|
+
}
|
572
|
+
class Reference extends Query {
|
601
573
|
/**
|
602
574
|
* Call options:
|
603
575
|
* new Reference(Repo, Path) or
|
@@ -605,49 +577,48 @@ var Reference = /** @class */ (function (_super) {
|
|
605
577
|
*
|
606
578
|
* Externally - this is the firebase.database.Reference type.
|
607
579
|
*/
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
return _this;
|
580
|
+
constructor(database$1, _delegate) {
|
581
|
+
super(database$1, new database._QueryImpl(_delegate._repo, _delegate._path, new database._QueryParams(), false));
|
582
|
+
this.database = database$1;
|
583
|
+
this._delegate = _delegate;
|
613
584
|
}
|
614
585
|
/** @returns {?string} */
|
615
|
-
|
586
|
+
getKey() {
|
616
587
|
util.validateArgCount('Reference.key', 0, 0, arguments.length);
|
617
588
|
return this._delegate.key;
|
618
|
-
}
|
619
|
-
|
589
|
+
}
|
590
|
+
child(pathString) {
|
620
591
|
util.validateArgCount('Reference.child', 1, 1, arguments.length);
|
621
592
|
if (typeof pathString === 'number') {
|
622
593
|
pathString = String(pathString);
|
623
594
|
}
|
624
595
|
return new Reference(this.database, database.child(this._delegate, pathString));
|
625
|
-
}
|
596
|
+
}
|
626
597
|
/** @returns {?Reference} */
|
627
|
-
|
598
|
+
getParent() {
|
628
599
|
util.validateArgCount('Reference.parent', 0, 0, arguments.length);
|
629
|
-
|
600
|
+
const parent = this._delegate.parent;
|
630
601
|
return parent ? new Reference(this.database, parent) : null;
|
631
|
-
}
|
602
|
+
}
|
632
603
|
/** @returns {!Reference} */
|
633
|
-
|
604
|
+
getRoot() {
|
634
605
|
util.validateArgCount('Reference.root', 0, 0, arguments.length);
|
635
606
|
return new Reference(this.database, this._delegate.root);
|
636
|
-
}
|
637
|
-
|
607
|
+
}
|
608
|
+
set(newVal, onComplete) {
|
638
609
|
util.validateArgCount('Reference.set', 1, 2, arguments.length);
|
639
610
|
util.validateCallback('Reference.set', 'onComplete', onComplete, true);
|
640
|
-
|
611
|
+
const result = database.set(this._delegate, newVal);
|
641
612
|
if (onComplete) {
|
642
|
-
result.then(
|
613
|
+
result.then(() => onComplete(null), error => onComplete(error));
|
643
614
|
}
|
644
615
|
return result;
|
645
|
-
}
|
646
|
-
|
616
|
+
}
|
617
|
+
update(values, onComplete) {
|
647
618
|
util.validateArgCount('Reference.update', 1, 2, arguments.length);
|
648
619
|
if (Array.isArray(values)) {
|
649
|
-
|
650
|
-
for (
|
620
|
+
const newObjectToMerge = {};
|
621
|
+
for (let i = 0; i < values.length; ++i) {
|
651
622
|
newObjectToMerge['' + i] = values[i];
|
652
623
|
}
|
653
624
|
values = newObjectToMerge;
|
@@ -658,98 +629,79 @@ var Reference = /** @class */ (function (_super) {
|
|
658
629
|
}
|
659
630
|
database._validateWritablePath('Reference.update', this._delegate._path);
|
660
631
|
util.validateCallback('Reference.update', 'onComplete', onComplete, true);
|
661
|
-
|
632
|
+
const result = database.update(this._delegate, values);
|
662
633
|
if (onComplete) {
|
663
|
-
result.then(
|
634
|
+
result.then(() => onComplete(null), error => onComplete(error));
|
664
635
|
}
|
665
636
|
return result;
|
666
|
-
}
|
667
|
-
|
637
|
+
}
|
638
|
+
setWithPriority(newVal, newPriority, onComplete) {
|
668
639
|
util.validateArgCount('Reference.setWithPriority', 2, 3, arguments.length);
|
669
640
|
util.validateCallback('Reference.setWithPriority', 'onComplete', onComplete, true);
|
670
|
-
|
641
|
+
const result = database.setWithPriority(this._delegate, newVal, newPriority);
|
671
642
|
if (onComplete) {
|
672
|
-
result.then(
|
643
|
+
result.then(() => onComplete(null), error => onComplete(error));
|
673
644
|
}
|
674
645
|
return result;
|
675
|
-
}
|
676
|
-
|
646
|
+
}
|
647
|
+
remove(onComplete) {
|
677
648
|
util.validateArgCount('Reference.remove', 0, 1, arguments.length);
|
678
649
|
util.validateCallback('Reference.remove', 'onComplete', onComplete, true);
|
679
|
-
|
650
|
+
const result = database.remove(this._delegate);
|
680
651
|
if (onComplete) {
|
681
|
-
result.then(
|
652
|
+
result.then(() => onComplete(null), error => onComplete(error));
|
682
653
|
}
|
683
654
|
return result;
|
684
|
-
}
|
685
|
-
|
686
|
-
var _this = this;
|
655
|
+
}
|
656
|
+
transaction(transactionUpdate, onComplete, applyLocally) {
|
687
657
|
util.validateArgCount('Reference.transaction', 1, 3, arguments.length);
|
688
658
|
util.validateCallback('Reference.transaction', 'transactionUpdate', transactionUpdate, false);
|
689
659
|
util.validateCallback('Reference.transaction', 'onComplete', onComplete, true);
|
690
660
|
validateBoolean('Reference.transaction', 'applyLocally', applyLocally, true);
|
691
|
-
|
692
|
-
applyLocally
|
693
|
-
}).then(
|
694
|
-
return new TransactionResult(transactionResult.committed, new DataSnapshot(_this.database, transactionResult.snapshot));
|
695
|
-
});
|
661
|
+
const result = database.runTransaction(this._delegate, transactionUpdate, {
|
662
|
+
applyLocally
|
663
|
+
}).then(transactionResult => new TransactionResult(transactionResult.committed, new DataSnapshot(this.database, transactionResult.snapshot)));
|
696
664
|
if (onComplete) {
|
697
|
-
result.then(
|
698
|
-
return onComplete(null, transactionResult.committed, transactionResult.snapshot);
|
699
|
-
}, function (error) { return onComplete(error, false, null); });
|
665
|
+
result.then(transactionResult => onComplete(null, transactionResult.committed, transactionResult.snapshot), error => onComplete(error, false, null));
|
700
666
|
}
|
701
667
|
return result;
|
702
|
-
}
|
703
|
-
|
668
|
+
}
|
669
|
+
setPriority(priority, onComplete) {
|
704
670
|
util.validateArgCount('Reference.setPriority', 1, 2, arguments.length);
|
705
671
|
util.validateCallback('Reference.setPriority', 'onComplete', onComplete, true);
|
706
|
-
|
672
|
+
const result = database.setPriority(this._delegate, priority);
|
707
673
|
if (onComplete) {
|
708
|
-
result.then(
|
674
|
+
result.then(() => onComplete(null), error => onComplete(error));
|
709
675
|
}
|
710
676
|
return result;
|
711
|
-
}
|
712
|
-
|
713
|
-
var _this = this;
|
677
|
+
}
|
678
|
+
push(value, onComplete) {
|
714
679
|
util.validateArgCount('Reference.push', 0, 2, arguments.length);
|
715
680
|
util.validateCallback('Reference.push', 'onComplete', onComplete, true);
|
716
|
-
|
717
|
-
|
681
|
+
const expPromise = database.push(this._delegate, value);
|
682
|
+
const promise = expPromise.then(expRef => new Reference(this.database, expRef));
|
718
683
|
if (onComplete) {
|
719
|
-
promise.then(
|
684
|
+
promise.then(() => onComplete(null), error => onComplete(error));
|
720
685
|
}
|
721
|
-
|
686
|
+
const result = new Reference(this.database, expPromise);
|
722
687
|
result.then = promise.then.bind(promise);
|
723
688
|
result.catch = promise.catch.bind(promise, undefined);
|
724
689
|
return result;
|
725
|
-
}
|
726
|
-
|
690
|
+
}
|
691
|
+
onDisconnect() {
|
727
692
|
database._validateWritablePath('Reference.onDisconnect', this._delegate._path);
|
728
693
|
return new OnDisconnect(new database.OnDisconnect(this._delegate._repo, this._delegate._path));
|
729
|
-
}
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
},
|
741
|
-
enumerable: false,
|
742
|
-
configurable: true
|
743
|
-
});
|
744
|
-
Object.defineProperty(Reference.prototype, "root", {
|
745
|
-
get: function () {
|
746
|
-
return this.getRoot();
|
747
|
-
},
|
748
|
-
enumerable: false,
|
749
|
-
configurable: true
|
750
|
-
});
|
751
|
-
return Reference;
|
752
|
-
}(Query));
|
694
|
+
}
|
695
|
+
get key() {
|
696
|
+
return this.getKey();
|
697
|
+
}
|
698
|
+
get parent() {
|
699
|
+
return this.getParent();
|
700
|
+
}
|
701
|
+
get root() {
|
702
|
+
return this.getRoot();
|
703
|
+
}
|
704
|
+
}
|
753
705
|
|
754
706
|
/**
|
755
707
|
* @license
|
@@ -770,16 +722,15 @@ var Reference = /** @class */ (function (_super) {
|
|
770
722
|
/**
|
771
723
|
* Class representing a firebase database.
|
772
724
|
*/
|
773
|
-
|
725
|
+
class Database {
|
774
726
|
/**
|
775
727
|
* The constructor should not be called by users of our public API.
|
776
728
|
*/
|
777
|
-
|
778
|
-
var _this = this;
|
729
|
+
constructor(_delegate, app) {
|
779
730
|
this._delegate = _delegate;
|
780
731
|
this.app = app;
|
781
732
|
this.INTERNAL = {
|
782
|
-
delete:
|
733
|
+
delete: () => this._delegate._delete(),
|
783
734
|
forceWebSockets: database.forceWebSockets,
|
784
735
|
forceLongPolling: database.forceLongPolling
|
785
736
|
};
|
@@ -793,48 +744,46 @@ var Database = /** @class */ (function () {
|
|
793
744
|
* @param port - the emulator port (ex: 8080)
|
794
745
|
* @param options.mockUserToken - the mock auth token to use for unit testing Security Rules
|
795
746
|
*/
|
796
|
-
|
797
|
-
if (options === void 0) { options = {}; }
|
747
|
+
useEmulator(host, port, options = {}) {
|
798
748
|
database.connectDatabaseEmulator(this._delegate, host, port, options);
|
799
|
-
}
|
800
|
-
|
749
|
+
}
|
750
|
+
ref(path) {
|
801
751
|
util.validateArgCount('database.ref', 0, 1, arguments.length);
|
802
752
|
if (path instanceof Reference) {
|
803
|
-
|
753
|
+
const childRef = database.refFromURL(this._delegate, path.toString());
|
804
754
|
return new Reference(this, childRef);
|
805
755
|
}
|
806
756
|
else {
|
807
|
-
|
757
|
+
const childRef = database.ref(this._delegate, path);
|
808
758
|
return new Reference(this, childRef);
|
809
759
|
}
|
810
|
-
}
|
760
|
+
}
|
811
761
|
/**
|
812
762
|
* Returns a reference to the root or the path specified in url.
|
813
763
|
* We throw a exception if the url is not in the same domain as the
|
814
764
|
* current repo.
|
815
765
|
* @returns Firebase reference.
|
816
766
|
*/
|
817
|
-
|
818
|
-
|
767
|
+
refFromURL(url) {
|
768
|
+
const apiName = 'database.refFromURL';
|
819
769
|
util.validateArgCount(apiName, 1, 1, arguments.length);
|
820
|
-
|
770
|
+
const childRef = database.refFromURL(this._delegate, url);
|
821
771
|
return new Reference(this, childRef);
|
822
|
-
}
|
772
|
+
}
|
823
773
|
// Make individual repo go offline.
|
824
|
-
|
774
|
+
goOffline() {
|
825
775
|
util.validateArgCount('database.goOffline', 0, 0, arguments.length);
|
826
776
|
return database.goOffline(this._delegate);
|
827
|
-
}
|
828
|
-
|
777
|
+
}
|
778
|
+
goOnline() {
|
829
779
|
util.validateArgCount('database.goOnline', 0, 0, arguments.length);
|
830
780
|
return database.goOnline(this._delegate);
|
831
|
-
}
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
}());
|
781
|
+
}
|
782
|
+
}
|
783
|
+
Database.ServerValue = {
|
784
|
+
TIMESTAMP: database.serverTimestamp(),
|
785
|
+
increment: (delta) => database.increment(delta)
|
786
|
+
};
|
838
787
|
|
839
788
|
/**
|
840
789
|
* Used by console to create a database based on the app,
|
@@ -845,24 +794,23 @@ var Database = /** @class */ (function () {
|
|
845
794
|
* @param version - custom version e.g. firebase-admin version
|
846
795
|
* @param customAuthImpl - custom auth implementation
|
847
796
|
*/
|
848
|
-
function initStandalone(
|
849
|
-
var app = _a.app, url = _a.url, version = _a.version, customAuthImpl = _a.customAuthImpl, customAppCheckImpl = _a.customAppCheckImpl, namespace = _a.namespace, _b = _a.nodeAdmin, nodeAdmin = _b === void 0 ? false : _b;
|
797
|
+
function initStandalone({ app, url, version, customAuthImpl, customAppCheckImpl, namespace, nodeAdmin = false }) {
|
850
798
|
database._setSDKVersion(version);
|
851
|
-
|
799
|
+
const container = new component.ComponentContainer('database-standalone');
|
852
800
|
/**
|
853
801
|
* ComponentContainer('database-standalone') is just a placeholder that doesn't perform
|
854
802
|
* any actual function.
|
855
803
|
*/
|
856
|
-
|
857
|
-
authProvider.setComponent(new component.Component('auth-internal',
|
858
|
-
|
804
|
+
const authProvider = new component.Provider('auth-internal', container);
|
805
|
+
authProvider.setComponent(new component.Component('auth-internal', () => customAuthImpl, "PRIVATE" /* ComponentType.PRIVATE */));
|
806
|
+
let appCheckProvider = undefined;
|
859
807
|
if (customAppCheckImpl) {
|
860
808
|
appCheckProvider = new component.Provider('app-check-internal', container);
|
861
|
-
appCheckProvider.setComponent(new component.Component('app-check-internal',
|
809
|
+
appCheckProvider.setComponent(new component.Component('app-check-internal', () => customAppCheckImpl, "PRIVATE" /* ComponentType.PRIVATE */));
|
862
810
|
}
|
863
811
|
return {
|
864
812
|
instance: new Database(database._repoManagerDatabaseFromApp(app, authProvider, appCheckProvider, url, nodeAdmin), app),
|
865
|
-
namespace
|
813
|
+
namespace
|
866
814
|
};
|
867
815
|
}
|
868
816
|
|
@@ -887,15 +835,14 @@ var INTERNAL = /*#__PURE__*/Object.freeze({
|
|
887
835
|
* See the License for the specific language governing permissions and
|
888
836
|
* limitations under the License.
|
889
837
|
*/
|
890
|
-
|
838
|
+
const ServerValue = Database.ServerValue;
|
891
839
|
function registerDatabase(instance) {
|
892
840
|
// Register the Database Service with the 'firebase' namespace.
|
893
|
-
instance.INTERNAL.registerComponent(new component.Component('database-compat',
|
894
|
-
var url = _a.instanceIdentifier;
|
841
|
+
instance.INTERNAL.registerComponent(new component.Component('database-compat', (container, { instanceIdentifier: url }) => {
|
895
842
|
/* Dependencies */
|
896
843
|
// getImmediate for FirebaseApp will always succeed
|
897
|
-
|
898
|
-
|
844
|
+
const app = container.getProvider('app-compat').getImmediate();
|
845
|
+
const databaseExp = container
|
899
846
|
.getProvider('database')
|
900
847
|
.getImmediate({ identifier: url });
|
901
848
|
return new Database(databaseExp, app);
|
@@ -903,13 +850,13 @@ function registerDatabase(instance) {
|
|
903
850
|
.setServiceProps(
|
904
851
|
// firebase.database namespace properties
|
905
852
|
{
|
906
|
-
Reference
|
907
|
-
Query
|
908
|
-
Database
|
909
|
-
DataSnapshot
|
853
|
+
Reference,
|
854
|
+
Query,
|
855
|
+
Database,
|
856
|
+
DataSnapshot,
|
910
857
|
enableLogging: database.enableLogging,
|
911
|
-
INTERNAL
|
912
|
-
ServerValue
|
858
|
+
INTERNAL,
|
859
|
+
ServerValue
|
913
860
|
})
|
914
861
|
.setMultipleInstances(true));
|
915
862
|
instance.registerVersion(name, version, 'node');
|