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