@firebase/database-compat 2.0.0 → 2.0.1-canary.ffbf5a60a

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