New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-hidden

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-hidden - npm Package Compare versions

Comparing version

to
1.7.1

lib/mpath.js

4

CHANGELOG.md
# Changelog
1.7.0
- replace custom setPath function with mpath.set (#69)
1.6.2

@@ -4,0 +8,0 @@

60

lib/mongoose-hidden.js
'use strict'
const mpath = require('mpath')
const mpath = require('./mpath.js')
const log = require('debug')('mongoose-hidden')

@@ -41,4 +41,4 @@

return (
schema.options[key] === true
|| (typeof schema.options[key] === 'function' && schema.options[key](doc, transformed))
schema.options[key] === true ||
(typeof schema.options[key] === 'function' && schema.options[key](doc, transformed))
)

@@ -69,5 +69,5 @@ }

return (
testOptions(options, pathname)
|| testSchema(schema, hide, doc, transformed)
|| testSchema(schema, hideTarget, doc, transformed)
testOptions(options, pathname) ||
testSchema(schema, hide, doc, transformed) ||
testSchema(schema, hideTarget, doc, transformed)
)

@@ -88,4 +88,4 @@ }

return (
schema.pathType(key) === 'virtual'
&& [hide, `hide${target}`].indexOf(options.virtuals[key]) === -1
schema.pathType(key) === 'virtual' &&
[hide, `hide${target}`].indexOf(options.virtuals[key]) === -1
)

@@ -203,39 +203,2 @@ }

/**
* Convert path parts into a nested object
*
* @access private
* @param {array} parts an array of parts on the path
* @param {mixed} value the value to set at the end of the path
* @returns {object} an object corresponding to the path that the parts represents
*/
const partsToValue = function(parts, value) {
if (parts.length === 0) {
return value
}
let obj = {}
obj[parts[0]] = partsToValue(parts.slice(1), value)
return obj
}
/**
* Set a value in object denoted by dot-path
*
* @access private
* @param {object} obj source object
* @param {string} path a dot-path
* @param {mixed} value the value to set at the end of the path
*/
const setPath = function(obj, path, value) {
const parts = path.split('.')
/* traverse existing path to nearest object */
while (parts.length > 1 && typeof obj[parts[0]] === 'object') {
obj = obj[parts.shift()]
}
/* set value */
obj[parts[0]] = partsToValue(parts.slice(1), value)
}
module.exports = function(defaults) {

@@ -284,3 +247,3 @@ let _defaults = Object.assign(

log('%s: copy "%s"', target, pathname)
setPath(finalTransform, pathname, value)
mpath.set(pathname, value, finalTransform)
}

@@ -295,3 +258,3 @@ }

log('%s: copy virtual "%s"', target, key)
setPath(finalTransform, key, mpath.get(key, transformed))
mpath.set(key, mpath.get(key, transformed), finalTransform)
}

@@ -323,4 +286,1 @@ }

}
/* for testing */
module.exports['__test__'] = { setPath: setPath }
{
"name": "mongoose-hidden",
"version": "1.6.2",
"version": "1.7.1",
"author": "Michael Bøcker-Larsen <m19n@pm.me>",

@@ -29,10 +29,10 @@ "description": "Hides certain model properties when invoking toJSON or toObject.",

"dependencies": {
"debug": "^4.0.1",
"debug": "^4.1.1",
"mpath": "^0.6.0"
},
"devDependencies": {
"coveralls": "^3.0.0",
"coveralls": "^3.0.6",
"istanbul": "^0.4.2",
"mocha": "^6.0.0",
"mongoose": "^5.0.0",
"mongoose": "^5.6.9",
"should": "^13.1.0"

@@ -39,0 +39,0 @@ },

@@ -5,2 +5,3 @@ # mongoose-hidden

[![Build status](http://img.shields.io/travis/mblarsen/mongoose-hidden.svg)](http://travis-ci.org/mblarsen/mongoose-hidden)
[![codebeat badge](https://codebeat.co/badges/05e78d4b-9038-4339-8e67-0702cc4416a2)](https://codebeat.co/projects/github-com-mblarsen-mongoose-hidden-master)
[![Coverage status](https://coveralls.io/repos/github/mblarsen/mongoose-hidden/badge.svg?branch=master)](https://coveralls.io/github/mblarsen/mongoose-hidden?branch=master)

@@ -135,3 +136,3 @@ [![Known vulnerabilities](https://snyk.io/test/github/mblarsen/mongoose-hidden/badge.svg)](https://snyk.io/test/github/mblarsen/mongoose-hidden)

If have nested virtuals use the path for the key above, e.g. `'nested.virtual': 'hideJSON'`.
For nested virtuals use the path for the key above, e.g. `'nested.virtual': 'hideJSON'`.

@@ -138,0 +139,0 @@ _Note: If you don't turn on virtuals for `toObject`, `fullname` in the above example `fullname` will *NOT* be hidden despite its `hideJSON` value._

@@ -10,3 +10,3 @@ 'use strict'

const setPath = plugin.__test__.setPath
const mpath = require('../lib/mpath.js')

@@ -45,4 +45,4 @@ describe('mongoose-hidden', function() {

}
let schema
= schemaProperties instanceof Schema ? schemaProperties : new Schema(schemaProperties)
let schema =
schemaProperties instanceof Schema ? schemaProperties : new Schema(schemaProperties)
schema.plugin(mongooseHidden, pluginOptions || {})

@@ -681,5 +681,5 @@ return mongoose.model(name, schema, undefined)

user.save(function() {
User.findOne().
populate('company').
exec(function(err, freshUser) {
User.findOne()
.populate('company')
.exec(function(err, freshUser) {
should.exist(freshUser.company)

@@ -734,5 +734,5 @@ freshUser.company.name.should.equal('GOGGLE')

user.save(function() {
User.findOne().
populate('companies').
exec(function(err, freshUser) {
User.findOne()
.populate('companies')
.exec(function(err, freshUser) {
should.exist(freshUser.companies)

@@ -895,3 +895,3 @@ freshUser.companies[0].name.should.equal('GOGGLE')

let obj = { password: 'secret' }
setPath(obj, 'password', 'no more secrets')
mpath.set('password', 'no more secrets', obj)
obj.password.should.equal('no more secrets')

@@ -901,3 +901,3 @@ })

let obj = {}
setPath(obj, 'password', 'no more secrets')
mpath.set('password', 'no more secrets', obj)
obj.password.should.equal('no more secrets')

@@ -907,5 +907,5 @@ })

let obj = { name: { first: 'Joe' } }
setPath(obj, 'name.first', 'Jane')
mpath.set('name.first', 'Jane', obj)
obj.name.first.should.equal('Jane')
setPath(obj, 'name.last', 'Doe')
mpath.set('name.last', 'Doe', obj)
obj.name.last.should.equal('Doe')

@@ -915,7 +915,9 @@ })

let obj = {}
setPath(obj, 'name.first', 'Jane')
mpath.set('name.first', 'Jane', obj)
obj.name.first.should.equal('Jane')
setPath(obj, 'rights.inland.case', 'A0003')
mpath.set('name.pets', ['Lolli', 'Pop'], obj)
obj.name.pets.should.deepEqual(['Lolli', 'Pop'])
mpath.set('rights.inland.case', 'A0003', obj)
obj.rights.inland.case.should.equal('A0003')
setPath(obj, 'rights.outlandish.case', 'A0004')
mpath.set('rights.outlandish.case', 'A0004', obj)
obj.rights.outlandish.case.should.equal('A0004')

@@ -922,0 +924,0 @@ })