forked from firebase/firebase-bower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase-database-externs.js
1682 lines (1619 loc) · 62 KB
/
firebase-database-externs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @license Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Firebase Database API.
* @externs
*/
/**
* Gets the {@link firebase.database.Database `Database`} service for the
* default app or a given app.
*
* `firebase.database()` can be called with no arguments to access the default
* app's {@link firebase.database.Database `Database`} service or as
* `firebase.database(app)` to access the
* {@link firebase.database.Database `Database`} service associated with a
* specific app.
*
* `firebase.database` is also a namespace that can be used to access global
* constants and methods associated with the `Database` service.
*
* @example
* // Get the Database service for the default app
* var defaultDatabase = firebase.database();
*
* @example
* // Get the Database service for a specific app
* var otherDatabase = firebase.database(app);
*
* @namespace
* @param {!firebase.app.App=} app Optional app whose Database service to
* return. If not provided, the default Database service will be returned.
* @return {!firebase.database.Database} The default Database service if no app
* is provided or the Database service associated with the provided app.
*/
firebase.database = function(app) {};
/**
* Gets the {@link firebase.database.Database `Database`} service for the
* current app.
*
* @example
* var database = app.database();
* // The above is shorthand for:
* // var database = firebase.database(app);
*
* @return {!firebase.database.Database}
*/
firebase.app.App.prototype.database = function() {};
/**
* The Firebase Database service interface.
*
* Do not call this constructor directly. Instead, use
* {@link firebase.database `firebase.database()`}.
*
* See
* {@link
* https://firebase.google.com/docs/database/web/start/
* Installation & Setup in JavaScript}
* for a full guide on how to use the Firebase Database service.
*
* @interface
*/
firebase.database.Database = function() {};
/**
* Logs debugging information to the console.
*
* @example
* // Enable logging
* firebase.database.enableLogging(true);
*
* @example
* // Disable logging
* firebase.database.enableLogging(false);
*
* @example
* // Enable logging across page refreshes
* firebase.database.enableLogging(true, true);
*
* @example
* // Provide custom logger which prefixes log statements with "[FIREBASE]"
* firebase.database.enableLogging(function(message) {
* console.log("[FIREBASE]", message);
* });
*
* @param {(boolean|function(string))=} logger Enables logging if `true`;
* disables logging if `false`. You can also provide a custom logger function
* to control how things get logged.
* @param {boolean=} persistent Remembers the logging state between page
* refreshes if `true`.
*/
firebase.database.enableLogging = function(logger, persistent) {};
/**
* @namespace
*/
firebase.database.ServerValue = {};
/**
* A placeholder value for auto-populating the current timestamp (time
* since the Unix epoch, in milliseconds) as determined by the Firebase
* servers.
*
* @example
* var sessionsRef = firebase.database().ref("sessions");
* sessionsRef.push({
* startedAt: firebase.database.ServerValue.TIMESTAMP
* });
*
* @const {!Object}
*/
firebase.database.ServerValue.TIMESTAMP;
/**
* The {@link firebase.app.App app} associated with the `Database` service
* instance.
*
* @example
* var app = database.app;
*
* @type {!firebase.app.App}
*/
firebase.database.Database.prototype.app;
/**
* Returns a `Reference` representing the location in the Database
* corresponding to the provided path. If no path is provided, the `Reference`
* will point to the root of the Database.
*
* @example
* // Get a reference to the root of the Database
* var rootRef = firebase.database().ref();
*
* @example
* // Get a reference to the /users/ada node
* var adaRef = firebase.database().ref("users/ada");
* // The above is shorthand for the following operations:
* //var rootRef = firebase.database().ref();
* //var adaRef = rootRef.child("users/ada");
*
* @param {string=} path Optional path representing the location the returned
* `Reference` will point. If not provided, the returned `Reference` will
* point to the root of the Database.
* @return {!firebase.database.Reference} If a path is provided, a `Reference`
* pointing to the provided path. Otherwise, a `Reference` pointing to the
* root of the Database.
*/
firebase.database.Database.prototype.ref = function(path) {};
/**
* Returns a `Reference` representing the location in the Database
* corresponding to the provided Firebase URL.
*
* An exception is thrown if the URL is not a valid Firebase Database URL or it
* has a different domain than the current `Database` instance.
*
* Note that all query parameters (`orderBy`, `limitToLast`, etc.) are ignored
* and are not applied to the returned `Reference`.
*
* @example
* // Get a reference to the root of the Database
* var rootRef = firebase.database().ref("https://<DATABASE_NAME>.firebaseio.com");
*
* @example
* // Get a reference to the /users/ada node
* var adaRef = firebase.database().ref("https://<DATABASE_NAME>.firebaseio.com/users/ada");
*
* @param {string} url The Firebase URL at which the returned `Reference` will
* point.
* @return {!firebase.database.Reference} A `Reference` pointing to the provided
* Firebase URL.
*/
firebase.database.Database.prototype.refFromURL = function(url) {};
/**
* Disconnects from the server (all Database operations will be completed
* offline).
*
* The client automatically maintains a persistent connection to the Database
* server, which will remain active indefinitely and reconnect when
* disconnected. However, the `goOffline()` and `goOnline()` methods may be used
* to control the client connection in cases where a persistent connection is
* undesirable.
*
* While offline, the client will no longer receive data updates from the
* Database. However, all Database operations performed locally will continue to
* immediately fire events, allowing your application to continue behaving
* normally. Additionally, each operation performed locally will automatically
* be queued and retried upon reconnection to the Database server.
*
* To reconnect to the Database and begin receiving remote events, see
* `goOnline()`.
*
* @example
* firebase.database().goOffline();
*/
firebase.database.Database.prototype.goOffline = function() {};
/**
* Reconnects to the server and synchronizes the offline Database state
* with the server state.
*
* This method should be used after disabling the active connection with
* `goOffline()`. Once reconnected, the client will transmit the proper data
* and fire the appropriate events so that your client "catches up"
* automatically.
*
* @example
* firebase.database().goOnline();
*/
firebase.database.Database.prototype.goOnline = function() {};
/**
* A `Reference` represents a specific location in your Database and can be used
* for reading or writing data to that Database location.
*
* You can reference the root or child location in your Database by calling
* `firebase.database().ref()` or `firebase.database().ref("child/path")`.
*
* Writing is done with the `set()` method and reading can be done with the
* `on()` method. See
* {@link
* https://firebase.google.com/docs/database/web/read-and-write
* Read and Write Data on the Web}
*
* @interface
* @extends {firebase.database.Query}
*/
firebase.database.Reference = function() {};
/**
* The last part of the `Reference`'s path.
*
* For example, `"ada"` is the key for
* `https://<DATABASE_NAME>.firebaseio.com/users/ada`.
*
* The key of a root `Reference` is `null`.
*
* @example
* // The key of a root reference is null
* var rootRef = firebase.database().ref();
* var key = rootRef.key; // key === null
*
* @example
* // The key of any non-root reference is the last token in the path
* var adaRef = firebase.database().ref("users/ada");
* var key = adaRef.key; // key === "ada"
* key = adaRef.child("name/last").key; // key === "last"
*
* @type {string|null}
*/
firebase.database.Reference.prototype.key;
/**
* Gets a `Reference` for the location at the specified relative path.
*
* The relative path can either be a simple child name (for example, "ada") or
* a deeper slash-separated path (for example, "ada/name/first").
*
* @example
* var usersRef = firebase.database().ref('users');
* var adaRef = usersRef.child('ada');
* var adaFirstNameRef = adaRef.child('name/first');
* var path = adaFirstNameRef.toString();
* // path is now 'https://sample-app.firebaseio.com/users/ada/name/first'
*
* @param {string} path A relative path from this location to the desired child
* location.
* @return {!firebase.database.Reference} The specified child location.
*/
firebase.database.Reference.prototype.child = function(path) {};
/**
* The parent location of a `Reference`.
*
* The parent of a root `Reference` is `null`.
*
* @example
* // The parent of a root reference is null
* var rootRef = firebase.database().ref();
* parent = rootRef.parent; // parent === null
*
* @example
* // The parent of any non-root reference is the parent location
* var usersRef = firebase.database().ref("users");
* var adaRef = firebase.database().ref("users/ada");
* // usersRef and adaRef.parent represent the same location
*
* @type {?firebase.database.Reference}
*/
firebase.database.Reference.prototype.parent;
/**
* The root `Reference` of the Database.
*
* @example
* // The root of a root reference is itself
* var rootRef = firebase.database().ref();
* // rootRef and rootRef.root represent the same location
*
* @example
* // The root of any non-root reference is the root location
* var adaRef = firebase.database().ref("users/ada");
* // rootRef and adaRef.root represent the same location
*
* @type {!firebase.database.Reference}
*/
firebase.database.Reference.prototype.root;
/**
* @type {string}
*/
firebase.database.Reference.prototype.path;
/**
* Writes data to this Database location.
*
* This will overwrite any data at this location and all child locations.
*
* The effect of the write will be visible immediately, and the corresponding
* events ("value", "child_added", etc.) will be triggered. Synchronization of
* the data to the Firebase servers will also be started, and the returned
* Promise will resolve when complete. If provided, the `onComplete` callback
* will be called asynchronously after synchronization has finished.
*
* Passing `null` for the new value is equivalent to calling `remove()`; namely,
* all data at this location and all child locations will be deleted.
*
* `set()` will remove any priority stored at this location, so if priority is
* meant to be preserved, you need to use `setWithPriority()` instead.
*
* Note that modifying data with `set()` will cancel any pending transactions
* at that location, so extreme care should be taken if mixing `set()` and
* `transaction()` to modify the same data.
*
* A single `set()` will generate a single "value" event at the location where
* the `set()` was performed.
*
* @example
* var adaNameRef = firebase.database().ref('users/ada/name');
* adaNameRef.child('first').set('Ada');
* adaNameRef.child('last').set('Lovelace');
* // We've written 'Ada' to the Database location storing Ada's first name,
* // and 'Lovelace' to the location storing her last name.
*
* @example
* adaNameRef.set({ first: 'Ada', last: 'Lovelace' });
* // Exact same effect as the previous example, except we've written
* // Ada's first and last name simultaneously.
*
* @example
* adaNameRef.set({ first: 'Ada', last: 'Lovelace' })
* .then(function() {
* console.log('Synchronization succeeded');
* })
* .catch(function(error) {
* console.log('Synchronization failed');
* });
* // Same as the previous example, except we will also log a message
* // when the data has finished synchronizing.
*
* @param {*} value The value to be written (string, number, boolean, object,
* array, or null).
* @param {function(?Error)=} onComplete Callback called when write to server is
* complete.
* @return {!firebase.Promise<void>} Resolves when write to server is complete.
*/
firebase.database.Reference.prototype.set = function(value, onComplete) {};
/**
* Writes multiple values to the Database at once.
*
* The `values` argument contains multiple property-value pairs that will be
* written to the Database together. Each child property can either be a simple
* property (for example, "name") or a relative path (for example,
* "name/first") from the current location to the data to update.
*
* As opposed to the `set()` method, `update()` can be use to selectively update
* only the referenced properties at the current location (instead of replacing
* all the child properties at the current location).
*
* The effect of the write will be visible immediately, and the corresponding
* events ('value', 'child_added', etc.) will be triggered. Synchronization of
* the data to the Firebase servers will also be started, and the returned
* Promise will resolve when complete. If provided, the `onComplete` callback
* will be called asynchronously after synchronization has finished.
*
* A single `update()` will generate a single "value" event at the location
* where the `update()` was performed, regardless of how many children were
* modified.
*
* Note that modifying data with `update()` will cancel any pending
* transactions at that location, so extreme care should be taken if mixing
* `update()` and `transaction()` to modify the same data.
*
* Passing `null` to `update()` will remove the data at this location.
*
* See
* {@link
* https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html
* Introducing multi-location updates and more}.
*
* @example
* var adaNameRef = firebase.database().ref('users/ada/name');
* // Modify the 'first' and 'last' properties, but leave other data at
* // adaNameRef unchanged.
* adaNameRef.update({ first: 'Ada', last: 'Lovelace' });
*
* @param {!Object} values Object containing multiple values.
* @param {function(?Error)=} onComplete Callback called when write to server is
* complete.
* @return {!firebase.Promise<void>} Resolves when update on server is complete.
*/
firebase.database.Reference.prototype.update = function(values, onComplete) {};
/**
* Writes data the Database location. Like `set()` but also specifies the
* priority for that data.
*
* Applications need not use priority but can order collections by
* ordinary properties (see
* {@link
* https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
* Sorting and filtering data}).
*
* @param {*} newVal
* @param {string|number|null} newPriority
* @param {function(?Error)=} onComplete
* @return {!firebase.Promise<void>}
*/
firebase.database.Reference.prototype.setWithPriority = function(
newVal,
newPriority,
onComplete
) {};
/**
* Removes the data at this Database location.
*
* Any data at child locations will also be deleted.
*
* The effect of the remove will be visible immediately and the corresponding
* event 'value' will be triggered. Synchronization of the remove to the
* Firebase servers will also be started, and the returned Promise will resolve
* when complete. If provided, the onComplete callback will be called
* asynchronously after synchronization has finished.
*
* @example
* var adaRef = firebase.database().ref('users/ada');
* adaRef.remove()
* .then(function() {
* console.log("Remove succeeded.")
* })
* .catch(function(error) {
* console.log("Remove failed: " + error.message)
* });
*
* @param {function(?Error)=} onComplete Callback called when write to server is
* complete.
* @return {!firebase.Promise<void>} Resolves when remove on server is complete.
*/
firebase.database.Reference.prototype.remove = function(onComplete) {};
/**
* Atomically modifies the data at this location.
*
* Atomically modify the data at this location. Unlike a normal `set()`, which
* just overwrites the data regardless of its previous value, `transaction()` is
* used to modify the existing value to a new value, ensuring there are no
* conflicts with other clients writing to the same location at the same time.
*
* To accomplish this, you pass `transaction()` an update function which is used
* to transform the current value into a new value. If another client writes to
* the location before your new value is successfully written, your update
* function will be called again with the new current value, and the write will
* be retried. This will happen repeatedly until your write succeeds without
* conflict or you abort the transaction by not returning a value from your
* update function.
*
* Note: Modifying data with `set()` will cancel any pending transactions at
* that location, so extreme care should be taken if mixing `set()` and
* `transaction()` to update the same data.
*
* Note: When using transactions with Security and Firebase Rules in place, be
* aware that a client needs `.read` access in addition to `.write` access in
* order to perform a transaction. This is because the client-side nature of
* transactions requires the client to read the data in order to transactionally
* update it.
*
* @example
* // Increment Ada's rank by 1.
* var adaRankRef = firebase.database().ref('users/ada/rank');
* adaRankRef.transaction(function(currentRank) {
* // If users/ada/rank has never been set, currentRank will be `null`.
* return currentRank + 1;
* });
*
* @example
* // Try to create a user for ada, but only if the user id 'ada' isn't
* // already taken
* var adaRef = firebase.database().ref('users/ada');
* adaRef.transaction(function(currentData) {
* if (currentData === null) {
* return { name: { first: 'Ada', last: 'Lovelace' } };
* } else {
* console.log('User ada already exists.');
* return; // Abort the transaction.
* }
* }, function(error, committed, snapshot) {
* if (error) {
* console.log('Transaction failed abnormally!', error);
* } else if (!committed) {
* console.log('We aborted the transaction (because ada already exists).');
* } else {
* console.log('User ada added!');
* }
* console.log("Ada's data: ", snapshot.val());
* });
*
*
* @param {function(*): *} transactionUpdate A developer-supplied function which
* will be passed the current data stored at this location (as a JavaScript
* object). The function should return the new value it would like written (as
* a JavaScript object). If `undefined` is returned (i.e. you return with no
* arguments) the transaction will be aborted and the data at this location
* will not be modified.
* @param {(function(?Error, boolean,
* ?firebase.database.DataSnapshot))=} onComplete A callback
* function that will be called when the transaction completes. The callback
* is passed three arguments: a possibly-null `Error`, a `boolean` indicating
* whether the transaction was committed, and a `DataSnapshot` indicating the
* final result. If the transaction failed abnormally, the first argument will
* be an `Error` object indicating the failure cause. If the transaction
* finished normally, but no data was committed because no data was returned
* from `transactionUpdate`, then second argument will be false. If the
* transaction completed and committed data to Firebase, the second argument
* will be true. Regardless, the third argument will be a `DataSnapshot`
* containing the resulting data in this location.
* @param {boolean=} applyLocally By default, events are raised each time the
* transaction update function runs. So if it is run multiple times, you may
* see intermediate states. You can set this to false to suppress these
* intermediate states and instead wait until the transaction has completed
* before events are raised.
* @return {!firebase.Promise<{
* committed: boolean,
* snapshot: ?firebase.database.DataSnapshot
* }>} Returns a Promise that can optionally be used instead of the onComplete
* callback to handle success and failure.
*/
firebase.database.Reference.prototype.transaction = function(
transactionUpdate,
onComplete,
applyLocally
) {};
/**
* Sets a priority for the data at this Database location.
*
* Applications need not use priority but can order collections by
* ordinary properties (see
* {@link
* https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
* Sorting and filtering data}).
*
* @param {string|number|null} priority
* @param {function(?Error)} onComplete
* @return {!firebase.Promise<void>}
*/
firebase.database.Reference.prototype.setPriority = function(
priority,
onComplete
) {};
/**
* @interface
* @extends {firebase.database.Reference}
* @extends {firebase.Thenable<void>}
*/
firebase.database.ThenableReference = function() {};
/**
* Generates a new child location using a unique key and returns its
* `Reference`.
*
* This is the most common pattern for adding data to a collection of items.
*
* If you provide a value to `push()`, the value will be written to the
* generated location. If you don't pass a value, nothing will be written to the
* Database and the child will remain empty (but you can use the `Reference`
* elsewhere).
*
* The unique key generated by `push()` are ordered by the current time, so the
* resulting list of items will be chronologically sorted. The keys are also
* designed to be unguessable (they contain 72 random bits of entropy).
*
*
* See
* {@link
* https://firebase.google.com/docs/database/web/lists-of-data#append_to_a_list_of_data
* Append to a list of data}
* </br>See
* {@link
* https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html
* The 2^120 Ways to Ensure Unique Identifiers}
*
* @example
* var messageListRef = firebase.database().ref('message_list');
* var newMessageRef = messageListRef.push();
* newMessageRef.set({
* 'user_id': 'ada',
* 'text': 'The Analytical Engine weaves algebraical patterns just as the Jacquard loom weaves flowers and leaves.'
* });
* // We've appended a new message to the message_list location.
* var path = newMessageRef.toString();
* // path will be something like
* // 'https://sample-app.firebaseio.com/message_list/-IKo28nwJLH0Nc5XeFmj'
*
* @param {*=} value Optional value to be written at the generated location.
* @param {function(?Error)=} onComplete Callback called when write to server is
* complete.
* @return {!firebase.database.ThenableReference} Combined `Promise` and
* `Reference`; resolves when write is complete, but can be used immediately
* as the `Reference` to the child location.
*/
firebase.database.Reference.prototype.push = function(value, onComplete) {};
/**
* Returns an `OnDisconnect` object - see
* {@link
* https://firebase.google.com/docs/database/web/offline-capabilities
* Enabling Offline Capabilities in JavaScript} for more information on how
* to use it.
*
* @return {!firebase.database.OnDisconnect}
*/
firebase.database.Reference.prototype.onDisconnect = function() {};
/**
* A `Query` sorts and filters the data at a Database location so only a subset
* of the child data is included. This can be used to order a collection of
* data by some attribute (for example, height of dinosaurs) as well as to
* restrict a large list of items (for example, chat messages) down to a number
* suitable for synchronizing to the client. Queries are created by chaining
* together one or more of the filter methods defined here.
*
* Just as with a `Reference`, you can receive data from a `Query` by using the
* `on()` method. You will only receive events and `DataSnapshot`s for the
* subset of the data that matches your query.
*
* Read our documentation on
* {@link
* https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
* Sorting and filtering data} for more information.
*
* @interface
*/
firebase.database.Query = function() {};
/**
* Returns a `Reference` to the `Query`'s location.
*
* @type {!firebase.database.Reference}
*/
firebase.database.Query.prototype.ref;
/**
* Returns whether or not the current and provided queries represent the same
* location, have the same query parameters, and are from the same instance of
* `firebase.app.App`.
*
* Two `Reference` objects are equivalent if they represent the same location
* and are from the same instance of `firebase.app.App`.
*
* Two `Query` objects are equivalent if they represent the same location, have
* the same query parameters, and are from the same instance of
* `firebase.app.App`. Equivalent queries share the same sort order, limits, and
* starting and ending points.
*
* @example
* var rootRef = firebase.database.ref();
* var usersRef = rootRef.child("users");
*
* usersRef.isEqual(rootRef); // false
* usersRef.isEqual(rootRef.child("users")); // true
* usersRef.parent.isEqual(rootRef); // true
*
* @example
* var rootRef = firebase.database.ref();
* var usersRef = rootRef.child("users");
* var usersQuery = usersRef.limitToLast(10);
*
* usersQuery.isEqual(usersRef); // false
* usersQuery.isEqual(usersRef.limitToLast(10)); // true
* usersQuery.isEqual(rootRef.limitToLast(10)); // false
* usersQuery.isEqual(usersRef.orderByKey().limitToLast(10)); // false
*
* @param {firebase.database.Query} other The query to compare against.
* @return {boolean} Whether or not the current and provided queries are
* equivalent.
*/
firebase.database.Query.prototype.isEqual = function(other) {};
/**
* Listens for data changes at a particular location.
*
* This is the primary way to read data from a Database. Your callback
* will be triggered for the initial data and again whenever the data changes.
* Use `off( )` to stop receiving updates. See
* {@link https://firebase.google.com/docs/database/web/retrieve-data
* Retrieve Data on the Web}
* for more details.
*
* <h4>value event</h4>
*
* This event will trigger once with the initial data stored at this location,
* and then trigger again each time the data changes. The `DataSnapshot` passed
* to the callback will be for the location at which `on()` was called. It
* won't trigger until the entire contents has been synchronized. If the
* location has no data, it will be triggered with an empty `DataSnapshot`
* (`val()` will return `null`).
*
* <h4>child_added event</h4>
*
* This event will be triggered once for each initial child at this location,
* and it will be triggered again every time a new child is added. The
* `DataSnapshot` passed into the callback will reflect the data for the
* relevant child. For ordering purposes, it is passed a second argument which
* is a string containing the key of the previous sibling child by sort order,
* or `null` if it is the first child.
*
* <h4>child_removed event</h4>
*
* This event will be triggered once every time a child is removed. The
* `DataSnapshot` passed into the callback will be the old data for the child
* that was removed. A child will get removed when either:
*
* - a client explicitly calls `remove()` on that child or one of its ancestors
* - a client calls `set(null)` on that child or one of its ancestors
* - that child has all of its children removed
* - there is a query in effect which now filters out the child (because it's
* sort order changed or the max limit was hit)
*
* <h4>child_changed event</h4>
*
* This event will be triggered when the data stored in a child (or any of its
* descendants) changes. Note that a single `child_changed` event may represent
* multiple changes to the child. The `DataSnapshot` passed to the callback will
* contain the new child contents. For ordering purposes, the callback is also
* passed a second argument which is a string containing the key of the previous
* sibling child by sort order, or `null` if it is the first child.
*
* <h4>child_moved event</h4>
*
* This event will be triggered when a child's sort order changes such that its
* position relative to its siblings changes. The `DataSnapshot` passed to the
* callback will be for the data of the child that has moved. It is also passed
* a second argument which is a string containing the key of the previous
* sibling child by sort order, or `null` if it is the first child.
*
* @example <caption>Handle a new value:</caption>
* ref.on('value', function(dataSnapshot) {
* ...
* });
*
* @example <caption>Handle a new child:</caption>
* ref.on('child_added', function(childSnapshot, prevChildKey) {
* ...
* });
*
* @example <caption>Handle child removal:</caption>
* ref.on('child_removed', function(oldChildSnapshot) {
* ...
* });
*
* @example <caption>Handle child data changes:</caption>
* ref.on('child_changed', function(childSnapshot, prevChildKey) {
* ...
* });
*
* @example <caption>Handle child ordering changes:</caption>
* ref.on('child_moved', function(childSnapshot, prevChildKey) {
* ...
* });
*
* @param {string} eventType One of the following strings: "value",
* "child_added", "child_changed", "child_removed", or "child_moved."
* @param {!function(firebase.database.DataSnapshot, string=)} callback A
* callback that fires when the specified event occurs. The callback will be
* passed a DataSnapshot. For ordering purposes, "child_added",
* "child_changed", and "child_moved" will also be passed a string containing
* the key of the previous child, by sort order, or `null` if it is the
* first child.
* @param {(function(Error)|Object)=} cancelCallbackOrContext An optional
* callback that will be notified if your event subscription is ever canceled
* because your client does not have permission to read this data (or it had
* permission but has now lost it). This callback will be passed an `Error`
* object indicating why the failure occurred.
* @param {Object=} context If provided, this object will be used as `this`
* when calling your callback(s).
* @return {!function(firebase.database.DataSnapshot, string=)} The provided
* callback function is returned unmodified. This is just for convenience if
* you want to pass an inline function to `on()` but store the callback
* function for later passing to `off()`.
*/
firebase.database.Query.prototype.on = function(
eventType,
callback,
cancelCallbackOrContext,
context
) {};
/**
* Detaches a callback previously attached with `on()`.
*
* Detach a callback previously attached with `on()`. Note that if `on()` was
* called multiple times with the same eventType and callback, the callback
* will be called multiple times for each event, and `off()` must be called
* multiple times to remove the callback. Calling `off()` on a parent listener
* will not automatically remove listeners registered on child nodes, `off()`
* must also be called on any child listeners to remove the callback.
*
* If a callback is not specified, all callbacks for the specified eventType
* will be removed. Similarly, if no eventType or callback is specified, all
* callbacks for the `Reference` will be removed.
*
* @example
* var onValueChange = function(dataSnapshot) { ... };
* ref.on('value', onValueChange);
* ref.child('meta-data').on('child_added', onChildAdded);
* // Sometime later...
* ref.off('value', onValueChange);
*
* // You must also call off() for any child listeners on ref
* // to cancel those callbacks
* ref.child('meta-data').off('child_added', onValueAdded);
*
* @example
* // Or you can save a line of code by using an inline function
* // and on()'s return value.
* var onValueChange = ref.on('value', function(dataSnapshot) { ... });
* // Sometime later...
* ref.off('value', onValueChange);
*
* @param {string=} eventType One of the following strings: "value",
* "child_added", "child_changed", "child_removed", or "child_moved."
* @param {function(!firebase.database.DataSnapshot, ?string=)=} callback The
* callback function that was passed to `on()`.
* @param {Object=} context The context that was passed to `on()`.
*/
firebase.database.Query.prototype.off = function(
eventType,
callback,
context
) {};
/**
* Listens for exactly one event of the specified event type, and then stops
* listening.
*
* This is equivalent to calling {@link firebase.database.Query#on `on()`}, and
* then calling {@link firebase.database.Query#off `off()`} inside the callback
* function. See {@link firebase.database.Query#on `on()`} for details on the
* event types.
*
* @example
* // Basic usage of .once() to read the data located at ref.
* ref.once('value')
* .then(function(dataSnapshot) {
* // handle read data.
* });
*
* @param {string} eventType One of the following strings: "value",
* "child_added", "child_changed", "child_removed", or "child_moved."
* @param {function(!firebase.database.DataSnapshot, string=)=} successCallback A
* callback that fires when the specified event occurs. The callback will be
* passed a DataSnapshot. For ordering purposes, "child_added",
* "child_changed", and "child_moved" will also be passed a string containing
* the key of the previous child by sort order, or `null` if it is the
* first child.
* @param {(function(Error)|Object)=} failureCallbackOrContext An optional
* callback that will be notified if your client does not have permission to
* read the data. This callback will be passed an `Error` object indicating
* why the failure occurred.
* @param {Object=} context If provided, this object will be used as `this`
* when calling your callback(s).
* @return {!firebase.Promise<*>}
*/
firebase.database.Query.prototype.once = function(
eventType,
successCallback,
failureCallbackOrContext,
context
) {};
/**
* Generates a new `Query` limited to the first specific number of children.
*
* The `limitToFirst()` method is used to set a maximum number of children to be
* synced for a given callback. If we set a limit of 100, we will initially only
* receive up to 100 `child_added` events. If we have fewer than 100 messages
* stored in our Database, a `child_added` event will fire for each message.
* However, if we have over 100 messages, we will only receive a `child_added`
* event for the first 100 ordered messages. As items change, we will receive
* `child_removed` events for each item that drops out of the active list so
* that the total number stays at 100.
*
* You can read more about `limitToFirst()` in
* {@link
* https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
* Filtering data}.
*
* @example
* // Find the two shortest dinosaurs.
* var ref = firebase.database().ref("dinosaurs");
* ref.orderByChild("height").limitToFirst(2).on("child_added", function(snapshot) {
* // This will be called exactly two times (unless there are less than two
* // dinosaurs in the Database).
*
* // It will also get fired again if one of the first two dinosaurs is
* // removed from the data set, as a new dinosaur will now be the second
* // shortest.
* console.log(snapshot.key);
* });
*
* @param {number} limit The maximum number of nodes to include in this query.
* @return {!firebase.database.Query}
*/
firebase.database.Query.prototype.limitToFirst = function(limit) {};
/**
* Generates a new `Query` object limited to the last specific number of
* children.
*
* The `limitToLast()` method is used to set a maximum number of children to be
* synced for a given callback. If we set a limit of 100, we will initially only
* receive up to 100 `child_added` events. If we have fewer than 100 messages
* stored in our Database, a `child_added` event will fire for each message.
* However, if we have over 100 messages, we will only receive a `child_added`
* event for the last 100 ordered messages. As items change, we will receive
* `child_removed` events for each item that drops out of the active list so
* that the total number stays at 100.
*
* You can read more about `limitToLast()` in
* {@link
* https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
* Filtering data}.
*
* @example
* // Find the two heaviest dinosaurs.
* var ref = firebase.database().ref("dinosaurs");
* ref.orderByChild("weight").limitToLast(2).on("child_added", function(snapshot) {
* // This callback will be triggered exactly two times, unless there are
* // fewer than two dinosaurs stored in the Database. It will also get fired
* // for every new, heavier dinosaur that gets added to the data set.
* console.log(snapshot.key);
* });
*
* @param {number} limit The maximum number of nodes to include in this query.
* @return {!firebase.database.Query}
*/
firebase.database.Query.prototype.limitToLast = function(limit) {};
/**
* Generates a new `Query` object ordered by the specified child key.
*
* Queries can only order by one key at a time. Calling `orderByChild()`
* multiple times on the same query is an error.
*
* Firebase queries allow you to order your data by any child key on the fly.
* However, if you know in advance what your indexes will be, you can define
* them via the .indexOn rule in your Security Rules for better performance. See
* the {@link https://firebase.google.com/docs/database/security/indexing-data
* .indexOn} rule for more information.
*
* You can read more about `orderByChild()` in
* {@link
* https://firebase.google.com/docs/database/web/lists-of-data#sort_data
* Sort data}.
*
* @example
* var ref = firebase.database().ref("dinosaurs");
* ref.orderByChild("height").on("child_added", function(snapshot) {
* console.log(snapshot.key + " was " + snapshot.val().height + " m tall");
* });
*