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.

planner.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.resolveVersion = exports.want = exports.have = exports.getExtensionSpec = exports.getExtension = exports.getExtensionVersion = void 0;
  4. const semver = require("semver");
  5. const extensionsApi = require("../../extensions/extensionsApi");
  6. const refs = require("../../extensions/refs");
  7. const error_1 = require("../../error");
  8. const extensionsHelper_1 = require("../../extensions/extensionsHelper");
  9. const logger_1 = require("../../logger");
  10. const manifest_1 = require("../../extensions/manifest");
  11. const paramHelper_1 = require("../../extensions/paramHelper");
  12. const specHelper_1 = require("../../extensions/emulator/specHelper");
  13. const functional_1 = require("../../functional");
  14. async function getExtensionVersion(i) {
  15. if (!i.extensionVersion) {
  16. if (!i.ref) {
  17. throw new error_1.FirebaseError(`Can't get ExtensionVersion for ${i.instanceId} because it has no ref`);
  18. }
  19. i.extensionVersion = await extensionsApi.getExtensionVersion(refs.toExtensionVersionRef(i.ref));
  20. }
  21. return i.extensionVersion;
  22. }
  23. exports.getExtensionVersion = getExtensionVersion;
  24. async function getExtension(i) {
  25. if (!i.ref) {
  26. throw new error_1.FirebaseError(`Can't get Extension for ${i.instanceId} because it has no ref`);
  27. }
  28. if (!i.extension) {
  29. i.extension = await extensionsApi.getExtension(refs.toExtensionRef(i.ref));
  30. }
  31. return i.extension;
  32. }
  33. exports.getExtension = getExtension;
  34. async function getExtensionSpec(i) {
  35. if (!i.extensionSpec) {
  36. if (i.ref) {
  37. const extensionVersion = await getExtensionVersion(i);
  38. i.extensionSpec = extensionVersion.spec;
  39. }
  40. else if (i.localPath) {
  41. i.extensionSpec = await (0, specHelper_1.readExtensionYaml)(i.localPath);
  42. i.extensionSpec.postinstallContent = await (0, specHelper_1.readPostinstall)(i.localPath);
  43. }
  44. else {
  45. throw new error_1.FirebaseError("InstanceSpec had no ref or localPath, unable to get extensionSpec");
  46. }
  47. }
  48. return i.extensionSpec;
  49. }
  50. exports.getExtensionSpec = getExtensionSpec;
  51. async function have(projectId) {
  52. const instances = await extensionsApi.listInstances(projectId);
  53. return instances.map((i) => {
  54. var _a;
  55. const dep = {
  56. instanceId: i.name.split("/").pop(),
  57. params: i.config.params,
  58. systemParams: (_a = i.config.systemParams) !== null && _a !== void 0 ? _a : {},
  59. allowedEventTypes: i.config.allowedEventTypes,
  60. eventarcChannel: i.config.eventarcChannel,
  61. etag: i.etag,
  62. };
  63. if (i.config.extensionRef) {
  64. const ref = refs.parse(i.config.extensionRef);
  65. dep.ref = ref;
  66. dep.ref.version = i.config.extensionVersion;
  67. }
  68. return dep;
  69. });
  70. }
  71. exports.have = have;
  72. async function want(args) {
  73. const instanceSpecs = [];
  74. const errors = [];
  75. for (const e of Object.entries(args.extensions)) {
  76. try {
  77. const instanceId = e[0];
  78. const rawParams = (0, manifest_1.readInstanceParam)({
  79. projectDir: args.projectDir,
  80. instanceId,
  81. projectId: args.projectId,
  82. projectNumber: args.projectNumber,
  83. aliases: args.aliases,
  84. checkLocal: args.emulatorMode,
  85. });
  86. const autoPopulatedParams = await (0, extensionsHelper_1.getFirebaseProjectParams)(args.projectId, args.emulatorMode);
  87. const subbedParams = (0, extensionsHelper_1.substituteParams)(rawParams, autoPopulatedParams);
  88. const [systemParams, params] = (0, functional_1.partitionRecord)(subbedParams, paramHelper_1.isSystemParam);
  89. const allowedEventTypes = params.ALLOWED_EVENT_TYPES !== undefined
  90. ? params.ALLOWED_EVENT_TYPES.split(",").filter((e) => e !== "")
  91. : undefined;
  92. const eventarcChannel = params.EVENTARC_CHANNEL;
  93. delete params["EVENTARC_CHANNEL"];
  94. delete params["ALLOWED_EVENT_TYPES"];
  95. if ((0, extensionsHelper_1.isLocalPath)(e[1])) {
  96. instanceSpecs.push({
  97. instanceId,
  98. localPath: e[1],
  99. params,
  100. systemParams,
  101. allowedEventTypes: allowedEventTypes,
  102. eventarcChannel: eventarcChannel,
  103. });
  104. }
  105. else {
  106. const ref = refs.parse(e[1]);
  107. ref.version = await resolveVersion(ref);
  108. instanceSpecs.push({
  109. instanceId,
  110. ref,
  111. params,
  112. systemParams,
  113. allowedEventTypes: allowedEventTypes,
  114. eventarcChannel: eventarcChannel,
  115. });
  116. }
  117. }
  118. catch (err) {
  119. logger_1.logger.debug(`Got error reading extensions entry ${e}: ${err}`);
  120. errors.push(err);
  121. }
  122. }
  123. if (errors.length) {
  124. const messages = errors.map((err) => `- ${err.message}`).join("\n");
  125. throw new error_1.FirebaseError(`Errors while reading 'extensions' in 'firebase.json'\n${messages}`);
  126. }
  127. return instanceSpecs;
  128. }
  129. exports.want = want;
  130. async function resolveVersion(ref) {
  131. const extensionRef = refs.toExtensionRef(ref);
  132. const versions = await extensionsApi.listExtensionVersions(extensionRef, undefined, true);
  133. if (versions.length === 0) {
  134. throw new error_1.FirebaseError(`No versions found for ${extensionRef}`);
  135. }
  136. if (!ref.version || ref.version === "latest") {
  137. return versions
  138. .filter((ev) => ev.spec.version !== undefined)
  139. .map((ev) => ev.spec.version)
  140. .sort(semver.compare)
  141. .pop();
  142. }
  143. const maxSatisfying = semver.maxSatisfying(versions.map((ev) => ev.spec.version), ref.version);
  144. if (!maxSatisfying) {
  145. throw new error_1.FirebaseError(`No version of ${extensionRef} matches requested version ${ref.version}`);
  146. }
  147. return maxSatisfying;
  148. }
  149. exports.resolveVersion = resolveVersion;