isInclusive.js 937 B

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