firebase-tools-with-isolate 13.15.0-0 → 13.26.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 (235) 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 +5 -1
  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 +3 -2
  61. package/lib/dataconnect/dataplaneClient.js +12 -9
  62. package/lib/dataconnect/ensureApis.js +6 -1
  63. package/lib/dataconnect/fileUtils.js +29 -12
  64. package/lib/dataconnect/freeTrial.js +45 -9
  65. package/lib/dataconnect/load.js +3 -1
  66. package/lib/dataconnect/provisionCloudSql.js +41 -24
  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 +95 -5
  76. package/lib/deploy/extensions/prepare.js +89 -42
  77. package/lib/deploy/extensions/release.js +17 -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/build.js +5 -5
  82. package/lib/deploy/functions/checkIam.js +7 -2
  83. package/lib/deploy/functions/deploy.js +12 -12
  84. package/lib/deploy/functions/ensure.js +11 -3
  85. package/lib/deploy/functions/params.js +5 -3
  86. package/lib/deploy/functions/prepare.js +18 -3
  87. package/lib/deploy/functions/release/index.js +4 -0
  88. package/lib/deploy/functions/release/planner.js +2 -1
  89. package/lib/deploy/functions/runtimes/discovery/index.js +6 -2
  90. package/lib/deploy/functions/runtimes/discovery/parsing.js +1 -1
  91. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +46 -0
  92. package/lib/deploy/functions/runtimes/node/index.js +5 -0
  93. package/lib/deploy/functions/services/auth.js +34 -3
  94. package/lib/deploy/functions/services/index.js +2 -0
  95. package/lib/deploy/index.js +8 -5
  96. package/lib/deploy/lifecycleHooks.js +2 -1
  97. package/lib/emulator/apphosting/config.js +27 -0
  98. package/lib/emulator/apphosting/index.js +38 -0
  99. package/lib/emulator/apphosting/serve.js +50 -0
  100. package/lib/emulator/apphosting/utils.js +18 -0
  101. package/lib/emulator/auth/handlers.js +27 -0
  102. package/lib/emulator/auth/operations.js +41 -2
  103. package/lib/emulator/auth/state.js +2 -1
  104. package/lib/emulator/commandUtils.js +8 -3
  105. package/lib/emulator/constants.js +11 -1
  106. package/lib/emulator/controller.js +59 -6
  107. package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +11 -0
  108. package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +58 -0
  109. package/lib/emulator/dataconnect/pg-gateway/auth/index.js +22 -0
  110. package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +124 -0
  111. package/lib/emulator/dataconnect/pg-gateway/auth/password.js +54 -0
  112. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +34 -0
  113. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +270 -0
  114. package/lib/emulator/dataconnect/pg-gateway/auth/trust.js +2 -0
  115. package/lib/emulator/dataconnect/pg-gateway/backend-error.js +75 -0
  116. package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +54 -0
  117. package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +79 -0
  118. package/lib/emulator/dataconnect/pg-gateway/connection.js +315 -0
  119. package/lib/emulator/dataconnect/pg-gateway/connection.types.js +8 -0
  120. package/lib/emulator/dataconnect/pg-gateway/crypto.js +40 -0
  121. package/lib/emulator/dataconnect/pg-gateway/duplex.js +53 -0
  122. package/lib/emulator/dataconnect/pg-gateway/index.js +27 -0
  123. package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +82 -0
  124. package/lib/emulator/dataconnect/pg-gateway/message-codes.js +52 -0
  125. package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +16 -0
  126. package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +35 -0
  127. package/lib/emulator/dataconnect/pg-gateway/utils.js +40 -0
  128. package/lib/emulator/dataconnect/pgliteServer.js +95 -0
  129. package/lib/emulator/dataconnectEmulator.js +58 -75
  130. package/lib/emulator/dataconnectToolkitController.js +44 -0
  131. package/lib/emulator/downloadableEmulators.js +30 -19
  132. package/lib/emulator/emulatorLogger.js +3 -0
  133. package/lib/emulator/env.js +3 -0
  134. package/lib/emulator/eventarcEmulator.js +1 -1
  135. package/lib/emulator/extensionsEmulator.js +38 -6
  136. package/lib/emulator/functionsEmulator.js +115 -42
  137. package/lib/emulator/functionsEmulatorShared.js +18 -1
  138. package/lib/emulator/functionsRuntimeWorker.js +2 -1
  139. package/lib/emulator/hub.js +13 -9
  140. package/lib/emulator/hubExport.js +10 -3
  141. package/lib/emulator/loggingEmulator.js +2 -2
  142. package/lib/emulator/portUtils.js +11 -11
  143. package/lib/emulator/registry.js +2 -0
  144. package/lib/emulator/storage/persistence.js +2 -2
  145. package/lib/emulator/storage/rules/runtime.js +1 -1
  146. package/lib/emulator/taskQueue.js +348 -0
  147. package/lib/emulator/tasksEmulator.js +240 -0
  148. package/lib/emulator/types.js +6 -0
  149. package/lib/emulator/ui.js +51 -25
  150. package/lib/error.js +31 -1
  151. package/lib/experiments.js +5 -0
  152. package/lib/extensions/askUserForEventsConfig.js +18 -8
  153. package/lib/extensions/askUserForParam.js +2 -1
  154. package/lib/extensions/displayExtensionInfo.js +5 -5
  155. package/lib/extensions/emulator/triggerHelper.js +1 -1
  156. package/lib/extensions/extensionsApi.js +15 -11
  157. package/lib/extensions/extensionsHelper.js +39 -8
  158. package/lib/extensions/localHelper.js +32 -1
  159. package/lib/extensions/refs.js +26 -11
  160. package/lib/extensions/runtimes/common.js +215 -0
  161. package/lib/extensions/runtimes/node.js +401 -0
  162. package/lib/extensions/types.js +67 -1
  163. package/lib/extensions/warnings.js +5 -2
  164. package/lib/firestore/api.js +2 -1
  165. package/lib/firestore/checkDatabaseType.js +10 -3
  166. package/lib/firestore/delete.js +11 -0
  167. package/lib/firestore/options.js +7 -0
  168. package/lib/frameworks/angular/index.js +15 -3
  169. package/lib/frameworks/constants.js +2 -2
  170. package/lib/frameworks/flutter/index.js +6 -6
  171. package/lib/frameworks/flutter/utils.js +34 -1
  172. package/lib/frameworks/next/constants.js +1 -1
  173. package/lib/frameworks/next/index.js +45 -17
  174. package/lib/frameworks/next/utils.js +57 -4
  175. package/lib/frameworks/vite/index.js +2 -2
  176. package/lib/fsutils.js +13 -1
  177. package/lib/functions/constants.js +4 -0
  178. package/lib/functions/events/v1.js +9 -2
  179. package/lib/gcp/apphosting.js +1 -1
  180. package/lib/gcp/cloudmonitoring.js +3 -3
  181. package/lib/gcp/cloudsql/cloudsqladmin.js +32 -20
  182. package/lib/gcp/cloudsql/connect.js +49 -37
  183. package/lib/gcp/cloudsql/interactive.js +49 -0
  184. package/lib/gcp/cloudsql/permissions.js +165 -0
  185. package/lib/gcp/devConnect.js +38 -1
  186. package/lib/gcp/firestore.js +5 -1
  187. package/lib/gcp/secretManager.js +12 -5
  188. package/lib/getProjectNumber.js +1 -1
  189. package/lib/init/features/apphosting.js +15 -0
  190. package/lib/init/features/dataconnect/index.js +166 -121
  191. package/lib/init/features/dataconnect/sdk.js +90 -81
  192. package/lib/init/features/emulators.js +2 -15
  193. package/lib/init/features/firestore/index.js +20 -1
  194. package/lib/init/features/firestore/indexes.js +4 -4
  195. package/lib/init/features/genkit/index.js +444 -0
  196. package/lib/init/features/hosting/index.js +2 -2
  197. package/lib/init/features/index.js +1 -1
  198. package/lib/init/features/project.js +6 -6
  199. package/lib/init/features/storage.js +0 -2
  200. package/lib/init/index.js +1 -0
  201. package/lib/init/spawn.js +23 -2
  202. package/lib/logger.js +2 -2
  203. package/lib/management/projects.js +24 -4
  204. package/lib/projectUtils.js +1 -1
  205. package/lib/prompt.js +22 -1
  206. package/lib/rc.js +1 -8
  207. package/lib/requireAuth.js +19 -5
  208. package/lib/requireDatabaseInstance.js +1 -1
  209. package/lib/requirePermissions.js +1 -1
  210. package/lib/responseToError.js +5 -2
  211. package/lib/rulesDeploy.js +1 -1
  212. package/lib/templates.js +2 -2
  213. package/lib/utils.js +16 -11
  214. package/lib/vsCodeUtils.js +8 -0
  215. package/package.json +8 -7
  216. package/schema/connector-yaml.json +57 -17
  217. package/schema/firebase-config.json +36 -0
  218. package/templates/extensions/javascript/package.lint.json +2 -2
  219. package/templates/extensions/javascript/package.nolint.json +2 -2
  220. package/templates/extensions/typescript/package.lint.json +2 -2
  221. package/templates/extensions/typescript/package.nolint.json +2 -2
  222. package/templates/genkit/firebase.0.9.0.template +57 -0
  223. package/templates/init/apphosting/apphosting.yaml +23 -0
  224. package/templates/init/dataconnect/connector.yaml +4 -3
  225. package/templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml +12 -0
  226. package/templates/init/dataconnect/dataconnect.yaml +6 -6
  227. package/templates/init/dataconnect/mutations.gql +44 -29
  228. package/templates/init/dataconnect/queries.gql +65 -38
  229. package/templates/init/dataconnect/schema.gql +38 -21
  230. package/templates/init/functions/javascript/package.lint.json +2 -2
  231. package/templates/init/functions/javascript/package.nolint.json +2 -2
  232. package/templates/init/functions/typescript/package.lint.json +2 -2
  233. package/templates/init/functions/typescript/package.nolint.json +2 -2
  234. package/lib/ensureCloudResourceLocation.js +0 -12
  235. package/lib/init/features/genkit.js +0 -53
@@ -81,10 +81,13 @@ class FunctionsEmulator {
81
81
  this.logger = emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.FUNCTIONS);
82
82
  this.multicastTriggers = {};
83
83
  this.blockingFunctionsConfig = {};
84
+ this.staticBackends = [];
85
+ this.dynamicBackends = [];
84
86
  this.debugMode = false;
87
+ this.staticBackends = args.emulatableBackends;
85
88
  emulatorLogger_1.EmulatorLogger.setVerbosity(this.args.verbosity ? emulatorLogger_1.Verbosity[this.args.verbosity] : emulatorLogger_1.Verbosity["DEBUG"]);
86
89
  if (this.args.debugPort) {
87
- const maybeNodeCodebases = this.args.emulatableBackends.filter((b) => !b.runtime || b.runtime.startsWith("node"));
90
+ const maybeNodeCodebases = this.staticBackends.filter((b) => !b.runtime || b.runtime.startsWith("node"));
88
91
  if (maybeNodeCodebases.length > 1 && typeof this.args.debugPort === "number") {
89
92
  throw new error_1.FirebaseError("Cannot debug on a single port with multiple codebases. " +
90
93
  "Use --inspect-functions=true to assign dynamic ports to each codebase");
@@ -96,12 +99,37 @@ class FunctionsEmulator {
96
99
  this.adminSdkConfig = { ...this.args.adminSdkConfig, projectId: this.args.projectId };
97
100
  const mode = this.debugMode ? types_1.FunctionsExecutionMode.SEQUENTIAL : types_1.FunctionsExecutionMode.AUTO;
98
101
  this.workerPools = {};
99
- for (const backend of this.args.emulatableBackends) {
102
+ for (const backend of this.staticBackends) {
100
103
  const pool = new functionsRuntimeWorker_1.RuntimeWorkerPool(mode);
101
104
  this.workerPools[backend.codebase] = pool;
102
105
  }
103
106
  this.workQueue = new workQueue_1.WorkQueue(mode);
104
107
  }
108
+ async loadDynamicExtensionBackends() {
109
+ if (this.args.extensionsEmulator) {
110
+ const unfilteredBackends = this.args.extensionsEmulator.getDynamicExtensionBackends();
111
+ this.dynamicBackends =
112
+ this.args.extensionsEmulator.filterUnemulatedTriggers(unfilteredBackends);
113
+ const mode = this.debugMode ? types_1.FunctionsExecutionMode.SEQUENTIAL : types_1.FunctionsExecutionMode.AUTO;
114
+ const credentialEnv = await this.getCredentialsEnvironment();
115
+ for (const backend of this.dynamicBackends) {
116
+ backend.env = { ...credentialEnv, ...backend.env };
117
+ if (this.workerPools[backend.codebase]) {
118
+ if (this.debugMode) {
119
+ this.workerPools[backend.codebase].exit();
120
+ }
121
+ else {
122
+ this.workerPools[backend.codebase].refresh();
123
+ }
124
+ }
125
+ else {
126
+ const pool = new functionsRuntimeWorker_1.RuntimeWorkerPool(mode);
127
+ this.workerPools[backend.codebase] = pool;
128
+ }
129
+ await this.loadTriggers(backend, true);
130
+ }
131
+ }
132
+ }
105
133
  async getCredentialsEnvironment() {
106
134
  const credentialEnv = {};
107
135
  if (process.env.GOOGLE_APPLICATION_CREDENTIALS) {
@@ -231,7 +259,7 @@ class FunctionsEmulator {
231
259
  }
232
260
  async start() {
233
261
  const credentialEnv = await this.getCredentialsEnvironment();
234
- for (const e of this.args.emulatableBackends) {
262
+ for (const e of this.staticBackends) {
235
263
  e.env = { ...credentialEnv, ...e.env };
236
264
  }
237
265
  if (Object.keys(this.adminSdkConfig || {}).length <= 1) {
@@ -251,7 +279,7 @@ class FunctionsEmulator {
251
279
  return Promise.resolve();
252
280
  }
253
281
  async connect() {
254
- for (const backend of this.args.emulatableBackends) {
282
+ for (const backend of this.staticBackends) {
255
283
  this.logger.logLabeled("BULLET", "functions", `Watching "${backend.functionsDir}" for Cloud Functions...`);
256
284
  const watcher = chokidar.watch(backend.functionsDir, {
257
285
  ignored: [
@@ -322,7 +350,18 @@ class FunctionsEmulator {
322
350
  };
323
351
  const userEnvs = functionsEnv.loadUserEnvs(userEnvOpt);
324
352
  const discoveredBuild = await runtimeDelegate.discoverBuild(runtimeConfig, environment);
325
- const resolution = await (0, build_1.resolveBackend)(discoveredBuild, JSON.parse(firebaseConfig), userEnvOpt, userEnvs);
353
+ if (discoveredBuild.extensions && this.args.extensionsEmulator) {
354
+ await this.args.extensionsEmulator.addDynamicExtensions(emulatableBackend.codebase, discoveredBuild);
355
+ await this.loadDynamicExtensionBackends();
356
+ }
357
+ const resolution = await (0, build_1.resolveBackend)({
358
+ build: discoveredBuild,
359
+ firebaseConfig: JSON.parse(firebaseConfig),
360
+ userEnvOpt,
361
+ userEnvs,
362
+ nonInteractive: false,
363
+ isEmulator: true,
364
+ });
326
365
  const discoveredBackend = resolution.backend;
327
366
  const endpoints = backend.allEndpoints(discoveredBackend);
328
367
  (0, functionsEmulatorShared_1.prepareEndpoints)(endpoints);
@@ -352,6 +391,9 @@ class FunctionsEmulator {
352
391
  }
353
392
  const toRemove = Object.keys(this.triggers).filter((recordKey) => {
354
393
  const record = this.getTriggerRecordByKey(recordKey);
394
+ if (record.backend.codebase !== emulatableBackend.codebase) {
395
+ return false;
396
+ }
355
397
  if (force) {
356
398
  return true;
357
399
  }
@@ -385,6 +427,9 @@ class FunctionsEmulator {
385
427
  if (definition.httpsTrigger) {
386
428
  added = true;
387
429
  url = FunctionsEmulator.getHttpFunctionUrl(this.args.projectId, definition.name, definition.region);
430
+ if (definition.taskQueueTrigger) {
431
+ added = await this.addTaskQueueTrigger(this.args.projectId, definition.region, definition.name, url, definition.taskQueueTrigger);
432
+ }
388
433
  }
389
434
  else if (definition.eventTrigger) {
390
435
  const service = (0, functionsEmulatorShared_1.getFunctionService)(definition);
@@ -426,17 +471,17 @@ class FunctionsEmulator {
426
471
  }
427
472
  const ignored = !added;
428
473
  this.addTriggerRecord(definition, { backend: emulatableBackend, ignored, url });
429
- const type = definition.httpsTrigger
474
+ const triggerType = definition.httpsTrigger
430
475
  ? "http"
431
476
  : constants_1.Constants.getServiceName((0, functionsEmulatorShared_1.getFunctionService)(definition));
432
477
  if (ignored) {
433
- const msg = `function ignored because the ${type} emulator does not exist or is not running.`;
478
+ const msg = `function ignored because the ${triggerType} emulator does not exist or is not running.`;
434
479
  this.logger.logLabeled("BULLET", `functions[${definition.id}]`, msg);
435
480
  }
436
481
  else {
437
482
  const msg = url
438
- ? `${clc.bold(type)} function initialized (${url}).`
439
- : `${clc.bold(type)} function initialized.`;
483
+ ? `${clc.bold(triggerType)} function initialized (${url}).`
484
+ : `${clc.bold(triggerType)} function initialized.`;
440
485
  this.logger.logLabeled("SUCCESS", `functions[${definition.id}]`, msg);
441
486
  }
442
487
  }
@@ -479,9 +524,9 @@ class FunctionsEmulator {
479
524
  }
480
525
  }
481
526
  }
482
- addEventarcTrigger(projectId, key, eventTrigger) {
527
+ async addEventarcTrigger(projectId, key, eventTrigger) {
483
528
  if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EVENTARC)) {
484
- return Promise.resolve(false);
529
+ return false;
485
530
  }
486
531
  const bundle = {
487
532
  eventTrigger: {
@@ -490,15 +535,16 @@ class FunctionsEmulator {
490
535
  },
491
536
  };
492
537
  logger_1.logger.debug(`addEventarcTrigger`, JSON.stringify(bundle));
493
- return registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC)
494
- .post(`/emulator/v1/projects/${projectId}/triggers/${key}`, bundle)
495
- .then(() => true)
496
- .catch((err) => {
538
+ try {
539
+ await registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC).post(`/emulator/v1/projects/${projectId}/triggers/${key}`, bundle);
540
+ return true;
541
+ }
542
+ catch (err) {
497
543
  this.logger.log("WARN", "Error adding Eventarc function: " + err);
498
- return false;
499
- });
544
+ }
545
+ return false;
500
546
  }
501
- removeEventarcTrigger(projectId, key, eventTrigger) {
547
+ async removeEventarcTrigger(projectId, key, eventTrigger) {
502
548
  if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EVENTARC)) {
503
549
  return Promise.resolve(false);
504
550
  }
@@ -509,17 +555,18 @@ class FunctionsEmulator {
509
555
  },
510
556
  };
511
557
  logger_1.logger.debug(`removeEventarcTrigger`, JSON.stringify(bundle));
512
- return registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC)
513
- .post(`/emulator/v1/remove/projects/${projectId}/triggers/${key}`, bundle)
514
- .then(() => true)
515
- .catch((err) => {
558
+ try {
559
+ await registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC).post(`/emulator/v1/remove/projects/${projectId}/triggers/${key}`, bundle);
560
+ return true;
561
+ }
562
+ catch (err) {
516
563
  this.logger.log("WARN", "Error removing Eventarc function: " + err);
517
- return false;
518
- });
564
+ }
565
+ return false;
519
566
  }
520
- addFirealertsTrigger(projectId, key, eventTrigger) {
567
+ async addFirealertsTrigger(projectId, key, eventTrigger) {
521
568
  if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EVENTARC)) {
522
- return Promise.resolve(false);
569
+ return false;
523
570
  }
524
571
  const bundle = {
525
572
  eventTrigger: {
@@ -528,17 +575,18 @@ class FunctionsEmulator {
528
575
  },
529
576
  };
530
577
  logger_1.logger.debug(`addFirealertsTrigger`, JSON.stringify(bundle));
531
- return registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC)
532
- .post(`/emulator/v1/projects/${projectId}/triggers/${key}`, bundle)
533
- .then(() => true)
534
- .catch((err) => {
578
+ try {
579
+ await registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC).post(`/emulator/v1/projects/${projectId}/triggers/${key}`, bundle);
580
+ return true;
581
+ }
582
+ catch (err) {
535
583
  this.logger.log("WARN", "Error adding FireAlerts function: " + err);
536
- return false;
537
- });
584
+ }
585
+ return false;
538
586
  }
539
- removeFirealertsTrigger(projectId, key, eventTrigger) {
587
+ async removeFirealertsTrigger(projectId, key, eventTrigger) {
540
588
  if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EVENTARC)) {
541
- return Promise.resolve(false);
589
+ return false;
542
590
  }
543
591
  const bundle = {
544
592
  eventTrigger: {
@@ -547,13 +595,14 @@ class FunctionsEmulator {
547
595
  },
548
596
  };
549
597
  logger_1.logger.debug(`removeFirealertsTrigger`, JSON.stringify(bundle));
550
- return registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC)
551
- .post(`/emulator/v1/remove/projects/${projectId}/triggers/${key}`, bundle)
552
- .then(() => true)
553
- .catch((err) => {
598
+ try {
599
+ await registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC).post(`/emulator/v1/remove/projects/${projectId}/triggers/${key}`, bundle);
600
+ return true;
601
+ }
602
+ catch (err) {
554
603
  this.logger.log("WARN", "Error removing FireAlerts function: " + err);
555
- return false;
556
- });
604
+ }
605
+ return false;
557
606
  }
558
607
  async performPostLoadOperations() {
559
608
  if (!this.blockingFunctionsConfig.triggers &&
@@ -771,6 +820,25 @@ class FunctionsEmulator {
771
820
  };
772
821
  return true;
773
822
  }
823
+ async addTaskQueueTrigger(projectId, location, entryPoint, defaultUri, taskQueueTrigger) {
824
+ logger_1.logger.debug(`addTaskQueueTrigger`, JSON.stringify(taskQueueTrigger));
825
+ if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.TASKS)) {
826
+ logger_1.logger.debug(`addTaskQueueTrigger`, "TQ not running");
827
+ return Promise.resolve(false);
828
+ }
829
+ const bundle = {
830
+ ...taskQueueTrigger,
831
+ defaultUri,
832
+ };
833
+ try {
834
+ await registry_1.EmulatorRegistry.client(types_1.Emulators.TASKS).post(`/projects/${projectId}/locations/${location}/queues/${entryPoint}`, bundle);
835
+ return true;
836
+ }
837
+ catch (err) {
838
+ this.logger.log("WARN", "Error adding Task Queue function: " + err);
839
+ return false;
840
+ }
841
+ }
774
842
  getProjectId() {
775
843
  return this.args.projectId;
776
844
  }
@@ -808,9 +876,14 @@ class FunctionsEmulator {
808
876
  }
809
877
  getBackendInfo() {
810
878
  const cf3Triggers = this.getCF3Triggers();
811
- return this.args.emulatableBackends.map((e) => {
879
+ const backendInfo = this.staticBackends.map((e) => {
812
880
  return (0, functionsEmulatorShared_1.toBackendInfo)(e, cf3Triggers);
813
881
  });
882
+ const dynamicInfo = this.dynamicBackends.map((e) => {
883
+ return (0, functionsEmulatorShared_1.toBackendInfo)(e, cf3Triggers, { createdBy: "SDK" });
884
+ });
885
+ backendInfo.push(...dynamicInfo);
886
+ return backendInfo;
814
887
  }
815
888
  getCF3Triggers() {
816
889
  return Object.values(this.triggers)
@@ -1065,7 +1138,7 @@ class FunctionsEmulator {
1065
1138
  async reloadTriggers() {
1066
1139
  this.triggerGeneration++;
1067
1140
  this.blockingFunctionsConfig = {};
1068
- for (const backend of this.args.emulatableBackends) {
1141
+ for (const backend of this.staticBackends.concat(this.dynamicBackends)) {
1069
1142
  await this.loadTriggers(backend);
1070
1143
  }
1071
1144
  await this.performPostLoadOperations();
@@ -131,6 +131,19 @@ function emulatedFunctionsFromEndpoints(endpoints) {
131
131
  }
132
132
  else if (backend.isTaskQueueTriggered(endpoint)) {
133
133
  def.httpsTrigger = {};
134
+ def.taskQueueTrigger = {
135
+ retryConfig: {
136
+ maxAttempts: endpoint.taskQueueTrigger.retryConfig?.maxAttempts,
137
+ maxRetrySeconds: endpoint.taskQueueTrigger.retryConfig?.maxRetrySeconds,
138
+ maxBackoffSeconds: endpoint.taskQueueTrigger.retryConfig?.maxBackoffSeconds,
139
+ maxDoublings: endpoint.taskQueueTrigger.retryConfig?.maxDoublings,
140
+ minBackoffSeconds: endpoint.taskQueueTrigger.retryConfig?.minBackoffSeconds,
141
+ },
142
+ rateLimits: {
143
+ maxConcurrentDispatches: endpoint.taskQueueTrigger.rateLimits?.maxConcurrentDispatches,
144
+ maxDispatchesPerSecond: endpoint.taskQueueTrigger.rateLimits?.maxDispatchesPerSecond,
145
+ },
146
+ };
134
147
  }
135
148
  else {
136
149
  }
@@ -188,6 +201,9 @@ function getFunctionService(def) {
188
201
  if (def.httpsTrigger) {
189
202
  return "https";
190
203
  }
204
+ if (def.taskQueueTrigger) {
205
+ return constants_1.Constants.SERVICE_CLOUD_TASKS;
206
+ }
191
207
  return "unknown";
192
208
  }
193
209
  exports.getFunctionService = getFunctionService;
@@ -292,7 +308,7 @@ function getSecretLocalPath(backend, projectDir) {
292
308
  return path.join(secretDirectory, secretsFile);
293
309
  }
294
310
  exports.getSecretLocalPath = getSecretLocalPath;
295
- function toBackendInfo(e, cf3Triggers) {
311
+ function toBackendInfo(e, cf3Triggers, labels) {
296
312
  const envWithSecrets = Object.assign({}, e.env);
297
313
  for (const s of e.secretEnv) {
298
314
  envWithSecrets[s.key] = backend.secretVersionName(s);
@@ -318,6 +334,7 @@ function toBackendInfo(e, cf3Triggers) {
318
334
  extension: e.extension,
319
335
  extensionVersion: extensionVersion,
320
336
  extensionSpec: extensionSpec,
337
+ labels,
321
338
  functionTriggers: e.predefinedTriggers ?? cf3Triggers.filter((t) => t.codebase === e.codebase),
322
339
  }));
323
340
  }
@@ -7,6 +7,7 @@ const types_1 = require("./types");
7
7
  const events_1 = require("events");
8
8
  const emulatorLogger_1 = require("./emulatorLogger");
9
9
  const error_1 = require("../error");
10
+ const discovery_1 = require("../deploy/functions/runtimes/discovery");
10
11
  var RuntimeWorkerState;
11
12
  (function (RuntimeWorkerState) {
12
13
  RuntimeWorkerState["CREATED"] = "CREATED";
@@ -196,7 +197,7 @@ class RuntimeWorker {
196
197
  const timeout = new Promise((resolve, reject) => {
197
198
  setTimeout(() => {
198
199
  reject(new error_1.FirebaseError("Failed to load function."));
199
- }, 30000);
200
+ }, (0, discovery_1.getFunctionDiscoveryTimeout)() || 30000);
200
201
  });
201
202
  while (true) {
202
203
  try {
@@ -10,6 +10,7 @@ const types_1 = require("./types");
10
10
  const hubExport_1 = require("./hubExport");
11
11
  const registry_1 = require("./registry");
12
12
  const ExpressBasedEmulator_1 = require("./ExpressBasedEmulator");
13
+ const vsCodeUtils_1 = require("../vsCodeUtils");
13
14
  const pkg = require("../../package.json");
14
15
  class EmulatorHub extends ExpressBasedEmulator_1.ExpressBasedEmulator {
15
16
  static readLocatorFile(projectId) {
@@ -19,7 +20,7 @@ class EmulatorHub extends ExpressBasedEmulator_1.ExpressBasedEmulator {
19
20
  }
20
21
  const data = fs.readFileSync(locatorPath, "utf8").toString();
21
22
  const locator = JSON.parse(data);
22
- if (locator.version !== this.CLI_VERSION) {
23
+ if (!vsCodeUtils_1.isVSCodeExtension && locator.version !== this.CLI_VERSION) {
23
24
  logger_1.logger.debug(`Found locator with mismatched version, ignoring: ${JSON.stringify(locator)}`);
24
25
  return undefined;
25
26
  }
@@ -40,6 +41,16 @@ class EmulatorHub extends ExpressBasedEmulator_1.ExpressBasedEmulator {
40
41
  await super.start();
41
42
  await this.writeLocatorFile();
42
43
  }
44
+ getRunningEmulatorsMapping() {
45
+ const emulators = {};
46
+ for (const info of registry_1.EmulatorRegistry.listRunningWithInfo()) {
47
+ emulators[info.name] = {
48
+ listen: this.args.listenForEmulator[info.name],
49
+ ...info,
50
+ };
51
+ }
52
+ return emulators;
53
+ }
43
54
  async createExpressApp() {
44
55
  const app = await super.createExpressApp();
45
56
  app.get("/", (req, res) => {
@@ -50,14 +61,7 @@ class EmulatorHub extends ExpressBasedEmulator_1.ExpressBasedEmulator {
50
61
  });
51
62
  });
52
63
  app.get(EmulatorHub.PATH_EMULATORS, (req, res) => {
53
- const body = {};
54
- for (const info of registry_1.EmulatorRegistry.listRunningWithInfo()) {
55
- body[info.name] = {
56
- listen: this.args.listenForEmulator[info.name],
57
- ...info,
58
- };
59
- }
60
- res.json(body);
64
+ res.json(this.getRunningEmulatorsMapping());
61
65
  });
62
66
  app.post(EmulatorHub.PATH_EXPORT, async (req, res) => {
63
67
  if (req.headers.origin) {
@@ -11,7 +11,7 @@ const registry_1 = require("./registry");
11
11
  const error_1 = require("../error");
12
12
  const hub_1 = require("./hub");
13
13
  const downloadableEmulators_1 = require("./downloadableEmulators");
14
- const rimraf = require("rimraf");
14
+ const node_fs_1 = require("node:fs");
15
15
  const track_1 = require("../track");
16
16
  class HubExport {
17
17
  constructor(projectId, options) {
@@ -25,7 +25,14 @@ class HubExport {
25
25
  if (!fs.existsSync(metadataPath)) {
26
26
  return undefined;
27
27
  }
28
- return JSON.parse(fs.readFileSync(metadataPath, "utf8").toString());
28
+ let mdString = "";
29
+ try {
30
+ mdString = fs.readFileSync(metadataPath, "utf8").toString();
31
+ return JSON.parse(mdString);
32
+ }
33
+ catch (err) {
34
+ throw new error_1.FirebaseError(`Unable to parse metadata file ${metadataPath}: ${mdString}`);
35
+ }
29
36
  }
30
37
  async exportAll() {
31
38
  const toExport = types_1.ALL_EMULATORS.filter(shouldExport);
@@ -74,7 +81,7 @@ class HubExport {
74
81
  const metadataPath = path.join(this.tmpDir, HubExport.METADATA_FILE_NAME);
75
82
  fs.writeFileSync(metadataPath, JSON.stringify(metadata, undefined, 2));
76
83
  logger_1.logger.debug(`hubExport: swapping ${this.tmpDir} with ${this.exportPath}`);
77
- rimraf.sync(this.exportPath);
84
+ (0, node_fs_1.rmSync)(this.exportPath, { recursive: true });
78
85
  fse.moveSync(this.tmpDir, this.exportPath);
79
86
  }
80
87
  async exportFirestore(metadata) {
@@ -7,7 +7,7 @@ const triple_beam_1 = require("triple-beam");
7
7
  const WebSocket = require("ws");
8
8
  const TransportStream = require("winston-transport");
9
9
  const logger_1 = require("../logger");
10
- const stripAnsi = require("strip-ansi");
10
+ const node_util_1 = require("node:util");
11
11
  class LoggingEmulator {
12
12
  constructor(args) {
13
13
  this.args = args;
@@ -106,7 +106,7 @@ class WebSocketTransport extends TransportStream {
106
106
  if (bundle.data && bundle.data.metadata && bundle.data.metadata.message) {
107
107
  bundle.message = bundle.data.metadata.message;
108
108
  }
109
- bundle.message = stripAnsi(bundle.message);
109
+ bundle.message = (0, node_util_1.stripVTControlCharacters)(bundle.message);
110
110
  this.history.push(bundle);
111
111
  this.connections.forEach((ws) => {
112
112
  ws.send(JSON.stringify(bundle));
@@ -11,7 +11,6 @@ const types_1 = require("./types");
11
11
  const constants_1 = require("./constants");
12
12
  const emulatorLogger_1 = require("./emulatorLogger");
13
13
  const node_child_process_1 = require("node:child_process");
14
- const dataconnectEmulator_1 = require("./dataconnectEmulator");
15
14
  const RESTRICTED_PORTS = new Set([
16
15
  1,
17
16
  7,
@@ -147,6 +146,7 @@ const EMULATOR_CAN_LISTEN_ON_PRIMARY_ONLY = {
147
146
  firestore: true,
148
147
  "firestore.websocket": true,
149
148
  pubsub: true,
149
+ "dataconnect.postgres": true,
150
150
  dataconnect: false,
151
151
  hub: false,
152
152
  ui: false,
@@ -156,7 +156,9 @@ const EMULATOR_CAN_LISTEN_ON_PRIMARY_ONLY = {
156
156
  functions: true,
157
157
  logging: true,
158
158
  storage: true,
159
+ tasks: true,
159
160
  hosting: true,
161
+ apphosting: true,
160
162
  };
161
163
  const MAX_PORT = 65535;
162
164
  async function resolveHostAndAssignPorts(listenConfig) {
@@ -183,7 +185,11 @@ async function resolveHostAndAssignPorts(listenConfig) {
183
185
  lookupForHost.set(host, lookup);
184
186
  }
185
187
  const findAddrs = lookup.then(async (addrs) => {
186
- const emuLogger = emulatorLogger_1.EmulatorLogger.forEmulator(name === "firestore.websocket" ? types_1.Emulators.FIRESTORE : name);
188
+ const emuLogger = emulatorLogger_1.EmulatorLogger.forEmulator(name === "firestore.websocket"
189
+ ? types_1.Emulators.FIRESTORE
190
+ : name === "dataconnect.postgres"
191
+ ? types_1.Emulators.DATACONNECT
192
+ : name);
187
193
  if (addrs.some((addr) => addr.address === dns_1.IPV6_UNSPECIFIED.address)) {
188
194
  if (!addrs.some((addr) => addr.address === dns_1.IPV4_UNSPECIFIED.address)) {
189
195
  emuLogger.logLabeled("DEBUG", name, `testing listening on IPv4 wildcard in addition to IPv6. To listen on IPv6 only, use "::0" instead.`);
@@ -220,14 +226,6 @@ async function resolveHostAndAssignPorts(listenConfig) {
220
226
  available.push(listen);
221
227
  }
222
228
  else {
223
- if (/^dataconnect/i.exec(name)) {
224
- const alreadyRunning = await (0, dataconnectEmulator_1.checkIfDataConnectEmulatorRunningOnAddress)(listen);
225
- if (alreadyRunning) {
226
- emuLogger.logLabeled("DEBUG", "dataconnect", `Detected already running emulator on ${listen.address}:${listen.port}. Will attempt to reuse it.`);
227
- }
228
- available.push(listen);
229
- continue;
230
- }
231
229
  if (!portFixed) {
232
230
  if (i > 0) {
233
231
  emuLogger.logLabeled("DEBUG", name, `Port ${p} taken on secondary address ${addr.address}, will keep searching to find a better port.`);
@@ -279,7 +277,9 @@ exports.resolveHostAndAssignPorts = resolveHostAndAssignPorts;
279
277
  function portDescription(name) {
280
278
  return name === "firestore.websocket"
281
279
  ? `websocket server for ${types_1.Emulators.FIRESTORE}`
282
- : constants_1.Constants.description(name);
280
+ : name === "dataconnect.postgres"
281
+ ? `postgres server for ${types_1.Emulators.DATACONNECT}`
282
+ : constants_1.Constants.description(name);
283
283
  }
284
284
  function warnPartiallyAvailablePort(emuLogger, port, available, unavailable) {
285
285
  emuLogger.logLabeled("WARN", `Port ${port} is available on ` +
@@ -42,6 +42,7 @@ class EmulatorRegistry {
42
42
  extensions: 1,
43
43
  functions: 1.1,
44
44
  hosting: 2,
45
+ apphosting: 2.1,
45
46
  database: 3.0,
46
47
  firestore: 3.1,
47
48
  pubsub: 3.2,
@@ -49,6 +50,7 @@ class EmulatorRegistry {
49
50
  storage: 3.5,
50
51
  eventarc: 3.6,
51
52
  dataconnect: 3.7,
53
+ tasks: 3.8,
52
54
  hub: 4,
53
55
  logging: 5,
54
56
  };
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Persistence = void 0;
4
4
  const fs_1 = require("fs");
5
- const rimraf_1 = require("rimraf");
5
+ const promises_1 = require("node:fs/promises");
6
6
  const fs = require("fs");
7
7
  const fse = require("fs-extra");
8
8
  const path = require("path");
@@ -57,7 +57,7 @@ class Persistence {
57
57
  this._diskPathMap.delete(fileName);
58
58
  }
59
59
  async deleteAll() {
60
- await (0, rimraf_1.rimraf)(this._dirPath);
60
+ await (0, promises_1.rm)(this._dirPath, { recursive: true });
61
61
  this._diskPathMap = new Map();
62
62
  return;
63
63
  }
@@ -107,7 +107,7 @@ class StorageRulesRuntime {
107
107
  };
108
108
  });
109
109
  this._childprocess.on("error", (err) => {
110
- (0, downloadableEmulators_1.handleEmulatorProcessError)(types_2.Emulators.STORAGE, err);
110
+ void (0, downloadableEmulators_1.handleEmulatorProcessError)(types_2.Emulators.STORAGE, err);
111
111
  });
112
112
  this._childprocess.stderr?.on("data", (buf) => {
113
113
  const error = buf.toString();