GSI - Employe Self Service Mobile
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.

51 lines
1.9 KiB

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.RTDBRemoveRemote = void 0;
  4. const apiv2_1 = require("../apiv2");
  5. const url_1 = require("url");
  6. const logger_1 = require("../logger");
  7. const utils = require("../utils");
  8. class RTDBRemoveRemote {
  9. constructor(instance, host, disableTriggers) {
  10. this.instance = instance;
  11. this.host = host;
  12. this.disableTriggers = disableTriggers;
  13. const url = new url_1.URL(utils.getDatabaseUrl(this.host, this.instance, "/"));
  14. this.apiClient = new apiv2_1.Client({ urlPrefix: url.origin, auth: true });
  15. }
  16. deletePath(path) {
  17. return this.patch(path, null, "all data");
  18. }
  19. deleteSubPath(path, subPaths) {
  20. const body = {};
  21. for (const c of subPaths) {
  22. body[c] = null;
  23. }
  24. return this.patch(path, body, `${subPaths.length} subpaths`);
  25. }
  26. async patch(path, body, note) {
  27. const t0 = Date.now();
  28. const url = new url_1.URL(utils.getDatabaseUrl(this.host, this.instance, path + ".json"));
  29. const queryParams = {
  30. print: "silent",
  31. writeSizeLimit: "tiny",
  32. disableTriggers: this.disableTriggers.toString(),
  33. };
  34. const res = await this.apiClient.request({
  35. method: "PATCH",
  36. path: url.pathname,
  37. body,
  38. queryParams,
  39. responseType: "stream",
  40. resolveOnHTTPError: true,
  41. });
  42. const dt = Date.now() - t0;
  43. if (res.status >= 400) {
  44. logger_1.logger.debug(`[database] Failed to remove ${note} at ${path} time: ${dt}ms, will try recursively chunked deletes.`);
  45. return false;
  46. }
  47. logger_1.logger.debug(`[database] Sucessfully removed ${note} at ${path} time: ${dt}ms`);
  48. return true;
  49. }
  50. }
  51. exports.RTDBRemoveRemote = RTDBRemoveRemote;