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.

rulesConfig.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getRulesConfig = exports.normalizeRulesConfig = void 0;
  4. const error_1 = require("../error");
  5. const logger_1 = require("../logger");
  6. const utils = require("../utils");
  7. function normalizeRulesConfig(rulesConfig, options) {
  8. const config = options.config;
  9. return rulesConfig.map((rc) => {
  10. return {
  11. instance: rc.instance,
  12. rules: config.path(rc.rules),
  13. };
  14. });
  15. }
  16. exports.normalizeRulesConfig = normalizeRulesConfig;
  17. function getRulesConfig(projectId, options) {
  18. const dbConfig = options.config.src.database;
  19. if (dbConfig === undefined) {
  20. return [];
  21. }
  22. const rc = options.rc;
  23. let allDatabases = !options.only;
  24. const onlyDatabases = new Set();
  25. if (options.only) {
  26. const split = options.only.split(",");
  27. if (split.includes("database")) {
  28. allDatabases = true;
  29. }
  30. else {
  31. for (const value of split) {
  32. if (value.startsWith("database:")) {
  33. const target = value.split(":")[1];
  34. onlyDatabases.add(target);
  35. }
  36. }
  37. }
  38. }
  39. if (!Array.isArray(dbConfig)) {
  40. if (dbConfig && dbConfig.rules) {
  41. utils.assertIsStringOrUndefined(options.instance);
  42. const instance = options.instance || `${options.project}-default-rtdb`;
  43. return [{ rules: dbConfig.rules, instance }];
  44. }
  45. else {
  46. logger_1.logger.debug("Possibly invalid database config: ", JSON.stringify(dbConfig));
  47. return [];
  48. }
  49. }
  50. const results = [];
  51. for (const c of dbConfig) {
  52. const { instance, target } = c;
  53. if (target) {
  54. if (allDatabases || onlyDatabases.has(target)) {
  55. rc.requireTarget(projectId, "database", target);
  56. const instances = rc.target(projectId, "database", target);
  57. for (const i of instances) {
  58. results.push({ instance: i, rules: c.rules });
  59. }
  60. onlyDatabases.delete(target);
  61. }
  62. }
  63. else if (instance) {
  64. if (allDatabases) {
  65. results.push(c);
  66. }
  67. }
  68. else {
  69. throw new error_1.FirebaseError('Must supply either "target" or "instance" in database config');
  70. }
  71. }
  72. if (!allDatabases && onlyDatabases.size !== 0) {
  73. throw new error_1.FirebaseError(`Could not find configurations in firebase.json for the following database targets: ${[
  74. ...onlyDatabases,
  75. ].join(", ")}`);
  76. }
  77. return results;
  78. }
  79. exports.getRulesConfig = getRulesConfig;