Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

firestore-delete.js 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const clc = require("colorette");
  5. const command_1 = require("../command");
  6. const types_1 = require("../emulator/types");
  7. const commandUtils_1 = require("../emulator/commandUtils");
  8. const delete_1 = require("../firestore/delete");
  9. const prompt_1 = require("../prompt");
  10. const requirePermissions_1 = require("../requirePermissions");
  11. const utils = require("../utils");
  12. function getConfirmationMessage(deleteOp, options) {
  13. if (options.allCollections) {
  14. return ("You are about to delete " +
  15. clc.bold(clc.yellow(clc.underline("THE ENTIRE DATABASE"))) +
  16. " for " +
  17. clc.cyan(options.project) +
  18. ". Are you sure?");
  19. }
  20. if (deleteOp.isDocumentPath) {
  21. if (options.recursive) {
  22. return ("You are about to delete the document at " +
  23. clc.cyan(deleteOp.path) +
  24. " and all of its subcollections " +
  25. " for " +
  26. clc.cyan(options.project) +
  27. ". Are you sure?");
  28. }
  29. return ("You are about to delete the document at " +
  30. clc.cyan(deleteOp.path) +
  31. " for " +
  32. clc.cyan(options.project) +
  33. ". Are you sure?");
  34. }
  35. if (options.recursive) {
  36. return ("You are about to delete all documents in the collection at " +
  37. clc.cyan(deleteOp.path) +
  38. " and all of their subcollections " +
  39. " for " +
  40. clc.cyan(options.project) +
  41. ". Are you sure?");
  42. }
  43. return ("You are about to delete all documents in the collection at " +
  44. clc.cyan(deleteOp.path) +
  45. " for " +
  46. clc.cyan(options.project) +
  47. ". Are you sure?");
  48. }
  49. exports.command = new command_1.Command("firestore:delete [path]")
  50. .description("Delete data from Cloud Firestore.")
  51. .option("-r, --recursive", "Recursive. Delete all documents and subcollections at and under the " +
  52. "specified level. May not be passed along with --shallow.")
  53. .option("--shallow", "Shallow. Delete only documents at the specified level and ignore documents in " +
  54. "subcollections. This action can potentially orphan documents nested in " +
  55. "subcollections. May not be passed along with -r.")
  56. .option("--all-collections", "Delete all. Deletes the entire Firestore database, " +
  57. "including all collections and documents. Any other flags or arguments will be ignored.")
  58. .option("-f, --force", "No confirmation. Otherwise, a confirmation prompt will appear.")
  59. .before(commandUtils_1.printNoticeIfEmulated, types_1.Emulators.FIRESTORE)
  60. .before(requirePermissions_1.requirePermissions, ["datastore.entities.list", "datastore.entities.delete"])
  61. .action(async (path, options) => {
  62. if (!path && !options.allCollections) {
  63. return utils.reject("Must specify a path.", { exit: 1 });
  64. }
  65. const deleteOp = new delete_1.FirestoreDelete(options.project, path, {
  66. recursive: options.recursive,
  67. shallow: options.shallow,
  68. allCollections: options.allCollections,
  69. });
  70. const confirm = await (0, prompt_1.promptOnce)({
  71. type: "confirm",
  72. name: "force",
  73. default: false,
  74. message: getConfirmationMessage(deleteOp, options),
  75. }, options);
  76. if (!confirm) {
  77. return utils.reject("Command aborted.", { exit: 1 });
  78. }
  79. if (options.allCollections) {
  80. return deleteOp.deleteDatabase();
  81. }
  82. return deleteOp.execute();
  83. });