Skip to content

Commit f5cdb9a

Browse files
author
Samuel Reed
committed
Merge pull request #5 from jacobwg/update-for-mongoose-3.6
Update for Mongoose 3.6
2 parents 749e048 + 00ca916 commit f5cdb9a

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
coverage
2+
lib-cov
3+
*.seed
4+
*.log
5+
*.csv
6+
*.dat
7+
*.out
8+
*.pid
9+
*.gz
10+
11+
pids
12+
logs
13+
results
14+
15+
npm-debug.log
16+
node_modules

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ UserSchema.plugin(filter, {
4747
},
4848
// 'nofilter' is a built-in filter that does no processing, be careful with this
4949
defaultFilterRole: 'nofilter',
50-
sanitize: true // Escape HTML in strings
50+
sanitize: true, // Escape HTML in strings
51+
compat: true // Enable compatibility for Mongoose versions prior to 3.6 (default false)
5152
});
5253
```
5354

@@ -84,6 +85,7 @@ User.findById(req.params.id, function(err, user){
8485
Useful for protected attributes like fb.accessToken.
8586
- `defaultFilterRole` (String)(default: 'nofilter'): Profile to use when one is not given, or the given profile does not exist.
8687
- `sanitize` (Boolean)(default: false): True to automatically escape HTML in strings.
88+
- `compat` (Boolean)(default: false): True to enable compatibility with Mongoose versions prior to 3.6
8789

8890
### Statics
8991

lib/denormalize.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* Example Usage:
1313
*
14-
* var denormalize = require('mongoose-denormalize-plugin');
14+
* var denormalize = require('mongoose-filter-denormalize').denormalize;
1515
* var ObjectId = mongoose.Schema.ObjectId;
1616
* var UserSchema = new Mongoose.schema({
1717
* name : String,
@@ -38,7 +38,7 @@
3838
*/
3939

4040
var mongoose = require('mongoose'),
41-
_ = require('underscore');
41+
_ = require('lodash');
4242

4343
module.exports = function denormalize(schema, options) {
4444
if(!options) options = {};
@@ -128,4 +128,4 @@ module.exports = function denormalize(schema, options) {
128128
});
129129
return ret;
130130
}
131-
};
131+
};

lib/filter.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* ----- Environment: -----
3636
* ----- -----
3737
*
38-
* var filter = require('mongoose-filter-plugin');
38+
* var filter = require('mongoose-filter-denormalize').filter;
3939
* var ObjectId = mongoose.Schema.ObjectId;
4040
* var UserSchema = new Mongoose.schema({
4141
* name : String,
@@ -89,21 +89,24 @@
8989
*/
9090

9191
var mongoose = require('mongoose'),
92-
_ = require('underscore'),
92+
_ = require('lodash'),
9393
sanitizer = require('sanitizer');
9494

9595
module.exports = function filter(schema, options) {
9696

9797
var defaults = {
9898
sanitize: false, // escapes HTML
99-
defaultFilterRole : 'nofilter'
99+
defaultFilterRole : 'nofilter',
100+
compat: false
100101
};
101102

102103
options = _.extend(defaults, options);
103104

104105
schema.statics.getReadFilterKeys = function(filterRole){
105106
var filters = this._getFilterKeys("readFilter", filterRole);
106-
return filters ? filters.concat('_id') : filters; // Always send _id property
107+
filters = filters ? filters.concat('_id') : filters; // Always send _id property
108+
if (options.compat) return filters;
109+
else return filters.join(' ');
107110
};
108111

109112
schema.statics.getWriteFilterKeys = function(filterRole){
@@ -246,4 +249,4 @@ module.exports = function filter(schema, options) {
246249
return obj;
247250
}
248251

249-
};
252+
};

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
{ "name": "mongoose-filter-denormalize",
1+
{
2+
"name": "mongoose-filter-denormalize",
23
"version": "0.2.0",
34
"description": "Simple collection filtering and denormalization.",
45
"author": "Samuel Reed <[email protected]",
56
"main": "index",
67
"tags": "mongoose filter plugin",
7-
"repository" : "git://github.com/STRML/mongoose-filter-denormalize",
8-
"dependencies" : {
9-
"mongoose" : "~3.0",
10-
"sanitizer" : "~0.0.15",
11-
"underscore" : "~1.3.1"
8+
"repository": "git://github.com/STRML/mongoose-filter-denormalize",
9+
"dependencies": {
10+
"lodash": "~2.2.0",
11+
"mongoose": "~3.6.0",
12+
"sanitizer": "~0.1.0"
1213
}
1314
}

0 commit comments

Comments
 (0)