Sin descripción
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.

util.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.booleanXOR = exports.parseFieldName = exports.parseIndexName = void 0;
  4. const error_1 = require("../error");
  5. const INDEX_NAME_REGEX = /projects\/([^\/]+?)\/databases\/\(default\)\/collectionGroups\/([^\/]+?)\/indexes\/([^\/]*)/;
  6. const FIELD_NAME_REGEX = /projects\/([^\/]+?)\/databases\/\(default\)\/collectionGroups\/([^\/]+?)\/fields\/([^\/]*)/;
  7. function parseIndexName(name) {
  8. if (!name) {
  9. throw new error_1.FirebaseError(`Cannot parse undefined index name.`);
  10. }
  11. const m = name.match(INDEX_NAME_REGEX);
  12. if (!m || m.length < 4) {
  13. throw new error_1.FirebaseError(`Error parsing index name: ${name}`);
  14. }
  15. return {
  16. projectId: m[1],
  17. collectionGroupId: m[2],
  18. indexId: m[3],
  19. };
  20. }
  21. exports.parseIndexName = parseIndexName;
  22. function parseFieldName(name) {
  23. const m = name.match(FIELD_NAME_REGEX);
  24. if (!m || m.length < 4) {
  25. throw new error_1.FirebaseError(`Error parsing field name: ${name}`);
  26. }
  27. return {
  28. projectId: m[1],
  29. collectionGroupId: m[2],
  30. fieldPath: m[3],
  31. };
  32. }
  33. exports.parseFieldName = parseFieldName;
  34. function booleanXOR(a, b) {
  35. return !!(Number(a) - Number(b));
  36. }
  37. exports.booleanXOR = booleanXOR;