UNPKG

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