isInclusive.js 934 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. const isDefiningProjection = require('./isDefiningProjection');
  3. const isPOJO = require('../isPOJO');
  4. /*!
  5. * ignore
  6. */
  7. module.exports = function isInclusive(projection) {
  8. if (projection == null) {
  9. return false;
  10. }
  11. const props = Object.keys(projection);
  12. const numProps = props.length;
  13. if (numProps === 0) {
  14. return false;
  15. }
  16. for (let i = 0; i < numProps; ++i) {
  17. const prop = props[i];
  18. // Plus paths can't define the projection (see gh-7050)
  19. if (prop.startsWith('+')) {
  20. continue;
  21. }
  22. // If field is truthy (1, true, etc.) and not an object, then this
  23. // projection must be inclusive. If object, assume its $meta, $slice, etc.
  24. if (isDefiningProjection(projection[prop]) && !!projection[prop]) {
  25. if (isPOJO(projection[prop])) {
  26. return isInclusive(projection[prop]);
  27. } else {
  28. return !!projection[prop];
  29. }
  30. }
  31. }
  32. return false;
  33. };