firebase-tools-with-isolate 13.16.0 → 13.26.0-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 (221) hide show
  1. package/lib/api.js +3 -1
  2. package/lib/apiv2.js +10 -3
  3. package/lib/appdistribution/client.js +62 -8
  4. package/lib/appdistribution/distribution.js +1 -1
  5. package/lib/apphosting/backend.js +299 -0
  6. package/lib/apphosting/config.js +31 -8
  7. package/lib/apphosting/githubConnections.js +70 -22
  8. package/lib/apphosting/index.js +3 -312
  9. package/lib/apphosting/rollout.js +138 -0
  10. package/lib/apphosting/secrets/index.js +70 -5
  11. package/lib/apphosting/utils.js +41 -0
  12. package/lib/apphosting/yaml.js +82 -0
  13. package/lib/archiveDirectory.js +1 -1
  14. package/lib/auth.js +31 -5
  15. package/lib/bin/firebase.js +2 -2
  16. package/lib/command.js +18 -4
  17. package/lib/commands/appdistribution-distribute.js +4 -4
  18. package/lib/commands/{appdistribution-group-create.js → appdistribution-groups-create.js} +2 -1
  19. package/lib/commands/{appdistribution-group-delete.js → appdistribution-groups-delete.js} +3 -2
  20. package/lib/commands/appdistribution-groups-list.js +55 -0
  21. package/lib/commands/appdistribution-testers-list.js +52 -0
  22. package/lib/commands/appdistribution-testers-remove.js +1 -1
  23. package/lib/commands/apphosting-backends-create.js +4 -4
  24. package/lib/commands/apphosting-backends-delete.js +7 -15
  25. package/lib/commands/apphosting-backends-get.js +1 -1
  26. package/lib/commands/apphosting-config-export.js +51 -0
  27. package/lib/commands/apphosting-repos-create.js +23 -0
  28. package/lib/commands/apphosting-rollouts-create.js +14 -15
  29. package/lib/commands/apphosting-secrets-grantaccess.js +2 -2
  30. package/lib/commands/database-import.js +4 -2
  31. package/lib/commands/database-push.js +4 -2
  32. package/lib/commands/database-set.js +4 -2
  33. package/lib/commands/database-settings-get.js +1 -1
  34. package/lib/commands/database-settings-set.js +1 -1
  35. package/lib/commands/dataconnect-sdk-generate.js +4 -1
  36. package/lib/commands/dataconnect-services-list.js +4 -3
  37. package/lib/commands/dataconnect-sql-diff.js +1 -1
  38. package/lib/commands/dataconnect-sql-grant.js +37 -0
  39. package/lib/commands/dataconnect-sql-migrate.js +1 -1
  40. package/lib/commands/dataconnect-sql-shell.js +115 -0
  41. package/lib/commands/deploy.js +2 -0
  42. package/lib/commands/emulators-start.js +4 -1
  43. package/lib/commands/ext-dev-init.js +2 -2
  44. package/lib/commands/ext-dev-list.js +1 -1
  45. package/lib/commands/ext-dev-register.js +2 -2
  46. package/lib/commands/ext-dev-upload.js +2 -2
  47. package/lib/commands/ext-dev-usage.js +2 -2
  48. package/lib/commands/ext-info.js +3 -1
  49. package/lib/commands/ext-install.js +2 -2
  50. package/lib/commands/ext-sdk-install.js +88 -0
  51. package/lib/commands/ext.js +1 -0
  52. package/lib/commands/firestore-databases-restore.js +39 -1
  53. package/lib/commands/functions-secrets-access.js +2 -4
  54. package/lib/commands/index.js +15 -2
  55. package/lib/commands/init.js +25 -15
  56. package/lib/commands/setup-emulators-dataconnect.js +0 -13
  57. package/lib/commands/use.js +1 -1
  58. package/lib/config.js +14 -4
  59. package/lib/crashlytics/buildToolsJarHelper.js +2 -2
  60. package/lib/dataconnect/client.js +1 -1
  61. package/lib/dataconnect/dataplaneClient.js +12 -9
  62. package/lib/dataconnect/ensureApis.js +6 -1
  63. package/lib/dataconnect/fileUtils.js +15 -39
  64. package/lib/dataconnect/freeTrial.js +45 -9
  65. package/lib/dataconnect/load.js +3 -1
  66. package/lib/dataconnect/provisionCloudSql.js +39 -26
  67. package/lib/dataconnect/schemaMigration.js +215 -74
  68. package/lib/dataconnect/types.js +4 -1
  69. package/lib/dataconnect/webhook.js +32 -0
  70. package/lib/deploy/dataconnect/deploy.js +18 -15
  71. package/lib/deploy/dataconnect/prepare.js +41 -0
  72. package/lib/deploy/dataconnect/release.js +16 -7
  73. package/lib/deploy/extensions/deploy.js +3 -1
  74. package/lib/deploy/extensions/deploymentSummary.js +7 -3
  75. package/lib/deploy/extensions/planner.js +44 -5
  76. package/lib/deploy/extensions/prepare.js +45 -73
  77. package/lib/deploy/extensions/release.js +11 -10
  78. package/lib/deploy/extensions/tasks.js +32 -21
  79. package/lib/deploy/firestore/prepare.js +9 -0
  80. package/lib/deploy/firestore/release.js +3 -6
  81. package/lib/deploy/functions/checkIam.js +7 -2
  82. package/lib/deploy/functions/ensure.js +11 -3
  83. package/lib/deploy/functions/prepare.js +32 -21
  84. package/lib/deploy/functions/prepareFunctionsUpload.js +15 -16
  85. package/lib/deploy/functions/release/planner.js +2 -1
  86. package/lib/deploy/functions/runtimes/discovery/index.js +6 -2
  87. package/lib/deploy/functions/runtimes/node/index.js +5 -0
  88. package/lib/deploy/functions/services/auth.js +34 -3
  89. package/lib/deploy/functions/services/index.js +2 -0
  90. package/lib/deploy/index.js +8 -5
  91. package/lib/deploy/lifecycleHooks.js +2 -1
  92. package/lib/emulator/apphosting/config.js +27 -0
  93. package/lib/emulator/apphosting/index.js +38 -0
  94. package/lib/emulator/apphosting/serve.js +50 -0
  95. package/lib/emulator/apphosting/utils.js +18 -0
  96. package/lib/emulator/auth/handlers.js +27 -0
  97. package/lib/emulator/auth/operations.js +41 -2
  98. package/lib/emulator/auth/state.js +2 -1
  99. package/lib/emulator/commandUtils.js +8 -3
  100. package/lib/emulator/constants.js +4 -1
  101. package/lib/emulator/controller.js +48 -5
  102. package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +11 -0
  103. package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +58 -0
  104. package/lib/emulator/dataconnect/pg-gateway/auth/index.js +22 -0
  105. package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +124 -0
  106. package/lib/emulator/dataconnect/pg-gateway/auth/password.js +54 -0
  107. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +34 -0
  108. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +270 -0
  109. package/lib/emulator/dataconnect/pg-gateway/auth/trust.js +2 -0
  110. package/lib/emulator/dataconnect/pg-gateway/backend-error.js +75 -0
  111. package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +54 -0
  112. package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +79 -0
  113. package/lib/emulator/dataconnect/pg-gateway/connection.js +315 -0
  114. package/lib/emulator/dataconnect/pg-gateway/connection.types.js +8 -0
  115. package/lib/emulator/dataconnect/pg-gateway/crypto.js +40 -0
  116. package/lib/emulator/dataconnect/pg-gateway/duplex.js +53 -0
  117. package/lib/emulator/dataconnect/pg-gateway/index.js +27 -0
  118. package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +82 -0
  119. package/lib/emulator/dataconnect/pg-gateway/message-codes.js +52 -0
  120. package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +16 -0
  121. package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +35 -0
  122. package/lib/emulator/dataconnect/pg-gateway/utils.js +40 -0
  123. package/lib/emulator/dataconnect/pgliteServer.js +95 -0
  124. package/lib/emulator/dataconnectEmulator.js +58 -75
  125. package/lib/emulator/dataconnectToolkitController.js +44 -0
  126. package/lib/emulator/downloadableEmulators.js +27 -16
  127. package/lib/emulator/emulatorLogger.js +3 -0
  128. package/lib/emulator/eventarcEmulator.js +1 -1
  129. package/lib/emulator/extensionsEmulator.js +38 -6
  130. package/lib/emulator/functionsEmulator.js +85 -41
  131. package/lib/emulator/functionsEmulatorShared.js +2 -1
  132. package/lib/emulator/functionsRuntimeWorker.js +2 -1
  133. package/lib/emulator/hub.js +13 -9
  134. package/lib/emulator/hubExport.js +10 -3
  135. package/lib/emulator/loggingEmulator.js +2 -2
  136. package/lib/emulator/portUtils.js +10 -11
  137. package/lib/emulator/registry.js +1 -0
  138. package/lib/emulator/storage/persistence.js +2 -2
  139. package/lib/emulator/storage/rules/runtime.js +1 -1
  140. package/lib/emulator/tasksEmulator.js +5 -2
  141. package/lib/emulator/types.js +3 -0
  142. package/lib/emulator/ui.js +51 -25
  143. package/lib/error.js +31 -1
  144. package/lib/experiments.js +5 -0
  145. package/lib/extensions/emulator/triggerHelper.js +1 -1
  146. package/lib/extensions/extensionsApi.js +14 -10
  147. package/lib/extensions/extensionsHelper.js +15 -6
  148. package/lib/extensions/localHelper.js +31 -0
  149. package/lib/extensions/runtimes/common.js +179 -39
  150. package/lib/extensions/runtimes/node.js +401 -0
  151. package/lib/extensions/types.js +25 -14
  152. package/lib/extensions/warnings.js +5 -2
  153. package/lib/firestore/api.js +2 -1
  154. package/lib/firestore/checkDatabaseType.js +10 -3
  155. package/lib/firestore/delete.js +11 -0
  156. package/lib/firestore/options.js +7 -0
  157. package/lib/frameworks/angular/index.js +15 -3
  158. package/lib/frameworks/constants.js +1 -1
  159. package/lib/frameworks/flutter/index.js +6 -6
  160. package/lib/frameworks/flutter/utils.js +34 -1
  161. package/lib/frameworks/next/index.js +10 -2
  162. package/lib/frameworks/next/utils.js +8 -5
  163. package/lib/frameworks/vite/index.js +2 -2
  164. package/lib/fsutils.js +13 -1
  165. package/lib/functions/constants.js +4 -0
  166. package/lib/functions/events/v1.js +9 -2
  167. package/lib/gcp/apphosting.js +1 -1
  168. package/lib/gcp/cloudmonitoring.js +3 -3
  169. package/lib/gcp/cloudsql/cloudsqladmin.js +32 -20
  170. package/lib/gcp/cloudsql/connect.js +49 -37
  171. package/lib/gcp/cloudsql/interactive.js +49 -0
  172. package/lib/gcp/cloudsql/permissions.js +165 -0
  173. package/lib/gcp/devConnect.js +38 -1
  174. package/lib/gcp/firestore.js +5 -1
  175. package/lib/gcp/secretManager.js +12 -5
  176. package/lib/getProjectNumber.js +1 -1
  177. package/lib/init/features/apphosting.js +15 -0
  178. package/lib/init/features/dataconnect/index.js +159 -120
  179. package/lib/init/features/dataconnect/sdk.js +77 -84
  180. package/lib/init/features/emulators.js +2 -15
  181. package/lib/init/features/firestore/index.js +20 -1
  182. package/lib/init/features/firestore/indexes.js +4 -4
  183. package/lib/init/features/genkit/index.js +444 -0
  184. package/lib/init/features/hosting/index.js +2 -2
  185. package/lib/init/features/index.js +1 -1
  186. package/lib/init/features/project.js +6 -6
  187. package/lib/init/features/storage.js +0 -2
  188. package/lib/init/index.js +1 -0
  189. package/lib/init/spawn.js +23 -2
  190. package/lib/logger.js +2 -2
  191. package/lib/management/projects.js +24 -4
  192. package/lib/projectUtils.js +1 -1
  193. package/lib/prompt.js +1 -1
  194. package/lib/rc.js +1 -8
  195. package/lib/requireAuth.js +19 -5
  196. package/lib/requireDatabaseInstance.js +1 -1
  197. package/lib/requirePermissions.js +1 -1
  198. package/lib/responseToError.js +5 -2
  199. package/lib/rulesDeploy.js +1 -1
  200. package/lib/templates.js +2 -2
  201. package/lib/utils.js +16 -11
  202. package/lib/vsCodeUtils.js +8 -0
  203. package/package.json +7 -6
  204. package/schema/connector-yaml.json +57 -17
  205. package/schema/firebase-config.json +24 -0
  206. package/templates/extensions/javascript/package.lint.json +2 -2
  207. package/templates/extensions/javascript/package.nolint.json +2 -2
  208. package/templates/extensions/typescript/package.lint.json +2 -2
  209. package/templates/extensions/typescript/package.nolint.json +2 -2
  210. package/templates/genkit/firebase.0.9.0.template +57 -0
  211. package/templates/init/apphosting/apphosting.yaml +23 -0
  212. package/templates/init/dataconnect/connector.yaml +0 -1
  213. package/templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml +12 -0
  214. package/templates/init/dataconnect/dataconnect.yaml +1 -1
  215. package/templates/init/dataconnect/queries.gql +1 -2
  216. package/templates/init/functions/javascript/package.lint.json +2 -2
  217. package/templates/init/functions/javascript/package.nolint.json +2 -2
  218. package/templates/init/functions/typescript/package.lint.json +2 -2
  219. package/templates/init/functions/typescript/package.nolint.json +2 -2
  220. package/lib/ensureCloudResourceLocation.js +0 -12
  221. package/lib/init/features/genkit.js +0 -53
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PGliteExtendedQueryPatch = exports.PostgresServer = void 0;
4
+ const pglite_1 = require("@electric-sql/pglite");
5
+ const { dynamicImport } = require(true && "../../dynamicImport");
6
+ const net = require("node:net");
7
+ const index_1 = require("./pg-gateway/index");
8
+ const node_1 = require("./pg-gateway/platforms/node");
9
+ const logger_1 = require("../../logger");
10
+ class PostgresServer {
11
+ async createPGServer(host = "127.0.0.1", port) {
12
+ const db = await this.getDb();
13
+ await db.waitReady;
14
+ const server = net.createServer(async (socket) => {
15
+ const connection = await (0, node_1.fromNodeSocket)(socket, {
16
+ serverVersion: "16.3 (PGlite 0.2.0)",
17
+ auth: { method: "trust" },
18
+ async onMessage(data, { isAuthenticated }) {
19
+ if (!isAuthenticated) {
20
+ return;
21
+ }
22
+ const result = await db.execProtocolRaw(data);
23
+ return extendedQueryPatch.filterResponse(data, result);
24
+ },
25
+ });
26
+ const extendedQueryPatch = new PGliteExtendedQueryPatch(connection);
27
+ socket.on("end", () => {
28
+ logger_1.logger.debug("Postgres client disconnected");
29
+ });
30
+ socket.on("error", (err) => {
31
+ server.emit("error", err);
32
+ });
33
+ });
34
+ const listeningPromise = new Promise((resolve) => {
35
+ server.listen(port, host, () => {
36
+ resolve();
37
+ });
38
+ });
39
+ await db.waitReady;
40
+ await listeningPromise;
41
+ return server;
42
+ }
43
+ async getDb() {
44
+ if (this.db) {
45
+ return this.db;
46
+ }
47
+ const vector = (await dynamicImport("@electric-sql/pglite/vector")).vector;
48
+ const uuidOssp = (await dynamicImport("@electric-sql/pglite/contrib/uuid_ossp")).uuid_ossp;
49
+ return pglite_1.PGlite.create({
50
+ username: this.username,
51
+ database: this.database,
52
+ debug: 0,
53
+ extensions: {
54
+ vector,
55
+ uuidOssp,
56
+ },
57
+ });
58
+ }
59
+ constructor(database, username) {
60
+ this.username = username;
61
+ this.database = database;
62
+ }
63
+ }
64
+ exports.PostgresServer = PostgresServer;
65
+ class PGliteExtendedQueryPatch {
66
+ constructor(connection) {
67
+ this.connection = connection;
68
+ this.isExtendedQuery = false;
69
+ }
70
+ async *filterResponse(message, response) {
71
+ const pipelineStartMessages = [
72
+ index_1.FrontendMessageCode.Parse,
73
+ index_1.FrontendMessageCode.Bind,
74
+ index_1.FrontendMessageCode.Close,
75
+ ];
76
+ if (pipelineStartMessages.includes(message[0])) {
77
+ this.isExtendedQuery = true;
78
+ }
79
+ if (message[0] === index_1.FrontendMessageCode.Sync) {
80
+ this.isExtendedQuery = false;
81
+ return this.connection.createReadyForQuery();
82
+ }
83
+ for await (const message of (0, index_1.getMessages)(response)) {
84
+ if (message[0] === index_1.BackendMessageCode.ErrorMessage) {
85
+ this.isExtendedQuery = false;
86
+ }
87
+ if (this.isExtendedQuery && message[0] === index_1.BackendMessageCode.ReadyForQuery) {
88
+ logger_1.logger.debug("Filtered out a ReadyForQuery.");
89
+ continue;
90
+ }
91
+ yield message;
92
+ }
93
+ }
94
+ }
95
+ exports.PGliteExtendedQueryPatch = PGliteExtendedQueryPatch;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkIfDataConnectEmulatorRunningOnAddress = exports.DataConnectEmulatorClient = exports.DataConnectEmulator = exports.dataConnectEmulatorEvents = void 0;
3
+ exports.DataConnectEmulatorClient = exports.DataConnectEmulator = exports.dataConnectEmulatorEvents = void 0;
4
4
  const childProcess = require("child_process");
5
+ const events_1 = require("events");
5
6
  const clc = require("colorette");
6
7
  const api_1 = require("../api");
7
8
  const constants_1 = require("./constants");
@@ -11,12 +12,12 @@ const error_1 = require("../error");
11
12
  const emulatorLogger_1 = require("./emulatorLogger");
12
13
  const types_2 = require("../dataconnect/types");
13
14
  const portUtils_1 = require("./portUtils");
14
- const apiv2_1 = require("../apiv2");
15
15
  const registry_1 = require("./registry");
16
16
  const logger_1 = require("../logger");
17
17
  const load_1 = require("../dataconnect/load");
18
+ const pgliteServer_1 = require("./dataconnect/pgliteServer");
19
+ const controller_1 = require("./controller");
18
20
  const utils_1 = require("../utils");
19
- const events_1 = require("events");
20
21
  exports.dataConnectEmulatorEvents = new events_1.EventEmitter();
21
22
  class DataConnectEmulator {
22
23
  constructor(args) {
@@ -32,48 +33,65 @@ class DataConnectEmulator {
32
33
  const info = await DataConnectEmulator.build({ configDir: resolvedConfigDir });
33
34
  if ((0, types_2.requiresVector)(info.metadata)) {
34
35
  if (constants_1.Constants.isDemoProject(this.args.projectId)) {
35
- this.logger.logLabeled("WARN", "Data Connect", "Detected a 'demo-' project, but vector embeddings require a real project. Operations that use vector_embed will fail.");
36
+ this.logger.logLabeled("WARN", "dataconnect", "Detected a 'demo-' project, but vector embeddings require a real project. Operations that use vector_embed will fail.");
36
37
  }
37
38
  else {
38
- this.logger.logLabeled("WARN", "Data Connect", "Operations that use vector_embed will make calls to production Vertex AI");
39
+ this.logger.logLabeled("WARN", "dataconnect", "Operations that use vector_embed will make calls to production Vertex AI");
39
40
  }
40
41
  }
41
42
  }
42
43
  catch (err) {
43
44
  this.logger.log("DEBUG", `'fdc build' failed with error: ${err.message}`);
44
45
  }
45
- const alreadyRunning = await this.discoverRunningInstance();
46
- if (alreadyRunning) {
47
- this.logger.logLabeled("INFO", "Data Connect", "Detected an instance of the emulator already running with your service, reusing it. This emulator will not be shut down at the end of this command.");
48
- this.usingExistingEmulator = true;
49
- this.watchUnmanagedInstance();
50
- }
51
- else {
52
- await (0, downloadableEmulators_1.start)(types_1.Emulators.DATACONNECT, {
53
- auto_download: this.args.auto_download,
54
- listen: (0, portUtils_1.listenSpecsToString)(this.args.listen),
55
- config_dir: resolvedConfigDir,
56
- enable_output_schema_extensions: true,
57
- enable_output_generated_sdk: true,
58
- });
59
- this.usingExistingEmulator = false;
60
- }
61
- if (!(0, utils_1.isVSCodeExtension)()) {
62
- await this.connectToPostgres();
46
+ await (0, downloadableEmulators_1.start)(types_1.Emulators.DATACONNECT, {
47
+ auto_download: this.args.auto_download,
48
+ listen: (0, portUtils_1.listenSpecsToString)(this.args.listen),
49
+ config_dir: resolvedConfigDir,
50
+ enable_output_schema_extensions: this.args.enable_output_schema_extensions,
51
+ enable_output_generated_sdk: this.args.enable_output_generated_sdk,
52
+ });
53
+ this.usingExistingEmulator = false;
54
+ if (this.args.autoconnectToPostgres) {
55
+ const info = await (0, load_1.load)(this.args.projectId, this.args.config, this.args.configDir);
56
+ const dbId = info.dataConnectYaml.schema.datasource.postgresql?.database || "postgres";
57
+ const serviceId = info.dataConnectYaml.serviceId;
58
+ const pgPort = this.args.postgresListen?.[0].port;
59
+ const pgHost = this.args.postgresListen?.[0].address;
60
+ let connStr = (0, api_1.dataConnectLocalConnString)();
61
+ if (connStr) {
62
+ this.logger.logLabeled("INFO", "dataconnect", `FIREBASE_DATACONNECT_POSTGRESQL_STRING is set to ${clc.bold(connStr)} - using that instead of starting a new database`);
63
+ }
64
+ else if (pgHost && pgPort) {
65
+ const pgServer = new pgliteServer_1.PostgresServer(dbId, "postgres");
66
+ const server = await pgServer.createPGServer(pgHost, pgPort);
67
+ const connectableHost = (0, utils_1.connectableHostname)(pgHost);
68
+ connStr = `postgres://${connectableHost}:${pgPort}/${dbId}?sslmode=disable`;
69
+ server.on("error", (err) => {
70
+ if (err instanceof error_1.FirebaseError) {
71
+ this.logger.logLabeled("ERROR", "Data Connect", `${err}`);
72
+ }
73
+ else {
74
+ this.logger.logLabeled("ERROR", "dataconnect", `Postgres threw an unexpected error, shutting down the Data Connect emulator: ${err}`);
75
+ }
76
+ void (0, controller_1.cleanShutdown)();
77
+ });
78
+ this.logger.logLabeled("INFO", "dataconnect", `Started up Postgres server, listening on ${JSON.stringify(server.address())}`);
79
+ }
80
+ await this.connectToPostgres(new URL(connStr), dbId, serviceId);
63
81
  }
64
82
  return;
65
83
  }
66
84
  async connect() {
67
85
  const emuInfo = await this.emulatorClient.getInfo();
68
86
  if (!emuInfo) {
69
- this.logger.logLabeled("ERROR", "Data Connect", "Could not connect to Data Connect emulator. Check dataconnect-debug.log for more details.");
87
+ this.logger.logLabeled("ERROR", "dataconnect", "Could not connect to Data Connect emulator. Check dataconnect-debug.log for more details.");
70
88
  return Promise.reject();
71
89
  }
72
90
  return Promise.resolve();
73
91
  }
74
92
  async stop() {
75
93
  if (this.usingExistingEmulator) {
76
- this.logger.logLabeled("INFO", "Data Connect", "Skipping cleanup of Data Connect emulator, as it was not started by this process.");
94
+ this.logger.logLabeled("INFO", "dataconnect", "Skipping cleanup of Data Connect emulator, as it was not started by this process.");
77
95
  return;
78
96
  }
79
97
  return (0, downloadableEmulators_1.stop)(types_1.Emulators.DATACONNECT);
@@ -100,6 +118,9 @@ class DataConnectEmulator {
100
118
  `--config_dir=${args.configDir}`,
101
119
  `--connector_id=${args.connectorId}`,
102
120
  ];
121
+ if (args.watch) {
122
+ cmd.push("--watch");
123
+ }
103
124
  const res = childProcess.spawnSync(commandInfo.binary, cmd, { encoding: "utf-8" });
104
125
  logger_1.logger.info(res.stderr);
105
126
  if (res.error) {
@@ -134,53 +155,23 @@ class DataConnectEmulator {
134
155
  throw new error_1.FirebaseError(`Unable to parse 'fdc build' output: ${res.stdout ?? res.stderr}`);
135
156
  }
136
157
  }
137
- getLocalConectionString() {
138
- if ((0, api_1.dataConnectLocalConnString)()) {
139
- return (0, api_1.dataConnectLocalConnString)();
140
- }
141
- return this.args.rc.getDataconnect()?.postgres?.localConnectionString;
142
- }
143
- async discoverRunningInstance() {
144
- const emuInfo = await this.emulatorClient.getInfo();
145
- if (!emuInfo) {
146
- return false;
147
- }
148
- const serviceInfo = await (0, load_1.load)(this.args.projectId, this.args.config, this.args.configDir);
149
- const sameService = emuInfo.services.find((s) => serviceInfo.dataConnectYaml.serviceId === s.serviceId);
150
- if (!sameService) {
151
- throw new error_1.FirebaseError(`There is a Data Connect emulator already running on ${this.args.listen[0].address}:${this.args.listen[0].port}, but it is emulating a different service. Please stop that instance of the Data Connect emulator, or specify a different port in 'firebase.json'`);
152
- }
153
- if (sameService.connectionString &&
154
- sameService.connectionString !== this.getLocalConectionString()) {
155
- throw new error_1.FirebaseError(`There is a Data Connect emulator already running, but it is using a different Postgres connection string. Please stop that instance of the Data Connect emulator, or specify a different port in 'firebase.json'`);
156
- }
157
- return true;
158
- }
159
- watchUnmanagedInstance() {
160
- return setInterval(async () => {
161
- if (!this.usingExistingEmulator) {
162
- return;
163
- }
164
- const emuInfo = await this.emulatorClient.getInfo();
165
- if (!emuInfo) {
166
- this.logger.logLabeled("INFO", "Data Connect", "The already running emulator seems to have shut down. Starting a new instance of the Data Connect emulator...");
167
- await this.start();
168
- exports.dataConnectEmulatorEvents.emit("restart");
169
- }
170
- }, 5000);
171
- }
172
- async connectToPostgres(localConnectionString, database, serviceId) {
173
- const connectionString = localConnectionString ?? this.getLocalConectionString();
158
+ async connectToPostgres(connectionString, database, serviceId) {
174
159
  if (!connectionString) {
175
- const msg = `No Postgres connection string found in '.firebaserc'. The Data Connect emulator will not be able to execute operations.
176
- Run ${clc.bold("firebase setup:emulators:dataconnect")} to set up a Postgres connection.`;
160
+ const msg = `No Postgres connection found. The Data Connect emulator will not be able to execute operations.`;
177
161
  throw new error_1.FirebaseError(msg);
178
162
  }
179
163
  const MAX_RETRIES = 3;
180
164
  for (let i = 1; i <= MAX_RETRIES; i++) {
181
165
  try {
182
- this.logger.logLabeled("DEBUG", "Data Connect", `Connecting to ${connectionString}}`);
183
- await this.emulatorClient.configureEmulator({ connectionString, database, serviceId });
166
+ this.logger.logLabeled("DEBUG", "Data Connect", `Connecting to ${connectionString}}...`);
167
+ connectionString.toString();
168
+ await this.emulatorClient.configureEmulator({
169
+ connectionString: connectionString.toString(),
170
+ database,
171
+ serviceId,
172
+ maxOpenConnections: 1,
173
+ });
174
+ this.logger.logLabeled("DEBUG", "Data Connect", `Successfully connected to ${connectionString}}`);
184
175
  return true;
185
176
  }
186
177
  catch (err) {
@@ -188,7 +179,7 @@ Run ${clc.bold("firebase setup:emulators:dataconnect")} to set up a Postgres con
188
179
  throw err;
189
180
  }
190
181
  this.logger.logLabeled("DEBUG", "Data Connect", `Retrying connectToPostgress call (${i} of ${MAX_RETRIES} attempts): ${err}`);
191
- await new Promise((resolve) => setTimeout(resolve, 800));
182
+ await new Promise((resolve) => setTimeout(resolve, 2000));
192
183
  }
193
184
  }
194
185
  return false;
@@ -222,14 +213,6 @@ class DataConnectEmulatorClient {
222
213
  }
223
214
  }
224
215
  exports.DataConnectEmulatorClient = DataConnectEmulatorClient;
225
- async function checkIfDataConnectEmulatorRunningOnAddress(l) {
226
- const client = new apiv2_1.Client({
227
- urlPrefix: `http:/${l.family === "IPv6" ? `[${l.address}]` : l.address}:${l.port}`,
228
- auth: false,
229
- });
230
- return getInfo(client);
231
- }
232
- exports.checkIfDataConnectEmulatorRunningOnAddress = checkIfDataConnectEmulatorRunningOnAddress;
233
216
  async function getInfo(client) {
234
217
  try {
235
218
  const res = await client.get("emulator/info");
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataConnectToolkitController = void 0;
4
+ const error_1 = require("../error");
5
+ const portUtils = require("./portUtils");
6
+ const utils_1 = require("../utils");
7
+ const dataconnectEmulator_1 = require("./dataconnectEmulator");
8
+ const name = "Data Connect Toolkit";
9
+ class DataConnectToolkitController {
10
+ static async start(args) {
11
+ if (this.isRunning || this.instance) {
12
+ throw new error_1.FirebaseError(`${name} is already running!`, {});
13
+ }
14
+ this.instance = new dataconnectEmulator_1.DataConnectEmulator(args);
15
+ this.isRunning = true;
16
+ await this.instance.start();
17
+ const info = this.instance.getInfo();
18
+ await portUtils.waitForPortUsed(info.port, (0, utils_1.connectableHostname)(info.host), info.timeout);
19
+ }
20
+ static async stop() {
21
+ if (!this.isRunning) {
22
+ return;
23
+ }
24
+ try {
25
+ await this.instance.stop();
26
+ this.isRunning = false;
27
+ }
28
+ catch (e) {
29
+ throw new error_1.FirebaseError(`Data Connect Toolkit failed to stop with error: ${e}`);
30
+ }
31
+ }
32
+ static getInfo() {
33
+ return this.instance.getInfo();
34
+ }
35
+ static getUrl() {
36
+ const info = this.instance.getInfo();
37
+ if (info.host.includes(":")) {
38
+ return `http://[${info.host}]:${info.port}`;
39
+ }
40
+ return `http://${info.host}:${info.port}`;
41
+ }
42
+ }
43
+ exports.DataConnectToolkitController = DataConnectToolkitController;
44
+ DataConnectToolkitController.isRunning = false;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.start = exports.downloadIfNecessary = exports.stop = exports.getPID = exports.get = exports.getDownloadDetails = exports.requiresJava = exports.handleEmulatorProcessError = exports._getCommand = exports.getLogFileName = exports.DownloadDetails = void 0;
4
+ const lsofi = require("lsofi");
4
5
  const types_1 = require("./types");
5
6
  const constants_1 = require("./constants");
6
7
  const error_1 = require("../error");
@@ -14,6 +15,7 @@ const os = require("os");
14
15
  const registry_1 = require("./registry");
15
16
  const download_1 = require("../emulator/download");
16
17
  const experiments = require("../experiments");
18
+ const process = require("process");
17
19
  const EMULATOR_INSTANCE_KILL_TIMEOUT = 4000;
18
20
  const CACHE_DIR = process.env.FIREBASE_EMULATORS_PATH || path.join(os.homedir(), ".cache", "firebase", "emulators");
19
21
  const EMULATOR_UPDATE_DETAILS = {
@@ -35,9 +37,9 @@ const EMULATOR_UPDATE_DETAILS = {
35
37
  ui: experiments.isEnabled("emulatoruisnapshot")
36
38
  ? { version: "SNAPSHOT", expectedSize: -1, expectedChecksum: "" }
37
39
  : {
38
- version: "1.13.0",
39
- expectedSize: 3605485,
40
- expectedChecksum: "ec0aa91592c56af9ff7df18168d58459",
40
+ version: "1.14.0",
41
+ expectedSize: 3615311,
42
+ expectedChecksum: "30763ff4a8b81e2c482f05b56799b5c0",
41
43
  },
42
44
  pubsub: {
43
45
  version: "0.8.14",
@@ -46,20 +48,20 @@ const EMULATOR_UPDATE_DETAILS = {
46
48
  },
47
49
  dataconnect: process.platform === "darwin"
48
50
  ? {
49
- version: "1.3.5",
50
- expectedSize: 24232704,
51
- expectedChecksum: "4eabf613a4a5feeaa173e1375b62bde0",
51
+ version: "1.7.3",
52
+ expectedSize: 25211648,
53
+ expectedChecksum: "8410794304b2ae340c3facf07d7edc16",
52
54
  }
53
55
  : process.platform === "win32"
54
56
  ? {
55
- version: "1.3.5",
56
- expectedSize: 24651264,
57
- expectedChecksum: "c7b2b7168ff7226f4e5626ae7d13e0ca",
57
+ version: "1.7.3",
58
+ expectedSize: 25641984,
59
+ expectedChecksum: "a4bd0f9d9d884528fa4494e4d7918c08",
58
60
  }
59
61
  : {
60
- version: "1.3.5",
61
- expectedSize: 24146072,
62
- expectedChecksum: "1457937751ce25fa332cdc16b561d64b",
62
+ version: "1.7.3",
63
+ expectedSize: 25125016,
64
+ expectedChecksum: "48660e6370aeed973f33c3420c3255fb",
63
65
  },
64
66
  };
65
67
  exports.DownloadDetails = {
@@ -231,8 +233,8 @@ const Commands = {
231
233
  shell: true,
232
234
  },
233
235
  ui: {
234
- binary: "node",
235
- args: [getExecPath(types_1.Emulators.UI)],
236
+ binary: "",
237
+ args: [],
236
238
  optionalArgs: [],
237
239
  joinArgs: false,
238
240
  shell: false,
@@ -295,6 +297,7 @@ function _getCommand(emulator, args) {
295
297
  optionalArgs: baseCmd.optionalArgs,
296
298
  joinArgs: baseCmd.joinArgs,
297
299
  shell: baseCmd.shell,
300
+ port: args.port,
298
301
  };
299
302
  }
300
303
  exports._getCommand = _getCommand;
@@ -308,11 +311,15 @@ async function _fatal(emulator, errorMsg) {
308
311
  process.exit(1);
309
312
  }
310
313
  }
311
- async function handleEmulatorProcessError(emulator, err) {
314
+ async function handleEmulatorProcessError(emulator, err, port) {
312
315
  const description = constants_1.Constants.description(emulator);
313
316
  if (err.path === "java" && err.code === "ENOENT") {
314
317
  await _fatal(emulator, `${description} has exited because java is not installed, you can install it from https://openjdk.java.net/install/`);
315
318
  }
319
+ else if (err.code === "EADDRINUSE") {
320
+ const ps = port ? await lsofi(port) : false;
321
+ await _fatal(emulator, `${description} has exited because its configured port is already in use${ps ? ` by process number ${ps}` : ""}. Are you running another copy of the emulator suite?`);
322
+ }
316
323
  else {
317
324
  await _fatal(emulator, `${description} has exited: ${err}`);
318
325
  }
@@ -365,9 +372,13 @@ async function _runBinary(emulator, command, extraEnv) {
365
372
  if (data.toString().includes("java.lang.UnsupportedClassVersionError")) {
366
373
  logger.logLabeled("WARN", emulator.name, "Unsupported java version, make sure java --version reports 1.8 or higher.");
367
374
  }
375
+ if (data.toString().includes("address already in use")) {
376
+ const message = `${description} has exited because its configured port ${command.port} is already in use. Are you running another copy of the emulator suite?`;
377
+ logger.logLabeled("ERROR", emulator.name, message);
378
+ }
368
379
  });
369
380
  emulator.instance.on("error", (err) => {
370
- handleEmulatorProcessError(emulator.name, err);
381
+ void handleEmulatorProcessError(emulator.name, err, command.port);
371
382
  });
372
383
  emulator.instance.once("exit", async (code, signal) => {
373
384
  if (signal) {
@@ -225,6 +225,9 @@ You can probably fix this by running "npm install ${systemLog.data.name}@latest"
225
225
  case "BULLET":
226
226
  utils.logLabeledBullet(label, text, "info", mergedData);
227
227
  break;
228
+ case "INFO":
229
+ utils.logLabeledBullet(label, text, "info", mergedData);
230
+ break;
228
231
  case "SUCCESS":
229
232
  utils.logLabeledSuccess(label, text, "info", mergedData);
230
233
  break;
@@ -53,7 +53,7 @@ class EventarcEmulator {
53
53
  const key = `${eventTrigger.eventType}-${channel}`;
54
54
  return { projectId, triggerName, eventTrigger, key };
55
55
  };
56
- const removeTriggerRoute = `/emulator/v1/remove/projects/:project_id/triggers/:trigger_name`;
56
+ const removeTriggerRoute = `/emulator/v1/remove/projects/:project_id/triggers/:trigger_name(*)`;
57
57
  const removeTriggerHandler = (req, res) => {
58
58
  try {
59
59
  const { projectId, triggerName, eventTrigger, key } = getTriggerIdentifiers(req);
@@ -19,10 +19,14 @@ const emulatorLogger_1 = require("./emulatorLogger");
19
19
  const validation_1 = require("./extensions/validation");
20
20
  const registry_1 = require("./registry");
21
21
  const types_1 = require("./types");
22
+ const common_1 = require("../extensions/runtimes/common");
22
23
  class ExtensionsEmulator {
23
24
  constructor(args) {
24
25
  this.want = [];
26
+ this.wantDynamic = {};
25
27
  this.backends = [];
28
+ this.staticBackends = [];
29
+ this.dynamicBackends = {};
26
30
  this.logger = emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.EXTENSIONS);
27
31
  this.pendingDownloads = new Map();
28
32
  this.args = args;
@@ -127,12 +131,40 @@ class ExtensionsEmulator {
127
131
  this.logger.logLabeled("DEBUG", "Extensions", `Finished "npm run gcp-build" for ${sourceCodePath}`);
128
132
  }
129
133
  async getExtensionBackends() {
134
+ this.backends = await this.getStaticExtensionBackends();
135
+ for (const backends of Object.values(this.dynamicBackends)) {
136
+ this.backends.push(...backends);
137
+ }
138
+ return this.backends;
139
+ }
140
+ async getStaticExtensionBackends() {
130
141
  await this.readManifest();
131
142
  await this.checkAndWarnAPIs(this.want);
132
- this.backends = await Promise.all(this.want.map((i) => {
143
+ this.staticBackends = await Promise.all(this.want.map((i) => {
133
144
  return this.toEmulatableBackend(i);
134
145
  }));
135
- return this.backends;
146
+ return this.staticBackends;
147
+ }
148
+ getDynamicExtensionBackends() {
149
+ const dynamicBackends = [];
150
+ for (const backends of Object.values(this.dynamicBackends)) {
151
+ dynamicBackends.push(...backends);
152
+ }
153
+ return dynamicBackends;
154
+ }
155
+ async addDynamicExtensions(codebase, build) {
156
+ const extensions = (0, common_1.extractExtensionsFromBuilds)({ build });
157
+ this.wantDynamic[codebase] = await planner.wantDynamic({
158
+ projectId: this.args.projectId,
159
+ projectNumber: this.args.projectNumber,
160
+ extensions,
161
+ emulatorMode: true,
162
+ });
163
+ await this.checkAndWarnAPIs(this.wantDynamic[codebase]);
164
+ this.dynamicBackends[codebase] = await Promise.all(this.wantDynamic[codebase].map((i) => {
165
+ return this.toEmulatableBackend(i);
166
+ }));
167
+ await this.getExtensionBackends();
136
168
  }
137
169
  async toEmulatableBackend(instance) {
138
170
  const extensionDir = await this.ensureSourceCode(instance);
@@ -204,10 +236,10 @@ class ExtensionsEmulator {
204
236
  }
205
237
  }
206
238
  }
207
- filterUnemulatedTriggers(options, backends) {
239
+ filterUnemulatedTriggers(backends) {
208
240
  let foundUnemulatedTrigger = false;
209
241
  const filteredBackends = backends.filter((backend) => {
210
- const unemulatedServices = (0, validation_1.checkForUnemulatedTriggerTypes)(backend, options);
242
+ const unemulatedServices = (0, validation_1.checkForUnemulatedTriggerTypes)(backend, this.args.options);
211
243
  if (unemulatedServices.length) {
212
244
  foundUnemulatedTrigger = true;
213
245
  const msg = ` ignored becuase it includes ${unemulatedServices.join(", ")} triggered functions, and the ${unemulatedServices.join(", ")} emulator does not exist or is not running.`;
@@ -229,8 +261,8 @@ class ExtensionsEmulator {
229
261
  uiUrl.pathname = `/${types_1.Emulators.EXTENSIONS}/${backend.extensionInstanceId}`;
230
262
  return clc.underline(clc.bold(uiUrl.toString()));
231
263
  }
232
- extensionsInfoTable(options) {
233
- const filtedBackends = this.filterUnemulatedTriggers(options, this.backends);
264
+ extensionsInfoTable() {
265
+ const filtedBackends = this.filterUnemulatedTriggers(this.backends);
234
266
  const uiRunning = registry_1.EmulatorRegistry.isRunning(types_1.Emulators.UI);
235
267
  const tableHead = ["Extension Instance Name", "Extension Ref"];
236
268
  if (uiRunning) {