diff --git a/lib/options/SchemaNumberOptions.js b/lib/options/SchemaNumberOptions.js new file mode 100644 index 00000000000..2186a83740b --- /dev/null +++ b/lib/options/SchemaNumberOptions.js @@ -0,0 +1,44 @@ +'use strict'; + +const SchemaTypeOptions = require('./SchemaTypeOptions'); + +class SchemaNumberOptions extends SchemaTypeOptions {} + +const opts = { + enumerable: true, + configurable: true, + writable: true, + value: null +}; + +/** + * If set, Mongoose adds a validator that checks that this path is at least the + * given `min`. + * + * @api public + * @property min + * @memberOf SchemaNumberOptions + * @type Number + * @instance + */ + +Object.defineProperty(SchemaNumberOptions.prototype, 'min', opts); + +/** + * If set, Mongoose adds a validator that checks that this path is at least the + * given `max`. + * + * @api public + * @property max + * @memberOf SchemaNumberOptions + * @type Number + * @instance + */ + +Object.defineProperty(SchemaNumberOptions.prototype, 'max', opts); + +/*! + * ignore + */ + +module.exports = SchemaNumberOptions; \ No newline at end of file diff --git a/lib/schema/number.js b/lib/schema/number.js index 8f9100d268c..62729eca174 100644 --- a/lib/schema/number.js +++ b/lib/schema/number.js @@ -5,6 +5,7 @@ */ const MongooseError = require('../error/index'); +const SchemaNumberOptions = require('../options/SchemaNumberOptions'); const SchemaType = require('../schematype'); const castNumber = require('../cast/number'); const handleBitwiseOperator = require('./operators/bitwise'); @@ -106,6 +107,7 @@ SchemaNumber.schemaName = 'Number'; */ SchemaNumber.prototype = Object.create(SchemaType.prototype); SchemaNumber.prototype.constructor = SchemaNumber; +SchemaNumber.prototype.OptionsConstructor = SchemaNumberOptions; /*! * ignore diff --git a/lib/schema/string.js b/lib/schema/string.js index c45d08f6dfb..fe3e9568a07 100644 --- a/lib/schema/string.js +++ b/lib/schema/string.js @@ -43,13 +43,13 @@ SchemaString.schemaName = 'String'; */ SchemaString.prototype = Object.create(SchemaType.prototype); SchemaString.prototype.constructor = SchemaString; +SchemaString.prototype.OptionsConstructor = SchemaStringOptions; /*! * ignore */ SchemaString._cast = castString; -SchemaString.OptionsConstructor = SchemaStringOptions; /** * Get/set the function used to cast arbitrary values to strings. diff --git a/lib/schematype.js b/lib/schematype.js index dea567766ca..2cd0caf0858 100644 --- a/lib/schematype.js +++ b/lib/schematype.js @@ -98,6 +98,12 @@ function SchemaType(path, options, instance) { }); } +/*! + * ignore + */ + +SchemaType.prototype.OptionsConstructor = SchemaTypeOptions; + /** * Get/set the function used to cast arbitrary values to this type. *