mongoose-hidden
Advanced tools
Comparing version
# Changelog | ||
1.5.1 | ||
- fix: 1.5.0 would add entries from the schema that were not in the original transform (thanks to @proswdev) | ||
1.5.0 | ||
@@ -4,0 +8,0 @@ |
@@ -36,6 +36,8 @@ 'use strict'; |
function testSchema(schema, key, doc, transformed) { |
if (typeof schema === 'undefined') { return false } |
return schema.options[key] === true || |
typeof schema.options[key] === 'function' && |
schema.options[key](doc, transformed) |
if (typeof schema === 'undefined') { |
return false |
} |
return schema.options[key] === true |
|| (typeof schema.options[key] === 'function' && schema.options[key](doc, transformed)) |
} |
@@ -74,3 +76,3 @@ |
* @param {Schema} schema a mongoose schema |
* @param {string} key |
* @param {string} key object key name |
* @param {object} options a set of options |
@@ -81,4 +83,4 @@ * @param {string} target the target to test, e.g 'JSON' |
function shouldCopyVirtual(schema, key, options, target) { |
return schema.pathType(key) === 'virtual' && |
[hide, `hide${target}`].indexOf(options.virtuals[key]) === -1 |
return schema.pathType(key) === 'virtual' |
&& [hide, `hide${target}`].indexOf(options.virtuals[key]) === -1 |
} |
@@ -204,3 +206,5 @@ |
const partsToValue = function (parts, value) { |
if (parts.length === 0) { return value } |
if (parts.length === 0) { |
return value |
} |
let obj = {} |
@@ -267,4 +271,7 @@ obj[parts[0]] = partsToValue(parts.slice(1), value) |
} else { |
log('%s: copy "%s"', target, pathname) |
setPath(finalTransform, pathname, mpath.get(pathname, transformed)) |
let value = mpath.get(pathname, transformed) |
if (typeof value !== 'undefined') { |
log('%s: copy "%s"', target, pathname) |
setPath(finalTransform, pathname, value) |
} |
} |
@@ -271,0 +278,0 @@ }) |
{ | ||
"name": "mongoose-hidden", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"author": "Michael Bøcker-Larsen <mblarsen@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Hides certain model properties when invoking toJSON or toObject.", |
@@ -8,5 +8,10 @@ # mongoose-hidden | ||
[](https://www.npmjs.com/package/mongoose-hidden/) [](https://www.npmjs.com/package/mongoose-hidden/) | ||
[](https://freewallet.org/id/mblarsen/btc) | ||
A Mongoose schema plugin that hooks into `toJSON()` and `toObject()` to allow hiding of properties you do not want sent client-side, like passwords and other secrets and sensitive information. | ||
<a target='_blank' rel='nofollow' href='https://app.codesponsor.io/link/okYdxs3cWxjapKfPcTg9nLwG/mblarsen/mongoose-hidden'> | ||
<img alt='Sponsor' width='888' height='68' src='https://app.codesponsor.io/embed/okYdxs3cWxjapKfPcTg9nLwG/mblarsen/mongoose-hidden.svg' /> | ||
</a> | ||
# Install | ||
@@ -13,0 +18,0 @@ |
1426
0.42%180
2.86%57977
-34.49%15
-6.25%