Ei kuvausta
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.

database-remove.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const command_1 = require("../command");
  5. const requireDatabaseInstance_1 = require("../requireDatabaseInstance");
  6. const requirePermissions_1 = require("../requirePermissions");
  7. const remove_1 = require("../database/remove");
  8. const types_1 = require("../emulator/types");
  9. const commandUtils_1 = require("../emulator/commandUtils");
  10. const database_1 = require("../management/database");
  11. const api_1 = require("../database/api");
  12. const utils = require("../utils");
  13. const prompt_1 = require("../prompt");
  14. const clc = require("colorette");
  15. exports.command = new command_1.Command("database:remove <path>")
  16. .description("remove data from your Firebase at the specified path")
  17. .option("-f, --force", "pass this option to bypass confirmation prompt")
  18. .option("--instance <instance>", "use the database <instance>.firebaseio.com (if omitted, use default database instance)")
  19. .option("--disable-triggers", "suppress any Cloud functions triggered by this operation")
  20. .before(requirePermissions_1.requirePermissions, ["firebasedatabase.instances.update"])
  21. .before(requireDatabaseInstance_1.requireDatabaseInstance)
  22. .before(database_1.populateInstanceDetails)
  23. .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.DATABASE)
  24. .action(async (path, options) => {
  25. if (!path.startsWith("/")) {
  26. return utils.reject("Path must begin with /", { exit: 1 });
  27. }
  28. const origin = (0, api_1.realtimeOriginOrEmulatorOrCustomUrl)(options.instanceDetails.databaseUrl);
  29. const databaseUrl = utils.getDatabaseUrl(origin, options.instance, path);
  30. const confirm = await (0, prompt_1.promptOnce)({
  31. type: "confirm",
  32. name: "force",
  33. default: false,
  34. message: "You are about to remove all data at " + clc.cyan(databaseUrl) + ". Are you sure?",
  35. }, options);
  36. if (!confirm) {
  37. return utils.reject("Command aborted.", { exit: 1 });
  38. }
  39. const removeOps = new remove_1.default(options.instance, path, origin, !!options.disableTriggers);
  40. await removeOps.execute();
  41. utils.logSuccess("Data removed successfully");
  42. });