summaryrefslogtreecommitdiffstats
path: root/node_modules/mongoose/lib/helpers/projection
diff options
context:
space:
mode:
authorGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
committerGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
commite06ec920f7a5d784e674c4c4b4e6d1da3dc7391d (patch)
tree55713f725f77b44ebfec86e4eec3ce33e71458ca /node_modules/mongoose/lib/helpers/projection
downloadwebsite_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.gz
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.bz2
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.zip
api, login, auth
Diffstat (limited to 'node_modules/mongoose/lib/helpers/projection')
-rw-r--r--node_modules/mongoose/lib/helpers/projection/isDefiningProjection.js18
-rw-r--r--node_modules/mongoose/lib/helpers/projection/isExclusive.js28
-rw-r--r--node_modules/mongoose/lib/helpers/projection/isInclusive.js34
-rw-r--r--node_modules/mongoose/lib/helpers/projection/isPathExcluded.js35
-rw-r--r--node_modules/mongoose/lib/helpers/projection/isPathSelectedInclusive.js28
-rw-r--r--node_modules/mongoose/lib/helpers/projection/parseProjection.js33
6 files changed, 176 insertions, 0 deletions
diff --git a/node_modules/mongoose/lib/helpers/projection/isDefiningProjection.js b/node_modules/mongoose/lib/helpers/projection/isDefiningProjection.js
new file mode 100644
index 0000000..67dfb39
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/projection/isDefiningProjection.js
@@ -0,0 +1,18 @@
+'use strict';
+
+/*!
+ * ignore
+ */
+
+module.exports = function isDefiningProjection(val) {
+ if (val == null) {
+ // `undefined` or `null` become exclusive projections
+ return true;
+ }
+ if (typeof val === 'object') {
+ // Only cases where a value does **not** define whether the whole projection
+ // is inclusive or exclusive are `$meta` and `$slice`.
+ return !('$meta' in val) && !('$slice' in val);
+ }
+ return true;
+};
diff --git a/node_modules/mongoose/lib/helpers/projection/isExclusive.js b/node_modules/mongoose/lib/helpers/projection/isExclusive.js
new file mode 100644
index 0000000..8c64bc5
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/projection/isExclusive.js
@@ -0,0 +1,28 @@
+'use strict';
+
+const isDefiningProjection = require('./isDefiningProjection');
+
+/*!
+ * ignore
+ */
+
+module.exports = function isExclusive(projection) {
+ const keys = Object.keys(projection);
+ let ki = keys.length;
+ let exclude = null;
+
+ if (ki === 1 && keys[0] === '_id') {
+ exclude = !!projection[keys[ki]];
+ } else {
+ while (ki--) {
+ // Does this projection explicitly define inclusion/exclusion?
+ // Explicitly avoid `$meta` and `$slice`
+ if (keys[ki] !== '_id' && isDefiningProjection(projection[keys[ki]])) {
+ exclude = !projection[keys[ki]];
+ break;
+ }
+ }
+ }
+
+ return exclude;
+};
diff --git a/node_modules/mongoose/lib/helpers/projection/isInclusive.js b/node_modules/mongoose/lib/helpers/projection/isInclusive.js
new file mode 100644
index 0000000..098309f
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/projection/isInclusive.js
@@ -0,0 +1,34 @@
+'use strict';
+
+const isDefiningProjection = require('./isDefiningProjection');
+
+/*!
+ * ignore
+ */
+
+module.exports = function isInclusive(projection) {
+ if (projection == null) {
+ return false;
+ }
+
+ const props = Object.keys(projection);
+ const numProps = props.length;
+ if (numProps === 0) {
+ return false;
+ }
+
+ for (let i = 0; i < numProps; ++i) {
+ const prop = props[i];
+ // Plus paths can't define the projection (see gh-7050)
+ if (prop.startsWith('+')) {
+ continue;
+ }
+ // If field is truthy (1, true, etc.) and not an object, then this
+ // projection must be inclusive. If object, assume its $meta, $slice, etc.
+ if (isDefiningProjection(projection[prop]) && !!projection[prop]) {
+ return true;
+ }
+ }
+
+ return false;
+};
diff --git a/node_modules/mongoose/lib/helpers/projection/isPathExcluded.js b/node_modules/mongoose/lib/helpers/projection/isPathExcluded.js
new file mode 100644
index 0000000..fc2592c
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/projection/isPathExcluded.js
@@ -0,0 +1,35 @@
+'use strict';
+
+const isDefiningProjection = require('./isDefiningProjection');
+
+/*!
+ * Determines if `path` is excluded by `projection`
+ *
+ * @param {Object} projection
+ * @param {string} path
+ * @return {Boolean}
+ */
+
+module.exports = function isPathExcluded(projection, path) {
+ if (path === '_id') {
+ return projection._id === 0;
+ }
+
+ const paths = Object.keys(projection);
+ let type = null;
+
+ for (const _path of paths) {
+ if (isDefiningProjection(projection[_path])) {
+ type = projection[path] === 1 ? 'inclusive' : 'exclusive';
+ break;
+ }
+ }
+
+ if (type === 'inclusive') {
+ return projection[path] !== 1;
+ }
+ if (type === 'exclusive') {
+ return projection[path] === 0;
+ }
+ return false;
+};
diff --git a/node_modules/mongoose/lib/helpers/projection/isPathSelectedInclusive.js b/node_modules/mongoose/lib/helpers/projection/isPathSelectedInclusive.js
new file mode 100644
index 0000000..8a05fc9
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/projection/isPathSelectedInclusive.js
@@ -0,0 +1,28 @@
+'use strict';
+
+/*!
+ * ignore
+ */
+
+module.exports = function isPathSelectedInclusive(fields, path) {
+ const chunks = path.split('.');
+ let cur = '';
+ let j;
+ let keys;
+ let numKeys;
+ for (let i = 0; i < chunks.length; ++i) {
+ cur += cur.length ? '.' : '' + chunks[i];
+ if (fields[cur]) {
+ keys = Object.keys(fields);
+ numKeys = keys.length;
+ for (j = 0; j < numKeys; ++j) {
+ if (keys[i].indexOf(cur + '.') === 0 && keys[i].indexOf(path) !== 0) {
+ continue;
+ }
+ }
+ return true;
+ }
+ }
+
+ return false;
+};
diff --git a/node_modules/mongoose/lib/helpers/projection/parseProjection.js b/node_modules/mongoose/lib/helpers/projection/parseProjection.js
new file mode 100644
index 0000000..d2a44b1
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/projection/parseProjection.js
@@ -0,0 +1,33 @@
+'use strict';
+
+/**
+ * Convert a string or array into a projection object, retaining all
+ * `-` and `+` paths.
+ */
+
+module.exports = function parseProjection(v, retainMinusPaths) {
+ const type = typeof v;
+
+ if (type === 'string') {
+ v = v.split(/\s+/);
+ }
+ if (!Array.isArray(v) && Object.prototype.toString.call(v) !== '[object Arguments]') {
+ return v;
+ }
+
+ const len = v.length;
+ const ret = {};
+ for (let i = 0; i < len; ++i) {
+ let field = v[i];
+ if (!field) {
+ continue;
+ }
+ const include = '-' == field[0] ? 0 : 1;
+ if (!retainMinusPaths && include === 0) {
+ field = field.substring(1);
+ }
+ ret[field] = include;
+ }
+
+ return ret;
+}; \ No newline at end of file