No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

validation.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.checkForUnemulatedTriggerTypes = exports.getUnemulatedAPIs = void 0;
  4. const planner = require("../../deploy/extensions/planner");
  5. const controller_1 = require("../controller");
  6. const constants_1 = require("../constants");
  7. const ensureApiEnabled_1 = require("../../ensureApiEnabled");
  8. const functionsEmulatorShared_1 = require("../functionsEmulatorShared");
  9. const types_1 = require("../types");
  10. const EMULATED_APIS = [
  11. "storage-component.googleapis.com",
  12. "firestore.googleapis.com",
  13. "pubsub.googleapis.com",
  14. "identitytoolkit.googleapis.com",
  15. ];
  16. async function getUnemulatedAPIs(projectId, instances) {
  17. var _a;
  18. const unemulatedAPIs = {};
  19. for (const i of instances) {
  20. const extensionSpec = await planner.getExtensionSpec(i);
  21. for (const api of (_a = extensionSpec.apis) !== null && _a !== void 0 ? _a : []) {
  22. if (!EMULATED_APIS.includes(api.apiName)) {
  23. if (unemulatedAPIs[api.apiName]) {
  24. unemulatedAPIs[api.apiName].instanceIds.push(i.instanceId);
  25. }
  26. else {
  27. const enabled = !constants_1.Constants.isDemoProject(projectId) &&
  28. (await (0, ensureApiEnabled_1.check)(projectId, api.apiName, "extensions", true));
  29. unemulatedAPIs[api.apiName] = {
  30. apiName: api.apiName,
  31. instanceIds: [i.instanceId],
  32. enabled,
  33. };
  34. }
  35. }
  36. }
  37. }
  38. return Object.values(unemulatedAPIs);
  39. }
  40. exports.getUnemulatedAPIs = getUnemulatedAPIs;
  41. function checkForUnemulatedTriggerTypes(backend, options) {
  42. var _a;
  43. const triggers = (_a = backend.predefinedTriggers) !== null && _a !== void 0 ? _a : [];
  44. const unemulatedTriggers = triggers
  45. .filter((definition) => {
  46. if (definition.httpsTrigger) {
  47. return false;
  48. }
  49. if (definition.eventTrigger) {
  50. const service = (0, functionsEmulatorShared_1.getFunctionService)(definition);
  51. switch (service) {
  52. case constants_1.Constants.SERVICE_FIRESTORE:
  53. return !(0, controller_1.shouldStart)(options, types_1.Emulators.FIRESTORE);
  54. case constants_1.Constants.SERVICE_REALTIME_DATABASE:
  55. return !(0, controller_1.shouldStart)(options, types_1.Emulators.DATABASE);
  56. case constants_1.Constants.SERVICE_PUBSUB:
  57. return !(0, controller_1.shouldStart)(options, types_1.Emulators.PUBSUB);
  58. case constants_1.Constants.SERVICE_AUTH:
  59. return !(0, controller_1.shouldStart)(options, types_1.Emulators.AUTH);
  60. case constants_1.Constants.SERVICE_STORAGE:
  61. return !(0, controller_1.shouldStart)(options, types_1.Emulators.STORAGE);
  62. case constants_1.Constants.SERVICE_EVENTARC:
  63. return !(0, controller_1.shouldStart)(options, types_1.Emulators.EVENTARC);
  64. default:
  65. return true;
  66. }
  67. }
  68. })
  69. .map((definition) => constants_1.Constants.getServiceName((0, functionsEmulatorShared_1.getFunctionService)(definition)));
  70. return [...new Set(unemulatedTriggers)];
  71. }
  72. exports.checkForUnemulatedTriggerTypes = checkForUnemulatedTriggerTypes;