mongoose-types-ext
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -0,1 +1,13 @@ | ||
<a name"0.2.0"></a> | ||
## 0.2.0 (2015-05-20) | ||
#### Features | ||
* **exact-length:** adapt to mongoose 4 validator syntax ([99a72122](https://github.com/the-darc/mongoose-types-ext/commit/99a72122)) | ||
* **exclusive-min:** adapt to mongoose 4 validator syntax ([d87b294f](https://github.com/the-darc/mongoose-types-ext/commit/d87b294f)) | ||
* **max-length:** remove maxlength, it is now a mongoose builtin ([ac52c945](https://github.com/the-darc/mongoose-types-ext/commit/ac52c945)) | ||
* **min-length:** remove minlength, it is now a mongoose builtin ([e6b5a49c](https://github.com/the-darc/mongoose-types-ext/commit/e6b5a49c)) | ||
<a name"0.1.0"></a> | ||
@@ -2,0 +14,0 @@ ## 0.1.0 (2015-03-19) |
@@ -24,7 +24,2 @@ var path = require('path'), | ||
function handleError(err) { | ||
console.log(err.toString()); | ||
this.emit('end'); | ||
} | ||
function mochaRunnerFactory(reporter) { | ||
@@ -38,8 +33,11 @@ return plugins.mocha({ | ||
function mochaRunner() { | ||
return gulp.src(config.files, { | ||
var g = gulp.src(config.files, { | ||
cwd: process.env.PWD, | ||
read: false | ||
}) | ||
.pipe(mochaRunnerFactory(config.reporter)) | ||
.on('error', handleError); | ||
.pipe(mochaRunnerFactory(config.reporter)); | ||
if (watch) { | ||
g.on('error', console.warn.bind(console)); | ||
} | ||
return g; | ||
} | ||
@@ -87,3 +85,11 @@ | ||
.pipe(plugins.istanbul.writeReports()) | ||
.on('end', done); | ||
.on('end', function() { | ||
if (process.env.TRAVIS) { | ||
gulp.src('./coverage/**/lcov.info') | ||
.pipe(plugins.coveralls()) | ||
.on('end', done); | ||
} else { | ||
done(); | ||
} | ||
}); | ||
}); | ||
@@ -90,0 +96,0 @@ }); |
module.exports = function(mongoose) { | ||
require('./lib/string-ext/max-length.js')(mongoose); | ||
require('./lib/string-ext/min-length.js')(mongoose); | ||
require('./lib/string-ext/exact-length.js')(mongoose); | ||
require('./lib/number-ext/exclusive-min.js')(mongoose); | ||
}; |
@@ -37,14 +37,12 @@ module.exports = function(mongoose) { | ||
SchemaNumber.prototype.exclusivemin = function (value, message) { | ||
if (this.exclusiveminValidator) { | ||
this.validators = this.validators.filter(function (v) { | ||
return v.validator !== this.exclusiveminValidator; | ||
}, this); | ||
} | ||
if (null !== value) { | ||
var msg = message || errorMessages.Number.exclusivemin; | ||
msg = msg.replace(/{EXCLUSIVE_MIN}/, value); | ||
this.validators.push([this.exclusiveminValidator = function (v) { | ||
return v === null || v === undefined || v > value; | ||
}, msg, 'exclusivemin']); | ||
this.validators.push({ | ||
validator: this.exclusiveminValidator = function (v) { | ||
return v === null || v === undefined || v > value; | ||
}, | ||
message: msg, | ||
type: 'exclusivemin' | ||
}); | ||
} | ||
@@ -51,0 +49,0 @@ |
@@ -38,14 +38,12 @@ module.exports = function(mongoose) { | ||
SchemaString.prototype.exactlength = function(value, message) { | ||
if (this.exactlengthValidator) { | ||
this.validators = this.validators.filter(function (v) { | ||
return v[0] !== this.exactlengthValidator; | ||
}, this); | ||
} | ||
if (null !== value) { | ||
var msg = message || errorMessages.String.exactlength; | ||
msg = msg.replace(/{EXACT_LENGTH}/, value); | ||
this.validators.push([this.exactlengthValidator = function (v) { | ||
return v === undefined || v === null || v.length === value; | ||
}, msg, 'exactlength']); | ||
this.validators.push({ | ||
validator: this.exactlengthValidator = function (v) { | ||
return v === undefined || v === null || v.length === value; | ||
}, | ||
message: msg, | ||
type: 'exactlength' | ||
}); | ||
} | ||
@@ -52,0 +50,0 @@ |
{ | ||
"name": "mongoose-types-ext", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A package of mongoose types extensions", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "gulp test" | ||
"test": "gulp test-coverage" | ||
}, | ||
@@ -32,2 +32,3 @@ "repository": { | ||
"gulp": "^3.8.11", | ||
"gulp-coveralls": "^0.1.3", | ||
"gulp-istanbul": "^0.6.0", | ||
@@ -40,5 +41,5 @@ "gulp-jshint": "^1.9.4", | ||
"mocha": "^2.2.1", | ||
"mongoose": "^3.8.25", | ||
"mongoose": "~4.0.3", | ||
"should": "^5.2.0" | ||
} | ||
} |
[![npm version](https://badge.fury.io/js/mongoose-types-ext.svg)](http://badge.fury.io/js/mongoose-types-ext) | ||
[![Build Status](https://travis-ci.org/the-darc/mongoose-types-ext.svg?branch=master)](https://travis-ci.org/the-darc/mongoose-types-ext) | ||
[![Coverage Status](https://coveralls.io/repos/the-darc/mongoose-types-ext/badge.svg)](https://coveralls.io/r/the-darc/mongoose-types-ext) | ||
@@ -16,22 +17,70 @@ # mongoose-types-ext # | ||
Require the extensions before load your mongoose models: | ||
### Runing tests ### | ||
```bash | ||
gulp test | ||
``` | ||
## Usage ## | ||
Just require the extensions before load your mongoose models: | ||
```javascript | ||
var mongoose = require('mongoose'); | ||
require('mongoose-types-ext')(mongoose); | ||
var YourSchemaDefinition = new mongooseSchema({ | ||
someField: { | ||
type: String, | ||
maxLength: 10 | ||
}, | ||
/* (...) */ | ||
}); | ||
var YourModel = mongoose.model('YourModel', YourSchemaDefinition); | ||
``` | ||
## Supported extentions ## | ||
### String ### | ||
- `exactLength`: Sets a exact length string validator. | ||
**Custom error messages:** You can also configure custom error messages and use the special token | ||
`{EXACT_LENGTH}` which will be replaced with the invalid value. Ex: | ||
```javascript | ||
var rule = [4, 'The length of path `{PATH}` ({VALUE}) should be equal {EXACT_LENGTH}.']; | ||
var schema = new Schema({ n: { type: String, exactLength: rule }) | ||
var M = mongoose.model('Measurement', schema); | ||
var s= new M({ n: 'teste' }); | ||
s.validate(function (err) { | ||
console.log(String(err)); // ValidationError: The length of path `n` (test) should be equal 4. | ||
}) | ||
``` | ||
### Runing tests ### | ||
### Number ### | ||
- `exclusivemin`: Sets a minimum number validator not including the configurated value. | ||
```bash | ||
gulp test | ||
**Custom error messages:** You can also configure custom error messages and use the special token | ||
`{EXCLUSIVE_MIN}` which will be replaced with the invalid value. Ex: | ||
```javascript | ||
var rule = [10, 'The value of path `{PATH}` ({VALUE}) should be greater than ({EXCLUSIVE_MIN}).']; | ||
var schema = new Schema({ n: { type: Number, exclusivemin: rule }) | ||
var M = mongoose.model('Measurement', schema); | ||
var s= new M({ n: 10 }); | ||
s.validate(function (err) { | ||
console.log(String(err)); // ValidationError: The value of path `n` (10) should be greater than 10. | ||
}); | ||
``` | ||
## Extentions ## | ||
How to contribute | ||
----------------- | ||
### String: min-length ### | ||
I am very glad to see this project living with pull requests. | ||
### String: max-length ### | ||
LICENSE | ||
------- | ||
### String: exact-length ### | ||
Copyright (c) 2015 Daniel Campos | ||
### Number: exclusive-min ### | ||
Licensed under the MIT license. | ||
@@ -1,3 +0,3 @@ | ||
var db = require('db'), | ||
mongoose = db.mongoose, | ||
var db = require('./db'), | ||
mongoose = require('mongoose'), | ||
should = require('should'); | ||
@@ -24,2 +24,6 @@ | ||
exactlength: [1, 'Path {PATH} ({VALUE}) has length different of {EXACT_LENGTH}'] | ||
}, | ||
field05: { | ||
type: String, | ||
exactlength: null | ||
} | ||
@@ -33,3 +37,3 @@ }); | ||
this.timeout(5000); | ||
var tst = new TestDoc({field01: '12345678'}); | ||
var tst = new TestDoc({field01: '12345678', field05: '12345678901234567890'}); | ||
tst.save(function(err, tst) { | ||
@@ -40,2 +44,3 @@ if(err) { | ||
should(tst.field01).be.eql('12345678'); | ||
should(tst.field05).be.eql('12345678901234567890'); | ||
done(); | ||
@@ -69,3 +74,3 @@ }); | ||
should(err).be.ok; | ||
should(err.message).be.eql('Validation failed'); | ||
should(err.message).be.eql('TestDoc validation failed'); | ||
should(err.name).be.eql('ValidationError'); | ||
@@ -83,3 +88,3 @@ should(err.errors.field02).be.ok; | ||
should(err).be.ok; | ||
should(err.message).be.eql('Validation failed'); | ||
should(err.message).be.eql('TestDoc validation failed'); | ||
should(err.name).be.eql('ValidationError'); | ||
@@ -100,3 +105,3 @@ should(err.errors.field02).be.ok; | ||
should(err).be.ok; | ||
should(err.message).be.eql('Validation failed'); | ||
should(err.message).be.eql('TestDoc validation failed'); | ||
should(err.name).be.eql('ValidationError'); | ||
@@ -116,3 +121,3 @@ should(err.errors.field02).be.ok; | ||
should(err).be.ok; | ||
should(err.message).be.eql('Validation failed'); | ||
should(err.message).be.eql('TestDoc validation failed'); | ||
should(err.name).be.eql('ValidationError'); | ||
@@ -119,0 +124,0 @@ should(err.errors.field04).be.ok; |
@@ -1,3 +0,3 @@ | ||
var db = require('db'), | ||
mongoose = db.mongoose, | ||
var db = require('./db'), | ||
mongoose = require('mongoose'), | ||
should = require('should'); | ||
@@ -24,2 +24,6 @@ | ||
exclusivemin: [20, 'Path {PATH} ({VALUE}) out of minimum limit {EXCLUSIVE_MIN}'] | ||
}, | ||
field05: { | ||
type: Number, | ||
exclusivemin: null | ||
} | ||
@@ -33,3 +37,3 @@ }); | ||
this.timeout(5000); | ||
var tst = new TestDoc({field01: 1}); | ||
var tst = new TestDoc({field01: 1, field05: -1}); | ||
tst.save(function(err, tst) { | ||
@@ -40,2 +44,3 @@ if(err) { | ||
should(tst.field01).be.eql(1); | ||
should(tst.field05).be.eql(-1); | ||
done(); | ||
@@ -73,3 +78,3 @@ }); | ||
should(err).be.ok; | ||
should(err.message).be.eql('Validation failed'); | ||
should(err.message).be.eql('TestDoc validation failed'); | ||
should(err.name).be.eql('ValidationError'); | ||
@@ -88,3 +93,3 @@ should(err.errors.field02).be.ok; | ||
should(err).be.ok; | ||
should(err.message).be.eql('Validation failed'); | ||
should(err.message).be.eql('TestDoc validation failed'); | ||
should(err.name).be.eql('ValidationError'); | ||
@@ -106,3 +111,3 @@ should(err.errors.field02).be.ok; | ||
should(err).be.ok; | ||
should(err.message).be.eql('Validation failed'); | ||
should(err.message).be.eql('TestDoc validation failed'); | ||
should(err.name).be.eql('ValidationError'); | ||
@@ -123,3 +128,3 @@ should(err.errors.field02).be.ok; | ||
should(err).be.ok; | ||
should(err.message).be.eql('Validation failed'); | ||
should(err.message).be.eql('TestDoc validation failed'); | ||
should(err.name).be.eql('ValidationError'); | ||
@@ -126,0 +131,0 @@ should(err.errors.field04).be.ok; |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
86
20286
12
14
465
5