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.

listRemote.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.RTDBListRemote = 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 RTDBListRemote {
  9. constructor(instance, host) {
  10. this.instance = instance;
  11. this.host = host;
  12. const url = new url_1.URL(utils.getDatabaseUrl(this.host, this.instance, "/"));
  13. this.apiClient = new apiv2_1.Client({ urlPrefix: url.origin, auth: true });
  14. }
  15. async listPath(path, numSubPath, startAfter, timeout) {
  16. const url = new url_1.URL(utils.getDatabaseUrl(this.host, this.instance, path + ".json"));
  17. const params = {
  18. shallow: true,
  19. limitToFirst: numSubPath,
  20. };
  21. if (startAfter) {
  22. params.startAfter = startAfter;
  23. }
  24. if (timeout) {
  25. params.timeout = `${timeout}ms`;
  26. }
  27. const t0 = Date.now();
  28. const res = await this.apiClient.get(url.pathname, {
  29. queryParams: params,
  30. });
  31. const paths = res.body ? Object.keys(res.body) : [];
  32. const dt = Date.now() - t0;
  33. logger_1.logger.debug(`[database] sucessfully fetched ${paths.length} path at ${path} ${dt}`);
  34. return paths;
  35. }
  36. }
  37. exports.RTDBListRemote = RTDBListRemote;