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.

firestore.js 1.2KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.deleteDocuments = exports.deleteDocument = exports.listCollectionIds = void 0;
  4. const api_1 = require("../api");
  5. const apiv2_1 = require("../apiv2");
  6. const apiClient = new apiv2_1.Client({
  7. auth: true,
  8. apiVersion: "v1",
  9. urlPrefix: api_1.firestoreOriginOrEmulator,
  10. });
  11. function listCollectionIds(project) {
  12. const url = "projects/" + project + "/databases/(default)/documents:listCollectionIds";
  13. const data = {
  14. pageSize: 2147483647,
  15. };
  16. return apiClient.post(url, data).then((res) => {
  17. return res.body.collectionIds || [];
  18. });
  19. }
  20. exports.listCollectionIds = listCollectionIds;
  21. async function deleteDocument(doc) {
  22. return apiClient.delete(doc.name);
  23. }
  24. exports.deleteDocument = deleteDocument;
  25. async function deleteDocuments(project, docs) {
  26. const url = "projects/" + project + "/databases/(default)/documents:commit";
  27. const writes = docs.map((doc) => {
  28. return { delete: doc.name };
  29. });
  30. const data = { writes };
  31. const res = await apiClient.post(url, data);
  32. return res.body.writeResults.length;
  33. }
  34. exports.deleteDocuments = deleteDocuments;