firebase-functions 6.6.0 → 7.0.0-rc.0

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 +290 -226
  155. package/protos/compiledFirestore.mjs +3512 -0
  156. package/protos/update.sh +28 -7
@@ -0,0 +1,34 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (all) => {
9
+ let target = {};
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ return target;
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
18
+ key = keys[i];
19
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
20
+ get: ((k) => from[k]).bind(null, key),
21
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
22
+ });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
27
+ value: mod,
28
+ enumerable: true
29
+ }) : target, mod));
30
+
31
+ //#endregion
32
+
33
+ exports.__export = __export;
34
+ exports.__toESM = __toESM;
@@ -1,119 +1,94 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- // The MIT License (MIT)
4
- //
5
- // Copyright (c) 2022 Firebase
6
- //
7
- // Permission is hereby granted, free of charge, to any person obtaining a copy
8
- // of this software and associated documentation files (the "Software"), to deal
9
- // in the Software without restriction, including without limitation the rights
10
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- // copies of the Software, and to permit persons to whom the Software is
12
- // furnished to do so, subject to the following conditions:
13
- //
14
- // The above copyright notice and this permission notice shall be included in all
15
- // copies or substantial portions of the Software.
16
- //
17
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- // SOFTWARE.
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- const express = require("express");
26
- const fs = require("fs/promises");
27
- const path = require("path");
28
- const loader_1 = require("../runtime/loader");
29
- const manifest_1 = require("../runtime/manifest");
2
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
3
+ const require_runtime_loader = require('../runtime/loader.js');
4
+ const require_runtime_manifest = require('../runtime/manifest.js');
5
+ let express = require("express");
6
+ express = require_rolldown_runtime.__toESM(express);
7
+ let fs_promises = require("fs/promises");
8
+ fs_promises = require_rolldown_runtime.__toESM(fs_promises);
9
+ let path = require("path");
10
+ path = require_rolldown_runtime.__toESM(path);
11
+
12
+ //#region src/bin/firebase-functions.ts
30
13
  function printUsageAndExit() {
31
- console.error(`
14
+ console.error(`
32
15
  Usage: firebase-functions [functionsDir]
33
16
 
34
17
  Arguments:
35
18
  - functionsDir: Directory containing source code for Firebase Functions.
36
19
  `);
37
- process.exit(1);
20
+ process.exit(1);
38
21
  }
39
22
  let functionsDir = ".";
40
23
  const args = process.argv.slice(2);
41
24
  if (args.length > 1) {
42
- if (args[0] === "-h" || args[0] === "--help") {
43
- printUsageAndExit();
44
- }
45
- functionsDir = args[0];
25
+ if (args[0] === "-h" || args[0] === "--help") {
26
+ printUsageAndExit();
27
+ }
28
+ functionsDir = args[0];
46
29
  }
47
30
  function handleQuitquitquit(req, res, server) {
48
- res.send("ok");
49
- server.close();
31
+ res.send("ok");
32
+ server.close();
50
33
  }
51
34
  if (process.env.FUNCTIONS_MANIFEST_OUTPUT_PATH) {
52
- void (async () => {
53
- var _a;
54
- const outputPath = process.env.FUNCTIONS_MANIFEST_OUTPUT_PATH;
55
- try {
56
- // Validate the output path
57
- const dir = path.dirname(outputPath);
58
- try {
59
- await fs.access(dir, fs.constants.W_OK);
60
- }
61
- catch (e) {
62
- console.error(`Error: Cannot write to directory '${dir}': ${e instanceof Error ? e.message : String(e)}`);
63
- console.error("Please ensure the directory exists and you have write permissions.");
64
- process.exit(1);
65
- }
66
- const stack = await (0, loader_1.loadStack)(functionsDir);
67
- const wireFormat = (0, manifest_1.stackToWire)(stack);
68
- await fs.writeFile(outputPath, JSON.stringify(wireFormat, null, 2));
69
- process.exit(0);
70
- }
71
- catch (e) {
72
- if (e.code === "ENOENT") {
73
- console.error(`Error: Directory '${path.dirname(outputPath)}' does not exist.`);
74
- console.error("Please create the directory or specify a valid path.");
75
- }
76
- else if (e.code === "EACCES") {
77
- console.error(`Error: Permission denied writing to '${outputPath}'.`);
78
- console.error("Please check file permissions or choose a different location.");
79
- }
80
- else if ((_a = e.message) === null || _a === void 0 ? void 0 : _a.includes("Failed to generate manifest")) {
81
- console.error(e.message);
82
- }
83
- else {
84
- console.error(`Failed to generate manifest from function source: ${e instanceof Error ? e.message : String(e)}`);
85
- }
86
- if (e instanceof Error && e.stack) {
87
- console.error(e.stack);
88
- }
89
- process.exit(1);
90
- }
91
- })();
92
- }
93
- else {
94
- let server = undefined;
95
- const app = express();
96
- app.get("/__/quitquitquit", (req, res) => handleQuitquitquit(req, res, server));
97
- app.post("/__/quitquitquit", (req, res) => handleQuitquitquit(req, res, server));
98
- if (process.env.FUNCTIONS_CONTROL_API === "true") {
99
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
100
- app.get("/__/functions.yaml", async (req, res) => {
101
- try {
102
- const stack = await (0, loader_1.loadStack)(functionsDir);
103
- res.setHeader("content-type", "text/yaml");
104
- res.send(JSON.stringify((0, manifest_1.stackToWire)(stack)));
105
- }
106
- catch (e) {
107
- console.error(e);
108
- const errorMessage = e instanceof Error ? e.message : String(e);
109
- res.status(400).send(`Failed to generate manifest from function source: ${errorMessage}`);
110
- }
111
- });
112
- }
113
- let port = 8080;
114
- if (process.env.PORT) {
115
- port = Number.parseInt(process.env.PORT);
116
- }
117
- console.log("Serving at port", port);
118
- server = app.listen(port);
35
+ void (async () => {
36
+ const outputPath = process.env.FUNCTIONS_MANIFEST_OUTPUT_PATH;
37
+ try {
38
+ const dir = path.dirname(outputPath);
39
+ try {
40
+ await fs_promises.default.access(dir, fs_promises.default.constants.W_OK);
41
+ } catch (e) {
42
+ console.error(`Error: Cannot write to directory '${dir}': ${e instanceof Error ? e.message : String(e)}`);
43
+ console.error("Please ensure the directory exists and you have write permissions.");
44
+ process.exit(1);
45
+ }
46
+ const stack = await require_runtime_loader.loadStack(functionsDir);
47
+ const wireFormat = require_runtime_manifest.stackToWire(stack);
48
+ await fs_promises.default.writeFile(outputPath, JSON.stringify(wireFormat, null, 2));
49
+ process.exit(0);
50
+ } catch (e) {
51
+ if (e.code === "ENOENT") {
52
+ console.error(`Error: Directory '${path.dirname(outputPath)}' does not exist.`);
53
+ console.error("Please create the directory or specify a valid path.");
54
+ } else if (e.code === "EACCES") {
55
+ console.error(`Error: Permission denied writing to '${outputPath}'.`);
56
+ console.error("Please check file permissions or choose a different location.");
57
+ } else if (e.message?.includes("Failed to generate manifest")) {
58
+ console.error(e.message);
59
+ } else {
60
+ console.error(`Failed to generate manifest from function source: ${e instanceof Error ? e.message : String(e)}`);
61
+ }
62
+ if (e instanceof Error && e.stack) {
63
+ console.error(e.stack);
64
+ }
65
+ process.exit(1);
66
+ }
67
+ })();
68
+ } else {
69
+ let server = undefined;
70
+ const app = (0, express.default)();
71
+ app.get("/__/quitquitquit", (req, res) => handleQuitquitquit(req, res, server));
72
+ app.post("/__/quitquitquit", (req, res) => handleQuitquitquit(req, res, server));
73
+ if (process.env.FUNCTIONS_CONTROL_API === "true") {
74
+ app.get("/__/functions.yaml", async (req, res) => {
75
+ try {
76
+ const stack = await require_runtime_loader.loadStack(functionsDir);
77
+ res.setHeader("content-type", "text/yaml");
78
+ res.send(JSON.stringify(require_runtime_manifest.stackToWire(stack)));
79
+ } catch (e) {
80
+ console.error(e);
81
+ const errorMessage = e instanceof Error ? e.message : String(e);
82
+ res.status(400).send(`Failed to generate manifest from function source: ${errorMessage}`);
83
+ }
84
+ });
85
+ }
86
+ let port = 8080;
87
+ if (process.env.PORT) {
88
+ port = Number.parseInt(process.env.PORT);
89
+ }
90
+ console.log("Serving at port", port);
91
+ server = app.listen(port);
119
92
  }
93
+
94
+ //#endregion
package/lib/common/app.js CHANGED
@@ -1,62 +1,42 @@
1
- "use strict";
2
- // The MIT License (MIT)
3
- //
4
- // Copyright (c) 2017 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.setApp = exports.getApp = void 0;
25
- const app_1 = require("firebase-admin/app");
26
- const config_1 = require("./config");
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
2
+ const require_common_config = require('./config.js');
3
+ let firebase_admin_app = require("firebase-admin/app");
4
+ firebase_admin_app = require_rolldown_runtime.__toESM(firebase_admin_app);
5
+
6
+ //#region src/common/app.ts
27
7
  const APP_NAME = "__FIREBASE_FUNCTIONS_SDK__";
28
8
  let cache;
29
9
  function getApp() {
30
- if (typeof cache === "undefined") {
31
- try {
32
- cache = (0, app_1.getApp)( /* default */);
33
- }
34
- catch {
35
- // Default app does not exist. Initialize app.
36
- cache = (0, app_1.initializeApp)({
37
- ...(0, config_1.firebaseConfig)(),
38
- credential: (0, app_1.applicationDefault)(),
39
- }, APP_NAME);
40
- }
41
- }
42
- return cache;
10
+ if (typeof cache === "undefined") {
11
+ try {
12
+ cache = (0, firebase_admin_app.getApp)();
13
+ } catch {
14
+ cache = (0, firebase_admin_app.initializeApp)({
15
+ ...require_common_config.firebaseConfig(),
16
+ credential: (0, firebase_admin_app.applicationDefault)()
17
+ }, APP_NAME);
18
+ }
19
+ }
20
+ return cache;
43
21
  }
44
- exports.getApp = getApp;
45
22
  /**
46
- * This function allows the Firebase Emulator Suite to override the FirebaseApp instance
47
- * used by the Firebase Functions SDK. Developers should never call this function for
48
- * other purposes.
49
- * N.B. For clarity for use in testing this name has no mention of emulation, but
50
- * it must be exported from index as app.setEmulatedAdminApp or we break the emulator.
51
- * We can remove this export when:
52
- * A) We complete the new emulator and no longer depend on monkeypatching
53
- * B) We tweak the CLI to look for different APIs to monkeypatch depending on versions.
54
- * @alpha
55
- */
23
+ * This function allows the Firebase Emulator Suite to override the FirebaseApp instance
24
+ * used by the Firebase Functions SDK. Developers should never call this function for
25
+ * other purposes.
26
+ * N.B. For clarity for use in testing this name has no mention of emulation, but
27
+ * it must be exported from index as app.setEmulatedAdminApp or we break the emulator.
28
+ * We can remove this export when:
29
+ * A) We complete the new emulator and no longer depend on monkeypatching
30
+ * B) We tweak the CLI to look for different APIs to monkeypatch depending on versions.
31
+ * @alpha
32
+ */
56
33
  function setApp(app) {
57
- if ((cache === null || cache === void 0 ? void 0 : cache.name) === APP_NAME) {
58
- void (0, app_1.deleteApp)(cache);
59
- }
60
- cache = app;
34
+ if (cache?.name === APP_NAME) {
35
+ void (0, firebase_admin_app.deleteApp)(cache);
36
+ }
37
+ cache = app;
61
38
  }
62
- exports.setApp = setApp;
39
+
40
+ //#endregion
41
+ exports.getApp = getApp;
42
+ exports.setApp = setApp;
@@ -1,80 +1,59 @@
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.Change = exports.applyFieldMask = void 0;
1
+
2
+ //#region src/common/change.ts
25
3
  /** @internal */
26
4
  function applyFieldMask(sparseBefore, after, fieldMask) {
27
- const before = { ...after };
28
- const masks = fieldMask.split(",");
29
- for (const mask of masks) {
30
- const parts = mask.split(".");
31
- const head = parts[0];
32
- const tail = parts.slice(1).join(".");
33
- if (parts.length > 1) {
34
- before[head] = applyFieldMask(sparseBefore === null || sparseBefore === void 0 ? void 0 : sparseBefore[head], after[head], tail);
35
- continue;
36
- }
37
- const val = sparseBefore === null || sparseBefore === void 0 ? void 0 : sparseBefore[head];
38
- if (typeof val === "undefined") {
39
- delete before[mask];
40
- }
41
- else {
42
- before[mask] = val;
43
- }
44
- }
45
- return before;
5
+ const before = { ...after };
6
+ const masks = fieldMask.split(",");
7
+ for (const mask of masks) {
8
+ const parts = mask.split(".");
9
+ const head = parts[0];
10
+ const tail = parts.slice(1).join(".");
11
+ if (parts.length > 1) {
12
+ before[head] = applyFieldMask(sparseBefore?.[head], after[head], tail);
13
+ continue;
14
+ }
15
+ const val = sparseBefore?.[head];
16
+ if (typeof val === "undefined") {
17
+ delete before[mask];
18
+ } else {
19
+ before[mask] = val;
20
+ }
21
+ }
22
+ return before;
46
23
  }
47
- exports.applyFieldMask = applyFieldMask;
48
24
  /**
49
- * The Cloud Functions interface for events that change state, such as
50
- * Realtime Database or Cloud Firestore `onWrite` and `onUpdate` events.
51
- *
52
- * For more information about the format used to construct `Change` objects, see
53
- * {@link ChangeJson} below.
54
- *
55
- */
56
- class Change {
57
- /**
58
- * Factory method for creating a `Change` from a `before` object and an `after`
59
- * object.
60
- */
61
- static fromObjects(before, after) {
62
- return new Change(before, after);
63
- }
64
- /**
65
- * Factory method for creating a `Change` from JSON and an optional customizer
66
- * function to be applied to both the `before` and the `after` fields.
67
- */
68
- static fromJSON(json, customizer = (x) => x) {
69
- let before = { ...json.before };
70
- if (json.fieldMask) {
71
- before = applyFieldMask(before, json.after, json.fieldMask);
72
- }
73
- return Change.fromObjects(customizer(before || {}), customizer(json.after || {}));
74
- }
75
- constructor(before, after) {
76
- this.before = before;
77
- this.after = after;
78
- }
79
- }
25
+ * The Cloud Functions interface for events that change state, such as
26
+ * Realtime Database or Cloud Firestore `onWrite` and `onUpdate` events.
27
+ *
28
+ * For more information about the format used to construct `Change` objects, see
29
+ * {@link ChangeJson} below.
30
+ *
31
+ */
32
+ var Change = class Change {
33
+ /**
34
+ * Factory method for creating a `Change` from a `before` object and an `after`
35
+ * object.
36
+ */
37
+ static fromObjects(before, after) {
38
+ return new Change(before, after);
39
+ }
40
+ /**
41
+ * Factory method for creating a `Change` from JSON and an optional customizer
42
+ * function to be applied to both the `before` and the `after` fields.
43
+ */
44
+ static fromJSON(json, customizer = (x) => x) {
45
+ let before = { ...json.before };
46
+ if (json.fieldMask) {
47
+ before = applyFieldMask(before, json.after, json.fieldMask);
48
+ }
49
+ return Change.fromObjects(customizer(before || {}), customizer(json.after || {}));
50
+ }
51
+ constructor(before, after) {
52
+ this.before = before;
53
+ this.after = after;
54
+ }
55
+ };
56
+
57
+ //#endregion
80
58
  exports.Change = Change;
59
+ exports.applyFieldMask = applyFieldMask;
@@ -1,49 +1,49 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.firebaseConfig = exports.resetCache = void 0;
4
- const fs_1 = require("fs");
5
- const path = require("path");
6
- const logger = require("../logger");
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
2
+ const require_logger_index = require('../logger/index.js');
3
+ let path = require("path");
4
+ path = require_rolldown_runtime.__toESM(path);
5
+ let fs = require("fs");
6
+ fs = require_rolldown_runtime.__toESM(fs);
7
+
8
+ //#region src/common/config.ts
7
9
  let cache = null;
8
10
  /**
9
- * @internal
10
- * @alpha
11
- */
11
+ * @internal
12
+ * @alpha
13
+ */
12
14
  function resetCache(newCache = null) {
13
- cache = newCache;
15
+ cache = newCache;
14
16
  }
15
- exports.resetCache = resetCache;
16
17
  /**
17
- * Get the fields you need to initialize a Firebase app
18
- * @alpha
19
- */
18
+ * Get the fields you need to initialize a Firebase app
19
+ * @alpha
20
+ */
20
21
  function firebaseConfig() {
21
- if (cache) {
22
- return cache;
23
- }
24
- let env = process.env.FIREBASE_CONFIG;
25
- if (env) {
26
- // Firebase Tools will always use a JSON blob in prod, but docs
27
- // explicitly state that the user can set the env to a file:
28
- // https://firebase.google.com/docs/admin/setup#initialize-without-parameters
29
- if (!env.startsWith("{")) {
30
- env = (0, fs_1.readFileSync)(path.join(process.env.PWD, env)).toString("utf8");
31
- }
32
- cache = JSON.parse(env);
33
- return cache;
34
- }
35
- if (process.env.GCLOUD_PROJECT) {
36
- logger.warn("Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail");
37
- cache = {
38
- databaseURL: process.env.DATABASE_URL || `https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
39
- storageBucket: process.env.STORAGE_BUCKET_URL || `${process.env.GCLOUD_PROJECT}.appspot.com`,
40
- projectId: process.env.GCLOUD_PROJECT,
41
- };
42
- return cache;
43
- }
44
- else {
45
- logger.warn("Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail");
46
- }
47
- return null;
22
+ if (cache) {
23
+ return cache;
24
+ }
25
+ let env = process.env.FIREBASE_CONFIG;
26
+ if (env) {
27
+ if (!env.startsWith("{")) {
28
+ env = fs.default.readFileSync(path.join(process.env.PWD, env)).toString("utf8");
29
+ }
30
+ cache = JSON.parse(env);
31
+ return cache;
32
+ }
33
+ if (process.env.GCLOUD_PROJECT) {
34
+ require_logger_index.warn("Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail");
35
+ cache = {
36
+ databaseURL: process.env.DATABASE_URL || `https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
37
+ storageBucket: process.env.STORAGE_BUCKET_URL || `${process.env.GCLOUD_PROJECT}.appspot.com`,
38
+ projectId: process.env.GCLOUD_PROJECT
39
+ };
40
+ return cache;
41
+ } else {
42
+ require_logger_index.warn("Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail");
43
+ }
44
+ return null;
48
45
  }
46
+
47
+ //#endregion
49
48
  exports.firebaseConfig = firebaseConfig;
49
+ exports.resetCache = resetCache;
@@ -1,54 +1,30 @@
1
- "use strict";
2
- // The MIT License (MIT)
3
- //
4
- // Copyright (c) 2021 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.isDebugFeatureEnabled = exports.debugFeatureValue = void 0;
25
- // Do NOT turn on a debug feature in production.
1
+
2
+ //#region src/common/debug.ts
26
3
  const debugMode = process.env.FIREBASE_DEBUG_MODE === "true";
27
4
  function loadDebugFeatures() {
28
- if (!debugMode) {
29
- return {};
30
- }
31
- try {
32
- const obj = JSON.parse(process.env.FIREBASE_DEBUG_FEATURES);
33
- if (typeof obj !== "object") {
34
- return {};
35
- }
36
- return obj;
37
- }
38
- catch (e) {
39
- return {};
40
- }
5
+ if (!debugMode) {
6
+ return {};
7
+ }
8
+ try {
9
+ const obj = JSON.parse(process.env.FIREBASE_DEBUG_FEATURES);
10
+ if (typeof obj !== "object") {
11
+ return {};
12
+ }
13
+ return obj;
14
+ } catch (_e) {
15
+ return {};
16
+ }
41
17
  }
42
- /* @internal */
43
18
  function debugFeatureValue(feat) {
44
- if (!debugMode) {
45
- return;
46
- }
47
- return loadDebugFeatures()[feat];
19
+ if (!debugMode) {
20
+ return;
21
+ }
22
+ return loadDebugFeatures()[feat];
48
23
  }
49
- exports.debugFeatureValue = debugFeatureValue;
50
- /* @internal */
51
24
  function isDebugFeatureEnabled(feat) {
52
- return debugMode && !!debugFeatureValue(feat);
25
+ return debugMode && !!debugFeatureValue(feat);
53
26
  }
54
- exports.isDebugFeatureEnabled = isDebugFeatureEnabled;
27
+
28
+ //#endregion
29
+ exports.debugFeatureValue = debugFeatureValue;
30
+ exports.isDebugFeatureEnabled = isDebugFeatureEnabled;