Brak opisu
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.

refs.js 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.equal = exports.toExtensionVersionName = exports.toExtensionName = exports.toExtensionVersionRef = exports.toExtensionRef = exports.parse = void 0;
  4. const semver = require("semver");
  5. const error_1 = require("../error");
  6. const refRegex = new RegExp(/^([^/@\n]+)\/{1}([^/@\n]+)(@{1}([^\n]+)|)$/);
  7. function parse(refOrName) {
  8. const ret = parseRef(refOrName) || parseName(refOrName);
  9. if (!ret || !ret.publisherId || !ret.extensionId) {
  10. throw new error_1.FirebaseError(`Unable to parse ${refOrName} as an extension ref`);
  11. }
  12. if (ret.version &&
  13. !semver.valid(ret.version) &&
  14. !semver.validRange(ret.version) &&
  15. ret.version !== "latest") {
  16. throw new error_1.FirebaseError(`Extension reference ${ret} contains an invalid version ${ret.version}.`);
  17. }
  18. return ret;
  19. }
  20. exports.parse = parse;
  21. function parseRef(ref) {
  22. const parts = refRegex.exec(ref);
  23. if (parts && (parts.length === 5 || parts.length === 7)) {
  24. const publisherId = parts[1];
  25. const extensionId = parts[2];
  26. const version = parts[4];
  27. return { publisherId, extensionId, version };
  28. }
  29. }
  30. function parseName(name) {
  31. const parts = name.split("/");
  32. return {
  33. publisherId: parts[1],
  34. extensionId: parts[3],
  35. version: parts[5],
  36. };
  37. }
  38. function toExtensionRef(ref) {
  39. return `${ref.publisherId}/${ref.extensionId}`;
  40. }
  41. exports.toExtensionRef = toExtensionRef;
  42. function toExtensionVersionRef(ref) {
  43. if (!ref.version) {
  44. throw new error_1.FirebaseError(`Ref does not have a version`);
  45. }
  46. return `${ref.publisherId}/${ref.extensionId}@${ref.version}`;
  47. }
  48. exports.toExtensionVersionRef = toExtensionVersionRef;
  49. function toExtensionName(ref) {
  50. return `publishers/${ref.publisherId}/extensions/${ref.extensionId}`;
  51. }
  52. exports.toExtensionName = toExtensionName;
  53. function toExtensionVersionName(ref) {
  54. if (!ref.version) {
  55. throw new error_1.FirebaseError(`Ref does not have a version`);
  56. }
  57. return `publishers/${ref.publisherId}/extensions/${ref.extensionId}/versions/${ref.version}`;
  58. }
  59. exports.toExtensionVersionName = toExtensionVersionName;
  60. function equal(a, b) {
  61. return (!!a &&
  62. !!b &&
  63. a.publisherId === b.publisherId &&
  64. a.extensionId === b.extensionId &&
  65. a.version === b.version);
  66. }
  67. exports.equal = equal;