firebase-functions 6.6.0 → 7.0.0-rc.1
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/lib/_virtual/rolldown_runtime.js +34 -0
- package/lib/bin/firebase-functions.js +78 -103
- package/lib/common/app.js +35 -55
- package/lib/common/change.js +54 -75
- package/lib/common/config.js +41 -41
- package/lib/common/debug.js +23 -47
- package/lib/common/encoding.js +59 -82
- package/lib/common/onInit.js +26 -28
- package/lib/common/options.js +22 -42
- package/lib/common/params.d.ts +6 -6
- package/lib/common/params.js +0 -23
- package/lib/common/providers/database.js +270 -300
- package/lib/common/providers/firestore.js +66 -92
- package/lib/common/providers/https.d.ts +0 -1
- package/lib/common/providers/https.js +537 -539
- package/lib/common/providers/identity.js +393 -444
- package/lib/common/providers/tasks.js +64 -98
- package/lib/common/timezone.js +544 -542
- package/lib/common/trace.d.ts +0 -1
- package/lib/common/trace.js +63 -55
- package/lib/common/utilities/assertions.d.ts +11 -0
- package/lib/common/utilities/assertions.js +18 -0
- package/lib/common/utilities/encoder.js +20 -37
- package/lib/common/utilities/path-pattern.js +106 -132
- package/lib/common/utilities/path.js +28 -27
- package/lib/common/utilities/utils.js +23 -45
- package/lib/esm/_virtual/rolldown_runtime.mjs +16 -0
- package/lib/esm/bin/firebase-functions.mjs +91 -0
- package/lib/esm/common/app.mjs +39 -0
- package/lib/esm/common/change.mjs +57 -0
- package/lib/esm/common/config.mjs +45 -0
- package/lib/esm/common/debug.mjs +28 -0
- package/lib/esm/common/encoding.mjs +69 -0
- package/lib/esm/common/onInit.mjs +33 -0
- package/lib/esm/common/options.mjs +22 -0
- package/lib/esm/common/params.mjs +1 -0
- package/lib/esm/common/providers/database.mjs +269 -0
- package/lib/esm/common/providers/firestore.mjs +78 -0
- package/lib/esm/common/providers/https.mjs +573 -0
- package/lib/esm/common/providers/identity.mjs +428 -0
- package/lib/esm/common/providers/tasks.mjs +67 -0
- package/lib/esm/common/timezone.mjs +544 -0
- package/lib/esm/common/trace.mjs +73 -0
- package/lib/esm/common/utilities/assertions.mjs +17 -0
- package/lib/esm/common/utilities/encoder.mjs +21 -0
- package/lib/esm/common/utilities/path-pattern.mjs +116 -0
- package/lib/esm/common/utilities/path.mjs +35 -0
- package/lib/esm/common/utilities/utils.mjs +29 -0
- package/lib/esm/function-configuration.mjs +1 -0
- package/lib/esm/logger/common.mjs +23 -0
- package/lib/esm/logger/compat.mjs +25 -0
- package/lib/esm/logger/index.mjs +131 -0
- package/lib/esm/params/index.mjs +160 -0
- package/lib/esm/params/types.mjs +400 -0
- package/lib/esm/runtime/loader.mjs +132 -0
- package/lib/esm/runtime/manifest.mjs +134 -0
- package/lib/esm/types/global.d.mjs +1 -0
- package/lib/esm/v1/cloud-functions.mjs +206 -0
- package/lib/esm/v1/config.mjs +14 -0
- package/lib/esm/v1/function-builder.mjs +252 -0
- package/lib/esm/v1/function-configuration.mjs +72 -0
- package/lib/esm/v1/index.mjs +27 -0
- package/lib/esm/v1/providers/analytics.mjs +212 -0
- package/lib/esm/v1/providers/auth.mjs +156 -0
- package/lib/esm/v1/providers/database.mjs +243 -0
- package/lib/esm/v1/providers/firestore.mjs +131 -0
- package/lib/esm/v1/providers/https.mjs +82 -0
- package/lib/esm/v1/providers/pubsub.mjs +175 -0
- package/lib/esm/v1/providers/remoteConfig.mjs +64 -0
- package/lib/esm/v1/providers/storage.mjs +163 -0
- package/lib/esm/v1/providers/tasks.mjs +63 -0
- package/lib/esm/v1/providers/testLab.mjs +94 -0
- package/lib/esm/v2/core.mjs +4 -0
- package/lib/esm/v2/index.mjs +28 -0
- package/lib/esm/v2/options.mjs +102 -0
- package/lib/esm/v2/providers/alerts/alerts.mjs +85 -0
- package/lib/esm/v2/providers/alerts/appDistribution.mjs +75 -0
- package/lib/esm/v2/providers/alerts/billing.mjs +51 -0
- package/lib/esm/v2/providers/alerts/crashlytics.mjs +122 -0
- package/lib/esm/v2/providers/alerts/index.mjs +22 -0
- package/lib/esm/v2/providers/alerts/performance.mjs +66 -0
- package/lib/esm/v2/providers/database.mjs +197 -0
- package/lib/esm/v2/providers/dataconnect.mjs +130 -0
- package/lib/esm/v2/providers/eventarc.mjs +51 -0
- package/lib/esm/v2/providers/firestore.mjs +294 -0
- package/lib/esm/v2/providers/https.mjs +210 -0
- package/lib/esm/v2/providers/identity.mjs +103 -0
- package/lib/esm/v2/providers/pubsub.mjs +148 -0
- package/lib/esm/v2/providers/remoteConfig.mjs +52 -0
- package/lib/esm/v2/providers/scheduler.mjs +84 -0
- package/lib/esm/v2/providers/storage.mjs +155 -0
- package/lib/esm/v2/providers/tasks.mjs +65 -0
- package/lib/esm/v2/providers/testLab.mjs +53 -0
- package/lib/esm/v2/trace.mjs +20 -0
- package/lib/function-configuration.d.ts +0 -0
- package/lib/function-configuration.js +0 -0
- package/lib/logger/common.js +21 -41
- package/lib/logger/compat.js +18 -33
- package/lib/logger/index.js +119 -130
- package/lib/params/index.d.ts +4 -2
- package/lib/params/index.js +150 -144
- package/lib/params/types.js +389 -423
- package/lib/runtime/loader.js +114 -148
- package/lib/runtime/manifest.js +106 -126
- package/lib/types/global.d.js +0 -0
- package/lib/v1/cloud-functions.d.ts +2 -2
- package/lib/v1/cloud-functions.js +193 -241
- package/lib/v1/config.d.ts +4 -7
- package/lib/v1/config.js +13 -75
- package/lib/v1/function-builder.js +239 -368
- package/lib/v1/function-configuration.js +70 -63
- package/lib/v1/index.js +118 -73
- package/lib/v1/providers/analytics.js +188 -235
- package/lib/v1/providers/auth.d.ts +2 -1
- package/lib/v1/providers/auth.js +159 -164
- package/lib/v1/providers/database.js +237 -242
- package/lib/v1/providers/firestore.js +131 -130
- package/lib/v1/providers/https.d.ts +2 -1
- package/lib/v1/providers/https.js +79 -86
- package/lib/v1/providers/pubsub.js +175 -172
- package/lib/v1/providers/remoteConfig.js +64 -68
- package/lib/v1/providers/storage.js +161 -163
- package/lib/v1/providers/tasks.d.ts +1 -1
- package/lib/v1/providers/tasks.js +65 -80
- package/lib/v1/providers/testLab.js +94 -94
- package/lib/v2/core.d.ts +1 -1
- package/lib/v2/core.js +5 -32
- package/lib/v2/index.d.ts +6 -3
- package/lib/v2/index.js +123 -75
- package/lib/v2/options.js +88 -114
- package/lib/v2/providers/alerts/alerts.js +76 -95
- package/lib/v2/providers/alerts/appDistribution.js +73 -78
- package/lib/v2/providers/alerts/billing.js +49 -53
- package/lib/v2/providers/alerts/crashlytics.js +110 -102
- package/lib/v2/providers/alerts/index.js +56 -53
- package/lib/v2/providers/alerts/performance.js +64 -74
- package/lib/v2/providers/database.js +177 -180
- package/lib/v2/providers/dataconnect.d.ts +95 -0
- package/lib/v2/providers/dataconnect.js +137 -0
- package/lib/v2/providers/eventarc.js +55 -77
- package/lib/v2/providers/firestore.js +262 -260
- package/lib/v2/providers/https.d.ts +3 -2
- package/lib/v2/providers/https.js +210 -247
- package/lib/v2/providers/identity.d.ts +2 -1
- package/lib/v2/providers/identity.js +96 -105
- package/lib/v2/providers/pubsub.js +149 -167
- package/lib/v2/providers/remoteConfig.js +54 -63
- package/lib/v2/providers/scheduler.js +84 -96
- package/lib/v2/providers/storage.js +147 -162
- package/lib/v2/providers/tasks.d.ts +1 -1
- package/lib/v2/providers/tasks.js +68 -95
- package/lib/v2/providers/testLab.js +55 -64
- package/lib/v2/trace.js +18 -19
- package/package.json +321 -88
- package/protos/compiledFirestore.mjs +3512 -0
- package/protos/update.sh +28 -7
|
@@ -1,301 +1,271 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// in the Software without restriction, including without limitation the rights
|
|
9
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
// furnished to do so, subject to the following conditions:
|
|
12
|
-
//
|
|
13
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
// copies or substantial portions of the Software.
|
|
15
|
-
//
|
|
16
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
// SOFTWARE.
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.DataSnapshot = void 0;
|
|
25
|
-
const database = require("firebase-admin/database");
|
|
26
|
-
const config_1 = require("../../common/config");
|
|
27
|
-
const path_1 = require("../../common/utilities/path");
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_common_config = require('../config.js');
|
|
3
|
+
const require_common_utilities_path = require('../utilities/path.js');
|
|
4
|
+
let firebase_admin_database = require("firebase-admin/database");
|
|
5
|
+
firebase_admin_database = require_rolldown_runtime.__toESM(firebase_admin_database);
|
|
6
|
+
|
|
7
|
+
//#region src/common/providers/database.ts
|
|
28
8
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class DataSnapshot {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
dup._childPath = (0, path_1.joinPath)(dup._childPath, childPath);
|
|
293
|
-
}
|
|
294
|
-
return dup;
|
|
295
|
-
}
|
|
296
|
-
/** @hidden */
|
|
297
|
-
_fullPath() {
|
|
298
|
-
return (this._path || "") + "/" + (this._childPath || "");
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
exports.DataSnapshot = DataSnapshot;
|
|
9
|
+
* Interface representing a Firebase Realtime database data snapshot.
|
|
10
|
+
*/
|
|
11
|
+
var DataSnapshot = class DataSnapshot {
|
|
12
|
+
constructor(data, path, app, instance) {
|
|
13
|
+
this.app = app;
|
|
14
|
+
const config = require_common_config.firebaseConfig();
|
|
15
|
+
if (instance) {
|
|
16
|
+
this.instance = instance;
|
|
17
|
+
} else if (app) {
|
|
18
|
+
this.instance = app.options.databaseURL;
|
|
19
|
+
} else if (config.databaseURL) {
|
|
20
|
+
this.instance = config.databaseURL;
|
|
21
|
+
} else if (process.env.GCLOUD_PROJECT) {
|
|
22
|
+
this.instance = "https://" + process.env.GCLOUD_PROJECT + "-default-rtdb.firebaseio.com";
|
|
23
|
+
}
|
|
24
|
+
this._path = path;
|
|
25
|
+
this._data = data;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns a [`Reference`](/docs/reference/admin/node/admin.database.Reference)
|
|
29
|
+
* to the database location where the triggering write occurred. Has
|
|
30
|
+
* full read and write access.
|
|
31
|
+
*/
|
|
32
|
+
get ref() {
|
|
33
|
+
if (!this.app) {
|
|
34
|
+
throw new Error("Please supply a Firebase app in the constructor for DataSnapshot" + " in order to use the .ref method.");
|
|
35
|
+
}
|
|
36
|
+
if (!this._ref) {
|
|
37
|
+
let db;
|
|
38
|
+
if (this.instance) {
|
|
39
|
+
db = firebase_admin_database.getDatabaseWithUrl(this.instance, this.app);
|
|
40
|
+
} else {
|
|
41
|
+
db = firebase_admin_database.getDatabase(this.app);
|
|
42
|
+
}
|
|
43
|
+
this._ref = db.ref(this._fullPath());
|
|
44
|
+
}
|
|
45
|
+
return this._ref;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The key (last part of the path) of the location of this `DataSnapshot`.
|
|
49
|
+
*
|
|
50
|
+
* The last token in a database location is considered its key. For example,
|
|
51
|
+
* "ada" is the key for the `/users/ada/` node. Accessing the key on any
|
|
52
|
+
* `DataSnapshot` returns the key for the location that generated it.
|
|
53
|
+
* However, accessing the key on the root URL of a database returns `null`.
|
|
54
|
+
*/
|
|
55
|
+
get key() {
|
|
56
|
+
const segments = require_common_utilities_path.pathParts(this._fullPath());
|
|
57
|
+
const last = segments[segments.length - 1];
|
|
58
|
+
return !last || last === "" ? null : last;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Extracts a JavaScript value from a `DataSnapshot`.
|
|
62
|
+
*
|
|
63
|
+
* Depending on the data in a `DataSnapshot`, the `val()` method may return a
|
|
64
|
+
* scalar type (string, number, or boolean), an array, or an object. It may also
|
|
65
|
+
* return `null`, indicating that the `DataSnapshot` is empty (contains no
|
|
66
|
+
* data).
|
|
67
|
+
*
|
|
68
|
+
* @return The snapshot's contents as a JavaScript value (Object,
|
|
69
|
+
* Array, string, number, boolean, or `null`).
|
|
70
|
+
*/
|
|
71
|
+
val() {
|
|
72
|
+
const parts = require_common_utilities_path.pathParts(this._childPath);
|
|
73
|
+
let source = this._data;
|
|
74
|
+
if (source === null) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
if (parts.length) {
|
|
78
|
+
for (const part of parts) {
|
|
79
|
+
if (typeof source === "undefined" || source === null) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
source = source[part];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const node = source ?? null;
|
|
86
|
+
return this._checkAndConvertToArray(node);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Exports the entire contents of the `DataSnapshot` as a JavaScript object.
|
|
90
|
+
*
|
|
91
|
+
* @return The contents of the `DataSnapshot` as a JavaScript value
|
|
92
|
+
* (Object, Array, string, number, boolean, or `null`).
|
|
93
|
+
*/
|
|
94
|
+
exportVal() {
|
|
95
|
+
return this.val();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Gets the priority value of the data in this `DataSnapshot`.
|
|
99
|
+
*
|
|
100
|
+
* As an alternative to using priority, applications can order collections by
|
|
101
|
+
* ordinary properties. See [Sorting and filtering
|
|
102
|
+
* data](/docs/database/web/lists-of-data#sorting_and_filtering_data).
|
|
103
|
+
*
|
|
104
|
+
* @return The priority value of the data.
|
|
105
|
+
*/
|
|
106
|
+
getPriority() {
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns `true` if this `DataSnapshot` contains any data. It is slightly more
|
|
111
|
+
* efficient than using `snapshot.val() !== null`.
|
|
112
|
+
*
|
|
113
|
+
* @return `true` if this `DataSnapshot` contains any data; otherwise, `false`.
|
|
114
|
+
*/
|
|
115
|
+
exists() {
|
|
116
|
+
const val = this.val();
|
|
117
|
+
if (typeof val === "undefined" || val === null) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if (typeof val === "object" && Object.keys(val).length === 0) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Gets a `DataSnapshot` for the location at the specified relative path.
|
|
127
|
+
*
|
|
128
|
+
* The relative path can either be a simple child name (for example, "ada") or
|
|
129
|
+
* a deeper slash-separated path (for example, "ada/name/first").
|
|
130
|
+
*
|
|
131
|
+
* @param path A relative path from this location to the desired child
|
|
132
|
+
* location.
|
|
133
|
+
* @return The specified child location.
|
|
134
|
+
*/
|
|
135
|
+
child(childPath) {
|
|
136
|
+
if (!childPath) {
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
return this._dup(childPath);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Enumerates the `DataSnapshot`s of the children items.
|
|
143
|
+
*
|
|
144
|
+
* Because of the way JavaScript objects work, the ordering of data in the
|
|
145
|
+
* JavaScript object returned by `val()` is not guaranteed to match the ordering
|
|
146
|
+
* on the server nor the ordering of `child_added` events. That is where
|
|
147
|
+
* `forEach()` comes in handy. It guarantees the children of a `DataSnapshot`
|
|
148
|
+
* can be iterated in their query order.
|
|
149
|
+
*
|
|
150
|
+
* If no explicit `orderBy*()` method is used, results are returned
|
|
151
|
+
* ordered by key (unless priorities are used, in which case, results are
|
|
152
|
+
* returned by priority).
|
|
153
|
+
*
|
|
154
|
+
* @param action A function that is called for each child `DataSnapshot`.
|
|
155
|
+
* The callback can return `true` to cancel further enumeration.
|
|
156
|
+
*
|
|
157
|
+
* @return `true` if enumeration was canceled due to your callback
|
|
158
|
+
* returning `true`.
|
|
159
|
+
*/
|
|
160
|
+
forEach(action) {
|
|
161
|
+
const val = this.val() || {};
|
|
162
|
+
if (typeof val === "object") {
|
|
163
|
+
return Object.keys(val).some((key) => action(this.child(key)) === true);
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Returns `true` if the specified child path has (non-`null`) data.
|
|
169
|
+
*
|
|
170
|
+
* @param path A relative path to the location of a potential child.
|
|
171
|
+
* @return `true` if data exists at the specified child path; otherwise,
|
|
172
|
+
* `false`.
|
|
173
|
+
*/
|
|
174
|
+
hasChild(childPath) {
|
|
175
|
+
return this.child(childPath).exists();
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Returns whether or not the `DataSnapshot` has any non-`null` child
|
|
179
|
+
* properties.
|
|
180
|
+
*
|
|
181
|
+
* You can use `hasChildren()` to determine if a `DataSnapshot` has any
|
|
182
|
+
* children. If it does, you can enumerate them using `forEach()`. If it
|
|
183
|
+
* doesn't, then either this snapshot contains a primitive value (which can be
|
|
184
|
+
* retrieved with `val()`) or it is empty (in which case, `val()` returns
|
|
185
|
+
* `null`).
|
|
186
|
+
*
|
|
187
|
+
* @return `true` if this snapshot has any children; else `false`.
|
|
188
|
+
*/
|
|
189
|
+
hasChildren() {
|
|
190
|
+
const val = this.val();
|
|
191
|
+
return val !== null && typeof val === "object" && Object.keys(val).length > 0;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Returns the number of child properties of this `DataSnapshot`.
|
|
195
|
+
*
|
|
196
|
+
* @return Number of child properties of this `DataSnapshot`.
|
|
197
|
+
*/
|
|
198
|
+
numChildren() {
|
|
199
|
+
const val = this.val();
|
|
200
|
+
return val !== null && typeof val === "object" ? Object.keys(val).length : 0;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Returns a JSON-serializable representation of this object.
|
|
204
|
+
*
|
|
205
|
+
* @return A JSON-serializable representation of this object.
|
|
206
|
+
*/
|
|
207
|
+
toJSON() {
|
|
208
|
+
return this.val();
|
|
209
|
+
}
|
|
210
|
+
/** Recursive function to check if keys are numeric & convert node object to array if they are
|
|
211
|
+
*
|
|
212
|
+
* @hidden
|
|
213
|
+
*/
|
|
214
|
+
_checkAndConvertToArray(node) {
|
|
215
|
+
if (node === null || typeof node === "undefined") {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
if (typeof node !== "object") {
|
|
219
|
+
return node;
|
|
220
|
+
}
|
|
221
|
+
const obj = {};
|
|
222
|
+
let numKeys = 0;
|
|
223
|
+
let maxKey = 0;
|
|
224
|
+
let allIntegerKeys = true;
|
|
225
|
+
for (const key in node) {
|
|
226
|
+
if (!node.hasOwnProperty(key)) {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
const childNode = node[key];
|
|
230
|
+
const v = this._checkAndConvertToArray(childNode);
|
|
231
|
+
if (v === null) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
obj[key] = v;
|
|
235
|
+
numKeys++;
|
|
236
|
+
const integerRegExp = /^(0|[1-9]\d*)$/;
|
|
237
|
+
if (allIntegerKeys && integerRegExp.test(key)) {
|
|
238
|
+
maxKey = Math.max(maxKey, Number(key));
|
|
239
|
+
} else {
|
|
240
|
+
allIntegerKeys = false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (numKeys === 0) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
if (allIntegerKeys && maxKey < 2 * numKeys) {
|
|
247
|
+
const array = [];
|
|
248
|
+
for (const key of Object.keys(obj)) {
|
|
249
|
+
array[key] = obj[key];
|
|
250
|
+
}
|
|
251
|
+
return array;
|
|
252
|
+
}
|
|
253
|
+
return obj;
|
|
254
|
+
}
|
|
255
|
+
/** @hidden */
|
|
256
|
+
_dup(childPath) {
|
|
257
|
+
const dup = new DataSnapshot(this._data, undefined, this.app, this.instance);
|
|
258
|
+
[dup._path, dup._childPath] = [this._path, this._childPath];
|
|
259
|
+
if (childPath) {
|
|
260
|
+
dup._childPath = require_common_utilities_path.joinPath(dup._childPath, childPath);
|
|
261
|
+
}
|
|
262
|
+
return dup;
|
|
263
|
+
}
|
|
264
|
+
/** @hidden */
|
|
265
|
+
_fullPath() {
|
|
266
|
+
return (this._path || "") + "/" + (this._childPath || "");
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
//#endregion
|
|
271
|
+
exports.DataSnapshot = DataSnapshot;
|