@@ -123,30 +123,27 @@ export class DataSnapshot implements Compat<ExpDataSnapshot> {
123
123
/**
124
124
* Returns a DataSnapshot of the specified child node's contents.
125
125
*
126
- * @param childPathString Path to a child.
126
+ * @param path Path to a child.
127
127
* @return DataSnapshot for child node.
128
128
*/
129
- child ( childPathString : string ) : DataSnapshot {
129
+ child ( path : string ) : DataSnapshot {
130
130
validateArgCount ( 'DataSnapshot.child' , 0 , 1 , arguments . length ) ;
131
131
// Ensure the childPath is a string (can be a number)
132
- childPathString = String ( childPathString ) ;
133
- validatePathString ( 'DataSnapshot.child' , 1 , childPathString , false ) ;
134
- return new DataSnapshot (
135
- this . _database ,
136
- this . _delegate . child ( childPathString )
137
- ) ;
132
+ path = String ( path ) ;
133
+ validatePathString ( 'DataSnapshot.child' , 'path' , path , false ) ;
134
+ return new DataSnapshot ( this . _database , this . _delegate . child ( path ) ) ;
138
135
}
139
136
140
137
/**
141
138
* Returns whether the snapshot contains a child at the specified path.
142
139
*
143
- * @param childPathString Path to a child.
140
+ * @param path Path to a child.
144
141
* @return Whether the child exists.
145
142
*/
146
- hasChild ( childPathString : string ) : boolean {
143
+ hasChild ( path : string ) : boolean {
147
144
validateArgCount ( 'DataSnapshot.hasChild' , 1 , 1 , arguments . length ) ;
148
- validatePathString ( 'DataSnapshot.hasChild' , 1 , childPathString , false ) ;
149
- return this . _delegate . hasChild ( childPathString ) ;
145
+ validatePathString ( 'DataSnapshot.hasChild' , 'path' , path , false ) ;
146
+ return this . _delegate . hasChild ( path ) ;
150
147
}
151
148
152
149
/**
@@ -169,7 +166,7 @@ export class DataSnapshot implements Compat<ExpDataSnapshot> {
169
166
*/
170
167
forEach ( action : ( snapshot : DataSnapshot ) => boolean | void ) : boolean {
171
168
validateArgCount ( 'DataSnapshot.forEach' , 1 , 1 , arguments . length ) ;
172
- validateCallback ( 'DataSnapshot.forEach' , 1 , action , false ) ;
169
+ validateCallback ( 'DataSnapshot.forEach' , 'action' , action , false ) ;
173
170
return this . _delegate . forEach ( expDataSnapshot =>
174
171
action ( new DataSnapshot ( this . _database , expDataSnapshot ) )
175
172
) ;
@@ -231,7 +228,7 @@ export class Query implements Compat<QueryImpl> {
231
228
context ?: object | null
232
229
) : SnapshotCallback {
233
230
validateArgCount ( 'Query.on' , 2 , 4 , arguments . length ) ;
234
- validateCallback ( 'Query.on' , 2 , callback , false ) ;
231
+ validateCallback ( 'Query.on' , 'callback' , callback , false ) ;
235
232
236
233
const ret = Query . getCancelAndContextArgs_ (
237
234
'Query.on' ,
@@ -267,7 +264,7 @@ export class Query implements Compat<QueryImpl> {
267
264
return callback ;
268
265
default :
269
266
throw new Error (
270
- errorPrefix ( 'Query.on' , 1 , false ) +
267
+ errorPrefix ( 'Query.on' , 'eventType' ) +
271
268
'must be a valid event type = "value", "child_added", "child_removed", ' +
272
269
'"child_changed", or "child_moved".'
273
270
) ;
@@ -280,9 +277,9 @@ export class Query implements Compat<QueryImpl> {
280
277
context ?: object | null
281
278
) : void {
282
279
validateArgCount ( 'Query.off' , 0 , 3 , arguments . length ) ;
283
- validateEventType ( 'Query.off' , 1 , eventType , true ) ;
284
- validateCallback ( 'Query.off' , 2 , callback , true ) ;
285
- validateContextObject ( 'Query.off' , 3 , context , true ) ;
280
+ validateEventType ( 'Query.off' , eventType , true ) ;
281
+ validateCallback ( 'Query.off' , 'callback' , callback , true ) ;
282
+ validateContextObject ( 'Query.off' , 'context' , context , true ) ;
286
283
if ( callback ) {
287
284
const valueCallback : UserCallback = ( ) => { } ;
288
285
valueCallback . userCallback = callback ;
@@ -307,12 +304,12 @@ export class Query implements Compat<QueryImpl> {
307
304
*/
308
305
once (
309
306
eventType : string ,
310
- userCallback ?: SnapshotCallback ,
307
+ callback ?: SnapshotCallback ,
311
308
failureCallbackOrContext ?: ( ( a : Error ) => void ) | object | null ,
312
309
context ?: object | null
313
310
) : Promise < DataSnapshot > {
314
311
validateArgCount ( 'Query.once' , 1 , 4 , arguments . length ) ;
315
- validateCallback ( 'Query.once' , 2 , userCallback , true ) ;
312
+ validateCallback ( 'Query.once' , 'callback' , callback , true ) ;
316
313
317
314
const ret = Query . getCancelAndContextArgs_ (
318
315
'Query.on' ,
@@ -322,12 +319,12 @@ export class Query implements Compat<QueryImpl> {
322
319
const deferred = new Deferred < DataSnapshot > ( ) ;
323
320
const valueCallback : UserCallback = ( expSnapshot , previousChildName ?) => {
324
321
const result = new DataSnapshot ( this . database , expSnapshot ) ;
325
- if ( userCallback ) {
326
- userCallback . call ( ret . context , result , previousChildName ) ;
322
+ if ( callback ) {
323
+ callback . call ( ret . context , result , previousChildName ) ;
327
324
}
328
325
deferred . resolve ( result ) ;
329
326
} ;
330
- valueCallback . userCallback = userCallback ;
327
+ valueCallback . userCallback = callback ;
331
328
valueCallback . context = ret . context ;
332
329
const cancelCallback = ( error : Error ) => {
333
330
if ( ret . cancel ) {
@@ -364,7 +361,7 @@ export class Query implements Compat<QueryImpl> {
364
361
break ;
365
362
default :
366
363
throw new Error (
367
- errorPrefix ( 'Query.once' , 1 , false ) +
364
+ errorPrefix ( 'Query.once' , 'eventType' ) +
368
365
'must be a valid event type = "value", "child_added", "child_removed", ' +
369
366
'"child_changed", or "child_moved".'
370
367
) ;
@@ -519,10 +516,10 @@ export class Query implements Compat<QueryImpl> {
519
516
} = { cancel : undefined , context : undefined } ;
520
517
if ( cancelOrContext && context ) {
521
518
ret . cancel = cancelOrContext as ( a : Error ) => void ;
522
- validateCallback ( fnName , 3 , ret . cancel , true ) ;
519
+ validateCallback ( fnName , 'cancel' , ret . cancel , true ) ;
523
520
524
521
ret . context = context ;
525
- validateContextObject ( fnName , 4 , ret . context , true ) ;
522
+ validateContextObject ( fnName , 'context' , ret . context , true ) ;
526
523
} else if ( cancelOrContext ) {
527
524
// we have either a cancel callback or a context.
528
525
if ( typeof cancelOrContext === 'object' && cancelOrContext !== null ) {
@@ -532,7 +529,7 @@ export class Query implements Compat<QueryImpl> {
532
529
ret . cancel = cancelOrContext as ( a : Error ) => void ;
533
530
} else {
534
531
throw new Error (
535
- errorPrefix ( fnName , 3 , true ) +
532
+ errorPrefix ( fnName , 'cancelOrContext' ) +
536
533
' must either be a cancel callback or a context object.'
537
534
) ;
538
535
}
@@ -598,7 +595,7 @@ export class Reference extends Query implements Compat<ReferenceImpl> {
598
595
onComplete ?: ( error : Error | null ) => void
599
596
) : Promise < unknown > {
600
597
validateArgCount ( 'Reference.set' , 1 , 2 , arguments . length ) ;
601
- validateCallback ( 'Reference.set' , 2 , onComplete , true ) ;
598
+ validateCallback ( 'Reference.set' , 'onComplete' , onComplete , true ) ;
602
599
const result = set ( this . _delegate , newVal ) ;
603
600
if ( onComplete ) {
604
601
result . then (
@@ -610,17 +607,17 @@ export class Reference extends Query implements Compat<ReferenceImpl> {
610
607
}
611
608
612
609
update (
613
- objectToMerge : object ,
610
+ values : object ,
614
611
onComplete ?: ( a : Error | null ) => void
615
612
) : Promise < unknown > {
616
613
validateArgCount ( 'Reference.update' , 1 , 2 , arguments . length ) ;
617
614
618
- if ( Array . isArray ( objectToMerge ) ) {
615
+ if ( Array . isArray ( values ) ) {
619
616
const newObjectToMerge : { [ k : string ] : unknown } = { } ;
620
- for ( let i = 0 ; i < objectToMerge . length ; ++ i ) {
621
- newObjectToMerge [ '' + i ] = objectToMerge [ i ] ;
617
+ for ( let i = 0 ; i < values . length ; ++ i ) {
618
+ newObjectToMerge [ '' + i ] = values [ i ] ;
622
619
}
623
- objectToMerge = newObjectToMerge ;
620
+ values = newObjectToMerge ;
624
621
warn (
625
622
'Passing an Array to Firebase.update() is deprecated. ' +
626
623
'Use set() if you want to overwrite the existing data, or ' +
@@ -629,9 +626,9 @@ export class Reference extends Query implements Compat<ReferenceImpl> {
629
626
) ;
630
627
}
631
628
validateWritablePath ( 'Reference.update' , this . _delegate . _path ) ;
632
- validateCallback ( 'Reference.update' , 2 , onComplete , true ) ;
629
+ validateCallback ( 'Reference.update' , 'onComplete' , onComplete , true ) ;
633
630
634
- const result = update ( this . _delegate , objectToMerge ) ;
631
+ const result = update ( this . _delegate , values ) ;
635
632
if ( onComplete ) {
636
633
result . then (
637
634
( ) => onComplete ( null ) ,
@@ -647,7 +644,12 @@ export class Reference extends Query implements Compat<ReferenceImpl> {
647
644
onComplete ?: ( a : Error | null ) => void
648
645
) : Promise < unknown > {
649
646
validateArgCount ( 'Reference.setWithPriority' , 2 , 3 , arguments . length ) ;
650
- validateCallback ( 'Reference.setWithPriority' , 3 , onComplete , true ) ;
647
+ validateCallback (
648
+ 'Reference.setWithPriority' ,
649
+ 'onComplete' ,
650
+ onComplete ,
651
+ true
652
+ ) ;
651
653
652
654
const result = setWithPriority ( this . _delegate , newVal , newPriority ) ;
653
655
if ( onComplete ) {
@@ -661,7 +663,7 @@ export class Reference extends Query implements Compat<ReferenceImpl> {
661
663
662
664
remove ( onComplete ?: ( a : Error | null ) => void ) : Promise < unknown > {
663
665
validateArgCount ( 'Reference.remove' , 0 , 1 , arguments . length ) ;
664
- validateCallback ( 'Reference.remove' , 1 , onComplete , true ) ;
666
+ validateCallback ( 'Reference.remove' , 'onComplete' , onComplete , true ) ;
665
667
666
668
const result = remove ( this . _delegate ) ;
667
669
if ( onComplete ) {
@@ -683,9 +685,19 @@ export class Reference extends Query implements Compat<ReferenceImpl> {
683
685
applyLocally ?: boolean
684
686
) : Promise < TransactionResult > {
685
687
validateArgCount ( 'Reference.transaction' , 1 , 3 , arguments . length ) ;
686
- validateCallback ( 'Reference.transaction' , 1 , transactionUpdate , false ) ;
687
- validateCallback ( 'Reference.transaction' , 2 , onComplete , true ) ;
688
- validateBoolean ( 'Reference.transaction' , 3 , applyLocally , true ) ;
688
+ validateCallback (
689
+ 'Reference.transaction' ,
690
+ 'transactionUpdate' ,
691
+ transactionUpdate ,
692
+ false
693
+ ) ;
694
+ validateCallback ( 'Reference.transaction' , 'onComplete' , onComplete , true ) ;
695
+ validateBoolean (
696
+ 'Reference.transaction' ,
697
+ 'applyLocally' ,
698
+ applyLocally ,
699
+ true
700
+ ) ;
689
701
690
702
const result = runTransaction ( this . _delegate , transactionUpdate , {
691
703
applyLocally
@@ -715,7 +727,7 @@ export class Reference extends Query implements Compat<ReferenceImpl> {
715
727
onComplete ?: ( a : Error | null ) => void
716
728
) : Promise < unknown > {
717
729
validateArgCount ( 'Reference.setPriority' , 1 , 2 , arguments . length ) ;
718
- validateCallback ( 'Reference.setPriority' , 2 , onComplete , true ) ;
730
+ validateCallback ( 'Reference.setPriority' , 'onComplete' , onComplete , true ) ;
719
731
720
732
const result = setPriority ( this . _delegate , priority ) ;
721
733
if ( onComplete ) {
@@ -729,7 +741,7 @@ export class Reference extends Query implements Compat<ReferenceImpl> {
729
741
730
742
push ( value ?: unknown , onComplete ?: ( a : Error | null ) => void ) : Reference {
731
743
validateArgCount ( 'Reference.push' , 0 , 2 , arguments . length ) ;
732
- validateCallback ( 'Reference.push' , 2 , onComplete , true ) ;
744
+ validateCallback ( 'Reference.push' , 'onComplete' , onComplete , true ) ;
733
745
734
746
const expPromise = push ( this . _delegate , value ) ;
735
747
const promise = expPromise . then (
0 commit comments