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.

prepare.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.prepare = void 0;
  4. const clc = require("colorette");
  5. const path = require("path");
  6. const error_1 = require("../../error");
  7. const parseBoltRules_1 = require("../../parseBoltRules");
  8. const rtdb = require("../../rtdb");
  9. const utils = require("../../utils");
  10. const dbRulesConfig = require("../../database/rulesConfig");
  11. function prepare(context, options) {
  12. const rulesConfig = dbRulesConfig.getRulesConfig(context.projectId, options);
  13. const next = Promise.resolve();
  14. if (!rulesConfig || rulesConfig.length === 0) {
  15. return next;
  16. }
  17. const ruleFiles = {};
  18. const deploys = [];
  19. rulesConfig.forEach((ruleConfig) => {
  20. if (!ruleConfig.rules) {
  21. return;
  22. }
  23. ruleFiles[ruleConfig.rules] = null;
  24. deploys.push(ruleConfig);
  25. });
  26. for (const file of Object.keys(ruleFiles)) {
  27. switch (path.extname(file)) {
  28. case ".json":
  29. ruleFiles[file] = options.config.readProjectFile(file);
  30. break;
  31. case ".bolt":
  32. ruleFiles[file] = (0, parseBoltRules_1.parseBoltRules)(file);
  33. break;
  34. default:
  35. throw new error_1.FirebaseError("Unexpected rules format " + path.extname(file));
  36. }
  37. }
  38. context.database = {
  39. deploys: deploys,
  40. ruleFiles: ruleFiles,
  41. };
  42. utils.logBullet(clc.bold(clc.cyan("database: ")) + "checking rules syntax...");
  43. return Promise.all(deploys.map((deploy) => {
  44. return rtdb
  45. .updateRules(context.projectId, deploy.instance, ruleFiles[deploy.rules], { dryRun: true })
  46. .then(() => {
  47. utils.logSuccess(clc.bold(clc.green("database: ")) +
  48. "rules syntax for database " +
  49. clc.bold(deploy.instance) +
  50. " is valid");
  51. });
  52. }));
  53. }
  54. exports.prepare = prepare;