Ingen beskrivning
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

projectConfig.js 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.configForCodebase = exports.normalizeAndValidate = exports.validate = exports.assertUnique = exports.validateCodebase = exports.normalize = exports.DEFAULT_CODEBASE = void 0;
  4. const error_1 = require("../error");
  5. exports.DEFAULT_CODEBASE = "default";
  6. function normalize(config) {
  7. if (!config) {
  8. throw new error_1.FirebaseError("No valid functions configuration detected in firebase.json");
  9. }
  10. if (Array.isArray(config)) {
  11. if (config.length < 1) {
  12. throw new error_1.FirebaseError("Requires at least one functions.source in firebase.json.");
  13. }
  14. return config;
  15. }
  16. return [config];
  17. }
  18. exports.normalize = normalize;
  19. function validateCodebase(codebase) {
  20. if (codebase.length === 0 || codebase.length > 63 || !/^[a-z0-9_-]+$/.test(codebase)) {
  21. throw new error_1.FirebaseError("Invalid codebase name. Codebase must be less than 64 characters and " +
  22. "can contain only lowercase letters, numeric characters, underscores, and dashes.");
  23. }
  24. }
  25. exports.validateCodebase = validateCodebase;
  26. function validateSingle(config) {
  27. if (!config.source) {
  28. throw new error_1.FirebaseError("codebase source must be specified");
  29. }
  30. if (!config.codebase) {
  31. config.codebase = exports.DEFAULT_CODEBASE;
  32. }
  33. validateCodebase(config.codebase);
  34. return Object.assign(Object.assign({}, config), { source: config.source, codebase: config.codebase });
  35. }
  36. function assertUnique(config, property, propval) {
  37. const values = new Set();
  38. if (propval) {
  39. values.add(propval);
  40. }
  41. for (const single of config) {
  42. const value = single[property];
  43. if (values.has(value)) {
  44. throw new error_1.FirebaseError(`functions.${property} must be unique but '${value}' was used more than once.`);
  45. }
  46. values.add(value);
  47. }
  48. }
  49. exports.assertUnique = assertUnique;
  50. function validate(config) {
  51. const validated = config.map((cfg) => validateSingle(cfg));
  52. assertUnique(validated, "source");
  53. assertUnique(validated, "codebase");
  54. return validated;
  55. }
  56. exports.validate = validate;
  57. function normalizeAndValidate(config) {
  58. return validate(normalize(config));
  59. }
  60. exports.normalizeAndValidate = normalizeAndValidate;
  61. function configForCodebase(config, codebase) {
  62. const codebaseCfg = config.find((c) => c.codebase === codebase);
  63. if (!codebaseCfg) {
  64. throw new error_1.FirebaseError(`No functions config found for codebase ${codebase}`);
  65. }
  66. return codebaseCfg;
  67. }
  68. exports.configForCodebase = configForCodebase;