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